svelte5-collapsible 1.0.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Nevo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # svelte5-collapsible
2
+
3
+ Rewrite of [svelte-collapsible](https://github.com/rsdavis/svelte-collapsible/) to support svelte5 syntax.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install svelte5-collapse
9
+ ```
10
+
11
+ ## Demos
12
+
13
+ ## Components
14
+
15
+ ### CollapsibleCard
16
+
17
+ Standalone collapsible card with transitions.
18
+
19
+ ```svelte
20
+ <script>
21
+ import { CollapsibleCard } from 'svelte5-collapse';
22
+ import { fade } from 'svelte/transition';
23
+ </script>
24
+
25
+ <CollapsibleCard transition={{ transition: fade }}>
26
+ {#snippet header()}
27
+ <div>Card Header</div>
28
+ {/snippet}
29
+ {#snippet body()}
30
+ <div>Card content here</div>
31
+ {/snippet}
32
+ </CollapsibleCard>
33
+ ```
34
+
35
+ ### Accordion
36
+
37
+ Collection where only one item is open at a time.
38
+
39
+ ```svelte
40
+ <script>
41
+ import { Accordion, AccordionItem } from 'svelte5-collapse';
42
+ </script>
43
+
44
+
45
+ <Accordion>
46
+ {#snippet item1(key)}
47
+ <AccordionItem {key} transition={accordionParams}>
48
+ {#snippet header()}
49
+ <div>First Item</div>
50
+ {/snippet}
51
+ {#snippet body()}
52
+ <div>Hello from first item</div>
53
+ {/snippet}
54
+ </AccordionItem>
55
+ {/snippet}
56
+ {#snippet item2(key)}
57
+ <AccordionItem {key} transition={accordionParams}>
58
+ {#snippet header()}
59
+ <div>Second Item</div>
60
+ {/snippet}
61
+ {#snippet body()}
62
+ <div>Hello from second item</div>
63
+ {/snippet}
64
+ </AccordionItem>
65
+ {/snippet}
66
+ </Accordion>
67
+ ```
68
+
69
+ ## Api
70
+
71
+ **CollapsibleCard:**
72
+ - `transition`: `TransitionParams`
73
+ - `transitionIn?`: `TransitionParams`
74
+ - `transitionOut?`: `TransitionParams`
75
+ - `isOpen?`: boolean (default: false)
76
+ - `header`: Snippet
77
+ - `body`: Snippet
78
+
79
+ **Accordion**
80
+ - `itemN`: Snippet function (e.g., `item1`, `item2`, etc.)
81
+ > Support for changing the item name will come soon™
82
+
83
+ **AccordionItem:**
84
+ - `transition`: `TransitionParams`
85
+ - `transitionIn?`: `TransitionParams`
86
+ - `transitionOut?`: `TransitionParams`
87
+ - `header`: Snippet
88
+ - `body`: Snippet
89
+
90
+ **TransitionParams:**
91
+ - `transition`: Transition type (svelte/transition)
92
+ - `easing`: EasingFunction (svelte/transition)
93
+ - `duration`: Duration of the animation in ms
94
+ - `delay`: Time before the animation starts in ms
95
+
@@ -0,0 +1,32 @@
1
+ <script lang="ts">
2
+ import { setContext, type Snippet } from "svelte";
3
+ import { SvelteMap } from "svelte/reactivity";
4
+
5
+ export type AccordionProps = {
6
+ [key: string]: Snippet<[string]>;
7
+ };
8
+
9
+ let props: AccordionProps = $props();
10
+
11
+ let itemsNames = Object.keys(props).filter((key) => {
12
+ const pattern = new RegExp(`^item\\d+$`);
13
+ return pattern.test(key);
14
+ });
15
+
16
+ let elements: Array<Snippet<[string]>> = itemsNames.map(
17
+ (key: string) => props[key],
18
+ );
19
+
20
+ let accordionMap = new SvelteMap<string, boolean>();
21
+ itemsNames.forEach((x) => {
22
+ accordionMap.set(x, false);
23
+ });
24
+
25
+ setContext("accordion", accordionMap);
26
+ </script>
27
+
28
+ <div class="accordion">
29
+ {#each elements as element, idx}
30
+ {@render element(itemsNames[idx])}
31
+ {/each}
32
+ </div>
@@ -0,0 +1,7 @@
1
+ import { type Snippet } from "svelte";
2
+ export type AccordionProps = {
3
+ [key: string]: Snippet<[string]>;
4
+ };
5
+ declare const Accordion: import("svelte").Component<AccordionProps, {}, "">;
6
+ type Accordion = ReturnType<typeof Accordion>;
7
+ export default Accordion;
@@ -0,0 +1,58 @@
1
+ <script lang="ts">
2
+ import { getContext, type Snippet } from "svelte";
3
+ import type { TransitionParams } from "./TransitionParams.d.js";
4
+ import type { SvelteMap } from "svelte/reactivity";
5
+
6
+ let {
7
+ transition,
8
+ transitionIn = transition,
9
+ transitionOut = transition,
10
+ key,
11
+ header,
12
+ body,
13
+ }: {
14
+ transition: TransitionParams;
15
+ transitionIn?: TransitionParams;
16
+ transitionOut?: TransitionParams;
17
+ key: string;
18
+ header: Snippet;
19
+ body: Snippet;
20
+ } = $props();
21
+
22
+ const store: SvelteMap<string, boolean> = getContext("accordion");
23
+ function handleToggle(): void {
24
+ store.forEach((_, k) => {
25
+ if (k != key) {
26
+ store.set(k, false);
27
+ }
28
+ });
29
+ store.set(key, !store.get(key));
30
+ }
31
+ </script>
32
+
33
+ <li>
34
+ <div
35
+ role="button"
36
+ onkeydown={handleToggle}
37
+ tabindex="0"
38
+ onclick={handleToggle}
39
+ >
40
+ {@render header()}
41
+ </div>
42
+ {#if store.get(key)}
43
+ <div
44
+ in:transitionIn.transition={{
45
+ delay: transitionIn.delay,
46
+ duration: transitionIn.duration,
47
+ easing: transitionIn.easing,
48
+ }}
49
+ out:transitionOut.transition={{
50
+ delay: transitionOut.delay,
51
+ duration: transitionOut.duration,
52
+ easing: transitionOut.easing,
53
+ }}
54
+ >
55
+ {@render body()}
56
+ </div>
57
+ {/if}
58
+ </li>
@@ -0,0 +1,13 @@
1
+ import { type Snippet } from "svelte";
2
+ import type { TransitionParams } from "./TransitionParams.d.ts";
3
+ type $$ComponentProps = {
4
+ transition: TransitionParams;
5
+ transitionIn?: TransitionParams;
6
+ transitionOut?: TransitionParams;
7
+ key: string;
8
+ header: Snippet;
9
+ body: Snippet;
10
+ };
11
+ declare const AccordionItem: import("svelte").Component<$$ComponentProps, {}, "">;
12
+ type AccordionItem = ReturnType<typeof AccordionItem>;
13
+ export default AccordionItem;
@@ -0,0 +1,47 @@
1
+ <script lang="ts">
2
+ import type { Snippet } from "svelte";
3
+ import type { TransitionParams } from "./TransitionParams.d.js";
4
+ let {
5
+ transition,
6
+ transitionIn = transition,
7
+ transitionOut = transition,
8
+ isOpen,
9
+ header,
10
+ body,
11
+ }: {
12
+ transition: TransitionParams;
13
+ transitionIn?: TransitionParams;
14
+ transitionOut?: TransitionParams;
15
+ isOpen?: boolean;
16
+ header: Snippet;
17
+ body: Snippet;
18
+ } = $props();
19
+
20
+ function handleToggle(): void {
21
+ isOpen = !isOpen;
22
+ }
23
+ </script>
24
+
25
+ <div>
26
+ <button type="button" class="card-header" onclick={handleToggle}>
27
+ {@render header()}
28
+ </button>
29
+
30
+ {#if isOpen}
31
+ <div
32
+ class="card-body"
33
+ in:transitionIn.transition={{
34
+ delay: transitionIn.delay,
35
+ duration: transitionIn.duration,
36
+ easing: transitionIn.easing,
37
+ }}
38
+ out:transitionOut.transition={{
39
+ delay: transitionOut.delay,
40
+ duration: transitionOut.duration,
41
+ easing: transitionOut.easing,
42
+ }}
43
+ >
44
+ {@render body()}
45
+ </div>
46
+ {/if}
47
+ </div>
@@ -0,0 +1,13 @@
1
+ import type { Snippet } from "svelte";
2
+ import type { TransitionParams } from "./TransitionParams.d.ts";
3
+ type $$ComponentProps = {
4
+ transition: TransitionParams;
5
+ transitionIn?: TransitionParams;
6
+ transitionOut?: TransitionParams;
7
+ isOpen?: boolean;
8
+ header: Snippet;
9
+ body: Snippet;
10
+ };
11
+ declare const CollapsibleCard: import("svelte").Component<$$ComponentProps, {}, "">;
12
+ type CollapsibleCard = ReturnType<typeof CollapsibleCard>;
13
+ export default CollapsibleCard;
@@ -0,0 +1,8 @@
1
+ import type { EasingFunction, TransitionConfig } from "svelte/transition";
2
+
3
+ export interface TransitionParams {
4
+ transition: (node: Element, params?: any) => TransitionConfig;
5
+ easing?: EasingFunction;
6
+ duration?: number;
7
+ delay?: number;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ // Reexport your entry components here
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "svelte5-collapsible",
3
+ "version": "1.0.2",
4
+ "description": "Rewrite of svelte-collapsible to use svelte5 syntax",
5
+ "scripts": {
6
+ "dev": "vite dev",
7
+ "build": "vite build && npm run prepack",
8
+ "preview": "vite preview",
9
+ "prepare": "svelte-kit sync || echo ''",
10
+ "prepack": "svelte-kit sync && svelte-package && publint",
11
+ "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
12
+ "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "!dist/**/*.test.*",
17
+ "!dist/**/*.spec.*"
18
+ ],
19
+ "sideEffects": [
20
+ "**/*.css"
21
+ ],
22
+ "svelte": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "type": "module",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "svelte": "./dist/index.js"
29
+ }
30
+ },
31
+ "peerDependencies": {
32
+ "svelte": "^5.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "@sveltejs/adapter-auto": "^7.0.0",
36
+ "@sveltejs/kit": "^2.49.1",
37
+ "@sveltejs/package": "^2.5.7",
38
+ "@sveltejs/vite-plugin-svelte": "^6.2.1",
39
+ "publint": "^0.3.15",
40
+ "svelte": "^5.45.6",
41
+ "svelte-check": "^4.3.4",
42
+ "typescript": "^5.9.3",
43
+ "vite": "^7.2.6"
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "https://github.com/NotArceuid/svelte5-collapsible",
48
+ "directory": "/"
49
+ },
50
+ "keywords": [
51
+ "svelte5",
52
+ "typescript",
53
+ "accordion",
54
+ "card",
55
+ "svelte",
56
+ "expand",
57
+ "component"
58
+ ]
59
+ }