svelte-comp 1.3.3 → 1.3.6

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 (138) hide show
  1. package/LICENSE.md +21 -21
  2. package/README.md +101 -100
  3. package/dist/App.svelte +507 -507
  4. package/dist/Container.svelte +59 -59
  5. package/dist/app.css +234 -235
  6. package/dist/app.d.ts +10 -0
  7. package/dist/lib/Accordion.svelte +155 -155
  8. package/dist/lib/Badge.svelte +44 -44
  9. package/dist/lib/Button.svelte +185 -170
  10. package/dist/lib/Calendar.svelte +384 -384
  11. package/dist/lib/Card.svelte +103 -103
  12. package/dist/lib/Carousel.svelte +293 -293
  13. package/dist/lib/Carousel.svelte.d.ts +1 -1
  14. package/dist/lib/CheckBox.svelte +210 -210
  15. package/dist/lib/CodeView.svelte +308 -307
  16. package/dist/lib/ColorPicker.svelte +159 -159
  17. package/dist/lib/ContextMenu.svelte +328 -322
  18. package/dist/lib/DatePicker.svelte +246 -246
  19. package/dist/lib/Dialog.svelte +233 -233
  20. package/dist/lib/Field.svelte +299 -299
  21. package/dist/lib/FilePicker.svelte +295 -240
  22. package/dist/lib/FilePicker.svelte.d.ts +6 -1
  23. package/dist/lib/Form.svelte +438 -438
  24. package/dist/lib/Hamburger.svelte +217 -217
  25. package/dist/lib/InstallPWA.svelte +94 -94
  26. package/dist/lib/Menu.svelte +623 -623
  27. package/dist/lib/NoticeBase.svelte +140 -140
  28. package/dist/lib/PaginatedCard.svelte +73 -73
  29. package/dist/lib/Pagination.svelte +119 -119
  30. package/dist/lib/PrimaryColorSelect.svelte +111 -111
  31. package/dist/lib/ProgressBar.svelte +141 -141
  32. package/dist/lib/ProgressCircle.svelte +190 -190
  33. package/dist/lib/Radio.svelte +189 -189
  34. package/dist/lib/SearchInput.svelte +104 -104
  35. package/dist/lib/Select.svelte +524 -524
  36. package/dist/lib/Slider.svelte +253 -253
  37. package/dist/lib/Splitter.svelte +159 -150
  38. package/dist/lib/Switch.svelte +168 -167
  39. package/dist/lib/Table.svelte +299 -299
  40. package/dist/lib/Tabs.svelte +213 -213
  41. package/dist/lib/ThemeToggle.svelte +128 -127
  42. package/dist/lib/TimePicker.svelte +312 -312
  43. package/dist/lib/TimePickerNew.svelte +634 -0
  44. package/dist/lib/TimePickerNew.svelte.d.ts +49 -0
  45. package/dist/lib/Toast.svelte +123 -123
  46. package/dist/lib/Tooltip.svelte +110 -110
  47. package/dist/lib/Topbar.svelte +107 -107
  48. package/dist/lib/__tests__/Accordion.test.d.ts +1 -0
  49. package/dist/lib/__tests__/Accordion.test.js +171 -0
  50. package/dist/lib/__tests__/Badge.test.d.ts +1 -0
  51. package/dist/lib/__tests__/Badge.test.js +41 -0
  52. package/dist/lib/__tests__/Button.test.d.ts +1 -0
  53. package/dist/lib/__tests__/Button.test.js +269 -0
  54. package/dist/lib/__tests__/Calendar.test.d.ts +1 -0
  55. package/dist/lib/__tests__/Calendar.test.js +171 -0
  56. package/dist/lib/__tests__/Card.test.d.ts +1 -0
  57. package/dist/lib/__tests__/Card.test.js +148 -0
  58. package/dist/lib/__tests__/Carousel.test.d.ts +1 -0
  59. package/dist/lib/__tests__/Carousel.test.js +439 -0
  60. package/dist/lib/__tests__/CheckBox.test.d.ts +1 -0
  61. package/dist/lib/__tests__/CheckBox.test.js +152 -0
  62. package/dist/lib/__tests__/CodeView.test.d.ts +1 -0
  63. package/dist/lib/__tests__/CodeView.test.js +157 -0
  64. package/dist/lib/__tests__/ColorPicker.test.d.ts +1 -0
  65. package/dist/lib/__tests__/ColorPicker.test.js +93 -0
  66. package/dist/lib/__tests__/ContextMenu.test.d.ts +1 -0
  67. package/dist/lib/__tests__/ContextMenu.test.js +67 -0
  68. package/dist/lib/__tests__/DatePicker.test.d.ts +1 -0
  69. package/dist/lib/__tests__/DatePicker.test.js +108 -0
  70. package/dist/lib/__tests__/Dialog.test.d.ts +1 -0
  71. package/dist/lib/__tests__/Dialog.test.js +183 -0
  72. package/dist/lib/__tests__/Field.test.d.ts +1 -0
  73. package/dist/lib/__tests__/Field.test.js +190 -0
  74. package/dist/lib/__tests__/FilePicker.test.d.ts +1 -0
  75. package/dist/lib/__tests__/FilePicker.test.js +179 -0
  76. package/dist/lib/__tests__/Form.integration.test.d.ts +1 -0
  77. package/dist/lib/__tests__/Form.integration.test.js +158 -0
  78. package/dist/lib/__tests__/Form.test.d.ts +1 -0
  79. package/dist/lib/__tests__/Form.test.js +463 -0
  80. package/dist/lib/__tests__/Hamburger.test.d.ts +1 -0
  81. package/dist/lib/__tests__/Hamburger.test.js +161 -0
  82. package/dist/lib/__tests__/InstallPWA.test.d.ts +1 -0
  83. package/dist/lib/__tests__/InstallPWA.test.js +15 -0
  84. package/dist/lib/__tests__/Menu.test.d.ts +1 -0
  85. package/dist/lib/__tests__/Menu.test.js +285 -0
  86. package/dist/lib/__tests__/NoticeBase.test.d.ts +1 -0
  87. package/dist/lib/__tests__/NoticeBase.test.js +60 -0
  88. package/dist/lib/__tests__/PaginatedCard.test.d.ts +1 -0
  89. package/dist/lib/__tests__/PaginatedCard.test.js +89 -0
  90. package/dist/lib/__tests__/Pagination.test.d.ts +1 -0
  91. package/dist/lib/__tests__/Pagination.test.js +168 -0
  92. package/dist/lib/__tests__/PrimaryColorSelect.test.d.ts +1 -0
  93. package/dist/lib/__tests__/PrimaryColorSelect.test.js +92 -0
  94. package/dist/lib/__tests__/ProgressBar.test.d.ts +1 -0
  95. package/dist/lib/__tests__/ProgressBar.test.js +69 -0
  96. package/dist/lib/__tests__/ProgressCircle.test.d.ts +1 -0
  97. package/dist/lib/__tests__/ProgressCircle.test.js +71 -0
  98. package/dist/lib/__tests__/Radio.test.d.ts +1 -0
  99. package/dist/lib/__tests__/Radio.test.js +127 -0
  100. package/dist/lib/__tests__/SearchInput.test.d.ts +1 -0
  101. package/dist/lib/__tests__/SearchInput.test.js +80 -0
  102. package/dist/lib/__tests__/Select.test.d.ts +1 -0
  103. package/dist/lib/__tests__/Select.test.js +408 -0
  104. package/dist/lib/__tests__/Slider.test.d.ts +1 -0
  105. package/dist/lib/__tests__/Slider.test.js +213 -0
  106. package/dist/lib/__tests__/Splitter.test.d.ts +1 -0
  107. package/dist/lib/__tests__/Splitter.test.js +87 -0
  108. package/dist/lib/__tests__/Switch.test.d.ts +1 -0
  109. package/dist/lib/__tests__/Switch.test.js +97 -0
  110. package/dist/lib/__tests__/Table.test.d.ts +1 -0
  111. package/dist/lib/__tests__/Table.test.js +349 -0
  112. package/dist/lib/__tests__/Tabs.test.d.ts +1 -0
  113. package/dist/lib/__tests__/Tabs.test.js +262 -0
  114. package/dist/lib/__tests__/ThemeToggle.test.d.ts +1 -0
  115. package/dist/lib/__tests__/ThemeToggle.test.js +84 -0
  116. package/dist/lib/__tests__/TimePicker.test.d.ts +1 -0
  117. package/dist/lib/__tests__/TimePicker.test.js +146 -0
  118. package/dist/lib/__tests__/TimePickerNew.test.d.ts +1 -0
  119. package/dist/lib/__tests__/TimePickerNew.test.js +322 -0
  120. package/dist/lib/__tests__/Toast.test.d.ts +1 -0
  121. package/dist/lib/__tests__/Toast.test.js +135 -0
  122. package/dist/lib/__tests__/Tooltip.test.d.ts +1 -0
  123. package/dist/lib/__tests__/Tooltip.test.js +171 -0
  124. package/dist/lib/__tests__/Topbar.test.d.ts +1 -0
  125. package/dist/lib/__tests__/Topbar.test.js +25 -0
  126. package/dist/lib/__tests__/setupLangContext.d.ts +1 -0
  127. package/dist/lib/__tests__/setupLangContext.js +65 -0
  128. package/dist/lib/__tests__/storage.test.d.ts +1 -0
  129. package/dist/lib/__tests__/storage.test.js +124 -0
  130. package/dist/lib/__tests__/utils.test.d.ts +1 -0
  131. package/dist/lib/__tests__/utils.test.js +11 -0
  132. package/dist/lib/index.d.ts +1 -0
  133. package/dist/lib/index.js +1 -0
  134. package/dist/lib/lang.d.ts +4 -0
  135. package/dist/lib/lang.js +4 -0
  136. package/dist/styles.css +234 -232
  137. package/dist/utils/index.js +15 -4
  138. package/package.json +52 -52
@@ -1,170 +1,185 @@
1
- <!-- src/lib/Button.svelte -->
2
- <script lang="ts">
3
- /**
4
- * @component Button
5
- * @description Versatile button supporting multiple variants, sizes, loading state, and link behavior.
6
- *
7
- * @prop disabled {boolean} - Disables interaction
8
- * @default false
9
- *
10
- * @prop children {Snippet} - Content rendered inside the button
11
- *
12
- * @prop onClick {(e: MouseEvent) => void} - Click handler
13
- *
14
- * @prop sz {SizeKey} - Button size variant
15
- * @options xs|sm|md|lg|xl
16
- * @default md
17
- *
18
- * @prop variant {ButtonVariant} - Visual style preset
19
- * @options primary|secondary|pill|danger|success|warning|ghost|link|info
20
- * @default primary
21
- *
22
- * @prop type {"button" | "submit" | "reset"} - Button type attribute
23
- * @default "button"
24
- *
25
- * @prop loaded {boolean} - Shows loading spinner and blocks clicks
26
- * @default false
27
- *
28
- * @prop link {string} - Navigates to a URL when clicked
29
- *
30
- * @prop class {string} - Additional classes for the button
31
- * @default ""
32
- *
33
- * @note `disabled` and `loaded` both prevent click events.
34
- * @note Automatically shows a centered spinner when `loaded` is `true`.
35
- * @note Link navigation supports `target` and `rel` attributes.
36
- * @note Accessible with `aria-disabled` and `aria-busy` states.
37
- * @note The component uses CSS variables for colors, spacing, and transitions.
38
- */
39
- import type { HTMLButtonAttributes } from "svelte/elements";
40
- import type { Snippet } from "svelte";
41
- import { type SizeKey, type ButtonVariant, TEXT } from "./types";
42
- import { cx } from "../utils";
43
-
44
- type Props = HTMLButtonAttributes & {
45
- disabled?: boolean;
46
- children?: Snippet;
47
- onClick?: (e: MouseEvent) => void;
48
- sz?: SizeKey;
49
- variant?: ButtonVariant;
50
- type?: "button" | "submit" | "reset";
51
- loaded?: boolean;
52
- link?: string;
53
- class?: string;
54
- };
55
-
56
- let {
57
- disabled,
58
- children,
59
- onClick,
60
- sz = "md",
61
- variant = "primary",
62
- type = "button",
63
- loaded = false,
64
- link,
65
- class: externalClass = "",
66
- ...rest
67
- }: Props = $props();
68
-
69
- const base = `
70
- relative inline-flex items-center justify-center gap-2 rounded-[var(--radius-md)] border font-medium
71
- transition-all duration-[var(--transition-fast)] ease-[var(--timing-default)] whitespace-nowrap select-none
72
- focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--border-color-focus)]
73
- disabled:opacity-[var(--opacity-disabled)]
74
- disabled:cursor-not-allowed
75
- disabled:brightness-100
76
- disabled:active:scale-100
77
- disabled:hover:brightness-100
78
- `;
79
-
80
- const sizes: Record<SizeKey, string> = {
81
- xs: "px-2 py-0.5 h-6",
82
- sm: "px-3 py-1 h-7",
83
- md: "px-4 py-2 h-8",
84
- lg: "px-5 py-2.5 h-9",
85
- xl: "px-6 py-3 h-10",
86
- };
87
-
88
- const variants: Record<ButtonVariant, string> = {
89
- primary:
90
- "bg-[var(--color-bg-primary)] text-white border-[var(--border-color-primary)] hover:brightness-110 active:scale-95",
91
- secondary:
92
- "bg-[var(--color-bg-secondary)] [color:var(--color-text-default)] border-[var(--border-color-default)] hover:bg-[var(--color-bg-hover)] active:scale-95",
93
- pill: "bg-[var(--color-bg-primary)] text-white border-[var(--border-color-primary)] rounded-full hover:brightness-110 active:scale-95",
94
- danger:
95
- "bg-[var(--color-bg-danger)] text-white border-[var(--color-bg-danger)] hover:brightness-110 active:scale-95",
96
- success:
97
- "bg-[var(--color-bg-success)] text-white border-[var(--color-bg-success)] hover:brightness-110 active:scale-95",
98
- warning:
99
- "bg-[var(--color-bg-warning)] text-white border-[var(--color-bg-warning)] hover:brightness-110 active:scale-95",
100
- ghost:
101
- "bg-transparent [color:var(--color-text-default)] border-transparent hover:bg-[var(--color-bg-hover)] active:bg-[var(--color-bg-active)] active:scale-95",
102
- link: "bg-transparent underline border-transparent [color:var(--color-text-link)] hover:brightness-110 active:scale-95 transition-transform ",
103
- info: "bg-[var(--color-bg-secondary)] text-white border-[var(--border-color-default)] hover:bg-[var(--color-bg-hover)] active:scale-95",
104
- };
105
-
106
- const buttonClass = $derived(
107
- cx(base, sizes[sz], TEXT[sz], variants[variant], externalClass)
108
- );
109
-
110
- const state = $derived(loaded ? "loading" : disabled ? "disabled" : "idle");
111
-
112
- function handleClick(e: MouseEvent) {
113
- if (disabled || loaded) {
114
- e.preventDefault();
115
- return;
116
- }
117
-
118
- if (type === "submit" || type === "reset") {
119
- onClick?.(e);
120
- return;
121
- }
122
-
123
- onClick?.(e);
124
- if (!link || e.defaultPrevented) return;
125
-
126
- if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
127
- return;
128
- }
129
-
130
- navigateToLink();
131
- }
132
-
133
- function navigateToLink() {
134
- if (!link || typeof window === "undefined") return;
135
-
136
- const restAttrs = rest as Record<string, unknown>;
137
- const target =
138
- typeof restAttrs.target === "string" ? restAttrs.target : undefined;
139
-
140
- if (target === "_blank") {
141
- window.open(link, "_blank", "noopener,noreferrer");
142
- } else {
143
- window.location.assign(link);
144
- }
145
- }
146
- </script>
147
-
148
- <button
149
- {type}
150
- {disabled}
151
- data-state={state}
152
- aria-disabled={disabled || loaded || undefined}
153
- aria-busy={loaded || undefined}
154
- onclick={handleClick}
155
- class={buttonClass}
156
- {...rest}
157
- >
158
- <span class={cx({ "opacity-0 pointer-events-none": loaded })}>
159
- {@render children?.()}
160
- </span>
161
-
162
- {#if loaded}
163
- <span
164
- class={cx(
165
- "absolute inset-0 m-auto w-[1em] h-[1em] border-2 [border-color:var(--color-spinner,currentColor)] border-r-transparent rounded-full motion-safe:[animation:spin_0.6s_linear_infinite]"
166
- )}
167
- aria-hidden="true"
168
- ></span>
169
- {/if}
170
- </button>
1
+ <!-- src/lib/Button.svelte -->
2
+ <script lang="ts">
3
+ /**
4
+ * @component Button
5
+ * @description Versatile button supporting multiple variants, sizes, loading state, and link behavior.
6
+ *
7
+ * @prop disabled {boolean} - Disables interaction
8
+ * @default false
9
+ *
10
+ * @prop children {Snippet} - Content rendered inside the button
11
+ *
12
+ * @prop onClick {(e: MouseEvent) => void} - Click handler
13
+ *
14
+ * @prop sz {SizeKey} - Button size variant
15
+ * @options xs|sm|md|lg|xl
16
+ * @default md
17
+ *
18
+ * @prop variant {ButtonVariant} - Visual style preset
19
+ * @options primary|secondary|pill|danger|success|warning|ghost|link|info
20
+ * @default primary
21
+ *
22
+ * @prop type {"button" | "submit" | "reset"} - Button type attribute
23
+ * @default "button"
24
+ *
25
+ * @prop loaded {boolean} - Shows loading spinner and blocks clicks
26
+ * @default false
27
+ *
28
+ * @prop link {string} - Navigates to a URL when clicked
29
+ *
30
+ * @prop class {string} - Additional classes for the button
31
+ * @default ""
32
+ *
33
+ * @note `disabled` and `loaded` both prevent click events.
34
+ * @note Automatically shows a centered spinner when `loaded` is `true`.
35
+ * @note Link navigation supports `target` and `rel` attributes.
36
+ * @note Accessible with `aria-disabled` and `aria-busy` states.
37
+ * @note The component uses CSS variables for colors, spacing, and transitions.
38
+ */
39
+ import type { HTMLButtonAttributes } from "svelte/elements";
40
+ import type { Snippet } from "svelte";
41
+ import { type SizeKey, type ButtonVariant, TEXT } from "./types";
42
+ import { cx } from "../utils";
43
+
44
+ type Props = HTMLButtonAttributes & {
45
+ disabled?: boolean;
46
+ children?: Snippet;
47
+ onClick?: (e: MouseEvent) => void;
48
+ sz?: SizeKey;
49
+ variant?: ButtonVariant;
50
+ type?: "button" | "submit" | "reset";
51
+ loaded?: boolean;
52
+ link?: string;
53
+ class?: string;
54
+ };
55
+
56
+ let {
57
+ disabled,
58
+ children,
59
+ onClick,
60
+ sz = "md",
61
+ variant = "primary",
62
+ type = "button",
63
+ loaded = false,
64
+ link,
65
+ class: externalClass = "",
66
+ ...rest
67
+ }: Props = $props();
68
+
69
+ const base = `
70
+ relative inline-flex items-center justify-center gap-2 rounded-[var(--radius-md)] border font-medium
71
+ transition-all duration-[var(--transition-fast)] ease-[var(--timing-default)] whitespace-nowrap select-none
72
+ focus:outline-none focus-visible:ring-2 focus-visible:ring-[var(--border-color-focus)]
73
+ [@media(pointer:coarse)]:min-h-11 [@media(pointer:coarse)]:min-w-11
74
+ disabled:opacity-[var(--opacity-disabled)]
75
+ disabled:cursor-not-allowed
76
+ disabled:brightness-100
77
+ disabled:active:scale-100
78
+ disabled:hover:brightness-100
79
+ `;
80
+
81
+ const sizes: Record<SizeKey, string> = {
82
+ xs: "px-2 py-0.5 h-6",
83
+ sm: "px-3 py-1 h-7",
84
+ md: "px-4 py-2 h-8",
85
+ lg: "px-5 py-2.5 h-9",
86
+ xl: "px-6 py-3 h-10",
87
+ };
88
+
89
+ const variants: Record<ButtonVariant, string> = {
90
+ primary:
91
+ "bg-[var(--color-bg-primary)] text-[var(--color-text-inverse,#fff)] border-[var(--border-color-primary)] hover:brightness-110 active:scale-95",
92
+ secondary:
93
+ "bg-[var(--color-bg-secondary)] [color:var(--color-text-default)] border-[var(--border-color-default)] hover:bg-[var(--color-bg-hover)] active:scale-95",
94
+ pill: "bg-[var(--color-bg-primary)] text-[var(--color-text-inverse,#fff)] border-[var(--border-color-primary)] rounded-full hover:brightness-110 active:scale-95",
95
+ danger:
96
+ "bg-[var(--color-bg-danger)] text-[var(--color-text-inverse,#fff)] border-[var(--color-bg-danger)] hover:brightness-110 active:scale-95",
97
+ success:
98
+ "bg-[var(--color-bg-success)] text-[var(--color-text-inverse,#fff)] border-[var(--color-bg-success)] hover:brightness-110 active:scale-95",
99
+ warning:
100
+ "bg-[var(--color-bg-warning)] text-[var(--color-text-inverse,#fff)] border-[var(--color-bg-warning)] hover:brightness-110 active:scale-95",
101
+ ghost:
102
+ "bg-transparent [color:var(--color-text-default)] border-transparent hover:bg-[var(--color-bg-hover)] active:bg-[var(--color-bg-active)] active:scale-95",
103
+ link: "bg-transparent underline border-transparent [color:var(--color-text-link)] hover:brightness-110 active:scale-95 transition-transform ",
104
+ info: "bg-[var(--color-bg-secondary)] text-[var(--color-text-inverse,#fff)] border-[var(--border-color-default)] hover:bg-[var(--color-bg-hover)] active:scale-95",
105
+ };
106
+
107
+ const buttonClass = $derived(
108
+ cx(base, sizes[sz], TEXT[sz], variants[variant], externalClass)
109
+ );
110
+
111
+ const state = $derived(loaded ? "loading" : disabled ? "disabled" : "idle");
112
+
113
+ function handleClick(e: MouseEvent) {
114
+ if (disabled || loaded) {
115
+ e.preventDefault();
116
+ return;
117
+ }
118
+
119
+ if (type === "submit" || type === "reset") {
120
+ onClick?.(e);
121
+ return;
122
+ }
123
+
124
+ onClick?.(e);
125
+ if (!link || e.defaultPrevented) return;
126
+
127
+ if (e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
128
+ return;
129
+ }
130
+
131
+ navigateToLink();
132
+ }
133
+
134
+ function navigateToLink() {
135
+ if (!link || typeof window === "undefined") return;
136
+ const safeLink = getSafeLink(link);
137
+ if (!safeLink) return;
138
+
139
+ const restAttrs = rest as Record<string, unknown>;
140
+ const target =
141
+ typeof restAttrs.target === "string" ? restAttrs.target : undefined;
142
+
143
+ if (target === "_blank") {
144
+ window.open(safeLink, "_blank", "noopener,noreferrer");
145
+ } else {
146
+ window.location.assign(safeLink);
147
+ }
148
+ }
149
+
150
+ function getSafeLink(value: string) {
151
+ try {
152
+ const url = new URL(value, window.location.href);
153
+ if (!["http:", "https:", "mailto:", "tel:"].includes(url.protocol)) {
154
+ return null;
155
+ }
156
+ return value;
157
+ } catch {
158
+ return null;
159
+ }
160
+ }
161
+ </script>
162
+
163
+ <button
164
+ {type}
165
+ {disabled}
166
+ data-state={state}
167
+ aria-disabled={disabled || loaded || undefined}
168
+ aria-busy={loaded || undefined}
169
+ onclick={handleClick}
170
+ class={buttonClass}
171
+ {...rest}
172
+ >
173
+ <span class={cx({ "opacity-0 pointer-events-none": loaded })}>
174
+ {@render children?.()}
175
+ </span>
176
+
177
+ {#if loaded}
178
+ <span
179
+ class={cx(
180
+ "absolute inset-0 m-auto w-[1em] h-[1em] border-2 [border-color:var(--color-spinner,currentColor)] border-r-transparent rounded-full motion-safe:[animation:spin_0.6s_linear_infinite]"
181
+ )}
182
+ aria-hidden="true"
183
+ ></span>
184
+ {/if}
185
+ </button>