@spark-ui/components 15.0.0 → 16.0.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/dist/dialog/Dialog.d.ts +1 -0
- package/dist/dialog/index.js +1 -1
- package/dist/dialog/index.js.map +1 -1
- package/dist/dialog/index.mjs +19 -18
- package/dist/dialog/index.mjs.map +1 -1
- package/dist/rating/Rating.d.ts +17 -12
- package/dist/rating/RatingStar.d.ts +12 -3
- package/dist/rating/index.js +1 -1
- package/dist/rating/index.js.map +1 -1
- package/dist/rating/index.mjs +210 -163
- package/dist/rating/index.mjs.map +1 -1
- package/dist/rating/types.d.ts +2 -1
- package/dist/rating/utils.d.ts +1 -2
- package/dist/rating-display/RatingDisplay.d.ts +26 -0
- package/dist/rating-display/RatingDisplayContext.d.ts +12 -0
- package/dist/rating-display/RatingDisplayCount.d.ts +12 -0
- package/dist/rating-display/RatingDisplayStar.d.ts +16 -0
- package/dist/rating-display/RatingDisplayStars.d.ts +22 -0
- package/dist/rating-display/RatingDisplayValue.d.ts +13 -0
- package/dist/rating-display/index.d.mts +14 -0
- package/dist/rating-display/index.d.ts +14 -0
- package/dist/rating-display/index.js +2 -0
- package/dist/rating-display/index.js.map +1 -0
- package/dist/rating-display/index.mjs +150 -0
- package/dist/rating-display/index.mjs.map +1 -0
- package/dist/rating-display/types.d.ts +1 -0
- package/dist/rating-display/utils.d.ts +10 -0
- package/dist/switch/index.js +1 -1
- package/dist/switch/index.js.map +1 -1
- package/dist/switch/index.mjs +1 -1
- package/dist/switch/index.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RatingDisplay as Root } from './RatingDisplay';
|
|
2
|
+
import { RatingDisplayCount as Count } from './RatingDisplayCount';
|
|
3
|
+
import { RatingDisplayStars as Stars } from './RatingDisplayStars';
|
|
4
|
+
import { RatingDisplayValue as Value } from './RatingDisplayValue';
|
|
5
|
+
export declare const RatingDisplay: typeof Root & {
|
|
6
|
+
Stars: typeof Stars;
|
|
7
|
+
Value: typeof Value;
|
|
8
|
+
Count: typeof Count;
|
|
9
|
+
};
|
|
10
|
+
export { type RatingDisplayProps, type RatingDisplayRootProps } from './RatingDisplay';
|
|
11
|
+
export { type RatingDisplayStarsProps } from './RatingDisplayStars';
|
|
12
|
+
export { type RatingDisplayValueProps } from './RatingDisplayValue';
|
|
13
|
+
export { type RatingDisplayCountProps } from './RatingDisplayCount';
|
|
14
|
+
export type { StarValue } from './types';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),x=require("react"),l=require("class-variance-authority"),N=require("@spark-ui/icons/StarFill"),j=require("@spark-ui/icons/StarOutline"),y=require("../Icon-CF0W0LKr.js"),D=x.createContext(null),V=({value:t,size:a,count:n,children:e})=>s.jsx(D.Provider,{value:{value:t,size:a,count:n},children:e}),d=()=>{const t=x.useContext(D);if(!t)throw new Error("RatingDisplay compound components must be used within RatingDisplay.");return t},v=({value:t=0,size:a="md",count:n,ref:e,children:i,...r})=>{const c=t??0;return s.jsx(V,{value:c,size:a,count:n,children:s.jsx("div",{ref:e,className:"gap-x-sm relative inline-flex items-center","data-spark-component":"rating-display",...r,children:i})})};v.displayName="RatingDisplay";const p=({className:t,children:a,...n})=>{const{count:e}=d();if(e===void 0)return null;const i=typeof a=="function"?a(e):a??e;return s.jsxs("span",{className:l.cx("text-on-surface/dim-1",t),...n,children:["(",i,")"]})};p.displayName="RatingDisplay.Count";const h=l.cva(["relative block after:absolute after:block after:inset-0"],{variants:{gap:{sm:["after:w-[calc(100%+(var(--spacing-sm)))]","last-of-type:after:content-none"],md:["after:w-[calc(100%+(var(--spacing-md)))]","last-of-type:after:content-none"]}},defaultVariants:{gap:"sm"}}),f=l.cva("",{variants:{size:{sm:"text-caption-link",md:"text-body-1",lg:"text-display-3"},design:{filled:["text-main-variant"],outlined:["text-on-surface/dim-3"]}}}),b=({value:t,size:a})=>s.jsxs("div",{"data-spark-component":"rating-display-star","data-part":"star",className:h({gap:a==="lg"?"md":"sm"}),children:[s.jsx("div",{className:l.cx("z-raised absolute overflow-hidden"),style:{width:t*100+"%"},children:s.jsx(y.Icon,{className:f({size:a,design:"filled"}),children:s.jsx(N.StarFill,{})})}),s.jsx(y.Icon,{className:f({size:a,design:"outlined"}),children:s.jsx(j.StarOutline,{})})]});function w(t){return Math.round(t/.5)*.5}function C(t){const a=Intl.DateTimeFormat().resolvedOptions().locale;return new Intl.NumberFormat(a,{minimumFractionDigits:0,maximumFractionDigits:1}).format(t)}function k({value:t,index:a}){if(t===void 0)return 0;const n=a+1,e=w(t);return Math.ceil(e)<n?0:e>=n?1:.5}function q(t){return t===void 0||t<1?0:t<4?.5:1}const m=({size:t,variant:a="default",getFillMode:n})=>{const{value:e,size:i}=d(),r=t??i,c=o=>n?n({index:o,value:e}):a==="single-star"?q(e):k({index:o,value:e}),S=a==="single-star"?[c(0)]:Array.from({length:5},(o,u)=>c(u));return s.jsx("div",{"data-spark-component":"rating-display-stars",className:l.cx(r==="lg"?"gap-x-md":"gap-x-sm","flex"),children:S.map((o,u)=>s.jsx(b,{size:r,value:o},u))})};m.displayName="RatingDisplay.Stars";const g=({className:t,children:a,...n})=>{const{value:e}=d(),i=C(e),r=typeof a=="function"?a(i,e):a??i;return s.jsx("span",{"data-spark-component":"rating-display-value",className:l.cx("text-on-surface font-bold",t),...n,children:r})};g.displayName="RatingDisplay.Value";const R=Object.assign(v,{Stars:m,Value:g,Count:p});R.displayName="RatingDisplay";m.displayName="RatingDisplay.Stars";g.displayName="RatingDisplay.Value";p.displayName="RatingDisplay.Count";exports.RatingDisplay=R;
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/rating-display/RatingDisplayContext.tsx","../../src/rating-display/RatingDisplay.tsx","../../src/rating-display/RatingDisplayCount.tsx","../../src/rating-display/RatingDisplayStar.tsx","../../src/rating-display/utils.ts","../../src/rating-display/RatingDisplayStars.tsx","../../src/rating-display/RatingDisplayValue.tsx","../../src/rating-display/index.ts"],"sourcesContent":["import { createContext, type PropsWithChildren, useContext } from 'react'\n\nimport type { RatingDisplayStarProps } from './RatingDisplayStar'\n\ninterface RatingDisplayContextValue {\n value: number\n size: RatingDisplayStarProps['size']\n count?: number\n}\n\nconst RatingDisplayContext = createContext<RatingDisplayContextValue | null>(null)\n\ninterface RatingDisplayProviderProps extends PropsWithChildren<RatingDisplayContextValue> {}\n\nexport const RatingDisplayProvider = ({\n value,\n size,\n count,\n children,\n}: RatingDisplayProviderProps) => {\n return (\n <RatingDisplayContext.Provider value={{ value, size, count }}>\n {children}\n </RatingDisplayContext.Provider>\n )\n}\n\nexport const useRatingDisplay = () => {\n const context = useContext(RatingDisplayContext)\n if (!context) {\n throw new Error('RatingDisplay compound components must be used within RatingDisplay.')\n }\n\n return context\n}\n","import { type ComponentPropsWithRef, type PropsWithChildren } from 'react'\n\nimport { RatingDisplayProvider } from './RatingDisplayContext'\nimport type { RatingDisplayStarProps } from './RatingDisplayStar'\n\nexport interface RatingDisplayProps extends PropsWithChildren<ComponentPropsWithRef<'div'>> {\n /**\n * The rating value to display, on a scale from 0 to 5.\n */\n value?: number\n /**\n * Sets the size of the stars.\n * @default 'md'\n */\n size?: RatingDisplayStarProps['size']\n /**\n * Optional count value available to `RatingDisplay.Count`.\n */\n count?: number\n /**\n * Accessible description of the rating content.\n */\n 'aria-label': string\n}\n\nexport type RatingDisplayRootProps = RatingDisplayProps\n\nexport const RatingDisplay = ({\n value = 0,\n size = 'md',\n count,\n ref,\n children,\n ...rest\n}: RatingDisplayProps) => {\n const ratingValue = value ?? 0\n\n return (\n <RatingDisplayProvider value={ratingValue} size={size} count={count}>\n <div\n ref={ref}\n className=\"gap-x-sm relative inline-flex items-center\"\n data-spark-component=\"rating-display\"\n {...rest}\n >\n {children}\n </div>\n </RatingDisplayProvider>\n )\n}\n\nRatingDisplay.displayName = 'RatingDisplay'\n","import { cx } from 'class-variance-authority'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\n\nexport interface RatingDisplayCountProps extends Omit<ComponentPropsWithRef<'span'>, 'children'> {\n /**\n * Custom count content.\n * Pass a render function to receive the count value and return the content to render.\n */\n children?: ReactNode | ((count: number) => ReactNode)\n}\n\nexport const RatingDisplayCount = ({ className, children, ...rest }: RatingDisplayCountProps) => {\n const { count } = useRatingDisplay()\n if (count === undefined) return null\n const renderedCount = typeof children === 'function' ? children(count) : (children ?? count)\n\n return (\n <span className={cx('text-on-surface/dim-1', className)} {...rest}>\n ({renderedCount})\n </span>\n )\n}\n\nRatingDisplayCount.displayName = 'RatingDisplay.Count'\n","import { StarFill } from '@spark-ui/icons/StarFill'\nimport { StarOutline } from '@spark-ui/icons/StarOutline'\nimport { cva, cx, type VariantProps } from 'class-variance-authority'\n\nimport { Icon } from '../icon'\nimport type { StarValue } from './types'\n\nconst ratingDisplayStarStyles = cva(['relative block after:absolute after:block after:inset-0'], {\n variants: {\n gap: {\n sm: ['after:w-[calc(100%+(var(--spacing-sm)))]', 'last-of-type:after:content-none'],\n md: ['after:w-[calc(100%+(var(--spacing-md)))]', 'last-of-type:after:content-none'],\n },\n },\n defaultVariants: {\n gap: 'sm',\n },\n})\n\nconst ratingDisplayStarIconStyles = cva('', {\n variants: {\n size: {\n sm: 'text-caption-link',\n md: 'text-body-1',\n lg: 'text-display-3',\n },\n design: {\n filled: ['text-main-variant'],\n outlined: ['text-on-surface/dim-3'],\n },\n },\n})\n\ntype RatingDisplayStarstylesProps = Omit<VariantProps<typeof ratingDisplayStarStyles>, never>\ntype RatingDisplayStarIconStylesProps = Omit<\n VariantProps<typeof ratingDisplayStarIconStyles>,\n 'design'\n>\n\nexport interface RatingDisplayStarProps\n extends RatingDisplayStarstylesProps,\n RatingDisplayStarIconStylesProps {\n value: StarValue\n}\n\nexport const RatingDisplayStar = ({ value, size }: RatingDisplayStarProps) => {\n return (\n <div\n data-spark-component=\"rating-display-star\"\n data-part=\"star\"\n className={ratingDisplayStarStyles({\n gap: size === 'lg' ? 'md' : 'sm',\n })}\n >\n <div className={cx('z-raised absolute overflow-hidden')} style={{ width: value * 100 + '%' }}>\n <Icon\n className={ratingDisplayStarIconStyles({\n size,\n design: 'filled',\n })}\n >\n <StarFill />\n </Icon>\n </div>\n\n <Icon className={ratingDisplayStarIconStyles({ size, design: 'outlined' })}>\n <StarOutline />\n </Icon>\n </div>\n )\n}\n","import { type StarValue } from './types'\n\nfunction getNearestHalfDecimal(num: number): number {\n return Math.round(num / 0.5) * 0.5\n}\n\nfunction formatRatingValue(value: number): string {\n const locale = Intl.DateTimeFormat().resolvedOptions().locale\n\n return new Intl.NumberFormat(locale, {\n minimumFractionDigits: 0,\n maximumFractionDigits: 1,\n }).format(value)\n}\n\nfunction getStarValue({ value, index }: { value?: number; index: number }): StarValue {\n if (value === undefined) return 0\n\n const starPosition = index + 1\n const formattedValue = getNearestHalfDecimal(value)\n\n if (Math.ceil(formattedValue) < starPosition) return 0\n\n return formattedValue >= starPosition ? 1 : 0.5\n}\n\nfunction getSingleStarValue(value?: number): StarValue {\n if (value === undefined) return 0\n if (value < 1) return 0\n if (value < 4) return 0.5\n return 1\n}\n\nfunction splitAt<T>(arr: T[], index: number): [T[], T[]] {\n const prev = arr.slice(0, index)\n const next = arr.slice(index)\n\n return [prev, next]\n}\n\nexport { formatRatingValue, getNearestHalfDecimal, getSingleStarValue, getStarValue, splitAt }\n","import { cx } from 'class-variance-authority'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\nimport { RatingDisplayStar, type RatingDisplayStarProps } from './RatingDisplayStar'\nimport type { StarValue } from './types'\nimport { getSingleStarValue, getStarValue } from './utils'\n\nexport interface RatingDisplayStarsProps {\n size?: RatingDisplayStarProps['size']\n /**\n * Sets the rendering mode for stars.\n * @default 'default'\n */\n variant?: 'default' | 'single-star'\n /**\n * Custom fill algorithm for each star.\n * By default, stars are rounded to the nearest 0.5.\n */\n getFillMode?: ({ value, index }: { value?: number; index: number }) => StarValue\n}\n\nexport const RatingDisplayStars = ({\n size,\n variant = 'default',\n getFillMode,\n}: RatingDisplayStarsProps) => {\n const { value, size: contextSize } = useRatingDisplay()\n const resolvedSize = size ?? contextSize\n const getDisplayValue = (index: number) => {\n if (getFillMode) {\n return getFillMode({ index, value })\n }\n\n return variant === 'single-star' ? getSingleStarValue(value) : getStarValue({ index, value })\n }\n\n const stars =\n variant === 'single-star'\n ? [getDisplayValue(0)]\n : Array.from({ length: 5 }, (_, index) => getDisplayValue(index))\n\n return (\n <div\n data-spark-component=\"rating-display-stars\"\n className={cx(resolvedSize === 'lg' ? 'gap-x-md' : 'gap-x-sm', 'flex')}\n >\n {stars.map((starValue, index) => (\n <RatingDisplayStar key={index} size={resolvedSize} value={starValue} />\n ))}\n </div>\n )\n}\n\nRatingDisplayStars.displayName = 'RatingDisplay.Stars'\n","import { cx } from 'class-variance-authority'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\nimport { formatRatingValue } from './utils'\n\nexport interface RatingDisplayValueProps extends Omit<ComponentPropsWithRef<'span'>, 'children'> {\n /**\n * Custom value content.\n * Pass a render function to receive the formatted value (first arg) and raw value (second arg),\n * then return the content to render.\n */\n children?: ReactNode | ((formattedValue: string, value: number) => ReactNode)\n}\n\nexport const RatingDisplayValue = ({ className, children, ...rest }: RatingDisplayValueProps) => {\n const { value } = useRatingDisplay()\n const formattedValue = formatRatingValue(value)\n const renderedValue =\n typeof children === 'function' ? children(formattedValue, value) : (children ?? formattedValue)\n\n return (\n <span\n data-spark-component=\"rating-display-value\"\n className={cx('text-on-surface font-bold', className)}\n {...rest}\n >\n {renderedValue}\n </span>\n )\n}\n\nRatingDisplayValue.displayName = 'RatingDisplay.Value'\n","import { RatingDisplay as Root } from './RatingDisplay'\nimport { RatingDisplayCount as Count } from './RatingDisplayCount'\nimport { RatingDisplayStars as Stars } from './RatingDisplayStars'\nimport { RatingDisplayValue as Value } from './RatingDisplayValue'\n\nexport const RatingDisplay: typeof Root & {\n Stars: typeof Stars\n Value: typeof Value\n Count: typeof Count\n} = Object.assign(Root, {\n Stars,\n Value,\n Count,\n})\n\nRatingDisplay.displayName = 'RatingDisplay'\nStars.displayName = 'RatingDisplay.Stars'\nValue.displayName = 'RatingDisplay.Value'\nCount.displayName = 'RatingDisplay.Count'\n\nexport { type RatingDisplayProps, type RatingDisplayRootProps } from './RatingDisplay'\nexport { type RatingDisplayStarsProps } from './RatingDisplayStars'\nexport { type RatingDisplayValueProps } from './RatingDisplayValue'\nexport { type RatingDisplayCountProps } from './RatingDisplayCount'\nexport type { StarValue } from './types'\n"],"names":["RatingDisplayContext","createContext","RatingDisplayProvider","value","size","count","children","jsx","useRatingDisplay","context","useContext","RatingDisplay","ref","rest","ratingValue","RatingDisplayCount","className","renderedCount","jsxs","cx","ratingDisplayStarStyles","cva","ratingDisplayStarIconStyles","RatingDisplayStar","Icon","StarFill","StarOutline","getNearestHalfDecimal","num","formatRatingValue","locale","getStarValue","index","starPosition","formattedValue","getSingleStarValue","RatingDisplayStars","variant","getFillMode","contextSize","resolvedSize","getDisplayValue","stars","_","starValue","RatingDisplayValue","renderedValue","Root","Stars","Value","Count"],"mappings":"8RAUMA,EAAuBC,EAAAA,cAAgD,IAAI,EAIpEC,EAAwB,CAAC,CACpC,MAAAC,EACA,KAAAC,EACA,MAAAC,EACA,SAAAC,CACF,IAEIC,MAACP,EAAqB,SAArB,CAA8B,MAAO,CAAE,MAAAG,EAAO,KAAAC,EAAM,MAAAC,GAClD,SAAAC,EACH,EAISE,EAAmB,IAAM,CACpC,MAAMC,EAAUC,EAAAA,WAAWV,CAAoB,EAC/C,GAAI,CAACS,EACH,MAAM,IAAI,MAAM,sEAAsE,EAGxF,OAAOA,CACT,ECPaE,EAAgB,CAAC,CAC5B,MAAAR,EAAQ,EACR,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as V } from "react";
|
|
3
|
+
import { cx as l, cva as v } from "class-variance-authority";
|
|
4
|
+
import { StarFill as h } from "@spark-ui/icons/StarFill";
|
|
5
|
+
import { StarOutline as b } from "@spark-ui/icons/StarOutline";
|
|
6
|
+
import { I as f } from "../Icon-Ck-dhfLd.mjs";
|
|
7
|
+
const x = S(null), w = ({
|
|
8
|
+
value: t,
|
|
9
|
+
size: a,
|
|
10
|
+
count: e,
|
|
11
|
+
children: n
|
|
12
|
+
}) => /* @__PURE__ */ i(x.Provider, { value: { value: t, size: a, count: e }, children: n }), m = () => {
|
|
13
|
+
const t = V(x);
|
|
14
|
+
if (!t)
|
|
15
|
+
throw new Error("RatingDisplay compound components must be used within RatingDisplay.");
|
|
16
|
+
return t;
|
|
17
|
+
}, R = ({
|
|
18
|
+
value: t = 0,
|
|
19
|
+
size: a = "md",
|
|
20
|
+
count: e,
|
|
21
|
+
ref: n,
|
|
22
|
+
children: s,
|
|
23
|
+
...r
|
|
24
|
+
}) => /* @__PURE__ */ i(w, { value: t ?? 0, size: a, count: e, children: /* @__PURE__ */ i(
|
|
25
|
+
"div",
|
|
26
|
+
{
|
|
27
|
+
ref: n,
|
|
28
|
+
className: "gap-x-sm relative inline-flex items-center",
|
|
29
|
+
"data-spark-component": "rating-display",
|
|
30
|
+
...r,
|
|
31
|
+
children: s
|
|
32
|
+
}
|
|
33
|
+
) });
|
|
34
|
+
R.displayName = "RatingDisplay";
|
|
35
|
+
const u = ({ className: t, children: a, ...e }) => {
|
|
36
|
+
const { count: n } = m();
|
|
37
|
+
if (n === void 0) return null;
|
|
38
|
+
const s = typeof a == "function" ? a(n) : a ?? n;
|
|
39
|
+
return /* @__PURE__ */ D("span", { className: l("text-on-surface/dim-1", t), ...e, children: [
|
|
40
|
+
"(",
|
|
41
|
+
s,
|
|
42
|
+
")"
|
|
43
|
+
] });
|
|
44
|
+
};
|
|
45
|
+
u.displayName = "RatingDisplay.Count";
|
|
46
|
+
const C = v(["relative block after:absolute after:block after:inset-0"], {
|
|
47
|
+
variants: {
|
|
48
|
+
gap: {
|
|
49
|
+
sm: ["after:w-[calc(100%+(var(--spacing-sm)))]", "last-of-type:after:content-none"],
|
|
50
|
+
md: ["after:w-[calc(100%+(var(--spacing-md)))]", "last-of-type:after:content-none"]
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
defaultVariants: {
|
|
54
|
+
gap: "sm"
|
|
55
|
+
}
|
|
56
|
+
}), y = v("", {
|
|
57
|
+
variants: {
|
|
58
|
+
size: {
|
|
59
|
+
sm: "text-caption-link",
|
|
60
|
+
md: "text-body-1",
|
|
61
|
+
lg: "text-display-3"
|
|
62
|
+
},
|
|
63
|
+
design: {
|
|
64
|
+
filled: ["text-main-variant"],
|
|
65
|
+
outlined: ["text-on-surface/dim-3"]
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}), k = ({ value: t, size: a }) => /* @__PURE__ */ D(
|
|
69
|
+
"div",
|
|
70
|
+
{
|
|
71
|
+
"data-spark-component": "rating-display-star",
|
|
72
|
+
"data-part": "star",
|
|
73
|
+
className: C({
|
|
74
|
+
gap: a === "lg" ? "md" : "sm"
|
|
75
|
+
}),
|
|
76
|
+
children: [
|
|
77
|
+
/* @__PURE__ */ i("div", { className: l("z-raised absolute overflow-hidden"), style: { width: t * 100 + "%" }, children: /* @__PURE__ */ i(
|
|
78
|
+
f,
|
|
79
|
+
{
|
|
80
|
+
className: y({
|
|
81
|
+
size: a,
|
|
82
|
+
design: "filled"
|
|
83
|
+
}),
|
|
84
|
+
children: /* @__PURE__ */ i(h, {})
|
|
85
|
+
}
|
|
86
|
+
) }),
|
|
87
|
+
/* @__PURE__ */ i(f, { className: y({ size: a, design: "outlined" }), children: /* @__PURE__ */ i(b, {}) })
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
function I(t) {
|
|
92
|
+
return Math.round(t / 0.5) * 0.5;
|
|
93
|
+
}
|
|
94
|
+
function z(t) {
|
|
95
|
+
const a = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
96
|
+
return new Intl.NumberFormat(a, {
|
|
97
|
+
minimumFractionDigits: 0,
|
|
98
|
+
maximumFractionDigits: 1
|
|
99
|
+
}).format(t);
|
|
100
|
+
}
|
|
101
|
+
function F({ value: t, index: a }) {
|
|
102
|
+
if (t === void 0) return 0;
|
|
103
|
+
const e = a + 1, n = I(t);
|
|
104
|
+
return Math.ceil(n) < e ? 0 : n >= e ? 1 : 0.5;
|
|
105
|
+
}
|
|
106
|
+
function j(t) {
|
|
107
|
+
return t === void 0 || t < 1 ? 0 : t < 4 ? 0.5 : 1;
|
|
108
|
+
}
|
|
109
|
+
const d = ({
|
|
110
|
+
size: t,
|
|
111
|
+
variant: a = "default",
|
|
112
|
+
getFillMode: e
|
|
113
|
+
}) => {
|
|
114
|
+
const { value: n, size: s } = m(), r = t ?? s, c = (o) => e ? e({ index: o, value: n }) : a === "single-star" ? j(n) : F({ index: o, value: n }), N = a === "single-star" ? [c(0)] : Array.from({ length: 5 }, (o, p) => c(p));
|
|
115
|
+
return /* @__PURE__ */ i(
|
|
116
|
+
"div",
|
|
117
|
+
{
|
|
118
|
+
"data-spark-component": "rating-display-stars",
|
|
119
|
+
className: l(r === "lg" ? "gap-x-md" : "gap-x-sm", "flex"),
|
|
120
|
+
children: N.map((o, p) => /* @__PURE__ */ i(k, { size: r, value: o }, p))
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
d.displayName = "RatingDisplay.Stars";
|
|
125
|
+
const g = ({ className: t, children: a, ...e }) => {
|
|
126
|
+
const { value: n } = m(), s = z(n), r = typeof a == "function" ? a(s, n) : a ?? s;
|
|
127
|
+
return /* @__PURE__ */ i(
|
|
128
|
+
"span",
|
|
129
|
+
{
|
|
130
|
+
"data-spark-component": "rating-display-value",
|
|
131
|
+
className: l("text-on-surface font-bold", t),
|
|
132
|
+
...e,
|
|
133
|
+
children: r
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
};
|
|
137
|
+
g.displayName = "RatingDisplay.Value";
|
|
138
|
+
const O = Object.assign(R, {
|
|
139
|
+
Stars: d,
|
|
140
|
+
Value: g,
|
|
141
|
+
Count: u
|
|
142
|
+
});
|
|
143
|
+
O.displayName = "RatingDisplay";
|
|
144
|
+
d.displayName = "RatingDisplay.Stars";
|
|
145
|
+
g.displayName = "RatingDisplay.Value";
|
|
146
|
+
u.displayName = "RatingDisplay.Count";
|
|
147
|
+
export {
|
|
148
|
+
O as RatingDisplay
|
|
149
|
+
};
|
|
150
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/rating-display/RatingDisplayContext.tsx","../../src/rating-display/RatingDisplay.tsx","../../src/rating-display/RatingDisplayCount.tsx","../../src/rating-display/RatingDisplayStar.tsx","../../src/rating-display/utils.ts","../../src/rating-display/RatingDisplayStars.tsx","../../src/rating-display/RatingDisplayValue.tsx","../../src/rating-display/index.ts"],"sourcesContent":["import { createContext, type PropsWithChildren, useContext } from 'react'\n\nimport type { RatingDisplayStarProps } from './RatingDisplayStar'\n\ninterface RatingDisplayContextValue {\n value: number\n size: RatingDisplayStarProps['size']\n count?: number\n}\n\nconst RatingDisplayContext = createContext<RatingDisplayContextValue | null>(null)\n\ninterface RatingDisplayProviderProps extends PropsWithChildren<RatingDisplayContextValue> {}\n\nexport const RatingDisplayProvider = ({\n value,\n size,\n count,\n children,\n}: RatingDisplayProviderProps) => {\n return (\n <RatingDisplayContext.Provider value={{ value, size, count }}>\n {children}\n </RatingDisplayContext.Provider>\n )\n}\n\nexport const useRatingDisplay = () => {\n const context = useContext(RatingDisplayContext)\n if (!context) {\n throw new Error('RatingDisplay compound components must be used within RatingDisplay.')\n }\n\n return context\n}\n","import { type ComponentPropsWithRef, type PropsWithChildren } from 'react'\n\nimport { RatingDisplayProvider } from './RatingDisplayContext'\nimport type { RatingDisplayStarProps } from './RatingDisplayStar'\n\nexport interface RatingDisplayProps extends PropsWithChildren<ComponentPropsWithRef<'div'>> {\n /**\n * The rating value to display, on a scale from 0 to 5.\n */\n value?: number\n /**\n * Sets the size of the stars.\n * @default 'md'\n */\n size?: RatingDisplayStarProps['size']\n /**\n * Optional count value available to `RatingDisplay.Count`.\n */\n count?: number\n /**\n * Accessible description of the rating content.\n */\n 'aria-label': string\n}\n\nexport type RatingDisplayRootProps = RatingDisplayProps\n\nexport const RatingDisplay = ({\n value = 0,\n size = 'md',\n count,\n ref,\n children,\n ...rest\n}: RatingDisplayProps) => {\n const ratingValue = value ?? 0\n\n return (\n <RatingDisplayProvider value={ratingValue} size={size} count={count}>\n <div\n ref={ref}\n className=\"gap-x-sm relative inline-flex items-center\"\n data-spark-component=\"rating-display\"\n {...rest}\n >\n {children}\n </div>\n </RatingDisplayProvider>\n )\n}\n\nRatingDisplay.displayName = 'RatingDisplay'\n","import { cx } from 'class-variance-authority'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\n\nexport interface RatingDisplayCountProps extends Omit<ComponentPropsWithRef<'span'>, 'children'> {\n /**\n * Custom count content.\n * Pass a render function to receive the count value and return the content to render.\n */\n children?: ReactNode | ((count: number) => ReactNode)\n}\n\nexport const RatingDisplayCount = ({ className, children, ...rest }: RatingDisplayCountProps) => {\n const { count } = useRatingDisplay()\n if (count === undefined) return null\n const renderedCount = typeof children === 'function' ? children(count) : (children ?? count)\n\n return (\n <span className={cx('text-on-surface/dim-1', className)} {...rest}>\n ({renderedCount})\n </span>\n )\n}\n\nRatingDisplayCount.displayName = 'RatingDisplay.Count'\n","import { StarFill } from '@spark-ui/icons/StarFill'\nimport { StarOutline } from '@spark-ui/icons/StarOutline'\nimport { cva, cx, type VariantProps } from 'class-variance-authority'\n\nimport { Icon } from '../icon'\nimport type { StarValue } from './types'\n\nconst ratingDisplayStarStyles = cva(['relative block after:absolute after:block after:inset-0'], {\n variants: {\n gap: {\n sm: ['after:w-[calc(100%+(var(--spacing-sm)))]', 'last-of-type:after:content-none'],\n md: ['after:w-[calc(100%+(var(--spacing-md)))]', 'last-of-type:after:content-none'],\n },\n },\n defaultVariants: {\n gap: 'sm',\n },\n})\n\nconst ratingDisplayStarIconStyles = cva('', {\n variants: {\n size: {\n sm: 'text-caption-link',\n md: 'text-body-1',\n lg: 'text-display-3',\n },\n design: {\n filled: ['text-main-variant'],\n outlined: ['text-on-surface/dim-3'],\n },\n },\n})\n\ntype RatingDisplayStarstylesProps = Omit<VariantProps<typeof ratingDisplayStarStyles>, never>\ntype RatingDisplayStarIconStylesProps = Omit<\n VariantProps<typeof ratingDisplayStarIconStyles>,\n 'design'\n>\n\nexport interface RatingDisplayStarProps\n extends RatingDisplayStarstylesProps,\n RatingDisplayStarIconStylesProps {\n value: StarValue\n}\n\nexport const RatingDisplayStar = ({ value, size }: RatingDisplayStarProps) => {\n return (\n <div\n data-spark-component=\"rating-display-star\"\n data-part=\"star\"\n className={ratingDisplayStarStyles({\n gap: size === 'lg' ? 'md' : 'sm',\n })}\n >\n <div className={cx('z-raised absolute overflow-hidden')} style={{ width: value * 100 + '%' }}>\n <Icon\n className={ratingDisplayStarIconStyles({\n size,\n design: 'filled',\n })}\n >\n <StarFill />\n </Icon>\n </div>\n\n <Icon className={ratingDisplayStarIconStyles({ size, design: 'outlined' })}>\n <StarOutline />\n </Icon>\n </div>\n )\n}\n","import { type StarValue } from './types'\n\nfunction getNearestHalfDecimal(num: number): number {\n return Math.round(num / 0.5) * 0.5\n}\n\nfunction formatRatingValue(value: number): string {\n const locale = Intl.DateTimeFormat().resolvedOptions().locale\n\n return new Intl.NumberFormat(locale, {\n minimumFractionDigits: 0,\n maximumFractionDigits: 1,\n }).format(value)\n}\n\nfunction getStarValue({ value, index }: { value?: number; index: number }): StarValue {\n if (value === undefined) return 0\n\n const starPosition = index + 1\n const formattedValue = getNearestHalfDecimal(value)\n\n if (Math.ceil(formattedValue) < starPosition) return 0\n\n return formattedValue >= starPosition ? 1 : 0.5\n}\n\nfunction getSingleStarValue(value?: number): StarValue {\n if (value === undefined) return 0\n if (value < 1) return 0\n if (value < 4) return 0.5\n return 1\n}\n\nfunction splitAt<T>(arr: T[], index: number): [T[], T[]] {\n const prev = arr.slice(0, index)\n const next = arr.slice(index)\n\n return [prev, next]\n}\n\nexport { formatRatingValue, getNearestHalfDecimal, getSingleStarValue, getStarValue, splitAt }\n","import { cx } from 'class-variance-authority'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\nimport { RatingDisplayStar, type RatingDisplayStarProps } from './RatingDisplayStar'\nimport type { StarValue } from './types'\nimport { getSingleStarValue, getStarValue } from './utils'\n\nexport interface RatingDisplayStarsProps {\n size?: RatingDisplayStarProps['size']\n /**\n * Sets the rendering mode for stars.\n * @default 'default'\n */\n variant?: 'default' | 'single-star'\n /**\n * Custom fill algorithm for each star.\n * By default, stars are rounded to the nearest 0.5.\n */\n getFillMode?: ({ value, index }: { value?: number; index: number }) => StarValue\n}\n\nexport const RatingDisplayStars = ({\n size,\n variant = 'default',\n getFillMode,\n}: RatingDisplayStarsProps) => {\n const { value, size: contextSize } = useRatingDisplay()\n const resolvedSize = size ?? contextSize\n const getDisplayValue = (index: number) => {\n if (getFillMode) {\n return getFillMode({ index, value })\n }\n\n return variant === 'single-star' ? getSingleStarValue(value) : getStarValue({ index, value })\n }\n\n const stars =\n variant === 'single-star'\n ? [getDisplayValue(0)]\n : Array.from({ length: 5 }, (_, index) => getDisplayValue(index))\n\n return (\n <div\n data-spark-component=\"rating-display-stars\"\n className={cx(resolvedSize === 'lg' ? 'gap-x-md' : 'gap-x-sm', 'flex')}\n >\n {stars.map((starValue, index) => (\n <RatingDisplayStar key={index} size={resolvedSize} value={starValue} />\n ))}\n </div>\n )\n}\n\nRatingDisplayStars.displayName = 'RatingDisplay.Stars'\n","import { cx } from 'class-variance-authority'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { useRatingDisplay } from './RatingDisplayContext'\nimport { formatRatingValue } from './utils'\n\nexport interface RatingDisplayValueProps extends Omit<ComponentPropsWithRef<'span'>, 'children'> {\n /**\n * Custom value content.\n * Pass a render function to receive the formatted value (first arg) and raw value (second arg),\n * then return the content to render.\n */\n children?: ReactNode | ((formattedValue: string, value: number) => ReactNode)\n}\n\nexport const RatingDisplayValue = ({ className, children, ...rest }: RatingDisplayValueProps) => {\n const { value } = useRatingDisplay()\n const formattedValue = formatRatingValue(value)\n const renderedValue =\n typeof children === 'function' ? children(formattedValue, value) : (children ?? formattedValue)\n\n return (\n <span\n data-spark-component=\"rating-display-value\"\n className={cx('text-on-surface font-bold', className)}\n {...rest}\n >\n {renderedValue}\n </span>\n )\n}\n\nRatingDisplayValue.displayName = 'RatingDisplay.Value'\n","import { RatingDisplay as Root } from './RatingDisplay'\nimport { RatingDisplayCount as Count } from './RatingDisplayCount'\nimport { RatingDisplayStars as Stars } from './RatingDisplayStars'\nimport { RatingDisplayValue as Value } from './RatingDisplayValue'\n\nexport const RatingDisplay: typeof Root & {\n Stars: typeof Stars\n Value: typeof Value\n Count: typeof Count\n} = Object.assign(Root, {\n Stars,\n Value,\n Count,\n})\n\nRatingDisplay.displayName = 'RatingDisplay'\nStars.displayName = 'RatingDisplay.Stars'\nValue.displayName = 'RatingDisplay.Value'\nCount.displayName = 'RatingDisplay.Count'\n\nexport { type RatingDisplayProps, type RatingDisplayRootProps } from './RatingDisplay'\nexport { type RatingDisplayStarsProps } from './RatingDisplayStars'\nexport { type RatingDisplayValueProps } from './RatingDisplayValue'\nexport { type RatingDisplayCountProps } from './RatingDisplayCount'\nexport type { StarValue } from './types'\n"],"names":["RatingDisplayContext","createContext","RatingDisplayProvider","value","size","count","children","jsx","useRatingDisplay","context","useContext","RatingDisplay","ref","rest","RatingDisplayCount","className","renderedCount","jsxs","cx","ratingDisplayStarStyles","cva","ratingDisplayStarIconStyles","RatingDisplayStar","Icon","StarFill","StarOutline","getNearestHalfDecimal","num","formatRatingValue","locale","getStarValue","index","starPosition","formattedValue","getSingleStarValue","RatingDisplayStars","variant","getFillMode","contextSize","resolvedSize","getDisplayValue","stars","_","starValue","RatingDisplayValue","renderedValue","Root","Stars","Value","Count"],"mappings":";;;;;;AAUA,MAAMA,IAAuBC,EAAgD,IAAI,GAIpEC,IAAwB,CAAC;AAAA,EACpC,OAAAC;AAAA,EACA,MAAAC;AAAA,EACA,OAAAC;AAAA,EACA,UAAAC;AACF,MAEI,gBAAAC,EAACP,EAAqB,UAArB,EAA8B,OAAO,EAAE,OAAAG,GAAO,MAAAC,GAAM,OAAAC,KAClD,UAAAC,GACH,GAISE,IAAmB,MAAM;AACpC,QAAMC,IAAUC,EAAWV,CAAoB;AAC/C,MAAI,CAACS;AACH,UAAM,IAAI,MAAM,sEAAsE;AAGxF,SAAOA;AACT,GCPaE,IAAgB,CAAC;AAAA,EAC5B,OAAAR,IAAQ;AAAA,EACR,MAAAC,IAAO;AAAA,EACP,OAAAC;AAAA,EACA,KAAAO;AAAA,EACA,UAAAN;AAAA,EACA,GAAGO;AACL,MAII,gBAAAN,EAACL,GAAA,EAAsB,OAHLC,KAAS,GAGgB,MAAAC,GAAY,OAAAC,GACrD,UAAA,gBAAAE;AAAA,EAAC;AAAA,EAAA;AAAA,IACC,KAAAK;AAAA,IACA,WAAU;AAAA,IACV,wBAAqB;AAAA,IACpB,GAAGC;AAAA,IAEH,UAAAP;AAAA,EAAA;AAAA,GAEL;AAIJK,EAAc,cAAc;ACtCrB,MAAMG,IAAqB,CAAC,EAAE,WAAAC,GAAW,UAAAT,GAAU,GAAGO,QAAoC;AAC/F,QAAM,EAAE,OAAAR,EAAA,IAAUG,EAAA;AAClB,MAAIH,MAAU,OAAW,QAAO;AAChC,QAAMW,IAAgB,OAAOV,KAAa,aAAaA,EAASD,CAAK,IAAKC,KAAYD;AAEtF,SACE,gBAAAY,EAAC,UAAK,WAAWC,EAAG,yBAAyBH,CAAS,GAAI,GAAGF,GAAM,UAAA;AAAA,IAAA;AAAA,IAC/DG;AAAA,IA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AAY,MAAM;AAAA,MAEpE,UAAAE,EAAM,IAAI,CAACE,GAAWZ,MACrB,gBAAAxB,EAACe,GAAA,EAA8B,MAAMiB,GAAc,OAAOI,EAAA,GAAlCZ,CAA6C,CACtE;AAAA,IAAA;AAAA,EAAA;AAGP;AAEAI,EAAmB,cAAc;ACtC1B,MAAMS,IAAqB,CAAC,EAAE,WAAA7B,GAAW,UAAAT,GAAU,GAAGO,QAAoC;AAC/F,QAAM,EAAE,OAAAV,EAAA,IAAUK,EAAA,GACZyB,IAAiBL,EAAkBzB,CAAK,GACxC0C,IACJ,OAAOvC,KAAa,aAAaA,EAAS2B,GAAgB9B,CAAK,IAAKG,KAAY2B;AAElF,SACE,gBAAA1B;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,wBAAqB;AAAA,MACrB,WAAWW,EAAG,6BAA6BH,CAAS;AAAA,MACnD,GAAGF;AAAA,MAEH,UAAAgC;AAAA,IAAA;AAAA,EAAA;AAGP;AAEAD,EAAmB,cAAc;AC3B1B,MAAMjC,IAIT,OAAO,OAAOmC,GAAM;AAAA,EAAA,OACtBC;AAAAA,EAAA,OACAC;AAAAA,EAAA,OACAC;AACF,CAAC;AAEDtC,EAAc,cAAc;AAC5BoC,EAAM,cAAc;AACpBC,EAAM,cAAc;AACpBC,EAAM,cAAc;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type StarValue = 0 | 0.5 | 1;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { StarValue } from './types';
|
|
2
|
+
declare function getNearestHalfDecimal(num: number): number;
|
|
3
|
+
declare function formatRatingValue(value: number): string;
|
|
4
|
+
declare function getStarValue({ value, index }: {
|
|
5
|
+
value?: number;
|
|
6
|
+
index: number;
|
|
7
|
+
}): StarValue;
|
|
8
|
+
declare function getSingleStarValue(value?: number): StarValue;
|
|
9
|
+
declare function splitAt<T>(arr: T[], index: number): [T[], T[]];
|
|
10
|
+
export { formatRatingValue, getNearestHalfDecimal, getSingleStarValue, getStarValue, splitAt };
|
package/dist/switch/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),y=require("@spark-ui/components/form-field"),c=require("class-variance-authority"),v=require("react"),D=require("@spark-ui/hooks/use-combined-state"),$=require("@spark-ui/icons/Check"),L=require("@spark-ui/icons/Close"),w=require("radix-ui"),k=require("../Slot-DQ8z2zsy.js"),a=require("@spark-ui/internal-utils"),P=require("../label/index.js"),T=c.cva(a.tw(["relative shrink-0 self-baseline","cursor-pointer","rounded-full border-transparent","hover:ring-4","transition-colors duration-200 ease-in-out","disabled:hover:ring-transparent disabled:cursor-not-allowed disabled:opacity-dim-3","focus-visible:u-outline","data-[state=unchecked]:bg-on-surface/dim-3","u-shadow-border-transition","overflow-x-hidden"]),{variants:{size:a.makeVariants({sm:a.tw(["h-sz-24","w-sz-40","border-md"]),md:a.tw(["h-sz-32","w-sz-56","border-[4px]"])}),intent:a.makeVariants({main:["data-[state=checked]:bg-main","hover:ring-main-container","text-main"],support:["data-[state=checked]:bg-support","hover:ring-support-container","text-support"],accent:["data-[state=checked]:bg-accent","hover:ring-accent-container","text-accent"],basic:["data-[state=checked]:bg-basic","hover:ring-basic-container","text-basic"],success:["data-[state=checked]:bg-success","hover:ring-success-container","text-success"],alert:["data-[state=checked]:bg-alert","hover:ring-alert-container","text-alert"],error:["data-[state=checked]:bg-error","hover:ring-error-container","text-error"],info:["data-[state=checked]:bg-info","hover:ring-info-container","text-info"],neutral:["data-[state=checked]:bg-neutral","hover:ring-neutral-container","text-neutral"]})},defaultVariants:{intent:"basic",size:"sm"}}),U=c.cva(["pointer-events-none absolute inset-0 flex items-center","transition-all duration-200 ease-in-out"],{variants:{checked:{true:"translate-x-full",false:"translate-x-0"}}}),A=c.cva(["absolute left-0 top-0 flex items-center justify-center","bg-surface","rounded-full","ring-0","transition-all duration-200 ease-in-out"],{variants:{size:a.makeVariants({sm:["h-sz-20","w-sz-20"],md:["h-sz-24","w-sz-24"]}),checked:{true:"-translate-x-full",false:"translate-x-0 text-on-surface/dim-2"}},defaultVariants:{size:"sm",checked:!1}}),S=c.cva(["transition-opacity duration-200"],{variants:{size:a.makeVariants({sm:["h-sz-10 w-sz-10"],md:["h-sz-12 w-sz-12"]})},defaultVariants:{size:"sm"}}),z=({checked:n,checkedIcon:t=e.jsx($.Check,{}),defaultChecked:r,intent:m,uncheckedIcon:o=e.jsx(L.Close,{}),size:i="md",value:b="on",onCheckedChange:x,className:l,required:d,ref:p,...u})=>{const[s,h]=D.useCombinedState(n,r),{name:f,description:q,state:I,isRequired:F,isInvalid:N}=y.useFormFieldControl(),V=I??m,R=g=>{h(g),x?.(g)};return e.jsx(w.Switch.Root,{"data-spark-component":"switch-input",ref:p,className:T({intent:V,size:i,className:l}),value:b,checked:n,defaultChecked:r,onCheckedChange:R,name:f,required:d||F,"aria-invalid":N,"aria-describedby":q,...u,children:e.jsx("span",{className:U({checked:s}),children:e.jsxs(w.Switch.Thumb,{className:A({size:i,checked:s}),children:[s&&t&&e.jsx(k.Slot,{className:S({size:i}),children:t}),!s&&o&&e.jsx(k.Slot,{className:S({size:i}),children:o})]})})})};z.displayName="SwitchInput";const E=c.cva("",{variants:{disabled:{true:["text-neutral/dim-2","cursor-not-allowed"],false:["cursor-pointer"]}},defaultVariants:{disabled:!1}}),G=({className:n,disabled:t,...r})=>e.jsx(P.Label,{"data-spark-component":"switch-label",className:E({disabled:t,className:n}),...r}),j=":switch",C=({size:n="md",children:t,className:r,id:m,disabled:o,reverse:i=!1,ref:b,...x})=>{const l=y.useFormFieldControl(),d=`${j}-label-${v.useId()}`,p=`${j}-input-${v.useId()}`,u=l.id||m||p,s=t&&e.jsx(G,{disabled:o,htmlFor:u,id:d,children:t}),h=e.jsx(z,{ref:b,size:n,id:u,disabled:o,"aria-labelledby":t?d:l.labelId,...x}),f=i?e.jsxs(e.Fragment,{children:[s,h]}):e.jsxs(e.Fragment,{children:[h,s]});return e.jsx("div",{"data-spark-component":"switch",className:c.cx("gap-md text-body-1 flex items-center",r),children:f})};C.displayName="Switch";exports.Switch=C;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),y=require("@spark-ui/components/form-field"),c=require("class-variance-authority"),v=require("react"),D=require("@spark-ui/hooks/use-combined-state"),$=require("@spark-ui/icons/Check"),L=require("@spark-ui/icons/Close"),w=require("radix-ui"),k=require("../Slot-DQ8z2zsy.js"),a=require("@spark-ui/internal-utils"),P=require("../label/index.js"),T=c.cva(a.tw(["relative shrink-0 self-baseline","cursor-pointer","rounded-full border-transparent","hover:ring-4","transition-colors duration-200 ease-in-out","disabled:hover:ring-transparent disabled:cursor-not-allowed disabled:opacity-dim-3","focus-visible:u-outline","data-[state=unchecked]:bg-on-surface/dim-3","u-shadow-border-transition","overflow-x-hidden"]),{variants:{size:a.makeVariants({sm:a.tw(["h-sz-24","w-sz-40","border-md"]),md:a.tw(["h-sz-32","w-sz-56","border-[4px]"])}),intent:a.makeVariants({main:["data-[state=checked]:bg-main","hover:ring-main-container","text-main"],support:["data-[state=checked]:bg-support","hover:ring-support-container","text-support"],accent:["data-[state=checked]:bg-accent","hover:ring-accent-container","text-accent"],basic:["data-[state=checked]:bg-basic","hover:ring-basic-container","text-basic"],success:["data-[state=checked]:bg-success","hover:ring-success-container","text-success"],alert:["data-[state=checked]:bg-alert","hover:ring-alert-container","text-alert"],error:["data-[state=checked]:bg-error","hover:ring-error-container","text-error"],info:["data-[state=checked]:bg-info","hover:ring-info-container","text-info"],neutral:["data-[state=checked]:bg-neutral","hover:ring-neutral-container","text-neutral"]})},defaultVariants:{intent:"basic",size:"sm"}}),U=c.cva(["pointer-events-none absolute inset-0 flex items-center","transition-all duration-200 ease-in-out"],{variants:{checked:{true:"translate-x-full",false:"translate-x-0"}}}),A=c.cva(["absolute left-0 top-0 flex items-center justify-center","bg-surface","rounded-full","ring-0","transition-all duration-200 ease-in-out"],{variants:{size:a.makeVariants({sm:["h-sz-20","w-sz-20"],md:["h-sz-24","w-sz-24"]}),checked:{true:"-translate-x-full",false:"translate-x-0 text-on-surface/dim-2"}},defaultVariants:{size:"sm",checked:!1}}),S=c.cva(["transition-opacity duration-200"],{variants:{size:a.makeVariants({sm:["h-sz-10 w-sz-10"],md:["h-sz-12 w-sz-12"]})},defaultVariants:{size:"sm"}}),z=({checked:n,checkedIcon:t=e.jsx($.Check,{}),defaultChecked:r,intent:m,uncheckedIcon:o=e.jsx(L.Close,{}),size:i="md",value:b="on",onCheckedChange:x,className:l,required:d,ref:p,...u})=>{const[s,h]=D.useCombinedState(n,r),{name:f,description:q,state:I,isRequired:F,isInvalid:N}=y.useFormFieldControl(),V=I??m,R=g=>{h(g),x?.(g)};return e.jsx(w.Switch.Root,{"data-spark-component":"switch-input",ref:p,className:T({intent:V,size:i,className:l}),value:b,checked:n,defaultChecked:r,onCheckedChange:R,name:f,required:d||F,"aria-invalid":N,"aria-describedby":q,...u,children:e.jsx("span",{className:U({checked:s}),children:e.jsxs(w.Switch.Thumb,{className:A({size:i,checked:s}),children:[s&&t&&e.jsx(k.Slot,{className:S({size:i}),children:t}),!s&&o&&e.jsx(k.Slot,{className:S({size:i}),children:o})]})})})};z.displayName="SwitchInput";const E=c.cva("default:text-on-surface",{variants:{disabled:{true:["text-neutral/dim-2","cursor-not-allowed"],false:["cursor-pointer"]}},defaultVariants:{disabled:!1}}),G=({className:n,disabled:t,...r})=>e.jsx(P.Label,{"data-spark-component":"switch-label",className:E({disabled:t,className:n}),...r}),j=":switch",C=({size:n="md",children:t,className:r,id:m,disabled:o,reverse:i=!1,ref:b,...x})=>{const l=y.useFormFieldControl(),d=`${j}-label-${v.useId()}`,p=`${j}-input-${v.useId()}`,u=l.id||m||p,s=t&&e.jsx(G,{disabled:o,htmlFor:u,id:d,children:t}),h=e.jsx(z,{ref:b,size:n,id:u,disabled:o,"aria-labelledby":t?d:l.labelId,...x}),f=i?e.jsxs(e.Fragment,{children:[s,h]}):e.jsxs(e.Fragment,{children:[h,s]});return e.jsx("div",{"data-spark-component":"switch",className:c.cx("gap-md text-body-1 flex items-center",r),children:f})};C.displayName="Switch";exports.Switch=C;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/switch/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/switch/SwitchInput.styles.ts","../../src/switch/SwitchInput.tsx","../../src/switch/SwitchLabel.styles.ts","../../src/switch/SwitchLabel.tsx","../../src/switch/Switch.tsx"],"sourcesContent":["import { makeVariants, tw } from '@spark-ui/internal-utils'\nimport { cva, VariantProps } from 'class-variance-authority'\n\nexport const styles = cva(\n tw([\n 'relative shrink-0 self-baseline',\n 'cursor-pointer',\n 'rounded-full border-transparent',\n 'hover:ring-4',\n 'transition-colors duration-200 ease-in-out',\n 'disabled:hover:ring-transparent disabled:cursor-not-allowed disabled:opacity-dim-3',\n 'focus-visible:u-outline',\n 'data-[state=unchecked]:bg-on-surface/dim-3',\n 'u-shadow-border-transition',\n 'overflow-x-hidden',\n ]),\n {\n variants: {\n /**\n * Size of the switch input.\n */\n size: makeVariants<'size', ['sm', 'md']>({\n sm: tw(['h-sz-24', 'w-sz-40', 'border-md']),\n md: tw(['h-sz-32', 'w-sz-56', 'border-[4px]']),\n }),\n /**\n * Color scheme of the switch input.\n */\n intent: makeVariants<\n 'intent',\n ['main', 'support', 'accent', 'basic', 'success', 'alert', 'error', 'info', 'neutral']\n >({\n main: ['data-[state=checked]:bg-main', 'hover:ring-main-container', 'text-main'],\n support: [\n 'data-[state=checked]:bg-support',\n 'hover:ring-support-container',\n 'text-support',\n ],\n accent: ['data-[state=checked]:bg-accent', 'hover:ring-accent-container', 'text-accent'],\n basic: ['data-[state=checked]:bg-basic', 'hover:ring-basic-container', 'text-basic'],\n success: [\n 'data-[state=checked]:bg-success',\n 'hover:ring-success-container',\n 'text-success',\n ],\n alert: ['data-[state=checked]:bg-alert', 'hover:ring-alert-container', 'text-alert'],\n error: ['data-[state=checked]:bg-error', 'hover:ring-error-container', 'text-error'],\n info: ['data-[state=checked]:bg-info', 'hover:ring-info-container', 'text-info'],\n neutral: [\n 'data-[state=checked]:bg-neutral',\n 'hover:ring-neutral-container',\n 'text-neutral',\n ],\n }),\n },\n defaultVariants: {\n intent: 'basic',\n size: 'sm',\n },\n }\n)\n\nexport type StylesProps = VariantProps<typeof styles>\n\nexport const thumbWrapperStyles = cva(\n [\n 'pointer-events-none absolute inset-0 flex items-center',\n 'transition-all duration-200 ease-in-out',\n ],\n {\n variants: {\n checked: {\n true: 'translate-x-full',\n false: 'translate-x-0',\n },\n },\n }\n)\n\nexport const thumbStyles = cva(\n [\n 'absolute left-0 top-0 flex items-center justify-center',\n 'bg-surface',\n 'rounded-full',\n 'ring-0',\n 'transition-all duration-200 ease-in-out',\n ],\n {\n variants: {\n size: makeVariants<'size', ['sm', 'md']>({\n sm: ['h-sz-20', 'w-sz-20'],\n md: ['h-sz-24', 'w-sz-24'],\n }),\n checked: {\n true: '-translate-x-full',\n false: 'translate-x-0 text-on-surface/dim-2',\n },\n },\n defaultVariants: {\n size: 'sm',\n checked: false,\n },\n }\n)\n\nexport const thumbCheckSVGStyles = cva(['transition-opacity duration-200'], {\n variants: {\n size: makeVariants<'size', ['sm', 'md']>({\n sm: ['h-sz-10 w-sz-10'],\n md: ['h-sz-12 w-sz-12'],\n }),\n },\n defaultVariants: {\n size: 'sm',\n },\n})\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { useCombinedState } from '@spark-ui/hooks/use-combined-state'\nimport { Check } from '@spark-ui/icons/Check'\nimport { Close } from '@spark-ui/icons/Close'\nimport { Switch as RadixSwitch } from 'radix-ui'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { Slot } from '../slot'\nimport {\n styles,\n type StylesProps,\n thumbCheckSVGStyles,\n thumbStyles,\n thumbWrapperStyles,\n} from './SwitchInput.styles'\n\nexport interface SwitchInputProps\n extends StylesProps,\n Omit<ComponentPropsWithRef<'button'>, 'value'> {\n /**\n * The state of the switch when it is initially rendered. Use when you do not need to control its state.\n */\n defaultChecked?: boolean\n /**\n * The controlled state of the switch. Must be used in conjunction with `onCheckedChange`.\n */\n checked?: boolean\n /**\n * When true, prevents the user from interacting with the switch.\n */\n /**\n * Event handler called when the state of the switch changes.\n */\n onCheckedChange?: (checked: boolean) => void\n /**\n * When `true`, prevents the user from interacting with the switch.\n */\n disabled?: boolean\n /**\n * When true, indicates that the user must check the switch before the owning form can be submitted.\n */\n required?: boolean\n /**\n * The name of the switch. Submitted with its owning form as part of a name/value pair.\n */\n name?: string\n /**\n * The value given as data when submitted with a name.\n */\n value?: string\n /**\n * Icon shown inside the thumb of the Switch whenever it is checked\n */\n checkedIcon?: ReactNode\n /**\n * Icon shown inside the thumb of the Switch whenever it is unchecked\n */\n uncheckedIcon?: ReactNode\n /**\n * When true, the label will be placed on the left side of the Switch\n */\n reverse?: boolean\n}\n\nexport const SwitchInput = ({\n checked,\n checkedIcon = <Check />,\n defaultChecked,\n intent: intentProp,\n uncheckedIcon = <Close />,\n size = 'md',\n value = 'on',\n onCheckedChange,\n className,\n required,\n ref,\n ...rest\n}: SwitchInputProps) => {\n const [isChecked, setIsChecked] = useCombinedState(checked, defaultChecked)\n const { name, description, state, isRequired, isInvalid } = useFormFieldControl()\n const intent = state ?? intentProp\n\n const handleCheckedChange = (updatedValue: boolean): void => {\n setIsChecked(updatedValue)\n onCheckedChange?.(updatedValue)\n }\n\n return (\n <RadixSwitch.Root\n data-spark-component=\"switch-input\"\n ref={ref}\n className={styles({ intent, size, className })}\n value={value}\n checked={checked}\n defaultChecked={defaultChecked}\n onCheckedChange={handleCheckedChange}\n name={name}\n required={required || isRequired}\n aria-invalid={isInvalid}\n aria-describedby={description}\n {...rest}\n >\n <span className={thumbWrapperStyles({ checked: isChecked })}>\n <RadixSwitch.Thumb className={thumbStyles({ size, checked: isChecked })}>\n {isChecked && checkedIcon && (\n <Slot className={thumbCheckSVGStyles({ size })}>{checkedIcon}</Slot>\n )}\n {!isChecked && uncheckedIcon && (\n <Slot className={thumbCheckSVGStyles({ size })}>{uncheckedIcon}</Slot>\n )}\n </RadixSwitch.Thumb>\n </span>\n </RadixSwitch.Root>\n )\n}\n\nSwitchInput.displayName = 'SwitchInput'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const labelStyles = cva('', {\n variants: {\n disabled: {\n true: ['text-neutral/dim-2', 'cursor-not-allowed'],\n false: ['cursor-pointer'],\n },\n },\n defaultVariants: {\n disabled: false,\n },\n})\n\nexport type LabelStylesProps = VariantProps<typeof labelStyles>\n","import { Label, LabelProps } from '../label'\nimport { labelStyles, LabelStylesProps } from './SwitchLabel.styles'\n\nexport interface SwitchLabelProps extends LabelStylesProps, LabelProps {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * The id of the element the label is associated with.\n */\n htmlFor?: string\n /**\n * When true, prevents the user from interacting with the switch item.\n */\n disabled?: boolean\n}\n\nexport const SwitchLabel = ({ className, disabled, ...others }: SwitchLabelProps) => (\n <Label\n data-spark-component=\"switch-label\"\n className={labelStyles({ disabled, className })}\n {...others}\n />\n)\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { cx } from 'class-variance-authority'\nimport { useId } from 'react'\n\nimport { SwitchInput, SwitchInputProps } from './SwitchInput'\nimport { SwitchLabel } from './SwitchLabel'\n\nexport type SwitchProps = SwitchInputProps\n\nconst ID_PREFIX = ':switch'\n\nexport const Switch = ({\n size = 'md',\n children,\n className,\n id,\n disabled,\n reverse = false,\n ref,\n ...rest\n}: SwitchProps) => {\n const field = useFormFieldControl()\n\n const labelID = `${ID_PREFIX}-label-${useId()}`\n const innerID = `${ID_PREFIX}-input-${useId()}`\n const fieldID = field.id || id || innerID\n\n const switchLabel = children && (\n <SwitchLabel disabled={disabled} htmlFor={fieldID} id={labelID}>\n {children}\n </SwitchLabel>\n )\n\n const switchInput = (\n <SwitchInput\n ref={ref}\n size={size}\n id={fieldID}\n disabled={disabled}\n /**\n * If the switch doesn't have any direct label (children) then we should try to\n * get an eventual alternative label from FormField.\n * On last resort, we shouldn't forget to define an aria-label attribute.\n */\n aria-labelledby={children ? labelID : field.labelId}\n {...rest}\n />\n )\n\n const content = reverse ? (\n <>\n {switchLabel}\n {switchInput}\n </>\n ) : (\n <>\n {switchInput}\n {switchLabel}\n </>\n )\n\n return (\n <div\n data-spark-component=\"switch\"\n className={cx('gap-md text-body-1 flex items-center', className)}\n >\n {content}\n </div>\n )\n}\n\nSwitch.displayName = 'Switch'\n"],"names":["styles","cva","tw","makeVariants","thumbWrapperStyles","thumbStyles","thumbCheckSVGStyles","SwitchInput","checked","checkedIcon","Check","defaultChecked","intentProp","uncheckedIcon","Close","size","value","onCheckedChange","className","required","ref","rest","isChecked","setIsChecked","useCombinedState","name","description","state","isRequired","isInvalid","useFormFieldControl","intent","handleCheckedChange","updatedValue","jsx","RadixSwitch","jsxs","Slot","labelStyles","SwitchLabel","disabled","others","Label","ID_PREFIX","Switch","children","id","reverse","field","labelID","useId","innerID","fieldID","switchLabel","switchInput","content","Fragment","cx"],"mappings":"6cAGaA,EAASC,EAAAA,IACpBC,KAAG,CACD,kCACA,iBACA,kCACA,eACA,6CACA,qFACA,0BACA,6CACA,6BACA,mBAAA,CACD,EACD,CACE,SAAU,CAIR,KAAMC,EAAAA,aAAmC,CACvC,GAAID,EAAAA,GAAG,CAAC,UAAW,UAAW,WAAW,CAAC,EAC1C,GAAIA,EAAAA,GAAG,CAAC,UAAW,UAAW,cAAc,CAAC,CAAA,CAC9C,EAID,OAAQC,EAAAA,aAGN,CACA,KAAM,CAAC,+BAAgC,4BAA6B,WAAW,EAC/E,QAAS,CACP,kCACA,+BACA,cAAA,EAEF,OAAQ,CAAC,iCAAkC,8BAA+B,aAAa,EACvF,MAAO,CAAC,gCAAiC,6BAA8B,YAAY,EACnF,QAAS,CACP,kCACA,+BACA,cAAA,EA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AY,UAELC,EAAS,CAAC,CACrB,KAAA7B,EAAO,KACP,SAAA8B,EACA,UAAA3B,EACA,GAAA4B,EACA,SAAAN,EACA,QAAAO,EAAU,GACV,IAAA3B,EACA,GAAGC,CACL,IAAmB,CACjB,MAAM2B,EAAQlB,EAAAA,oBAAA,EAERmB,EAAU,GAAGN,CAAS,UAAUO,EAAAA,OAAO,GACvCC,EAAU,GAAGR,CAAS,UAAUO,EAAAA,OAAO,GACvCE,EAAUJ,EAAM,IAAMF,GAAMK,EAE5BE,EAAcR,GAClBX,EAAAA,IAACK,EAAA,CAAY,SAAAC,EAAoB,QAASY,EAAS,GAAIH,EACpD,SAAAJ,CAAA,CACH,EAGIS,EACJpB,EAAAA,IAAC3B,EAAA,CACC,IAAAa,EACA,KAAAL,EACA,GAAIqC,EACJ,SAAAZ,EAMA,kBAAiBK,EAAWI,EAAUD,EAAM,QAC3C,GAAG3B,CAAA,CAAA,EAIFkC,EAAUR,EACdX,EAAAA,KAAAoB,EAAAA,SAAA,CACG,SAAA,CAAAH,EACAC,CAAA,CAAA,CACH,EAEAlB,EAAAA,KAAAoB,EAAAA,SAAA,CACG,SAAA,CAAAF,EACAD,CAAA,EACH,EAGF,OACEnB,EAAAA,IAAC,MAAA,CACC,uBAAqB,SACrB,UAAWuB,EAAAA,GAAG,uCAAwCvC,CAAS,EAE9D,SAAAqC,CAAA,CAAA,CAGP,EAEAX,EAAO,YAAc"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/switch/SwitchInput.styles.ts","../../src/switch/SwitchInput.tsx","../../src/switch/SwitchLabel.styles.ts","../../src/switch/SwitchLabel.tsx","../../src/switch/Switch.tsx"],"sourcesContent":["import { makeVariants, tw } from '@spark-ui/internal-utils'\nimport { cva, VariantProps } from 'class-variance-authority'\n\nexport const styles = cva(\n tw([\n 'relative shrink-0 self-baseline',\n 'cursor-pointer',\n 'rounded-full border-transparent',\n 'hover:ring-4',\n 'transition-colors duration-200 ease-in-out',\n 'disabled:hover:ring-transparent disabled:cursor-not-allowed disabled:opacity-dim-3',\n 'focus-visible:u-outline',\n 'data-[state=unchecked]:bg-on-surface/dim-3',\n 'u-shadow-border-transition',\n 'overflow-x-hidden',\n ]),\n {\n variants: {\n /**\n * Size of the switch input.\n */\n size: makeVariants<'size', ['sm', 'md']>({\n sm: tw(['h-sz-24', 'w-sz-40', 'border-md']),\n md: tw(['h-sz-32', 'w-sz-56', 'border-[4px]']),\n }),\n /**\n * Color scheme of the switch input.\n */\n intent: makeVariants<\n 'intent',\n ['main', 'support', 'accent', 'basic', 'success', 'alert', 'error', 'info', 'neutral']\n >({\n main: ['data-[state=checked]:bg-main', 'hover:ring-main-container', 'text-main'],\n support: [\n 'data-[state=checked]:bg-support',\n 'hover:ring-support-container',\n 'text-support',\n ],\n accent: ['data-[state=checked]:bg-accent', 'hover:ring-accent-container', 'text-accent'],\n basic: ['data-[state=checked]:bg-basic', 'hover:ring-basic-container', 'text-basic'],\n success: [\n 'data-[state=checked]:bg-success',\n 'hover:ring-success-container',\n 'text-success',\n ],\n alert: ['data-[state=checked]:bg-alert', 'hover:ring-alert-container', 'text-alert'],\n error: ['data-[state=checked]:bg-error', 'hover:ring-error-container', 'text-error'],\n info: ['data-[state=checked]:bg-info', 'hover:ring-info-container', 'text-info'],\n neutral: [\n 'data-[state=checked]:bg-neutral',\n 'hover:ring-neutral-container',\n 'text-neutral',\n ],\n }),\n },\n defaultVariants: {\n intent: 'basic',\n size: 'sm',\n },\n }\n)\n\nexport type StylesProps = VariantProps<typeof styles>\n\nexport const thumbWrapperStyles = cva(\n [\n 'pointer-events-none absolute inset-0 flex items-center',\n 'transition-all duration-200 ease-in-out',\n ],\n {\n variants: {\n checked: {\n true: 'translate-x-full',\n false: 'translate-x-0',\n },\n },\n }\n)\n\nexport const thumbStyles = cva(\n [\n 'absolute left-0 top-0 flex items-center justify-center',\n 'bg-surface',\n 'rounded-full',\n 'ring-0',\n 'transition-all duration-200 ease-in-out',\n ],\n {\n variants: {\n size: makeVariants<'size', ['sm', 'md']>({\n sm: ['h-sz-20', 'w-sz-20'],\n md: ['h-sz-24', 'w-sz-24'],\n }),\n checked: {\n true: '-translate-x-full',\n false: 'translate-x-0 text-on-surface/dim-2',\n },\n },\n defaultVariants: {\n size: 'sm',\n checked: false,\n },\n }\n)\n\nexport const thumbCheckSVGStyles = cva(['transition-opacity duration-200'], {\n variants: {\n size: makeVariants<'size', ['sm', 'md']>({\n sm: ['h-sz-10 w-sz-10'],\n md: ['h-sz-12 w-sz-12'],\n }),\n },\n defaultVariants: {\n size: 'sm',\n },\n})\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { useCombinedState } from '@spark-ui/hooks/use-combined-state'\nimport { Check } from '@spark-ui/icons/Check'\nimport { Close } from '@spark-ui/icons/Close'\nimport { Switch as RadixSwitch } from 'radix-ui'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { Slot } from '../slot'\nimport {\n styles,\n type StylesProps,\n thumbCheckSVGStyles,\n thumbStyles,\n thumbWrapperStyles,\n} from './SwitchInput.styles'\n\nexport interface SwitchInputProps\n extends StylesProps,\n Omit<ComponentPropsWithRef<'button'>, 'value'> {\n /**\n * The state of the switch when it is initially rendered. Use when you do not need to control its state.\n */\n defaultChecked?: boolean\n /**\n * The controlled state of the switch. Must be used in conjunction with `onCheckedChange`.\n */\n checked?: boolean\n /**\n * When true, prevents the user from interacting with the switch.\n */\n /**\n * Event handler called when the state of the switch changes.\n */\n onCheckedChange?: (checked: boolean) => void\n /**\n * When `true`, prevents the user from interacting with the switch.\n */\n disabled?: boolean\n /**\n * When true, indicates that the user must check the switch before the owning form can be submitted.\n */\n required?: boolean\n /**\n * The name of the switch. Submitted with its owning form as part of a name/value pair.\n */\n name?: string\n /**\n * The value given as data when submitted with a name.\n */\n value?: string\n /**\n * Icon shown inside the thumb of the Switch whenever it is checked\n */\n checkedIcon?: ReactNode\n /**\n * Icon shown inside the thumb of the Switch whenever it is unchecked\n */\n uncheckedIcon?: ReactNode\n /**\n * When true, the label will be placed on the left side of the Switch\n */\n reverse?: boolean\n}\n\nexport const SwitchInput = ({\n checked,\n checkedIcon = <Check />,\n defaultChecked,\n intent: intentProp,\n uncheckedIcon = <Close />,\n size = 'md',\n value = 'on',\n onCheckedChange,\n className,\n required,\n ref,\n ...rest\n}: SwitchInputProps) => {\n const [isChecked, setIsChecked] = useCombinedState(checked, defaultChecked)\n const { name, description, state, isRequired, isInvalid } = useFormFieldControl()\n const intent = state ?? intentProp\n\n const handleCheckedChange = (updatedValue: boolean): void => {\n setIsChecked(updatedValue)\n onCheckedChange?.(updatedValue)\n }\n\n return (\n <RadixSwitch.Root\n data-spark-component=\"switch-input\"\n ref={ref}\n className={styles({ intent, size, className })}\n value={value}\n checked={checked}\n defaultChecked={defaultChecked}\n onCheckedChange={handleCheckedChange}\n name={name}\n required={required || isRequired}\n aria-invalid={isInvalid}\n aria-describedby={description}\n {...rest}\n >\n <span className={thumbWrapperStyles({ checked: isChecked })}>\n <RadixSwitch.Thumb className={thumbStyles({ size, checked: isChecked })}>\n {isChecked && checkedIcon && (\n <Slot className={thumbCheckSVGStyles({ size })}>{checkedIcon}</Slot>\n )}\n {!isChecked && uncheckedIcon && (\n <Slot className={thumbCheckSVGStyles({ size })}>{uncheckedIcon}</Slot>\n )}\n </RadixSwitch.Thumb>\n </span>\n </RadixSwitch.Root>\n )\n}\n\nSwitchInput.displayName = 'SwitchInput'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const labelStyles = cva('default:text-on-surface', {\n variants: {\n disabled: {\n true: ['text-neutral/dim-2', 'cursor-not-allowed'],\n false: ['cursor-pointer'],\n },\n },\n defaultVariants: {\n disabled: false,\n },\n})\n\nexport type LabelStylesProps = VariantProps<typeof labelStyles>\n","import { Label, LabelProps } from '../label'\nimport { labelStyles, LabelStylesProps } from './SwitchLabel.styles'\n\nexport interface SwitchLabelProps extends LabelStylesProps, LabelProps {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * The id of the element the label is associated with.\n */\n htmlFor?: string\n /**\n * When true, prevents the user from interacting with the switch item.\n */\n disabled?: boolean\n}\n\nexport const SwitchLabel = ({ className, disabled, ...others }: SwitchLabelProps) => (\n <Label\n data-spark-component=\"switch-label\"\n className={labelStyles({ disabled, className })}\n {...others}\n />\n)\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { cx } from 'class-variance-authority'\nimport { useId } from 'react'\n\nimport { SwitchInput, SwitchInputProps } from './SwitchInput'\nimport { SwitchLabel } from './SwitchLabel'\n\nexport type SwitchProps = SwitchInputProps\n\nconst ID_PREFIX = ':switch'\n\nexport const Switch = ({\n size = 'md',\n children,\n className,\n id,\n disabled,\n reverse = false,\n ref,\n ...rest\n}: SwitchProps) => {\n const field = useFormFieldControl()\n\n const labelID = `${ID_PREFIX}-label-${useId()}`\n const innerID = `${ID_PREFIX}-input-${useId()}`\n const fieldID = field.id || id || innerID\n\n const switchLabel = children && (\n <SwitchLabel disabled={disabled} htmlFor={fieldID} id={labelID}>\n {children}\n </SwitchLabel>\n )\n\n const switchInput = (\n <SwitchInput\n ref={ref}\n size={size}\n id={fieldID}\n disabled={disabled}\n /**\n * If the switch doesn't have any direct label (children) then we should try to\n * get an eventual alternative label from FormField.\n * On last resort, we shouldn't forget to define an aria-label attribute.\n */\n aria-labelledby={children ? labelID : field.labelId}\n {...rest}\n />\n )\n\n const content = reverse ? (\n <>\n {switchLabel}\n {switchInput}\n </>\n ) : (\n <>\n {switchInput}\n {switchLabel}\n </>\n )\n\n return (\n <div\n data-spark-component=\"switch\"\n className={cx('gap-md text-body-1 flex items-center', className)}\n >\n {content}\n </div>\n )\n}\n\nSwitch.displayName = 'Switch'\n"],"names":["styles","cva","tw","makeVariants","thumbWrapperStyles","thumbStyles","thumbCheckSVGStyles","SwitchInput","checked","checkedIcon","Check","defaultChecked","intentProp","uncheckedIcon","Close","size","value","onCheckedChange","className","required","ref","rest","isChecked","setIsChecked","useCombinedState","name","description","state","isRequired","isInvalid","useFormFieldControl","intent","handleCheckedChange","updatedValue","jsx","RadixSwitch","jsxs","Slot","labelStyles","SwitchLabel","disabled","others","Label","ID_PREFIX","Switch","children","id","reverse","field","labelID","useId","innerID","fieldID","switchLabel","switchInput","content","Fragment","cx"],"mappings":"6cAGaA,EAASC,EAAAA,IACpBC,KAAG,CACD,kCACA,iBACA,kCACA,eACA,6CACA,qFACA,0BACA,6CACA,6BACA,mBAAA,CACD,EACD,CACE,SAAU,CAIR,KAAMC,EAAAA,aAAmC,CACvC,GAAID,EAAAA,GAAG,CAAC,UAAW,UAAW,WAAW,CAAC,EAC1C,GAAIA,EAAAA,GAAG,CAAC,UAAW,UAAW,cAAc,CAAC,CAAA,CAC9C,EAID,OAAQC,EAAAA,aAGN,CACA,KAAM,CAAC,+BAAgC,4BAA6B,WAAW,EAC/E,QAAS,CACP,kCACA,+BACA,cAAA,EAEF,OAAQ,CAAC,iCAAkC,8BAA+B,aAAa,EACvF,MAAO,CAAC,gCAAiC,6BAA8B,YAAY,EACnF,QAAS,CACP,kCACA,+BACA,cAAA,EAEF,MAAO,CAAC,gCAAiC,6BAA8B,YAAY,EACnF,MAAO,CAAC,gCAAiC,6BAA8B,YAAY,EACnF,KAAM,CAAC,+BAAgC,4BAA6B,WAAW,EAC/E,QAAS,CACP,kCACA,+BACA,cAAA,CACF,CACD,CAAA,EAEH,gBAAiB,CACf,OAAQ,QACR,KAAM,IAAA,CACR,CAEJ,EAIaC,EAAqBH,EAAAA,IAChC,CACE,yDACA,yCAAA,EAEF,CACE,SAAU,CACR,QAAS,CACP,KAAM,mBACN,MAAO,eAAA,CACT,CACF,CAEJ,EAEaI,EAAcJ,EAAAA,IACzB,CACE,yDACA,aACA,eACA,SACA,yCAAA,EAEF,CACE,SAAU,CACR,KAAME,EAAAA,aAAmC,CACvC,GAAI,CAAC,UAAW,SAAS,EACzB,GAAI,CAAC,UAAW,SAAS,CAAA,CAC1B,EACD,QAAS,CACP,KAAM,oBACN,M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3C,GAAG3B,CAAA,CAAA,EAIFkC,EAAUR,EACdX,EAAAA,KAAAoB,EAAAA,SAAA,CACG,SAAA,CAAAH,EACAC,CAAA,CAAA,CACH,EAEAlB,EAAAA,KAAAoB,EAAAA,SAAA,CACG,SAAA,CAAAF,EACAD,CAAA,EACH,EAGF,OACEnB,EAAAA,IAAC,MAAA,CACC,uBAAqB,SACrB,UAAWuB,EAAAA,GAAG,uCAAwCvC,CAAS,EAE9D,SAAAqC,CAAA,CAAA,CAGP,EAEAX,EAAO,YAAc"}
|
package/dist/switch/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/switch/SwitchInput.styles.ts","../../src/switch/SwitchInput.tsx","../../src/switch/SwitchLabel.styles.ts","../../src/switch/SwitchLabel.tsx","../../src/switch/Switch.tsx"],"sourcesContent":["import { makeVariants, tw } from '@spark-ui/internal-utils'\nimport { cva, VariantProps } from 'class-variance-authority'\n\nexport const styles = cva(\n tw([\n 'relative shrink-0 self-baseline',\n 'cursor-pointer',\n 'rounded-full border-transparent',\n 'hover:ring-4',\n 'transition-colors duration-200 ease-in-out',\n 'disabled:hover:ring-transparent disabled:cursor-not-allowed disabled:opacity-dim-3',\n 'focus-visible:u-outline',\n 'data-[state=unchecked]:bg-on-surface/dim-3',\n 'u-shadow-border-transition',\n 'overflow-x-hidden',\n ]),\n {\n variants: {\n /**\n * Size of the switch input.\n */\n size: makeVariants<'size', ['sm', 'md']>({\n sm: tw(['h-sz-24', 'w-sz-40', 'border-md']),\n md: tw(['h-sz-32', 'w-sz-56', 'border-[4px]']),\n }),\n /**\n * Color scheme of the switch input.\n */\n intent: makeVariants<\n 'intent',\n ['main', 'support', 'accent', 'basic', 'success', 'alert', 'error', 'info', 'neutral']\n >({\n main: ['data-[state=checked]:bg-main', 'hover:ring-main-container', 'text-main'],\n support: [\n 'data-[state=checked]:bg-support',\n 'hover:ring-support-container',\n 'text-support',\n ],\n accent: ['data-[state=checked]:bg-accent', 'hover:ring-accent-container', 'text-accent'],\n basic: ['data-[state=checked]:bg-basic', 'hover:ring-basic-container', 'text-basic'],\n success: [\n 'data-[state=checked]:bg-success',\n 'hover:ring-success-container',\n 'text-success',\n ],\n alert: ['data-[state=checked]:bg-alert', 'hover:ring-alert-container', 'text-alert'],\n error: ['data-[state=checked]:bg-error', 'hover:ring-error-container', 'text-error'],\n info: ['data-[state=checked]:bg-info', 'hover:ring-info-container', 'text-info'],\n neutral: [\n 'data-[state=checked]:bg-neutral',\n 'hover:ring-neutral-container',\n 'text-neutral',\n ],\n }),\n },\n defaultVariants: {\n intent: 'basic',\n size: 'sm',\n },\n }\n)\n\nexport type StylesProps = VariantProps<typeof styles>\n\nexport const thumbWrapperStyles = cva(\n [\n 'pointer-events-none absolute inset-0 flex items-center',\n 'transition-all duration-200 ease-in-out',\n ],\n {\n variants: {\n checked: {\n true: 'translate-x-full',\n false: 'translate-x-0',\n },\n },\n }\n)\n\nexport const thumbStyles = cva(\n [\n 'absolute left-0 top-0 flex items-center justify-center',\n 'bg-surface',\n 'rounded-full',\n 'ring-0',\n 'transition-all duration-200 ease-in-out',\n ],\n {\n variants: {\n size: makeVariants<'size', ['sm', 'md']>({\n sm: ['h-sz-20', 'w-sz-20'],\n md: ['h-sz-24', 'w-sz-24'],\n }),\n checked: {\n true: '-translate-x-full',\n false: 'translate-x-0 text-on-surface/dim-2',\n },\n },\n defaultVariants: {\n size: 'sm',\n checked: false,\n },\n }\n)\n\nexport const thumbCheckSVGStyles = cva(['transition-opacity duration-200'], {\n variants: {\n size: makeVariants<'size', ['sm', 'md']>({\n sm: ['h-sz-10 w-sz-10'],\n md: ['h-sz-12 w-sz-12'],\n }),\n },\n defaultVariants: {\n size: 'sm',\n },\n})\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { useCombinedState } from '@spark-ui/hooks/use-combined-state'\nimport { Check } from '@spark-ui/icons/Check'\nimport { Close } from '@spark-ui/icons/Close'\nimport { Switch as RadixSwitch } from 'radix-ui'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { Slot } from '../slot'\nimport {\n styles,\n type StylesProps,\n thumbCheckSVGStyles,\n thumbStyles,\n thumbWrapperStyles,\n} from './SwitchInput.styles'\n\nexport interface SwitchInputProps\n extends StylesProps,\n Omit<ComponentPropsWithRef<'button'>, 'value'> {\n /**\n * The state of the switch when it is initially rendered. Use when you do not need to control its state.\n */\n defaultChecked?: boolean\n /**\n * The controlled state of the switch. Must be used in conjunction with `onCheckedChange`.\n */\n checked?: boolean\n /**\n * When true, prevents the user from interacting with the switch.\n */\n /**\n * Event handler called when the state of the switch changes.\n */\n onCheckedChange?: (checked: boolean) => void\n /**\n * When `true`, prevents the user from interacting with the switch.\n */\n disabled?: boolean\n /**\n * When true, indicates that the user must check the switch before the owning form can be submitted.\n */\n required?: boolean\n /**\n * The name of the switch. Submitted with its owning form as part of a name/value pair.\n */\n name?: string\n /**\n * The value given as data when submitted with a name.\n */\n value?: string\n /**\n * Icon shown inside the thumb of the Switch whenever it is checked\n */\n checkedIcon?: ReactNode\n /**\n * Icon shown inside the thumb of the Switch whenever it is unchecked\n */\n uncheckedIcon?: ReactNode\n /**\n * When true, the label will be placed on the left side of the Switch\n */\n reverse?: boolean\n}\n\nexport const SwitchInput = ({\n checked,\n checkedIcon = <Check />,\n defaultChecked,\n intent: intentProp,\n uncheckedIcon = <Close />,\n size = 'md',\n value = 'on',\n onCheckedChange,\n className,\n required,\n ref,\n ...rest\n}: SwitchInputProps) => {\n const [isChecked, setIsChecked] = useCombinedState(checked, defaultChecked)\n const { name, description, state, isRequired, isInvalid } = useFormFieldControl()\n const intent = state ?? intentProp\n\n const handleCheckedChange = (updatedValue: boolean): void => {\n setIsChecked(updatedValue)\n onCheckedChange?.(updatedValue)\n }\n\n return (\n <RadixSwitch.Root\n data-spark-component=\"switch-input\"\n ref={ref}\n className={styles({ intent, size, className })}\n value={value}\n checked={checked}\n defaultChecked={defaultChecked}\n onCheckedChange={handleCheckedChange}\n name={name}\n required={required || isRequired}\n aria-invalid={isInvalid}\n aria-describedby={description}\n {...rest}\n >\n <span className={thumbWrapperStyles({ checked: isChecked })}>\n <RadixSwitch.Thumb className={thumbStyles({ size, checked: isChecked })}>\n {isChecked && checkedIcon && (\n <Slot className={thumbCheckSVGStyles({ size })}>{checkedIcon}</Slot>\n )}\n {!isChecked && uncheckedIcon && (\n <Slot className={thumbCheckSVGStyles({ size })}>{uncheckedIcon}</Slot>\n )}\n </RadixSwitch.Thumb>\n </span>\n </RadixSwitch.Root>\n )\n}\n\nSwitchInput.displayName = 'SwitchInput'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const labelStyles = cva('', {\n variants: {\n disabled: {\n true: ['text-neutral/dim-2', 'cursor-not-allowed'],\n false: ['cursor-pointer'],\n },\n },\n defaultVariants: {\n disabled: false,\n },\n})\n\nexport type LabelStylesProps = VariantProps<typeof labelStyles>\n","import { Label, LabelProps } from '../label'\nimport { labelStyles, LabelStylesProps } from './SwitchLabel.styles'\n\nexport interface SwitchLabelProps extends LabelStylesProps, LabelProps {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * The id of the element the label is associated with.\n */\n htmlFor?: string\n /**\n * When true, prevents the user from interacting with the switch item.\n */\n disabled?: boolean\n}\n\nexport const SwitchLabel = ({ className, disabled, ...others }: SwitchLabelProps) => (\n <Label\n data-spark-component=\"switch-label\"\n className={labelStyles({ disabled, className })}\n {...others}\n />\n)\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { cx } from 'class-variance-authority'\nimport { useId } from 'react'\n\nimport { SwitchInput, SwitchInputProps } from './SwitchInput'\nimport { SwitchLabel } from './SwitchLabel'\n\nexport type SwitchProps = SwitchInputProps\n\nconst ID_PREFIX = ':switch'\n\nexport const Switch = ({\n size = 'md',\n children,\n className,\n id,\n disabled,\n reverse = false,\n ref,\n ...rest\n}: SwitchProps) => {\n const field = useFormFieldControl()\n\n const labelID = `${ID_PREFIX}-label-${useId()}`\n const innerID = `${ID_PREFIX}-input-${useId()}`\n const fieldID = field.id || id || innerID\n\n const switchLabel = children && (\n <SwitchLabel disabled={disabled} htmlFor={fieldID} id={labelID}>\n {children}\n </SwitchLabel>\n )\n\n const switchInput = (\n <SwitchInput\n ref={ref}\n size={size}\n id={fieldID}\n disabled={disabled}\n /**\n * If the switch doesn't have any direct label (children) then we should try to\n * get an eventual alternative label from FormField.\n * On last resort, we shouldn't forget to define an aria-label attribute.\n */\n aria-labelledby={children ? labelID : field.labelId}\n {...rest}\n />\n )\n\n const content = reverse ? (\n <>\n {switchLabel}\n {switchInput}\n </>\n ) : (\n <>\n {switchInput}\n {switchLabel}\n </>\n )\n\n return (\n <div\n data-spark-component=\"switch\"\n className={cx('gap-md text-body-1 flex items-center', className)}\n >\n {content}\n </div>\n )\n}\n\nSwitch.displayName = 'Switch'\n"],"names":["styles","cva","tw","makeVariants","thumbWrapperStyles","thumbStyles","thumbCheckSVGStyles","SwitchInput","checked","checkedIcon","Check","defaultChecked","intentProp","uncheckedIcon","Close","size","value","onCheckedChange","className","required","ref","rest","isChecked","setIsChecked","useCombinedState","name","description","state","isRequired","isInvalid","useFormFieldControl","intent","handleCheckedChange","updatedValue","jsx","RadixSwitch","jsxs","Slot","labelStyles","SwitchLabel","disabled","others","Label","ID_PREFIX","Switch","children","id","reverse","field","labelID","useId","innerID","fieldID","switchLabel","switchInput","content","Fragment","cx"],"mappings":";;;;;;;;;;;AAGO,MAAMA,IAASC;AAAA,EACpBC,EAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACD;AAAA,EACD;AAAA,IACE,UAAU;AAAA;AAAA;AAAA;AAAA,MAIR,MAAMC,EAAmC;AAAA,QACvC,IAAID,EAAG,CAAC,WAAW,WAAW,WAAW,CAAC;AAAA,QAC1C,IAAIA,EAAG,C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J,EAAM,MAAMF,KAAMK,GAE5BE,IAAcR,KAClB,gBAAAX,EAACK,GAAA,EAAY,UAAAC,GAAoB,SAASY,GAAS,IAAIH,GACpD,UAAAJ,EAAA,CACH,GAGIS,IACJ,gBAAApB;AAAA,IAAC3B;AAAA,IAAA;AAAA,MACC,KAAAa;AAAA,MACA,MAAAL;AAAA,MACA,IAAIqC;AAAA,MACJ,UAAAZ;AAAA,MAMA,mBAAiBK,IAAWI,IAAUD,EAAM;AAAA,MAC3C,GAAG3B;AAAA,IAAA;AAAA,EAAA,GAIFkC,IAAUR,IACd,gBAAAX,EAAAoB,GAAA,EACG,UAAA;AAAA,IAAAH;AAAA,IACAC;AAAA,EAAA,EAAA,CACH,IAEA,gBAAAlB,EAAAoB,GAAA,EACG,UAAA;AAAA,IAAAF;AAAA,IACAD;AAAA,EAAA,GACH;AAGF,SACE,gBAAAnB;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,wBAAqB;AAAA,MACrB,WAAWuB,EAAG,wCAAwCvC,CAAS;AAAA,MAE9D,UAAAqC;AAAA,IAAA;AAAA,EAAA;AAGP;AAEAX,EAAO,cAAc;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/switch/SwitchInput.styles.ts","../../src/switch/SwitchInput.tsx","../../src/switch/SwitchLabel.styles.ts","../../src/switch/SwitchLabel.tsx","../../src/switch/Switch.tsx"],"sourcesContent":["import { makeVariants, tw } from '@spark-ui/internal-utils'\nimport { cva, VariantProps } from 'class-variance-authority'\n\nexport const styles = cva(\n tw([\n 'relative shrink-0 self-baseline',\n 'cursor-pointer',\n 'rounded-full border-transparent',\n 'hover:ring-4',\n 'transition-colors duration-200 ease-in-out',\n 'disabled:hover:ring-transparent disabled:cursor-not-allowed disabled:opacity-dim-3',\n 'focus-visible:u-outline',\n 'data-[state=unchecked]:bg-on-surface/dim-3',\n 'u-shadow-border-transition',\n 'overflow-x-hidden',\n ]),\n {\n variants: {\n /**\n * Size of the switch input.\n */\n size: makeVariants<'size', ['sm', 'md']>({\n sm: tw(['h-sz-24', 'w-sz-40', 'border-md']),\n md: tw(['h-sz-32', 'w-sz-56', 'border-[4px]']),\n }),\n /**\n * Color scheme of the switch input.\n */\n intent: makeVariants<\n 'intent',\n ['main', 'support', 'accent', 'basic', 'success', 'alert', 'error', 'info', 'neutral']\n >({\n main: ['data-[state=checked]:bg-main', 'hover:ring-main-container', 'text-main'],\n support: [\n 'data-[state=checked]:bg-support',\n 'hover:ring-support-container',\n 'text-support',\n ],\n accent: ['data-[state=checked]:bg-accent', 'hover:ring-accent-container', 'text-accent'],\n basic: ['data-[state=checked]:bg-basic', 'hover:ring-basic-container', 'text-basic'],\n success: [\n 'data-[state=checked]:bg-success',\n 'hover:ring-success-container',\n 'text-success',\n ],\n alert: ['data-[state=checked]:bg-alert', 'hover:ring-alert-container', 'text-alert'],\n error: ['data-[state=checked]:bg-error', 'hover:ring-error-container', 'text-error'],\n info: ['data-[state=checked]:bg-info', 'hover:ring-info-container', 'text-info'],\n neutral: [\n 'data-[state=checked]:bg-neutral',\n 'hover:ring-neutral-container',\n 'text-neutral',\n ],\n }),\n },\n defaultVariants: {\n intent: 'basic',\n size: 'sm',\n },\n }\n)\n\nexport type StylesProps = VariantProps<typeof styles>\n\nexport const thumbWrapperStyles = cva(\n [\n 'pointer-events-none absolute inset-0 flex items-center',\n 'transition-all duration-200 ease-in-out',\n ],\n {\n variants: {\n checked: {\n true: 'translate-x-full',\n false: 'translate-x-0',\n },\n },\n }\n)\n\nexport const thumbStyles = cva(\n [\n 'absolute left-0 top-0 flex items-center justify-center',\n 'bg-surface',\n 'rounded-full',\n 'ring-0',\n 'transition-all duration-200 ease-in-out',\n ],\n {\n variants: {\n size: makeVariants<'size', ['sm', 'md']>({\n sm: ['h-sz-20', 'w-sz-20'],\n md: ['h-sz-24', 'w-sz-24'],\n }),\n checked: {\n true: '-translate-x-full',\n false: 'translate-x-0 text-on-surface/dim-2',\n },\n },\n defaultVariants: {\n size: 'sm',\n checked: false,\n },\n }\n)\n\nexport const thumbCheckSVGStyles = cva(['transition-opacity duration-200'], {\n variants: {\n size: makeVariants<'size', ['sm', 'md']>({\n sm: ['h-sz-10 w-sz-10'],\n md: ['h-sz-12 w-sz-12'],\n }),\n },\n defaultVariants: {\n size: 'sm',\n },\n})\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { useCombinedState } from '@spark-ui/hooks/use-combined-state'\nimport { Check } from '@spark-ui/icons/Check'\nimport { Close } from '@spark-ui/icons/Close'\nimport { Switch as RadixSwitch } from 'radix-ui'\nimport { type ComponentPropsWithRef, type ReactNode } from 'react'\n\nimport { Slot } from '../slot'\nimport {\n styles,\n type StylesProps,\n thumbCheckSVGStyles,\n thumbStyles,\n thumbWrapperStyles,\n} from './SwitchInput.styles'\n\nexport interface SwitchInputProps\n extends StylesProps,\n Omit<ComponentPropsWithRef<'button'>, 'value'> {\n /**\n * The state of the switch when it is initially rendered. Use when you do not need to control its state.\n */\n defaultChecked?: boolean\n /**\n * The controlled state of the switch. Must be used in conjunction with `onCheckedChange`.\n */\n checked?: boolean\n /**\n * When true, prevents the user from interacting with the switch.\n */\n /**\n * Event handler called when the state of the switch changes.\n */\n onCheckedChange?: (checked: boolean) => void\n /**\n * When `true`, prevents the user from interacting with the switch.\n */\n disabled?: boolean\n /**\n * When true, indicates that the user must check the switch before the owning form can be submitted.\n */\n required?: boolean\n /**\n * The name of the switch. Submitted with its owning form as part of a name/value pair.\n */\n name?: string\n /**\n * The value given as data when submitted with a name.\n */\n value?: string\n /**\n * Icon shown inside the thumb of the Switch whenever it is checked\n */\n checkedIcon?: ReactNode\n /**\n * Icon shown inside the thumb of the Switch whenever it is unchecked\n */\n uncheckedIcon?: ReactNode\n /**\n * When true, the label will be placed on the left side of the Switch\n */\n reverse?: boolean\n}\n\nexport const SwitchInput = ({\n checked,\n checkedIcon = <Check />,\n defaultChecked,\n intent: intentProp,\n uncheckedIcon = <Close />,\n size = 'md',\n value = 'on',\n onCheckedChange,\n className,\n required,\n ref,\n ...rest\n}: SwitchInputProps) => {\n const [isChecked, setIsChecked] = useCombinedState(checked, defaultChecked)\n const { name, description, state, isRequired, isInvalid } = useFormFieldControl()\n const intent = state ?? intentProp\n\n const handleCheckedChange = (updatedValue: boolean): void => {\n setIsChecked(updatedValue)\n onCheckedChange?.(updatedValue)\n }\n\n return (\n <RadixSwitch.Root\n data-spark-component=\"switch-input\"\n ref={ref}\n className={styles({ intent, size, className })}\n value={value}\n checked={checked}\n defaultChecked={defaultChecked}\n onCheckedChange={handleCheckedChange}\n name={name}\n required={required || isRequired}\n aria-invalid={isInvalid}\n aria-describedby={description}\n {...rest}\n >\n <span className={thumbWrapperStyles({ checked: isChecked })}>\n <RadixSwitch.Thumb className={thumbStyles({ size, checked: isChecked })}>\n {isChecked && checkedIcon && (\n <Slot className={thumbCheckSVGStyles({ size })}>{checkedIcon}</Slot>\n )}\n {!isChecked && uncheckedIcon && (\n <Slot className={thumbCheckSVGStyles({ size })}>{uncheckedIcon}</Slot>\n )}\n </RadixSwitch.Thumb>\n </span>\n </RadixSwitch.Root>\n )\n}\n\nSwitchInput.displayName = 'SwitchInput'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const labelStyles = cva('default:text-on-surface', {\n variants: {\n disabled: {\n true: ['text-neutral/dim-2', 'cursor-not-allowed'],\n false: ['cursor-pointer'],\n },\n },\n defaultVariants: {\n disabled: false,\n },\n})\n\nexport type LabelStylesProps = VariantProps<typeof labelStyles>\n","import { Label, LabelProps } from '../label'\nimport { labelStyles, LabelStylesProps } from './SwitchLabel.styles'\n\nexport interface SwitchLabelProps extends LabelStylesProps, LabelProps {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * The id of the element the label is associated with.\n */\n htmlFor?: string\n /**\n * When true, prevents the user from interacting with the switch item.\n */\n disabled?: boolean\n}\n\nexport const SwitchLabel = ({ className, disabled, ...others }: SwitchLabelProps) => (\n <Label\n data-spark-component=\"switch-label\"\n className={labelStyles({ disabled, className })}\n {...others}\n />\n)\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { cx } from 'class-variance-authority'\nimport { useId } from 'react'\n\nimport { SwitchInput, SwitchInputProps } from './SwitchInput'\nimport { SwitchLabel } from './SwitchLabel'\n\nexport type SwitchProps = SwitchInputProps\n\nconst ID_PREFIX = ':switch'\n\nexport const Switch = ({\n size = 'md',\n children,\n className,\n id,\n disabled,\n reverse = false,\n ref,\n ...rest\n}: SwitchProps) => {\n const field = useFormFieldControl()\n\n const labelID = `${ID_PREFIX}-label-${useId()}`\n const innerID = `${ID_PREFIX}-input-${useId()}`\n const fieldID = field.id || id || innerID\n\n const switchLabel = children && (\n <SwitchLabel disabled={disabled} htmlFor={fieldID} id={labelID}>\n {children}\n </SwitchLabel>\n )\n\n const switchInput = (\n <SwitchInput\n ref={ref}\n size={size}\n id={fieldID}\n disabled={disabled}\n /**\n * If the switch doesn't have any direct label (children) then we should try to\n * get an eventual alternative label from FormField.\n * On last resort, we shouldn't forget to define an aria-label attribute.\n */\n aria-labelledby={children ? labelID : field.labelId}\n {...rest}\n />\n )\n\n const content = reverse ? (\n <>\n {switchLabel}\n {switchInput}\n </>\n ) : (\n <>\n {switchInput}\n {switchLabel}\n </>\n )\n\n return (\n <div\n data-spark-component=\"switch\"\n className={cx('gap-md text-body-1 flex items-center', className)}\n >\n {content}\n </div>\n )\n}\n\nSwitch.displayName = 'Switch'\n"],"names":["styles","cva","tw","makeVariants","thumbWrapperStyles","thumbStyles","thumbCheckSVGStyles","SwitchInput","checked","checkedIcon","Check","defaultChecked","intentProp","uncheckedIcon","Close","size","value","onCheckedChange","className","required","ref","rest","isChecked","setIsChecked","useCombinedState","name","description","state","isRequired","isInvalid","useFormFieldControl","intent","handleCheckedChange","updatedValue","jsx","RadixSwitch","jsxs","Slot","labelStyles","SwitchLabel","disabled","others","Label","ID_PREFIX","Switch","children","id","reverse","field","labelID","useId","innerID","fieldID","switchLabel","switchInput","content","Fragment","c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AAA,EAAA;AACN,GCdIE,IAAY,WAELC,IAAS,CAAC;AAAA,EACrB,MAAA7B,IAAO;AAAA,EACP,UAAA8B;AAAA,EACA,WAAA3B;AAAA,EACA,IAAA4B;AAAA,EACA,UAAAN;AAAA,EACA,SAAAO,IAAU;AAAA,EACV,KAAA3B;AAAA,EACA,GAAGC;AACL,MAAmB;AACjB,QAAM2B,IAAQlB,EAAA,GAERmB,IAAU,GAAGN,CAAS,UAAUO,GAAO,IACvCC,IAAU,GAAGR,CAAS,UAAUO,GAAO,IACvCE,IAAUJ,EAAM,MAAMF,KAAMK,GAE5BE,IAAcR,KAClB,gBAAAX,EAACK,GAAA,EAAY,UAAAC,GAAoB,SAASY,GAAS,IAAIH,GACpD,UAAAJ,EAAA,CACH,GAGIS,IACJ,gBAAApB;AAAA,IAAC3B;AAAA,IAAA;AAAA,MACC,KAAAa;AAAA,MACA,MAAAL;AAAA,MACA,IAAIqC;AAAA,MACJ,UAAAZ;AAAA,MAMA,mBAAiBK,IAAWI,IAAUD,EAAM;AAAA,MAC3C,GAAG3B;AAAA,IAAA;AAAA,EAAA,GAIFkC,IAAUR,IACd,gBAAAX,EAAAoB,GAAA,EACG,UAAA;AAAA,IAAAH;AAAA,IACAC;AAAA,EAAA,EAAA,CACH,IAEA,gBAAAlB,EAAAoB,GAAA,EACG,UAAA;AAAA,IAAAF;AAAA,IACAD;AAAA,EAAA,GACH;AAGF,SACE,gBAAAnB;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,wBAAqB;AAAA,MACrB,WAAWuB,EAAG,wCAAwCvC,CAAS;AAAA,MAE9D,UAAAqC;AAAA,IAAA;AAAA,EAAA;AAGP;AAEAX,EAAO,cAAc;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spark-ui/components",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Spark (Leboncoin design system) components.",
|
|
6
6
|
"exports": {
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"@react-aria/toast": "^3.0.0-beta.18",
|
|
55
55
|
"@react-stately/numberfield": "3.9.11",
|
|
56
56
|
"@react-stately/toast": "^3.0.0-beta.7",
|
|
57
|
-
"@spark-ui/hooks": "^
|
|
58
|
-
"@spark-ui/icons": "^
|
|
59
|
-
"@spark-ui/internal-utils": "^
|
|
57
|
+
"@spark-ui/hooks": "^16.0.0",
|
|
58
|
+
"@spark-ui/icons": "^16.0.0",
|
|
59
|
+
"@spark-ui/internal-utils": "^16.0.0",
|
|
60
60
|
"@zag-js/pagination": "1.30.0",
|
|
61
61
|
"@zag-js/react": "1.30.0",
|
|
62
62
|
"class-variance-authority": "0.7.1",
|