@alpinejs/docs 3.9.6-revision.1 → 3.10.2-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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alpinejs/docs",
3
- "version": "3.9.6-revision.1",
3
+ "version": "3.10.2-revision.1",
4
4
  "description": "The documentation for Alpine",
5
5
  "author": "Caleb Porzio",
6
6
  "license": "MIT"
@@ -159,7 +159,7 @@ And like most expressions in Alpine, you can always use the result of a JavaScri
159
159
 
160
160
  `x-bind` allows you to bind an object of different directives and attributes to an element.
161
161
 
162
- The object keys can be anything you would normally write as an attribute name in Alpine. This includes Alpine directives and modifiers, but also plain HTML attributes. The object values are either plain strings, or in the case of dynamic Alpine directoves, callbacks to be evaluated by Alpine.
162
+ The object keys can be anything you would normally write as an attribute name in Alpine. This includes Alpine directives and modifiers, but also plain HTML attributes. The object values are either plain strings, or in the case of dynamic Alpine directives, callbacks to be evaluated by Alpine.
163
163
 
164
164
  ```alpine
165
165
  <div x-data="dropdown()">
@@ -174,6 +174,7 @@ The object keys can be anything you would normally write as an attribute name in
174
174
  open: false,
175
175
 
176
176
  trigger: {
177
+ ['x-ref']: 'trigger',
177
178
  ['@click']() {
178
179
  this.open = true
179
180
  },
@@ -33,7 +33,7 @@ There are two rules worth noting about `x-for`:
33
33
  <a name="keys"></a>
34
34
  ## Keys
35
35
 
36
- It is important to specify keys for each `x-for` iteration if you are going to be re-ordering items. Without dynamic keys, Alpine may have a hard time keeping track of what re-orders and will cause odd side-effects.
36
+ It is important to specify unique keys for each `x-for` iteration if you are going to be re-ordering items. Without dynamic keys, Alpine may have a hard time keeping track of what re-orders and will cause odd side-effects.
37
37
 
38
38
  ```alpine
39
39
  <ul x-data="{ colors: [
@@ -288,7 +288,7 @@ Color: <span x-text="color"></span>
288
288
  <a name="lazy"></a>
289
289
  ### `.lazy`
290
290
 
291
- On text inputs, by default, `x-model` updates the property on every key-stroke. By adding the `.lazy` modifier, you can force an `x-model` input to only update the property when user focuses away from the input element.
291
+ On text inputs, by default, `x-model` updates the property on every keystroke. By adding the `.lazy` modifier, you can force an `x-model` input to only update the property when user focuses away from the input element.
292
292
 
293
293
  This is handy for things like real-time form-validation where you might not want to show an input validation error until the user "tabs" away from a field.
294
294
 
@@ -89,6 +89,7 @@ For easy reference, here is a list of common keys you may want to listen for.
89
89
  | `.caps-lock` | Caps Lock |
90
90
  | `.equal` | Equal, `=` |
91
91
  | `.period` | Period, `.` |
92
+ | `.slash` | Foward Slash, `/` |
92
93
 
93
94
  <a name="custom-events"></a>
94
95
  ## Custom events
@@ -165,7 +166,7 @@ In the above example, clicking the button WON'T log the message. This is because
165
166
 
166
167
  In the above example, after showing the dropdown contents by clicking the "Toggle" button, you can close the dropdown by clicking anywhere on the page outside the content.
167
168
 
168
- This is because `.outside` is listening for clicks that DONT originate from the element it's registered on.
169
+ This is because `.outside` is listening for clicks that DON'T originate from the element it's registered on.
169
170
 
170
171
  > It's worth noting that the `.outside` expression will only be evaluated when the element it's registered on is visible on the page. Otherwise, there would be nasty race conditions where clicking the "Toggle" button would also fire the `@click.outside` handler when it is not visible.
171
172
 
@@ -101,7 +101,7 @@ To make this experience more seamless, you can "forward" events by simply regist
101
101
 
102
102
  Notice how we are now able to listen for events dispatched from within the teleported element from outside the `<template>` element itself?
103
103
 
104
- Alpine does this by looking for event listeners registered on `<template x-teleport...>` and stops those events from propogating past the live, teleported, DOM element. Then, it creates a copy of that event and re-dispatches it from `<template x-teleport...>`.
104
+ Alpine does this by looking for event listeners registered on `<template x-teleport...>` and stops those events from propagating past the live, teleported, DOM element. Then, it creates a copy of that event and re-dispatches it from `<template x-teleport...>`.
105
105
 
106
106
  <a name="nesting"></a>
107
107
  ## Nesting
@@ -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.9.6/dist/cdn.min.js"></script>
36
+ <script defer src="https://unpkg.com/alpinejs@3.10.2/dist/cdn.min.js"></script>
37
37
  ```
38
38
 
39
39
  That's it! Alpine is now available for use inside your page.
@@ -54,7 +54,7 @@ Although this may seem obvious to some, it's worth mentioning that Alpine data c
54
54
  <a name="data-less-alpine"></a>
55
55
  ### Data-less Alpine
56
56
 
57
- Sometimes you may want to use Alpine functionality, but don't need any reactive data. In these cases, you can opt-out of passing an expression to `x-data` entirely. For example:
57
+ Sometimes you may want to use Alpine functionality, but don't need any reactive data. In these cases, you can opt out of passing an expression to `x-data` entirely. For example:
58
58
 
59
59
  ```alpine
60
60
  <button x-data @click="alert('I\'ve been clicked!')">Click Me</button>
@@ -34,7 +34,7 @@ Now let's say you want to have those same two input elements, but this time you
34
34
 
35
35
  This presents a problem, you now need to be able to reference the same ID twice. One for the `<label>`'s `for` attribute, and the other for the `id` on the input.
36
36
 
37
- Here's is a way that you might think to accomplish this and is totally valid:
37
+ Here is a way that you might think to accomplish this and is totally valid:
38
38
 
39
39
  ```alpine
40
40
  <div x-data="{ id: $id('text-input') }">
@@ -21,3 +21,22 @@ title: nextTick
21
21
  ```
22
22
 
23
23
  In the above example, rather than logging "Hello" to the console, "Hello World!" will be logged because `$nextTick` was used to wait until Alpine was finished updating the DOM.
24
+
25
+ <a name="promises"></a>
26
+
27
+ ## Promises
28
+
29
+ `$nextTick` returns a promise, allowing the use of `$nextTick` to pause an async function until after pending dom updates. When used like this, `$nextTick` also does not require an argument to be passed.
30
+
31
+ ```alpine
32
+ <div x-data="{ title: 'Hello' }">
33
+ <button
34
+ @click="
35
+ title = 'Hello World!';
36
+ await $nextTick();
37
+ console.log($el.innerText);
38
+ "
39
+ x-text="title"
40
+ ></button>
41
+ </div>
42
+ ```
@@ -187,7 +187,7 @@ Here is nesting in action:
187
187
  <a name="inert"></a>
188
188
  #### .inert
189
189
 
190
- When building things like dialogs/modals, it's recommended to hide all the other elements on the page from screenreaders when trapping focus.
190
+ When building things like dialogs/modals, it's recommended to hide all the other elements on the page from screen readers when trapping focus.
191
191
 
192
192
  By adding `.inert` to `x-trap`, when focus is trapped, all other elements on the page will receive `aria-hidden="true"` attributes, and when focus trapping is disabled, those attributes will also be removed.
193
193
 
@@ -218,7 +218,7 @@ By adding `.inert` to `x-trap`, when focus is trapped, all other elements on the
218
218
  <a name="noscroll"></a>
219
219
  #### .noscroll
220
220
 
221
- When building dialogs/modals with Alpine, it's recommended that you disable scrollling for the surrounding content when the dialog is open.
221
+ When building dialogs/modals with Alpine, it's recommended that you disable scrolling for the surrounding content when the dialog is open.
222
222
 
223
223
  `x-trap` allows you to do this automatically with the `.noscroll` modifiers.
224
224
 
@@ -1,5 +1,5 @@
1
1
  ---
2
- order: 1
2
+ order: 2
3
3
  title: Intersect
4
4
  description: An Alpine convenience wrapper for Intersection Observer that allows you to easily react when an element enters the viewport.
5
5
  graph_image: https://alpinejs.dev/social_intersect.jpg
@@ -0,0 +1,157 @@
1
+ ---
2
+ order: 1
3
+ title: Mask
4
+ description: Automatically format text fields as users type
5
+ graph_image: https://alpinejs.dev/social_mask.jpg
6
+ ---
7
+
8
+ # Mask Plugin
9
+
10
+ Alpine's Mask plugin allows you to automatically format a text input field as a user types.
11
+
12
+ This is useful for many different types of inputs: phone numbers, credit cards, dollar amounts, account numbers, dates, etc.
13
+
14
+ <a name="installation"></a>
15
+ ## Installation
16
+
17
+ <div x-data="{ expanded: false }">
18
+ <div class=" relative">
19
+ <div x-show="! expanded" class="absolute inset-0 flex justify-start items-end bg-gradient-to-t from-white to-[#ffffff66]"></div>
20
+ <div x-show="expanded" x-collapse.min.80px class="markdown">
21
+
22
+ You can use this plugin by either including it from a `<script>` tag or installing it via NPM:
23
+
24
+ ### Via CDN
25
+
26
+ You can include the CDN build of this plugin as a `<script>` tag, just make sure to include it BEFORE Alpine's core JS file.
27
+
28
+ ```alpine
29
+ <!-- Alpine Plugins -->
30
+ <script defer src="https://unpkg.com/@alpinejs/mask@3.x.x/dist/cdn.min.js"></script>
31
+
32
+ <!-- Alpine Core -->
33
+ <script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
34
+ ```
35
+
36
+ ### Via NPM
37
+
38
+ You can install Mask from NPM for use inside your bundle like so:
39
+
40
+ ```shell
41
+ npm install @alpinejs/mask
42
+ ```
43
+
44
+ Then initialize it from your bundle:
45
+
46
+ ```js
47
+ import Alpine from 'alpinejs'
48
+ import mask from '@alpinejs/mask'
49
+
50
+ Alpine.plugin(mask)
51
+
52
+ ...
53
+ ```
54
+
55
+ </div>
56
+ </div>
57
+ <button :aria-expanded="expanded" @click="expanded = ! expanded" class="text-aqua-600 font-medium underline">
58
+ <span x-text="expanded ? 'Hide' : 'Show more'">Show</span> <span x-text="expanded ? '↑' : '↓'">↓</span>
59
+ </button>
60
+ </div>
61
+
62
+ <a name="x-mask"></a>
63
+ ## x-mask
64
+
65
+ The primary API for using this plugin is the `x-mask` directive.
66
+
67
+ Let's start by looking at the following simple example of a date field:
68
+
69
+ ```alpine
70
+ <input x-mask="99/99/9999" placeholder="MM/DD/YYYY">
71
+ ```
72
+
73
+ <!-- START_VERBATIM -->
74
+ <div class="demo">
75
+ <input x-data x-mask="99/99/9999" placeholder="MM/DD/YYYY">
76
+ </div>
77
+ <!-- END_VERBATIM -->
78
+
79
+ Notice how the text you type into the input field must adhere to the format provided by `x-mask`. In addition to enforcing numeric characters, the forward slashes `/` are also automatically added if a user doesn't type them first.
80
+
81
+ The following wildcard characters are supported in masks:
82
+
83
+ | Wildcard | Description |
84
+ | -------------------------- | --------------------------- |
85
+ | `*` | Any character |
86
+ | `a` | Only alpha characters (a-z, A-Z) |
87
+ | `9` | Only numeric characters (0-9) |
88
+
89
+ <a name="mask-functions"></a>
90
+ ## Dynamic Masks
91
+
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
+
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
+
96
+ ```alpine
97
+ <input x-mask:dynamic="
98
+ $input.startsWith('34') || $input.startsWith('37')
99
+ ? '9999 999999 99999' : '9999 9999 9999 9999'
100
+ ">
101
+ ```
102
+
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
+
105
+ Try it for yourself by typing a number that starts with "34" and one that doesn't.
106
+
107
+ <!-- START_VERBATIM -->
108
+ <div class="demo">
109
+ <input x-data x-mask:dynamic="
110
+ $input.startsWith('34') || $input.startsWith('37')
111
+ ? '9999 999999 99999' : '9999 9999 9999 9999'
112
+ ">
113
+ </div>
114
+ <!-- END_VERBATIM -->
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
+
130
+ <a name="money-inputs"></a>
131
+ ## Money Inputs
132
+
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()`.
134
+
135
+ Here is a fully functioning money input mask:
136
+
137
+ ```alpine
138
+ <input x-mask:dynamic="$money($input)">
139
+ ```
140
+
141
+ <!-- START_VERBATIM -->
142
+ <div class="demo" x-data>
143
+ <input type="text" x-mask:dynamic="$money($input)" placeholder="0.00">
144
+ </div>
145
+ <!-- END_VERBATIM -->
146
+
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:
148
+
149
+ ```alpine
150
+ <input x-mask:dynamic="$money($input, ',')">
151
+ ```
152
+
153
+ <!-- START_VERBATIM -->
154
+ <div class="demo" x-data>
155
+ <input type="text" x-mask:dynamic="$money($input, ',')" placeholder="0,00">
156
+ </div>
157
+ <!-- END_VERBATIM -->
@@ -137,7 +137,7 @@ Here's an example of using `Alpine.morph()` to update an Alpine component with n
137
137
 
138
138
  The "Morph" plugin works by comparing two DOM trees, the live element, and the passed in HTML.
139
139
 
140
- Morph walks both trees simultaneusly and compares each node and its children. If it finds differences, it "patches" (changes) the current DOM tree to match the passed in HTML's tree.
140
+ Morph walks both trees simultaneously and compares each node and its children. If it finds differences, it "patches" (changes) the current DOM tree to match the passed in HTML's tree.
141
141
 
142
142
  While the default algorithm is very capable, there are cases where you may want to hook into its lifecycle and observe or change its behavior as it's happening.
143
143
 
@@ -249,4 +249,4 @@ By adding keys to each node, we can accomplish this like so:
249
249
 
250
250
  Now that there are "keys" on the `<li>`s, Morph will match them in both trees and move them accordingly.
251
251
 
252
- You can configure what Morph considers a "key" with the `key:` configutation option. [More on that here](#lifecycle-hooks)
252
+ You can configure what Morph considers a "key" with the `key:` configuration option. [More on that here](#lifecycle-hooks)
@@ -299,7 +299,7 @@ In Alpine V2 for below code
299
299
  </div>
300
300
  ```
301
301
 
302
- after clicking button all `$refs` were displayed. However in Alpine V3 it's possible to access only `$refs` for elements created statically, so only first ref will be returned as expected.
302
+ after clicking button all `$refs` were displayed. However, in Alpine V3 it's possible to access only `$refs` for elements created statically, so only first ref will be returned as expected.
303
303
 
304
304
 
305
305
  <a name="no-ie-11"></a>