kosui 0.0.24 → 0.0.25

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/index.d.ts CHANGED
@@ -33,6 +33,7 @@ export * from "./portal";
33
33
  export * from "./progress";
34
34
  export * from "./shortcut";
35
35
  export * from "./skeleton";
36
+ export * from "./switch";
36
37
  export * from "./textarea";
37
38
  export * from "./toggle";
38
39
  export * from "./tooltip";
package/dist/index.js CHANGED
@@ -33,6 +33,7 @@ export * from "./portal";
33
33
  export * from "./progress";
34
34
  export * from "./shortcut";
35
35
  export * from "./skeleton";
36
+ export * from "./switch";
36
37
  export * from "./textarea";
37
38
  export * from "./toggle";
38
39
  export * from "./tooltip";
@@ -1,20 +1,18 @@
1
1
  <script lang="ts" module>
2
+ import type { HTMLInputAttributes } from "svelte/elements";
3
+ import { twMerge } from "tailwind-merge";
2
4
  import {
3
5
  COLORS,
4
- noop,
5
6
  RADII,
6
7
  SIZES,
7
- type ClassName,
8
8
  type Color,
9
9
  type ColorProp,
10
- type ElementRef,
11
10
  type Radius,
12
11
  type RadiusProp,
13
12
  type Size,
14
13
  type SizeProp,
15
- } from "..";
16
- import type { HTMLInputAttributes } from "svelte/elements";
17
- import { twMerge } from "tailwind-merge";
14
+ } from "../base";
15
+ import { noop, type ClassName, type ElementRef } from "../utils";
18
16
 
19
17
  export const INPUT_VARIANTS = ["outlined", "filled", "inherit"] as const;
20
18
  export type InputVariant = (typeof INPUT_VARIANTS)[number];
@@ -60,6 +58,8 @@
60
58
  bind:this={el}
61
59
  use:ref
62
60
  class={twMerge(
61
+ "disabled:cursor-not-allowed disabled:bg-m3-on-surface/12 disabled:text-m3-on-surface/38",
62
+
63
63
  variant === "outlined" &&
64
64
  "bg-m3-surface-container-lowest outline-1 outline-m3-outline-variant hover:outline-m3-outline/80 disabled:hover:outline-m3-outline-variant",
65
65
  variant === "filled" &&
@@ -82,8 +82,6 @@
82
82
  radius == "lg" && "rounded-2xl",
83
83
  radius == "xl" && "rounded-4xl",
84
84
 
85
- "disabled:cursor-not-allowed disabled:bg-m3-on-surface/12 disabled:text-m3-on-surface/38",
86
-
87
85
  className,
88
86
  )}
89
87
  {...restProps}
@@ -1,5 +1,6 @@
1
- import { type ClassName, type Color, type ColorProp, type ElementRef, type Radius, type RadiusProp, type Size, type SizeProp } from "..";
2
1
  import type { HTMLInputAttributes } from "svelte/elements";
2
+ import { type Color, type ColorProp, type Radius, type RadiusProp, type Size, type SizeProp } from "../base";
3
+ import { type ClassName, type ElementRef } from "../utils";
3
4
  export declare const INPUT_VARIANTS: readonly ["outlined", "filled", "inherit"];
4
5
  export type InputVariant = (typeof INPUT_VARIANTS)[number];
5
6
  export type InputVariantProp = {
@@ -0,0 +1 @@
1
+ export { default as Switch, SWITCH_COLORS, SWITCH_RADII, SWITCH_SIZES, type SwitchColor, type SwitchColorProp, type SwitchProps, type SwitchRadius, type SwitchRadiusProp, type SwitchSize, type SwitchSizeProp, } from "./switch.svelte";
@@ -0,0 +1 @@
1
+ export { default as Switch, SWITCH_COLORS, SWITCH_RADII, SWITCH_SIZES, } from "./switch.svelte";
@@ -0,0 +1,107 @@
1
+ <script lang="ts" module>
2
+ import type { HTMLButtonAttributes } from "svelte/elements";
3
+ import { twMerge } from "tailwind-merge";
4
+ import {
5
+ COLORS,
6
+ RADII,
7
+ SIZES,
8
+ type Color,
9
+ type ColorProp,
10
+ type Radius,
11
+ type RadiusProp,
12
+ type Size,
13
+ type SizeProp,
14
+ } from "../base";
15
+ import { mergeProps } from "../merge-props";
16
+ import type { ClassName } from "../utils";
17
+
18
+ export const SWITCH_COLORS = COLORS;
19
+ export type SwitchColor = Color;
20
+ export type SwitchColorProp = ColorProp;
21
+
22
+ export const SWITCH_SIZES = SIZES;
23
+ export type SwitchSize = Size;
24
+ export type SwitchSizeProp = SizeProp;
25
+
26
+ export const SWITCH_RADII = RADII;
27
+ export type SwitchRadius = Radius;
28
+ export type SwitchRadiusProp = RadiusProp;
29
+
30
+ export type SwitchProps = {
31
+ checked?: boolean;
32
+ } & ClassName &
33
+ SwitchSizeProp &
34
+ SwitchRadiusProp &
35
+ SwitchColorProp &
36
+ HTMLButtonAttributes;
37
+ </script>
38
+
39
+ <script lang="ts">
40
+ let {
41
+ checked = $bindable(false),
42
+ class: className,
43
+ color = "primary",
44
+ size = "sm",
45
+ radius = "xl",
46
+ ...restProps
47
+ }: SwitchProps = $props();
48
+ </script>
49
+
50
+ <button
51
+ type="button"
52
+ role="switch"
53
+ aria-checked={checked}
54
+ class={twMerge(
55
+ "group relative inline-flex cursor-pointer transition-all focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
56
+
57
+ color === "primary" && "focus-visible:outline-m3-primary",
58
+ color === "secondary" && "focus-visible:outline-m3-secondary",
59
+ color === "tertiary" && "focus-visible:outline-m3-tertiary",
60
+ color === "error" && "focus-visible:outline-m3-error",
61
+
62
+ className,
63
+ )}
64
+ {...mergeProps(restProps, { onclick: () => (checked = !checked) })}
65
+ >
66
+ <!-- Track -->
67
+ <div
68
+ class={twMerge(
69
+ "bg-m3-surface-container-highest transition-colors",
70
+
71
+ color === "primary" && "group-aria-checked:bg-m3-primary",
72
+ color === "secondary" && "group-aria-checked:bg-m3-secondary",
73
+ color === "tertiary" && "group-aria-checked:bg-m3-tertiary",
74
+ color === "error" && "group-aria-checked:bg-m3-error",
75
+
76
+ size === "xs" && "h-4 w-8",
77
+ size === "sm" && "h-5 w-10",
78
+ size === "md" && "h-6 w-12",
79
+ size === "lg" && "h-7 w-14",
80
+ size === "xl" && "h-8 w-16",
81
+
82
+ radius === "xs" && "rounded-xs",
83
+ radius === "sm" && "rounded-sm",
84
+ radius === "md" && "rounded-lg",
85
+ radius === "lg" && "rounded-2xl",
86
+ radius === "xl" && "rounded-4xl",
87
+ )}
88
+ ></div>
89
+ <!-- Thumb -->
90
+ <div
91
+ class={twMerge(
92
+ "absolute top-0.5 left-0.5 bg-m3-on-primary shadow-sm transition-all",
93
+
94
+ size === "xs" && "size-3 group-aria-checked:translate-x-4",
95
+ size === "sm" && "size-4 group-aria-checked:translate-x-5",
96
+ size === "md" && "size-5 group-aria-checked:translate-x-6",
97
+ size === "lg" && "size-6 group-aria-checked:translate-x-7",
98
+ size === "xl" && "size-7 group-aria-checked:translate-x-8",
99
+
100
+ radius === "xs" && "rounded-xs",
101
+ radius === "sm" && "rounded-sm",
102
+ radius === "md" && "rounded-lg",
103
+ radius === "lg" && "rounded-2xl",
104
+ radius === "xl" && "rounded-4xl",
105
+ )}
106
+ ></div>
107
+ </button>
@@ -0,0 +1,18 @@
1
+ import type { HTMLButtonAttributes } from "svelte/elements";
2
+ import { type Color, type ColorProp, type Radius, type RadiusProp, type Size, type SizeProp } from "../base";
3
+ import type { ClassName } from "../utils";
4
+ export declare const SWITCH_COLORS: readonly ["primary", "secondary", "tertiary", "error", "inherit"];
5
+ export type SwitchColor = Color;
6
+ export type SwitchColorProp = ColorProp;
7
+ export declare const SWITCH_SIZES: readonly ["xs", "sm", "md", "lg", "xl", "inherit"];
8
+ export type SwitchSize = Size;
9
+ export type SwitchSizeProp = SizeProp;
10
+ export declare const SWITCH_RADII: readonly ["xs", "sm", "md", "lg", "xl", "inherit"];
11
+ export type SwitchRadius = Radius;
12
+ export type SwitchRadiusProp = RadiusProp;
13
+ export type SwitchProps = {
14
+ checked?: boolean;
15
+ } & ClassName & SwitchSizeProp & SwitchRadiusProp & SwitchColorProp & HTMLButtonAttributes;
16
+ declare const Switch: import("svelte").Component<SwitchProps, {}, "checked">;
17
+ type Switch = ReturnType<typeof Switch>;
18
+ export default Switch;
@@ -53,6 +53,8 @@
53
53
  <textarea
54
54
  bind:value
55
55
  class={twMerge(
56
+ "px-3 py-2 disabled:cursor-not-allowed disabled:bg-m3-on-surface/12 disabled:text-m3-on-surface/38",
57
+
56
58
  variant === "outlined" &&
57
59
  "bg-m3-surface-container-lowest outline-1 outline-m3-outline-variant hover:outline-m3-outline/80 disabled:hover:outline-m3-outline-variant",
58
60
  variant === "filled" &&
@@ -75,9 +77,6 @@
75
77
  radius == "lg" && "rounded-2xl",
76
78
  radius == "xl" && "rounded-4xl",
77
79
 
78
- "disabled:cursor-not-allowed disabled:bg-m3-on-surface/12 disabled:text-m3-on-surface/38",
79
-
80
- "px-3 py-2",
81
80
  className,
82
81
  )}
83
82
  {...restProps}
@@ -36,6 +36,13 @@
36
36
  );
37
37
  </script>
38
38
 
39
- <div bind:this={el} use:ref class={twMerge("flex", className)} {...restProps}>
39
+ <div
40
+ bind:this={el}
41
+ use:ref
42
+ role="listbox"
43
+ aria-orientation="horizontal"
44
+ class={twMerge("flex", className)}
45
+ {...restProps}
46
+ >
40
47
  {@render children()}
41
48
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kosui",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {