@studiocms/ui 0.3.2 → 0.4.1

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 (156) hide show
  1. package/dist/components/Accordion/Accordion.astro +23 -0
  2. package/dist/components/Accordion/Item.astro +21 -0
  3. package/dist/components/Accordion/accordion.css +64 -0
  4. package/dist/components/Accordion/accordion.d.ts +1 -0
  5. package/dist/components/Accordion/accordion.js +70 -0
  6. package/dist/components/Badge/Badge.astro +49 -0
  7. package/dist/components/Badge/badge.css +111 -0
  8. package/dist/components/Breadcrumbs/Breadcrumbs.astro +31 -0
  9. package/dist/components/Breadcrumbs/breadcrumbs.css +15 -0
  10. package/dist/components/Button/Button.astro +75 -0
  11. package/dist/components/Button/button.css +292 -0
  12. package/{src/components → dist/components/Card}/Card.astro +1 -48
  13. package/dist/components/Card/card.css +38 -0
  14. package/dist/components/Center/Center.astro +7 -0
  15. package/dist/components/Center/center.css +8 -0
  16. package/dist/components/Checkbox/Checkbox.astro +95 -0
  17. package/dist/components/Checkbox/checkbox.css +119 -0
  18. package/dist/components/Checkbox/checkbox.d.ts +2 -0
  19. package/dist/components/Checkbox/checkbox.js +20 -0
  20. package/{src/components → dist/components/Divider}/Divider.astro +2 -25
  21. package/dist/components/Divider/divider.css +21 -0
  22. package/dist/components/Dropdown/Dropdown.astro +116 -0
  23. package/dist/components/Dropdown/dropdown.css +180 -0
  24. package/dist/components/Dropdown/dropdown.d.ts +48 -0
  25. package/dist/components/Dropdown/dropdown.js +201 -0
  26. package/dist/components/Footer/Footer.astro +58 -0
  27. package/dist/components/Footer/footer.css +68 -0
  28. package/dist/components/Group/Group.astro +7 -0
  29. package/dist/components/Group/group.css +19 -0
  30. package/{src/utils → dist/components/Icon}/Icon.astro +1 -1
  31. package/{src/utils/iconType.ts → dist/components/Icon/iconType.d.ts} +0 -1
  32. package/dist/components/Icon/iconType.js +0 -0
  33. package/{src/components → dist/components/Input}/Input.astro +2 -48
  34. package/dist/components/Input/input.css +38 -0
  35. package/{src → dist}/components/Modal/Modal.astro +4 -122
  36. package/dist/components/Modal/modal.css +100 -0
  37. package/dist/components/Modal/modal.d.ts +48 -0
  38. package/dist/components/Modal/modal.js +129 -0
  39. package/dist/components/Progress/Progress.astro +21 -0
  40. package/dist/components/Progress/helper.d.ts +13 -0
  41. package/dist/components/Progress/helper.js +32 -0
  42. package/dist/components/Progress/progress.css +29 -0
  43. package/dist/components/Progress/progress.d.ts +1 -0
  44. package/dist/components/Progress/progress.js +10 -0
  45. package/dist/components/RadioGroup/RadioGroup.astro +124 -0
  46. package/dist/components/RadioGroup/radiogroup.css +96 -0
  47. package/dist/components/RadioGroup/radiogroup.d.ts +1 -0
  48. package/dist/components/RadioGroup/radiogroup.js +48 -0
  49. package/{src/components → dist/components/Row}/Row.astro +1 -24
  50. package/dist/components/Row/row.css +18 -0
  51. package/dist/components/SearchSelect/SearchSelect.astro +135 -0
  52. package/dist/components/SearchSelect/searchselect.css +95 -0
  53. package/dist/components/SearchSelect/searchselect.d.ts +6 -0
  54. package/dist/components/SearchSelect/searchselect.js +166 -0
  55. package/dist/components/Select/Select.astro +147 -0
  56. package/dist/components/Select/select.css +110 -0
  57. package/dist/components/Select/select.d.ts +1 -0
  58. package/dist/components/Select/select.js +143 -0
  59. package/dist/components/Sidebar/helpers.d.ts +76 -0
  60. package/dist/components/Sidebar/helpers.js +160 -0
  61. package/{src → dist}/components/Tabs/TabItem.astro +3 -3
  62. package/dist/components/Tabs/Tabs.astro +150 -0
  63. package/dist/components/Tabs/tabs.css +121 -0
  64. package/dist/components/Tabs/tabs.d.ts +1 -0
  65. package/dist/components/Tabs/tabs.js +82 -0
  66. package/{src/components → dist/components/Textarea}/Textarea.astro +2 -61
  67. package/dist/components/Textarea/textarea.css +49 -0
  68. package/dist/components/ThemeToggle/ThemeToggle.astro +21 -0
  69. package/dist/components/ThemeToggle/themetoggle.css +17 -0
  70. package/dist/components/ThemeToggle/themetoggle.d.ts +1 -0
  71. package/dist/components/ThemeToggle/themetoggle.js +4 -0
  72. package/dist/components/Toast/Toaster.astro +69 -0
  73. package/dist/components/Toast/toast.d.ts +8 -0
  74. package/dist/components/Toast/toast.js +9 -0
  75. package/dist/components/Toast/toaster.css +168 -0
  76. package/dist/components/Toast/toaster.d.ts +1 -0
  77. package/dist/components/Toast/toaster.js +160 -0
  78. package/dist/components/Toggle/Toggle.astro +84 -0
  79. package/dist/components/Toggle/toggle.css +93 -0
  80. package/dist/components/Toggle/toggle.d.ts +2 -0
  81. package/dist/components/Toggle/toggle.js +20 -0
  82. package/{src/components → dist/components/User}/User.astro +3 -43
  83. package/dist/components/User/user.css +35 -0
  84. package/dist/css/colors.css +95 -0
  85. package/dist/css/global.css +3 -0
  86. package/dist/css/radii.css +6 -0
  87. package/dist/css/resets.css +46 -0
  88. package/dist/index.d.ts +12 -0
  89. package/dist/index.js +379 -0
  90. package/dist/toolbar/ColorPicker.d.ts +7 -0
  91. package/dist/toolbar/ColorPicker.js +85 -0
  92. package/dist/toolbar/icon.d.ts +1 -0
  93. package/dist/toolbar/icon.js +4 -0
  94. package/dist/toolbar/index.d.ts +2 -0
  95. package/dist/toolbar/index.js +292 -0
  96. package/dist/types/index.d.ts +11 -0
  97. package/dist/types/index.js +0 -0
  98. package/dist/utils/ThemeHelper.d.ts +49 -0
  99. package/dist/utils/ThemeHelper.js +113 -0
  100. package/{src/utils/colors.ts → dist/utils/colors.d.ts} +1 -1
  101. package/dist/utils/colors.js +0 -0
  102. package/dist/utils/generateID.d.ts +2 -0
  103. package/dist/utils/generateID.js +6 -0
  104. package/dist/utils/headers.d.ts +43 -0
  105. package/dist/utils/headers.js +129 -0
  106. package/dist/utils/iconStrings.d.ts +4 -0
  107. package/dist/utils/iconStrings.js +13 -0
  108. package/dist/utils/integration-utils.d.ts +130 -0
  109. package/dist/utils/integration-utils.js +161 -0
  110. package/package.json +26 -10
  111. package/src/components/BaseHead.astro +0 -22
  112. package/src/components/Button.astro +0 -372
  113. package/src/components/Center.astro +0 -16
  114. package/src/components/Checkbox.astro +0 -250
  115. package/src/components/Dropdown/Dropdown.astro +0 -314
  116. package/src/components/Dropdown/dropdown.ts +0 -258
  117. package/src/components/Dropdown/index.ts +0 -2
  118. package/src/components/Footer.astro +0 -137
  119. package/src/components/Modal/index.ts +0 -2
  120. package/src/components/Modal/modal.ts +0 -163
  121. package/src/components/RadioGroup.astro +0 -299
  122. package/src/components/SearchSelect.astro +0 -486
  123. package/src/components/Select.astro +0 -467
  124. package/src/components/Sidebar/helpers.ts +0 -179
  125. package/src/components/Sidebar/index.ts +0 -3
  126. package/src/components/Tabs/Tabs.astro +0 -393
  127. package/src/components/Tabs/index.ts +0 -2
  128. package/src/components/ThemeToggle.astro +0 -46
  129. package/src/components/Toast/Toaster.astro +0 -470
  130. package/src/components/Toast/index.ts +0 -2
  131. package/src/components/Toast/toast.ts +0 -16
  132. package/src/components/Toggle.astro +0 -214
  133. package/src/components/index.ts +0 -27
  134. package/src/components.ts +0 -26
  135. package/src/css/colors.css +0 -106
  136. package/src/css/global.css +0 -2
  137. package/src/css/resets.css +0 -54
  138. package/src/env.d.ts +0 -15
  139. package/src/integration.ts +0 -31
  140. package/src/layouts/RootLayout.astro +0 -33
  141. package/src/layouts/index.ts +0 -2
  142. package/src/layouts.ts +0 -1
  143. package/src/types/index.ts +0 -11
  144. package/src/utils/ThemeHelper.ts +0 -145
  145. package/src/utils/create-resolver.ts +0 -30
  146. package/src/utils/generateID.ts +0 -5
  147. package/src/utils/headers.ts +0 -190
  148. package/src/utils/iconStrings.ts +0 -29
  149. package/src/utils/index.ts +0 -1
  150. package/src/utils/virtual-module-plugin-builder.ts +0 -37
  151. /package/{src → dist}/components/Sidebar/Double.astro +0 -0
  152. /package/{src → dist}/components/Sidebar/Single.astro +0 -0
  153. /package/{src → dist}/icons/Checkmark.astro +0 -0
  154. /package/{src → dist}/icons/ChevronUpDown.astro +0 -0
  155. /package/{src → dist}/icons/User.astro +0 -0
  156. /package/{src → dist}/icons/X-Mark.astro +0 -0
@@ -1,470 +0,0 @@
1
- ---
2
- /**
3
- * Props for the Toast component.
4
- */
5
- interface Props {
6
- /**
7
- * The position of the toaster. All toasts will originate from this position.
8
- */
9
- position?:
10
- | 'top-left'
11
- | 'top-right'
12
- | 'top-center'
13
- | 'bottom-left'
14
- | 'bottom-right'
15
- | 'bottom-center';
16
- /**
17
- * The duration of the toast in milliseconds. Defaults to 4000 (4 seconds).
18
- */
19
- duration?: number;
20
- /**
21
- * Whether the toast has a close button. Defaults to false.
22
- */
23
- closeButton?: boolean;
24
- /**
25
- * The offset of the toaster from the edge of the screen in pixels. Defaults to 32.
26
- */
27
- offset?: number;
28
- /**
29
- * The gap between toasts in pixels. Defaults to 8.
30
- */
31
- gap?: number;
32
- }
33
-
34
- const {
35
- position = 'top-center',
36
- duration = 4000,
37
- closeButton = false,
38
- offset = 32,
39
- gap = 8,
40
- } = Astro.props;
41
- ---
42
- <div
43
- id="sui-toaster"
44
- class:list={[
45
- closeButton && "closeable",
46
- position,
47
- ]},
48
- >
49
- <div
50
- id="sui-toast-drawer"
51
- data-offset={offset}
52
- data-gap={gap}
53
- data-duration={duration}
54
- style={[
55
- `${position.includes("top-") ? 'top:' : 'bottom:'} ${offset}px;`,
56
- position.includes("-left") && `left: ${offset}px`,
57
- position.includes("-right") && `right: ${offset}px`,
58
- position.includes("-center") && `left: 50%; transform: translateX(-50%);`,
59
- `--gap: ${gap}px;`,
60
- `padding-left: ${offset}px;`,
61
- `padding-right: ${offset}px;`,
62
- ].filter(Boolean).join("")}
63
- />
64
- </div>
65
- <script>
66
- import type { ToastProps } from '../../types';
67
- import type { ValidIconString } from '../../utils/iconStrings';
68
-
69
- import { generateID } from '../../utils/generateID';
70
- import { getIconString } from '../../utils/iconStrings';
71
-
72
- let activeToasts: string[] = [];
73
-
74
- let lastActiveElement: HTMLElement | null = null;
75
-
76
- const revertFocusBackToLastActiveElement = () => {
77
- if (lastActiveElement) {
78
- lastActiveElement.focus();
79
- lastActiveElement = null;
80
- }
81
- };
82
-
83
- /**
84
- * Callback wrapper that allows for pausing, continuing and clearing a timer. Based on https://stackoverflow.com/a/20745721.
85
- * @param callback The callback to be called.
86
- * @param delay The delay in milliseconds.
87
- */
88
- class Timer {
89
- private id: NodeJS.Timeout | null;
90
- private started: Date | null;
91
- private remaining: number;
92
- private running: boolean;
93
- private callback: () => any;
94
-
95
- constructor(callback: () => any, delay: number) {
96
- this.id = null;
97
- this.started = null;
98
- this.remaining = delay;
99
- this.running = false;
100
- this.callback = callback;
101
-
102
- this.start();
103
- }
104
-
105
- start = () => {
106
- this.running = true;
107
- this.started = new Date();
108
- this.id = setTimeout(this.callback, this.remaining);
109
- };
110
-
111
- pause = () => {
112
- if (!this.id || !this.started || !this.running) return;
113
-
114
- this.running = false;
115
- clearTimeout(this.id);
116
- this.remaining -= new Date().getTime() - this.started.getTime();
117
- };
118
-
119
- getTimeLeft = () => {
120
- if (this.running) {
121
- this.pause();
122
- this.start();
123
- }
124
-
125
- return this.remaining;
126
- };
127
-
128
- getStateRunning = () => {
129
- return this.running;
130
- };
131
- }
132
-
133
- function removeToast(toastID: string) {
134
- const toastEl = document.getElementById(toastID);
135
-
136
- if (!toastEl) return;
137
-
138
- activeToasts = activeToasts.filter(x => x !== toastID);
139
-
140
- toastEl.classList.add('closing');
141
-
142
- setTimeout(() => toastEl.remove(), 400);
143
- }
144
-
145
- function createToast(props: ToastProps) {
146
- const toastParent = document.getElementById('sui-toast-drawer')! as HTMLDivElement;
147
-
148
- const toastContainer = document.createElement('div');
149
- const toastID = generateID('toast');
150
- toastContainer.tabIndex = 0;
151
- toastContainer.ariaLive = 'polite';
152
- toastContainer.role = 'alert';
153
- toastContainer.id = toastID;
154
- toastContainer.ariaLabel = `${props.title} (F8)`;
155
- toastContainer.classList.add('sui-toast-container', props.type, `${props.closeButton || props.persistent && "closeable"}`, `${props.persistent && 'persistent'}`);
156
-
157
- const toastHeader = document.createElement('div');
158
- toastHeader.classList.add('sui-toast-header');
159
-
160
- const toastHeaderLeftSide = document.createElement('div');
161
- toastHeaderLeftSide.classList.add('sui-toast-header-left-side')
162
-
163
- const toastTitle = document.createElement('span');
164
- toastTitle.textContent = props.title;
165
- toastTitle.classList.add('sui-toast-title');
166
-
167
- let iconString: ValidIconString;
168
-
169
- if (props.type === 'success') {
170
- iconString = 'check-circle';
171
- } else if (props.type === 'danger') {
172
- iconString = 'exclamation-circle';
173
- } else if (props.type === 'warning') {
174
- iconString = 'exclamation-triangle';
175
- } else {
176
- iconString = 'information-circle';
177
- }
178
-
179
- const toastIcon = getIconString(iconString, 'toast-icon', 24, 24);
180
- toastHeaderLeftSide.innerHTML = toastIcon;
181
-
182
- toastHeaderLeftSide.appendChild(toastTitle);
183
- toastHeader.appendChild(toastHeaderLeftSide);
184
-
185
- if (props.closeButton || props.persistent) {
186
- const closeIconContainer = document.createElement('button');
187
- closeIconContainer.classList.add('close-icon-container');
188
- closeIconContainer.addEventListener('click', () => removeToast(toastID));
189
- closeIconContainer.innerHTML = getIconString('x-mark', 'close-icon', 24, 24);
190
- closeIconContainer.tabIndex = 0;
191
- closeIconContainer.ariaLabel = 'Close toast';
192
-
193
- toastHeader.appendChild(closeIconContainer);
194
- }
195
-
196
- toastContainer.appendChild(toastHeader);
197
-
198
- if (props.description) {
199
- const toastDesc = document.createElement('span');
200
- toastDesc.innerHTML = props.description;
201
- toastDesc.classList.add('sui-toast-desc');
202
-
203
- toastContainer.appendChild(toastDesc);
204
- }
205
-
206
- if (!props.persistent) {
207
- const toastProgressBar = document.createElement('div');
208
- toastProgressBar.classList.add('sui-toast-progress-bar');
209
- toastProgressBar.style.animationDuration = props.duration ? `${props.duration}ms` : `${toastParent.dataset.duration || 4000}ms`;
210
-
211
- toastContainer.appendChild(toastProgressBar);
212
- }
213
-
214
- toastParent.appendChild(toastContainer);
215
-
216
- activeToasts.push(toastID);
217
-
218
- if (!props.persistent) {
219
- let timer = new Timer(
220
- () => removeToast(toastID),
221
- props.duration || (toastParent.dataset.duration ? parseInt(toastParent.dataset.duration) : 4000)
222
- );
223
-
224
- const timerPauseWrapper = () => {
225
- toastContainer.classList.add('paused');
226
- timer.pause();
227
- };
228
-
229
- const timerStartWrapper = () => {
230
- toastContainer.classList.remove('paused');
231
- timer.start();
232
- };
233
-
234
- toastContainer.addEventListener('mouseenter', timerPauseWrapper);
235
- toastContainer.addEventListener('focusin', timerPauseWrapper);
236
-
237
- toastContainer.addEventListener('mouseleave', timerStartWrapper);
238
- toastContainer.addEventListener('focusout', () => {
239
- let focusedOrHasFocused = toastContainer.matches(':focus-within');
240
-
241
- if (!focusedOrHasFocused) {
242
- revertFocusBackToLastActiveElement();
243
- }
244
-
245
- timerStartWrapper();
246
- });
247
- }
248
-
249
- toastContainer.addEventListener('keydown', (e) => {
250
- if (e.key === 'Escape') {
251
- e.preventDefault();
252
- removeToast(toastID);
253
- revertFocusBackToLastActiveElement();
254
- }
255
- });
256
- }
257
-
258
- document.addEventListener('createtoast', (e) => {
259
- e.stopImmediatePropagation();
260
-
261
- const event = e as CustomEvent<ToastProps>;
262
-
263
- createToast(event.detail);
264
- });
265
-
266
- window.addEventListener('keydown', (e) => {
267
- if (e.key === 'F8') {
268
- e.preventDefault();
269
-
270
- const oldestToast = activeToasts[0];
271
-
272
- if (oldestToast) {
273
- lastActiveElement = document.activeElement as HTMLElement;
274
-
275
- const toastEl = document.getElementById(oldestToast);
276
- if (toastEl) toastEl?.focus();
277
- }
278
- }
279
- });
280
- </script>
281
- <style>
282
- #sui-toaster {
283
- width: 100vw;
284
- height: 100vh;
285
- position: fixed;
286
- top: 0;
287
- left: 0;
288
- z-index: 100;
289
- pointer-events: none;
290
- color: hsl(var(--text-normal));
291
- }
292
-
293
- #sui-toast-drawer {
294
- max-width: 420px;
295
- width: 100%;
296
- height: fit-content;
297
- position: absolute;
298
- display: flex;
299
- flex-direction: column;
300
- }
301
-
302
- #sui-toaster.top-left #sui-toast-drawer,
303
- #sui-toaster.bottom-left #sui-toast-drawer {
304
- left: 50%;
305
- transform: translateX(-50%);
306
- }
307
- </style>
308
- <style is:global>
309
- .sui-toast-container {
310
- pointer-events: all;
311
- padding: 1rem;
312
- border-radius: .5rem;
313
- border: 1px solid hsl(var(--border));
314
- background-color: hsl(var(--background-base));
315
- box-shadow: 0px 4px 8px hsl(var(--shadow), 0.5);
316
- display: flex;
317
- flex-direction: column;
318
- gap: .5rem;
319
- position: relative;
320
- overflow: hidden;
321
- margin-bottom: var(--gap);
322
- animation: toast-pop-in .25s ease forwards;
323
- z-index: 90;
324
- }
325
-
326
- .sui-toast-header {
327
- display: flex;
328
- flex-direction: row;
329
- align-items: center;
330
- justify-content: space-between;
331
- }
332
-
333
- .sui-toast-header-left-side {
334
- display: flex;
335
- flex-direction: row;
336
- gap: .5rem;
337
- align-items: center;
338
- font-weight: 500;
339
- font-size: 1.125em;
340
- }
341
-
342
- .sui-toast-header-left-side svg {
343
- color: hsl(var(--primary-base));
344
- }
345
-
346
- .sui-toast-container.success .sui-toast-header-left-side svg {
347
- color: hsl(var(--success-base));
348
- }
349
-
350
- .sui-toast-container.warning .sui-toast-header-left-side svg {
351
- color: hsl(var(--warning-base));
352
- }
353
-
354
- .sui-toast-container.danger .sui-toast-header-left-side svg {
355
- color: hsl(var(--danger-base));
356
- }
357
-
358
- .sui-toast-progress-bar {
359
- position: absolute;
360
- height: 4px;
361
- width: 100%;
362
- bottom: 0;
363
- left: 0%;
364
- background-color: hsl(var(--primary-base));
365
- animation: toast-progress forwards linear;
366
- }
367
-
368
- .sui-toast-container.paused .sui-toast-progress-bar {
369
- animation-play-state: paused;
370
- }
371
-
372
- .sui-toast-container.success .sui-toast-progress-bar {
373
- background-color: hsl(var(--success-base));
374
- }
375
-
376
- .sui-toast-container.warning .sui-toast-progress-bar {
377
- background-color: hsl(var(--warning-base));
378
- }
379
-
380
- .sui-toast-container.danger .sui-toast-progress-bar {
381
- background-color: hsl(var(--danger-base));
382
- }
383
-
384
- .close-icon-container {
385
- cursor: pointer;
386
- height: 1.5rem;
387
- width: 1.5rem;
388
- display: flex;
389
- align-items: center;
390
- justify-content: center;
391
- transition: background-color .15s ease;
392
- border-radius: .25rem;
393
- }
394
-
395
- .close-icon-container:hover {
396
- background-color: hsl(var(--default-base));
397
- }
398
-
399
- .close-icon-container:focus-visible {
400
- outline: 2px solid hsl(var(--text-normal));
401
- outline-offset: 2px;
402
- }
403
-
404
- .sui-toast-container.closing {
405
- animation: toast-closing .25s ease forwards;
406
- }
407
-
408
- .sui-toast-container.persistent {
409
- border: 1px solid hsl(var(--primary-base));
410
- }
411
-
412
- .sui-toast-container.persistent.success {
413
- border: 1px solid hsl(var(--success-base));
414
- }
415
-
416
- .sui-toast-container.persistent.warning {
417
- border: 1px solid hsl(var(--warning-base));
418
- }
419
-
420
- .sui-toast-container.persistent.danger {
421
- border: 1px solid hsl(var(--danger-base));
422
- }
423
-
424
- @keyframes toast-pop-in {
425
- 0% {
426
- opacity: 0;
427
- scale: 0.75;
428
- }
429
- 100% {
430
- opacity: 1;
431
- scale: 1;
432
- }
433
- }
434
-
435
- @keyframes toast-closing {
436
- 0% {
437
- opacity: 1;
438
- scale: 1;
439
- max-height: 500px;
440
- margin-bottom: var(--gap);
441
- padding: 1rem;
442
- border: 1px solid hsl(var(--border));
443
- }
444
- 62.5% {
445
- scale: 0.75;
446
- opacity: 0;
447
- max-height: 500px;
448
- margin-bottom: var(--gap);
449
- padding: 1rem;
450
- border: 1px solid hsl(var(--border));
451
- }
452
- 100% {
453
- scale: 0.75;
454
- opacity: 0;
455
- max-height: 0px;
456
- margin-bottom: 0;
457
- padding: 0;
458
- border: 0px solid hsl(var(--border));
459
- }
460
- }
461
-
462
- @keyframes toast-progress {
463
- 0% {
464
- left: 0%;
465
- }
466
- 100% {
467
- left: -100%;
468
- }
469
- }
470
- </style>
@@ -1,2 +0,0 @@
1
- export { default as Toaster } from './Toaster.astro';
2
- export { toast } from './toast';
@@ -1,16 +0,0 @@
1
- import type { ToastProps } from '../../types';
2
-
3
- /**
4
- * A function to create toasts with.
5
-
6
- * @param props The props to pass to the toast
7
- */
8
- function toast(props: ToastProps) {
9
- const createToast = new CustomEvent('createtoast', {
10
- detail: props,
11
- });
12
-
13
- document.dispatchEvent(createToast);
14
- }
15
-
16
- export { toast };
@@ -1,214 +0,0 @@
1
- ---
2
- import type { StudioCMSColorway } from '../utils/colors';
3
- import { generateID } from '../utils/generateID';
4
-
5
- /**
6
- * The props for the toggle component
7
- */
8
- interface Props {
9
- /**
10
- * The label of the toggle.
11
- */
12
- label: string;
13
- /**
14
- * The size of the toggle. Defaults to `md`.
15
- */
16
- size?: 'sm' | 'md' | 'lg';
17
- /**
18
- * The color of the toggle. Defaults to `default`.
19
- */
20
- color?: StudioCMSColorway;
21
- /**
22
- * Whether the toggle is checked by default. Defaults to `false`.
23
- */
24
- defaultChecked?: boolean;
25
- /**
26
- * Whether the toggle is disabled. Defaults to `false`.
27
- */
28
- disabled?: boolean;
29
- /**
30
- * The name of the toggle.
31
- */
32
- name?: string;
33
- /**
34
- * Whether the toggle is required. Defaults to `false`.
35
- */
36
- isRequired?: boolean;
37
- }
38
-
39
- const {
40
- size = 'md',
41
- color = 'default',
42
- defaultChecked,
43
- disabled,
44
- name = generateID('checkbox'),
45
- label,
46
- isRequired,
47
- } = Astro.props;
48
- ---
49
- <label
50
- class="sui-toggle-label"
51
- for={name}
52
- class:list={[
53
- disabled && "disabled",
54
- color,
55
- size,
56
- ]}
57
- >
58
- <div class="sui-toggle-container">
59
- <div
60
- class="sui-toggle-switch"
61
- tabindex="0"
62
- role="checkbox"
63
- aria-checked={defaultChecked}
64
- aria-label={label}
65
- />
66
- <input
67
- type="checkbox"
68
- name={name}
69
- id={name}
70
- checked={defaultChecked}
71
- disabled={disabled}
72
- required={isRequired}
73
- class="sui-toggle-checkbox"
74
- hidden
75
- />
76
- </div>
77
- <span id={`label-${name}`}>
78
- {label} <span class="req-star">{isRequired && "*"}</span>
79
- </span>
80
- </label>
81
- <script>
82
- const elements = document.querySelectorAll<HTMLDivElement>('.sui-toggle-container');
83
- const toggles = document.querySelectorAll<HTMLInputElement>('.sui-toggle-checkbox');
84
-
85
- for (const element of elements) {
86
- if (element.dataset.initialized) continue;
87
-
88
- element.dataset.initialized = 'true';
89
-
90
- element.addEventListener('keydown', (e) => {
91
- if (e.key !== 'Enter' && e.key !== ' ') return;
92
-
93
- e.preventDefault();
94
-
95
- const checkbox = element.querySelector<HTMLInputElement>('.sui-toggle-checkbox');
96
-
97
- if (!checkbox) return;
98
-
99
- checkbox.click();
100
- });
101
- }
102
-
103
- for (const box of toggles) {
104
- if (box.dataset.initialized) continue;
105
-
106
- box.dataset.initialized = 'true';
107
-
108
- box.addEventListener('change', (e) => {
109
- (box.previousSibling as HTMLDivElement).ariaChecked = (e.target as HTMLInputElement).checked ? 'true' : 'false';
110
- });
111
- }
112
- </script>
113
- <style>
114
- .sui-toggle-label {
115
- display: flex;
116
- flex-direction: row;
117
- align-items: center;
118
- gap: .5rem;
119
- position: relative;
120
- margin: .25rem 0;
121
- }
122
-
123
- .sui-toggle-label.disabled {
124
- opacity: 0.5;
125
- pointer-events: none;
126
- color: hsl(var(--text-muted));
127
- }
128
-
129
- .sui-toggle-label:active .sui-toggle-switch {
130
- transform: scale(0.85);
131
- }
132
-
133
- .sui-toggle-container {
134
- --toggle-height: 12px;
135
- --toggle-width: 40px;
136
- display: flex;
137
- align-items: center;
138
- cursor: pointer;
139
- transition: all .15s ease;
140
- background-color: hsl(var(--default-base));
141
- width: var(--toggle-width);
142
- height: var(--toggle-height);
143
- border-radius: var(--toggle-height);
144
- }
145
-
146
- .sui-toggle-switch {
147
- --switch: calc(var(--toggle-height) * 1.75);
148
- height: var(--switch);
149
- width: var(--switch);
150
- background-color: hsl(var(--text-muted));
151
- border-radius: var(--toggle-height);
152
- position: relative;
153
- left: 0;
154
- transition: all .15s ease;
155
- will-change: transform;
156
- }
157
-
158
- .sui-toggle-switch:focus-visible {
159
- outline: 2px solid hsl(var(--text-normal));
160
- outline-offset: 2px;
161
- }
162
-
163
- .sui-toggle-container:has(.sui-toggle-checkbox:checked) .sui-toggle-switch {
164
- left: calc(100% - var(--switch));
165
- background-color: hsl(var(--text-normal));
166
- }
167
-
168
- .sui-toggle-label.sm .sui-toggle-container {
169
- --toggle-height: 10px;
170
- --toggle-width: 32px;
171
- }
172
-
173
- .sui-toggle-label.sm .sui-toggle-switch {
174
- --switch: calc(var(--toggle-height) * 1.65);
175
- }
176
-
177
- .sui-toggle-label.lg .sui-toggle-container {
178
- --toggle-height: 16px;
179
- --toggle-width: 48px;
180
- }
181
-
182
- .sui-toggle-label.lg .sui-toggle-switch {
183
- --switch: calc(var(--toggle-height) * 1.65);
184
- }
185
-
186
- .sui-toggle-label.primary .sui-toggle-container:has(.sui-toggle-checkbox:checked) {
187
- background-color: hsl(var(--primary-base));
188
- }
189
-
190
- .sui-toggle-label.success .sui-toggle-container:has(.sui-toggle-checkbox:checked) {
191
- background-color: hsl(var(--success-base));
192
- }
193
-
194
- .sui-toggle-label.warning .sui-toggle-container:has(.sui-toggle-checkbox:checked) {
195
- background-color: hsl(var(--warning-base));
196
- }
197
-
198
- .sui-toggle-label.danger .sui-toggle-container:has(.sui-toggle-checkbox:checked) {
199
- background-color: hsl(var(--danger-base));
200
- }
201
-
202
- .req-star {
203
- color: hsl(var(--danger-base));
204
- font-weight: 700;
205
- }
206
-
207
- .sui-toggle-checkbox {
208
- width: 0;
209
- height: 0;
210
- visibility: hidden;
211
- opacity: 0;
212
- margin: 0;
213
- }
214
- </style>