@spark-ui/components 11.2.5 → 11.3.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.
@@ -0,0 +1,197 @@
1
+ // src/progress/Progress.tsx
2
+ import { cx } from "class-variance-authority";
3
+ import { Progress as RadixProgress2 } from "radix-ui";
4
+ import { useMemo, useState } from "react";
5
+
6
+ // src/progress/ProgressBar.styles.ts
7
+ import { cva } from "class-variance-authority";
8
+ var progressBarStyles = cva(
9
+ ["relative", "h-sz-4 w-full", "transform-gpu overflow-hidden", "bg-on-background/dim-4"],
10
+ {
11
+ variants: {
12
+ shape: {
13
+ square: [],
14
+ rounded: ["rounded-sm"]
15
+ }
16
+ }
17
+ }
18
+ );
19
+
20
+ // src/progress/ProgressContext.tsx
21
+ import { createContext, useContext } from "react";
22
+ var ProgressContext = createContext(null);
23
+ var ID_PREFIX = ":progress";
24
+ var useProgress = () => {
25
+ const context = useContext(ProgressContext);
26
+ if (!context) {
27
+ throw new Error("useProgress must be used within a Progress provider");
28
+ }
29
+ return context;
30
+ };
31
+
32
+ // src/progress/ProgressIndicator.tsx
33
+ import { Progress as RadixProgress } from "radix-ui";
34
+
35
+ // src/progress/ProgressIndicator.styles.ts
36
+ import { cva as cva2 } from "class-variance-authority";
37
+ var progressIndicatorStyles = cva2(["h-full w-full", "transition-transform duration-400"], {
38
+ variants: {
39
+ /**
40
+ * Color scheme of the progress component.
41
+ */
42
+ intent: {
43
+ basic: ["bg-basic"],
44
+ main: ["bg-main"],
45
+ support: ["bg-support"],
46
+ accent: ["bg-accent"],
47
+ success: ["bg-success"],
48
+ alert: ["bg-alert"],
49
+ danger: ["bg-error"],
50
+ info: ["bg-info"],
51
+ neutral: ["bg-neutral"]
52
+ },
53
+ /**
54
+ * Shape of the progress component.
55
+ */
56
+ shape: {
57
+ square: [],
58
+ rounded: ["rounded-sm"]
59
+ },
60
+ /**
61
+ * Sets if the progress value is not determinated.
62
+ */
63
+ isIndeterminate: {
64
+ true: ["absolute", "-translate-x-1/2", "animate-standalone-indeterminate-bar"],
65
+ false: []
66
+ }
67
+ }
68
+ });
69
+
70
+ // src/progress/ProgressIndicator.tsx
71
+ import { jsx } from "react/jsx-runtime";
72
+ var ProgressIndicator = ({
73
+ className,
74
+ style,
75
+ ref,
76
+ ...others
77
+ }) => {
78
+ const { value, max, intent, shape, isIndeterminate } = useProgress();
79
+ const x = (max - value) / max * 100;
80
+ return /* @__PURE__ */ jsx(
81
+ RadixProgress.ProgressIndicator,
82
+ {
83
+ "data-spark-component": "progress-indicator",
84
+ className: progressIndicatorStyles({ className, intent, shape, isIndeterminate }),
85
+ style: { ...style, ...!isIndeterminate && { transform: `translateX(-${x}%)` } },
86
+ ref,
87
+ ...others
88
+ }
89
+ );
90
+ };
91
+ ProgressIndicator.displayName = "Progress.Indicator";
92
+
93
+ // src/progress/ProgressBar.tsx
94
+ import { jsx as jsx2 } from "react/jsx-runtime";
95
+ var ProgressBar = ({
96
+ className,
97
+ children = /* @__PURE__ */ jsx2(ProgressIndicator, {}),
98
+ ref,
99
+ ...others
100
+ }) => {
101
+ const { shape } = useProgress();
102
+ return /* @__PURE__ */ jsx2(
103
+ "div",
104
+ {
105
+ "data-spark-component": "progress-bar",
106
+ className: progressBarStyles({ className, shape }),
107
+ ref,
108
+ ...others,
109
+ children
110
+ }
111
+ );
112
+ };
113
+ ProgressBar.displayName = "Progress.Bar";
114
+
115
+ // src/progress/Progress.tsx
116
+ import { jsx as jsx3 } from "react/jsx-runtime";
117
+ var Progress = ({
118
+ className,
119
+ value: valueProp,
120
+ max = 100,
121
+ shape = "square",
122
+ intent = "basic",
123
+ isIndeterminate = false,
124
+ children = /* @__PURE__ */ jsx3(ProgressBar, {}),
125
+ ref,
126
+ ...others
127
+ }) => {
128
+ const [labelId, setLabelId] = useState();
129
+ const value = useMemo(() => {
130
+ return { value: valueProp ?? 0, max, intent, shape, isIndeterminate, onLabelId: setLabelId };
131
+ }, [max, valueProp, intent, shape, isIndeterminate, setLabelId]);
132
+ return /* @__PURE__ */ jsx3(ProgressContext.Provider, { "data-spark-component": "progress", value, children: /* @__PURE__ */ jsx3(
133
+ RadixProgress2.Progress,
134
+ {
135
+ "data-spark-component": "progress",
136
+ ref,
137
+ className: cx("gap-sm focus-visible:u-outline flex flex-col", className),
138
+ value: valueProp,
139
+ "aria-labelledby": labelId,
140
+ max,
141
+ tabIndex: -1,
142
+ ...others,
143
+ children
144
+ }
145
+ ) });
146
+ };
147
+ Progress.displayName = "Progress";
148
+
149
+ // src/progress/ProgressLabel.tsx
150
+ import { useMergeRefs } from "@spark-ui/hooks/use-merge-refs";
151
+ import { useCallback, useId } from "react";
152
+ import { jsx as jsx4 } from "react/jsx-runtime";
153
+ var ProgressLabel = ({
154
+ id: idProp,
155
+ children,
156
+ ref: forwardedRef,
157
+ ...others
158
+ }) => {
159
+ const internalID = `${ID_PREFIX}-label-${useId()}`;
160
+ const id = idProp || internalID;
161
+ const { onLabelId } = useProgress();
162
+ const rootRef = useCallback(
163
+ (el) => {
164
+ onLabelId(el ? id : void 0);
165
+ },
166
+ [id, onLabelId]
167
+ );
168
+ const ref = useMergeRefs(forwardedRef, rootRef);
169
+ return /* @__PURE__ */ jsx4(
170
+ "span",
171
+ {
172
+ "data-spark-component": "progress-label",
173
+ id,
174
+ className: "text-body-2 text-on-surface",
175
+ ref,
176
+ ...others,
177
+ children
178
+ }
179
+ );
180
+ };
181
+ ProgressLabel.displayName = "Progress.Label";
182
+
183
+ // src/progress/index.ts
184
+ var Progress2 = Object.assign(Progress, {
185
+ Label: ProgressLabel,
186
+ Bar: ProgressBar,
187
+ Indicator: ProgressIndicator
188
+ });
189
+ Progress2.displayName = "Progress";
190
+ ProgressBar.displayName = "Progress.Bar";
191
+ ProgressIndicator.displayName = "Progress.Indicator";
192
+ ProgressLabel.displayName = "Progress.Label";
193
+
194
+ export {
195
+ Progress2 as Progress
196
+ };
197
+ //# sourceMappingURL=chunk-TKAU6SMC.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/progress/Progress.tsx","../src/progress/ProgressBar.styles.ts","../src/progress/ProgressContext.tsx","../src/progress/ProgressIndicator.tsx","../src/progress/ProgressIndicator.styles.ts","../src/progress/ProgressBar.tsx","../src/progress/ProgressLabel.tsx","../src/progress/index.ts"],"sourcesContent":["import { cx } from 'class-variance-authority'\nimport { Progress as RadixProgress } from 'radix-ui'\nimport { PropsWithChildren, Ref, useMemo, useState } from 'react'\n\nimport { ProgressBar } from './ProgressBar'\nimport { ProgressContext } from './ProgressContext'\nimport { ProgressIndicatorStylesProps } from './ProgressIndicator.styles'\n\nexport interface ProgressProps\n extends RadixProgress.ProgressProps,\n Pick<ProgressIndicatorStylesProps, 'intent'> {\n shape?: 'square' | 'rounded'\n isIndeterminate?: boolean\n ref?: Ref<HTMLDivElement>\n}\n\nexport const Progress = ({\n className,\n value: valueProp,\n max = 100,\n shape = 'square',\n intent = 'basic',\n isIndeterminate = false,\n children = <ProgressBar />,\n ref,\n ...others\n}: PropsWithChildren<ProgressProps>) => {\n const [labelId, setLabelId] = useState<string>()\n\n const value = useMemo(() => {\n return { value: valueProp ?? 0, max, intent, shape, isIndeterminate, onLabelId: setLabelId }\n }, [max, valueProp, intent, shape, isIndeterminate, setLabelId])\n\n return (\n <ProgressContext.Provider data-spark-component=\"progress\" value={value}>\n <RadixProgress.Progress\n data-spark-component=\"progress\"\n ref={ref}\n className={cx('gap-sm focus-visible:u-outline flex flex-col', className)}\n value={valueProp}\n aria-labelledby={labelId}\n max={max}\n tabIndex={-1}\n {...others}\n >\n {children}\n </RadixProgress.Progress>\n </ProgressContext.Provider>\n )\n}\n\nProgress.displayName = 'Progress'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const progressBarStyles = cva(\n ['relative', 'h-sz-4 w-full', 'transform-gpu overflow-hidden', 'bg-on-background/dim-4'],\n {\n variants: {\n shape: {\n square: [],\n rounded: ['rounded-sm'],\n },\n },\n }\n)\n\nexport type ProgressBarStylesProps = VariantProps<typeof progressBarStyles>\n","import { createContext, useContext } from 'react'\n\nimport { ProgressIndicatorStylesProps } from './ProgressIndicator.styles'\n\nexport interface ProgressContextValue {\n value: number\n max: number\n isIndeterminate: boolean\n shape: 'square' | 'rounded'\n intent: ProgressIndicatorStylesProps['intent']\n onLabelId: (id?: string) => void\n}\n\nexport const ProgressContext = createContext<ProgressContextValue | null>(null)\n\nexport const ID_PREFIX = ':progress'\n\nexport const useProgress = () => {\n const context = useContext(ProgressContext)\n\n if (!context) {\n throw new Error('useProgress must be used within a Progress provider')\n }\n\n return context\n}\n","import { Progress as RadixProgress } from 'radix-ui'\nimport { ComponentPropsWithRef, PropsWithChildren } from 'react'\n\nimport { useProgress } from './ProgressContext'\nimport { progressIndicatorStyles } from './ProgressIndicator.styles'\n\nexport type ProgressIndicatorProps = ComponentPropsWithRef<'div'>\n\nexport const ProgressIndicator = ({\n className,\n style,\n ref,\n ...others\n}: PropsWithChildren<ProgressIndicatorProps>) => {\n const { value, max, intent, shape, isIndeterminate } = useProgress()\n const x = ((max - value) / max) * 100\n\n return (\n <RadixProgress.ProgressIndicator\n data-spark-component=\"progress-indicator\"\n className={progressIndicatorStyles({ className, intent, shape, isIndeterminate })}\n style={{ ...style, ...(!isIndeterminate && { transform: `translateX(-${x}%)` }) }}\n ref={ref}\n {...others}\n />\n )\n}\n\nProgressIndicator.displayName = 'Progress.Indicator'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const progressIndicatorStyles = cva(['h-full w-full', 'transition-transform duration-400'], {\n variants: {\n /**\n * Color scheme of the progress component.\n */\n intent: {\n basic: ['bg-basic'],\n main: ['bg-main'],\n support: ['bg-support'],\n accent: ['bg-accent'],\n success: ['bg-success'],\n alert: ['bg-alert'],\n danger: ['bg-error'],\n info: ['bg-info'],\n neutral: ['bg-neutral'],\n },\n /**\n * Shape of the progress component.\n */\n shape: {\n square: [],\n rounded: ['rounded-sm'],\n },\n /**\n * Sets if the progress value is not determinated.\n */\n isIndeterminate: {\n true: ['absolute', '-translate-x-1/2', 'animate-standalone-indeterminate-bar'],\n false: [],\n },\n },\n})\n\nexport type ProgressIndicatorStylesProps = VariantProps<typeof progressIndicatorStyles>\n","import { ComponentPropsWithRef, PropsWithChildren } from 'react'\n\nimport { progressBarStyles } from './ProgressBar.styles'\nimport { useProgress } from './ProgressContext'\nimport { ProgressIndicator } from './ProgressIndicator'\n\nexport type ProgressBarProps = ComponentPropsWithRef<'div'>\n\nexport const ProgressBar = ({\n className,\n children = <ProgressIndicator />,\n ref,\n ...others\n}: PropsWithChildren<ProgressBarProps>) => {\n const { shape } = useProgress()\n\n return (\n <div\n data-spark-component=\"progress-bar\"\n className={progressBarStyles({ className, shape })}\n ref={ref}\n {...others}\n >\n {children}\n </div>\n )\n}\n\nProgressBar.displayName = 'Progress.Bar'\n","import { useMergeRefs } from '@spark-ui/hooks/use-merge-refs'\nimport { ComponentPropsWithRef, useCallback, useId } from 'react'\n\nimport { ID_PREFIX, useProgress } from './ProgressContext'\n\nexport type ProgressLabelProps = ComponentPropsWithRef<'span'>\n\nexport const ProgressLabel = ({\n id: idProp,\n children,\n ref: forwardedRef,\n ...others\n}: ProgressLabelProps) => {\n const internalID = `${ID_PREFIX}-label-${useId()}`\n const id = idProp || internalID\n\n const { onLabelId } = useProgress()\n const rootRef = useCallback(\n (el: HTMLSpanElement) => {\n onLabelId(el ? id : undefined)\n },\n [id, onLabelId]\n )\n const ref = useMergeRefs(forwardedRef, rootRef)\n\n return (\n <span\n data-spark-component=\"progress-label\"\n id={id}\n className=\"text-body-2 text-on-surface\"\n ref={ref}\n {...others}\n >\n {children}\n </span>\n )\n}\n\nProgressLabel.displayName = 'Progress.Label'\n","import { Progress as Root } from './Progress'\nimport { ProgressBar } from './ProgressBar'\nimport { ProgressIndicator } from './ProgressIndicator'\nimport { ProgressLabel } from './ProgressLabel'\n\nexport const Progress: typeof Root & {\n Label: typeof ProgressLabel\n Bar: typeof ProgressBar\n Indicator: typeof ProgressIndicator\n} = Object.assign(Root, {\n Label: ProgressLabel,\n Bar: ProgressBar,\n Indicator: ProgressIndicator,\n})\n\nProgress.displayName = 'Progress'\nProgressBar.displayName = 'Progress.Bar'\nProgressIndicator.displayName = 'Progress.Indicator'\nProgressLabel.displayName = 'Progress.Label'\n\nexport { type ProgressProps } from './Progress'\nexport { type ProgressBarProps } from './ProgressBar'\nexport { type ProgressLabelProps } from './ProgressLabel'\nexport { type ProgressIndicatorProps } from './ProgressIndicator'\n"],"mappings":";AAAA,SAAS,UAAU;AACnB,SAAS,YAAYA,sBAAqB;AAC1C,SAAiC,SAAS,gBAAgB;;;ACF1D,SAAS,WAAyB;AAE3B,IAAM,oBAAoB;AAAA,EAC/B,CAAC,YAAY,iBAAiB,iCAAiC,wBAAwB;AAAA,EACvF;AAAA,IACE,UAAU;AAAA,MACR,OAAO;AAAA,QACL,QAAQ,CAAC;AAAA,QACT,SAAS,CAAC,YAAY;AAAA,MACxB;AAAA,IACF;AAAA,EACF;AACF;;;ACZA,SAAS,eAAe,kBAAkB;AAanC,IAAM,kBAAkB,cAA2C,IAAI;AAEvE,IAAM,YAAY;AAElB,IAAM,cAAc,MAAM;AAC/B,QAAM,UAAU,WAAW,eAAe;AAE1C,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AAEA,SAAO;AACT;;;ACzBA,SAAS,YAAY,qBAAqB;;;ACA1C,SAAS,OAAAC,YAAyB;AAE3B,IAAM,0BAA0BA,KAAI,CAAC,iBAAiB,mCAAmC,GAAG;AAAA,EACjG,UAAU;AAAA;AAAA;AAAA;AAAA,IAIR,QAAQ;AAAA,MACN,OAAO,CAAC,UAAU;AAAA,MAClB,MAAM,CAAC,SAAS;AAAA,MAChB,SAAS,CAAC,YAAY;AAAA,MACtB,QAAQ,CAAC,WAAW;AAAA,MACpB,SAAS,CAAC,YAAY;AAAA,MACtB,OAAO,CAAC,UAAU;AAAA,MAClB,QAAQ,CAAC,UAAU;AAAA,MACnB,MA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