@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.
Files changed (52) hide show
  1. package/index.ts +46 -0
  2. package/package.json +21 -5
  3. package/src/AccessibleIcon.astro +14 -0
  4. package/src/AspectRatio.astro +14 -0
  5. package/src/Avatar.astro +54 -0
  6. package/src/Badge.astro +34 -0
  7. package/src/Blockquote.astro +21 -0
  8. package/src/Box.astro +13 -0
  9. package/src/Button.astro +2 -2
  10. package/src/Callout.astro +34 -0
  11. package/src/CalloutIcon.astro +12 -0
  12. package/src/CalloutText.astro +12 -0
  13. package/src/Card.astro +30 -0
  14. package/src/Checkbox.astro +212 -0
  15. package/src/Code.astro +21 -0
  16. package/src/Container.astro +26 -0
  17. package/src/DecoratedBox.astro +22 -0
  18. package/src/Em.astro +10 -0
  19. package/src/Flex.astro +25 -0
  20. package/src/Grid.astro +21 -0
  21. package/src/Heading.astro +43 -0
  22. package/src/InputControl.astro +40 -0
  23. package/src/InputField.astro +10 -0
  24. package/src/InputSlot.astro +41 -0
  25. package/src/Kbd.astro +11 -0
  26. package/src/Link.astro +33 -0
  27. package/src/Panel.astro +12 -0
  28. package/src/Progress.astro +63 -0
  29. package/src/Quote.astro +10 -0
  30. package/src/RadioCards.astro +71 -0
  31. package/src/RadioCardsItem.astro +41 -0
  32. package/src/RadioGroup.astro +70 -0
  33. package/src/RadioGroupItem.astro +53 -0
  34. package/src/Section.astro +23 -0
  35. package/src/SegmentedControl.astro +189 -0
  36. package/src/Separator.astro +25 -0
  37. package/src/Skeleton.astro +30 -0
  38. package/src/Spinner.astro +31 -0
  39. package/src/Strong.astro +10 -0
  40. package/src/Switch.astro +164 -0
  41. package/src/Tabs.astro +179 -0
  42. package/src/TabsContent.astro +20 -0
  43. package/src/TabsIndicator.astro +17 -0
  44. package/src/TabsList.astro +12 -0
  45. package/src/TabsTrigger.astro +23 -0
  46. package/src/Text.astro +43 -0
  47. package/src/TextArea.astro +30 -0
  48. package/src/TextField.astro +70 -0
  49. package/src/VisuallyHidden.astro +10 -0
  50. package/src/internal/radio-group.ts +82 -0
  51. package/src/internal/ssr.ts +18 -0
  52. package/src/internal/zag.ts +24 -0
package/src/Flex.astro ADDED
@@ -0,0 +1,25 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+
4
+ interface Props extends HTMLAttributes<"div"> {
5
+ align?: "start" | "center" | "end" | "stretch" | "baseline";
6
+ className?: string;
7
+ direction?: "row" | "column" | "row-reverse" | "column-reverse";
8
+ gap?: "xs" | "sm" | "md" | "lg" | "xl";
9
+ justify?: "start" | "center" | "end" | "between" | "around" | "evenly";
10
+ wrap?: "nowrap" | "wrap" | "wrap-reverse";
11
+ }
12
+ const { align, className, direction, gap, justify, wrap, ...rest } = Astro.props as Props;
13
+ ---
14
+
15
+ <div
16
+ {...rest}
17
+ data-align={align}
18
+ data-direction={direction}
19
+ data-gap={gap}
20
+ data-justify={justify}
21
+ data-wrap={wrap}
22
+ class:list={["el-Flex", className]}
23
+ >
24
+ <slot />
25
+ </div>
package/src/Grid.astro ADDED
@@ -0,0 +1,21 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+
4
+ interface Props extends Omit<HTMLAttributes<"div">, "style"> {
5
+ className?: string;
6
+ columns?: string;
7
+ gap?: "xs" | "sm" | "md" | "lg" | "xl";
8
+ style?: Record<string, string | number>;
9
+ }
10
+ const { className, columns, gap, style, ...rest } = Astro.props as Props;
11
+ ---
12
+
13
+ <div
14
+ {...rest}
15
+ data-columns={columns}
16
+ data-gap={gap}
17
+ class:list={["el-Grid", className]}
18
+ style={columns ? { gridTemplateColumns: columns, ...style } : style}
19
+ >
20
+ <slot />
21
+ </div>
@@ -0,0 +1,43 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+
4
+ interface Props extends Omit<HTMLAttributes<"h2">, "color"> {
5
+ align?: "left" | "center" | "right";
6
+ as?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
7
+ className?: string;
8
+ color?: string;
9
+ highContrast?: boolean;
10
+ size?: "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
11
+ trim?: "normal" | "start" | "end" | "both";
12
+ truncate?: boolean;
13
+ weight?: "light" | "regular" | "medium" | "bold";
14
+ wrap?: "normal" | "nowrap" | "pretty" | "balance";
15
+ }
16
+ const {
17
+ align,
18
+ as: Tag = "h2",
19
+ className,
20
+ color,
21
+ highContrast,
22
+ size,
23
+ trim,
24
+ truncate,
25
+ weight,
26
+ wrap,
27
+ ...rest
28
+ } = Astro.props as Props;
29
+ ---
30
+
31
+ <Tag
32
+ {...rest}
33
+ data-accent-color={color}
34
+ data-align={align}
35
+ data-high-contrast={highContrast ? true : undefined}
36
+ data-size={size}
37
+ data-trim={trim}
38
+ data-weight={weight}
39
+ data-wrap={wrap}
40
+ class:list={["el-Heading", truncate && "el-Heading-truncate", className]}
41
+ >
42
+ <slot />
43
+ </Tag>
@@ -0,0 +1,40 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+
4
+ interface Props extends Omit<HTMLAttributes<"div">, "color"> {
5
+ className?: string;
6
+ color?: string;
7
+ /** Defaults to the surrounding `TextField` variant, else surface. */
8
+ variant?: "surface" | "soft";
9
+ }
10
+ const { className, color, variant, ...rest } = Astro.props as Props;
11
+ ---
12
+
13
+ <div
14
+ {...rest}
15
+ data-accent-color={color}
16
+ data-variant={variant}
17
+ class:list={["el-InputControl", className]}
18
+ >
19
+ <slot />
20
+ </div>
21
+
22
+ <script>
23
+ // Clicking a slot (not the input, a button or a link) focuses the input, like the React InputControl
24
+ const rightSlot =
25
+ ".el-InputSlot[data-side='right'], .el-InputSlot:not([data-side='right']) ~ .el-InputSlot:not([data-side='left'])";
26
+ document.addEventListener("pointerdown", (event) => {
27
+ const target = event.target;
28
+ if (!(target instanceof Element) || target.closest("input, button, a")) return;
29
+ const control = target.closest(".el-InputControl");
30
+ const input = control?.querySelector<HTMLInputElement>(".el-InputField");
31
+ if (!input || event.defaultPrevented) return;
32
+ const position = target.closest(rightSlot) ? input.value.length : 0;
33
+ requestAnimationFrame(() => {
34
+ try {
35
+ input.setSelectionRange(position, position);
36
+ } catch {}
37
+ input.focus();
38
+ });
39
+ });
40
+ </script>
@@ -0,0 +1,10 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+
4
+ interface Props extends HTMLAttributes<"input"> {
5
+ className?: string;
6
+ }
7
+ const { className, ...rest } = Astro.props as Props;
8
+ ---
9
+
10
+ <input {...rest} class:list={["el-InputField", className]} />
@@ -0,0 +1,41 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+
4
+ type Space = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
5
+
6
+ interface Props extends Omit<HTMLAttributes<"div">, "color" | "style"> {
7
+ className?: string;
8
+ /** Tints the slot with `--accent-a11`. */
9
+ color?: string;
10
+ /** Defaults to left; two unsided slots land left then right. */
11
+ side?: "left" | "right";
12
+ /** Space scale step (0-9) overriding the size-based defaults. */
13
+ gap?: Space;
14
+ px?: Space;
15
+ pl?: Space;
16
+ pr?: Space;
17
+ style?: string;
18
+ }
19
+ const { className, color, side, gap, px, pl, pr, style, ...rest } = Astro.props as Props;
20
+
21
+ const space = (value?: Space) => (value === undefined ? undefined : `var(--space-${value})`);
22
+ const vars = Object.entries({
23
+ "--slot-gap": space(gap),
24
+ "--slot-px": space(px),
25
+ "--slot-pl": space(pl),
26
+ "--slot-pr": space(pr),
27
+ })
28
+ .filter(([, value]) => value !== undefined)
29
+ .map(([name, value]) => `${name}: ${value}`);
30
+ const css = [...vars, style].filter(Boolean).join("; ") || undefined;
31
+ ---
32
+
33
+ <div
34
+ {...rest}
35
+ data-accent-color={color}
36
+ data-side={side}
37
+ style={css}
38
+ class:list={["el-InputSlot", className]}
39
+ >
40
+ <slot />
41
+ </div>
package/src/Kbd.astro ADDED
@@ -0,0 +1,11 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+
4
+ interface Props extends HTMLAttributes<"kbd"> {
5
+ className?: string;
6
+ size?: "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
7
+ }
8
+ const { className, size, ...rest } = Astro.props as Props;
9
+ ---
10
+
11
+ <kbd {...rest} data-size={size} class:list={["el-Kbd", className]}><slot /></kbd>
package/src/Link.astro ADDED
@@ -0,0 +1,33 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+
4
+ interface Props extends Omit<HTMLAttributes<"a">, "color"> {
5
+ className?: string;
6
+ color?: string;
7
+ highContrast?: boolean;
8
+ size?: "xs" | "sm" | "md" | "lg" | "xl";
9
+ truncate?: boolean;
10
+ underline?: "auto" | "always" | "hover" | "none";
11
+ variant?: "soft" | "surface" | "outline";
12
+ }
13
+ const {
14
+ className,
15
+ color,
16
+ highContrast,
17
+ size,
18
+ truncate,
19
+ underline = "auto",
20
+ variant,
21
+ ...rest
22
+ } = Astro.props as Props;
23
+ ---
24
+
25
+ <a
26
+ {...rest}
27
+ data-accent-color={color}
28
+ data-high-contrast={highContrast ? true : undefined}
29
+ data-size={size}
30
+ data-underline={underline}
31
+ data-variant={variant}
32
+ class:list={["el-Link", truncate && "el-Link-truncate", className]}><slot /></a
33
+ >
@@ -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-PanelBase", className]}>
11
+ <slot />
12
+ </div>
@@ -0,0 +1,63 @@
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
+ max?: number;
11
+ min?: number;
12
+ radius?: "none" | "small" | "medium" | "large" | "full";
13
+ size?: Size;
14
+ /** Omit for an indeterminate progress bar */
15
+ value?: number;
16
+ variant?: "soft" | "surface";
17
+ }
18
+ const {
19
+ className,
20
+ color,
21
+ highContrast,
22
+ max = 100,
23
+ min = 0,
24
+ radius,
25
+ size = "md",
26
+ value,
27
+ variant = "surface",
28
+ ...rest
29
+ } = Astro.props as Props;
30
+
31
+ const sizes: Record<Size, string> = {
32
+ xs: "el-Progress-size-xs",
33
+ sm: "el-Progress-size-sm",
34
+ md: "el-Progress-size-md",
35
+ lg: "el-Progress-size-lg",
36
+ };
37
+
38
+ const indeterminate = value === undefined;
39
+ const percent = indeterminate ? undefined : ((value - min) / (max - min)) * 100;
40
+ const state = indeterminate ? "indeterminate" : value >= max ? "complete" : "loading";
41
+ ---
42
+
43
+ <div
44
+ {...rest}
45
+ role="progressbar"
46
+ aria-valuemin={min}
47
+ aria-valuemax={max}
48
+ aria-valuenow={value}
49
+ data-accent-color={color}
50
+ data-high-contrast={highContrast ? "true" : undefined}
51
+ data-state={state}
52
+ data-variant={variant}
53
+ class:list={["el-Progress", sizes[size], className]}
54
+ >
55
+ <div class="el-Progress-track" data-radius={radius}>
56
+ <div
57
+ class="el-Progress-range"
58
+ data-state={state}
59
+ style={percent === undefined ? undefined : { width: `${percent}%` }}
60
+ >
61
+ </div>
62
+ </div>
63
+ </div>
@@ -0,0 +1,10 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+
4
+ interface Props extends HTMLAttributes<"q"> {
5
+ className?: string;
6
+ }
7
+ const { className, ...rest } = Astro.props as Props;
8
+ ---
9
+
10
+ <q {...rest} class:list={["el-Quote", className]}><slot /></q>
@@ -0,0 +1,71 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import { markChecked } from "./internal/ssr";
4
+
5
+ type Size = "xs" | "sm" | "md";
6
+
7
+ interface Props extends Omit<HTMLAttributes<"div">, "color" | "dir" | "name"> {
8
+ className?: string;
9
+ color?: string;
10
+ defaultValue?: string;
11
+ dir?: "ltr" | "rtl";
12
+ disabled?: boolean;
13
+ highContrast?: boolean;
14
+ name?: string;
15
+ orientation?: "horizontal" | "vertical";
16
+ radius?: "none" | "small" | "medium" | "large" | "full";
17
+ required?: boolean;
18
+ size?: Size;
19
+ variant?: "surface";
20
+ }
21
+ const {
22
+ className,
23
+ color,
24
+ defaultValue,
25
+ dir,
26
+ disabled,
27
+ highContrast,
28
+ name,
29
+ orientation = "vertical",
30
+ radius,
31
+ required,
32
+ size = "sm",
33
+ variant = "surface",
34
+ ...rest
35
+ } = Astro.props as Props;
36
+
37
+ const sizes: Record<Size, string> = {
38
+ xs: "el-RadioCards-size-xs",
39
+ sm: "el-RadioCards-size-sm",
40
+ md: "el-RadioCards-size-md",
41
+ };
42
+ const items = markChecked(await Astro.slots.render("default"), defaultValue);
43
+ ---
44
+
45
+ <!-- Same Zag radio-group machine as RadioGroup: the custom element is shared -->
46
+ <el-radio-group
47
+ {...rest}
48
+ role="radiogroup"
49
+ data-scope="radio-group"
50
+ data-part="root"
51
+ data-slot="control"
52
+ data-accent-color={color}
53
+ data-default-value={defaultValue}
54
+ data-dir={dir}
55
+ data-disabled={disabled ? "" : undefined}
56
+ data-high-contrast={highContrast ? "true" : undefined}
57
+ data-name={name}
58
+ data-orientation={orientation}
59
+ data-radius={radius}
60
+ data-required={required ? "true" : undefined}
61
+ data-variant={variant}
62
+ class:list={["el-RadioCardsRoot", sizes[size], className]}
63
+ >
64
+ <Fragment set:html={items} />
65
+ </el-radio-group>
66
+
67
+ <script>
68
+ import { defineRadioGroup } from "./internal/radio-group";
69
+
70
+ defineRadioGroup();
71
+ </script>
@@ -0,0 +1,41 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+
4
+ interface Props extends Omit<HTMLAttributes<"label">, "value" | "color"> {
5
+ className?: string;
6
+ color?: string;
7
+ disabled?: boolean;
8
+ value: string;
9
+ }
10
+ const { className, color, disabled, value, ...rest } = Astro.props as Props;
11
+ ---
12
+
13
+ <label
14
+ {...rest}
15
+ data-scope="radio-group"
16
+ data-part="item"
17
+ data-state="unchecked"
18
+ data-accent-color={color}
19
+ data-item-value={value}
20
+ data-item-disabled={disabled ? "" : undefined}
21
+ data-disabled={disabled ? "" : undefined}
22
+ class:list={["el-BaseCard el-RadioCardsItem", className]}
23
+ >
24
+ <span
25
+ data-scope="radio-group"
26
+ data-part="item-text"
27
+ data-state="unchecked"
28
+ data-item-value={value}
29
+ >
30
+ <slot />
31
+ </span>
32
+ <input
33
+ type="radio"
34
+ data-part="hidden-input"
35
+ data-state="unchecked"
36
+ data-item-value={value}
37
+ value={value}
38
+ disabled={disabled}
39
+ 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"
40
+ />
41
+ </label>
@@ -0,0 +1,70 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+ import { markChecked } from "./internal/ssr";
4
+
5
+ type Size = "xs" | "sm" | "md" | "lg";
6
+
7
+ interface Props extends Omit<HTMLAttributes<"div">, "color" | "dir" | "name"> {
8
+ className?: string;
9
+ color?: string;
10
+ defaultValue?: string;
11
+ dir?: "ltr" | "rtl";
12
+ disabled?: boolean;
13
+ highContrast?: boolean;
14
+ name?: string;
15
+ orientation?: "horizontal" | "vertical";
16
+ radius?: "none" | "small" | "medium" | "large" | "full";
17
+ required?: boolean;
18
+ size?: Size;
19
+ variant?: "surface" | "soft";
20
+ }
21
+ const {
22
+ className,
23
+ color,
24
+ defaultValue,
25
+ dir,
26
+ disabled,
27
+ highContrast,
28
+ name,
29
+ orientation = "vertical",
30
+ radius,
31
+ required,
32
+ size = "md",
33
+ variant = "surface",
34
+ ...rest
35
+ } = Astro.props as Props;
36
+
37
+ const sizes: Record<Size, string> = {
38
+ xs: "el-RadioGroup-size-xs",
39
+ sm: "el-RadioGroup-size-sm",
40
+ md: "el-RadioGroup-size-md",
41
+ lg: "el-RadioGroup-size-lg",
42
+ };
43
+ const items = markChecked(await Astro.slots.render("default"), defaultValue);
44
+ ---
45
+
46
+ <el-radio-group
47
+ {...rest}
48
+ role="radiogroup"
49
+ data-scope="radio-group"
50
+ data-part="root"
51
+ data-accent-color={color}
52
+ data-default-value={defaultValue}
53
+ data-dir={dir}
54
+ data-disabled={disabled ? "" : undefined}
55
+ data-high-contrast={highContrast ? "true" : undefined}
56
+ data-name={name}
57
+ data-orientation={orientation}
58
+ data-radius={radius}
59
+ data-required={required ? "true" : undefined}
60
+ data-variant={variant}
61
+ class:list={["el-RadioGroup", sizes[size], className]}
62
+ >
63
+ <Fragment set:html={items} />
64
+ </el-radio-group>
65
+
66
+ <script>
67
+ import { defineRadioGroup } from "./internal/radio-group";
68
+
69
+ defineRadioGroup();
70
+ </script>
@@ -0,0 +1,53 @@
1
+ ---
2
+ import type { HTMLAttributes } from "astro/types";
3
+
4
+ interface Props extends Omit<HTMLAttributes<"label">, "value"> {
5
+ className?: string;
6
+ disabled?: boolean;
7
+ value: string;
8
+ }
9
+ const { className, disabled, value, ...rest } = Astro.props as Props;
10
+ const hasText = Astro.slots.has("default");
11
+ ---
12
+
13
+ <label
14
+ {...rest}
15
+ data-scope="radio-group"
16
+ data-part="item"
17
+ data-state="unchecked"
18
+ data-item-value={value}
19
+ data-item-disabled={disabled ? "" : undefined}
20
+ data-disabled={disabled ? "" : undefined}
21
+ class:list={["el-RadioGroup-item", className]}
22
+ >
23
+ <div
24
+ data-scope="radio-group"
25
+ data-part="item-control"
26
+ data-state="unchecked"
27
+ data-item-value={value}
28
+ class="el-RadioGroup-itemControl"
29
+ >
30
+ </div>
31
+ {
32
+ hasText && (
33
+ <span
34
+ data-scope="radio-group"
35
+ data-part="item-text"
36
+ data-state="unchecked"
37
+ data-item-value={value}
38
+ class="el-RadioGroup-itemText"
39
+ >
40
+ <slot />
41
+ </span>
42
+ )
43
+ }
44
+ <input
45
+ type="radio"
46
+ data-part="hidden-input"
47
+ data-state="unchecked"
48
+ data-item-value={value}
49
+ value={value}
50
+ disabled={disabled}
51
+ 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"
52
+ />
53
+ </label>
@@ -0,0 +1,23 @@
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
+ size?: Size;
10
+ }
11
+ const { className, color, size = "md", ...rest } = Astro.props as Props;
12
+
13
+ const sizes: Record<Size, string> = {
14
+ xs: "el-Section-size-xs",
15
+ sm: "el-Section-size-sm",
16
+ md: "el-Section-size-md",
17
+ lg: "el-Section-size-lg",
18
+ };
19
+ ---
20
+
21
+ <div {...rest} data-accent-color={color} class:list={["el-Section", sizes[size], className]}>
22
+ <slot />
23
+ </div>