@dust-tt/sparkle 0.2.265 → 0.2.266-rc-1
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/cjs/index.js +584 -192
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/components/Checkbox.d.ts +18 -9
- package/dist/esm/components/Checkbox.d.ts.map +1 -1
- package/dist/esm/components/Checkbox.js +42 -56
- package/dist/esm/components/Checkbox.js.map +1 -1
- package/dist/esm/components/index.d.ts +2 -1
- package/dist/esm/components/index.d.ts.map +1 -1
- package/dist/esm/components/index.js +1 -1
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/stories/Checkbox.stories.d.ts +4 -10
- package/dist/esm/stories/Checkbox.stories.d.ts.map +1 -1
- package/dist/esm/stories/Checkbox.stories.js +22 -51
- package/dist/esm/stories/Checkbox.stories.js.map +1 -1
- package/dist/esm/stories/Tree.stories.d.ts.map +1 -1
- package/dist/esm/stories/Tree.stories.js +39 -78
- package/dist/esm/stories/Tree.stories.js.map +1 -1
- package/dist/sparkle.css +37 -61
- package/package.json +3 -1
- package/src/components/Checkbox.tsx +79 -103
- package/src/components/index.ts +6 -1
- package/src/stories/Checkbox.stories.tsx +40 -92
- package/src/stories/Tree.stories.tsx +39 -78
|
@@ -1,122 +1,98 @@
|
|
|
1
|
+
import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
|
|
2
|
+
import { cva, VariantProps } from "class-variance-authority";
|
|
1
3
|
import React from "react";
|
|
2
4
|
|
|
3
5
|
import { CheckIcon, DashIcon } from "@sparkle/icons/solid";
|
|
4
|
-
import {
|
|
6
|
+
import { cn } from "@sparkle/lib/utils";
|
|
5
7
|
|
|
6
8
|
import { Icon } from "./Icon";
|
|
9
|
+
import { Label } from "./Label";
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
case "checked":
|
|
31
|
-
isChecked = true;
|
|
32
|
-
isPartialChecked = false;
|
|
33
|
-
break;
|
|
34
|
-
case "unchecked":
|
|
35
|
-
isChecked = false;
|
|
36
|
-
isPartialChecked = false;
|
|
37
|
-
break;
|
|
38
|
-
case "partial":
|
|
39
|
-
isChecked = true;
|
|
40
|
-
isPartialChecked = true;
|
|
41
|
-
break;
|
|
42
|
-
default:
|
|
43
|
-
throw new Error("Invalid checked prop");
|
|
11
|
+
const checkboxStyles = cva(
|
|
12
|
+
cn(
|
|
13
|
+
"s-shrink-0 s-peer s-border s-border-primary-500 s-text-foreground",
|
|
14
|
+
"data-[state=checked]:s-text-white data-[state=checked]:s-text-foreground",
|
|
15
|
+
"focus-visible:s-ring-ring s-ring-offset-background focus-visible:s-outline-none focus-visible:s-ring-2 focus-visible:s-ring-offset-2",
|
|
16
|
+
"disabled:s-cursor-not-allowed disabled:s-opacity-50"
|
|
17
|
+
),
|
|
18
|
+
{
|
|
19
|
+
variants: {
|
|
20
|
+
isPartial: {
|
|
21
|
+
false: "data-[state=checked]:s-bg-action-500",
|
|
22
|
+
true: "data-[state=checked]:s-bg-element-700",
|
|
23
|
+
},
|
|
24
|
+
size: {
|
|
25
|
+
xs: "s-h-4 s-w-4 s-rounded",
|
|
26
|
+
sm: "s-h-5 s-w-5 s-rounded-md",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
defaultVariants: {
|
|
30
|
+
size: "sm",
|
|
31
|
+
isPartial: false,
|
|
32
|
+
},
|
|
44
33
|
}
|
|
34
|
+
);
|
|
45
35
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
hover:
|
|
50
|
-
"hover:s-border-action-500 hover:s-bg-action-200 hover:s-text-white/100",
|
|
51
|
-
disabled: "s-bg-structure-0 s-border-structure-300 s-cursor-default",
|
|
52
|
-
dark: {
|
|
53
|
-
base: "dark:s-bg-structure-50-dark dark:s-border-element-500-dark",
|
|
54
|
-
hover:
|
|
55
|
-
"dark:hover:s-border-action-500-dark dark:hover:s-bg-action-200-dark",
|
|
56
|
-
disabled:
|
|
57
|
-
"dark:s-bg-structure-0-dark dark:s-border-structure-300-dark s-cursor-default",
|
|
58
|
-
},
|
|
59
|
-
};
|
|
36
|
+
interface CheckboxProps
|
|
37
|
+
extends React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>,
|
|
38
|
+
VariantProps<typeof checkboxStyles> {}
|
|
60
39
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
40
|
+
const Checkbox = React.forwardRef<
|
|
41
|
+
React.ElementRef<typeof CheckboxPrimitive.Root>,
|
|
42
|
+
CheckboxProps
|
|
43
|
+
>(({ className, size = "sm", isPartial = false, checked, ...props }, ref) => (
|
|
44
|
+
<CheckboxPrimitive.Root
|
|
45
|
+
ref={ref}
|
|
46
|
+
className={cn(checkboxStyles({ isPartial, size }), className)}
|
|
47
|
+
checked={isPartial || checked}
|
|
48
|
+
{...props}
|
|
49
|
+
>
|
|
50
|
+
<CheckboxPrimitive.Indicator className="s-flex s-items-center s-justify-center s-text-current">
|
|
51
|
+
<span className={cn(size === "xs" ? "-s-mt-px" : "")}>
|
|
52
|
+
<Icon size="xs" visual={isPartial ? DashIcon : CheckIcon} />
|
|
53
|
+
</span>
|
|
54
|
+
</CheckboxPrimitive.Indicator>
|
|
55
|
+
</CheckboxPrimitive.Root>
|
|
56
|
+
));
|
|
65
57
|
|
|
66
|
-
|
|
67
|
-
base: "s-transition s-duration-300 s-ease-in-out",
|
|
68
|
-
selected: "s-opacity-100 s-bg-action-500 dark:s-bg-action-500-dark",
|
|
69
|
-
unselected: "s-opacity-0",
|
|
70
|
-
partialChecked: "s-opacity-100 s-bg-element-700 dark:s-bg-element-700-dark",
|
|
71
|
-
disabled: "s-opacity-100 s-bg-element-500 dark:s-bg-element-500-dark",
|
|
72
|
-
};
|
|
58
|
+
Checkbox.displayName = CheckboxPrimitive.Root.displayName;
|
|
73
59
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
};
|
|
60
|
+
interface CheckboxWithTextProps extends CheckboxProps {
|
|
61
|
+
text: string;
|
|
62
|
+
}
|
|
78
63
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
className
|
|
64
|
+
function CheckboxWithText({ text, ...props }: CheckboxWithTextProps) {
|
|
65
|
+
return (
|
|
66
|
+
<div className="s-items-top s-flex s-items-center s-space-x-2">
|
|
67
|
+
<Checkbox {...props} />
|
|
68
|
+
<Label className="s-text-sm s-leading-none peer-disabled:s-cursor-not-allowed peer-disabled:s-opacity-70">
|
|
69
|
+
{text}
|
|
70
|
+
</Label>
|
|
71
|
+
</div>
|
|
88
72
|
);
|
|
73
|
+
}
|
|
89
74
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
isChecked && !isPartialChecked && !disabled
|
|
94
|
-
? checkedIndicatorClasses.selected
|
|
95
|
-
: "",
|
|
96
|
-
isPartialChecked && !disabled ? checkedIndicatorClasses.partialChecked : "",
|
|
97
|
-
!isChecked && !disabled ? checkedIndicatorClasses.unselected : ""
|
|
98
|
-
);
|
|
75
|
+
interface CheckboxWithTextAndDescriptionProps extends CheckboxWithTextProps {
|
|
76
|
+
description: string;
|
|
77
|
+
}
|
|
99
78
|
|
|
79
|
+
function CheckBoxWithTextAndDescription({
|
|
80
|
+
text,
|
|
81
|
+
description,
|
|
82
|
+
...props
|
|
83
|
+
}: CheckboxWithTextAndDescriptionProps) {
|
|
100
84
|
return (
|
|
101
|
-
<
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
/>
|
|
109
|
-
<div className={classNames(combinedBaseClasses, "s-relative")}>
|
|
110
|
-
<div
|
|
111
|
-
className={combinedCheckedIndicatorClasses}
|
|
112
|
-
style={sizeStyles[size]}
|
|
113
|
-
/>
|
|
114
|
-
{variant === "checkable" && (
|
|
115
|
-
<div className="s-absolute">
|
|
116
|
-
<Icon visual={isPartialChecked ? DashIcon : CheckIcon} size="xs" />
|
|
117
|
-
</div>
|
|
118
|
-
)}
|
|
85
|
+
<div className="s-items-top s-flex s-space-x-2">
|
|
86
|
+
<Checkbox {...props} />
|
|
87
|
+
<div className="s-grid s-gap-1.5 s-leading-none">
|
|
88
|
+
<Label className="s-text-sm s-leading-none peer-disabled:s-cursor-not-allowed peer-disabled:s-opacity-70">
|
|
89
|
+
{text}
|
|
90
|
+
</Label>
|
|
91
|
+
<p className="s-text-xs s-text-muted-foreground">{description}</p>
|
|
119
92
|
</div>
|
|
120
|
-
</
|
|
93
|
+
</div>
|
|
121
94
|
);
|
|
122
95
|
}
|
|
96
|
+
|
|
97
|
+
export { Checkbox, CheckboxWithText, CheckBoxWithTextAndDescription };
|
|
98
|
+
export type { CheckboxProps };
|
package/src/components/index.ts
CHANGED
|
@@ -5,7 +5,12 @@ export { BarHeader } from "./BarHeader";
|
|
|
5
5
|
export { Breadcrumbs } from "./Breadcrumbs";
|
|
6
6
|
export { Button } from "./Button";
|
|
7
7
|
export { CardButton } from "./CardButton";
|
|
8
|
-
export {
|
|
8
|
+
export type { CheckboxProps } from "./Checkbox";
|
|
9
|
+
export {
|
|
10
|
+
Checkbox,
|
|
11
|
+
CheckboxWithText,
|
|
12
|
+
CheckBoxWithTextAndDescription,
|
|
13
|
+
} from "./Checkbox";
|
|
9
14
|
export { Chip } from "./Chip";
|
|
10
15
|
export { Citation } from "./Citation";
|
|
11
16
|
export { default as CollapseButton } from "./CollapseButton";
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import type { Meta
|
|
1
|
+
import type { Meta } from "@storybook/react";
|
|
2
2
|
import React from "react";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
Checkbox,
|
|
6
|
+
CheckboxWithText,
|
|
7
|
+
CheckBoxWithTextAndDescription,
|
|
8
|
+
} from "../index_with_tw_base";
|
|
5
9
|
|
|
6
10
|
const meta = {
|
|
7
11
|
title: "Primitives/Checkbox",
|
|
@@ -9,107 +13,51 @@ const meta = {
|
|
|
9
13
|
} satisfies Meta<typeof Checkbox>;
|
|
10
14
|
|
|
11
15
|
export default meta;
|
|
12
|
-
type Story = StoryObj<typeof meta>;
|
|
13
|
-
export const CheckBoxExample = () => {
|
|
14
|
-
// No-op function for onChange
|
|
15
|
-
const handleChange = () => {
|
|
16
|
-
// This function intentionally left blank
|
|
17
|
-
};
|
|
18
16
|
|
|
17
|
+
const handleChange = () => {
|
|
18
|
+
// This function intentionally left blank
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const CheckBoxSizesExample = () => {
|
|
19
22
|
return (
|
|
20
23
|
<div className="s-flex s-flex-col s-gap-10">
|
|
21
|
-
SM
|
|
22
24
|
<div className="s-flex s-gap-10">
|
|
23
|
-
|
|
24
|
-
<Checkbox
|
|
25
|
-
<Checkbox
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
onChange={handleChange}
|
|
29
|
-
/>
|
|
30
|
-
<Checkbox
|
|
31
|
-
checked="partial"
|
|
32
|
-
variant="selectable"
|
|
33
|
-
onChange={handleChange}
|
|
34
|
-
/>
|
|
35
|
-
Checkable
|
|
36
|
-
<Checkbox variant="checkable" onChange={handleChange} />
|
|
37
|
-
<Checkbox
|
|
38
|
-
checked="checked"
|
|
39
|
-
variant="checkable"
|
|
40
|
-
onChange={handleChange}
|
|
41
|
-
/>
|
|
42
|
-
<Checkbox
|
|
43
|
-
checked="partial"
|
|
44
|
-
variant="checkable"
|
|
45
|
-
onChange={handleChange}
|
|
46
|
-
/>
|
|
25
|
+
SM
|
|
26
|
+
<Checkbox onChange={handleChange} />
|
|
27
|
+
<Checkbox checked onChange={handleChange} />
|
|
28
|
+
<Checkbox isPartial checked onChange={handleChange} />
|
|
29
|
+
<Checkbox checked="indeterminate" onChange={handleChange} />
|
|
47
30
|
</div>
|
|
48
|
-
XS
|
|
49
31
|
<div className="s-flex s-gap-10">
|
|
50
|
-
|
|
51
|
-
<Checkbox size="xs"
|
|
52
|
-
<Checkbox
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
variant="selectable"
|
|
56
|
-
onChange={handleChange}
|
|
57
|
-
/>
|
|
58
|
-
<Checkbox
|
|
59
|
-
size="xs"
|
|
60
|
-
checked="partial"
|
|
61
|
-
variant="selectable"
|
|
62
|
-
onChange={handleChange}
|
|
63
|
-
/>
|
|
64
|
-
Checkable
|
|
65
|
-
<Checkbox size="xs" variant="checkable" onChange={handleChange} />
|
|
66
|
-
<Checkbox
|
|
67
|
-
size="xs"
|
|
68
|
-
checked="checked"
|
|
69
|
-
variant="checkable"
|
|
70
|
-
onChange={handleChange}
|
|
71
|
-
/>
|
|
72
|
-
<Checkbox
|
|
73
|
-
size="xs"
|
|
74
|
-
checked="partial"
|
|
75
|
-
variant="checkable"
|
|
76
|
-
onChange={handleChange}
|
|
77
|
-
/>
|
|
32
|
+
XS
|
|
33
|
+
<Checkbox size="xs" onChange={handleChange} />
|
|
34
|
+
<Checkbox size="xs" checked onChange={handleChange} />
|
|
35
|
+
<Checkbox size="xs" isPartial checked onChange={handleChange} />
|
|
36
|
+
<Checkbox size="xs" checked="indeterminate" onChange={handleChange} />
|
|
78
37
|
</div>
|
|
79
38
|
</div>
|
|
80
39
|
);
|
|
81
40
|
};
|
|
82
41
|
|
|
83
|
-
export const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
export const Checked: Story = {
|
|
91
|
-
args: {
|
|
92
|
-
checked: "checked",
|
|
93
|
-
variant: "checkable",
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export const Unchecked: Story = {
|
|
98
|
-
args: {
|
|
99
|
-
checked: "unchecked",
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export const PartialChecked: Story = {
|
|
104
|
-
args: {
|
|
105
|
-
checked: "partial",
|
|
106
|
-
variant: "checkable",
|
|
107
|
-
},
|
|
42
|
+
export const CheckBoxWithTextExample = () => {
|
|
43
|
+
return (
|
|
44
|
+
<div className="s-flex s-gap-10">
|
|
45
|
+
<CheckboxWithText text="Google Drive" />
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
108
48
|
};
|
|
109
49
|
|
|
110
|
-
export const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
50
|
+
export const CheckBoxWithTextAndDescriptionExample = () => {
|
|
51
|
+
return (
|
|
52
|
+
<div className="s-flex s-flex-col s-gap-3">
|
|
53
|
+
<CheckBoxWithTextAndDescription
|
|
54
|
+
text="Google Drive"
|
|
55
|
+
description="This is a nice Google Drive description."
|
|
56
|
+
/>
|
|
57
|
+
<CheckBoxWithTextAndDescription
|
|
58
|
+
text="Microsoft"
|
|
59
|
+
description="This is a nice Microsoft description."
|
|
60
|
+
/>
|
|
61
|
+
</div>
|
|
62
|
+
);
|
|
115
63
|
};
|