@elysn/astro 0.0.3 → 0.0.4
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/index.ts +46 -0
- package/package.json +21 -5
- package/src/AccessibleIcon.astro +14 -0
- package/src/AspectRatio.astro +14 -0
- package/src/Avatar.astro +54 -0
- package/src/Badge.astro +34 -0
- package/src/Blockquote.astro +21 -0
- package/src/Box.astro +13 -0
- package/src/Button.astro +2 -2
- package/src/Callout.astro +34 -0
- package/src/CalloutIcon.astro +12 -0
- package/src/CalloutText.astro +12 -0
- package/src/Card.astro +30 -0
- package/src/Checkbox.astro +212 -0
- package/src/Code.astro +21 -0
- package/src/Container.astro +26 -0
- package/src/DecoratedBox.astro +22 -0
- package/src/Em.astro +10 -0
- package/src/Flex.astro +25 -0
- package/src/Grid.astro +21 -0
- package/src/Heading.astro +43 -0
- package/src/InputControl.astro +40 -0
- package/src/InputField.astro +10 -0
- package/src/InputSlot.astro +41 -0
- package/src/Kbd.astro +11 -0
- package/src/Link.astro +33 -0
- package/src/Panel.astro +12 -0
- package/src/Progress.astro +63 -0
- package/src/Quote.astro +10 -0
- package/src/RadioCards.astro +71 -0
- package/src/RadioCardsItem.astro +41 -0
- package/src/RadioGroup.astro +70 -0
- package/src/RadioGroupItem.astro +53 -0
- package/src/Section.astro +23 -0
- package/src/SegmentedControl.astro +189 -0
- package/src/Separator.astro +25 -0
- package/src/Skeleton.astro +30 -0
- package/src/Spinner.astro +31 -0
- package/src/Strong.astro +10 -0
- package/src/Switch.astro +164 -0
- package/src/Tabs.astro +179 -0
- package/src/TabsContent.astro +20 -0
- package/src/TabsIndicator.astro +17 -0
- package/src/TabsList.astro +12 -0
- package/src/TabsTrigger.astro +23 -0
- package/src/Text.astro +43 -0
- package/src/TextArea.astro +30 -0
- package/src/TextField.astro +70 -0
- package/src/VisuallyHidden.astro +10 -0
- package/src/internal/radio-group.ts +82 -0
- package/src/internal/ssr.ts +18 -0
- package/src/internal/zag.ts +24 -0
package/index.ts
CHANGED
|
@@ -1,4 +1,50 @@
|
|
|
1
1
|
// Do not write code directly here, instead use the `src` folder!
|
|
2
2
|
// Then, use this file to export everything you want your user to access.
|
|
3
3
|
|
|
4
|
+
export { default as AccessibleIcon } from "./src/AccessibleIcon.astro";
|
|
5
|
+
export { default as AspectRatio } from "./src/AspectRatio.astro";
|
|
6
|
+
export { default as Avatar } from "./src/Avatar.astro";
|
|
7
|
+
export { default as Badge } from "./src/Badge.astro";
|
|
8
|
+
export { default as Blockquote } from "./src/Blockquote.astro";
|
|
9
|
+
export { default as Box } from "./src/Box.astro";
|
|
4
10
|
export { default as Button } from "./src/Button.astro";
|
|
11
|
+
export { default as Callout } from "./src/Callout.astro";
|
|
12
|
+
export { default as CalloutIcon } from "./src/CalloutIcon.astro";
|
|
13
|
+
export { default as CalloutText } from "./src/CalloutText.astro";
|
|
14
|
+
export { default as Card } from "./src/Card.astro";
|
|
15
|
+
export { default as Checkbox } from "./src/Checkbox.astro";
|
|
16
|
+
export { default as Code } from "./src/Code.astro";
|
|
17
|
+
export { default as Container } from "./src/Container.astro";
|
|
18
|
+
export { default as DecoratedBox } from "./src/DecoratedBox.astro";
|
|
19
|
+
export { default as Em } from "./src/Em.astro";
|
|
20
|
+
export { default as Flex } from "./src/Flex.astro";
|
|
21
|
+
export { default as Grid } from "./src/Grid.astro";
|
|
22
|
+
export { default as Heading } from "./src/Heading.astro";
|
|
23
|
+
export { default as InputControl } from "./src/InputControl.astro";
|
|
24
|
+
export { default as InputField } from "./src/InputField.astro";
|
|
25
|
+
export { default as InputSlot } from "./src/InputSlot.astro";
|
|
26
|
+
export { default as Kbd } from "./src/Kbd.astro";
|
|
27
|
+
export { default as Link } from "./src/Link.astro";
|
|
28
|
+
export { default as Panel } from "./src/Panel.astro";
|
|
29
|
+
export { default as Progress } from "./src/Progress.astro";
|
|
30
|
+
export { default as Quote } from "./src/Quote.astro";
|
|
31
|
+
export { default as RadioCards } from "./src/RadioCards.astro";
|
|
32
|
+
export { default as RadioCardsItem } from "./src/RadioCardsItem.astro";
|
|
33
|
+
export { default as RadioGroup } from "./src/RadioGroup.astro";
|
|
34
|
+
export { default as RadioGroupItem } from "./src/RadioGroupItem.astro";
|
|
35
|
+
export { default as Section } from "./src/Section.astro";
|
|
36
|
+
export { default as SegmentedControl } from "./src/SegmentedControl.astro";
|
|
37
|
+
export { default as Separator } from "./src/Separator.astro";
|
|
38
|
+
export { default as Skeleton } from "./src/Skeleton.astro";
|
|
39
|
+
export { default as Spinner } from "./src/Spinner.astro";
|
|
40
|
+
export { default as Strong } from "./src/Strong.astro";
|
|
41
|
+
export { default as Switch } from "./src/Switch.astro";
|
|
42
|
+
export { default as Tabs } from "./src/Tabs.astro";
|
|
43
|
+
export { default as TabsContent } from "./src/TabsContent.astro";
|
|
44
|
+
export { default as TabsIndicator } from "./src/TabsIndicator.astro";
|
|
45
|
+
export { default as TabsList } from "./src/TabsList.astro";
|
|
46
|
+
export { default as TabsTrigger } from "./src/TabsTrigger.astro";
|
|
47
|
+
export { default as Text } from "./src/Text.astro";
|
|
48
|
+
export { default as TextArea } from "./src/TextArea.astro";
|
|
49
|
+
export { default as TextField } from "./src/TextField.astro";
|
|
50
|
+
export { default as VisuallyHidden } from "./src/VisuallyHidden.astro";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elysn/astro",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Elysn Astro components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro-component"
|
|
@@ -24,16 +24,32 @@
|
|
|
24
24
|
"default": "./index.ts"
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@zag-js/checkbox": "1.47.0",
|
|
29
|
+
"@zag-js/color-picker": "1.47.0",
|
|
30
|
+
"@zag-js/dialog": "1.47.0",
|
|
31
|
+
"@zag-js/menu": "1.47.0",
|
|
32
|
+
"@zag-js/popover": "1.47.0",
|
|
33
|
+
"@zag-js/radio-group": "1.47.0",
|
|
34
|
+
"@zag-js/scroll-area": "1.47.0",
|
|
35
|
+
"@zag-js/select": "1.47.0",
|
|
36
|
+
"@zag-js/slider": "1.47.0",
|
|
37
|
+
"@zag-js/switch": "1.47.0",
|
|
38
|
+
"@zag-js/tabs": "1.47.0",
|
|
39
|
+
"@zag-js/tooltip": "1.47.0",
|
|
40
|
+
"@zag-js/vanilla": "1.47.0"
|
|
41
|
+
},
|
|
27
42
|
"devDependencies": {
|
|
28
|
-
"@
|
|
29
|
-
"
|
|
30
|
-
"
|
|
43
|
+
"@astrojs/check": "^0.9.12",
|
|
44
|
+
"@elysn/theme": "0.0.7",
|
|
45
|
+
"astro": "^7.4.10",
|
|
46
|
+
"typescript": "^6.0.3"
|
|
31
47
|
},
|
|
32
48
|
"peerDependencies": {
|
|
33
49
|
"@elysn/theme": ">=0.0.6 <0.1.0",
|
|
34
50
|
"astro": "^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0"
|
|
35
51
|
},
|
|
36
52
|
"scripts": {
|
|
37
|
-
"typecheck": "
|
|
53
|
+
"typecheck": "astro check"
|
|
38
54
|
}
|
|
39
55
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
|
|
4
|
+
interface Props extends HTMLAttributes<"span"> {
|
|
5
|
+
className?: string;
|
|
6
|
+
label: string;
|
|
7
|
+
}
|
|
8
|
+
const { className, label, ...rest } = Astro.props as Props;
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
<span {...rest} class:list={["el-AccessibleIcon", className]}>
|
|
12
|
+
<span aria-hidden="true"><slot /></span>
|
|
13
|
+
<span class="el-VisuallyHidden">{label}</span>
|
|
14
|
+
</span>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
|
|
4
|
+
interface Props extends Omit<HTMLAttributes<"div">, "style"> {
|
|
5
|
+
className?: string;
|
|
6
|
+
ratio?: number;
|
|
7
|
+
style?: Record<string, string | number>;
|
|
8
|
+
}
|
|
9
|
+
const { className, ratio = 1, style, ...rest } = Astro.props as Props;
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
<div {...rest} class:list={["el-AspectRatio", className]} style={{ "--aspect-ratio": ratio, ...style }}>
|
|
13
|
+
<slot />
|
|
14
|
+
</div>
|
package/src/Avatar.astro
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
|
|
4
|
+
type Size = "xs" | "sm" | "md" | "lg" | "xl";
|
|
5
|
+
|
|
6
|
+
interface Props extends Omit<HTMLAttributes<"div">, "color"> {
|
|
7
|
+
alt?: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
color?: string;
|
|
10
|
+
highContrast?: boolean;
|
|
11
|
+
radius?: "none" | "small" | "medium" | "large" | "full";
|
|
12
|
+
size?: Size;
|
|
13
|
+
src?: string;
|
|
14
|
+
variant?: "solid" | "soft" | "surface";
|
|
15
|
+
}
|
|
16
|
+
const {
|
|
17
|
+
alt,
|
|
18
|
+
className,
|
|
19
|
+
color,
|
|
20
|
+
highContrast,
|
|
21
|
+
radius,
|
|
22
|
+
size = "md",
|
|
23
|
+
src,
|
|
24
|
+
variant = "soft",
|
|
25
|
+
...rest
|
|
26
|
+
} = Astro.props as Props;
|
|
27
|
+
|
|
28
|
+
const sizes: Record<Size, string> = {
|
|
29
|
+
xs: "el-Avatar-size-xs",
|
|
30
|
+
sm: "el-Avatar-size-sm",
|
|
31
|
+
md: "el-Avatar-size-md",
|
|
32
|
+
lg: "el-Avatar-size-lg",
|
|
33
|
+
xl: "el-Avatar-size-xl",
|
|
34
|
+
};
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
<div
|
|
38
|
+
{...rest}
|
|
39
|
+
data-accent-color={color}
|
|
40
|
+
data-high-contrast={highContrast ? true : undefined}
|
|
41
|
+
data-radius={radius}
|
|
42
|
+
data-variant={variant}
|
|
43
|
+
class:list={["el-Avatar", sizes[size], className]}
|
|
44
|
+
>
|
|
45
|
+
{
|
|
46
|
+
src ? (
|
|
47
|
+
<img class="el-Avatar-image" src={src} alt={alt} />
|
|
48
|
+
) : (
|
|
49
|
+
<span class="el-Avatar-fallback">
|
|
50
|
+
<slot />
|
|
51
|
+
</span>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
</div>
|
package/src/Badge.astro
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
|
|
4
|
+
type Size = "xs" | "sm" | "md" | "lg";
|
|
5
|
+
|
|
6
|
+
interface Props extends Omit<HTMLAttributes<"span">, "color"> {
|
|
7
|
+
className?: string;
|
|
8
|
+
color?: string;
|
|
9
|
+
highContrast?: boolean;
|
|
10
|
+
radius?: "none" | "small" | "medium" | "large" | "full";
|
|
11
|
+
size?: Size;
|
|
12
|
+
variant?: "solid" | "soft" | "surface" | "outline";
|
|
13
|
+
}
|
|
14
|
+
const { className, color, highContrast, radius, size = "sm", variant = "soft", ...rest } =
|
|
15
|
+
Astro.props as Props;
|
|
16
|
+
|
|
17
|
+
const sizes: Record<Size, string> = {
|
|
18
|
+
xs: "el-Badge-size-xs",
|
|
19
|
+
sm: "el-Badge-size-sm",
|
|
20
|
+
md: "el-Badge-size-md",
|
|
21
|
+
lg: "el-Badge-size-lg",
|
|
22
|
+
};
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
<span
|
|
26
|
+
{...rest}
|
|
27
|
+
data-accent-color={color}
|
|
28
|
+
data-high-contrast={highContrast ? true : undefined}
|
|
29
|
+
data-radius={radius}
|
|
30
|
+
data-variant={variant}
|
|
31
|
+
class:list={["el-Badge", sizes[size], className]}
|
|
32
|
+
>
|
|
33
|
+
<slot />
|
|
34
|
+
</span>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
|
|
4
|
+
interface Props extends Omit<HTMLAttributes<"blockquote">, "color"> {
|
|
5
|
+
className?: string;
|
|
6
|
+
color?: string;
|
|
7
|
+
highContrast?: boolean;
|
|
8
|
+
size?: "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
9
|
+
}
|
|
10
|
+
const { className, color, highContrast, size, ...rest } = Astro.props as Props;
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
<blockquote
|
|
14
|
+
{...rest}
|
|
15
|
+
data-accent-color={color}
|
|
16
|
+
data-high-contrast={highContrast ? true : undefined}
|
|
17
|
+
data-size={size}
|
|
18
|
+
class:list={["el-Blockquote", className]}
|
|
19
|
+
>
|
|
20
|
+
<slot />
|
|
21
|
+
</blockquote>
|
package/src/Box.astro
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
|
|
4
|
+
interface Props extends Omit<HTMLAttributes<"div">, "color"> {
|
|
5
|
+
className?: string;
|
|
6
|
+
color?: string;
|
|
7
|
+
}
|
|
8
|
+
const { className, color, ...rest } = Astro.props as Props;
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
<div {...rest} data-accent-color={color} class:list={["el-Box", className]}>
|
|
12
|
+
<slot />
|
|
13
|
+
</div>
|
package/src/Button.astro
CHANGED
|
@@ -38,11 +38,11 @@ const Tag = href ? "a" : "button";
|
|
|
38
38
|
<Tag
|
|
39
39
|
{...rest}
|
|
40
40
|
href={href}
|
|
41
|
-
data-disabled={disabled
|
|
41
|
+
data-disabled={disabled || undefined}
|
|
42
42
|
data-accent-color={color}
|
|
43
43
|
data-radius={radius}
|
|
44
44
|
data-variant={variant}
|
|
45
|
-
data-high-contrast={highContrast
|
|
45
|
+
data-high-contrast={highContrast ? true : undefined}
|
|
46
46
|
class:list={["el-BaseButton", "el-Button", sizes[size], className]}
|
|
47
47
|
disabled={href ? undefined : disabled}
|
|
48
48
|
>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
|
|
4
|
+
type Size = "xs" | "sm" | "md" | "lg";
|
|
5
|
+
|
|
6
|
+
interface Props extends Omit<HTMLAttributes<"div">, "color"> {
|
|
7
|
+
className?: string;
|
|
8
|
+
color?: string;
|
|
9
|
+
highContrast?: boolean;
|
|
10
|
+
radius?: "none" | "small" | "medium" | "large" | "full";
|
|
11
|
+
size?: Size;
|
|
12
|
+
variant?: "soft" | "surface" | "outline";
|
|
13
|
+
}
|
|
14
|
+
const { className, color, highContrast, radius, size = "md", variant = "soft", ...rest } =
|
|
15
|
+
Astro.props as Props;
|
|
16
|
+
|
|
17
|
+
const sizes: Record<Size, string> = {
|
|
18
|
+
xs: "el-Callout-size-xs",
|
|
19
|
+
sm: "el-Callout-size-sm",
|
|
20
|
+
md: "el-Callout-size-md",
|
|
21
|
+
lg: "el-Callout-size-lg",
|
|
22
|
+
};
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
<div
|
|
26
|
+
{...rest}
|
|
27
|
+
data-accent-color={color}
|
|
28
|
+
data-high-contrast={highContrast ? true : undefined}
|
|
29
|
+
data-radius={radius}
|
|
30
|
+
data-variant={variant}
|
|
31
|
+
class:list={["el-Callout", sizes[size], className]}
|
|
32
|
+
>
|
|
33
|
+
<slot />
|
|
34
|
+
</div>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
|
|
4
|
+
interface Props extends HTMLAttributes<"div"> {
|
|
5
|
+
className?: string;
|
|
6
|
+
}
|
|
7
|
+
const { className, ...rest } = Astro.props as Props;
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
<div {...rest} class:list={["el-Callout-icon", className]}>
|
|
11
|
+
<slot />
|
|
12
|
+
</div>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
|
|
4
|
+
interface Props extends HTMLAttributes<"p"> {
|
|
5
|
+
className?: string;
|
|
6
|
+
}
|
|
7
|
+
const { className, ...rest } = Astro.props as Props;
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
<p {...rest} class:list={["el-Callout-text", className]}>
|
|
11
|
+
<slot />
|
|
12
|
+
</p>
|
package/src/Card.astro
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
|
|
4
|
+
type Size = "xs" | "sm" | "md" | "lg" | "xl";
|
|
5
|
+
|
|
6
|
+
interface Props extends Omit<HTMLAttributes<"div">, "color"> {
|
|
7
|
+
className?: string;
|
|
8
|
+
color?: string;
|
|
9
|
+
size?: Size;
|
|
10
|
+
variant?: "surface" | "ghost";
|
|
11
|
+
}
|
|
12
|
+
const { className, color, size = "xs", variant = "surface", ...rest } = Astro.props as Props;
|
|
13
|
+
|
|
14
|
+
const sizes: Record<Size, string> = {
|
|
15
|
+
xs: "el-Card-size-xs",
|
|
16
|
+
sm: "el-Card-size-sm",
|
|
17
|
+
md: "el-Card-size-md",
|
|
18
|
+
lg: "el-Card-size-lg",
|
|
19
|
+
xl: "el-Card-size-xl",
|
|
20
|
+
};
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
<div
|
|
24
|
+
{...rest}
|
|
25
|
+
data-accent-color={color}
|
|
26
|
+
data-variant={variant}
|
|
27
|
+
class:list={["el-BaseCard", "el-Card", sizes[size], className]}
|
|
28
|
+
>
|
|
29
|
+
<slot />
|
|
30
|
+
</div>
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
|
|
4
|
+
type Size = "xs" | "sm" | "md" | "lg";
|
|
5
|
+
|
|
6
|
+
interface Props extends Omit<HTMLAttributes<"label">, "color" | "dir" | "name"> {
|
|
7
|
+
className?: string;
|
|
8
|
+
color?: string;
|
|
9
|
+
defaultChecked?: boolean | "indeterminate";
|
|
10
|
+
dir?: "ltr" | "rtl";
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
highContrast?: boolean;
|
|
13
|
+
invalid?: boolean;
|
|
14
|
+
name?: string;
|
|
15
|
+
radius?: "none" | "small" | "medium" | "large" | "full";
|
|
16
|
+
required?: boolean;
|
|
17
|
+
size?: Size;
|
|
18
|
+
value?: string;
|
|
19
|
+
variant?: "surface" | "soft";
|
|
20
|
+
}
|
|
21
|
+
const {
|
|
22
|
+
className,
|
|
23
|
+
color,
|
|
24
|
+
defaultChecked,
|
|
25
|
+
dir,
|
|
26
|
+
disabled,
|
|
27
|
+
highContrast,
|
|
28
|
+
invalid,
|
|
29
|
+
name,
|
|
30
|
+
radius,
|
|
31
|
+
required,
|
|
32
|
+
size = "md",
|
|
33
|
+
value = "on",
|
|
34
|
+
variant = "surface",
|
|
35
|
+
...rest
|
|
36
|
+
} = Astro.props as Props;
|
|
37
|
+
|
|
38
|
+
const sizes: Record<Size, string> = {
|
|
39
|
+
xs: "el-Checkbox-size-xs",
|
|
40
|
+
sm: "el-Checkbox-size-sm",
|
|
41
|
+
md: "el-Checkbox-size-md",
|
|
42
|
+
lg: "el-Checkbox-size-lg",
|
|
43
|
+
};
|
|
44
|
+
const indeterminate = defaultChecked === "indeterminate";
|
|
45
|
+
const checked = defaultChecked === true;
|
|
46
|
+
const state = indeterminate ? "indeterminate" : checked ? "checked" : "unchecked";
|
|
47
|
+
const hasLabel = Astro.slots.has("default");
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
<!-- display: contents keeps the Zag root (a <label>) as the visual box -->
|
|
51
|
+
<el-checkbox
|
|
52
|
+
style="display: contents"
|
|
53
|
+
data-default-checked={defaultChecked === undefined ? undefined : String(defaultChecked)}
|
|
54
|
+
data-dir={dir}
|
|
55
|
+
>
|
|
56
|
+
<label
|
|
57
|
+
{...rest}
|
|
58
|
+
data-scope="checkbox"
|
|
59
|
+
data-part="root"
|
|
60
|
+
data-state={state}
|
|
61
|
+
data-disabled={disabled ? "" : undefined}
|
|
62
|
+
data-invalid={invalid ? "" : undefined}
|
|
63
|
+
data-accent-color={color}
|
|
64
|
+
data-high-contrast={highContrast ? "true" : undefined}
|
|
65
|
+
data-radius={radius}
|
|
66
|
+
data-variant={variant}
|
|
67
|
+
class:list={["el-Checkbox", sizes[size], className]}
|
|
68
|
+
>
|
|
69
|
+
<div data-scope="checkbox" data-part="control" data-state={state} class="el-Checkbox-control">
|
|
70
|
+
<div
|
|
71
|
+
data-scope="checkbox"
|
|
72
|
+
data-part="indicator"
|
|
73
|
+
data-indicator="checked"
|
|
74
|
+
data-state={state}
|
|
75
|
+
hidden={!checked}
|
|
76
|
+
>
|
|
77
|
+
<svg
|
|
78
|
+
fill="none"
|
|
79
|
+
height="10"
|
|
80
|
+
stroke="currentColor"
|
|
81
|
+
stroke-width="2.5"
|
|
82
|
+
viewBox="0 0 14 14"
|
|
83
|
+
width="10"
|
|
84
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
85
|
+
>
|
|
86
|
+
<path d="M2 7L5.5 10.5L12 3" stroke-linecap="round" stroke-linejoin="round"></path>
|
|
87
|
+
</svg>
|
|
88
|
+
</div>
|
|
89
|
+
<div
|
|
90
|
+
data-scope="checkbox"
|
|
91
|
+
data-part="indicator"
|
|
92
|
+
data-indicator="indeterminate"
|
|
93
|
+
data-state={state}
|
|
94
|
+
hidden={!indeterminate}
|
|
95
|
+
>
|
|
96
|
+
<svg
|
|
97
|
+
fill="none"
|
|
98
|
+
height="10"
|
|
99
|
+
stroke="currentColor"
|
|
100
|
+
stroke-width="2.5"
|
|
101
|
+
viewBox="0 0 14 14"
|
|
102
|
+
width="10"
|
|
103
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
104
|
+
>
|
|
105
|
+
<path d="M2 7H12" stroke-linecap="round"></path>
|
|
106
|
+
</svg>
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
{
|
|
110
|
+
hasLabel && (
|
|
111
|
+
<span data-scope="checkbox" data-part="label" data-state={state} class="el-Checkbox-label">
|
|
112
|
+
<slot />
|
|
113
|
+
</span>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
<input
|
|
117
|
+
type="checkbox"
|
|
118
|
+
data-part="hidden-input"
|
|
119
|
+
name={name}
|
|
120
|
+
value={value}
|
|
121
|
+
checked={checked}
|
|
122
|
+
disabled={disabled}
|
|
123
|
+
required={required}
|
|
124
|
+
style="border:0;clip:rect(0 0 0 0);height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;white-space:nowrap;word-wrap:normal"
|
|
125
|
+
/>
|
|
126
|
+
</label>
|
|
127
|
+
</el-checkbox>
|
|
128
|
+
|
|
129
|
+
<script>
|
|
130
|
+
import * as zcheckbox from "@zag-js/checkbox";
|
|
131
|
+
import { VanillaMachine, normalizeProps } from "@zag-js/vanilla";
|
|
132
|
+
import { createSpreader, nextId, textDirection } from "./internal/zag";
|
|
133
|
+
|
|
134
|
+
type Machine = ReturnType<typeof createMachine>;
|
|
135
|
+
const createMachine = (props: zcheckbox.Props) => new VanillaMachine(zcheckbox.machine, props);
|
|
136
|
+
|
|
137
|
+
class ElCheckbox extends HTMLElement {
|
|
138
|
+
#machine?: Machine;
|
|
139
|
+
#unsubscribe?: () => void;
|
|
140
|
+
#spread = createSpreader("");
|
|
141
|
+
|
|
142
|
+
connectedCallback() {
|
|
143
|
+
if (this.#machine) return;
|
|
144
|
+
const id = nextId("el-checkbox");
|
|
145
|
+
this.#spread = createSpreader(id);
|
|
146
|
+
const input = this.#part("hidden-input") as HTMLInputElement | undefined;
|
|
147
|
+
const initial = this.dataset["defaultChecked"];
|
|
148
|
+
const machine = createMachine({
|
|
149
|
+
id,
|
|
150
|
+
defaultChecked: initial === "indeterminate" ? "indeterminate" : initial === "true",
|
|
151
|
+
disabled: input?.disabled,
|
|
152
|
+
required: input?.required,
|
|
153
|
+
invalid: this.querySelector("[data-invalid]") !== null,
|
|
154
|
+
name: input?.name || undefined,
|
|
155
|
+
value: input?.value,
|
|
156
|
+
dir: textDirection(this),
|
|
157
|
+
getRootNode: () => this.getRootNode(),
|
|
158
|
+
onCheckedChange: ({ checked }: { checked: boolean | "indeterminate" }) =>
|
|
159
|
+
this.dispatchEvent(
|
|
160
|
+
new CustomEvent("el-checkbox:checked-change", { detail: { checked }, bubbles: true }),
|
|
161
|
+
),
|
|
162
|
+
});
|
|
163
|
+
this.#machine = machine;
|
|
164
|
+
machine.start();
|
|
165
|
+
this.#render();
|
|
166
|
+
this.#unsubscribe = machine.subscribe(() => this.#render());
|
|
167
|
+
this.dataset["ready"] = "";
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
disconnectedCallback() {
|
|
171
|
+
this.#unsubscribe?.();
|
|
172
|
+
this.#spread.clear();
|
|
173
|
+
this.#machine?.stop();
|
|
174
|
+
this.#machine = undefined;
|
|
175
|
+
delete this.dataset["ready"];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Programmatic API: `el.checked` / `el.checked = "indeterminate"`. */
|
|
179
|
+
get checked() {
|
|
180
|
+
const api = this.#api();
|
|
181
|
+
return api?.indeterminate ? "indeterminate" : (api?.checked ?? false);
|
|
182
|
+
}
|
|
183
|
+
set checked(checked: boolean | "indeterminate") {
|
|
184
|
+
this.#api()?.setChecked(checked);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
#api() {
|
|
188
|
+
return this.#machine && zcheckbox.connect(this.#machine.service, normalizeProps);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
#part(name: string) {
|
|
192
|
+
return this.querySelector<HTMLElement>(`[data-part='${name}']`) ?? undefined;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
#render() {
|
|
196
|
+
const api = this.#api();
|
|
197
|
+
if (!api) return;
|
|
198
|
+
// Zag never looks the root up by id, so keep the author's `id` instead of its generated one
|
|
199
|
+
const { id: _id, ...rootProps } = api.getRootProps();
|
|
200
|
+
this.#spread.apply(this.#part("root"), rootProps);
|
|
201
|
+
this.#spread.apply(this.#part("control"), api.getControlProps());
|
|
202
|
+
this.#spread.apply(this.#part("label"), api.getLabelProps());
|
|
203
|
+
this.#spread.apply(this.#part("hidden-input"), api.getHiddenInputProps());
|
|
204
|
+
for (const el of this.querySelectorAll<HTMLElement>("[data-part='indicator']")) {
|
|
205
|
+
this.#spread.apply(el, api.getIndicatorProps());
|
|
206
|
+
el.hidden = el.dataset["indicator"] === "indeterminate" ? !api.indeterminate : !api.checked;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (!customElements.get("el-checkbox")) customElements.define("el-checkbox", ElCheckbox);
|
|
212
|
+
</script>
|
package/src/Code.astro
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
|
|
4
|
+
interface Props extends Omit<HTMLAttributes<"code">, "color"> {
|
|
5
|
+
className?: string;
|
|
6
|
+
color?: string;
|
|
7
|
+
highContrast?: boolean;
|
|
8
|
+
size?: "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
9
|
+
variant?: "solid" | "soft" | "surface";
|
|
10
|
+
}
|
|
11
|
+
const { className, color, highContrast, size, variant = "soft", ...rest } = Astro.props as Props;
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
<code
|
|
15
|
+
{...rest}
|
|
16
|
+
data-accent-color={color}
|
|
17
|
+
data-high-contrast={highContrast ? true : undefined}
|
|
18
|
+
data-size={size}
|
|
19
|
+
data-variant={variant}
|
|
20
|
+
class:list={["el-Code", className]}><slot /></code
|
|
21
|
+
>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
|
|
4
|
+
type Size = "xs" | "sm" | "md" | "lg" | "xl";
|
|
5
|
+
|
|
6
|
+
interface Props extends Omit<HTMLAttributes<"div">, "color"> {
|
|
7
|
+
className?: string;
|
|
8
|
+
color?: string;
|
|
9
|
+
size?: Size;
|
|
10
|
+
}
|
|
11
|
+
const { className, color, size = "xl", ...rest } = Astro.props as Props;
|
|
12
|
+
|
|
13
|
+
const sizes: Record<Size, string> = {
|
|
14
|
+
xs: "el-Container-size-xs",
|
|
15
|
+
sm: "el-Container-size-sm",
|
|
16
|
+
md: "el-Container-size-md",
|
|
17
|
+
lg: "el-Container-size-lg",
|
|
18
|
+
xl: "el-Container-size-xl",
|
|
19
|
+
};
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
<div {...rest} data-accent-color={color} class:list={["el-Container", sizes[size], className]}>
|
|
23
|
+
<div class="el-ContainerInner">
|
|
24
|
+
<slot />
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
|
|
4
|
+
interface Props extends HTMLAttributes<"div"> {
|
|
5
|
+
className?: string;
|
|
6
|
+
}
|
|
7
|
+
const { className, style, ...rest } = Astro.props as Props;
|
|
8
|
+
|
|
9
|
+
const hatch =
|
|
10
|
+
"url(\"data:image/svg+xml,%3Csvg width='6' height='6' viewBox='0 0 6 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%239C92AC' fill-opacity='0.2' fill-rule='evenodd'%3E%3Cpath d='M5 0h1L0 6V5zM6 5v1H5z'/%3E%3C/g%3E%3C/svg%3E\")";
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
<div
|
|
14
|
+
{...rest}
|
|
15
|
+
class:list={[
|
|
16
|
+
"bg-gray-a3 border-gray-a5 h-full w-full rounded-md border text-center",
|
|
17
|
+
className,
|
|
18
|
+
]}
|
|
19
|
+
style={[`background-image: ${hatch}`, style].filter(Boolean).join(";")}
|
|
20
|
+
>
|
|
21
|
+
<slot />
|
|
22
|
+
</div>
|
package/src/Em.astro
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { HTMLAttributes } from "astro/types";
|
|
3
|
+
|
|
4
|
+
interface Props extends HTMLAttributes<"em"> {
|
|
5
|
+
className?: string;
|
|
6
|
+
}
|
|
7
|
+
const { className, ...rest } = Astro.props as Props;
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
<em {...rest} class:list={["el-Em", className]}><slot /></em>
|