@studiocms/ui 0.3.2 → 0.4.0

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 +25 -9
  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,163 +0,0 @@
1
- class ModalHelper {
2
- private element: HTMLDialogElement;
3
- private cancelButton: HTMLButtonElement | undefined;
4
- private confirmButton: HTMLButtonElement | undefined;
5
-
6
- private isForm = false;
7
- private modalForm: HTMLFormElement;
8
-
9
- /**
10
- * A helper to manage modals.
11
- * @param id The ID of the modal.
12
- * @param triggerID The ID of the element that should trigger the modal.
13
- */
14
- constructor(id: string, triggerID?: string) {
15
- const element = document.getElementById(id) as HTMLDialogElement;
16
-
17
- if (!element) {
18
- throw new Error(`No modal with ID ${id} found.`);
19
- }
20
-
21
- this.element = element as HTMLDialogElement;
22
- this.modalForm = document.getElementById(`${id}-form-element`) as HTMLFormElement;
23
-
24
- const isDismissable = this.element.dataset.dismissable === 'true';
25
- const isForm = this.element.dataset.form === 'true';
26
-
27
- if (isDismissable) {
28
- this.addDismissiveClickListener();
29
- }
30
-
31
- if (isForm) this.isForm = true;
32
-
33
- this.addButtonListeners(id, isDismissable);
34
-
35
- if (triggerID) {
36
- this.bindTrigger(triggerID);
37
- }
38
- }
39
-
40
- /**
41
- * A helper function which adds event listeners to the modal buttons to close the modal when clicked.
42
- * @param id The ID of the modal.
43
- * @param dismissable Whether the modal is dismissable.
44
- */
45
- private addButtonListeners = (id: string, dismissable: boolean) => {
46
- if (
47
- dismissable ||
48
- (!this.element.dataset.hasCancelButton && !this.element.dataset.hasActionButton)
49
- ) {
50
- const xMarkButton = document.getElementById(`${id}-btn-x`) as HTMLButtonElement;
51
- xMarkButton.addEventListener('click', this.hide);
52
- }
53
-
54
- if (!!this.element.dataset.hasCancelButton && !this.element.dataset.hasActionButton) return;
55
-
56
- if (this.element.dataset.hasCancelButton) {
57
- this.cancelButton = document.getElementById(`${id}-btn-cancel`) as HTMLButtonElement;
58
- this.cancelButton.addEventListener('click', this.hide);
59
- }
60
-
61
- if (this.element.dataset.hasActionButton) {
62
- this.confirmButton = document.getElementById(`${id}-btn-confirm`) as HTMLButtonElement;
63
- this.confirmButton.addEventListener('click', this.hide);
64
- }
65
- };
66
-
67
- /**
68
- * A helper function to close the modal when the user clicks outside of it.
69
- */
70
- private addDismissiveClickListener = () => {
71
- this.element.addEventListener('click', (e: MouseEvent) => {
72
- if (!e.target) return;
73
-
74
- const { left, right, top, bottom } = this.element.getBoundingClientRect();
75
-
76
- const clickWithinModalBox =
77
- e.clientX < right && e.clientX > left && e.clientY < bottom && e.clientY > top;
78
-
79
- if (!clickWithinModalBox) {
80
- this.element.close();
81
- }
82
- });
83
- };
84
-
85
- /**
86
- * A function to show the modal.
87
- */
88
- public show = () => {
89
- this.element.showModal();
90
- this.element.focus();
91
- };
92
-
93
- /**
94
- * A function to hide the modal.
95
- */
96
- public hide = () => {
97
- this.element.close();
98
- };
99
-
100
- /**
101
- * A function to add another trigger to show the modal with.
102
- * @param elementID The ID of the element that should trigger the modal when clicked.
103
- */
104
- public bindTrigger = (elementID: string) => {
105
- const element = document.getElementById(elementID);
106
-
107
- if (!element) {
108
- throw new Error(`No element with ID ${elementID} found.`);
109
- }
110
-
111
- element.addEventListener('click', this.show);
112
- };
113
-
114
- /**
115
- * Registers a callback for the cancel button.
116
- * @param func The callback function.
117
- */
118
- public registerCancelCallback = (func: () => void) => {
119
- if (!this.cancelButton) {
120
- throw new Error('Unable to register cancel callback without a cancel button.');
121
- }
122
-
123
- this.cancelButton.removeEventListener('click', this.hide);
124
-
125
- this.cancelButton.addEventListener('click', () => {
126
- func();
127
- this.hide();
128
- });
129
- };
130
-
131
- /**
132
- * Registers a callback for the confirm button.
133
- * @param func The callback function. If the modal is a form, the function will be called with
134
- * the form data as the first argument.
135
- */
136
- public registerConfirmCallback = (func: (data?: FormData | undefined) => void) => {
137
- if (!this.confirmButton) {
138
- throw new Error('Unable to register cancel callback without a confirmation button.');
139
- }
140
-
141
- this.confirmButton.removeEventListener('click', this.hide);
142
-
143
- if (this.isForm) {
144
- this.modalForm.addEventListener('submit', (e) => {
145
- e.preventDefault();
146
-
147
- const formData = new FormData(this.modalForm);
148
-
149
- func(formData);
150
- this.hide();
151
-
152
- setTimeout(() => this.modalForm.reset(), 450);
153
- });
154
- } else {
155
- this.confirmButton.addEventListener('click', () => {
156
- func();
157
- this.hide();
158
- });
159
- }
160
- };
161
- }
162
-
163
- export { ModalHelper };
@@ -1,299 +0,0 @@
1
- ---
2
- import type { StudioCMSColorway } from '../utils/colors';
3
- import { generateID } from '../utils/generateID';
4
-
5
- /**
6
- * The props for the RadioGroup component.
7
- */
8
- interface Option {
9
- /**
10
- * The label of the option.
11
- */
12
- label: string;
13
- /**
14
- * The value of the option.
15
- */
16
- value: string;
17
- /**
18
- * Whether the option is disabled.
19
- */
20
- disabled?: boolean;
21
- }
22
-
23
- /**
24
- * The props for the RadioGroup component.
25
- */
26
- interface Props {
27
- /**
28
- * The label of the radio group.
29
- */
30
- label: string;
31
- /**
32
- * The color of the radio group. Defaults to `default`.
33
- */
34
- color?: StudioCMSColorway;
35
- /**
36
- * The default value of the radio group. Needs to be one of the values in the options.
37
- */
38
- defaultValue?: string;
39
- /**
40
- * The options to display in the radio group.
41
- */
42
- options: Option[];
43
- /**
44
- * Whether the radio group is disabled. Defaults to `false`.
45
- */
46
- disabled?: boolean;
47
- /**
48
- * The name of the radio group.
49
- */
50
- name?: string;
51
- /**
52
- * Whether the radio group is required. Defaults to `false`.
53
- */
54
- isRequired?: boolean;
55
- /**
56
- * Whether the radio group is horizontal. Defaults to `false`.
57
- */
58
- horizontal?: boolean;
59
- /**
60
- * Additional classes to apply to the radio group.
61
- */
62
- class?: string;
63
- }
64
-
65
- const {
66
- label,
67
- color = 'default',
68
- defaultValue,
69
- options,
70
- disabled = false,
71
- isRequired = false,
72
- horizontal = false,
73
- name = generateID('radio'),
74
- class: className,
75
- } = Astro.props;
76
- ---
77
-
78
- <div
79
- class="sui-radio-container"
80
- class:list={[
81
- disabled && "disabled",
82
- horizontal && "horizontal",
83
- color,
84
- className
85
- ]}
86
- >
87
- <span>
88
- {label} <span class="req-star">{isRequired && "*"}</span>
89
- </span>
90
- <div class="sui-radio-inputs" role="radiogroup">
91
- {options.map(({ label, value, disabled: individuallyDisabled }, i) => (
92
- <label
93
- for={value}
94
- class="sui-radio-label"
95
- class:list={[ individuallyDisabled && "disabled" ]}
96
- >
97
- <div class="sui-radio-box-container">
98
- <div
99
- class="sui-radio-box"
100
- role="radio"
101
- tabindex={i === 0 ? 0 : -1}
102
- aria-checked={value === defaultValue}
103
- aria-label={label}
104
- />
105
- </div>
106
- <input
107
- class="sui-radio-toggle"
108
- type="radio"
109
- value={value}
110
- id={value}
111
- name={name}
112
- checked={value === defaultValue}
113
- disabled={disabled || individuallyDisabled}
114
- required={isRequired}
115
- />
116
- <span>{label}</span>
117
- </label>
118
- ))}
119
- </div>
120
- </div>
121
- <script>
122
- const elements = document.querySelectorAll<HTMLDivElement>('.sui-radio-container');
123
-
124
- for (const element of elements) {
125
- if (element.dataset.initialized) continue;
126
-
127
- element.dataset.initialized = 'true';
128
-
129
- const radioBoxes = element.querySelectorAll<HTMLDivElement>('.sui-radio-box');
130
-
131
- let i = 0;
132
-
133
- for (const radioBox of radioBoxes) {
134
- radioBox.addEventListener('keydown', (e) => {
135
- if (e.key === 'Enter' || e.key === " ") {
136
- e.preventDefault();
137
-
138
- const input = (e.target as HTMLDivElement).parentElement!.parentElement!.querySelector<HTMLInputElement>('.sui-radio-toggle')!;
139
-
140
- if (input.disabled) return;
141
-
142
- input.checked = true;
143
- }
144
-
145
- if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
146
- e.preventDefault();
147
-
148
- let nextRadioBox: HTMLDivElement | undefined;
149
-
150
- radioBoxes.forEach((box, index) => {
151
- if (box === radioBox) nextRadioBox = radioBoxes[index + 1];
152
- });
153
-
154
- if (!nextRadioBox) return;
155
-
156
- radioBox.tabIndex = -1;
157
- nextRadioBox.tabIndex = 0;
158
- nextRadioBox.focus();
159
- nextRadioBox.click();
160
- }
161
-
162
- if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
163
- e.preventDefault();
164
-
165
- let previousRadioBox: HTMLDivElement | undefined;
166
-
167
- radioBoxes.forEach((box, index) => {
168
- if (box === radioBox) previousRadioBox = radioBoxes[index - 1];
169
- });
170
-
171
- if (!previousRadioBox) return;
172
-
173
- radioBox.tabIndex = -1;
174
- previousRadioBox.tabIndex = 0;
175
- previousRadioBox.focus();
176
- previousRadioBox.click();
177
- }
178
- });
179
-
180
- i++;
181
- }
182
- element.addEventListener('keydown', (e) => {
183
- if (e.key !== 'Enter') return;
184
-
185
- const checkbox = element.querySelector<HTMLInputElement>('.sui-checkbox');
186
-
187
- if (!checkbox) return;
188
-
189
- checkbox.click();
190
- });
191
- }
192
- </script>
193
- <style>
194
- .sui-radio-container {
195
- display: flex;
196
- flex-direction: column;
197
- gap: .5rem;
198
- }
199
-
200
- .sui-radio-container.disabled {
201
- opacity: 0.5;
202
- color: hsl(var(--text-muted));
203
- }
204
-
205
- .sui-radio-label.disabled {
206
- opacity: 0.5;
207
- color: hsl(var(--text-muted));
208
- pointer-events: none;
209
- }
210
-
211
- .req-star {
212
- color: hsl(var(--danger-base));
213
- font-weight: 700;
214
- }
215
-
216
- .sui-radio-inputs {
217
- display: flex;
218
- flex-direction: column;
219
- gap: .75rem;
220
- }
221
-
222
- .sui-radio-container.horizontal .sui-radio-inputs {
223
- flex-direction: row;
224
- }
225
-
226
- .sui-radio-label {
227
- display: flex;
228
- flex-direction: row;
229
- gap: .5rem;
230
- position: relative;
231
- align-items: center;
232
- }
233
-
234
- .sui-radio-label:hover .sui-radio-box {
235
- outline-color: hsl(var(--default-hover));
236
- }
237
-
238
- .sui-radio-container:not(.disabled) .sui-radio-label:active .sui-radio-box {
239
- outline-color: hsl(var(--default-active));
240
- scale: 0.9;
241
- }
242
-
243
- .sui-radio-label:has(.sui-radio-toggle:checked) .sui-radio-box {
244
- background-color: hsl(var(--text-normal));
245
- outline-color: hsl(var(--text-normal));
246
- }
247
-
248
- .sui-radio-container.primary .sui-radio-label:has(.sui-radio-toggle:checked) .sui-radio-box {
249
- background-color: hsl(var(--primary-base));
250
- outline-color: hsl(var(--primary-base));
251
- }
252
-
253
- .sui-radio-container.success .sui-radio-label:has(.sui-radio-toggle:checked) .sui-radio-box {
254
- background-color: hsl(var(--success-base));
255
- outline-color: hsl(var(--success-base));
256
- }
257
-
258
- .sui-radio-container.warning .sui-radio-label:has(.sui-radio-toggle:checked) .sui-radio-box {
259
- background-color: hsl(var(--warning-base));
260
- outline-color: hsl(var(--warning-base));
261
- }
262
-
263
- .sui-radio-container.danger .sui-radio-label:has(.sui-radio-toggle:checked) .sui-radio-box {
264
- background-color: hsl(var(--danger-base));
265
- outline-color: hsl(var(--danger-base));
266
- }
267
-
268
- .sui-radio-box-container {
269
- width: 20px;
270
- height: 20px;
271
- display: flex;
272
- flex-direction: row;
273
- align-items: center;
274
- justify-content: center;
275
- cursor: pointer;
276
- }
277
-
278
- .sui-radio-box {
279
- width: 12px;
280
- height: 12px;
281
- border-radius: 20px;
282
- outline: 1px solid hsl(var(--default-base));
283
- outline-offset: 4px;
284
- transition: all .15s ease;
285
- }
286
-
287
- .sui-radio-box:focus-visible {
288
- outline-color: hsl(var(--text-normal)) !important;
289
- }
290
-
291
- .sui-radio-toggle {
292
- width: 0;
293
- height: 0;
294
- visibility: hidden;
295
- opacity: 0;
296
- margin: 0;
297
- position: absolute;
298
- }
299
- </style>