{"name":"@solid-primitives/transition-group","version":"1.0.4","description":"Reactive primitives for implementing transition effects in SolidJS","author":{"name":"Damian Tarnawski","email":"gthetarnav@gmail.com"},"contributors":[],"license":"MIT","homepage":"https://github.com/solidjs-community/solid-primitives/tree/main/packages/transition-group#readme","repository":{"type":"git","url":"git+https://github.com/solidjs-community/solid-primitives.git"},"bugs":{"url":"https://github.com/solidjs-community/solid-primitives/issues"},"primitive":{"name":"transition-group","stage":2,"list":["createSwitchTransition","createListTransition"],"category":"Animation"},"keywords":["solid","primitives","transition","animation","transition-group"],"private":false,"sideEffects":false,"type":"module","main":"./dist/index.cjs","module":"./dist/index.js","browser":{},"types":"./dist/index.d.ts","exports":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}},"peerDependencies":{"solid-js":"^1.6.12"},"devDependencies":{"solid-js":"^1.8.7","@solid-primitives/refs":"^1.0.6","@solid-primitives/utils":"^6.2.2"},"typesVersions":{},"scripts":{"dev":"tsx ../../scripts/dev.ts","build":"tsx ../../scripts/build.ts","vitest":"vitest -c ../../configs/vitest.config.ts","test":"pnpm run vitest","test:ssr":"pnpm run vitest --mode ssr"},"_id":"@solid-primitives/transition-group@1.0.4","_integrity":"sha512-9nPg6HYAmEi7riH0C2bSCVw/2asgGSzHuN0yFFYyK9JgmXqJgyeyA+6thZbj7GgUQMRhtBxpH8yG7N2nEh8ttA==","_resolved":"/tmp/ae87790553622b09bafb2634ba5b4924/solid-primitives-transition-group-1.0.4.tgz","_from":"file:solid-primitives-transition-group-1.0.4.tgz","_nodeVersion":"18.19.0","_npmVersion":"10.2.3","dist":{"integrity":"sha512-9nPg6HYAmEi7riH0C2bSCVw/2asgGSzHuN0yFFYyK9JgmXqJgyeyA+6thZbj7GgUQMRhtBxpH8yG7N2nEh8ttA==","shasum":"cd0819504adf3f03ec3ef03627c25b44802b94a8","tarball":"http://registry-npm.ywwl.com/@solid-primitives/transition-group/download/@solid-primitives/transition-group-1.0.4.tgz","fileCount":8,"unpackedSize":35134,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD+8ktdMOiX8A1TlxHP8BX/Sd3VtPCRJJZnYCAYOcopzgIhAPFtCFzoAga62B3MzkGmC2zhbmA6+uSASgmRzUDF42ok"}],"size":6003,"noattachment":false,"key":"/@solid-primitives/transition-group/-/@solid-primitives/transition-group-1.0.4.tgz"},"_npmUser":{"name":"thetarnav.","email":"gthetarnav@gmail.com"},"directories":{},"maintainers":[{"name":"thetarnav.","email":"gthetarnav@gmail.com"},{"name":"lexlohr","email":"alex.th.kloss.77@googlemail.com"},{"name":"davedbase","email":"dave.dibiase@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/transition-group_1.0.4_1705395498407_0.29264244930866923"},"_hasShrinkwrap":false,"readme":"<p>\n  <img width=\"100%\" src=\"https://assets.solidjs.com/banner?type=Primitives&background=tiles&project=transition\" alt=\"Solid Primitives transition\">\n</p>\n\n# @solid-primitives/transition-group\n\n[![turborepo](https://img.shields.io/badge/built%20with-turborepo-cc00ff.svg?style=for-the-badge&logo=turborepo)](https://turborepo.org/)\n[![size](https://img.shields.io/bundlephobia/minzip/@solid-primitives/transition-group?style=for-the-badge&label=size)](https://bundlephobia.com/package/@solid-primitives/transition-group)\n[![version](https://img.shields.io/npm/v/@solid-primitives/transition-group?style=for-the-badge)](https://www.npmjs.com/package/@solid-primitives/transition-group)\n[![stage](https://img.shields.io/endpoint?style=for-the-badge&url=https%3A%2F%2Fraw.githubusercontent.com%2Fsolidjs-community%2Fsolid-primitives%2Fmain%2Fassets%2Fbadges%2Fstage-2.json)](https://github.com/solidjs-community/solid-primitives#contribution-process)\n\nProvides reactive primitives for implementing transition effects on a group of elements, or your own `<Transition>` and `<TransitionGroup>` components.\n\n- [`createSwitchTransition`](#createSwitchTransition) - Create an element transition interface for switching between single elements.\n- [`createListTransition`](#createListTransition) - Create an element list transition interface for changes to the list of elements.\n\n## Installation\n\n```bash\nnpm install @solid-primitives/transition-group\n# or\nyarn add @solid-primitives/transition-group\n# or\npnpm add @solid-primitives/transition-group\n```\n\n## `createSwitchTransition`\n\nCreate an element transition interface for switching between single elements.\nIt can be used to implement own transition effect, or a custom `<Transition>`-like component.\n\n### How to use it\n\nIt will observe the source and return a signal with array of elements to be rendered (current one and exiting ones).\n\n`createSwitchTransition` takes two parameters:\n\n- `source` a signal with the current element. Any nullish value will mean there is no element.\n  Any object can used as the source, but most likely you will want to use a `HTMLElement` or `SVGElement`.\n\n- `options` transition options:\n\n  - `onEnter` - a function to be called when a new element is entering. It receives the element and a callback to be called when the transition is done.\n\n  - `onExit` - a function to be called when an exiting element is leaving. It receives the element and a callback to be called when the transition is done.\n\n  - `mode` - transition mode. Defaults to `\"parallel\"`. Other options are `\"out-in\"` and `\"in-out\"`.\n\n  - `appear` - whether to run the transition on the initial element. Defaults to `false`.\n\n    If enabled, the initial element will still be included in the initial render (for SSR), but the transition fill happen when the first client-side effect is run. So to avoid the initial element to be visible, you can set the initial element's style to `display: none` and set it to `display: block` in the `onEnter` callback.\n\nReturns a signal with an array of the current element and exiting previous elements.\n\n```ts\nimport { createSwitchTransition } from \"@solid-primitives/transition-group\";\n\nconst [el, setEl] = createSignal<HTMLDivElement>();\n\nconst rendered = createSwitchTransition(el, {\n  onEnter(el, done) {\n    // the enter callback is called before the element is inserted into the DOM\n    // so run the animation in the next animation frame / microtask\n    queueMicrotask(() => {\n      /*...*/\n    });\n  },\n  onExit(el, done) {\n    // the exitting element is kept in the DOM until the done() callback is called\n  },\n});\n\n// change the source to trigger the transition\nsetEl(refToHtmlElement);\n```\n\n### Resolving JSX\n\nUsually the source will be a JSX element, and you will want to resolve it to a DOM element before passing it to `createSwitchTransition`. It leaves the resolving to you, so you can do it in any way you want.\n\nFor example, you can `children` helper from `solid-js`, to get the first found HTML element.\n\n```ts\nimport { children } from \"solid-js\";\nimport { createSwitchTransition } from \"@solid-primitives/transition-group\";\n\nconst resolved = children(() => props.children);\nconst filtered = createMemo(() => resolved.toArray().find(el => el instanceof HTMLElement));\nreturn createSwitchTransition(filtered, {\n  /*...*/\n});\n```\n\nOr use a `resolveFirst` helper from `@solid-primitives/refs`\n\n```ts\nimport { resolveFirst } from \"@solid-primitives/refs\";\nimport { createSwitchTransition } from \"@solid-primitives/transition-group\";\n\nconst resolved = resolveFirst(() => props.children);\nreturn createSwitchTransition(resolved, {\n  /*...*/\n});\n```\n\n## `createListTransition`\n\nCreate an element list transition interface for changes to the list of elements.\nIt can be used to implement own transition effect, or a custom `<TransitionGroup>`-like component.\n\n### How to use it\n\nIt will observe the source and return a signal with array of elements to be rendered (current ones and exiting ones).\n\n`createListTransition` takes two parameters:\n\n- `source` a signal with the current list of elements.\n  Any object can used as the element, but most likely you will want to use a `HTMLElement` or `SVGElement`.\n\n- `options` transition options:\n\n  - `onChange` - a function to be called when the list changes. It receives the list of added elements, removed elements, and moved elements. It also receives a callback to be called when the removed elements are finished animating (they can be removed from the DOM).\n\n  - `appear` - whether to run the transition on the initial elements. Defaults to `false`.\n\n  If enabled, the initial elements will still be included in the initial render (for SSR), but the transition fill happen when the first client-side effect is run. So to avoid the initial elements to be visible, you can set the initial element's style to `display: none` and set it to `display: block` in the `onChange` callback.\n\n  - `exitMethod` - This controls how the elements exit.\n\n    - `\"remove\"` removes the element immediately.\n    - `\"move-to-end\"` (default) will move elements which have exited to the end of the array.\n    - `\"keep-index\"` will splice them in at their previous index.\n\nReturns a signal with an array of the current elements and exiting previous elements.\n\n```ts\nimport { createListTransition } from \"@solid-primitives/transition-group\";\n\nconst [els, setEls] = createSignal<HTMLElement[]>([]);\n\nconst rendered = createListTransition(els, {\n  onChange({ list, added, removed, unchanged, finishRemoved }) {\n    // the callback is called before the added elements are inserted into the DOM\n    // so run the animation in the next animation frame / microtask\n    queueMicrotask(() => {\n      /*...*/\n    });\n\n    // the removed elements are kept in the DOM until the finishRemoved() callback is called\n    finishRemoved(removed);\n  },\n});\n\n// change the source to trigger the transition\nsetEls([...refsToHTMLElements]);\n```\n\n### Resolving JSX\n\nUsually the source will be a JSX Element, and you will want to resolve it to a list of DOM elements before passing it to `createListTransition`. It leaves the resolving to you, so you can do it in any way you want.\n\nFor example, you can `children` helper from `solid-js`, and filter out non-HTML elements:\n\n```ts\nimport { children } from \"solid-js\";\nimport { createListTransition } from \"@solid-primitives/transition-group\";\n\nconst resolved = children(() => props.children);\nconst filtered = createMemo(() => resolved.toArray().filter(el => el instanceof HTMLElement));\nreturn createListTransition(filtered, {\n  /*...*/\n});\n```\n\nOr use a `resolveElements` helper from `@solid-primitives/refs`\n\n```ts\nimport { resolveElements } from \"@solid-primitives/refs\";\nimport { createSwitchTransition } from \"@solid-primitives/transition-group\";\n\nconst resolved = resolveElements(() => props.children);\nreturn createListTransition(resolved.toArray, {\n  /*...*/\n});\n```\n\n## Demo\n\n[Deployed example](https://primitives.solidjs.community/playground/transition-group) | [Source code](https://github.com/solidjs-community/solid-primitives/tree/main/packages/transition-group/dev)\n\n## Usage references\n\nPackages that use `@solid-primitives/transition-group`:\n\n- [`solid-transition-group`](https://github.com/solidjs-community/solid-transition-group/tree/main/src)\n- [`motionone/solid`](https://github.com/motiondivision/motionone/tree/main/packages/solid/src)\n\n## Changelog\n\nSee [CHANGELOG.md](./CHANGELOG.md)\n","publish_time":1705395498568,"_cnpm_publish_time":1705395498568,"dist-tags":{"beta":"0.0.1-beta.0","latest":"2.0.0","next":"2.0.0-next.4"}}