Skip to content

Commit 2890380

Browse files
Damien Carrierweaverryan
authored andcommitted
[TogglePasswordComponent] Add documentation for usage without Symfony Forms
1 parent 19feb79 commit 2890380

File tree

4 files changed

+49
-14
lines changed

4 files changed

+49
-14
lines changed

src/TogglePassword/assets/dist/controller.d.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,22 @@ export default class extends Controller<HTMLInputElement> {
66
readonly hiddenIconValue: string;
77
readonly buttonClassesValue: Array<string>;
88
static values: {
9-
visibleLabel: StringConstructor;
10-
visibleIcon: StringConstructor;
11-
hiddenLabel: StringConstructor;
12-
hiddenIcon: StringConstructor;
9+
visibleLabel: {
10+
type: StringConstructor;
11+
default: string;
12+
};
13+
visibleIcon: {
14+
type: StringConstructor;
15+
default: string;
16+
};
17+
hiddenLabel: {
18+
type: StringConstructor;
19+
default: string;
20+
};
21+
hiddenIcon: {
22+
type: StringConstructor;
23+
default: string;
24+
};
1325
buttonClasses: ArrayConstructor;
1426
};
1527
isDisplayed: boolean;

src/TogglePassword/assets/dist/controller.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ class default_1 extends Controller {
4747
}
4848
}
4949
default_1.values = {
50-
visibleLabel: String,
51-
visibleIcon: String,
52-
hiddenLabel: String,
53-
hiddenIcon: String,
50+
visibleLabel: { type: String, default: 'Show' },
51+
visibleIcon: { type: String, default: 'Default' },
52+
hiddenLabel: { type: String, default: 'Hide' },
53+
hiddenIcon: { type: String, default: 'Default' },
5454
buttonClasses: Array,
5555
};
5656

src/TogglePassword/assets/src/controller.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ export default class extends Controller<HTMLInputElement> {
1919
declare readonly buttonClassesValue: Array<string>;
2020

2121
static values = {
22-
visibleLabel: String,
23-
visibleIcon: String,
24-
hiddenLabel: String,
25-
hiddenIcon: String,
22+
visibleLabel: { type: String, default: 'Show' },
23+
visibleIcon: { type: String, default: 'Default' },
24+
hiddenLabel: { type: String, default: 'Hide' },
25+
hiddenIcon: { type: String, default: 'Default' },
2626
buttonClasses: Array,
2727
};
2828

src/TogglePassword/doc/index.rst

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ needed if you're using AssetMapper):
3434
$ yarn install --force
3535
$ yarn watch
3636
37-
Usage
38-
-----
37+
Usage with Symfony Forms
38+
------------------------
3939

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

@@ -259,6 +259,29 @@ Then in your form, add your controller as an HTML attribute::
259259
// ...
260260
}
261261

262+
Usage without Symfony Forms
263+
---------------------------
264+
265+
You can also use the TogglePassword with native HTML inputs:
266+
267+
.. code-block:: html+twig
268+
269+
// ...
270+
271+
<div class="toggle-password-container"> // Add "toggle-password-container" or a class that applies position: relative to this container.
272+
<label for="password">Password</label>
273+
<input
274+
id="password"
275+
name="password"
276+
type="password"
277+
{{ stimulus_controller('symfony/ux-toggle-password/toggle-password', {
278+
buttonClasses: ['toggle-password-button'], // Add as many classes as you wish. "toggle-password-button" is needed to activate the default CSS.
279+
}) }}
280+
>
281+
</div>
282+
283+
// ...
284+
262285
Backward Compatibility promise
263286
------------------------------
264287

0 commit comments

Comments
 (0)