{"name":"@solid-primitives/transition-group","version":"1.0.2","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":"./dist/index.cjs"},"peerDependencies":{"solid-js":"^1.6.12"},"devDependencies":{"@solidjs/router":"^0.8.2","@solid-primitives/refs":"^1.0.2","@solid-primitives/utils":"^6.1.0"},"typesVersions":{},"scripts":{"dev":"vite serve dev","page":"vite build dev","build":"jiti ../../scripts/build.ts","test":"vitest -c ../../configs/vitest.config.ts","test:ssr":"pnpm run test --mode ssr"},"_id":"@solid-primitives/transition-group@1.0.2","_integrity":"sha512-+o3J7TnU0/Sok+LKA0z0wvhim88dpd2eFBk8/05adE6wVypVlME8sKqTMO+xRv8HoT4Kq3sczmvwV07FKg2n+g==","_resolved":"/tmp/4c59007a69d903e038dae78edfe2a52a/solid-primitives-transition-group-1.0.2.tgz","_from":"file:solid-primitives-transition-group-1.0.2.tgz","_nodeVersion":"18.16.0","_npmVersion":"9.5.1","dist":{"integrity":"sha512-+o3J7TnU0/Sok+LKA0z0wvhim88dpd2eFBk8/05adE6wVypVlME8sKqTMO+xRv8HoT4Kq3sczmvwV07FKg2n+g==","shasum":"d16233f236c1450a980600d8e0870ef2651e2afc","tarball":"http://registry-npm.ywwl.com/@solid-primitives/transition-group/download/@solid-primitives/transition-group-1.0.2.tgz","fileCount":6,"unpackedSize":25241,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDeG1rklLdt4kwyBHVSatZsyoAJT6dQlgGs4Dd3CY8bJgIhALgv4yTUKYNCNgJspVvTdx5k//sciPEQBXD3mcxFBKeA"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJkQWqHACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqYDQ/5AJ3NNpYOcNAdOzqpdvdZxtZ6iNjN1ffFgyBRttM5egc52hnt\r\nSZYMhjEugcxaiiKucTuscjoXflxmuHndYKqRxKdBWi3A5Y12ImDqD5S4eVPI\r\nutdn7I+mrUPKUfCDPTrvVWVYw3ZTFTRIrBW9k7vMu4BgH8EpQLsqX4rasH3x\r\nshJxfVa2CNoOOT3ZFSLWq3c3u/mxjJmLsGNjOyjieTuemvO/6wKn8WNrbDPt\r\npYThG7PFhWEk+f731toModtxmVEnNwZnotYX9cpq6mxii93k7S/j5pIpt8u3\r\nbUMlk5mGfKW9xVjPFsdLUHZimzY87Sv33CCiz+Unbm1m7+7x82gEiyvB5uly\r\n4r3CtqG7zps0oUKVYgITcg3HjTiu3+xDWkBtgL4d7QcRFhxk/O9z37G9NXJN\r\noL4hL17TE0EUpWKqWyCfI9QPblRcQqkbneZwzCgI95uGKEthhqfe+i1F1Bx3\r\nCWHir6kSziUfj5v9n5C09JU9/nMAFYK0UPND/+otEA+4V78nvnIFQYfabQh0\r\nX3e8mBvmBqhTf6LSmsTA4W6XKSGGh6ZZ0MHoFcsGKWiY1Z8yNV4L1L9hFBBH\r\ntcaf/ZJxJnik2JzvEV3OQ4JBHJICUUFL/CSTp/eyaE4ZCYVSkhmKu1SLmvSu\r\nC4moJO7lo66CEsR2p5x7WH9f2nX9qrtfmhc=\r\n=kGf9\r\n-----END PGP SIGNATURE-----\r\n","size":5793,"noattachment":false,"key":"/@solid-primitives/transition-group/-/@solid-primitives/transition-group-1.0.2.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.2_1682008711374_0.226370569921301"},"_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":1682008711537,"_cnpm_publish_time":1682008711537,"dist-tags":{"beta":"0.0.1-beta.0","latest":"2.0.0","next":"2.0.0-next.4"}}