@alpinejs/docs 3.10.1-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.10.1-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"
@@ -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.1/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.
@@ -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
- ## Custom Mask Functions
90
+ ## Dynamic Masks
91
91
 
92
- Sometimes simple mask literals (i.e. `(999) 999-9999`) are not sufficient. In these cases, `x-mask:function` allows you to dynamically generate masks on the fly based on user input.
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:function="
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 function as `$input`. Based on the `$input`, a different mask is utilized in the field.
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:function="
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 custom mask function for money inputs is fairly complex, Alpine offers a prebuilt one and makes it available as `$money()`.
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:function="$money($input)">
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:function="$money($input)" placeholder="0.00">
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:function="$money($input, ',')">
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:function="$money($input, ',')" placeholder="0.00">
155
+ <input type="text" x-mask:dynamic="$money($input, ',')" placeholder="0,00">
142
156
  </div>
143
157
  <!-- END_VERBATIM -->