@spark-ui/collapsible 0.1.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # 0.1.0 (2024-06-07)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **collapsible:** code review updates, tests and types ([6c351bd](https://github.com/adevinta/spark/commit/6c351bd92a32968c62d77312dacc7bea29825f8e))
11
+
12
+ ### Features
13
+
14
+ - **collapsible:** collapsible package, using zagjs ([b196c08](https://github.com/adevinta/spark/commit/b196c08ee81974d82838de7c12bf7db184a51eee))
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Adevinta ASA.
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,13 @@
1
+ # Collapsible
2
+ > @spark-ui/collapsible
3
+
4
+ [![storybook](https://img.shields.io/badge/storybook-black?logo=storybook)](https://sparkui.vercel.app/?path=/docs/components-collapsible--docs)
5
+ [![documentation](https://img.shields.io/badge/documentation-black?logo=googledocs)](https://sparkui-adv.vercel.app/docs/components/collapsible)
6
+ [![issue](https://img.shields.io/badge/report%20a%20bug-black?logo=openbugbounty&logoColor=red)](https://github.com/adevinta/spark/issues/new?&projects=4&template=bug-report.yml&assignees=&labels=component,collapsible)
7
+ [![npm](https://img.shields.io/npm/dt/%40spark-ui/collapsible?logo=npm&labelColor=black)](https://www.npmjs.com/package/@spark-ui/collapsible)
8
+
9
+
10
+ This package is part of the [`@spark-ui`](https://github.com/adevinta/spark) react-js user interface component library project.
11
+
12
+ [![Issues open](https://img.shields.io/github/issues-search/adevinta/spark?query=is%3Aopen%20label%3Acomponent%20label%3Acollapsible&logo=openbugbounty&logoColor=red&label=issues%20open&color=red)](https://github.com/adevinta/spark/issues?q=is%3Aopen+label%3Acomponent+label%3Acollapsible)
13
+ [![NPM](https://img.shields.io/npm/l/%40spark-ui%2Fcollapsible)](https://github.com/adevinta/spark/blob/main/packages/components/collapsible/LICENSE.md)
@@ -0,0 +1,27 @@
1
+ import * as collapsible from '@zag-js/collapsible';
2
+ import { type PropTypes } from '@zag-js/react';
3
+ import { type ComponentPropsWithoutRef } from 'react';
4
+ export interface CollapsibleProps extends ComponentPropsWithoutRef<'div'> {
5
+ /**
6
+ * Change the default rendered element for the one passed as a child, merging their props and behavior.
7
+ */
8
+ asChild?: boolean;
9
+ /**
10
+ * The open state of the collapsible when it is initially rendered. Use when you do not need to control its open state.
11
+ */
12
+ defaultOpen?: boolean;
13
+ /**
14
+ * When `true`, prevents the user from interacting with the collapsible.
15
+ */
16
+ disabled?: boolean;
17
+ /**
18
+ * Event handler called when the open state of the collapsible changes.
19
+ */
20
+ onOpenChange?: (open: boolean) => void;
21
+ /**
22
+ * The controlled open state of the collapsible. Must be used in conjunction with `onOpenChange`.
23
+ */
24
+ open?: boolean;
25
+ }
26
+ export declare const Collapsible: import("react").ForwardRefExoticComponent<CollapsibleProps & import("react").RefAttributes<HTMLDivElement>>;
27
+ export declare const useCollapsibleContext: () => collapsible.Api<PropTypes>;
@@ -0,0 +1,5 @@
1
+ import { type ComponentPropsWithoutRef } from 'react';
2
+ export interface CollapsibleContentProps extends ComponentPropsWithoutRef<'div'> {
3
+ asChild?: boolean;
4
+ }
5
+ export declare const Content: import("react").ForwardRefExoticComponent<CollapsibleContentProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,7 @@
1
+ import { type ComponentPropsWithoutRef, type ReactNode } from 'react';
2
+ export interface CollapsibleTriggerProps extends ComponentPropsWithoutRef<'button'> {
3
+ asChild?: boolean;
4
+ children: ReactNode;
5
+ className?: string;
6
+ }
7
+ export declare const Trigger: import("react").ForwardRefExoticComponent<CollapsibleTriggerProps & import("react").RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,11 @@
1
+ import type { FC } from 'react';
2
+ import { type CollapsibleProps } from './Collapsible';
3
+ import { Content } from './CollapsibleContent';
4
+ import { Trigger } from './CollapsibleTrigger';
5
+ export declare const Collapsible: FC<CollapsibleProps> & {
6
+ Trigger: typeof Trigger;
7
+ Content: typeof Content;
8
+ };
9
+ export { type CollapsibleProps } from './Collapsible';
10
+ export { type CollapsibleContentProps } from './CollapsibleContent';
11
+ export { type CollapsibleTriggerProps } from './CollapsibleTrigger';
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),i=require("@spark-ui/slot"),S=require("@zag-js/collapsible"),s=require("@zag-js/react"),j=require("class-variance-authority");function w(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const o in e)if(o!=="default"){const l=Object.getOwnPropertyDescriptor(e,o);Object.defineProperty(r,o,l.get?l:{enumerable:!0,get:()=>e[o]})}}return r.default=e,Object.freeze(r)}const g=w(S),f=t.createContext(null),h=t.forwardRef(({asChild:e=!1,children:r,defaultOpen:o=!1,disabled:l=!1,onOpenChange:n,open:a,...P})=>{const p={"open.controlled":a!==void 0,open:o||a,disabled:l,id:t.useId(),onOpenChange(N){n?.(N.open)}},O={...p,open:a,disabled:l},[u,b]=s.useMachine(g.machine(p),{context:O}),m=t.useMemo(()=>g.connect(u,b,s.normalizeProps),[b,u]),v=e?i.Slot:"div";return t.createElement(f.Provider,{value:m},t.createElement(v,{"data-spark-component":"collapsible",...s.mergeProps(m.rootProps,P)},r))});h.displayName="Collapsible";const y=()=>{const e=t.useContext(f);if(!e)throw Error("useCollapsibleContext must be used within a Collapsible provider");return e},c=t.forwardRef(({asChild:e=!1,className:r,children:o,...l})=>{const{contentProps:n}=y(),a=e?i.Slot:"div";return t.createElement(a,{...s.mergeProps(n,{className:j.cx("data-[state=closed]:hidden",r),...l}),"data-spark-component":"collapsible-content"},o)});c.displayName="Collapsible.Content";const d=t.forwardRef(({asChild:e=!1,children:r,...o})=>{const{triggerProps:l}=y(),n=e?i.Slot:"button";return t.createElement(n,{"data-spark-component":"collapsible-trigger",...s.mergeProps(l,o)},r)});d.displayName="Collapsible.Trigger";const C=Object.assign(h,{Trigger:d,Content:c});C.displayName="Collapsible",d.displayName="Collapsible.Trigger",c.displayName="Collapsible.Content",exports.Collapsible=C;
package/dist/index.mjs ADDED
@@ -0,0 +1,32 @@
1
+ import n, { createContext as E, forwardRef as r, useId as O, useMemo as k, useContext as w } from "react";
2
+ import { Slot as i } from "@spark-ui/slot";
3
+ import * as g from "@zag-js/collapsible";
4
+ import { useMachine as T, normalizeProps as M, mergeProps as p } from "@zag-js/react";
5
+ import { cx as j } from "class-variance-authority";
6
+ const h = E(null), f = r(({ asChild: e = !1, children: a, defaultOpen: s = !1, disabled: o = !1, onOpenChange: t, open: l, ...v }) => {
7
+ const m = { "open.controlled": l !== void 0, open: s || l, disabled: o, id: O(), onOpenChange(P) {
8
+ t?.(P.open);
9
+ } }, y = { ...m, open: l, disabled: o }, [b, C] = T(g.machine(m), { context: y }), u = k(() => g.connect(b, C, M), [C, b]), x = e ? i : "div";
10
+ return n.createElement(h.Provider, { value: u }, n.createElement(x, { "data-spark-component": "collapsible", ...p(u.rootProps, v) }, a));
11
+ });
12
+ f.displayName = "Collapsible";
13
+ const N = () => {
14
+ const e = w(h);
15
+ if (!e)
16
+ throw Error("useCollapsibleContext must be used within a Collapsible provider");
17
+ return e;
18
+ }, c = r(({ asChild: e = !1, className: a, children: s, ...o }) => {
19
+ const { contentProps: t } = N(), l = e ? i : "div";
20
+ return n.createElement(l, { ...p(t, { className: j("data-[state=closed]:hidden", a), ...o }), "data-spark-component": "collapsible-content" }, s);
21
+ });
22
+ c.displayName = "Collapsible.Content";
23
+ const d = r(({ asChild: e = !1, children: a, ...s }) => {
24
+ const { triggerProps: o } = N(), t = e ? i : "button";
25
+ return n.createElement(t, { "data-spark-component": "collapsible-trigger", ...p(o, s) }, a);
26
+ });
27
+ d.displayName = "Collapsible.Trigger";
28
+ const z = Object.assign(f, { Trigger: d, Content: c });
29
+ z.displayName = "Collapsible", d.displayName = "Collapsible.Trigger", c.displayName = "Collapsible.Content";
30
+ export {
31
+ z as Collapsible
32
+ };
@@ -0,0 +1,182 @@
1
+ {
2
+ "Collapsible": {
3
+ "tags": {},
4
+ "description": "",
5
+ "displayName": "Collapsible",
6
+ "methods": [],
7
+ "props": {
8
+ "asChild": {
9
+ "defaultValue": null,
10
+ "description": "Change the default rendered element for the one passed as a child, merging their props and behavior.",
11
+ "name": "asChild",
12
+ "parent": {
13
+ "fileName": "collapsible/src/Collapsible.tsx",
14
+ "name": "CollapsibleProps"
15
+ },
16
+ "declarations": [
17
+ {
18
+ "fileName": "collapsible/src/Collapsible.tsx",
19
+ "name": "CollapsibleProps"
20
+ }
21
+ ],
22
+ "required": false,
23
+ "type": {
24
+ "name": "boolean"
25
+ }
26
+ },
27
+ "defaultOpen": {
28
+ "defaultValue": null,
29
+ "description": "The open state of the collapsible when it is initially rendered. Use when you do not need to control its open state.",
30
+ "name": "defaultOpen",
31
+ "parent": {
32
+ "fileName": "collapsible/src/Collapsible.tsx",
33
+ "name": "CollapsibleProps"
34
+ },
35
+ "declarations": [
36
+ {
37
+ "fileName": "collapsible/src/Collapsible.tsx",
38
+ "name": "CollapsibleProps"
39
+ }
40
+ ],
41
+ "required": false,
42
+ "type": {
43
+ "name": "boolean"
44
+ }
45
+ },
46
+ "disabled": {
47
+ "defaultValue": null,
48
+ "description": "When `true`, prevents the user from interacting with the collapsible.",
49
+ "name": "disabled",
50
+ "parent": {
51
+ "fileName": "collapsible/src/Collapsible.tsx",
52
+ "name": "CollapsibleProps"
53
+ },
54
+ "declarations": [
55
+ {
56
+ "fileName": "collapsible/src/Collapsible.tsx",
57
+ "name": "CollapsibleProps"
58
+ }
59
+ ],
60
+ "required": false,
61
+ "type": {
62
+ "name": "boolean"
63
+ }
64
+ },
65
+ "onOpenChange": {
66
+ "defaultValue": null,
67
+ "description": "Event handler called when the open state of the collapsible changes.",
68
+ "name": "onOpenChange",
69
+ "parent": {
70
+ "fileName": "collapsible/src/Collapsible.tsx",
71
+ "name": "CollapsibleProps"
72
+ },
73
+ "declarations": [
74
+ {
75
+ "fileName": "collapsible/src/Collapsible.tsx",
76
+ "name": "CollapsibleProps"
77
+ }
78
+ ],
79
+ "required": false,
80
+ "type": {
81
+ "name": "(open: boolean) => void"
82
+ }
83
+ },
84
+ "open": {
85
+ "defaultValue": null,
86
+ "description": "The controlled open state of the collapsible. Must be used in conjunction with `onOpenChange`.",
87
+ "name": "open",
88
+ "parent": {
89
+ "fileName": "collapsible/src/Collapsible.tsx",
90
+ "name": "CollapsibleProps"
91
+ },
92
+ "declarations": [
93
+ {
94
+ "fileName": "collapsible/src/Collapsible.tsx",
95
+ "name": "CollapsibleProps"
96
+ }
97
+ ],
98
+ "required": false,
99
+ "type": {
100
+ "name": "boolean"
101
+ }
102
+ }
103
+ }
104
+ },
105
+ "Collapsible.Content": {
106
+ "tags": {},
107
+ "description": "",
108
+ "displayName": "Collapsible.Content",
109
+ "methods": [],
110
+ "props": {
111
+ "asChild": {
112
+ "defaultValue": {
113
+ "value": false
114
+ },
115
+ "description": "",
116
+ "name": "asChild",
117
+ "parent": {
118
+ "fileName": "collapsible/src/CollapsibleContent.tsx",
119
+ "name": "CollapsibleContentProps"
120
+ },
121
+ "declarations": [
122
+ {
123
+ "fileName": "collapsible/src/CollapsibleContent.tsx",
124
+ "name": "CollapsibleContentProps"
125
+ }
126
+ ],
127
+ "required": false,
128
+ "type": {
129
+ "name": "boolean"
130
+ }
131
+ }
132
+ }
133
+ },
134
+ "Collapsible.Trigger": {
135
+ "tags": {},
136
+ "description": "",
137
+ "displayName": "Collapsible.Trigger",
138
+ "methods": [],
139
+ "props": {
140
+ "asChild": {
141
+ "defaultValue": {
142
+ "value": false
143
+ },
144
+ "description": "",
145
+ "name": "asChild",
146
+ "parent": {
147
+ "fileName": "collapsible/src/CollapsibleTrigger.tsx",
148
+ "name": "CollapsibleTriggerProps"
149
+ },
150
+ "declarations": [
151
+ {
152
+ "fileName": "collapsible/src/CollapsibleTrigger.tsx",
153
+ "name": "CollapsibleTriggerProps"
154
+ }
155
+ ],
156
+ "required": false,
157
+ "type": {
158
+ "name": "boolean"
159
+ }
160
+ },
161
+ "className": {
162
+ "defaultValue": null,
163
+ "description": "",
164
+ "name": "className",
165
+ "parent": {
166
+ "fileName": "collapsible/src/CollapsibleTrigger.tsx",
167
+ "name": "CollapsibleTriggerProps"
168
+ },
169
+ "declarations": [
170
+ {
171
+ "fileName": "collapsible/src/CollapsibleTrigger.tsx",
172
+ "name": "CollapsibleTriggerProps"
173
+ }
174
+ ],
175
+ "required": false,
176
+ "type": {
177
+ "name": "string"
178
+ }
179
+ }
180
+ }
181
+ }
182
+ }
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@spark-ui/collapsible",
3
+ "version": "0.1.0",
4
+ "description": "An interactive component which expands/collapses a panel.",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "keywords": [
9
+ "@spark-ui",
10
+ "react",
11
+ "component",
12
+ "accessible",
13
+ "accessibility",
14
+ "wai-aria",
15
+ "aria",
16
+ "a11y",
17
+ "collapsible",
18
+ "disclosure"
19
+ ],
20
+ "main": "./dist/index.js",
21
+ "module": "./dist/index.mjs",
22
+ "types": "./dist/index.d.ts",
23
+ "scripts": {
24
+ "build": "vite build"
25
+ },
26
+ "peerDependencies": {
27
+ "@spark-ui/theme-utils": "^4.0.0",
28
+ "react": "^18.0 || ^19.0",
29
+ "react-dom": "^18.0 || ^19.0",
30
+ "tailwindcss": "^3.0.0"
31
+ },
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/adevinta/spark.git",
35
+ "directory": "packages/components/collapsible"
36
+ },
37
+ "config": {
38
+ "title": "collapsible",
39
+ "category": "components"
40
+ },
41
+ "bugs": {
42
+ "url": "https://github.com/adevinta/spark/issues?q=is%3Aopen+label%3Autility+label%3Acollapsible"
43
+ },
44
+ "homepage": "https://sparkui.vercel.app",
45
+ "license": "MIT",
46
+ "dependencies": {
47
+ "@spark-ui/slot": "^1.7.1",
48
+ "@zag-js/collapsible": "^0.53.0",
49
+ "@zag-js/react": "^0.53.0"
50
+ },
51
+ "gitHead": "5ab06446afc6e44e90583cff54175ab1fe01f6a0"
52
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": ["src/**/*", "../../../global.d.ts"]
4
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,6 @@
1
+ import path from 'path'
2
+ import { getComponentConfiguration } from '../../../config/index'
3
+
4
+ const { name } = require(path.resolve(__dirname, 'package.json'))
5
+
6
+ export default getComponentConfiguration(process.cwd(), name)