@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.
- package/dist/components/Accordion/Accordion.astro +23 -0
- package/dist/components/Accordion/Item.astro +21 -0
- package/dist/components/Accordion/accordion.css +64 -0
- package/dist/components/Accordion/accordion.d.ts +1 -0
- package/dist/components/Accordion/accordion.js +70 -0
- package/dist/components/Badge/Badge.astro +49 -0
- package/dist/components/Badge/badge.css +111 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.astro +31 -0
- package/dist/components/Breadcrumbs/breadcrumbs.css +15 -0
- package/dist/components/Button/Button.astro +75 -0
- package/dist/components/Button/button.css +292 -0
- package/{src/components → dist/components/Card}/Card.astro +1 -48
- package/dist/components/Card/card.css +38 -0
- package/dist/components/Center/Center.astro +7 -0
- package/dist/components/Center/center.css +8 -0
- package/dist/components/Checkbox/Checkbox.astro +95 -0
- package/dist/components/Checkbox/checkbox.css +119 -0
- package/dist/components/Checkbox/checkbox.d.ts +2 -0
- package/dist/components/Checkbox/checkbox.js +20 -0
- package/{src/components → dist/components/Divider}/Divider.astro +2 -25
- package/dist/components/Divider/divider.css +21 -0
- package/dist/components/Dropdown/Dropdown.astro +116 -0
- package/dist/components/Dropdown/dropdown.css +180 -0
- package/dist/components/Dropdown/dropdown.d.ts +48 -0
- package/dist/components/Dropdown/dropdown.js +201 -0
- package/dist/components/Footer/Footer.astro +58 -0
- package/dist/components/Footer/footer.css +68 -0
- package/dist/components/Group/Group.astro +7 -0
- package/dist/components/Group/group.css +19 -0
- package/{src/utils → dist/components/Icon}/Icon.astro +1 -1
- package/{src/utils/iconType.ts → dist/components/Icon/iconType.d.ts} +0 -1
- package/dist/components/Icon/iconType.js +0 -0
- package/{src/components → dist/components/Input}/Input.astro +2 -48
- package/dist/components/Input/input.css +38 -0
- package/{src → dist}/components/Modal/Modal.astro +4 -122
- package/dist/components/Modal/modal.css +100 -0
- package/dist/components/Modal/modal.d.ts +48 -0
- package/dist/components/Modal/modal.js +129 -0
- package/dist/components/Progress/Progress.astro +21 -0
- package/dist/components/Progress/helper.d.ts +13 -0
- package/dist/components/Progress/helper.js +32 -0
- package/dist/components/Progress/progress.css +29 -0
- package/dist/components/Progress/progress.d.ts +1 -0
- package/dist/components/Progress/progress.js +10 -0
- package/dist/components/RadioGroup/RadioGroup.astro +124 -0
- package/dist/components/RadioGroup/radiogroup.css +96 -0
- package/dist/components/RadioGroup/radiogroup.d.ts +1 -0
- package/dist/components/RadioGroup/radiogroup.js +48 -0
- package/{src/components → dist/components/Row}/Row.astro +1 -24
- package/dist/components/Row/row.css +18 -0
- package/dist/components/SearchSelect/SearchSelect.astro +135 -0
- package/dist/components/SearchSelect/searchselect.css +95 -0
- package/dist/components/SearchSelect/searchselect.d.ts +6 -0
- package/dist/components/SearchSelect/searchselect.js +166 -0
- package/dist/components/Select/Select.astro +147 -0
- package/dist/components/Select/select.css +110 -0
- package/dist/components/Select/select.d.ts +1 -0
- package/dist/components/Select/select.js +143 -0
- package/dist/components/Sidebar/helpers.d.ts +76 -0
- package/dist/components/Sidebar/helpers.js +160 -0
- package/{src → dist}/components/Tabs/TabItem.astro +3 -3
- package/dist/components/Tabs/Tabs.astro +150 -0
- package/dist/components/Tabs/tabs.css +121 -0
- package/dist/components/Tabs/tabs.d.ts +1 -0
- package/dist/components/Tabs/tabs.js +82 -0
- package/{src/components → dist/components/Textarea}/Textarea.astro +2 -61
- package/dist/components/Textarea/textarea.css +49 -0
- package/dist/components/ThemeToggle/ThemeToggle.astro +21 -0
- package/dist/components/ThemeToggle/themetoggle.css +17 -0
- package/dist/components/ThemeToggle/themetoggle.d.ts +1 -0
- package/dist/components/ThemeToggle/themetoggle.js +4 -0
- package/dist/components/Toast/Toaster.astro +69 -0
- package/dist/components/Toast/toast.d.ts +8 -0
- package/dist/components/Toast/toast.js +9 -0
- package/dist/components/Toast/toaster.css +168 -0
- package/dist/components/Toast/toaster.d.ts +1 -0
- package/dist/components/Toast/toaster.js +160 -0
- package/dist/components/Toggle/Toggle.astro +84 -0
- package/dist/components/Toggle/toggle.css +93 -0
- package/dist/components/Toggle/toggle.d.ts +2 -0
- package/dist/components/Toggle/toggle.js +20 -0
- package/{src/components → dist/components/User}/User.astro +3 -43
- package/dist/components/User/user.css +35 -0
- package/dist/css/colors.css +95 -0
- package/dist/css/global.css +3 -0
- package/dist/css/radii.css +6 -0
- package/dist/css/resets.css +46 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +379 -0
- package/dist/toolbar/ColorPicker.d.ts +7 -0
- package/dist/toolbar/ColorPicker.js +85 -0
- package/dist/toolbar/icon.d.ts +1 -0
- package/dist/toolbar/icon.js +4 -0
- package/dist/toolbar/index.d.ts +2 -0
- package/dist/toolbar/index.js +292 -0
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.js +0 -0
- package/dist/utils/ThemeHelper.d.ts +49 -0
- package/dist/utils/ThemeHelper.js +113 -0
- package/{src/utils/colors.ts → dist/utils/colors.d.ts} +1 -1
- package/dist/utils/colors.js +0 -0
- package/dist/utils/generateID.d.ts +2 -0
- package/dist/utils/generateID.js +6 -0
- package/dist/utils/headers.d.ts +43 -0
- package/dist/utils/headers.js +129 -0
- package/dist/utils/iconStrings.d.ts +4 -0
- package/dist/utils/iconStrings.js +13 -0
- package/dist/utils/integration-utils.d.ts +130 -0
- package/dist/utils/integration-utils.js +161 -0
- package/package.json +25 -9
- package/src/components/BaseHead.astro +0 -22
- package/src/components/Button.astro +0 -372
- package/src/components/Center.astro +0 -16
- package/src/components/Checkbox.astro +0 -250
- package/src/components/Dropdown/Dropdown.astro +0 -314
- package/src/components/Dropdown/dropdown.ts +0 -258
- package/src/components/Dropdown/index.ts +0 -2
- package/src/components/Footer.astro +0 -137
- package/src/components/Modal/index.ts +0 -2
- package/src/components/Modal/modal.ts +0 -163
- package/src/components/RadioGroup.astro +0 -299
- package/src/components/SearchSelect.astro +0 -486
- package/src/components/Select.astro +0 -467
- package/src/components/Sidebar/helpers.ts +0 -179
- package/src/components/Sidebar/index.ts +0 -3
- package/src/components/Tabs/Tabs.astro +0 -393
- package/src/components/Tabs/index.ts +0 -2
- package/src/components/ThemeToggle.astro +0 -46
- package/src/components/Toast/Toaster.astro +0 -470
- package/src/components/Toast/index.ts +0 -2
- package/src/components/Toast/toast.ts +0 -16
- package/src/components/Toggle.astro +0 -214
- package/src/components/index.ts +0 -27
- package/src/components.ts +0 -26
- package/src/css/colors.css +0 -106
- package/src/css/global.css +0 -2
- package/src/css/resets.css +0 -54
- package/src/env.d.ts +0 -15
- package/src/integration.ts +0 -31
- package/src/layouts/RootLayout.astro +0 -33
- package/src/layouts/index.ts +0 -2
- package/src/layouts.ts +0 -1
- package/src/types/index.ts +0 -11
- package/src/utils/ThemeHelper.ts +0 -145
- package/src/utils/create-resolver.ts +0 -30
- package/src/utils/generateID.ts +0 -5
- package/src/utils/headers.ts +0 -190
- package/src/utils/iconStrings.ts +0 -29
- package/src/utils/index.ts +0 -1
- package/src/utils/virtual-module-plugin-builder.ts +0 -37
- /package/{src → dist}/components/Sidebar/Double.astro +0 -0
- /package/{src → dist}/components/Sidebar/Single.astro +0 -0
- /package/{src → dist}/icons/Checkmark.astro +0 -0
- /package/{src → dist}/icons/ChevronUpDown.astro +0 -0
- /package/{src → dist}/icons/User.astro +0 -0
- /package/{src → dist}/icons/X-Mark.astro +0 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
---
|
|
2
|
+
import type { StudioCMSColorway } from '../../utils/colors.js';
|
|
3
|
+
import { generateID } from '../../utils/generateID.js';
|
|
4
|
+
import './radiogroup.css';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The props for the RadioGroup component.
|
|
8
|
+
*/
|
|
9
|
+
interface Option {
|
|
10
|
+
/**
|
|
11
|
+
* The label of the option.
|
|
12
|
+
*/
|
|
13
|
+
label: string;
|
|
14
|
+
/**
|
|
15
|
+
* The value of the option.
|
|
16
|
+
*/
|
|
17
|
+
value: string;
|
|
18
|
+
/**
|
|
19
|
+
* Whether the option is disabled.
|
|
20
|
+
*/
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The props for the RadioGroup component.
|
|
26
|
+
*/
|
|
27
|
+
interface Props {
|
|
28
|
+
/**
|
|
29
|
+
* The label of the radio group.
|
|
30
|
+
*/
|
|
31
|
+
label: string;
|
|
32
|
+
/**
|
|
33
|
+
* The color of the radio group. Defaults to `default`.
|
|
34
|
+
*/
|
|
35
|
+
color?: Omit<StudioCMSColorway, 'default'>;
|
|
36
|
+
/**
|
|
37
|
+
* The default value of the radio group. Needs to be one of the values in the options.
|
|
38
|
+
*/
|
|
39
|
+
defaultValue?: string;
|
|
40
|
+
/**
|
|
41
|
+
* The options to display in the radio group.
|
|
42
|
+
*/
|
|
43
|
+
options: Option[];
|
|
44
|
+
/**
|
|
45
|
+
* Whether the radio group is disabled. Defaults to `false`.
|
|
46
|
+
*/
|
|
47
|
+
disabled?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* The name of the radio group.
|
|
50
|
+
*/
|
|
51
|
+
name?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Whether the radio group is required. Defaults to `false`.
|
|
54
|
+
*/
|
|
55
|
+
isRequired?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Whether the radio group is horizontal. Defaults to `false`.
|
|
58
|
+
*/
|
|
59
|
+
horizontal?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Additional classes to apply to the radio group.
|
|
62
|
+
*/
|
|
63
|
+
class?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const {
|
|
67
|
+
label,
|
|
68
|
+
color = 'primary',
|
|
69
|
+
defaultValue,
|
|
70
|
+
options,
|
|
71
|
+
disabled = false,
|
|
72
|
+
isRequired = false,
|
|
73
|
+
horizontal = false,
|
|
74
|
+
name = generateID('radio'),
|
|
75
|
+
class: className,
|
|
76
|
+
} = Astro.props;
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
<div
|
|
80
|
+
class="sui-radio-container"
|
|
81
|
+
class:list={[
|
|
82
|
+
disabled && "disabled",
|
|
83
|
+
horizontal && "horizontal",
|
|
84
|
+
color,
|
|
85
|
+
className
|
|
86
|
+
]}
|
|
87
|
+
>
|
|
88
|
+
<span>
|
|
89
|
+
{label} <span class="req-star">{isRequired && "*"}</span>
|
|
90
|
+
</span>
|
|
91
|
+
<div class="sui-radio-inputs" role="radiogroup">
|
|
92
|
+
{options.map(({ label, value, disabled: individuallyDisabled }, i) => (
|
|
93
|
+
<label
|
|
94
|
+
for={value}
|
|
95
|
+
class="sui-radio-label"
|
|
96
|
+
class:list={[ individuallyDisabled && "disabled" ]}
|
|
97
|
+
>
|
|
98
|
+
<div class="sui-radio-box-container">
|
|
99
|
+
<div
|
|
100
|
+
class="sui-radio-box"
|
|
101
|
+
role="radio"
|
|
102
|
+
tabindex={i === 0 ? 0 : -1}
|
|
103
|
+
aria-checked={value === defaultValue}
|
|
104
|
+
aria-label={label}
|
|
105
|
+
/>
|
|
106
|
+
</div>
|
|
107
|
+
<input
|
|
108
|
+
class="sui-radio-toggle"
|
|
109
|
+
type="radio"
|
|
110
|
+
value={value}
|
|
111
|
+
id={value}
|
|
112
|
+
name={name}
|
|
113
|
+
checked={value === defaultValue}
|
|
114
|
+
disabled={disabled || individuallyDisabled}
|
|
115
|
+
required={isRequired}
|
|
116
|
+
/>
|
|
117
|
+
<span>{label}</span>
|
|
118
|
+
</label>
|
|
119
|
+
))}
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
<script>
|
|
123
|
+
import 'studiocms:ui/scripts/radiogroup'
|
|
124
|
+
</script>
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
.sui-radio-container {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: .5rem;
|
|
5
|
+
}
|
|
6
|
+
.sui-radio-container.disabled {
|
|
7
|
+
opacity: 0.5;
|
|
8
|
+
color: hsl(var(--text-muted));
|
|
9
|
+
}
|
|
10
|
+
.sui-radio-label.disabled {
|
|
11
|
+
opacity: 0.5;
|
|
12
|
+
color: hsl(var(--text-muted));
|
|
13
|
+
pointer-events: none;
|
|
14
|
+
}
|
|
15
|
+
.req-star {
|
|
16
|
+
color: hsl(var(--danger-base));
|
|
17
|
+
font-weight: 700;
|
|
18
|
+
}
|
|
19
|
+
.sui-radio-inputs {
|
|
20
|
+
display: flex;
|
|
21
|
+
flex-direction: column;
|
|
22
|
+
gap: .75rem;
|
|
23
|
+
}
|
|
24
|
+
.sui-radio-container.horizontal .sui-radio-inputs {
|
|
25
|
+
flex-direction: row;
|
|
26
|
+
}
|
|
27
|
+
.sui-radio-label {
|
|
28
|
+
display: flex;
|
|
29
|
+
flex-direction: row;
|
|
30
|
+
gap: .5rem;
|
|
31
|
+
position: relative;
|
|
32
|
+
align-items: center;
|
|
33
|
+
}
|
|
34
|
+
.sui-radio-label:hover .sui-radio-box {
|
|
35
|
+
outline-color: hsl(var(--default-hover));
|
|
36
|
+
}
|
|
37
|
+
.sui-radio-container:not(.disabled) .sui-radio-label:active .sui-radio-box {
|
|
38
|
+
outline-color: hsl(var(--default-active));
|
|
39
|
+
scale: 0.9;
|
|
40
|
+
}
|
|
41
|
+
.sui-radio-label:has(.sui-radio-toggle:checked) .sui-radio-box {
|
|
42
|
+
background-color: hsl(var(--text-normal));
|
|
43
|
+
outline-color: hsl(var(--text-normal));
|
|
44
|
+
}
|
|
45
|
+
.sui-radio-container.primary .sui-radio-label:has(.sui-radio-toggle:checked) .sui-radio-box {
|
|
46
|
+
background-color: hsl(var(--primary-base));
|
|
47
|
+
outline-color: hsl(var(--primary-base));
|
|
48
|
+
}
|
|
49
|
+
.sui-radio-container.success .sui-radio-label:has(.sui-radio-toggle:checked) .sui-radio-box {
|
|
50
|
+
background-color: hsl(var(--success-base));
|
|
51
|
+
outline-color: hsl(var(--success-base));
|
|
52
|
+
}
|
|
53
|
+
.sui-radio-container.warning .sui-radio-label:has(.sui-radio-toggle:checked) .sui-radio-box {
|
|
54
|
+
background-color: hsl(var(--warning-base));
|
|
55
|
+
outline-color: hsl(var(--warning-base));
|
|
56
|
+
}
|
|
57
|
+
.sui-radio-container.danger .sui-radio-label:has(.sui-radio-toggle:checked) .sui-radio-box {
|
|
58
|
+
background-color: hsl(var(--danger-base));
|
|
59
|
+
outline-color: hsl(var(--danger-base));
|
|
60
|
+
}
|
|
61
|
+
.sui-radio-container.info .sui-radio-label:has(.sui-radio-toggle:checked) .sui-radio-box {
|
|
62
|
+
background-color: hsl(var(--info-base));
|
|
63
|
+
outline-color: hsl(var(--info-base));
|
|
64
|
+
}
|
|
65
|
+
.sui-radio-container.mono .sui-radio-label:has(.sui-radio-toggle:checked) .sui-radio-box {
|
|
66
|
+
background-color: hsl(var(--mono-base));
|
|
67
|
+
outline-color: hsl(var(--mono-base));
|
|
68
|
+
}
|
|
69
|
+
.sui-radio-box-container {
|
|
70
|
+
width: 20px;
|
|
71
|
+
height: 20px;
|
|
72
|
+
display: flex;
|
|
73
|
+
flex-direction: row;
|
|
74
|
+
align-items: center;
|
|
75
|
+
justify-content: center;
|
|
76
|
+
cursor: pointer;
|
|
77
|
+
}
|
|
78
|
+
.sui-radio-box {
|
|
79
|
+
width: 12px;
|
|
80
|
+
height: 12px;
|
|
81
|
+
border-radius: var(--radius-full);
|
|
82
|
+
outline: 1px solid hsl(var(--default-base));
|
|
83
|
+
outline-offset: 4px;
|
|
84
|
+
transition: all .15s ease;
|
|
85
|
+
}
|
|
86
|
+
.sui-radio-box:focus-visible {
|
|
87
|
+
outline-color: hsl(var(--text-normal)) !important;
|
|
88
|
+
}
|
|
89
|
+
.sui-radio-toggle {
|
|
90
|
+
width: 0;
|
|
91
|
+
height: 0;
|
|
92
|
+
visibility: hidden;
|
|
93
|
+
opacity: 0;
|
|
94
|
+
margin: 0;
|
|
95
|
+
position: absolute;
|
|
96
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare const AllRadioGroupContainers: NodeListOf<HTMLDivElement>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const AllRadioGroupContainers = document.querySelectorAll(".sui-radio-container");
|
|
2
|
+
for (const element of AllRadioGroupContainers) {
|
|
3
|
+
if (element.dataset.initialized) continue;
|
|
4
|
+
element.dataset.initialized = "true";
|
|
5
|
+
const radioBoxes = element.querySelectorAll(".sui-radio-box");
|
|
6
|
+
let i = 0;
|
|
7
|
+
for (const radioBox of radioBoxes) {
|
|
8
|
+
radioBox.addEventListener("keydown", (e) => {
|
|
9
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
10
|
+
e.preventDefault();
|
|
11
|
+
const input = e.target.parentElement.parentElement.querySelector(".sui-radio-toggle");
|
|
12
|
+
if (input.disabled) return;
|
|
13
|
+
input.checked = true;
|
|
14
|
+
}
|
|
15
|
+
if (e.key === "ArrowRight" || e.key === "ArrowDown") {
|
|
16
|
+
e.preventDefault();
|
|
17
|
+
let nextRadioBox;
|
|
18
|
+
radioBoxes.forEach((box, index) => {
|
|
19
|
+
if (box === radioBox) nextRadioBox = radioBoxes[index + 1];
|
|
20
|
+
});
|
|
21
|
+
if (!nextRadioBox) return;
|
|
22
|
+
radioBox.tabIndex = -1;
|
|
23
|
+
nextRadioBox.tabIndex = 0;
|
|
24
|
+
nextRadioBox.focus();
|
|
25
|
+
nextRadioBox.click();
|
|
26
|
+
}
|
|
27
|
+
if (e.key === "ArrowLeft" || e.key === "ArrowUp") {
|
|
28
|
+
e.preventDefault();
|
|
29
|
+
let previousRadioBox;
|
|
30
|
+
radioBoxes.forEach((box, index) => {
|
|
31
|
+
if (box === radioBox) previousRadioBox = radioBoxes[index - 1];
|
|
32
|
+
});
|
|
33
|
+
if (!previousRadioBox) return;
|
|
34
|
+
radioBox.tabIndex = -1;
|
|
35
|
+
previousRadioBox.tabIndex = 0;
|
|
36
|
+
previousRadioBox.focus();
|
|
37
|
+
previousRadioBox.click();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
i++;
|
|
41
|
+
}
|
|
42
|
+
element.addEventListener("keydown", (e) => {
|
|
43
|
+
if (e.key !== "Enter") return;
|
|
44
|
+
const checkbox = element.querySelector(".sui-checkbox");
|
|
45
|
+
if (!checkbox) return;
|
|
46
|
+
checkbox.click();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
import type { HTMLAttributes } from 'astro/types';
|
|
3
|
+
import './row.css';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* The props for the row component.
|
|
@@ -21,27 +22,3 @@ const { alignCenter, gapSize = 'md', ...props } = Astro.props;
|
|
|
21
22
|
<div class="sui-row" class:list={[alignCenter && "align", gapSize]} {...props}>
|
|
22
23
|
<slot />
|
|
23
24
|
</div>
|
|
24
|
-
<style>
|
|
25
|
-
.sui-row {
|
|
26
|
-
display: flex;
|
|
27
|
-
flex-direction: row;
|
|
28
|
-
position: relative;
|
|
29
|
-
flex-wrap: wrap;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.sui-row.align {
|
|
33
|
-
align-items: center;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
.sui-row.sm {
|
|
37
|
-
gap: .5rem;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
.sui-row.md {
|
|
41
|
-
gap: 1rem;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
.sui-row.lg {
|
|
45
|
-
gap: 2rem;
|
|
46
|
-
}
|
|
47
|
-
</style>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
.sui-row {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: row;
|
|
4
|
+
position: relative;
|
|
5
|
+
flex-wrap: wrap;
|
|
6
|
+
}
|
|
7
|
+
.sui-row.align {
|
|
8
|
+
align-items: center;
|
|
9
|
+
}
|
|
10
|
+
.sui-row.sm {
|
|
11
|
+
gap: .5rem;
|
|
12
|
+
}
|
|
13
|
+
.sui-row.md {
|
|
14
|
+
gap: 1rem;
|
|
15
|
+
}
|
|
16
|
+
.sui-row.lg {
|
|
17
|
+
gap: 2rem;
|
|
18
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { generateID } from '../../utils/generateID.js';
|
|
3
|
+
import Icon from '../Icon/Icon.astro';
|
|
4
|
+
import Input from '../Input/Input.astro';
|
|
5
|
+
import './searchselect.css';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* An option in the select dropdown
|
|
9
|
+
*/
|
|
10
|
+
interface Option {
|
|
11
|
+
/**
|
|
12
|
+
* The label of the option.
|
|
13
|
+
*/
|
|
14
|
+
label: string;
|
|
15
|
+
/**
|
|
16
|
+
* The value of the option.
|
|
17
|
+
*/
|
|
18
|
+
value: string;
|
|
19
|
+
/**
|
|
20
|
+
* Whether the option is disabled.
|
|
21
|
+
*/
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The props for the search select component.
|
|
27
|
+
*/
|
|
28
|
+
interface Props {
|
|
29
|
+
/**
|
|
30
|
+
* The label of the search select.
|
|
31
|
+
*/
|
|
32
|
+
label?: string;
|
|
33
|
+
/**
|
|
34
|
+
* The default value of the search select. Needs to be one of the values in the options.
|
|
35
|
+
*/
|
|
36
|
+
defaultValue?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Additional classes to apply to the search select.
|
|
39
|
+
*/
|
|
40
|
+
class?: string;
|
|
41
|
+
/**
|
|
42
|
+
* The name of the search select.
|
|
43
|
+
*/
|
|
44
|
+
name?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Whether the search select is required. Defaults to `false`.
|
|
47
|
+
*/
|
|
48
|
+
isRequired?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The options to display in the search select.
|
|
51
|
+
*/
|
|
52
|
+
options: Option[];
|
|
53
|
+
/**
|
|
54
|
+
* Whether the search select is disabled. Defaults to `false`.
|
|
55
|
+
*/
|
|
56
|
+
disabled?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Whether the search select should take up the full width of its container.
|
|
59
|
+
*/
|
|
60
|
+
fullWidth?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* The placeholder of the search select.
|
|
63
|
+
*/
|
|
64
|
+
placeholder?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const {
|
|
68
|
+
label,
|
|
69
|
+
defaultValue,
|
|
70
|
+
class: className,
|
|
71
|
+
name = generateID('search-select'),
|
|
72
|
+
isRequired,
|
|
73
|
+
options = [],
|
|
74
|
+
disabled,
|
|
75
|
+
fullWidth,
|
|
76
|
+
placeholder,
|
|
77
|
+
} = Astro.props;
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
<div
|
|
81
|
+
id={`${name}-container`}
|
|
82
|
+
class="sui-search-select-label"
|
|
83
|
+
class:list={[disabled && "disabled", className, fullWidth && "full"]}
|
|
84
|
+
data-options={JSON.stringify(options)}
|
|
85
|
+
data-id={name}
|
|
86
|
+
>
|
|
87
|
+
<div class="sui-search-input-wrapper" id={`${name}-search-input-wrapper`}>
|
|
88
|
+
<Input
|
|
89
|
+
placeholder={options.find((x) => x.value === defaultValue)?.label || (placeholder || "Select")}
|
|
90
|
+
role='combobox'
|
|
91
|
+
aria-controls={`${name}-dropdown`}
|
|
92
|
+
aria-expanded="false"
|
|
93
|
+
label={label || ''}
|
|
94
|
+
isRequired={isRequired || false}
|
|
95
|
+
/>
|
|
96
|
+
<Icon name="chevron-up-down" class="sui-search-select-indicator" width={24} height={24} />
|
|
97
|
+
</div>
|
|
98
|
+
<ul class="sui-search-select-dropdown" role="listbox" id={`${name}-dropdown`}>
|
|
99
|
+
{
|
|
100
|
+
options.map((x, i) => (
|
|
101
|
+
<li
|
|
102
|
+
class="sui-search-select-option"
|
|
103
|
+
role="option"
|
|
104
|
+
value={x.value}
|
|
105
|
+
class:list={[
|
|
106
|
+
x.disabled && "disabled",
|
|
107
|
+
i === 0 && 'focused',
|
|
108
|
+
]}
|
|
109
|
+
id={defaultValue === x.value ? `${name}-selected` : ""}
|
|
110
|
+
data-option-index={i}
|
|
111
|
+
data-value={x.value}
|
|
112
|
+
>
|
|
113
|
+
{x.label}
|
|
114
|
+
</li>
|
|
115
|
+
))
|
|
116
|
+
}
|
|
117
|
+
</ul>
|
|
118
|
+
<select class="sui-hidden-select" id={name} name={name} required={isRequired} hidden tabindex="-1">
|
|
119
|
+
<option value={""}> Select </option>
|
|
120
|
+
{
|
|
121
|
+
options.map((x) => (
|
|
122
|
+
<option
|
|
123
|
+
value={x.value}
|
|
124
|
+
selected={defaultValue === x.value}
|
|
125
|
+
disabled={x.disabled}
|
|
126
|
+
>
|
|
127
|
+
{x.label}
|
|
128
|
+
</option>
|
|
129
|
+
))
|
|
130
|
+
}
|
|
131
|
+
</select>
|
|
132
|
+
</div>
|
|
133
|
+
<script>
|
|
134
|
+
import "studiocms:ui/scripts/searchselect"
|
|
135
|
+
</script>
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
.sui-search-select-label {
|
|
2
|
+
width: fit-content;
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
gap: 0.25rem;
|
|
6
|
+
min-width: 200px;
|
|
7
|
+
position: relative;
|
|
8
|
+
}
|
|
9
|
+
.sui-search-select-label.full {
|
|
10
|
+
width: 100%;
|
|
11
|
+
}
|
|
12
|
+
.sui-search-select-label.disabled {
|
|
13
|
+
opacity: 0.5;
|
|
14
|
+
pointer-events: none;
|
|
15
|
+
color: hsl(var(--text-muted));
|
|
16
|
+
}
|
|
17
|
+
.label {
|
|
18
|
+
font-size: 14px;
|
|
19
|
+
}
|
|
20
|
+
.req-star {
|
|
21
|
+
color: hsl(var(--danger-base));
|
|
22
|
+
font-weight: 700;
|
|
23
|
+
}
|
|
24
|
+
.sui-search-select-dropdown {
|
|
25
|
+
position: absolute;
|
|
26
|
+
width: 100%;
|
|
27
|
+
border: 1px solid hsl(var(--border));
|
|
28
|
+
list-style: none;
|
|
29
|
+
margin: 0;
|
|
30
|
+
padding: 0;
|
|
31
|
+
flex-direction: column;
|
|
32
|
+
border-radius: var(--radius-md);
|
|
33
|
+
background-color: hsl(var(--background-step-2));
|
|
34
|
+
overflow: hidden;
|
|
35
|
+
top: calc(100% + 0.25rem);
|
|
36
|
+
left: 0;
|
|
37
|
+
display: none;
|
|
38
|
+
z-index: 90;
|
|
39
|
+
box-shadow: 0px 4px 8px hsl(var(--shadow), 0.5);
|
|
40
|
+
}
|
|
41
|
+
.sui-search-select-dropdown.above {
|
|
42
|
+
top: auto;
|
|
43
|
+
bottom: calc(100% - 18px + 0.25rem);
|
|
44
|
+
}
|
|
45
|
+
.sui-search-select-option,
|
|
46
|
+
.empty-search-results {
|
|
47
|
+
padding: 0.5rem;
|
|
48
|
+
cursor: pointer;
|
|
49
|
+
font-size: 0.975em;
|
|
50
|
+
transition: all 0.15s ease;
|
|
51
|
+
}
|
|
52
|
+
.sui-search-select-option.disabled {
|
|
53
|
+
pointer-events: none;
|
|
54
|
+
color: hsl(var(--text-muted));
|
|
55
|
+
}
|
|
56
|
+
.sui-search-select-option:hover,
|
|
57
|
+
.sui-search-select-option.focused {
|
|
58
|
+
background-color: hsl(var(--background-step-3));
|
|
59
|
+
}
|
|
60
|
+
.sui-search-select-option.selected {
|
|
61
|
+
background-color: hsl(var(--primary-base));
|
|
62
|
+
color: hsl(var(--text-inverted));
|
|
63
|
+
cursor: default;
|
|
64
|
+
}
|
|
65
|
+
.sui-hidden-select {
|
|
66
|
+
height: 0;
|
|
67
|
+
width: 0;
|
|
68
|
+
border: none;
|
|
69
|
+
outline: none;
|
|
70
|
+
position: absolute;
|
|
71
|
+
background-color: transparent;
|
|
72
|
+
pointer-events: none;
|
|
73
|
+
opacity: 0;
|
|
74
|
+
}
|
|
75
|
+
.sui-search-input-wrapper {
|
|
76
|
+
width: 100%;
|
|
77
|
+
position: relative;
|
|
78
|
+
height: fit-content;
|
|
79
|
+
cursor: pointer;
|
|
80
|
+
}
|
|
81
|
+
.sui-search-input-wrapper input {
|
|
82
|
+
padding-right: 2.5rem;
|
|
83
|
+
}
|
|
84
|
+
.sui-search-select-indicator {
|
|
85
|
+
position: absolute;
|
|
86
|
+
bottom: .675rem;
|
|
87
|
+
right: .675rem;
|
|
88
|
+
}
|
|
89
|
+
.sui-search-input-wrapper:has(input:focus) + .sui-search-select-dropdown {
|
|
90
|
+
display: flex;
|
|
91
|
+
}
|
|
92
|
+
.sui-search-select-dropdown.active,
|
|
93
|
+
.sui-search-select-dropdown:has(> li:active) {
|
|
94
|
+
display: flex;
|
|
95
|
+
}
|