@alpinejs/docs 3.10.1-revision.1 → 3.10.3-revision.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/en/directives/on.md +2 -2
- package/src/en/directives/show.md +17 -0
- package/src/en/essentials/installation.md +1 -1
- package/src/en/magics/store.md +1 -1
- package/src/en/plugins/focus.md +10 -10
- package/src/en/plugins/mask.md +25 -11
- package/src/en/plugins/morph.md +11 -11
- package/src/en/ui.md +6 -0
package/package.json
CHANGED
package/src/en/directives/on.md
CHANGED
|
@@ -13,7 +13,7 @@ Here's an example of simple button that shows an alert when clicked.
|
|
|
13
13
|
<button x-on:click="alert('Hello World!')">Say Hi</button>
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
> `x-on` can only listen for events with lower case names, as HTML attributes are case-insensitive. Writing `x-on:CLICK` will listen for an event named `click`. If you need to listen for a custom event with a camelCase name, you can use the [`.camel` helper](#camel) to work around this limitation. Alternatively, you can use [`x-bind`](/directives/bind
|
|
16
|
+
> `x-on` can only listen for events with lower case names, as HTML attributes are case-insensitive. Writing `x-on:CLICK` will listen for an event named `click`. If you need to listen for a custom event with a camelCase name, you can use the [`.camel` helper](#camel) to work around this limitation. Alternatively, you can use [`x-bind`](/directives/bind#bind-directives) to attach an `x-on` directive to an element in javascript code (where case will be preserved).
|
|
17
17
|
|
|
18
18
|
<a name="shorthand-syntax"></a>
|
|
19
19
|
## Shorthand syntax
|
|
@@ -81,7 +81,7 @@ For easy reference, here is a list of common keys you may want to listen for.
|
|
|
81
81
|
| `.space` | Space |
|
|
82
82
|
| `.ctrl` | Ctrl |
|
|
83
83
|
| `.cmd` | Cmd |
|
|
84
|
-
| `.meta` | Cmd on Mac,
|
|
84
|
+
| `.meta` | Cmd on Mac, Windows key on Windows |
|
|
85
85
|
| `.alt` | Alt |
|
|
86
86
|
| `.up` `.down` `.left` `.right` | Up/Down/Left/Right arrows |
|
|
87
87
|
| `.escape` | Escape |
|
|
@@ -37,3 +37,20 @@ If you want to apply smooth transitions to the `x-show` behavior, you can use it
|
|
|
37
37
|
</div>
|
|
38
38
|
</div>
|
|
39
39
|
```
|
|
40
|
+
|
|
41
|
+
<a name="using-the-important-modifier"></a>
|
|
42
|
+
## Using the important modifier
|
|
43
|
+
|
|
44
|
+
Sometimes you need to apply a little more force to actually hide an element. In cases where a CSS selector applies the `display` property with the `!important` flag, it will take precedence over the inline style set by Alpine.
|
|
45
|
+
|
|
46
|
+
In these cases you may use the `.important` modifier to set the inline style to `display: none !important`.
|
|
47
|
+
|
|
48
|
+
```alpine
|
|
49
|
+
<div x-data="{ open: false }">
|
|
50
|
+
<button x-on:click="open = ! open">Toggle Dropdown</button>
|
|
51
|
+
|
|
52
|
+
<div x-show.important="open">
|
|
53
|
+
Dropdown Contents...
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
```
|
|
@@ -33,7 +33,7 @@ This is by far the simplest way to get started with Alpine. Include the followin
|
|
|
33
33
|
Notice the `@3.x.x` in the provided CDN link. This will pull the latest version of Alpine version 3. For stability in production, it's recommended that you hardcode the latest version in the CDN link.
|
|
34
34
|
|
|
35
35
|
```alpine
|
|
36
|
-
<script defer src="https://unpkg.com/alpinejs@3.10.
|
|
36
|
+
<script defer src="https://unpkg.com/alpinejs@3.10.3/dist/cdn.min.js"></script>
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
That's it! Alpine is now available for use inside your page.
|
package/src/en/magics/store.md
CHANGED
|
@@ -6,7 +6,7 @@ title: store
|
|
|
6
6
|
|
|
7
7
|
# $store
|
|
8
8
|
|
|
9
|
-
You can use `$store` to conveniently access global Alpine stores registered using [`Alpine.store(...)`](/
|
|
9
|
+
You can use `$store` to conveniently access global Alpine stores registered using [`Alpine.store(...)`](/globals/alpine-store). For example:
|
|
10
10
|
|
|
11
11
|
```alpine
|
|
12
12
|
<button x-data @click="$store.darkMode.toggle()">Toggle Dark Mode</button>
|
package/src/en/plugins/focus.md
CHANGED
|
@@ -280,7 +280,7 @@ For example:
|
|
|
280
280
|
<!-- START_VERBATIM -->
|
|
281
281
|
<div class="demo">
|
|
282
282
|
<div
|
|
283
|
-
x-data="{ open: false }"
|
|
283
|
+
x-data="{ open: false }"
|
|
284
284
|
x-trap.noreturn="open"
|
|
285
285
|
@click.outside="open = false"
|
|
286
286
|
@keyup.escape.prevent.stop="open = false"
|
|
@@ -345,9 +345,9 @@ Let's walk through a few examples of these utilities in use. The example below a
|
|
|
345
345
|
@keydown.right="$focus.next()"
|
|
346
346
|
@keydown.left="$focus.previous()"
|
|
347
347
|
>
|
|
348
|
-
<button class="focus:outline-none focus:ring-2 focus:ring-
|
|
349
|
-
<button class="focus:outline-none focus:ring-2 focus:ring-
|
|
350
|
-
<button class="focus:outline-none focus:ring-2 focus:ring-
|
|
348
|
+
<button class="focus:outline-none focus:ring-2 focus:ring-cyan-400">First</button>
|
|
349
|
+
<button class="focus:outline-none focus:ring-2 focus:ring-cyan-400">Second</button>
|
|
350
|
+
<button class="focus:outline-none focus:ring-2 focus:ring-cyan-400">Third</button>
|
|
351
351
|
</div>
|
|
352
352
|
(Click a button, then use the arrow keys to move left and right)
|
|
353
353
|
</div>
|
|
@@ -373,9 +373,9 @@ Notice how if the last button is focused, pressing "right arrow" won't do anythi
|
|
|
373
373
|
@keydown.right="$focus.wrap().next()"
|
|
374
374
|
@keydown.left="$focus.wrap().previous()"
|
|
375
375
|
>
|
|
376
|
-
<button class="focus:outline-none focus:ring-2 focus:ring-
|
|
377
|
-
<button class="focus:outline-none focus:ring-2 focus:ring-
|
|
378
|
-
<button class="focus:outline-none focus:ring-2 focus:ring-
|
|
376
|
+
<button class="focus:outline-none focus:ring-2 focus:ring-cyan-400">First</button>
|
|
377
|
+
<button class="focus:outline-none focus:ring-2 focus:ring-cyan-400">Second</button>
|
|
378
|
+
<button class="focus:outline-none focus:ring-2 focus:ring-cyan-400">Third</button>
|
|
379
379
|
</div>
|
|
380
380
|
(Click a button, then use the arrow keys to move left and right)
|
|
381
381
|
</div>
|
|
@@ -410,9 +410,9 @@ Now, let's add two buttons, one to focus the first element in the button group,
|
|
|
410
410
|
@keydown.right="$focus.wrap().next()"
|
|
411
411
|
@keydown.left="$focus.wrap().previous()"
|
|
412
412
|
>
|
|
413
|
-
<button class="focus:outline-none focus:ring-2 focus:ring-
|
|
414
|
-
<button class="focus:outline-none focus:ring-2 focus:ring-
|
|
415
|
-
<button class="focus:outline-none focus:ring-2 focus:ring-
|
|
413
|
+
<button class="focus:outline-none focus:ring-2 focus:ring-cyan-400">First</button>
|
|
414
|
+
<button class="focus:outline-none focus:ring-2 focus:ring-cyan-400">Second</button>
|
|
415
|
+
<button class="focus:outline-none focus:ring-2 focus:ring-cyan-400">Third</button>
|
|
416
416
|
</div>
|
|
417
417
|
</div>
|
|
418
418
|
<!-- END_VERBATIM -->
|
package/src/en/plugins/mask.md
CHANGED
|
@@ -54,7 +54,7 @@ Alpine.plugin(mask)
|
|
|
54
54
|
|
|
55
55
|
</div>
|
|
56
56
|
</div>
|
|
57
|
-
<button :aria-expanded="expanded" @click="expanded = ! expanded" class="text-
|
|
57
|
+
<button :aria-expanded="expanded" @click="expanded = ! expanded" class="text-cyan-600 font-medium underline">
|
|
58
58
|
<span x-text="expanded ? 'Hide' : 'Show more'">Show</span> <span x-text="expanded ? '↑' : '↓'">↓</span>
|
|
59
59
|
</button>
|
|
60
60
|
</div>
|
|
@@ -87,57 +87,71 @@ The following wildcard characters are supported in masks:
|
|
|
87
87
|
| `9` | Only numeric characters (0-9) |
|
|
88
88
|
|
|
89
89
|
<a name="mask-functions"></a>
|
|
90
|
-
##
|
|
90
|
+
## Dynamic Masks
|
|
91
91
|
|
|
92
|
-
Sometimes simple mask literals (i.e. `(999) 999-9999`) are not sufficient. In these cases, `x-mask:
|
|
92
|
+
Sometimes simple mask literals (i.e. `(999) 999-9999`) are not sufficient. In these cases, `x-mask:dynamic` allows you to dynamically generate masks on the fly based on user input.
|
|
93
93
|
|
|
94
94
|
Here's an example of a credit card input that needs to change it's mask based on if the number starts with the numbers "34" or "37" (which means it's an Amex card and therefore has a different format).
|
|
95
95
|
|
|
96
96
|
```alpine
|
|
97
|
-
<input x-mask:
|
|
97
|
+
<input x-mask:dynamic="
|
|
98
98
|
$input.startsWith('34') || $input.startsWith('37')
|
|
99
99
|
? '9999 999999 99999' : '9999 9999 9999 9999'
|
|
100
100
|
">
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
-
As you can see in the above example, every time a user types in the input, that value is passed to the
|
|
103
|
+
As you can see in the above example, every time a user types in the input, that value is passed to the expression as `$input`. Based on the `$input`, a different mask is utilized in the field.
|
|
104
104
|
|
|
105
105
|
Try it for yourself by typing a number that starts with "34" and one that doesn't.
|
|
106
106
|
|
|
107
107
|
<!-- START_VERBATIM -->
|
|
108
108
|
<div class="demo">
|
|
109
|
-
<input x-data x-mask:
|
|
109
|
+
<input x-data x-mask:dynamic="
|
|
110
110
|
$input.startsWith('34') || $input.startsWith('37')
|
|
111
111
|
? '9999 999999 99999' : '9999 9999 9999 9999'
|
|
112
112
|
">
|
|
113
113
|
</div>
|
|
114
114
|
<!-- END_VERBATIM -->
|
|
115
115
|
|
|
116
|
+
`x-mask:dynamic` also accepts a function as a result of the expression and will automatically pass it the `$input` as the the first paramter. For example:
|
|
117
|
+
|
|
118
|
+
```alpine
|
|
119
|
+
<input x-mask:dynamic="creditCardMask">
|
|
120
|
+
|
|
121
|
+
<script>
|
|
122
|
+
function creditCardMask(input) {
|
|
123
|
+
return input.startsWith('34') || input.startsWith('37')
|
|
124
|
+
? '9999 999999 99999'
|
|
125
|
+
: '9999 9999 9999 9999'
|
|
126
|
+
}
|
|
127
|
+
</script>
|
|
128
|
+
```
|
|
129
|
+
|
|
116
130
|
<a name="money-inputs"></a>
|
|
117
131
|
## Money Inputs
|
|
118
132
|
|
|
119
|
-
Because writing your own
|
|
133
|
+
Because writing your own dynamic mask expression for money inputs is fairly complex, Alpine offers a prebuilt one and makes it available as `$money()`.
|
|
120
134
|
|
|
121
135
|
Here is a fully functioning money input mask:
|
|
122
136
|
|
|
123
137
|
```alpine
|
|
124
|
-
<input x-mask:
|
|
138
|
+
<input x-mask:dynamic="$money($input)">
|
|
125
139
|
```
|
|
126
140
|
|
|
127
141
|
<!-- START_VERBATIM -->
|
|
128
142
|
<div class="demo" x-data>
|
|
129
|
-
<input type="text" x-mask:
|
|
143
|
+
<input type="text" x-mask:dynamic="$money($input)" placeholder="0.00">
|
|
130
144
|
</div>
|
|
131
145
|
<!-- END_VERBATIM -->
|
|
132
146
|
|
|
133
147
|
If you wish to swap the periods for commas and vice versa (as is required in certain currencies), you can do so using the second optional parameter:
|
|
134
148
|
|
|
135
149
|
```alpine
|
|
136
|
-
<input x-mask:
|
|
150
|
+
<input x-mask:dynamic="$money($input, ',')">
|
|
137
151
|
```
|
|
138
152
|
|
|
139
153
|
<!-- START_VERBATIM -->
|
|
140
154
|
<div class="demo" x-data>
|
|
141
|
-
<input type="text" x-mask:
|
|
155
|
+
<input type="text" x-mask:dynamic="$money($input, ',')" placeholder="0,00">
|
|
142
156
|
</div>
|
|
143
157
|
<!-- END_VERBATIM -->
|
package/src/en/plugins/morph.md
CHANGED
|
@@ -21,10 +21,10 @@ The best way to understand its purpose is with the following interactive visuali
|
|
|
21
21
|
|
|
22
22
|
<div class="flex w-full justify-between" style="padding-bottom: 1rem">
|
|
23
23
|
<div class="w-1/2 px-4">
|
|
24
|
-
<button @click="slide = (slide === 1) ? 13 : slide - 1" class="w-full bg-
|
|
24
|
+
<button @click="slide = (slide === 1) ? 13 : slide - 1" class="w-full bg-cyan-400 rounded-full text-center py-3 font-bold text-white">Previous</button>
|
|
25
25
|
</div>
|
|
26
26
|
<div class="w-1/2 px-4">
|
|
27
|
-
<button @click="slide = (slide % 13) + 1" class="w-full bg-
|
|
27
|
+
<button @click="slide = (slide % 13) + 1" class="w-full bg-cyan-400 rounded-full text-center py-3 font-bold text-white">Next</button>
|
|
28
28
|
</div>
|
|
29
29
|
</div>
|
|
30
30
|
</div>
|
|
@@ -82,8 +82,8 @@ Here's an example of using `Alpine.morph()` to update an Alpine component with n
|
|
|
82
82
|
|
|
83
83
|
```alpine
|
|
84
84
|
<div x-data="{ message: 'Change me, then press the button!' }">
|
|
85
|
-
<input type="text" x-model="message">
|
|
86
|
-
<span x-text="message"></span>
|
|
85
|
+
<input type="text" x-model="message">
|
|
86
|
+
<span x-text="message"></span>
|
|
87
87
|
</div>
|
|
88
88
|
|
|
89
89
|
<button>Run Morph</button>
|
|
@@ -95,9 +95,9 @@ Here's an example of using `Alpine.morph()` to update an Alpine component with n
|
|
|
95
95
|
Alpine.morph(el, `
|
|
96
96
|
<div x-data="{ message: 'Change me, then press the button!' }">
|
|
97
97
|
<h2>See how new elements have been added</h2>
|
|
98
|
-
|
|
99
|
-
<input type="text" x-model="message">
|
|
100
|
-
<span x-text="message"></span>
|
|
98
|
+
|
|
99
|
+
<input type="text" x-model="message">
|
|
100
|
+
<span x-text="message"></span>
|
|
101
101
|
|
|
102
102
|
<h2>but the state of this component hasn't changed? Magical.</h2>
|
|
103
103
|
</div>
|
|
@@ -110,9 +110,9 @@ Here's an example of using `Alpine.morph()` to update an Alpine component with n
|
|
|
110
110
|
<div class="demo">
|
|
111
111
|
<div x-data="{ message: 'Change me, then press the button!' }" id="morph-demo-1" class="space-y-2">
|
|
112
112
|
<input type="text" x-model="message" class="w-full">
|
|
113
|
-
<span x-text="message"></span>
|
|
113
|
+
<span x-text="message"></span>
|
|
114
114
|
</div>
|
|
115
|
-
|
|
115
|
+
|
|
116
116
|
<button id="morph-button-1" class="mt-4">Run Morph</button>
|
|
117
117
|
</div>
|
|
118
118
|
|
|
@@ -123,8 +123,8 @@ Here's an example of using `Alpine.morph()` to update an Alpine component with n
|
|
|
123
123
|
Alpine.morph(el, `
|
|
124
124
|
<div x-data="{ message: 'Change me, then press the button!' }" id="morph-demo-1" class="space-y-2">
|
|
125
125
|
<h4>See how new elements have been added</h4>
|
|
126
|
-
<input type="text" x-model="message" class="w-full">
|
|
127
|
-
<span x-text="message"></span>
|
|
126
|
+
<input type="text" x-model="message" class="w-full">
|
|
127
|
+
<span x-text="message"></span>
|
|
128
128
|
<h4>but the state of this component hasn't changed? Magical.</h4>
|
|
129
129
|
</div>
|
|
130
130
|
`)
|