@alpinejs/docs 3.8.0-revision.1 → 3.9.0-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.8.0-revision.1",
3
+ "version": "3.9.0-revision.1",
4
4
  "description": "The documentation for Alpine",
5
5
  "author": "Caleb Porzio",
6
6
  "license": "MIT"
@@ -157,9 +157,9 @@ And like most expressions in Alpine, you can always use the result of a JavaScri
157
157
  <a name="bind-directives"></a>
158
158
  ## Binding Alpine Directives Directly
159
159
 
160
- `x-bind` allows you to bind an object of different properties to an element.
160
+ `x-bind` allows you to bind an object of different directives and attributes to an element.
161
161
 
162
- The object keys are the directives (can be any directive including modifiers), and the values are 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 directoves, callbacks to be evaluated by Alpine.
163
163
 
164
164
  ```alpine
165
165
  <div x-data="dropdown()">
@@ -110,13 +110,13 @@ Occasionally, you want to create an Alpine component, but you don't need any dat
110
110
  In these cases, you can always pass in an empty object.
111
111
 
112
112
  ```alpine
113
- <div x-data="{}"...
113
+ <div x-data="{}">
114
114
  ```
115
115
 
116
116
  However, if you wish, you can also eliminate the attribute value entirely if it looks better to you.
117
117
 
118
118
  ```alpine
119
- <div x-data...
119
+ <div x-data>
120
120
  ```
121
121
 
122
122
  <a name="single-element-components"></a>
@@ -0,0 +1,37 @@
1
+ ---
2
+ order: 7
3
+ title: modelable
4
+ ---
5
+
6
+ # x-modelable
7
+
8
+ `x-modelable` allows you to expose any value by name as the target of the `x-model` directive.
9
+
10
+ Typically this feature would be used in conjunction with a backend templating framework like Laravel Blade. It's useful for abstracting away Alpine components into backend templates and exposing state to the outside through `x-model` as if it were a native input.
11
+
12
+ Here's a simple example of using `x-modelable` to expose a variable for binding with `x-model`.
13
+
14
+ ```alpine
15
+ <div x-data="{ number: 5 }">
16
+ <div x-data="{ count: 0 }" x-modelable="count" x-model="numberOfItems">
17
+ <button @click="count++">Increment</button>
18
+ </div>
19
+
20
+ Some Number: <span x-text="number"></span>
21
+ </div>
22
+ ```
23
+
24
+ <!-- START_VERBATIM -->
25
+ <div class="demo">
26
+ <div x-data="{ number: 5 }">
27
+ <div x-data="{ count: 0 }" x-modelable="count" x-model="numberOfItems">
28
+ <button @click="count++">Increment</button>
29
+ </div>
30
+
31
+ Number: <span x-text="number"></span>
32
+ </div>
33
+ </div>
34
+ <!-- END_VERBATIM -->
35
+
36
+ As you can see the outer scope property "number" is now bound to the inner scope property "count".
37
+
@@ -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.8.0/dist/cdn.min.js"></script>
36
+ <script defer src="https://unpkg.com/alpinejs@3.9.0/dist/cdn.min.js"></script>
37
37
  ```
38
38
 
39
39
  That's it! Alpine is now available for use inside your page.
@@ -0,0 +1,36 @@
1
+ ---
2
+ order: 3
3
+ title: bind()
4
+ ---
5
+
6
+ # Alpine.bind
7
+
8
+ `Alpine.bind(...)` provides a way to re-use [`x-bind`](/directives/bind#bind-directives) objects within your application.
9
+
10
+ Here's a simple example. Rather than binding attributes manually with Alpine:
11
+
12
+ ```alpine
13
+ <button type="button" @click="doSomething()" :disabled="shouldDisable"></button>
14
+ ```
15
+
16
+ You can bundle these attributes up into a reusable object and use `x-bind` to bind to that:
17
+
18
+ ```alpine
19
+ <button x-bind="SomeButton"></button>
20
+
21
+ <script>
22
+ document.addEventListener('alpine:init', () => {
23
+ Alpine.bind('SomeButton', () => ({
24
+ type: 'button',
25
+
26
+ '@click'() {
27
+ this.doSomething()
28
+ },
29
+
30
+ ':disabled'() {
31
+ return this.shouldDisable
32
+ },
33
+ }))
34
+ })
35
+ </script>
36
+ ```
@@ -3,7 +3,7 @@ order: 1
3
3
  title: data()
4
4
  ---
5
5
 
6
- # `Alpine.data`
6
+ # Alpine.data
7
7
 
8
8
  `Alpine.data(...)` provides a way to re-use `x-data` contexts within your application.
9
9
 
@@ -3,7 +3,7 @@ order: 2
3
3
  title: store()
4
4
  ---
5
5
 
6
- # `Alpine.store`
6
+ # Alpine.store
7
7
 
8
8
  Alpine offers global state management through the `Alpine.store()` API.
9
9
 
@@ -6,7 +6,7 @@ title: id
6
6
 
7
7
  # $id
8
8
 
9
- `$id` is a magic property that can be used to generate an element's ID and ensure that it is within on the page and won't conflict with other IDs of the same name.
9
+ `$id` is a magic property that can be used to generate an element's ID and ensure that it won't conflict with other IDs of the same name on the same page.
10
10
 
11
11
  This utility is extremely helpful when building re-usable components (presumably in a back-end template) that might occur multiple times on a page, and make use of ID attributes.
12
12
 
@@ -5,6 +5,8 @@ description: Easily manage focus within the page
5
5
  graph_image: https://alpinejs.dev/social_focus.jpg
6
6
  ---
7
7
 
8
+ > Notice: This Plugin was previously called "Trap". Trap's functionality has been absorbed into this plugin along with additional functionality. You can swap Trap for Focus without any breaking changes.
9
+
8
10
  # Focus Plugin
9
11
 
10
12
  Alpine's Focus plugin allows you to manage focus on a page.
@@ -252,6 +254,53 @@ For example:
252
254
  </div>
253
255
  <!-- END_VERBATIM -->
254
256
 
257
+ <a name="noreturn"></a>
258
+ #### .noreturn
259
+
260
+ Sometimes you may not want focus to be returned to where it was previously. Consider a dropdown that's triggered upon focusing an input, returning focus to the input on close will just trigger the dropdown to open again.
261
+
262
+ `x-trap` allows you to disable this behavior with the `.noreturn` modifier.
263
+
264
+ By adding `.noreturn`, Alpine will not return focus upon x-trap evaluating to false.
265
+
266
+ For example:
267
+
268
+ ```alpine
269
+ <div x-data="{ open: false }" x-trap.noreturn="open">
270
+ <input type="search" placeholder="search for something" />
271
+
272
+ <div x-show="open">
273
+ Search results
274
+
275
+ <button @click="open = false">Close</button>
276
+ </div>
277
+ </div>
278
+ ```
279
+
280
+ <!-- START_VERBATIM -->
281
+ <div class="demo">
282
+ <div
283
+ x-data="{ open: false }"
284
+ x-trap.noreturn="open"
285
+ @click.outside="open = false"
286
+ @keyup.escape.prevent.stop="open = false"
287
+ >
288
+ <input type="search" placeholder="search for something"
289
+ @focus="open = true"
290
+ @keyup.escape.prevent="$el.blur()"
291
+ />
292
+
293
+ <div x-show="open">
294
+ <div class="mb-4 text-bold">Search results</div>
295
+
296
+ <p class="mb-4 text-gray-600 text-sm">Notice when closing this dropdown, focus is not returned to the input.</p>
297
+
298
+ <button class="mt-4" @click="open = false">Close Dialog</button>
299
+ </div>
300
+ </div>
301
+ </div>
302
+ <!-- END_VERBATIM -->
303
+
255
304
  <a name="focus-magic"></a>
256
305
  ## $focus
257
306
 
@@ -78,16 +78,18 @@ For example, in the following snippet, `shown` will remain `false` until the ele
78
78
  <a name="x-intersect-enter"></a>
79
79
  ### x-intersect:enter
80
80
 
81
- You can opt to only trigger x-intersect when the element ENTERS the viewport by adding the `:enter` suffix to `x-intersect` like so:
81
+ The `:enter` suffix is an alias of `x-intersect`, and works the same way:
82
82
 
83
83
  ```alpine
84
84
  <div x-intersect:enter="shown = true">...</div>
85
85
  ```
86
86
 
87
+ You may choose to use this for clarity when also using the `:leave` suffix.
88
+
87
89
  <a name="x-intersect-leave"></a>
88
90
  ### x-intersect:leave
89
91
 
90
- Similarly, you can add `:leave` to only trigger x-intersect when the element LEAVES the viewport:
92
+ Appending `:leave` runs your expression when the element leaves the viewport:
91
93
 
92
94
  ```alpine
93
95
  <div x-intersect:leave="shown = true">...</div>
@@ -126,3 +128,25 @@ Useful for elements where it's important to show the whole element.
126
128
  ```alpine
127
129
  <div x-intersect.full="shown = true">...</div> // when `0.99` of the element is in the viewport
128
130
  ```
131
+
132
+ <a name="margin"></a>
133
+ ### .margin
134
+
135
+ Allows you to control the `rootMargin` property of the underlying `IntersectionObserver`.
136
+ This effectively tweaks the size of the viewport boundary. Positive values
137
+ expand the boundary beyond the viewport, and negative values shrink it inward. The values
138
+ work like CSS margin: one value for all sides, two values for top/bottom, left/right, or
139
+ four values for top, right, bottom, left. You can use `px` and `%` values, or use a bare number to
140
+ get a pixel value.
141
+
142
+ ```alpine
143
+ <div x-intersect.margin.200px="loaded = true">...</div> // Load when the element is within 200px of the viewport
144
+ ```
145
+
146
+ ```alpine
147
+ <div x-intersect:leave.margin.10%.25px.25.25px="loaded = false">...</div> // Unload when the element gets within 10% of the top of the viewport, or within 25px of the other three edges
148
+ ```
149
+
150
+ ```alpine
151
+ <div x-intersect.margin.-100px="visible = true">...</div> // Mark as visible when element is more than 100 pixels into the viewport.
152
+ ```
@@ -158,7 +158,7 @@ Here are the available lifecycle hooks (passed in as the third parameter to `Alp
158
158
  | `updated(el, toEl)` | Called after Morph has patched `el`. |
159
159
  | `removing(el, skip)` | Called before Morph removes an element from the live DOM. |
160
160
  | `removed(el)` | Called after Morph has removed an element from the live DOM. |
161
- | `adding(el, sip)` | Called before adding a new element. |
161
+ | `adding(el, skip)` | Called before adding a new element. |
162
162
  | `added(el)` | Called after adding a new element to the live DOM tree. |
163
163
  | `key(el)` | A re-usable function to determine how Morph "keys" elements in the tree before comparing/patching. [More on that here](#keys) |
164
164
  | `lookahead` | A boolean value telling Morph to enable an extra feature in its algorithm that "looks ahead" to make sure a DOM element that's about to be removed should instead just be "moved" to a later sibling. |