@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,467 +0,0 @@
1
- ---
2
- import Icon from '../utils/Icon.astro';
3
- import { generateID } from '../utils/generateID';
4
-
5
- /**
6
- * The props for the select 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. Defaults to `false`.
19
- */
20
- disabled?: boolean;
21
- }
22
-
23
- /**
24
- * The props for the select component.
25
- */
26
- interface Props {
27
- /**
28
- * The label of the select.
29
- */
30
- label?: string;
31
- /**
32
- * The default value of the select.
33
- */
34
- defaultValue?: string;
35
- /**
36
- * Additional classes to apply to the select.
37
- */
38
- class?: string;
39
- /**
40
- * The name of the select. Required because of the helper.
41
- */
42
- name?: string;
43
- /**
44
- * Whether the select is required. Defaults to `false`.
45
- */
46
- isRequired?: boolean;
47
- /**
48
- * The options to display in the select.
49
- */
50
- options: Option[];
51
- /**
52
- * Whether the select is disabled. Defaults to `false`.
53
- */
54
- disabled?: boolean;
55
- /**
56
- * Whether the select is full width. Defaults to `false`.
57
- */
58
- fullWidth?: boolean;
59
- /**
60
- * The placeholder of the select. Defaults to `Select`.
61
- */
62
- placeholder?: string;
63
- }
64
-
65
- const {
66
- label,
67
- defaultValue,
68
- class: className,
69
- name = generateID('select'),
70
- isRequired,
71
- options = [],
72
- disabled,
73
- fullWidth,
74
- placeholder = 'Select',
75
- } = Astro.props;
76
- ---
77
-
78
- <div
79
- id={`${name}-container`}
80
- class="sui-select-label"
81
- class:list={[disabled && "disabled", className, fullWidth && "full"]}
82
- data-options={JSON.stringify(options)}
83
- data-id={name}
84
- >
85
- {label && (
86
- <label class="label" for={`${name}-select-btn`}>
87
- {label}
88
- <span class="req-star">{isRequired && "*"}</span>
89
- </label>
90
- )}
91
- <button
92
- class="sui-select-button"
93
- role="combobox"
94
- aria-controls={`${name}-dropdown`}
95
- aria-expanded="false"
96
- id={`${name}-select-btn`}
97
- type="button"
98
- aria-label={placeholder}
99
- title={placeholder}
100
- >
101
- <span class="sui-select-value-span" id={`${name}-value-span`}>
102
- {
103
- defaultValue
104
- ? options.find((x) => x.value === defaultValue)?.label
105
- : placeholder
106
- }
107
- </span>
108
- <Icon name="chevron-up-down" width={24} height={24} />
109
- </button>
110
- <ul class="sui-select-dropdown" role="listbox" id={`${name}-dropdown`}>
111
- {
112
- options.map((x, i) => (
113
- <li
114
- class="sui-select-option"
115
- role="option"
116
- value={x.value}
117
- class:list={[
118
- defaultValue === x.value && `selected`,
119
- x.disabled && "disabled",
120
- ]}
121
- id={defaultValue === x.value ? `${name}-selected` : ""}
122
- data-option-index={i}
123
- >
124
- {x.label}
125
- </li>
126
- ))
127
- }
128
- </ul>
129
- <select class="sui-hidden-select" id={name} name={name} required={isRequired} hidden tabindex="-1">
130
- <option value={""}> Select </option>
131
- {
132
- options.map((x) => (
133
- <option
134
- value={x.value}
135
- selected={defaultValue === x.value}
136
- disabled={x.disabled}
137
- >
138
- {x.label}
139
- </option>
140
- ))
141
- }
142
- </select>
143
- </div>
144
- <script>
145
- const allSelects = document.querySelectorAll<HTMLDivElement>(".sui-select-label");
146
- // id, options
147
-
148
- for (const container of allSelects) {
149
- const hiddenSelect = container.querySelector('select')!;
150
- const button = container.querySelector('button')!;
151
- const valueSpan = container.querySelector('.sui-select-value-span')!;
152
- const dropdown = container.querySelector('.sui-select-dropdown')!;
153
- const optionElements = container.querySelectorAll<HTMLLIElement>('.sui-select-option');
154
-
155
- const options = JSON.parse(container.dataset.options!);
156
- const id = container.dataset.id!;
157
- let active = false;
158
-
159
- const closeDropdown = () => {
160
- dropdown.classList.remove("active", "above");
161
- active = false;
162
- button.ariaExpanded = 'false';
163
- focusIndex = -1;
164
-
165
- for (const entry of optionElements) {
166
- entry.classList.remove('focused');
167
- }
168
- };
169
-
170
- const openDropdown = (toggle: boolean) => {
171
- const { bottom, left, right, width, x, y, height } =
172
- button.getBoundingClientRect();
173
-
174
- const optionHeight = 36;
175
- const totalBorderSize = 2;
176
- const margin = 4;
177
-
178
- const dropdownHeight =
179
- options.length * optionHeight + totalBorderSize + margin;
180
-
181
- const CustomRect = {
182
- top: bottom + margin,
183
- left,
184
- right,
185
- bottom: bottom + margin + dropdownHeight,
186
- width,
187
- height: dropdownHeight,
188
- x,
189
- y: y + height + margin,
190
- };
191
-
192
- if (active && toggle) {
193
- closeDropdown();
194
- return;
195
- }
196
-
197
- active = true;
198
- button.ariaExpanded = 'true';
199
-
200
- // Set focusIndex to currently selected option
201
- focusIndex = Array.from(optionElements).findIndex((x) =>
202
- x.classList.contains("selected")
203
- );
204
-
205
- if (
206
- CustomRect.top >= 0 &&
207
- CustomRect.left >= 0 &&
208
- CustomRect.bottom <=
209
- (window.innerHeight || document.documentElement.clientHeight) &&
210
- CustomRect.right <=
211
- (window.innerWidth || document.documentElement.clientWidth)
212
- ) {
213
- dropdown.classList.add("active");
214
- } else {
215
- dropdown.classList.add("active", "above");
216
- }
217
- }
218
-
219
- button.addEventListener("click", () => openDropdown(true));
220
-
221
- let focusIndex = -1;
222
-
223
- const recomputeOptions = () => {
224
- for (const entry of optionElements) {
225
- if (Number.parseInt(entry.dataset.optionIndex!) == focusIndex) {
226
- entry.classList.add('focused');
227
- } else {
228
- entry.classList.remove('focused');
229
- }
230
- }
231
- }
232
-
233
- button.addEventListener('keydown', (e) => {
234
- if (e.key === 'Tab' || e.key === 'Escape') {
235
- closeDropdown();
236
- return;
237
- }
238
-
239
- if (e.key === ' ' && !active) openDropdown(false);
240
-
241
- if (e.key === 'Enter') {
242
- let currentlyFocused = container.querySelector<HTMLElement>('.focused');
243
- if (currentlyFocused) {
244
- currentlyFocused.classList.remove('focused');
245
- currentlyFocused.click();
246
-
247
- // Stop dropdown from immediately reopening
248
- e.preventDefault();
249
- e.stopImmediatePropagation();
250
- }
251
-
252
- return;
253
- }
254
-
255
- e.preventDefault();
256
- e.stopImmediatePropagation();
257
-
258
- const neighbor = (offset: number) => {
259
- return optionElements.item((Array.from(optionElements).findIndex((x) => x.classList.contains("selected")) ?? -1) + offset)
260
- }
261
-
262
- if (e.key === "ArrowUp" && (focusIndex > 0 || !active)) {
263
- if (!active) return neighbor(-1)?.click();
264
- focusIndex--;
265
- recomputeOptions();
266
- }
267
-
268
- if (e.key === "ArrowDown" && focusIndex + 1 < optionElements.length) {
269
- if (!active) return neighbor(1)?.click();
270
- focusIndex++;
271
- recomputeOptions();
272
- }
273
-
274
- if (e.key === 'PageUp') {
275
- focusIndex = 0;
276
- if (!active) return optionElements.item(focusIndex)?.click();
277
- recomputeOptions();
278
- }
279
- if (e.key === 'PageDown') {
280
- focusIndex = optionElements.length - 1;
281
- if (!active) return optionElements.item(focusIndex)?.click();
282
- recomputeOptions();
283
- }
284
- });
285
-
286
- const handleSelection = (e: MouseEvent, option: HTMLElement) => {
287
- e.stopImmediatePropagation();
288
- if (option.id === `${id}-selected` || !id) return;
289
- const currentlySelected = document.getElementById(`${id}-selected`);
290
- if (currentlySelected) {
291
- currentlySelected.classList.remove("selected");
292
- currentlySelected.id = "";
293
- }
294
- option.id = `${id}-selected`;
295
- option.classList.add("selected");
296
- const opt = options[parseInt(option.dataset.optionIndex!)];
297
- hiddenSelect.value = opt.value;
298
- valueSpan.textContent = opt.label;
299
- closeDropdown();
300
- }
301
-
302
- optionElements.forEach((option) => {
303
- const handleSelectionForOption = (e: MouseEvent) => handleSelection(e, option)
304
-
305
- option.addEventListener("click", handleSelectionForOption);
306
- });
307
-
308
- window.addEventListener("scroll", closeDropdown);
309
-
310
- document.addEventListener("keydown", (e) => {
311
- if (e.key === "Escape" && dropdown.classList.contains("active")) {
312
- closeDropdown();
313
- }
314
- });
315
-
316
- hideOnClickOutside(container);
317
-
318
- function hideOnClickOutside(element: HTMLElement) {
319
- const outsideClickListener = (event: MouseEvent) => {
320
- if (
321
- !element.contains(event.target as HTMLElement) &&
322
- isVisible(element) &&
323
- active === true
324
- ) {
325
- // or use: event.target.closest(selector) === null
326
- closeDropdown();
327
- }
328
- };
329
-
330
- document.addEventListener("click", outsideClickListener);
331
- }
332
-
333
- // source (2018-03-11): https://github.com/jquery/jquery/blob/master/src/css/hiddenVisibleSelectors.js
334
- const isVisible = (elem: HTMLElement) =>
335
- !!elem &&
336
- !!(
337
- elem.offsetWidth ||
338
- elem.offsetHeight ||
339
- elem.getClientRects().length
340
- );
341
- }
342
- </script>
343
- <style>
344
- .sui-select-label {
345
- width: fit-content;
346
- display: flex;
347
- flex-direction: column;
348
- gap: 0.25rem;
349
- min-width: 200px;
350
- position: relative;
351
- height: fit-content;
352
- }
353
-
354
- .sui-select-label.full, .sui-select-label.full .sui-select-button {
355
- width: 100%;
356
- }
357
-
358
- .sui-select-label.disabled {
359
- opacity: 0.5;
360
- pointer-events: none;
361
- color: hsl(var(--text-muted));
362
- }
363
-
364
- .label {
365
- font-size: 14px;
366
- }
367
-
368
- .req-star {
369
- color: hsl(var(--danger-base));
370
- font-weight: 700;
371
- }
372
-
373
- .sui-select-button {
374
- padding: 0.5rem 0.75rem 0.5rem 1rem;
375
- border-radius: 8px;
376
- border: 1px solid hsl(var(--border));
377
- background: hsl(var(--background-step-2));
378
- color: hsl(var(--text-normal));
379
- transition: background border 0.15s ease;
380
- display: flex;
381
- flex-direction: row;
382
- align-items: center;
383
- justify-content: space-between;
384
- cursor: pointer;
385
- gap: 1rem;
386
- }
387
-
388
- .sui-select-button:focus {
389
- border: 1px solid hsl(var(--primary-base));
390
- }
391
-
392
- .sui-select-button:hover, .sui-select-button:focus {
393
- background: hsl(var(--background-step-3));
394
- }
395
-
396
- .sui-select-button.active,
397
- .sui-select-button:active,
398
- .sui-select-button:has(+ .sui-select-dropdown.active) {
399
- border: 1px solid hsl(var(--primary-base));
400
- background: hsl(var(--background-step-2));
401
- }
402
-
403
- .sui-select-dropdown {
404
- position: absolute;
405
- width: 100%;
406
- border: 1px solid hsl(var(--border));
407
- list-style: none;
408
- margin: 0;
409
- padding: 0;
410
- flex-direction: column;
411
- border-radius: 0.5rem;
412
- background-color: hsl(var(--background-step-2));
413
- overflow: hidden;
414
- top: calc(100% + 0.25rem);
415
- left: 0;
416
- display: none;
417
- z-index: 90;
418
- box-shadow: 0px 4px 8px hsl(var(--shadow), 0.5);
419
- }
420
-
421
- .sui-select-dropdown.active {
422
- display: flex;
423
- }
424
-
425
- .sui-select-dropdown.above {
426
- top: auto;
427
- bottom: calc(100% - 18px + 0.25rem);
428
- }
429
-
430
- .sui-select-option {
431
- padding: 0.5rem;
432
- cursor: pointer;
433
- font-size: 0.975em;
434
- transition: all 0.15s ease;
435
- }
436
-
437
- .sui-select-option.disabled {
438
- pointer-events: none;
439
- color: hsl(var(--text-muted));
440
- }
441
-
442
- .sui-select-option:hover, .sui-select-option:focus, .sui-select-option.focused {
443
- background-color: hsl(var(--background-step-3));
444
- }
445
-
446
- .sui-select-option:focus {
447
- outline: none;
448
- border: none;
449
- }
450
-
451
- .sui-select-option.selected {
452
- background-color: hsl(var(--primary-base));
453
- color: hsl(var(--text-inverted));
454
- cursor: default;
455
- }
456
-
457
- .sui-hidden-select {
458
- height: 0;
459
- width: 0;
460
- border: none;
461
- outline: none;
462
- position: absolute;
463
- background-color: transparent;
464
- pointer-events: none;
465
- opacity: 0;
466
- }
467
- </style>
@@ -1,179 +0,0 @@
1
- class SingleSidebarHelper {
2
- private sidebar: HTMLElement;
3
- private sidebarToggle?: HTMLElement | undefined;
4
-
5
- /**
6
- * A helper to manage the sidebar with.
7
- * @param toggleID The ID of the element that should toggle the sidebar.
8
- */
9
- constructor(toggleID?: string) {
10
- const sidebarContainer = document.getElementById('sui-sidebar');
11
-
12
- if (!sidebarContainer) {
13
- throw new Error(
14
- `No item with ID 'sui-sidebar' found. Please add the <Sidebar> component to this page.`
15
- );
16
- }
17
-
18
- this.sidebar = sidebarContainer;
19
-
20
- if (toggleID) {
21
- const navToggle = document.getElementById(toggleID);
22
-
23
- if (!navToggle) {
24
- throw new Error(`No item with ID ${toggleID} found.`);
25
- }
26
-
27
- this.sidebarToggle = navToggle;
28
-
29
- this.sidebarToggle.addEventListener('click', () => {
30
- this.sidebar.classList.toggle('active');
31
- });
32
- }
33
- }
34
-
35
- /**
36
- * A helper function register an element which should toggle the sidebar.
37
- * @param elementID The ID of the element that should toggle the sidebar.
38
- */
39
- public toggleSidebarOnClick = (elementID: string) => {
40
- const navToggle = document.getElementById(elementID);
41
-
42
- if (!navToggle) {
43
- throw new Error(`No item with ID ${elementID} found.`);
44
- }
45
-
46
- this.sidebarToggle = navToggle;
47
-
48
- this.sidebarToggle.addEventListener('click', () => {
49
- this.sidebar.classList.toggle('active');
50
- });
51
- };
52
-
53
- /**
54
- * A helper function to hide the sidebar when an element is clicked.
55
- * @param elementID The ID of the element that should hide the sidebar.
56
- */
57
- public hideSidebarOnClick = (elementID: string) => {
58
- const element = document.getElementById(elementID);
59
-
60
- if (!element) {
61
- throw new Error(`No item with ID ${elementID} found.`);
62
- }
63
-
64
- element.addEventListener('click', this.hideSidebar);
65
- };
66
-
67
- /**
68
- * A helper function to show the sidebar when an element is clicked.
69
- * @param elementID The ID of the element that should show the sidebar.
70
- */
71
- public showSidebarOnClick = (elementID: string) => {
72
- const element = document.getElementById(elementID);
73
-
74
- if (!element) {
75
- throw new Error(`No item with ID ${elementID} found.`);
76
- }
77
-
78
- element.addEventListener('click', this.showSidebar);
79
- };
80
-
81
- /**
82
- * A function to hide the sidebar.
83
- */
84
- public hideSidebar = () => {
85
- this.sidebar.classList.remove('active');
86
- };
87
-
88
- /**
89
- * A function to show the sidebar.
90
- */
91
- public showSidebar = () => {
92
- this.sidebar.classList.add('active');
93
- };
94
- }
95
-
96
- class DoubleSidebarHelper {
97
- private sidebarsContainer: HTMLElement;
98
-
99
- /**
100
- * A helper to manage the double sidebar with.
101
- */
102
- constructor() {
103
- const sidebarsContainer = document.getElementById('sui-sidebars');
104
-
105
- if (!sidebarsContainer) {
106
- throw new Error(
107
- `No item with ID 'sidebars' found. Please add the <DoubleSidebar> component to this page.`
108
- );
109
- }
110
-
111
- this.sidebarsContainer = sidebarsContainer;
112
- }
113
-
114
- /**
115
- * A helper function to hide the sidebar when an element is clicked.
116
- * @param elementID The ID of the element that should hide the sidebar.
117
- */
118
- public hideSidebarOnClick = (elementID: string) => {
119
- const element = document.getElementById(elementID);
120
-
121
- if (!element) {
122
- throw new Error(`No item with ID ${elementID} found.`);
123
- }
124
-
125
- element.addEventListener('click', this.hideSidebar);
126
- };
127
-
128
- /**
129
- * A helper function to show the outer sidebar when an element is clicked.
130
- * @param elementID The ID of the element that should show the outer sidebar.
131
- */
132
- public showOuterOnClick = (elementID: string) => {
133
- const element = document.getElementById(elementID);
134
-
135
- if (!element) {
136
- throw new Error(`No item with ID ${elementID} found.`);
137
- }
138
-
139
- element.addEventListener('click', this.showOuterSidebar);
140
- };
141
-
142
- /**
143
- * A helper function to show the inner sidebar when an element is clicked.
144
- * @param elementID The ID of the element that should show the inner sidebar.
145
- */
146
- public showInnerOnClick = (elementID: string) => {
147
- const element = document.getElementById(elementID);
148
-
149
- if (!element) {
150
- throw new Error(`No item with ID ${elementID} found.`);
151
- }
152
-
153
- element.addEventListener('click', this.showInnerSidebar);
154
- };
155
-
156
- /**
157
- * A function to show the inner sidebar.
158
- */
159
- public showInnerSidebar = () => {
160
- this.sidebarsContainer.classList.add('inner', 'active');
161
- };
162
-
163
- /**
164
- * A function to show the outer sidebar.
165
- */
166
- public showOuterSidebar = () => {
167
- this.sidebarsContainer.classList.add('active');
168
- this.sidebarsContainer.classList.remove('inner');
169
- };
170
-
171
- /**
172
- * A function to hide the sidebar altogether.
173
- */
174
- public hideSidebar = () => {
175
- this.sidebarsContainer.classList.remove('inner', 'active');
176
- };
177
- }
178
-
179
- export { SingleSidebarHelper, DoubleSidebarHelper };
@@ -1,3 +0,0 @@
1
- export { default as SingleSidebar } from './Single.astro';
2
- export { default as DoubleSidebar } from './Double.astro';
3
- export { SingleSidebarHelper, DoubleSidebarHelper } from './helpers';