@fusion.dev/helix-docs 0.244.1 → 0.245.0

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.
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: The duration and easing tokens, and how components handle reduced motion.
2
+ description: The duration and easing tokens, how components handle reduced motion, and the functions that move your own elements.
3
3
  section: Foundations
4
4
  title: Motion
5
5
  ---
@@ -270,3 +270,140 @@ It names the way for the length of the move, changes the page at once under
270
270
  reduced motion or where the browser has no view transitions, and rejects
271
271
  where the change does. To keep a header still while the rest of the page
272
272
  moves, give it a `view-transition-name` of its own on every page.
273
+
274
+ ## Motion on your own elements
275
+
276
+ Four functions in `@fusion.dev/helix-core` give elements you write yourself
277
+ the motion Helix's own families have, with no component around them:
278
+
279
+ - `moveItems` slides the items of a list to their new places.
280
+ - `trackIndicator` sends one mark from item to item.
281
+ - `countTo` counts a figure to a new number.
282
+ - `followPointer` writes where a mouse or pen is over an element.
283
+
284
+ Each one works on any element, in any framework, and needs no Helix
285
+ stylesheet. Times and curves default to the tokens above, and to the values
286
+ those tokens hold where the page does not load them. Under reduced motion
287
+ nothing moves, the figure changes at once, and the pointer is not followed.
288
+ `moveItems`, `followPointer`, and `trackIndicator` return the way to stop.
289
+
290
+ ### Items that move
291
+
292
+ `moveItems` watches an element's children. When you or your framework add,
293
+ remove, reorder, or hide them, each item slides from its old place to its new
294
+ one, and an item you add fades in:
295
+
296
+ ```js
297
+ import { moveItems } from '@fusion.dev/helix-core'
298
+
299
+ const stop = moveItems(document.querySelector('#tasks'), {
300
+ leaving: document.querySelector('#tasks-box'),
301
+ })
302
+ ```
303
+
304
+ | Option | Default |
305
+ | --- | --- |
306
+ | `items`, a selector or a function returning the items | the element's children |
307
+ | `duration`, in milliseconds, as a time, or as a custom property | `--helix-duration-normal` |
308
+ | `easing`, a curve or a custom property | `--helix-easing-standard` |
309
+ | `leaving`, a positioned box around the element | none, so an item that leaves is gone at once |
310
+ | `arriveIntoEmpty`, so the first item into an empty list fades in | `false` |
311
+
312
+ A copy of an item that leaves fades out where it was, in the `leaving` box.
313
+ The copy never joins the element's own children, which your framework
314
+ manages, so give the box `position: relative` and put the list inside it.
315
+ When every item is new at once, as when a framework draws the whole list
316
+ again, the list appears without moving.
317
+
318
+ ### A mark that travels
319
+
320
+ `trackIndicator` places one mark on the item that is marked now, and places it
321
+ again whenever an attribute inside the element changes, an item arrives or
322
+ leaves, or the element changes size:
323
+
324
+ ```js
325
+ import { trackIndicator } from '@fusion.dev/helix-core'
326
+
327
+ trackIndicator(document.querySelector('nav'), {
328
+ active: '[aria-current="page"]',
329
+ indicator: document.querySelector('nav .mark'),
330
+ })
331
+ ```
332
+
333
+ It writes four custom properties on the mark: `--indicator-x`,
334
+ `--indicator-y`, `--indicator-inline-size`, and `--indicator-block-size`.
335
+ Your stylesheet moves the mark with them, so its transition is the move:
336
+
337
+ ```css
338
+ nav {
339
+ position: relative;
340
+ }
341
+
342
+ nav .mark {
343
+ block-size: var(--indicator-block-size, 0);
344
+ inline-size: var(--indicator-inline-size, 0);
345
+ inset-block-start: 0;
346
+ inset-inline-start: 0;
347
+ opacity: 0;
348
+ position: absolute;
349
+ transition:
350
+ translate var(--helix-duration-normal) var(--helix-easing-emphasized),
351
+ inline-size var(--helix-duration-normal) var(--helix-easing-emphasized),
352
+ opacity var(--helix-duration-fast);
353
+ translate: var(--indicator-x, 0) var(--indicator-y, 0);
354
+ }
355
+
356
+ nav .mark[data-placed] {
357
+ opacity: 1;
358
+ }
359
+ ```
360
+
361
+ `data-placed` is on the mark once it has a place, so it fades in where it
362
+ belongs. `data-moving` is on it while it travels. With nothing marked, the
363
+ mark loses `data-placed`. Call `place()` on what it returns after a change it
364
+ cannot see, such as a new stylesheet, and `stop()` to end it.
365
+
366
+ ### A figure that counts
367
+
368
+ `countTo` counts the number an element shows to a new one, and resolves once
369
+ the new figure is written:
370
+
371
+ ```js
372
+ import { countTo } from '@fusion.dev/helix-core'
373
+
374
+ await countTo(document.querySelector('#revenue'), 1284)
375
+ ```
376
+
377
+ It counts from the number last counted to, or from the number the element's
378
+ text reads. Pass `from` the first time for a figure written with grouping in
379
+ another language. The figure is written in the element's language, or with
380
+ `format`, which takes the number and returns its text. The count takes
381
+ `--helix-duration-slow` along `--helix-easing-decelerate`, and a new count
382
+ started during one carries on from the figure drawn.
383
+
384
+ The element's text changes on every frame, so keep it out of a live region and
385
+ tell screen reader users the new number another way.
386
+
387
+ ### Following the pointer
388
+
389
+ `followPointer` writes `--pointer-x` and `--pointer-y` on an element while a
390
+ mouse or pen is over it, each from -1 to 1, with 0 and 0 in the middle. A
391
+ right-to-left page mirrors `--pointer-x`. The two go when the pointer leaves,
392
+ so give them `0` as the fallback:
393
+
394
+ ```js
395
+ import { followPointer } from '@fusion.dev/helix-core'
396
+
397
+ followPointer(document.querySelector('.card'))
398
+ ```
399
+
400
+ ```css
401
+ .card {
402
+ rotate: x calc(var(--pointer-y, 0) * -6deg);
403
+ transition: rotate var(--helix-duration-normal) var(--helix-easing-standard);
404
+ }
405
+ ```
406
+
407
+ `data-following` is on the element while the two are written. A touch is not
408
+ followed, since a finger is on the element only while it presses. Pass `moved`
409
+ and `left` to hear the same positions in script.
@@ -138,7 +138,7 @@ export const docPages = [
138
138
  title: 'Metrics',
139
139
  },
140
140
  {
141
- description: 'The duration and easing tokens, and how components handle reduced motion.',
141
+ description: 'The duration and easing tokens, how components handle reduced motion, and the functions that move your own elements.',
142
142
  section: 'Foundations',
143
143
  slug: 'motion',
144
144
  title: 'Motion',