svseeds 0.4.6 → 0.4.8

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 (51) hide show
  1. package/_svseeds/Accordion.svelte +17 -17
  2. package/_svseeds/Accordion.svelte.d.ts +10 -10
  3. package/_svseeds/DarkToggle.svelte +15 -15
  4. package/_svseeds/DarkToggle.svelte.d.ts +6 -6
  5. package/_svseeds/TagsInputField.svelte +48 -53
  6. package/_svseeds/TagsInputField.svelte.d.ts +22 -22
  7. package/_svseeds/ToggleGroupField.svelte +39 -39
  8. package/_svseeds/ToggleGroupField.svelte.d.ts +18 -18
  9. package/_svseeds/_Button.svelte +23 -22
  10. package/_svseeds/_Button.svelte.d.ts +13 -13
  11. package/_svseeds/_CheckField.svelte +33 -33
  12. package/_svseeds/_CheckField.svelte.d.ts +14 -14
  13. package/_svseeds/_ColorPicker.svelte +16 -16
  14. package/_svseeds/_ColorPicker.svelte.d.ts +10 -10
  15. package/_svseeds/_ComboBox.svelte +15 -15
  16. package/_svseeds/_ComboBox.svelte.d.ts +8 -8
  17. package/_svseeds/_ContextMenu.svelte +18 -18
  18. package/_svseeds/_ContextMenu.svelte.d.ts +12 -12
  19. package/_svseeds/_Disclosure.svelte +31 -29
  20. package/_svseeds/_Disclosure.svelte.d.ts +14 -14
  21. package/_svseeds/_HotkeyCapture.svelte +19 -19
  22. package/_svseeds/_HotkeyCapture.svelte.d.ts +10 -10
  23. package/_svseeds/_Modal.svelte +19 -19
  24. package/_svseeds/_Modal.svelte.d.ts +12 -12
  25. package/_svseeds/_ProgressTracker.svelte +27 -26
  26. package/_svseeds/_ProgressTracker.svelte.d.ts +15 -15
  27. package/_svseeds/_SelectField.svelte +36 -36
  28. package/_svseeds/_SelectField.svelte.d.ts +14 -14
  29. package/_svseeds/_Slider.svelte +26 -25
  30. package/_svseeds/_Slider.svelte.d.ts +15 -15
  31. package/_svseeds/_Sortable.svelte +35 -35
  32. package/_svseeds/_Sortable.svelte.d.ts +18 -18
  33. package/_svseeds/_Tabs.svelte +23 -23
  34. package/_svseeds/_Tabs.svelte.d.ts +10 -10
  35. package/_svseeds/{TagsInput.svelte → _TagsInput.svelte} +40 -47
  36. package/_svseeds/{TagsInput.svelte.d.ts → _TagsInput.svelte.d.ts} +17 -21
  37. package/_svseeds/_TextField.svelte +39 -39
  38. package/_svseeds/_TextField.svelte.d.ts +16 -16
  39. package/_svseeds/_Toggle.svelte +30 -34
  40. package/_svseeds/_Toggle.svelte.d.ts +16 -18
  41. package/_svseeds/_ToggleGroup.svelte +16 -16
  42. package/_svseeds/_ToggleGroup.svelte.d.ts +10 -10
  43. package/_svseeds/_Tooltip.svelte +21 -21
  44. package/_svseeds/_Tooltip.svelte.d.ts +13 -13
  45. package/_svseeds/core.d.ts +34 -17
  46. package/_svseeds/core.js +1 -1
  47. package/index.d.ts +3 -4
  48. package/index.js +2 -3
  49. package/package.json +1 -1
  50. package/_svseeds/_Badge.svelte +0 -73
  51. package/_svseeds/_Badge.svelte.d.ts +0 -33
@@ -1,15 +1,15 @@
1
1
  export interface TooltipProps {
2
- main?: Snippet<[string, string, boolean]>;
2
+ children?: Snippet<[string, string, boolean]>;
3
3
  name?: string;
4
4
  position?: Position;
5
5
  align?: Align;
6
6
  offset?: Vector;
7
- status?: string;
8
- style?: SVSStyle;
9
7
  element?: HTMLDivElement;
8
+ styling?: SVSClass;
9
+ variant?: string;
10
10
  }
11
11
  export type TooltipReqdProps = never;
12
- export type TooltipBindProps = "status" | "element";
12
+ export type TooltipBindProps = "variant" | "element";
13
13
  export declare function tooltip(node: HTMLElement, params: {
14
14
  text: string;
15
15
  delay?: number;
@@ -25,25 +25,25 @@ export type Position = "top" | "left" | "bottom" | "right";
25
25
  export type Align = "start" | "center" | "end";
26
26
  import { type Snippet } from "svelte";
27
27
  import { type Action, type ActionReturn } from "svelte/action";
28
- import { type SVSStyle } from "./core";
28
+ import { type SVSClass } from "./core";
29
29
  /**
30
- * default value: `<value>`
30
+ * default value: `(value)`
31
31
  * ```ts
32
32
  * interface TooltipProps {
33
- * main?: Snippet<[string, string, boolean]>; // Snippet<[status,text,isFlipped]>
33
+ * children?: Snippet<[string, string, boolean]>; // Snippet<[text,variant,isFlipped]>
34
34
  * name?: string;
35
- * position?: Position; // "top"
36
- * align?: Align; // "center"
37
- * offset?: Vector; // <{ x: 0, y: 0 }>
38
- * status?: string; // bindable <STATE.NEUTRAL>
39
- * style?: SVSStyle;
35
+ * position?: Position; // ("top")
36
+ * align?: Align; // ("center")
37
+ * offset?: Vector; // ({ x: 0, y: 0 })
40
38
  * element?: HTMLDivElement; // bindable
39
+ * styling?: SVSClass;
40
+ * variant?: string; // bindable (VARIANT.NEUTRAL)
41
41
  * }
42
42
  * type Vector = { x: number, y: number };
43
43
  * type Position = "top" | "left" | "bottom" | "right";
44
44
  * type Align = "start" | "center" | "end";
45
45
  * ```
46
46
  */
47
- declare const Tooltip: import("svelte").Component<TooltipProps, {}, "status" | "element">;
47
+ declare const Tooltip: import("svelte").Component<TooltipProps, {}, "variant" | "element">;
48
48
  type Tooltip = ReturnType<typeof Tooltip>;
49
49
  export default Tooltip;
@@ -1,13 +1,13 @@
1
- export { type SVSStyle, BASE, STATE, PARTS, elemId, fnClass, isNeutral, omit, debounce, throttle, UniqueId, };
1
+ export { type SVSClass, BASE, VARIANT, PARTS, elemId, fnClass, isNeutral, isUnsignedInteger, omit, debounce, throttle, UniqueId, };
2
2
  type ClassDictionary = Record<string, unknown>;
3
3
  type ClassArray = (ClassArray | ClassDictionary | string | number | bigint | null | boolean | undefined)[];
4
4
  type ClassPartialValue = string | ClassArray;
5
5
  type ClassValue = ClassPartialValue | ClassDictionary;
6
6
  type ClassRule = Record<string, ClassValue> | ClassPartialValue;
7
- type SVSStyle = Record<string, ClassRule> | string;
8
- type ClassFn = (part: string, status: string) => ClassValue | undefined;
7
+ type SVSClass = Record<string, ClassRule> | string;
8
+ type ClassFn = (part: string, variant: string) => ClassValue | undefined;
9
9
  declare const BASE = "base";
10
- declare const STATE: Readonly<{
10
+ declare const VARIANT: Readonly<{
11
11
  NEUTRAL: "neutral";
12
12
  ACTIVE: "active";
13
13
  INACTIVE: "inactive";
@@ -25,16 +25,16 @@ declare const PARTS: Readonly<{
25
25
  EXTRA: "extra";
26
26
  }>;
27
27
  /**
28
- * Creates a function that dynamically generates CSS classes based on component parts and status.
28
+ * Creates a function that dynamically generates CSS classes based on component parts and variant.
29
29
  *
30
30
  * Compatible with ClassValue type available in Svelte 5.16+ class attributes,
31
31
  * this function generates a ClassFn that returns appropriate CSS classes
32
- * based on the combination of component parts and their states.
32
+ * based on the combination of component parts and their variants.
33
33
  *
34
34
  * @param preset - Preset style definition. Can be a string or style rule object
35
35
  * @param style - Optional style definition. Takes precedence over preset when provided
36
36
  *
37
- * @returns Function that takes part and status parameters and returns ClassValue
37
+ * @returns Function that takes part and variant parameters and returns ClassValue
38
38
  *
39
39
  * @example
40
40
  * // String preset case
@@ -70,7 +70,7 @@ declare const PARTS: Readonly<{
70
70
  * const classFn = fnClass(preset, customStyle);
71
71
  * classFn("button", "active"); // ["btn", "btn-active"]
72
72
  */
73
- declare function fnClass(preset: SVSStyle, style?: SVSStyle): ClassFn;
73
+ declare function fnClass(preset: SVSClass, style?: SVSClass): ClassFn;
74
74
  /**
75
75
  * Generates unique random alphabetic ID strings with collision detection.
76
76
  * Uses a carefully selected character set of 50 letters (A-Y, a-y) to ensure
@@ -130,7 +130,7 @@ declare class UniqueId {
130
130
  *
131
131
  * @example
132
132
  * ```typescript
133
- * const generator = new UniqueId();
133
+ * const generator = new UniqueId(4);
134
134
  * const id1 = generator.get(true); // "AbCd"
135
135
  * const id2 = generator.get(false); // undefined
136
136
  * const id3 = generator.get("hello"); // "XyAb"
@@ -141,20 +141,37 @@ declare class UniqueId {
141
141
  }
142
142
  declare const elemId: UniqueId;
143
143
  /**
144
- * Determines whether a status is in a neutral state (neither ACTIVE nor INACTIVE).
144
+ * Determines whether a variant is in a neutral variant (neither ACTIVE nor INACTIVE).
145
+ *
146
+ * @param variant - The variant string to check
147
+ * @returns false if the variant is ACTIVE or INACTIVE, true otherwise
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * isNeutral(VARIANT.NEUTRAL); // true
152
+ * isNeutral("custom variant"); // true
153
+ * isNeutral(VARIANT.ACTIVE); // false
154
+ * isNeutral(VARIANT.INACTIVE); // false
155
+ * ```
156
+ */
157
+ declare function isNeutral(variant: string): boolean;
158
+ /**
159
+ * Checks if a given number is an unsigned integer (non-negative integer).
145
160
  *
146
- * @param status - The status string to check
147
- * @returns false if the status is ACTIVE or INACTIVE, true otherwise
161
+ * @param num - The number to check
162
+ * @returns True if the number is an integer and greater than or equal to zero, false otherwise
148
163
  *
149
164
  * @example
150
165
  * ```typescript
151
- * isNeutral(STATE.NEUTRAL); // true
152
- * isNeutral("custom state"); // true
153
- * isNeutral(STATE.ACTIVE); // false
154
- * isNeutral(STATE.INACTIVE); // false
166
+ * isUnsignedInteger(5); // true
167
+ * isUnsignedInteger(0); // true
168
+ * isUnsignedInteger(-1); // false
169
+ * isUnsignedInteger(3.14); // false
170
+ * isUnsignedInteger(NaN); // false
171
+ * isUnsignedInteger(Infinity); // false
155
172
  * ```
156
173
  */
157
- declare function isNeutral(status: string): boolean;
174
+ declare function isUnsignedInteger(num: number): boolean;
158
175
  /**
159
176
  * Creates a new object with specified keys omitted from the original object.
160
177
  * Returns an empty object if the input object is undefined or null.
package/_svseeds/core.js CHANGED
@@ -1 +1 @@
1
- export{t as BASE,e as STATE,r as PARTS,s as elemId,n as fnClass,a as isNeutral,u as omit,c as debounce,l as throttle,o as UniqueId};const t="base",e=Object.freeze({NEUTRAL:"neutral",ACTIVE:"active",INACTIVE:"inactive"}),r=Object.freeze({WHOLE:"whole",MIDDLE:"middle",MAIN:"main",TOP:"top",LEFT:"left",RIGHT:"right",BOTTOM:"bottom",LABEL:"label",AUX:"aux",EXTRA:"extra"});function n(r,n){const o=i(n)??i(r);return null==o?(t,e)=>{}:"string"==typeof o?(t,e)=>`${o} ${t} ${e}`:(r,n)=>function(r,n,i){const o=r[n]?.[t]??"",s=r[n]?.[i]??r[n]?.[e.NEUTRAL]??"";if(!o&&!s)return;return o&&s?[o,s]:o||s}(o,r,n)}function i(t){if(null==t)return;if("string"==typeof t)return t.trim()?t:void 0;const e=Object.entries(t);return e.length?Object.fromEntries(e.map((([t,e])=>null===e||"object"!=typeof e||Array.isArray(e)?[t,{base:e}]:[t,e]))):void 0}class o{static#t=[...Array.from(Array(25).keys(),(t=>t+65)),...Array.from(Array(25).keys(),(t=>t+97))];#e=new Set;#r=3;#n=1e5;get id(){return this.get(!0)}constructor(t=3,e=1e5){t>2&&(this.#r=t),(e=Math.trunc(e))>0&&e<Math.min(Math.pow(50,this.#r),Number.MAX_SAFE_INTEGER)&&(this.#n=e)}get(t){if(t)return this.#e.size>this.#n&&this.#e.clear(),this.#i()}#o(){return o.#t[Math.trunc(Math.random()*o.#t.length)]}#s(){return String.fromCharCode(...Array(this.#r).fill(null).map((()=>this.#o())))}#i(){let t=this.#s();for(;this.#e.has(t);)t=this.#s();return this.#e.add(t),t}}const s=new o;function a(t){return t!==e.ACTIVE&&t!==e.INACTIVE}function u(t,...e){if(!t)return{};const r={...t};return e.forEach((t=>delete r[t])),r}function c(t,e){let r;return(...n)=>{r&&clearTimeout(r),r=setTimeout((()=>{e.call(null,...n)}),t)}}function l(t,e){let r,n=0;const i=()=>Date.now()-n,o=t=>{e.call(null,...t),n=Date.now()};return(...e)=>{if(!n)return o(e);clearTimeout(r),r=setTimeout((()=>{i()>=t&&o(e)}),t-i())}}
1
+ export{t as BASE,e as VARIANT,r as PARTS,s as elemId,n as fnClass,u as isNeutral,a as isUnsignedInteger,c as omit,l as debounce,h as throttle,o as UniqueId};const t="base",e=Object.freeze({NEUTRAL:"neutral",ACTIVE:"active",INACTIVE:"inactive"}),r=Object.freeze({WHOLE:"whole",MIDDLE:"middle",MAIN:"main",TOP:"top",LEFT:"left",RIGHT:"right",BOTTOM:"bottom",LABEL:"label",AUX:"aux",EXTRA:"extra"});function n(r,n){const o=i(n)??i(r);return null==o?(t,e)=>{}:"string"==typeof o?(t,e)=>`${o} ${t} ${e}`:(r,n)=>function(r,n,i){const o=r[n]?.[t]??"",s=r[n]?.[i]??r[n]?.[e.NEUTRAL]??"";if(!o&&!s)return;return o&&s?[o,s]:o||s}(o,r,n)}function i(t){if(null==t)return;if("string"==typeof t)return t.trim()?t:void 0;const e=Object.entries(t);return e.length?Object.fromEntries(e.map((([t,e])=>null===e||"object"!=typeof e||Array.isArray(e)?[t,{base:e}]:[t,e]))):void 0}class o{static#t=[...Array.from(Array(25).keys(),(t=>t+65)),...Array.from(Array(25).keys(),(t=>t+97))];#e=new Set;#r=3;#n=1e5;get id(){return this.get(!0)}constructor(t=3,e=1e5){t>2&&(this.#r=t),(e=Math.trunc(e))>0&&e<Math.min(Math.pow(50,this.#r),Number.MAX_SAFE_INTEGER)&&(this.#n=e)}get(t){if(t)return this.#e.size>this.#n&&this.#e.clear(),this.#i()}#o(){return o.#t[Math.trunc(Math.random()*o.#t.length)]}#s(){return String.fromCharCode(...Array(this.#r).fill(null).map((()=>this.#o())))}#i(){let t=this.#s();for(;this.#e.has(t);)t=this.#s();return this.#e.add(t),t}}const s=new o;function u(t){return t!==e.ACTIVE&&t!==e.INACTIVE}function a(t){return Number.isInteger(t)&&t>=0}function c(t,...e){if(!t)return{};const r={...t};return e.forEach((t=>delete r[t])),r}function l(t,e){let r;return(...n)=>{r&&clearTimeout(r),r=setTimeout((()=>{e.call(null,...n)}),t)}}function h(t,e){let r,n=0;const i=()=>Date.now()-n,o=t=>{e.call(null,...t),n=Date.now()};return(...e)=>{if(!n)return o(e);clearTimeout(r),r=setTimeout((()=>{i()>=t&&o(e)}),t-i())}}
package/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- export { type SVSStyle, BASE, STATE, PARTS, elemId, fnClass, isNeutral, omit, debounce, throttle, UniqueId } from "./_svseeds/core";
2
- export { default as Badge, type BadgeProps, type BadgeReqdProps, type BadgeBindProps } from "./_svseeds/_Badge.svelte";
1
+ export { type SVSClass, BASE, VARIANT, PARTS, elemId, fnClass, isNeutral, isUnsignedInteger, omit, debounce, throttle, UniqueId } from "./_svseeds/core";
3
2
  export { default as Button, type ButtonProps, type ButtonReqdProps, type ButtonBindProps } from "./_svseeds/_Button.svelte";
4
3
  export { default as CheckField, type CheckFieldProps, type CheckFieldReqdProps, type CheckFieldBindProps, type CheckFieldValidation } from "./_svseeds/_CheckField.svelte";
5
4
  export { default as ColorPicker, type ColorPickerProps, type ColorPickerReqdProps, type ColorPickerBindProps, getHex } from "./_svseeds/_ColorPicker.svelte";
@@ -13,12 +12,12 @@ export { default as SelectField, type SelectFieldProps, type SelectFieldReqdProp
13
12
  export { default as Slider, type SliderProps, type SliderReqdProps, type SliderBindProps, type Range } from "./_svseeds/_Slider.svelte";
14
13
  export { default as Sortable, type SortableProps, type SortableReqdProps, type SortableBindProps, SortableItems } from "./_svseeds/_Sortable.svelte";
15
14
  export { default as Tabs, type TabsProps, type TabsReqdProps, type TabsBindProps } from "./_svseeds/_Tabs.svelte";
15
+ export { default as TagsInput, type TagsInputProps, type TagsInputReqdProps, type TagsInputBindProps, type TagsInputEvents } from "./_svseeds/_TagsInput.svelte";
16
16
  export { default as TextField, type TextFieldProps, type TextFieldReqdProps, type TextFieldBindProps, type TextFieldValidation } from "./_svseeds/_TextField.svelte";
17
17
  export { default as Toggle, type ToggleProps, type ToggleReqdProps, type ToggleBindProps } from "./_svseeds/_Toggle.svelte";
18
18
  export { default as ToggleGroup, type ToggleGroupProps, type ToggleGroupReqdProps, type ToggleGroupBindProps } from "./_svseeds/_ToggleGroup.svelte";
19
19
  export { default as Tooltip, type TooltipProps, type TooltipReqdProps, type TooltipBindProps, type Vector, type Position, type Align, tooltip, tooltipAction } from "./_svseeds/_Tooltip.svelte";
20
20
  export { default as Accordion, type AccordionProps, type AccordionDeps, type AccordionReqdProps, type AccordionBindProps } from "./_svseeds/Accordion.svelte";
21
21
  export { default as DarkToggle, type DarkToggleProps, type DarkToggleDeps, type DarkToggleReqdProps, type DarkToggleBindProps, THEME, setThemeToRoot } from "./_svseeds/DarkToggle.svelte";
22
- export { default as TagsInput, type TagsInputProps, type TagsInputDeps, type TagsInputReqdProps, type TagsInputBindProps, type TagsInputEvents } from "./_svseeds/TagsInput.svelte";
23
- export { default as TagsInputField, type TagsInputFieldProps, type TagsInputFieldReqdProps, type TagsInputFieldBindProps, type TagsInputFieldConstraint, type TagsInputFieldValidation, type TagsInputFieldCountValidation } from "./_svseeds/TagsInputField.svelte";
22
+ export { default as TagsInputField, type TagsInputFieldProps, type TagsInputFieldDeps, type TagsInputFieldReqdProps, type TagsInputFieldBindProps, type TagsInputFieldConstraint, type TagsInputFieldValidation, type TagsInputFieldCountValidation } from "./_svseeds/TagsInputField.svelte";
24
23
  export { default as ToggleGroupField, type ToggleGroupFieldProps, type ToggleGroupFieldDeps, type ToggleGroupFieldReqdProps, type ToggleGroupFieldBindProps, type ToggleGroupFieldValidation } from "./_svseeds/ToggleGroupField.svelte";
package/index.js CHANGED
@@ -1,5 +1,4 @@
1
- export { BASE, STATE, PARTS, elemId, fnClass, isNeutral, omit, debounce, throttle, UniqueId } from "./_svseeds/core";
2
- export { default as Badge } from "./_svseeds/_Badge.svelte";
1
+ export { BASE, VARIANT, PARTS, elemId, fnClass, isNeutral, isUnsignedInteger, omit, debounce, throttle, UniqueId } from "./_svseeds/core";
3
2
  export { default as Button } from "./_svseeds/_Button.svelte";
4
3
  export { default as CheckField } from "./_svseeds/_CheckField.svelte";
5
4
  export { default as ColorPicker, getHex } from "./_svseeds/_ColorPicker.svelte";
@@ -13,12 +12,12 @@ export { default as SelectField } from "./_svseeds/_SelectField.svelte";
13
12
  export { default as Slider } from "./_svseeds/_Slider.svelte";
14
13
  export { default as Sortable, SortableItems } from "./_svseeds/_Sortable.svelte";
15
14
  export { default as Tabs } from "./_svseeds/_Tabs.svelte";
15
+ export { default as TagsInput } from "./_svseeds/_TagsInput.svelte";
16
16
  export { default as TextField } from "./_svseeds/_TextField.svelte";
17
17
  export { default as Toggle } from "./_svseeds/_Toggle.svelte";
18
18
  export { default as ToggleGroup } from "./_svseeds/_ToggleGroup.svelte";
19
19
  export { default as Tooltip, tooltip, tooltipAction } from "./_svseeds/_Tooltip.svelte";
20
20
  export { default as Accordion } from "./_svseeds/Accordion.svelte";
21
21
  export { default as DarkToggle, THEME, setThemeToRoot } from "./_svseeds/DarkToggle.svelte";
22
- export { default as TagsInput } from "./_svseeds/TagsInput.svelte";
23
22
  export { default as TagsInputField } from "./_svseeds/TagsInputField.svelte";
24
23
  export { default as ToggleGroupField } from "./_svseeds/ToggleGroupField.svelte";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svseeds",
3
- "version": "0.4.6",
3
+ "version": "0.4.8",
4
4
  "description": "Simple components for Svelte.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -1,73 +0,0 @@
1
- <!--
2
- @component
3
- default value: `<value>`
4
- ```ts
5
- interface BadgeProps {
6
- children: Snippet;
7
- left?: Snippet<[string]>; // Snippet<[status]>
8
- right?: Snippet<[string]>; // Snippet<[status]>
9
- type?: "plain" | "link" | "left" | "right"; // <"plain">
10
- href?: string;
11
- onclick?: MouseEventHandler<HTMLButtonElement> | null;
12
- status?: string; // bindable <STATE.NEUTRAL>
13
- style?: SVSStyle;
14
- }
15
- ```
16
- -->
17
- <script module lang="ts">
18
- export interface BadgeProps {
19
- children: Snippet;
20
- left?: Snippet<[string]>; // Snippet<[status]>
21
- right?: Snippet<[string]>; // Snippet<[status]>
22
- type?: "plain" | "link" | "left" | "right"; // <"plain">
23
- href?: string;
24
- onclick?: MouseEventHandler<HTMLButtonElement> | null;
25
- status?: string; // bindable <STATE.NEUTRAL>
26
- style?: SVSStyle;
27
- }
28
- export type BadgeReqdProps = "children";
29
- export type BadgeBindProps = "status";
30
-
31
- const preset = "svs-badge";
32
-
33
- import { type Snippet } from "svelte";
34
- import { type MouseEventHandler } from "svelte/elements";
35
- import { type SVSStyle, STATE, PARTS, fnClass } from "./core";
36
- </script>
37
-
38
- <script lang="ts">
39
- let { children, left, right, type = "plain", href = "", onclick, status = $bindable(""), style }: BadgeProps = $props();
40
-
41
- // *** Initialize *** //
42
- if (!status) status = STATE.NEUTRAL;
43
- const cls = fnClass(preset, style);
44
- </script>
45
-
46
- <!---------------------------------------->
47
-
48
- {#if type === "link"}
49
- <a class={cls(PARTS.WHOLE, status)} {href}>
50
- {@render whole()}
51
- </a>
52
- {:else}
53
- <span class={cls(PARTS.WHOLE, status)}>
54
- {@render whole()}
55
- </span>
56
- {/if}
57
-
58
- {#snippet side(area: string, btn: boolean, body?: Snippet<[string]>)}
59
- {#if body}
60
- {#if btn}
61
- <button class={cls(area, status)} {onclick}>{@render body(status)}</button>
62
- {:else}
63
- <span class={cls(area, status)}>{@render body(status)}</span>
64
- {/if}
65
- {/if}
66
- {/snippet}
67
- {#snippet whole()}
68
- {@render side(PARTS.LEFT, type === "left", left)}
69
- <span class={cls(PARTS.MAIN, status)}>
70
- {@render children()}
71
- </span>
72
- {@render side(PARTS.RIGHT, type === "right", right)}
73
- {/snippet}
@@ -1,33 +0,0 @@
1
- export interface BadgeProps {
2
- children: Snippet;
3
- left?: Snippet<[string]>;
4
- right?: Snippet<[string]>;
5
- type?: "plain" | "link" | "left" | "right";
6
- href?: string;
7
- onclick?: MouseEventHandler<HTMLButtonElement> | null;
8
- status?: string;
9
- style?: SVSStyle;
10
- }
11
- export type BadgeReqdProps = "children";
12
- export type BadgeBindProps = "status";
13
- import { type Snippet } from "svelte";
14
- import { type MouseEventHandler } from "svelte/elements";
15
- import { type SVSStyle } from "./core";
16
- /**
17
- * default value: `<value>`
18
- * ```ts
19
- * interface BadgeProps {
20
- * children: Snippet;
21
- * left?: Snippet<[string]>; // Snippet<[status]>
22
- * right?: Snippet<[string]>; // Snippet<[status]>
23
- * type?: "plain" | "link" | "left" | "right"; // <"plain">
24
- * href?: string;
25
- * onclick?: MouseEventHandler<HTMLButtonElement> | null;
26
- * status?: string; // bindable <STATE.NEUTRAL>
27
- * style?: SVSStyle;
28
- * }
29
- * ```
30
- */
31
- declare const Badge: import("svelte").Component<BadgeProps, {}, "status">;
32
- type Badge = ReturnType<typeof Badge>;
33
- export default Badge;