Skip to content

[TogglePasswordComponent] Add documentation for usage without Symfony Forms #1101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/TogglePassword/assets/dist/controller.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@ export default class extends Controller<HTMLInputElement> {
readonly hiddenIconValue: string;
readonly buttonClassesValue: Array<string>;
static values: {
visibleLabel: StringConstructor;
visibleIcon: StringConstructor;
hiddenLabel: StringConstructor;
hiddenIcon: StringConstructor;
visibleLabel: {
type: StringConstructor;
default: string;
};
visibleIcon: {
type: StringConstructor;
default: string;
};
hiddenLabel: {
type: StringConstructor;
default: string;
};
hiddenIcon: {
type: StringConstructor;
default: string;
};
buttonClasses: ArrayConstructor;
};
isDisplayed: boolean;
Expand Down
8 changes: 4 additions & 4 deletions src/TogglePassword/assets/dist/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ class default_1 extends Controller {
}
}
default_1.values = {
visibleLabel: String,
visibleIcon: String,
hiddenLabel: String,
hiddenIcon: String,
visibleLabel: { type: String, default: 'Show' },
visibleIcon: { type: String, default: 'Default' },
hiddenLabel: { type: String, default: 'Hide' },
hiddenIcon: { type: String, default: 'Default' },
buttonClasses: Array,
};

Expand Down
8 changes: 4 additions & 4 deletions src/TogglePassword/assets/src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ export default class extends Controller<HTMLInputElement> {
declare readonly buttonClassesValue: Array<string>;

static values = {
visibleLabel: String,
visibleIcon: String,
hiddenLabel: String,
hiddenIcon: String,
visibleLabel: { type: String, default: 'Show' },
visibleIcon: { type: String, default: 'Default' },
hiddenLabel: { type: String, default: 'Hide' },
hiddenIcon: { type: String, default: 'Default' },
buttonClasses: Array,
};

Expand Down
27 changes: 25 additions & 2 deletions src/TogglePassword/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ needed if you're using AssetMapper):
$ yarn install --force
$ yarn watch

Usage
-----
Usage with Symfony Forms
------------------------

Any ``PasswordType`` can be transformed into a toggle password field by adding the ``toggle`` option::

Expand Down Expand Up @@ -259,6 +259,29 @@ Then in your form, add your controller as an HTML attribute::
// ...
}

Usage without Symfony Forms
---------------------------

You can also use the TogglePassword with native HTML inputs:

.. code-block:: html+twig

// ...

<div class="toggle-password-container"> // Add "toggle-password-container" or a class that applies position: relative to this container.
<label for="password">Password</label>
<input
id="password"
name="password"
type="password"
{{ stimulus_controller('symfony/ux-toggle-password/toggle-password', {
buttonClasses: ['toggle-password-button'], // Add as many classes as you wish. "toggle-password-button" is needed to activate the default CSS.
}) }}
>
</div>

// ...

Backward Compatibility promise
------------------------------

Expand Down