@stacksjs/components 0.2.343 → 0.2.344
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/{Accordion-8tv78bh9.stx → Accordion-ccye7erw.stx} +23 -3
- package/dist/{Audio-y0sgq50z.stx → Audio-tnjd6anm.stx} +7 -7
- package/dist/{Avatar-e43x17z1.stx → Avatar-7vegrsg6.stx} +3 -3
- package/dist/Badge-439n5p0a.stx +74 -0
- package/dist/{Breadcrumb-csf164sd.stx → Breadcrumb-7hwnfyyw.stx} +21 -6
- package/dist/Button-y8fnx29x.stx +193 -0
- package/dist/{Calendar-gjjhhfnt.stx → Calendar-8q76ees6.stx} +6 -6
- package/dist/{Card-7byck6ep.stx → Card-r55zpjqh.stx} +6 -6
- package/dist/{Checkbox-2s2a7n4h.stx → Checkbox-xnm8ax5q.stx} +9 -9
- package/dist/{ComboboxInput-z1293bbh.stx → ComboboxInput-9q87fb22.stx} +2 -2
- package/dist/{ComboboxOption-6yh7xk7q.stx → ComboboxOption-qm38e8e9.stx} +2 -2
- package/dist/{ComboboxOptions-sq5360ae.stx → ComboboxOptions-nbndbrxz.stx} +1 -1
- package/dist/{CommandPalette-fzfv1pme.stx → CommandPalette-mkqqep2s.stx} +4 -4
- package/dist/{DefaultPaymentMethod-6qrem3sg.stx → DefaultPaymentMethod-v11254p4.stx} +8 -8
- package/dist/Dialog-d1020hj6.stx +268 -0
- package/dist/DialogBackdrop-de5m5m4w.stx +12 -0
- package/dist/DialogPanel-vhdqymc2.stx +19 -0
- package/dist/{DialogTitle-x0r6k8x9.stx → DialogTitle-0jjdk5ra.stx} +1 -1
- package/dist/{Drawer-9jx39xef.stx → Drawer-rymajw9v.stx} +86 -21
- package/dist/{DropdownButton-wcz67dxy.stx → DropdownButton-n6gsmcte.stx} +2 -2
- package/dist/{DropdownItem-d8ht2bp5.stx → DropdownItem-qs772agw.stx} +1 -1
- package/dist/{DropdownItems-1sxnd5qn.stx → DropdownItems-yf25hdh1.stx} +1 -1
- package/dist/{EmailInput-vak3kkmk.stx → EmailInput-agb8kqae.stx} +4 -4
- package/dist/{FilterChip-h896vrxm.stx → FilterChip-ww5nkepm.stx} +26 -2
- package/dist/{Image-4ezne2xj.stx → Image-79xyzb5j.stx} +3 -3
- package/dist/{ListRow-v45ymhcn.stx → ListRow-8d3e1yxh.stx} +2 -2
- package/dist/{Listbox-0cyysv0f.stx → Listbox-e5jreb0a.stx} +1 -1
- package/dist/{ListboxButton-keb8gm0q.stx → ListboxButton-w3vfvte7.stx} +2 -2
- package/dist/{RadioGroupLabel-7mymt1b8.stx → ListboxLabel-ka0hfm7b.stx} +1 -1
- package/dist/{ListboxOption-4j070101.stx → ListboxOption-ea0j02a8.stx} +2 -2
- package/dist/{ListboxOptions-ejkatcfg.stx → ListboxOptions-qxrkrb8z.stx} +1 -1
- package/dist/{Login-2cp65d41.stx → Login-hh53d6tw.stx} +14 -14
- package/dist/{NavBar-wcb6f2d3.stx → NavBar-qqrrhdnk.stx} +24 -0
- package/dist/{Navigator-smpa7my4.stx → Navigator-55wpcpx1.stx} +2 -2
- package/dist/{Notification-03vfh3k6.stx → Notification-7wgk0sw6.stx} +6 -6
- package/dist/{NumberInput-j9p5bm5y.stx → NumberInput-54d23rq0.stx} +21 -11
- package/dist/{Pagination-ff7nzp7d.stx → Pagination-0ra20dja.stx} +4 -4
- package/dist/{PasswordInput-4qykq1dz.stx → PasswordInput-3snyppj4.stx} +24 -14
- package/dist/{PaymentMethods-2xy66bwk.stx → PaymentMethods-zwa7c6kh.stx} +10 -10
- package/dist/{PopoverButton-mffzc9pr.stx → PopoverButton-panmcysh.stx} +2 -2
- package/dist/{PopoverPanel-054yh38h.stx → PopoverPanel-7771yf35.stx} +2 -2
- package/dist/{Portal-yghnqdj8.stx → Portal-m73vz879.stx} +1 -1
- package/dist/{Progress-twhhzsd9.stx → Progress-cj0z83rx.stx} +47 -18
- package/dist/{Radio-ccm07b2m.stx → Radio-m2wz5ny6.stx} +8 -8
- package/dist/{RadioGroup-82ytfqdb.stx → RadioGroup-jg9s4ttg.stx} +1 -1
- package/dist/{ListboxLabel-7mymt1b8.stx → RadioGroupLabel-ka0hfm7b.stx} +1 -1
- package/dist/{RadioGroupOption-7pq7rw84.stx → RadioGroupOption-zvp0y9sn.stx} +2 -2
- package/dist/{SearchInput-pdx7agn0.stx → SearchInput-psbjk2ye.stx} +3 -3
- package/dist/{SectionCard-r73hvvbc.stx → SectionCard-8ctdacjr.stx} +28 -1
- package/dist/{Select-zt72gg1e.stx → Select-pj584jza.stx} +19 -9
- package/dist/{Sidebar-f1tff5p3.stx → Sidebar-ve2asgf3.stx} +6 -6
- package/dist/{SidebarHeader-3dppxxjh.stx → SidebarHeader-esvby82n.stx} +3 -3
- package/dist/{SidebarItem-5v8atp7p.stx → SidebarItem-r4f2pref.stx} +4 -4
- package/dist/{SidebarSection-sqz49ary.stx → SidebarSection-5sqza2j6.stx} +2 -2
- package/dist/{SidebarSpace-nmbvgrky.stx → SidebarSpace-bwv98azf.stx} +3 -3
- package/dist/{SidebarSpaceSwitcher-v5e472j0.stx → SidebarSpaceSwitcher-1mycft2g.stx} +1 -1
- package/dist/{SidebarSpaces-6v3p9htw.stx → SidebarSpaces-mdtrynr2.stx} +2 -2
- package/dist/{Signup-cbncrtvd.stx → Signup-egdrk3rh.stx} +11 -11
- package/dist/{Skeleton-y9tycz2h.stx → Skeleton-me2hwqrc.stx} +4 -4
- package/dist/{Spinner-reb6rse4.stx → Spinner-grahbp9a.stx} +9 -9
- package/dist/{StepperStep-3ahq4d9m.stx → StepperStep-xw55xjh0.stx} +9 -4
- package/dist/{SubscriptionCheckout-7fdkwf04.stx → SubscriptionCheckout-wj4s182k.stx} +13 -13
- package/dist/{Switch-cgy7hy0s.stx → Switch-fxbw7s16.stx} +7 -4
- package/dist/{TabBarItem-hd2r2ayy.stx → TabBarItem-cnxhgy92.stx} +25 -1
- package/dist/{Table-0mc3fdek.stx → Table-akbk3t5q.stx} +1 -1
- package/dist/{TableHeader-sxc77b4d.stx → TableHeader-qsc3e208.stx} +1 -1
- package/dist/{Tabs-b4xsba1w.stx → Tabs-2cjt68my.stx} +28 -8
- package/dist/{Teleport-3gnjtsjf.stx → Teleport-c8nn3757.stx} +2 -2
- package/dist/{TextInput-hbe2ynzj.stx → TextInput-9wqzeeg1.stx} +23 -13
- package/dist/{Textarea-xcdym703.stx → Textarea-xwkdg8se.stx} +11 -11
- package/dist/{Tooltip-y0kzkwh4.stx → Tooltip-14gt4f1w.stx} +9 -6
- package/dist/{Transition-7smenaz8.stx → Transition-yrvqbhjy.stx} +1 -1
- package/dist/{TwoFactorChallenge-y7n4yrk9.stx → TwoFactorChallenge-0200pjc0.stx} +5 -5
- package/dist/{Video-a0aeyexv.stx → Video-rhy7dskw.stx} +6 -6
- package/dist/{VirtualTable-jvm1784g.stx → VirtualTable-jvje0ybn.stx} +4 -4
- package/dist/composables/index.js +2 -2
- package/dist/index.js +13 -13
- package/dist/utils/highlighter.d.ts +1 -0
- package/dist/utils/highlighter.js +1 -1
- package/package.json +3 -3
- package/src/components/CodeBlock.stx +7 -1
- package/src/components/Footer.stx +1 -1
- package/src/components/Hero.stx +2 -2
- package/src/components/Installation.stx +4 -4
- package/src/ui/accordion/Accordion.stx +23 -3
- package/src/ui/audio/Audio.stx +7 -7
- package/src/ui/auth/Login.stx +14 -14
- package/src/ui/auth/Signup.stx +11 -11
- package/src/ui/auth/TwoFactorChallenge.stx +5 -5
- package/src/ui/avatar/Avatar.stx +3 -3
- package/src/ui/badge/Badge.stx +31 -19
- package/src/ui/breadcrumb/Breadcrumb.stx +21 -6
- package/src/ui/button/Button.stx +148 -29
- package/src/ui/calendar/Calendar.stx +6 -6
- package/src/ui/card/Card.stx +6 -6
- package/src/ui/checkbox/Checkbox.stx +9 -9
- package/src/ui/combobox/ComboboxInput.stx +2 -2
- package/src/ui/combobox/ComboboxOption.stx +2 -2
- package/src/ui/combobox/ComboboxOptions.stx +1 -1
- package/src/ui/command-palette/CommandPalette.stx +4 -4
- package/src/ui/dialog/Dialog.stx +231 -4
- package/src/ui/dialog/DialogBackdrop.stx +5 -2
- package/src/ui/dialog/DialogPanel.stx +5 -2
- package/src/ui/dialog/DialogTitle.stx +1 -1
- package/src/ui/dialog/README.md +15 -4
- package/src/ui/drawer/Drawer.stx +86 -21
- package/src/ui/dropdown/DropdownButton.stx +2 -2
- package/src/ui/dropdown/DropdownItem.stx +1 -1
- package/src/ui/dropdown/DropdownItems.stx +1 -1
- package/src/ui/heatmap/Heatmap.stx +1 -1
- package/src/ui/image/Image.stx +3 -3
- package/src/ui/input/EmailInput.stx +4 -4
- package/src/ui/input/NumberInput.stx +21 -11
- package/src/ui/input/PasswordInput.stx +24 -14
- package/src/ui/input/SearchInput.stx +3 -3
- package/src/ui/input/TextInput.stx +23 -13
- package/src/ui/listbox/Listbox.stx +1 -1
- package/src/ui/listbox/ListboxButton.stx +2 -2
- package/src/ui/listbox/ListboxLabel.stx +1 -1
- package/src/ui/listbox/ListboxOption.stx +2 -2
- package/src/ui/listbox/ListboxOptions.stx +1 -1
- package/src/ui/mobile/FilterChip.stx +26 -2
- package/src/ui/mobile/ListRow.stx +2 -2
- package/src/ui/mobile/NavBar.stx +24 -0
- package/src/ui/mobile/SectionCard.stx +28 -1
- package/src/ui/mobile/TabBarItem.stx +25 -1
- package/src/ui/navigator/Navigator.stx +2 -2
- package/src/ui/notification/Notification.stx +6 -6
- package/src/ui/pagination/Pagination.stx +4 -4
- package/src/ui/payment/DefaultPaymentMethod.stx +8 -8
- package/src/ui/payment/PaymentMethods.stx +10 -10
- package/src/ui/payment/SubscriptionCheckout.stx +13 -13
- package/src/ui/popover/PopoverButton.stx +2 -2
- package/src/ui/popover/PopoverPanel.stx +2 -2
- package/src/ui/portal/Portal.stx +1 -1
- package/src/ui/progress/Progress.stx +47 -18
- package/src/ui/radio/Radio.stx +8 -8
- package/src/ui/radio-group/RadioGroup.stx +1 -1
- package/src/ui/radio-group/RadioGroupLabel.stx +1 -1
- package/src/ui/radio-group/RadioGroupOption.stx +2 -2
- package/src/ui/select/Select.stx +19 -9
- package/src/ui/sidebar/Sidebar.stx +6 -6
- package/src/ui/sidebar/SidebarHeader.stx +3 -3
- package/src/ui/sidebar/SidebarItem.stx +4 -4
- package/src/ui/sidebar/SidebarSection.stx +2 -2
- package/src/ui/sidebar/SidebarSpace.stx +3 -3
- package/src/ui/sidebar/SidebarSpaceSwitcher.stx +1 -1
- package/src/ui/sidebar/SidebarSpaces.stx +2 -2
- package/src/ui/skeleton/Skeleton.stx +4 -4
- package/src/ui/spinner/Spinner.stx +9 -9
- package/src/ui/stepper/StepperStep.stx +9 -4
- package/src/ui/switch/Switch.stx +7 -4
- package/src/ui/table/Table.stx +1 -1
- package/src/ui/table/TableHeader.stx +1 -1
- package/src/ui/tabs/Tabs.stx +28 -8
- package/src/ui/teleport/Teleport.stx +2 -2
- package/src/ui/textarea/Textarea.stx +11 -11
- package/src/ui/tooltip/Tooltip.stx +9 -6
- package/src/ui/transition/Transition.stx +1 -1
- package/src/ui/video/Video.stx +6 -6
- package/src/ui/virtual-table/VirtualTable.stx +4 -4
- package/src/utils/highlighter.ts +65 -4
- package/dist/Badge-xwjeq24d.stx +0 -62
- package/dist/Button-h2mk4wfw.stx +0 -74
- package/dist/Dialog-y5rz2vrq.stx +0 -41
- package/dist/DialogBackdrop-rxax3sec.stx +0 -9
- package/dist/DialogPanel-44d8jeqy.stx +0 -16
package/src/ui/dialog/Dialog.stx
CHANGED
|
@@ -1,28 +1,253 @@
|
|
|
1
1
|
<script server>
|
|
2
|
-
export const open = $props.open
|
|
2
|
+
export const open = $bool($props.open)
|
|
3
3
|
export const className = $props.className || ''
|
|
4
4
|
|
|
5
5
|
const baseClasses = 'relative z-50'
|
|
6
6
|
export const dialogClasses = `${baseClasses} ${className}`.trim()
|
|
7
|
+
|
|
8
|
+
/*
|
|
9
|
+
* This dialog's own id.
|
|
10
|
+
*
|
|
11
|
+
* Every lookup below is scoped to it, so two dialogs on one page - a list and
|
|
12
|
+
* the confirmation for deleting from it - do not take each other's panel or
|
|
13
|
+
* each other's Escape. Same idiom as Drawer, Dropdown and Popover.
|
|
14
|
+
*/
|
|
15
|
+
export const dialogInstanceId = $uid
|
|
7
16
|
</script>
|
|
8
17
|
|
|
9
18
|
<script client>
|
|
10
19
|
const emit = defineEmits()
|
|
20
|
+
const dialogInstanceId = {{ dialogInstanceId }}
|
|
11
21
|
// useReactiveProp wires `:open="parentSignal()"` from the parent into our
|
|
12
22
|
// local `isOpen` signal — when the parent's signal changes, bindAttr
|
|
13
23
|
// updates the root's `open` attribute, our MutationObserver picks it up,
|
|
14
24
|
// and isOpen flips. See stacksjs/stx#1704.
|
|
15
25
|
const isOpen = useReactiveProp('open', {{ open }})
|
|
26
|
+
const rootRef = useRef('rootRef')
|
|
27
|
+
|
|
28
|
+
/*
|
|
29
|
+
* Whether hydration has run.
|
|
30
|
+
*
|
|
31
|
+
* Everything below reaches into the DOM through rootRef, and an effect's first
|
|
32
|
+
* run happens while this setup function is still executing - before x-ref is
|
|
33
|
+
* wired, when the ref can only be null. A dialog rendered open on first paint
|
|
34
|
+
* would otherwise get no scroll lock and no focus. See #1979 for the same
|
|
35
|
+
* mistake in Tabs.
|
|
36
|
+
*/
|
|
37
|
+
const mounted = state(false)
|
|
38
|
+
|
|
39
|
+
onMount(() => {
|
|
40
|
+
mounted.set(true)
|
|
41
|
+
})
|
|
16
42
|
|
|
17
43
|
function close() {
|
|
18
44
|
isOpen.set(false)
|
|
19
45
|
emit('close')
|
|
20
46
|
}
|
|
21
47
|
|
|
22
|
-
|
|
23
|
-
|
|
48
|
+
/** The panel, or the dialog root if this dialog has no DialogPanel in it. */
|
|
49
|
+
function panelEl() {
|
|
50
|
+
const root = rootRef.value
|
|
51
|
+
if (!root) return null
|
|
52
|
+
return root.querySelector('[data-stx-dialog-panel]') || root
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function focusable() {
|
|
56
|
+
const panel = panelEl()
|
|
57
|
+
if (!panel) return []
|
|
58
|
+
return Array.from(panel.querySelectorAll('a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])'))
|
|
59
|
+
.filter(el => el.offsetParent !== null || el === document.activeElement)
|
|
24
60
|
}
|
|
25
61
|
|
|
62
|
+
/*
|
|
63
|
+
* Escape closes it from anywhere, not just from inside the dialog.
|
|
64
|
+
*
|
|
65
|
+
* It used to be a @keydown on the root element, which only fires once focus is
|
|
66
|
+
* already inside - and nothing moved focus there on open. So in the ordinary
|
|
67
|
+
* case (click a trigger, dialog appears) Escape did nothing at all, and the
|
|
68
|
+
* two omissions hid each other: no initial focus made the handler unreachable,
|
|
69
|
+
* and the unreachable handler made the missing focus look harmless.
|
|
70
|
+
* stacksjs/stx#1973, #1978
|
|
71
|
+
*/
|
|
72
|
+
function onDocumentKey(event) {
|
|
73
|
+
if (!isOpen()) return
|
|
74
|
+
|
|
75
|
+
if (event.key === 'Escape') {
|
|
76
|
+
close()
|
|
77
|
+
return
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (event.key !== 'Tab') return
|
|
81
|
+
|
|
82
|
+
/*
|
|
83
|
+
* The focus trap.
|
|
84
|
+
*
|
|
85
|
+
* aria-modal="true" tells assistive technology that the rest of the page is
|
|
86
|
+
* inert. Without containment that is not a missing feature but an active
|
|
87
|
+
* misstatement to AT, so the attribute and this handler belong together: six
|
|
88
|
+
* Tab presses used to walk focus out of a delete-confirmation dialog and
|
|
89
|
+
* onto the page behind it.
|
|
90
|
+
*/
|
|
91
|
+
const items = focusable()
|
|
92
|
+
if (items.length === 0) {
|
|
93
|
+
// Nothing to land on inside: keep focus on the panel rather than letting
|
|
94
|
+
// Tab leave.
|
|
95
|
+
event.preventDefault()
|
|
96
|
+
panelEl()?.focus?.()
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const first = items[0]
|
|
101
|
+
const last = items[items.length - 1]
|
|
102
|
+
const active = document.activeElement
|
|
103
|
+
const inside = panelEl()?.contains(active)
|
|
104
|
+
|
|
105
|
+
if (!inside) {
|
|
106
|
+
event.preventDefault()
|
|
107
|
+
;(event.shiftKey ? last : first).focus()
|
|
108
|
+
return
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (event.shiftKey && active === first) {
|
|
112
|
+
event.preventDefault()
|
|
113
|
+
last.focus()
|
|
114
|
+
}
|
|
115
|
+
else if (!event.shiftKey && active === last) {
|
|
116
|
+
event.preventDefault()
|
|
117
|
+
first.focus()
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/*
|
|
122
|
+
* A click on the backdrop closes it.
|
|
123
|
+
*
|
|
124
|
+
* The backdrop is a child component, so this listens on the dialog root and
|
|
125
|
+
* asks whether the click landed on the marker DialogBackdrop renders. Checking
|
|
126
|
+
* the target rather than comparing against the panel means a click inside the
|
|
127
|
+
* panel is not a backdrop click even though the backdrop is behind it.
|
|
128
|
+
*/
|
|
129
|
+
function onRootClick(event) {
|
|
130
|
+
const target = event.target
|
|
131
|
+
if (target && target.closest && target.closest('[data-stx-dialog-backdrop]')) close()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/*
|
|
135
|
+
* Hold the page still behind the dialog.
|
|
136
|
+
*
|
|
137
|
+
* Without this the page scrolls under the overlay, which on a phone means a
|
|
138
|
+
* drag anywhere over the dialog scrolls what is behind it. The scrollbar's
|
|
139
|
+
* width is replaced as padding so the page does not jump sideways when it
|
|
140
|
+
* disappears. Same implementation as Drawer.
|
|
141
|
+
*/
|
|
142
|
+
let restoreScroll = null
|
|
143
|
+
|
|
144
|
+
function lockScroll() {
|
|
145
|
+
if (restoreScroll) return
|
|
146
|
+
|
|
147
|
+
const gap = window.innerWidth - document.documentElement.clientWidth
|
|
148
|
+
const previous = { overflow: document.body.style.overflow, paddingRight: document.body.style.paddingRight }
|
|
149
|
+
|
|
150
|
+
document.body.style.overflow = 'hidden'
|
|
151
|
+
if (gap > 0) document.body.style.paddingRight = `${gap}px`
|
|
152
|
+
|
|
153
|
+
restoreScroll = () => {
|
|
154
|
+
document.body.style.overflow = previous.overflow
|
|
155
|
+
document.body.style.paddingRight = previous.paddingRight
|
|
156
|
+
restoreScroll = null
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function unlockScroll() {
|
|
161
|
+
if (restoreScroll) restoreScroll()
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/*
|
|
165
|
+
* Focus moves in on open and back on close.
|
|
166
|
+
*
|
|
167
|
+
* A dialog that leaves focus behind is unreachable by keyboard: Tab walks the
|
|
168
|
+
* page underneath it, and a screen reader never learns anything opened. Focus
|
|
169
|
+
* returns to whatever opened it on the way out, so closing does not dump the
|
|
170
|
+
* reader at the top of the document.
|
|
171
|
+
*/
|
|
172
|
+
let opener = null
|
|
173
|
+
|
|
174
|
+
/*
|
|
175
|
+
* The next chance to try, whichever comes first.
|
|
176
|
+
*
|
|
177
|
+
* requestAnimationFrame is the right signal when the page is painting and is
|
|
178
|
+
* suspended entirely when it is not - a background tab, a parked window - so a
|
|
179
|
+
* timer races it and the first to arrive wins.
|
|
180
|
+
*/
|
|
181
|
+
function soon(callback) {
|
|
182
|
+
let done = false
|
|
183
|
+
|
|
184
|
+
const once = () => {
|
|
185
|
+
if (done) return
|
|
186
|
+
done = true
|
|
187
|
+
callback()
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
requestAnimationFrame(once)
|
|
191
|
+
setTimeout(once, 32)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/*
|
|
195
|
+
* Retried across frames, because focus is refused before the dialog is shown.
|
|
196
|
+
*
|
|
197
|
+
* `:show` toggles display, and that has not happened yet on the frame the
|
|
198
|
+
* effect runs: focus() on a display:none element is a silent no-op, so a single
|
|
199
|
+
* attempt left focus on the body every time. Bounded, so a dialog with nothing
|
|
200
|
+
* focusable cannot spin - the panel carries tabindex=-1 and takes focus in that
|
|
201
|
+
* case - and it stops if the dialog closed in the meantime.
|
|
202
|
+
*/
|
|
203
|
+
function focusFirst(attempts) {
|
|
204
|
+
if (!isOpen()) return
|
|
205
|
+
|
|
206
|
+
const panel = panelEl()
|
|
207
|
+
if (!panel) return
|
|
208
|
+
|
|
209
|
+
const target = panel.querySelector('[autofocus]') || focusable()[0] || panel
|
|
210
|
+
|
|
211
|
+
target.focus?.()
|
|
212
|
+
|
|
213
|
+
if (document.activeElement === target) return
|
|
214
|
+
if (attempts > 0) soon(() => focusFirst(attempts - 1))
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function captureFocus() {
|
|
218
|
+
opener = document.activeElement
|
|
219
|
+
|
|
220
|
+
soon(() => focusFirst(10))
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function releaseFocus() {
|
|
224
|
+
const target = opener
|
|
225
|
+
opener = null
|
|
226
|
+
if (target && typeof target.focus === 'function') target.focus()
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
effect(() => {
|
|
230
|
+
if (!mounted()) return
|
|
231
|
+
|
|
232
|
+
if (isOpen()) {
|
|
233
|
+
lockScroll()
|
|
234
|
+
captureFocus()
|
|
235
|
+
document.addEventListener('keydown', onDocumentKey)
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
unlockScroll()
|
|
239
|
+
releaseFocus()
|
|
240
|
+
document.removeEventListener('keydown', onDocumentKey)
|
|
241
|
+
}
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
onDestroy(() => {
|
|
245
|
+
// A dialog removed while open would otherwise leave the page locked, with no
|
|
246
|
+
// dialog left to unlock it.
|
|
247
|
+
unlockScroll()
|
|
248
|
+
document.removeEventListener('keydown', onDocumentKey)
|
|
249
|
+
})
|
|
250
|
+
|
|
26
251
|
defineExpose({
|
|
27
252
|
open: () => isOpen.set(true),
|
|
28
253
|
close,
|
|
@@ -31,11 +256,13 @@ defineExpose({
|
|
|
31
256
|
</script>
|
|
32
257
|
|
|
33
258
|
<div
|
|
259
|
+
x-ref="rootRef"
|
|
34
260
|
:show="isOpen()"
|
|
35
261
|
class="{{ dialogClasses }}"
|
|
262
|
+
data-stx-dialog="{{ dialogInstanceId }}"
|
|
36
263
|
role="dialog"
|
|
37
264
|
aria-modal="true"
|
|
38
|
-
@
|
|
265
|
+
@click="onRootClick($event)"
|
|
39
266
|
>
|
|
40
267
|
<slot />
|
|
41
268
|
</div>
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
export const className = $props.className || ''
|
|
3
3
|
export const as = $props.as || 'div'
|
|
4
4
|
|
|
5
|
-
const baseClasses = 'fixed inset-0 bg-black
|
|
5
|
+
const baseClasses = 'fixed inset-0 bg-black/25 dark:bg-black/50 transition-opacity'
|
|
6
6
|
const backdropClasses = `${baseClasses} ${className}`.trim()
|
|
7
7
|
</script>
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
<!-- The marker is what Dialog reads to tell a backdrop click from a click
|
|
10
|
+
inside the panel: the backdrop is behind the panel, so comparing the
|
|
11
|
+
click target against the panel is not the same question. -->
|
|
12
|
+
<component :is="{{ as }}" class="{{ backdropClasses }}" data-stx-dialog-backdrop aria-hidden="true" />
|
|
@@ -4,12 +4,15 @@ export const as = $props.as || 'div'
|
|
|
4
4
|
|
|
5
5
|
const baseClasses = 'fixed inset-0 overflow-y-auto'
|
|
6
6
|
const panelWrapperClasses = 'flex min-h-full items-center justify-center p-4 text-center'
|
|
7
|
-
const panelClasses = `transform overflow-hidden rounded-
|
|
7
|
+
const panelClasses = `transform overflow-hidden rounded-panel bg-panel p-6 text-left align-middle shadow-xl transition-all ${className}`.trim()
|
|
8
8
|
</script>
|
|
9
9
|
|
|
10
10
|
<component :is="{{ as }}" class="{{ baseClasses }}">
|
|
11
11
|
<div class="{{ panelWrapperClasses }}">
|
|
12
|
-
|
|
12
|
+
<!-- data-stx-dialog-panel is what Dialog scopes its focus trap and its
|
|
13
|
+
initial focus to; tabindex=-1 lets the panel itself take focus when
|
|
14
|
+
it contains nothing focusable, so Tab cannot leave a modal dialog. -->
|
|
15
|
+
<div class="{{ panelClasses }}" data-stx-dialog-panel tabindex="-1">
|
|
13
16
|
<slot />
|
|
14
17
|
</div>
|
|
15
18
|
</div>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export const className = $props.className || ''
|
|
3
3
|
export const as = $props.as || 'h3'
|
|
4
4
|
|
|
5
|
-
const baseClasses = 'text-lg font-medium leading-6 text-
|
|
5
|
+
const baseClasses = 'text-lg font-medium leading-6 text-fg'
|
|
6
6
|
const titleClasses = `${baseClasses} ${className}`.trim()
|
|
7
7
|
</script>
|
|
8
8
|
|
package/src/ui/dialog/README.md
CHANGED
|
@@ -111,11 +111,22 @@ function openModal() {
|
|
|
111
111
|
|
|
112
112
|
## Features
|
|
113
113
|
|
|
114
|
-
- Focus trap
|
|
115
|
-
|
|
116
|
-
-
|
|
114
|
+
- Focus trap: Tab and Shift+Tab cycle within the panel, and focus is pulled
|
|
115
|
+
back in if it is outside
|
|
116
|
+
- Initial focus into the panel on open, restored to whatever opened it on close
|
|
117
|
+
- Body scroll lock while open, with the scrollbar's width replaced as padding
|
|
118
|
+
so the page does not jump sideways
|
|
119
|
+
- Escape closes it, bound on the document so it works before you click into
|
|
120
|
+
the dialog
|
|
121
|
+
- Backdrop overlay, and clicking it closes the dialog
|
|
117
122
|
- Dark mode support
|
|
118
|
-
- Accessible (WAI-ARIA)
|
|
123
|
+
- Accessible (WAI-ARIA): `role="dialog"` with `aria-modal="true"`, which the
|
|
124
|
+
focus trap above makes true rather than merely asserted
|
|
119
125
|
- Customizable with headwind classes
|
|
120
126
|
- Multiple sizes
|
|
121
127
|
- Scrollable content support
|
|
128
|
+
|
|
129
|
+
This list was aspirational until stacksjs/stx#1973 and #1978: the focus trap,
|
|
130
|
+
the scroll lock, the focus restore and a working Escape were all documented
|
|
131
|
+
here and none was implemented. They are pinned now by
|
|
132
|
+
`test/dialog-modal-behaviour.test.ts`, which drives the real runtime.
|
package/src/ui/drawer/Drawer.stx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script server>
|
|
2
|
-
export const open = $props.open
|
|
2
|
+
export const open = $bool($props.open)
|
|
3
3
|
export const position = $props.position || 'right'
|
|
4
4
|
export const title = $props.title || ''
|
|
5
5
|
export const className = $props.className || ''
|
|
@@ -7,7 +7,7 @@ export const className = $props.className || ''
|
|
|
7
7
|
/*
|
|
8
8
|
* The surface, left to the app.
|
|
9
9
|
*
|
|
10
|
-
* The panel painted itself `bg-
|
|
10
|
+
* The panel painted itself `bg-panel` and offered no way
|
|
11
11
|
* to say otherwise, so a drawer in an app with its own palette arrived as a
|
|
12
12
|
* white rectangle with the app's colours inside it - the one element on the
|
|
13
13
|
* screen that belongs to no theme. `className` did not help: it lands on the
|
|
@@ -19,7 +19,7 @@ export const className = $props.className || ''
|
|
|
19
19
|
*/
|
|
20
20
|
export const panelClass = $props.panelClass || ''
|
|
21
21
|
export const panelStyle = $props.panelStyle || ''
|
|
22
|
-
export const backdropClass = $props.backdropClass || 'bg-
|
|
22
|
+
export const backdropClass = $props.backdropClass || 'bg-neutral-500/75 dark:bg-neutral-900/75'
|
|
23
23
|
|
|
24
24
|
const positionClasses = {
|
|
25
25
|
right: 'inset-y-0 right-0 pl-10 sm:pl-16',
|
|
@@ -28,10 +28,37 @@ const positionClasses = {
|
|
|
28
28
|
bottom: 'inset-x-0 bottom-0 pt-10',
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
/*
|
|
32
|
+
* `size` widens a side drawer without the app having to know that the width
|
|
33
|
+
* lives on the wrapper rather than the panel. Ignored for top/bottom, which
|
|
34
|
+
* are constrained by height instead.
|
|
35
|
+
*
|
|
36
|
+
* Spelled out as a map because the class name has to exist as a literal in
|
|
37
|
+
* this file. It was built by interpolation - `max-w-${size}` - which means the
|
|
38
|
+
* string `max-w-xl` appeared nowhere in the source tree, so a content-scanning
|
|
39
|
+
* CSS engine never saw it and emitted no rule for it. The panel then fell back
|
|
40
|
+
* to `w-screen`: full width, the one thing `size` is there to prevent. The
|
|
41
|
+
* default worked, because `'max-w-md'` was a literal in that same expression,
|
|
42
|
+
* so the prop was broken only once you passed it (stacksjs/stx#2002).
|
|
43
|
+
*/
|
|
44
|
+
export const size = $props.size || 'md'
|
|
45
|
+
|
|
46
|
+
const widthClasses = {
|
|
47
|
+
xs: 'max-w-xs',
|
|
48
|
+
sm: 'max-w-sm',
|
|
49
|
+
md: 'max-w-md',
|
|
50
|
+
lg: 'max-w-lg',
|
|
51
|
+
xl: 'max-w-xl',
|
|
52
|
+
'2xl': 'max-w-2xl',
|
|
53
|
+
'3xl': 'max-w-3xl',
|
|
54
|
+
'4xl': 'max-w-4xl',
|
|
55
|
+
'5xl': 'max-w-5xl',
|
|
56
|
+
'6xl': 'max-w-6xl',
|
|
57
|
+
'7xl': 'max-w-7xl',
|
|
58
|
+
full: 'max-w-full',
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const width = widthClasses[size] || widthClasses.md
|
|
35
62
|
|
|
36
63
|
const sizeClasses = {
|
|
37
64
|
right: `${width} w-screen`,
|
|
@@ -47,9 +74,33 @@ const closeButtonPosition = {
|
|
|
47
74
|
bottom: 'right-0 -mr-8',
|
|
48
75
|
}
|
|
49
76
|
|
|
50
|
-
export const containerClasses = `pointer-events-none fixed ${positionClasses[position]} flex max-w-full`.trim()
|
|
51
|
-
export const panelClasses = `pointer-events-auto relative ${sizeClasses[position]} ${className}`.trim()
|
|
52
|
-
export const closeButtonClasses = `absolute top-0 ${closeButtonPosition[position]} flex pt-4 pr-2 sm:pr-4`.trim()
|
|
77
|
+
export const containerClasses = `pointer-events-none fixed ${positionClasses[position] || positionClasses.right} flex max-w-full`.trim()
|
|
78
|
+
export const panelClasses = `pointer-events-auto relative ${sizeClasses[position] || sizeClasses.right} ${className}`.trim()
|
|
79
|
+
export const closeButtonClasses = `absolute top-0 ${closeButtonPosition[position] || closeButtonPosition.right} flex pt-4 pr-2 sm:pr-4`.trim()
|
|
80
|
+
|
|
81
|
+
/*
|
|
82
|
+
* Which slide-in to run, decided here rather than in the stylesheet.
|
|
83
|
+
*
|
|
84
|
+
* There was one `@keyframes slideIn` whose `from` transform was a mustache
|
|
85
|
+
* over `position`. A component style block is lifted out of the source before
|
|
86
|
+
* expressions run, so that mustache shipped verbatim, the declaration was
|
|
87
|
+
* invalid, and the browser dropped it - leaving an empty 0% frame. The panel
|
|
88
|
+
* did not slide in from its edge, it appeared in place, and nothing reported
|
|
89
|
+
* it (stacksjs/stx#1982). `fadeIn` in the same block was fine, because it had
|
|
90
|
+
* nothing to interpolate.
|
|
91
|
+
*
|
|
92
|
+
* So the four offsets are four static keyframes and the choice is an animation
|
|
93
|
+
* NAME in a style attribute, which is an ordinary attribute and does
|
|
94
|
+
* interpolate.
|
|
95
|
+
*/
|
|
96
|
+
const slideAnimations = {
|
|
97
|
+
right: 'slideInRight',
|
|
98
|
+
left: 'slideInLeft',
|
|
99
|
+
top: 'slideInTop',
|
|
100
|
+
bottom: 'slideInBottom',
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const slideAnimation = slideAnimations[position] || slideAnimations.right
|
|
53
104
|
|
|
54
105
|
/*
|
|
55
106
|
* This drawer's own id.
|
|
@@ -240,17 +291,17 @@ defineExpose({
|
|
|
240
291
|
<div class="{{ containerClasses }}">
|
|
241
292
|
<div
|
|
242
293
|
class="{{ panelClasses }}"
|
|
243
|
-
style="animation:
|
|
294
|
+
style="animation: {{ slideAnimation }} 0.5s ease-in-out"
|
|
244
295
|
data-stx-drawer-panel="{{ drawerInstanceId }}"
|
|
245
296
|
role="dialog"
|
|
246
297
|
aria-modal="true"
|
|
247
|
-
|
|
298
|
+
aria-label="{{ title }}"
|
|
248
299
|
tabindex="-1"
|
|
249
300
|
>
|
|
250
301
|
<div class="{{ closeButtonClasses }}">
|
|
251
302
|
<button
|
|
252
303
|
type="button"
|
|
253
|
-
class="relative rounded-
|
|
304
|
+
class="relative rounded-control text-neutral-300 dark:text-neutral-400 hover:text-white dark:hover:text-white focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
|
254
305
|
@click="close()"
|
|
255
306
|
>
|
|
256
307
|
<span class="absolute -inset-2.5"></span>
|
|
@@ -261,7 +312,7 @@ defineExpose({
|
|
|
261
312
|
</button>
|
|
262
313
|
</div>
|
|
263
314
|
|
|
264
|
-
<div class="relative flex h-full flex-col overflow-y-auto {{ panelClass || 'bg-
|
|
315
|
+
<div class="relative flex h-full flex-col overflow-y-auto {{ panelClass || 'bg-panel' }} py-6 shadow-xl" style="{{ panelStyle }}">
|
|
265
316
|
@if(title)
|
|
266
317
|
<div class="px-4 sm:px-6">
|
|
267
318
|
<h2 class="text-base font-semibold text-fg">
|
|
@@ -285,12 +336,26 @@ defineExpose({
|
|
|
285
336
|
to { opacity: 1; }
|
|
286
337
|
}
|
|
287
338
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
339
|
+
/* One per edge, so nothing in here needs interpolating. A mustache inside a
|
|
340
|
+
component style block is always dead: it is extracted before
|
|
341
|
+
expressions run. */
|
|
342
|
+
@keyframes slideInRight {
|
|
343
|
+
from { transform: translateX(100%); }
|
|
344
|
+
to { transform: translate(0, 0); }
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
@keyframes slideInLeft {
|
|
348
|
+
from { transform: translateX(-100%); }
|
|
349
|
+
to { transform: translate(0, 0); }
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
@keyframes slideInTop {
|
|
353
|
+
from { transform: translateY(-100%); }
|
|
354
|
+
to { transform: translate(0, 0); }
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
@keyframes slideInBottom {
|
|
358
|
+
from { transform: translateY(100%); }
|
|
359
|
+
to { transform: translate(0, 0); }
|
|
295
360
|
}
|
|
296
361
|
</style>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<script server>
|
|
2
2
|
export const className = $props.className || ''
|
|
3
3
|
export const as = $props.as || 'button'
|
|
4
|
-
export const disabled = $props.disabled
|
|
4
|
+
export const disabled = $bool($props.disabled)
|
|
5
5
|
|
|
6
|
-
const baseClasses = 'inline-flex justify-center items-center rounded-
|
|
6
|
+
const baseClasses = 'inline-flex justify-center items-center rounded-control focus:outline-none focus-visible:ring-2 focus-visible:ring-white/75'
|
|
7
7
|
export const buttonClasses = `${baseClasses} ${className}`.trim()
|
|
8
8
|
</script>
|
|
9
9
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script server>
|
|
2
2
|
export const className = $props.className || ''
|
|
3
3
|
export const as = $props.as || 'div'
|
|
4
|
-
export const disabled = $props.disabled
|
|
4
|
+
export const disabled = $bool($props.disabled)
|
|
5
5
|
export const value = $props.value
|
|
6
6
|
|
|
7
7
|
const baseClasses = 'group flex w-full items-center px-2 py-2 text-sm transition-colors text-fg hover:bg-blue-500 hover:text-white dark:hover:bg-blue-600'
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export const className = $props.className || ''
|
|
3
3
|
export const as = $props.as || 'div'
|
|
4
4
|
|
|
5
|
-
const baseClasses = 'absolute z-10 mt-2 origin-top-right divide-y divide-neutral-100 rounded-
|
|
5
|
+
const baseClasses = 'absolute z-10 mt-2 origin-top-right divide-y divide-neutral-100 rounded-panel bg-white shadow-lg ring-1 ring-black/5 focus:outline-none dark:bg-neutral-800 dark:divide-neutral-700 dark:ring-neutral-600'
|
|
6
6
|
export const itemsClasses = `${baseClasses} ${className}`.trim()
|
|
7
7
|
</script>
|
|
8
8
|
|
|
@@ -7,7 +7,7 @@ export const radius = $props.radius || 20
|
|
|
7
7
|
export const blur = $props.blur || 15
|
|
8
8
|
export const opacity = $props.opacity || 0.6
|
|
9
9
|
export const showLegend = $props.showLegend !== false
|
|
10
|
-
export const interactive = $props.interactive
|
|
10
|
+
export const interactive = $bool($props.interactive)
|
|
11
11
|
export const dataSource = $props.dataSource || 'auto'
|
|
12
12
|
export const endpoint = $props.endpoint || ''
|
|
13
13
|
export const colorScheme = $props.colorScheme || 'default'
|
package/src/ui/image/Image.stx
CHANGED
|
@@ -7,7 +7,7 @@ export const webpSrcSet = $props.webpSrcSet || ''
|
|
|
7
7
|
export const alt = $props.alt || ''
|
|
8
8
|
export const width = $props.width
|
|
9
9
|
export const height = $props.height
|
|
10
|
-
export const priority = $props.priority
|
|
10
|
+
export const priority = $bool($props.priority)
|
|
11
11
|
export const lazy = priority ? false : ($props.lazy ?? true)
|
|
12
12
|
export const decoding = $props.decoding || 'async'
|
|
13
13
|
export const fetchpriority = priority ? 'high' : ($props.fetchpriority || 'auto')
|
|
@@ -25,8 +25,8 @@ export const placeholder = $props.placeholder || ''
|
|
|
25
25
|
export const aspectRatio = $props.aspectRatio
|
|
26
26
|
export const objectFit = $props.objectFit || 'cover'
|
|
27
27
|
export const objectPosition = $props.objectPosition || 'center'
|
|
28
|
-
export const rounded = $props.rounded
|
|
29
|
-
export const zoomOnHover = $props.zoomOnHover
|
|
28
|
+
export const rounded = $bool($props.rounded)
|
|
29
|
+
export const zoomOnHover = $bool($props.zoomOnHover)
|
|
30
30
|
export const className = $props.className || ''
|
|
31
31
|
|
|
32
32
|
export const hasWebP = !!(webpSrc || webpSrcSet)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
<script server>
|
|
2
2
|
export const value = $props.value || ''
|
|
3
3
|
export const placeholder = $props.placeholder || 'Enter your email'
|
|
4
|
-
export const disabled = $props.disabled
|
|
5
|
-
export const readonly = $props.readonly
|
|
4
|
+
export const disabled = $bool($props.disabled)
|
|
5
|
+
export const readonly = $bool($props.readonly)
|
|
6
6
|
export const size = $props.size || 'md'
|
|
7
|
-
export const error = $props.error
|
|
7
|
+
export const error = $bool($props.error)
|
|
8
8
|
export const label = $props.label || ''
|
|
9
9
|
export const helperText = $props.helperText || ''
|
|
10
|
-
export const required = $props.required
|
|
10
|
+
export const required = $bool($props.required)
|
|
11
11
|
export const className = $props.className || ''
|
|
12
12
|
|
|
13
13
|
export const emailIcon = '<svg fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" /></svg>'
|
|
@@ -1,33 +1,43 @@
|
|
|
1
1
|
<script server>
|
|
2
2
|
export const value = $props.value || ''
|
|
3
3
|
export const placeholder = $props.placeholder || '0'
|
|
4
|
-
export const disabled = $props.disabled
|
|
5
|
-
export const readonly = $props.readonly
|
|
4
|
+
export const disabled = $bool($props.disabled)
|
|
5
|
+
export const readonly = $bool($props.readonly)
|
|
6
6
|
export const size = $props.size || 'md'
|
|
7
|
-
export const error = $props.error
|
|
7
|
+
export const error = $bool($props.error)
|
|
8
8
|
export const label = $props.label || ''
|
|
9
9
|
export const helperText = $props.helperText || ''
|
|
10
|
-
export const required = $props.required
|
|
10
|
+
export const required = $bool($props.required)
|
|
11
11
|
export const min = $props.min
|
|
12
12
|
export const max = $props.max
|
|
13
13
|
export const step = $props.step || 1
|
|
14
|
-
export const showControls = $props.showControls
|
|
14
|
+
export const showControls = $bool($props.showControls, true)
|
|
15
15
|
export const className = $props.className || ''
|
|
16
16
|
export const inputClassName = $props.inputClassName || ''
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
/*
|
|
19
|
+
* Padding decides the height here too, with no `h-*` to override it: an app
|
|
20
|
+
* passing its own `py-1.5` got the padding it asked for and the height it did
|
|
21
|
+
* not, and `className` cannot beat `h-10` at equal specificity
|
|
22
|
+
* (stacksjs/stx#1993).
|
|
23
|
+
*
|
|
24
|
+
* `lg` also needed a padding step adjusted - py-3 around a 1.75rem line-height
|
|
25
|
+
* is 3.25rem of content inside a declared 3rem box - so py-2.5 lands on the
|
|
26
|
+
* 3rem it always claimed. sm and md were already exact.
|
|
27
|
+
*/
|
|
28
|
+
const sizeClasses = { sm: 'px-3 py-1.5 text-sm', md: 'px-4 py-2 text-base', lg: 'px-5 py-2.5 text-lg' }
|
|
29
|
+
const baseClasses = 'block w-full border-0 rounded-control shadow-sm ring-1 ring-inset transition-colors duration-200 focus:ring-2 focus:ring-inset dark:bg-neutral-700 dark:text-neutral-100'
|
|
20
30
|
const stateClasses = error
|
|
21
|
-
? 'ring-
|
|
31
|
+
? 'ring-danger-line text-danger-fg placeholder-danger-fg-subtle focus:ring-danger-focus'
|
|
22
32
|
: 'ring-line-strong text-fg placeholder-fg-subtle focus:ring-accent'
|
|
23
33
|
const disabledClasses = disabled
|
|
24
34
|
? 'opacity-50 cursor-not-allowed bg-surface'
|
|
25
35
|
: readonly
|
|
26
36
|
? 'bg-surface cursor-default'
|
|
27
|
-
: 'bg-
|
|
37
|
+
: 'bg-field'
|
|
28
38
|
const paddingClasses = showControls ? 'pr-10' : ''
|
|
29
39
|
|
|
30
|
-
export const inputClasses = `${baseClasses} ${sizeClasses[size]} ${stateClasses} ${disabledClasses} ${paddingClasses} ${inputClassName}`.trim()
|
|
40
|
+
export const inputClasses = `${baseClasses} ${sizeClasses[size] || sizeClasses.md} ${stateClasses} ${disabledClasses} ${paddingClasses} ${inputClassName}`.trim()
|
|
31
41
|
export const labelClasses = `block text-sm font-medium leading-6 mb-2 ${error ? 'text-danger' : 'text-fg'}`.trim()
|
|
32
42
|
export const helperClasses = `mt-2 text-sm ${error ? 'text-danger' : 'text-fg-soft'}`.trim()
|
|
33
43
|
</script>
|
|
@@ -69,7 +79,7 @@ defineExpose({ value: inputValue, increment, decrement })
|
|
|
69
79
|
<label for="number-input" class="{{ labelClasses }}">
|
|
70
80
|
{{ label }}
|
|
71
81
|
@if(required)
|
|
72
|
-
<span class="text-
|
|
82
|
+
<span class="text-danger ml-1">*</span>
|
|
73
83
|
@endif
|
|
74
84
|
</label>
|
|
75
85
|
@endif
|