diff --git a/packages/docs/src/en/plugins/anchor.md b/packages/docs/src/en/plugins/anchor.md index 05cad10d1..b7c3b94c7 100644 --- a/packages/docs/src/en/plugins/anchor.md +++ b/packages/docs/src/en/plugins/anchor.md @@ -1,5 +1,5 @@ --- -order: 5 +order: 7 title: Anchor description: Anchor an element's positioning to another element on the page graph_image: https://alpinejs.dev/social_anchor.jpg diff --git a/packages/docs/src/en/plugins/collapse.md b/packages/docs/src/en/plugins/collapse.md index de9472f8c..063caec54 100644 --- a/packages/docs/src/en/plugins/collapse.md +++ b/packages/docs/src/en/plugins/collapse.md @@ -1,5 +1,5 @@ --- -order: 4 +order: 6 title: Collapse description: Collapse and expand elements with robust animations graph_image: https://alpinejs.dev/social_collapse.jpg diff --git a/packages/docs/src/en/plugins/focus.md b/packages/docs/src/en/plugins/focus.md index 57c9f92fc..90cc728d3 100644 --- a/packages/docs/src/en/plugins/focus.md +++ b/packages/docs/src/en/plugins/focus.md @@ -1,5 +1,5 @@ --- -order: 3 +order: 5 title: Focus description: Easily manage focus within the page graph_image: https://alpinejs.dev/social_focus.jpg diff --git a/packages/docs/src/en/plugins/morph.md b/packages/docs/src/en/plugins/morph.md index b8a8769af..cc60d4a79 100644 --- a/packages/docs/src/en/plugins/morph.md +++ b/packages/docs/src/en/plugins/morph.md @@ -1,5 +1,5 @@ --- -order: 6 +order: 8 title: Morph description: Morph an element into the provided HTML graph_image: https://alpinejs.dev/social_morph.jpg diff --git a/packages/docs/src/en/plugins/persist.md b/packages/docs/src/en/plugins/persist.md index f8850194c..4c6fb665a 100644 --- a/packages/docs/src/en/plugins/persist.md +++ b/packages/docs/src/en/plugins/persist.md @@ -1,5 +1,5 @@ --- -order: 2 +order: 4 title: Persist description: Easily persist data across page loads using localStorage graph_image: https://alpinejs.dev/social_persist.jpg diff --git a/packages/docs/src/en/plugins/resize.md b/packages/docs/src/en/plugins/resize.md new file mode 100644 index 000000000..cf9b27e6c --- /dev/null +++ b/packages/docs/src/en/plugins/resize.md @@ -0,0 +1,99 @@ +--- +order: 3 +title: Resize +description: An Alpine convenience wrapper for the Resize Observer API that allows you to easily react when an element is resized. +graph_image: https://alpinejs.dev/social_resize.jpg +--- + +# Resize Plugin + +Alpine's Resize plugin is a convenience wrapper for the [Resize Observer](https://developer.mozilla.org/en-US/docs/Web/API/Resize_Observer_API) that allows you to easily react when an element changes size. + +This is useful for: custom size-based animations, intelligent sticky positioning, conditionally adding attributes based on the element's size, etc. + + +## Installation + +You can use this plugin by either including it from a ` + + + +``` + +### Via NPM + +You can install Resize from NPM for use inside your bundle like so: + +```shell +npm install @alpinejs/resize +``` + +Then initialize it from your bundle: + +```js +import Alpine from 'alpinejs' +import resize from '@alpinejs/resize' + +Alpine.plugin(resize) + +... +``` + + +## x-resize + +The primary API for using this plugin is `x-resize`. You can add `x-resize` to any element within an Alpine component, and when that element is resized for any reason, the provided expression will execute with two magic properties: `$width` and `$height`. + +For example, here's a simple example of using `x-resize` do display the width and height of an element as it changes size. + +```alpine +
+

+

+
+``` + + +
+
+ Resize your browser window to see the width and height values change. +

+

+

+
+
+ + + +## Modifiers + + +### .document + +It's often useful to observer the entire document's size, rather than a specific element. To do this, you can add the `.document` modifier to `x-resize`: + +```alpine +
+``` + + +
+
+ Resize your browser window to see the document width and height values change. +

+

+

+
+
+ diff --git a/packages/docs/src/en/plugins/sort.md b/packages/docs/src/en/plugins/sort.md index 33ef2217a..3595c9173 100644 --- a/packages/docs/src/en/plugins/sort.md +++ b/packages/docs/src/en/plugins/sort.md @@ -1,5 +1,5 @@ --- -order: 6 +order: 9 title: Sort description: Easily re-order elements by dragging them with your mouse graph_image: https://alpinejs.dev/social_sort.jpg