kosui 0.0.20 → 0.0.24

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.
@@ -1,14 +1,8 @@
1
1
  <script module lang="ts">
2
- import type { HTMLInputAttributes } from "svelte/elements";
3
- import { type Variants } from "../base";
4
- import { Input } from "../input";
5
- import type { ClassName, ElementRef } from "../utils";
2
+ import { Input, type InputProps } from "..";
6
3
  import { getAutocompleteContext } from "./autocomplete-context.svelte";
7
4
 
8
- export type AutocompleteInputProps = {} & ElementRef &
9
- ClassName &
10
- Variants &
11
- Omit<HTMLInputAttributes, "autocomplete">;
5
+ export type AutocompleteInputProps = InputProps;
12
6
  </script>
13
7
 
14
8
  <script lang="ts">
@@ -1,7 +1,5 @@
1
- import type { HTMLInputAttributes } from "svelte/elements";
2
- import { type Variants } from "../base";
3
- import type { ClassName, ElementRef } from "../utils";
4
- export type AutocompleteInputProps = {} & ElementRef & ClassName & Variants & Omit<HTMLInputAttributes, "autocomplete">;
5
- declare const AutocompleteInput: import("svelte").Component<AutocompleteInputProps, {}, "el" | "value">;
1
+ import { type InputProps } from "..";
2
+ export type AutocompleteInputProps = InputProps;
3
+ declare const AutocompleteInput: import("svelte").Component<InputProps, {}, "el" | "value">;
6
4
  type AutocompleteInput = ReturnType<typeof AutocompleteInput>;
7
5
  export default AutocompleteInput;
package/dist/base.d.ts CHANGED
@@ -1,20 +1,34 @@
1
- export declare const variants: readonly ["elevated", "filled", "tonal", "outlined", "plain", "text"];
2
- export declare const colors: readonly ["primary", "secondary", "tertiary", "error", "inherit"];
3
- export declare const shapes: readonly ["square", "rounded", "circle"];
4
- export declare const underlines: readonly ["always", "hover", "none"];
5
- export type Variant = {
6
- variant?: (typeof variants)[number];
1
+ export declare const VARIANTS: readonly ["elevated", "filled", "tonal", "outlined", "plain", "text"];
2
+ export type Variant = (typeof VARIANTS)[number];
3
+ export type VariantProp = {
4
+ variant?: Variant;
7
5
  };
8
- export type Color = {
9
- color?: (typeof colors)[number];
6
+ export declare const COLORS: readonly ["primary", "secondary", "tertiary", "error", "inherit"];
7
+ export type Color = (typeof COLORS)[number];
8
+ export type ColorProp = {
9
+ color?: Color;
10
10
  };
11
- export type Shape = {
12
- shape?: (typeof shapes)[number];
11
+ export declare const SHAPES: readonly ["square", "rounded", "circle"];
12
+ export type Shape = (typeof SHAPES)[number];
13
+ export type ShapeProp = {
14
+ shape?: Shape;
13
15
  };
14
- export type Underline = {
15
- underline?: (typeof underlines)[number];
16
+ export declare const SIZES: readonly ["xs", "sm", "md", "lg", "xl", "inherit"];
17
+ export type Size = (typeof SIZES)[number];
18
+ export type SizeProp = {
19
+ size?: Size;
16
20
  };
17
- export type Variants = Variant & Color & Shape & Underline & {
21
+ export declare const RADII: readonly ["xs", "sm", "md", "lg", "xl", "inherit"];
22
+ export type Radius = (typeof RADII)[number];
23
+ export type RadiusProp = {
24
+ radius?: Radius;
25
+ };
26
+ export declare const UNDERLINES: readonly ["always", "hover", "none"];
27
+ export type Underline = (typeof UNDERLINES)[number];
28
+ export type UnderlineProp = {
29
+ underline?: Underline;
30
+ };
31
+ export type Variants = VariantProp & ColorProp & ShapeProp & UnderlineProp & {
18
32
  hover?: boolean;
19
33
  focus?: boolean;
20
34
  };
package/dist/base.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { twMerge } from "tailwind-merge";
2
- export const variants = [
2
+ export const VARIANTS = [
3
3
  "elevated",
4
4
  "filled",
5
5
  "tonal",
@@ -7,15 +7,17 @@ export const variants = [
7
7
  "plain",
8
8
  "text",
9
9
  ];
10
- export const colors = [
10
+ export const COLORS = [
11
11
  "primary",
12
12
  "secondary",
13
13
  "tertiary",
14
14
  "error",
15
15
  "inherit",
16
16
  ];
17
- export const shapes = ["square", "rounded", "circle"];
18
- export const underlines = ["always", "hover", "none"];
17
+ export const SHAPES = ["square", "rounded", "circle"];
18
+ export const SIZES = ["xs", "sm", "md", "lg", "xl", "inherit"];
19
+ export const RADII = ["xs", "sm", "md", "lg", "xl", "inherit"];
20
+ export const UNDERLINES = ["always", "hover", "none"];
19
21
  const hoverBaseClasses = ({ variant, color }) => twMerge("disabled:text-m3-on-surface/38 disabled:bg-m3-on-surface/12 disabled:cursor-not-allowed", variant === "filled" && "hover:opacity-90", variant === "tonal" && "hover:opacity-80", variant === "text" && "hover:opacity-80", variant === "elevated" &&
20
22
  color === "primary" &&
21
23
  "hover:bg-m3-primary-container/30", variant === "elevated" &&
package/dist/index.d.ts CHANGED
@@ -38,4 +38,5 @@ export * from "./toggle";
38
38
  export * from "./tooltip";
39
39
  export * from "./base";
40
40
  export * from "./merge-props";
41
+ export * from "./stores.svelte";
41
42
  export * from "./utils";
package/dist/index.js CHANGED
@@ -38,4 +38,5 @@ export * from "./toggle";
38
38
  export * from "./tooltip";
39
39
  export * from "./base";
40
40
  export * from "./merge-props";
41
+ export * from "./stores.svelte";
41
42
  export * from "./utils";
@@ -1 +1 @@
1
- export { default as Input, type InputProps } from "./input.svelte";
1
+ export { default as Input, INPUT_COLORS, INPUT_RADII, INPUT_SIZES, INPUT_VARIANTS, type InputColor, type InputColorProp, type InputProps, type InputRadius, type InputRadiusProp, type InputSize, type InputSizeProp, type InputVariant, type InputVariantProp, } from "./input.svelte";
@@ -1 +1 @@
1
- export { default as Input } from "./input.svelte";
1
+ export { default as Input, INPUT_COLORS, INPUT_RADII, INPUT_SIZES, INPUT_VARIANTS, } from "./input.svelte";
@@ -1,13 +1,44 @@
1
1
  <script lang="ts" module>
2
+ import {
3
+ COLORS,
4
+ noop,
5
+ RADII,
6
+ SIZES,
7
+ type ClassName,
8
+ type Color,
9
+ type ColorProp,
10
+ type ElementRef,
11
+ type Radius,
12
+ type RadiusProp,
13
+ type Size,
14
+ type SizeProp,
15
+ } from "..";
2
16
  import type { HTMLInputAttributes } from "svelte/elements";
3
17
  import { twMerge } from "tailwind-merge";
4
- import { baseClasses, type Variants } from "../base";
5
- import { noop, type ClassName, type ElementRef } from "../utils";
18
+
19
+ export const INPUT_VARIANTS = ["outlined", "filled", "inherit"] as const;
20
+ export type InputVariant = (typeof INPUT_VARIANTS)[number];
21
+ export type InputVariantProp = { variant?: InputVariant };
22
+
23
+ export const INPUT_COLORS = COLORS;
24
+ export type InputColor = Color;
25
+ export type InputColorProp = ColorProp;
26
+
27
+ export const INPUT_SIZES = SIZES;
28
+ export type InputSize = Size;
29
+ export type InputSizeProp = SizeProp;
30
+
31
+ export const INPUT_RADII = RADII;
32
+ export type InputRadius = Radius;
33
+ export type InputRadiusProp = RadiusProp;
6
34
 
7
35
  export type InputProps = ElementRef &
8
36
  ClassName &
9
- Variants &
10
- HTMLInputAttributes;
37
+ InputVariantProp &
38
+ InputSizeProp &
39
+ InputRadiusProp &
40
+ InputColorProp &
41
+ Omit<HTMLInputAttributes, "size">;
11
42
  </script>
12
43
 
13
44
  <script lang="ts">
@@ -17,24 +48,42 @@
17
48
  ref = noop,
18
49
  class: className,
19
50
  variant = "outlined",
20
- color = "secondary",
21
- shape = "rounded",
51
+ color = "primary",
52
+ size = "sm",
53
+ radius = "md",
22
54
  ...restProps
23
55
  }: InputProps = $props();
24
56
  </script>
25
57
 
26
58
  <input
59
+ bind:value
27
60
  bind:this={el}
28
61
  use:ref
29
- bind:value
30
62
  class={twMerge(
31
- "bg-m3-surface-container",
32
- baseClasses({ variant, color, shape, hover: true, focus: true }),
63
+ variant === "outlined" &&
64
+ "bg-m3-surface-container-lowest outline-1 outline-m3-outline-variant hover:outline-m3-outline/80 disabled:hover:outline-m3-outline-variant",
65
+ variant === "filled" &&
66
+ "bg-m3-surface-container hover:bg-m3-surface-container-high focus:outline-1",
67
+
68
+ color === "primary" && "focus-visible:outline-m3-primary",
69
+ color === "secondary" && "focus-visible:outline-m3-secondary",
70
+ color === "tertiary" && "focus-visible:outline-m3-tertiary",
71
+ color === "error" && "focus-visible:outline-m3-error",
72
+
73
+ size === "xs" && "px-2.5 py-1.5 text-xs",
74
+ size === "sm" && "px-3 py-1.5 text-sm",
75
+ size === "md" && "px-3.5 py-2 text-base",
76
+ size === "lg" && "px-4 py-2.5 text-lg",
77
+ size === "xl" && "px-5 py-4 text-xl",
78
+
79
+ radius == "xs" && "rounded-xs",
80
+ radius == "sm" && "rounded-sm",
81
+ radius == "md" && "rounded-lg",
82
+ radius == "lg" && "rounded-2xl",
83
+ radius == "xl" && "rounded-4xl",
33
84
 
34
- (variant === "outlined" || variant === "plain") &&
35
- "hover:bg-m3-surface-container-low focus-visible:bg-m3-surface-container-low",
85
+ "disabled:cursor-not-allowed disabled:bg-m3-on-surface/12 disabled:text-m3-on-surface/38",
36
86
 
37
- "h-9 px-3",
38
87
  className,
39
88
  )}
40
89
  {...restProps}
@@ -1,7 +1,20 @@
1
+ import { type ClassName, type Color, type ColorProp, type ElementRef, type Radius, type RadiusProp, type Size, type SizeProp } from "..";
1
2
  import type { HTMLInputAttributes } from "svelte/elements";
2
- import { type Variants } from "../base";
3
- import { type ClassName, type ElementRef } from "../utils";
4
- export type InputProps = ElementRef & ClassName & Variants & HTMLInputAttributes;
3
+ export declare const INPUT_VARIANTS: readonly ["outlined", "filled", "inherit"];
4
+ export type InputVariant = (typeof INPUT_VARIANTS)[number];
5
+ export type InputVariantProp = {
6
+ variant?: InputVariant;
7
+ };
8
+ export declare const INPUT_COLORS: readonly ["primary", "secondary", "tertiary", "error", "inherit"];
9
+ export type InputColor = Color;
10
+ export type InputColorProp = ColorProp;
11
+ export declare const INPUT_SIZES: readonly ["xs", "sm", "md", "lg", "xl", "inherit"];
12
+ export type InputSize = Size;
13
+ export type InputSizeProp = SizeProp;
14
+ export declare const INPUT_RADII: readonly ["xs", "sm", "md", "lg", "xl", "inherit"];
15
+ export type InputRadius = Radius;
16
+ export type InputRadiusProp = RadiusProp;
17
+ export type InputProps = ElementRef & ClassName & InputVariantProp & InputSizeProp & InputRadiusProp & InputColorProp & Omit<HTMLInputAttributes, "size">;
5
18
  declare const Input: import("svelte").Component<InputProps, {}, "el" | "value">;
6
19
  type Input = ReturnType<typeof Input>;
7
20
  export default Input;
@@ -0,0 +1,18 @@
1
+ type StoreOpts = {
2
+ storage?: Storage;
3
+ };
4
+ type LoadOpts<T> = {
5
+ decode?: (data: string) => T;
6
+ };
7
+ type SaveOpts<T> = {
8
+ encode?: (value: T) => string;
9
+ };
10
+ export declare function load<T>(key: string, init: T, opts: LoadOpts<T> & StoreOpts): T;
11
+ export declare function save<T>(key: string, value: T, opts: SaveOpts<T> & StoreOpts): void;
12
+ export type Storable<T> = {
13
+ value: T;
14
+ };
15
+ export declare function useLocalStorage<T>(key: string, init: T, opts?: LoadOpts<T> & SaveOpts<T> & StoreOpts): Storable<T>;
16
+ export declare const loads: (key: string, init: string | null, opts?: StoreOpts) => string | null;
17
+ export declare const saves: (key: string, value: string | null, opts?: StoreOpts) => void;
18
+ export {};
@@ -0,0 +1,28 @@
1
+ export function load(key, init, opts) {
2
+ const { storage = localStorage, decode = (data) => (data ? JSON.parse(data) : init), } = opts;
3
+ const data = storage.getItem(key);
4
+ return data ? decode(data) : init;
5
+ }
6
+ export function save(key, value, opts) {
7
+ const { storage = localStorage, encode = (value) => JSON.stringify(value) } = opts;
8
+ if (value) {
9
+ storage.setItem(key, encode(value));
10
+ }
11
+ else {
12
+ storage.removeItem(key);
13
+ }
14
+ }
15
+ export function useLocalStorage(key, init, opts = {}) {
16
+ let value = $state(load(key, init, opts));
17
+ return {
18
+ get value() {
19
+ return value;
20
+ },
21
+ set value(v) {
22
+ value = v;
23
+ save(key, value, opts);
24
+ },
25
+ };
26
+ }
27
+ export const loads = (key, init, opts = {}) => load(key, init, { decode: (data) => data, ...opts });
28
+ export const saves = (key, value, opts = {}) => save(key, value, { encode: (value) => String(value), ...opts });
@@ -1 +1 @@
1
- export { default as Textarea, type TextareaProps } from "./textarea.svelte";
1
+ export { default as Textarea, TEXTAREA_COLORS, TEXTAREA_RADII, TEXTAREA_SIZES, TEXTAREA_VARIANTS, type TextareaColor, type TextareaColorProp, type TextareaProps, type TextareaRadius, type TextareaRadiusProp, type TextareaSize, type TextareaSizeProp, type TextareaVariant, type TextareaVariantProp, } from "./textarea.svelte";
@@ -1 +1 @@
1
- export { default as Textarea } from "./textarea.svelte";
1
+ export { default as Textarea, TEXTAREA_COLORS, TEXTAREA_RADII, TEXTAREA_SIZES, TEXTAREA_VARIANTS, } from "./textarea.svelte";
@@ -1,38 +1,81 @@
1
1
  <script module lang="ts">
2
- import { baseClasses, type Variants } from "../base";
3
- import { noop, type ClassName, type ElementRef } from "../utils";
2
+ import {
3
+ COLORS,
4
+ RADII,
5
+ SIZES,
6
+ type Color,
7
+ type ColorProp,
8
+ type Radius,
9
+ type RadiusProp,
10
+ type Size,
11
+ type SizeProp,
12
+ } from "..";
13
+ import { type ClassName } from "../utils";
4
14
  import type { HTMLTextareaAttributes } from "svelte/elements";
5
15
  import { twMerge } from "tailwind-merge";
6
16
 
7
- export type TextareaProps = ElementRef &
8
- ClassName &
9
- Variants &
10
- HTMLTextareaAttributes;
17
+ export const TEXTAREA_VARIANTS = ["outlined", "filled", "inherit"] as const;
18
+ export type TextareaVariant = (typeof TEXTAREA_VARIANTS)[number];
19
+ export type TextareaVariantProp = { variant?: TextareaVariant };
20
+
21
+ export const TEXTAREA_COLORS = COLORS;
22
+ export type TextareaColor = Color;
23
+ export type TextareaColorProp = ColorProp;
24
+
25
+ export const TEXTAREA_SIZES = SIZES;
26
+ export type TextareaSize = Size;
27
+ export type TextareaSizeProp = SizeProp;
28
+
29
+ export const TEXTAREA_RADII = RADII;
30
+ export type TextareaRadius = Radius;
31
+ export type TextareaRadiusProp = RadiusProp;
32
+
33
+ export type TextareaProps = ClassName &
34
+ TextareaVariantProp &
35
+ TextareaSizeProp &
36
+ TextareaRadiusProp &
37
+ TextareaColorProp &
38
+ Omit<HTMLTextareaAttributes, "size">;
11
39
  </script>
12
40
 
13
41
  <script lang="ts">
14
42
  let {
15
43
  value = $bindable(),
16
- el = $bindable(),
17
- ref = noop,
18
44
  class: className,
19
45
  variant = "outlined",
20
- color = "secondary",
21
- shape = "rounded",
46
+ color = "primary",
47
+ size = "sm",
48
+ radius = "md",
22
49
  ...restProps
23
50
  }: TextareaProps = $props();
24
51
  </script>
25
52
 
26
53
  <textarea
27
- bind:this={el}
28
- use:ref
29
54
  bind:value
30
55
  class={twMerge(
31
- "bg-m3-surface-container",
32
- baseClasses({ variant, color, shape, hover: true, focus: true }),
56
+ variant === "outlined" &&
57
+ "bg-m3-surface-container-lowest outline-1 outline-m3-outline-variant hover:outline-m3-outline/80 disabled:hover:outline-m3-outline-variant",
58
+ variant === "filled" &&
59
+ "bg-m3-surface-container hover:bg-m3-surface-container-high focus:outline-1",
60
+
61
+ color === "primary" && "focus-visible:outline-m3-primary",
62
+ color === "secondary" && "focus-visible:outline-m3-secondary",
63
+ color === "tertiary" && "focus-visible:outline-m3-tertiary",
64
+ color === "error" && "focus-visible:outline-m3-error",
65
+
66
+ size === "xs" && "px-2.5 py-1.5 text-xs",
67
+ size === "sm" && "px-3 py-1.5 text-sm",
68
+ size === "md" && "px-3.5 py-2 text-base",
69
+ size === "lg" && "px-4 py-2.5 text-lg",
70
+ size === "xl" && "px-5 py-4 text-xl",
71
+
72
+ radius == "xs" && "rounded-xs",
73
+ radius == "sm" && "rounded-sm",
74
+ radius == "md" && "rounded-lg",
75
+ radius == "lg" && "rounded-2xl",
76
+ radius == "xl" && "rounded-4xl",
33
77
 
34
- (variant === "outlined" || variant === "plain") &&
35
- "hover:bg-m3-surface-container-low focus-visible:bg-m3-surface-container-low",
78
+ "disabled:cursor-not-allowed disabled:bg-m3-on-surface/12 disabled:text-m3-on-surface/38",
36
79
 
37
80
  "px-3 py-2",
38
81
  className,
@@ -1,7 +1,21 @@
1
- import { type Variants } from "../base";
2
- import { type ClassName, type ElementRef } from "../utils";
1
+ import { type Color, type ColorProp, type Radius, type RadiusProp, type Size, type SizeProp } from "..";
2
+ import { type ClassName } from "../utils";
3
3
  import type { HTMLTextareaAttributes } from "svelte/elements";
4
- export type TextareaProps = ElementRef & ClassName & Variants & HTMLTextareaAttributes;
5
- declare const Textarea: import("svelte").Component<TextareaProps, {}, "el" | "value">;
4
+ export declare const TEXTAREA_VARIANTS: readonly ["outlined", "filled", "inherit"];
5
+ export type TextareaVariant = (typeof TEXTAREA_VARIANTS)[number];
6
+ export type TextareaVariantProp = {
7
+ variant?: TextareaVariant;
8
+ };
9
+ export declare const TEXTAREA_COLORS: readonly ["primary", "secondary", "tertiary", "error", "inherit"];
10
+ export type TextareaColor = Color;
11
+ export type TextareaColorProp = ColorProp;
12
+ export declare const TEXTAREA_SIZES: readonly ["xs", "sm", "md", "lg", "xl", "inherit"];
13
+ export type TextareaSize = Size;
14
+ export type TextareaSizeProp = SizeProp;
15
+ export declare const TEXTAREA_RADII: readonly ["xs", "sm", "md", "lg", "xl", "inherit"];
16
+ export type TextareaRadius = Radius;
17
+ export type TextareaRadiusProp = RadiusProp;
18
+ export type TextareaProps = ClassName & TextareaVariantProp & TextareaSizeProp & TextareaRadiusProp & TextareaColorProp & Omit<HTMLTextareaAttributes, "size">;
19
+ declare const Textarea: import("svelte").Component<TextareaProps, {}, "value">;
6
20
  type Textarea = ReturnType<typeof Textarea>;
7
21
  export default Textarea;
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "kosui",
3
- "version": "0.0.20",
3
+ "version": "0.0.24",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/kosolabs/kosui.git"
9
+ },
6
10
  "engines": {
7
11
  "node": ">= 20"
8
12
  },
@@ -39,6 +43,7 @@
39
43
  "@sveltejs/kit": "^2.22.0",
40
44
  "@sveltejs/package": "^2.0.0",
41
45
  "@sveltejs/vite-plugin-svelte": "^6.0.0",
46
+ "@tailwindcss/forms": "^0.5.10",
42
47
  "@tailwindcss/postcss": "^4.1.11",
43
48
  "@tailwindcss/vite": "^4.0.0",
44
49
  "@types/node": "^24.1.0",