@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
@@ -0,0 +1,69 @@
1
+ ---
2
+ import './toaster.css';
3
+
4
+ /**
5
+ * Props for the Toast component.
6
+ */
7
+ interface Props {
8
+ /**
9
+ * The position of the toaster. All toasts will originate from this position.
10
+ */
11
+ position?:
12
+ | 'top-left'
13
+ | 'top-right'
14
+ | 'top-center'
15
+ | 'bottom-left'
16
+ | 'bottom-right'
17
+ | 'bottom-center';
18
+ /**
19
+ * The duration of the toast in milliseconds. Defaults to 4000 (4 seconds).
20
+ */
21
+ duration?: number;
22
+ /**
23
+ * Whether the toast has a close button. Defaults to false.
24
+ */
25
+ closeButton?: boolean;
26
+ /**
27
+ * The offset of the toaster from the edge of the screen in pixels. Defaults to 32.
28
+ */
29
+ offset?: number;
30
+ /**
31
+ * The gap between toasts in pixels. Defaults to 8.
32
+ */
33
+ gap?: number;
34
+ }
35
+
36
+ const {
37
+ position = 'top-center',
38
+ duration = 4000,
39
+ closeButton = false,
40
+ offset = 32,
41
+ gap = 8,
42
+ } = Astro.props;
43
+ ---
44
+ <div
45
+ id="sui-toaster"
46
+ class:list={[
47
+ closeButton && "closeable",
48
+ position,
49
+ ]},
50
+ >
51
+ <div
52
+ id="sui-toast-drawer"
53
+ data-offset={offset}
54
+ data-gap={gap}
55
+ data-duration={duration}
56
+ style={[
57
+ `${position.includes("top-") ? 'top:' : 'bottom:'} ${offset}px;`,
58
+ position.includes("-left") && `left: ${offset}px`,
59
+ position.includes("-right") && `right: ${offset}px`,
60
+ position.includes("-center") && `left: 50%; transform: translateX(-50%);`,
61
+ `--gap: ${gap}px;`,
62
+ `padding-left: ${offset}px;`,
63
+ `padding-right: ${offset}px;`,
64
+ ].filter(Boolean).join("")}
65
+ />
66
+ </div>
67
+ <script>
68
+ import "studiocms:ui/scripts/toaster"
69
+ </script>
@@ -0,0 +1,8 @@
1
+ import type { ToastProps } from '../../types/index.js';
2
+ /**
3
+ * A function to create toasts with.
4
+
5
+ * @param props The props to pass to the toast
6
+ */
7
+ declare function toast(props: ToastProps): void;
8
+ export { toast };
@@ -0,0 +1,9 @@
1
+ function toast(props) {
2
+ const createToast = new CustomEvent("createtoast", {
3
+ detail: props
4
+ });
5
+ document.dispatchEvent(createToast);
6
+ }
7
+ export {
8
+ toast
9
+ };
@@ -0,0 +1,168 @@
1
+ #sui-toaster {
2
+ width: 100vw;
3
+ height: 100vh;
4
+ position: fixed;
5
+ top: 0;
6
+ left: 0;
7
+ z-index: 100;
8
+ pointer-events: none;
9
+ color: hsl(var(--text-normal));
10
+ }
11
+ #sui-toast-drawer {
12
+ max-width: 420px;
13
+ width: 100%;
14
+ height: fit-content;
15
+ position: absolute;
16
+ display: flex;
17
+ flex-direction: column;
18
+ }
19
+ #sui-toaster.top-left #sui-toast-drawer,
20
+ #sui-toaster.bottom-left #sui-toast-drawer {
21
+ left: 50%;
22
+ transform: translateX(-50%);
23
+ }
24
+ .sui-toast-container {
25
+ pointer-events: all;
26
+ padding: 1rem;
27
+ border-radius: var(--radius-md);
28
+ border: 1px solid hsl(var(--border));
29
+ background-color: hsl(var(--background-base));
30
+ box-shadow: 0px 4px 8px hsl(var(--shadow), 0.5);
31
+ display: flex;
32
+ flex-direction: column;
33
+ gap: .5rem;
34
+ position: relative;
35
+ overflow: hidden;
36
+ margin-bottom: var(--gap);
37
+ animation: toast-pop-in .25s ease forwards;
38
+ z-index: 90;
39
+ }
40
+ .sui-toast-header {
41
+ display: flex;
42
+ flex-direction: row;
43
+ align-items: center;
44
+ justify-content: space-between;
45
+ }
46
+ .sui-toast-header-left-side {
47
+ display: flex;
48
+ flex-direction: row;
49
+ gap: .5rem;
50
+ align-items: center;
51
+ font-weight: 500;
52
+ font-size: 1.125em;
53
+ }
54
+ .sui-toast-header-left-side svg {
55
+ color: hsl(var(--primary-base));
56
+ }
57
+ .sui-toast-container.success .sui-toast-header-left-side svg {
58
+ color: hsl(var(--success-base));
59
+ }
60
+ .sui-toast-container.warning .sui-toast-header-left-side svg {
61
+ color: hsl(var(--warning-base));
62
+ }
63
+ .sui-toast-container.danger .sui-toast-header-left-side svg {
64
+ color: hsl(var(--danger-base));
65
+ }
66
+ .sui-toast-container.info .sui-toast-header-left-side svg {
67
+ color: hsl(var(--info-base));
68
+ }
69
+ .sui-toast-container.mono .sui-toast-header-left-side svg {
70
+ color: hsl(var(--mono-base));
71
+ }
72
+ .sui-toast-progress-bar {
73
+ position: absolute;
74
+ height: 4px;
75
+ width: 100%;
76
+ bottom: 0;
77
+ left: 0%;
78
+ background-color: hsl(var(--primary-base));
79
+ animation: toast-progress forwards linear;
80
+ }
81
+ .sui-toast-container.paused .sui-toast-progress-bar {
82
+ animation-play-state: paused;
83
+ }
84
+ .sui-toast-container.success .sui-toast-progress-bar {
85
+ background-color: hsl(var(--success-base));
86
+ }
87
+ .sui-toast-container.warning .sui-toast-progress-bar {
88
+ background-color: hsl(var(--warning-base));
89
+ }
90
+ .sui-toast-container.danger .sui-toast-progress-bar {
91
+ background-color: hsl(var(--danger-base));
92
+ }
93
+ .close-icon-container {
94
+ cursor: pointer;
95
+ height: 1.5rem;
96
+ width: 1.5rem;
97
+ display: flex;
98
+ align-items: center;
99
+ justify-content: center;
100
+ transition: background-color .15s ease;
101
+ border-radius: var(--radius-sm);
102
+ }
103
+ .close-icon-container:hover {
104
+ background-color: hsl(var(--default-base));
105
+ }
106
+ .close-icon-container:focus-visible {
107
+ outline: 2px solid hsl(var(--text-normal));
108
+ outline-offset: 2px;
109
+ }
110
+ .sui-toast-container.closing {
111
+ animation: toast-closing .25s ease forwards;
112
+ }
113
+ .sui-toast-container.persistent {
114
+ border: 1px solid hsl(var(--primary-base));
115
+ }
116
+ .sui-toast-container.persistent.success {
117
+ border: 1px solid hsl(var(--success-base));
118
+ }
119
+ .sui-toast-container.persistent.warning {
120
+ border: 1px solid hsl(var(--warning-base));
121
+ }
122
+ .sui-toast-container.persistent.danger {
123
+ border: 1px solid hsl(var(--danger-base));
124
+ }
125
+ @keyframes toast-pop-in {
126
+ 0% {
127
+ opacity: 0;
128
+ scale: 0.75;
129
+ }
130
+ 100% {
131
+ opacity: 1;
132
+ scale: 1;
133
+ }
134
+ }
135
+ @keyframes toast-closing {
136
+ 0% {
137
+ opacity: 1;
138
+ scale: 1;
139
+ max-height: 500px;
140
+ margin-bottom: var(--gap);
141
+ padding: 1rem;
142
+ border: 1px solid hsl(var(--border));
143
+ }
144
+ 62.5% {
145
+ scale: 0.75;
146
+ opacity: 0;
147
+ max-height: 500px;
148
+ margin-bottom: var(--gap);
149
+ padding: 1rem;
150
+ border: 1px solid hsl(var(--border));
151
+ }
152
+ 100% {
153
+ scale: 0.75;
154
+ opacity: 0;
155
+ max-height: 0px;
156
+ margin-bottom: 0;
157
+ padding: 0;
158
+ border: 0px solid hsl(var(--border));
159
+ }
160
+ }
161
+ @keyframes toast-progress {
162
+ 0% {
163
+ left: 0%;
164
+ }
165
+ 100% {
166
+ left: -100%;
167
+ }
168
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,160 @@
1
+ import { generateID } from "../../utils/generateID.js";
2
+ import { getIconString } from "../../utils/iconStrings.js";
3
+ let activeToasts = [];
4
+ let lastActiveElement = null;
5
+ const revertFocusBackToLastActiveElement = () => {
6
+ if (lastActiveElement) {
7
+ lastActiveElement.focus();
8
+ lastActiveElement = null;
9
+ }
10
+ };
11
+ class Timer {
12
+ id;
13
+ started;
14
+ remaining;
15
+ running;
16
+ callback;
17
+ constructor(callback, delay) {
18
+ this.id = null;
19
+ this.started = null;
20
+ this.remaining = delay;
21
+ this.running = false;
22
+ this.callback = callback;
23
+ this.start();
24
+ }
25
+ start = () => {
26
+ this.running = true;
27
+ this.started = /* @__PURE__ */ new Date();
28
+ this.id = setTimeout(this.callback, this.remaining);
29
+ };
30
+ pause = () => {
31
+ if (!this.id || !this.started || !this.running) return;
32
+ this.running = false;
33
+ clearTimeout(this.id);
34
+ this.remaining -= (/* @__PURE__ */ new Date()).getTime() - this.started.getTime();
35
+ };
36
+ getTimeLeft = () => {
37
+ if (this.running) {
38
+ this.pause();
39
+ this.start();
40
+ }
41
+ return this.remaining;
42
+ };
43
+ getStateRunning = () => {
44
+ return this.running;
45
+ };
46
+ }
47
+ function removeToast(toastID) {
48
+ const toastEl = document.getElementById(toastID);
49
+ if (!toastEl) return;
50
+ activeToasts = activeToasts.filter((x) => x !== toastID);
51
+ toastEl.classList.add("closing");
52
+ setTimeout(() => toastEl.remove(), 400);
53
+ }
54
+ function createToast(props) {
55
+ const toastParent = document.getElementById("sui-toast-drawer");
56
+ const toastContainer = document.createElement("div");
57
+ const toastID = generateID("toast");
58
+ toastContainer.tabIndex = 0;
59
+ toastContainer.ariaLive = "polite";
60
+ toastContainer.role = "alert";
61
+ toastContainer.id = toastID;
62
+ toastContainer.ariaLabel = `${props.title} (F8)`;
63
+ toastContainer.classList.add(
64
+ "sui-toast-container",
65
+ `${props.closeButton || props.persistent && "closeable"}`,
66
+ `${props.persistent && "persistent"}`
67
+ );
68
+ const toastHeader = document.createElement("div");
69
+ toastHeader.classList.add("sui-toast-header");
70
+ const toastHeaderLeftSide = document.createElement("div");
71
+ toastHeaderLeftSide.classList.add("sui-toast-header-left-side");
72
+ const toastTitle = document.createElement("span");
73
+ toastTitle.textContent = props.title;
74
+ toastTitle.classList.add("sui-toast-title");
75
+ let iconString;
76
+ if (props.type === "success") {
77
+ iconString = "check-circle";
78
+ } else if (props.type === "danger") {
79
+ iconString = "exclamation-circle";
80
+ } else if (props.type === "warning") {
81
+ iconString = "exclamation-triangle";
82
+ } else {
83
+ iconString = "information-circle";
84
+ }
85
+ const toastIcon = getIconString(iconString, "toast-icon", 24, 24);
86
+ toastHeaderLeftSide.innerHTML = toastIcon;
87
+ toastHeaderLeftSide.appendChild(toastTitle);
88
+ toastHeader.appendChild(toastHeaderLeftSide);
89
+ if (props.closeButton || props.persistent) {
90
+ const closeIconContainer = document.createElement("button");
91
+ closeIconContainer.classList.add("close-icon-container");
92
+ closeIconContainer.addEventListener("click", () => removeToast(toastID));
93
+ closeIconContainer.innerHTML = getIconString("x-mark", "close-icon", 24, 24);
94
+ closeIconContainer.tabIndex = 0;
95
+ closeIconContainer.ariaLabel = "Close toast";
96
+ toastHeader.appendChild(closeIconContainer);
97
+ }
98
+ toastContainer.appendChild(toastHeader);
99
+ if (props.description) {
100
+ const toastDesc = document.createElement("span");
101
+ toastDesc.innerHTML = props.description;
102
+ toastDesc.classList.add("sui-toast-desc");
103
+ toastContainer.appendChild(toastDesc);
104
+ }
105
+ if (!props.persistent) {
106
+ const toastProgressBar = document.createElement("div");
107
+ toastProgressBar.classList.add("sui-toast-progress-bar");
108
+ toastProgressBar.style.animationDuration = props.duration ? `${props.duration}ms` : `${toastParent.dataset.duration || 4e3}ms`;
109
+ toastContainer.appendChild(toastProgressBar);
110
+ }
111
+ toastParent.appendChild(toastContainer);
112
+ activeToasts.push(toastID);
113
+ if (!props.persistent) {
114
+ const timer = new Timer(
115
+ () => removeToast(toastID),
116
+ props.duration || (toastParent.dataset.duration ? Number.parseInt(toastParent.dataset.duration) : 4e3)
117
+ );
118
+ const timerPauseWrapper = () => {
119
+ toastContainer.classList.add("paused");
120
+ timer.pause();
121
+ };
122
+ const timerStartWrapper = () => {
123
+ toastContainer.classList.remove("paused");
124
+ timer.start();
125
+ };
126
+ toastContainer.addEventListener("mouseenter", timerPauseWrapper);
127
+ toastContainer.addEventListener("focusin", timerPauseWrapper);
128
+ toastContainer.addEventListener("mouseleave", timerStartWrapper);
129
+ toastContainer.addEventListener("focusout", () => {
130
+ const focusedOrHasFocused = toastContainer.matches(":focus-within");
131
+ if (!focusedOrHasFocused) {
132
+ revertFocusBackToLastActiveElement();
133
+ }
134
+ timerStartWrapper();
135
+ });
136
+ }
137
+ toastContainer.addEventListener("keydown", (e) => {
138
+ if (e.key === "Escape") {
139
+ e.preventDefault();
140
+ removeToast(toastID);
141
+ revertFocusBackToLastActiveElement();
142
+ }
143
+ });
144
+ }
145
+ document.addEventListener("createtoast", (e) => {
146
+ e.stopImmediatePropagation();
147
+ const event = e;
148
+ createToast(event.detail);
149
+ });
150
+ window.addEventListener("keydown", (e) => {
151
+ if (e.key === "F8") {
152
+ e.preventDefault();
153
+ const oldestToast = activeToasts[0];
154
+ if (oldestToast) {
155
+ lastActiveElement = document.activeElement;
156
+ const toastEl = document.getElementById(oldestToast);
157
+ if (toastEl) toastEl?.focus();
158
+ }
159
+ }
160
+ });
@@ -0,0 +1,84 @@
1
+ ---
2
+ import type { StudioCMSColorway } from '../../utils/colors.js';
3
+ import { generateID } from '../../utils/generateID.js';
4
+ import './toggle.css';
5
+
6
+ /**
7
+ * The props for the toggle component
8
+ */
9
+ interface Props {
10
+ /**
11
+ * The label of the toggle.
12
+ */
13
+ label: string;
14
+ /**
15
+ * The size of the toggle. Defaults to `md`.
16
+ */
17
+ size?: 'sm' | 'md' | 'lg';
18
+ /**
19
+ * The color of the toggle. Defaults to `default`.
20
+ */
21
+ color?: StudioCMSColorway;
22
+ /**
23
+ * Whether the toggle is checked by default. Defaults to `false`.
24
+ */
25
+ defaultChecked?: boolean;
26
+ /**
27
+ * Whether the toggle is disabled. Defaults to `false`.
28
+ */
29
+ disabled?: boolean;
30
+ /**
31
+ * The name of the toggle.
32
+ */
33
+ name?: string;
34
+ /**
35
+ * Whether the toggle is required. Defaults to `false`.
36
+ */
37
+ isRequired?: boolean;
38
+ }
39
+
40
+ const {
41
+ size = 'md',
42
+ color = 'default',
43
+ defaultChecked,
44
+ disabled,
45
+ name = generateID('checkbox'),
46
+ label,
47
+ isRequired,
48
+ } = Astro.props;
49
+ ---
50
+ <label
51
+ class="sui-toggle-label"
52
+ for={name}
53
+ class:list={[
54
+ disabled && "disabled",
55
+ color,
56
+ size,
57
+ ]}
58
+ >
59
+ <div class="sui-toggle-container">
60
+ <div
61
+ class="sui-toggle-switch"
62
+ tabindex="0"
63
+ role="checkbox"
64
+ aria-checked={defaultChecked}
65
+ aria-label={label}
66
+ />
67
+ <input
68
+ type="checkbox"
69
+ name={name}
70
+ id={name}
71
+ checked={defaultChecked}
72
+ disabled={disabled}
73
+ required={isRequired}
74
+ class="sui-toggle-checkbox"
75
+ hidden
76
+ />
77
+ </div>
78
+ <span id={`label-${name}`}>
79
+ {label} <span class="req-star">{isRequired && "*"}</span>
80
+ </span>
81
+ </label>
82
+ <script>
83
+ import "studiocms:ui/scripts/toggle"
84
+ </script>
@@ -0,0 +1,93 @@
1
+ .sui-toggle-label {
2
+ display: flex;
3
+ flex-direction: row;
4
+ align-items: center;
5
+ gap: .5rem;
6
+ position: relative;
7
+ margin: .25rem 0;
8
+ }
9
+ .sui-toggle-label.disabled {
10
+ opacity: 0.5;
11
+ pointer-events: none;
12
+ color: hsl(var(--text-muted));
13
+ }
14
+ .sui-toggle-label:active .sui-toggle-switch {
15
+ transform: scale(0.85);
16
+ }
17
+ .sui-toggle-container {
18
+ --toggle-height: 12px;
19
+ --toggle-width: 40px;
20
+ display: flex;
21
+ align-items: center;
22
+ cursor: pointer;
23
+ transition: all .15s ease;
24
+ background-color: hsl(var(--default-base));
25
+ width: var(--toggle-width);
26
+ height: var(--toggle-height);
27
+ border-radius: var(--radius-full);
28
+ }
29
+ .sui-toggle-switch {
30
+ --switch: calc(var(--toggle-height) * 1.75);
31
+ height: var(--switch);
32
+ width: var(--switch);
33
+ background-color: hsl(var(--text-muted));
34
+ border-radius: var(--radius-full);
35
+ position: relative;
36
+ left: 0;
37
+ transition: all .15s ease;
38
+ will-change: transform;
39
+ }
40
+ .sui-toggle-switch:focus-visible {
41
+ outline: 2px solid hsl(var(--text-normal));
42
+ outline-offset: 2px;
43
+ }
44
+ .sui-toggle-container:has(.sui-toggle-checkbox:checked) .sui-toggle-switch {
45
+ left: calc(100% - var(--switch));
46
+ background-color: hsl(var(--text-normal));
47
+ }
48
+ .sui-toggle-label.sm .sui-toggle-container {
49
+ --toggle-height: 10px;
50
+ --toggle-width: 32px;
51
+ }
52
+ .sui-toggle-label.sm .sui-toggle-switch {
53
+ --switch: calc(var(--toggle-height) * 1.65);
54
+ }
55
+ .sui-toggle-label.lg .sui-toggle-container {
56
+ --toggle-height: 16px;
57
+ --toggle-width: 48px;
58
+ }
59
+ .sui-toggle-label.lg .sui-toggle-switch {
60
+ --switch: calc(var(--toggle-height) * 1.65);
61
+ }
62
+ .sui-toggle-label.primary .sui-toggle-container:has(.sui-toggle-checkbox:checked) {
63
+ background-color: hsl(var(--primary-base));
64
+ }
65
+ .sui-toggle-label.success .sui-toggle-container:has(.sui-toggle-checkbox:checked) {
66
+ background-color: hsl(var(--success-base));
67
+ }
68
+ .sui-toggle-label.warning .sui-toggle-container:has(.sui-toggle-checkbox:checked) {
69
+ background-color: hsl(var(--warning-base));
70
+ }
71
+ .sui-toggle-label.danger .sui-toggle-container:has(.sui-toggle-checkbox:checked) {
72
+ background-color: hsl(var(--danger-base));
73
+ }
74
+ .sui-toggle-label.info .sui-toggle-container:has(.sui-toggle-checkbox:checked) {
75
+ background-color: hsl(var(--info-base));
76
+ }
77
+ .sui-toggle-label.mono .sui-toggle-container:has(.sui-toggle-checkbox:checked) {
78
+ background-color: hsl(var(--mono-base));
79
+ }
80
+ .sui-toggle-label.mono .sui-toggle-switch {
81
+ border: 1px solid hsl(var(--text-inverted));
82
+ }
83
+ .req-star {
84
+ color: hsl(var(--danger-base));
85
+ font-weight: 700;
86
+ }
87
+ .sui-toggle-checkbox {
88
+ width: 0;
89
+ height: 0;
90
+ visibility: hidden;
91
+ opacity: 0;
92
+ margin: 0;
93
+ }
@@ -0,0 +1,2 @@
1
+ declare const allToggleElements: NodeListOf<HTMLDivElement>;
2
+ declare const allToggles: NodeListOf<HTMLInputElement>;
@@ -0,0 +1,20 @@
1
+ const allToggleElements = document.querySelectorAll(".sui-toggle-container");
2
+ const allToggles = document.querySelectorAll(".sui-toggle-checkbox");
3
+ for (const element of allToggleElements) {
4
+ if (element.dataset.initialized) continue;
5
+ element.dataset.initialized = "true";
6
+ element.addEventListener("keydown", (e) => {
7
+ if (e.key !== "Enter" && e.key !== " ") return;
8
+ e.preventDefault();
9
+ const checkbox = element.querySelector(".sui-toggle-checkbox");
10
+ if (!checkbox) return;
11
+ checkbox.click();
12
+ });
13
+ }
14
+ for (const box of allToggles) {
15
+ if (box.dataset.initialized) continue;
16
+ box.dataset.initialized = "true";
17
+ box.addEventListener("change", (e) => {
18
+ box.previousSibling.ariaChecked = e.target.checked ? "true" : "false";
19
+ });
20
+ }
@@ -1,6 +1,8 @@
1
1
  ---
2
+ // @ts-ignore
2
3
  import { Image } from 'astro:assets';
3
- import Icon from '../utils/Icon.astro';
4
+ import Icon from '../Icon/Icon.astro';
5
+ import './user.css';
4
6
 
5
7
  /**
6
8
  * The props for the User component.
@@ -43,45 +45,3 @@ const { name, description, avatar, class: className, loading = 'lazy' } = Astro.
43
45
  <span class="sui-description">{description}</span>
44
46
  </div>
45
47
  </div>
46
- <style>
47
- .sui-user-container {
48
- display: flex;
49
- flex-direction: row;
50
- align-items: center;
51
- gap: 1rem;
52
- }
53
-
54
- .sui-avatar-container {
55
- width: 2.5rem;
56
- height: 2.5rem;
57
- background-color: hsl(var(--default-base));
58
- border-radius: 3rem;
59
- display: flex;
60
- align-items: center;
61
- justify-content: center;
62
- overflow: hidden;
63
- border: 1px solid hsl(var(--border));
64
- }
65
-
66
- .sui-avatar-img {
67
- width: 100%;
68
- height: auto;
69
- }
70
-
71
- .sui-text-content {
72
- display: flex;
73
- flex-direction: column;
74
- gap: .125rem;
75
- }
76
-
77
- .sui-name {
78
- font-size: 1em;
79
- font-weight: 600;
80
- }
81
-
82
- .sui-description {
83
- font-size: .875em;
84
- font-weight: 400;
85
- color: hsl(var(--text-muted));
86
- }
87
- </style>