@thekestongroup/ui 0.2.1 → 0.3.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/README.md +90 -32
- package/dist/components/Age/Age.vue.d.ts +19 -0
- package/dist/components/AppShell/AppShell.vue.d.ts +108 -0
- package/dist/components/Avatar/Avatar.vue.d.ts +34 -0
- package/dist/components/AvatarGroup/AvatarGroup.vue.d.ts +25 -0
- package/dist/components/Badge/Badge.vue.d.ts +41 -0
- package/dist/components/Breadcrumb/Breadcrumb.vue.d.ts +39 -0
- package/dist/components/Button/Button.vue.d.ts +69 -0
- package/dist/components/Calendar/Calendar.vue.d.ts +34 -0
- package/dist/components/Card/Card.vue.d.ts +56 -0
- package/dist/components/Checkbox/Checkbox.vue.d.ts +40 -0
- package/dist/components/Checklist/Checklist.vue.d.ts +18 -0
- package/dist/components/Chip/Chip.vue.d.ts +44 -0
- package/dist/components/Divider/Divider.vue.d.ts +36 -0
- package/dist/components/{ToastItem.vue.d.ts → FormField/FieldMessage.vue.d.ts} +10 -2
- package/dist/components/FormField/FormField.vue.d.ts +61 -0
- package/dist/components/Header/Header.vue.d.ts +104 -0
- package/dist/components/InfoTip/InfoTip.vue.d.ts +20 -0
- package/dist/components/Input/Input.vue.d.ts +56 -0
- package/dist/components/InputCode/InputCode.vue.d.ts +53 -0
- package/dist/components/InputDate/InputDate.vue.d.ts +49 -0
- package/dist/components/InputNumber/InputNumber.vue.d.ts +44 -0
- package/dist/components/InputPassword/InputPassword.vue.d.ts +51 -0
- package/dist/components/InputRichText/InputRichText.vue.d.ts +44 -0
- package/dist/components/Link/Link.vue.d.ts +39 -0
- package/dist/components/Notification/Notification.vue.d.ts +62 -0
- package/dist/components/Notification/NotificationPane.vue.d.ts +38 -0
- package/dist/components/Notification/Toaster.vue.d.ts +51 -0
- package/dist/components/Notification/notification.samples.d.ts +3 -0
- package/dist/components/Notification/notifications.d.ts +115 -0
- package/dist/components/PageHeader/PageHeader.vue.d.ts +43 -0
- package/dist/components/Popover/Popover.vue.d.ts +83 -0
- package/dist/components/Popover/popover.d.ts +16 -0
- package/dist/components/Progress/Progress.vue.d.ts +26 -0
- package/dist/components/RadioGroup/RadioGroup.vue.d.ts +45 -0
- package/dist/components/RelativeTime/RelativeTime.vue.d.ts +22 -0
- package/dist/components/Select/Select.vue.d.ts +110 -0
- package/dist/components/Sidebar/Sidebar.vue.d.ts +106 -0
- package/dist/components/Sidebar/sidebar.d.ts +10 -0
- package/dist/components/Slideover/Slideover.vue.d.ts +125 -0
- package/dist/components/Spinner/Spinner.vue.d.ts +30 -0
- package/dist/components/StatTile/StatTile.vue.d.ts +46 -0
- package/dist/components/SummaryList/SummaryList.vue.d.ts +62 -0
- package/dist/components/Switch/Switch.vue.d.ts +39 -0
- package/dist/components/Table/Table.vue.d.ts +82 -0
- package/dist/components/Table/table.d.ts +36 -0
- package/dist/components/Tooltip/Tooltip.vue.d.ts +46 -0
- package/dist/index.d.ts +89 -25
- package/dist/keston-ui.js +4963 -14785
- package/dist/lib/cn.d.ts +4 -0
- package/dist/lib/dates.d.ts +27 -0
- package/dist/lib/initials.d.ts +2 -0
- package/dist/lib/parseDate.d.ts +44 -0
- package/dist/lib/useNow.d.ts +3 -0
- package/package.json +53 -24
- package/src/components/.gitkeep +0 -0
- package/src/components/Age/Age.stories.ts +24 -0
- package/src/components/Age/Age.vue +56 -0
- package/src/components/AppShell/AppShell.stories.ts +124 -0
- package/src/components/AppShell/AppShell.vue +212 -0
- package/src/components/Avatar/Avatar.stories.ts +56 -0
- package/src/components/Avatar/Avatar.vue +118 -0
- package/src/components/AvatarGroup/AvatarGroup.stories.ts +47 -0
- package/src/components/AvatarGroup/AvatarGroup.vue +97 -0
- package/src/components/Badge/Badge.stories.ts +92 -0
- package/src/components/Badge/Badge.vue +67 -0
- package/src/components/Breadcrumb/Breadcrumb.stories.ts +58 -0
- package/src/components/Breadcrumb/Breadcrumb.vue +109 -0
- package/src/components/Button/Button.mdx +79 -0
- package/src/components/Button/Button.stories.ts +207 -0
- package/src/components/Button/Button.vue +266 -0
- package/src/components/Calendar/Calendar.stories.ts +51 -0
- package/src/components/Calendar/Calendar.vue +364 -0
- package/src/components/Card/Card.stories.ts +109 -0
- package/src/components/Card/Card.vue +115 -0
- package/src/components/Checkbox/Checkbox.stories.ts +102 -0
- package/src/components/Checkbox/Checkbox.vue +102 -0
- package/src/components/Checklist/Checklist.stories.ts +67 -0
- package/src/components/Checklist/Checklist.vue +38 -0
- package/src/components/Chip/Chip.stories.ts +71 -0
- package/src/components/Chip/Chip.vue +86 -0
- package/src/components/Divider/Divider.stories.ts +57 -0
- package/src/components/Divider/Divider.vue +58 -0
- package/src/components/FormField/FieldMessage.vue +81 -0
- package/src/components/FormField/FormField.stories.ts +55 -0
- package/src/components/FormField/FormField.vue +160 -0
- package/src/components/Header/Header.stories.ts +168 -0
- package/src/components/Header/Header.vue +232 -0
- package/src/components/InfoTip/InfoTip.stories.ts +63 -0
- package/src/components/InfoTip/InfoTip.vue +50 -0
- package/src/components/Input/Input.stories.ts +206 -0
- package/src/components/Input/Input.vue +90 -0
- package/src/components/InputCode/InputCode.stories.ts +85 -0
- package/src/components/InputCode/InputCode.vue +145 -0
- package/src/components/InputDate/InputDate.stories.ts +58 -0
- package/src/components/InputDate/InputDate.vue +258 -0
- package/src/components/InputNumber/InputNumber.stories.ts +63 -0
- package/src/components/InputNumber/InputNumber.vue +109 -0
- package/src/components/InputPassword/InputPassword.stories.ts +105 -0
- package/src/components/InputPassword/InputPassword.vue +132 -0
- package/src/components/InputRichText/InputRichText.stories.ts +100 -0
- package/src/components/InputRichText/InputRichText.vue +194 -0
- package/src/components/Link/Link.stories.ts +73 -0
- package/src/components/Link/Link.vue +56 -0
- package/src/components/Notification/Notification.stories.ts +196 -0
- package/src/components/Notification/Notification.vue +136 -0
- package/src/components/Notification/NotificationPane.vue +187 -0
- package/src/components/Notification/Toaster.vue +446 -0
- package/src/components/Notification/notification.samples.ts +45 -0
- package/src/components/Notification/notifications.test.ts +99 -0
- package/src/components/Notification/notifications.ts +172 -0
- package/src/components/PageHeader/PageHeader.stories.ts +79 -0
- package/src/components/PageHeader/PageHeader.vue +66 -0
- package/src/components/Popover/Popover.stories.ts +135 -0
- package/src/components/Popover/Popover.vue +192 -0
- package/src/components/Popover/popover.ts +20 -0
- package/src/components/Progress/Progress.stories.ts +74 -0
- package/src/components/Progress/Progress.vue +75 -0
- package/src/components/RadioGroup/RadioGroup.stories.ts +90 -0
- package/src/components/RadioGroup/RadioGroup.vue +132 -0
- package/src/components/RelativeTime/RelativeTime.stories.ts +74 -0
- package/src/components/RelativeTime/RelativeTime.vue +51 -0
- package/src/components/Select/Select.mdx +202 -0
- package/src/components/Select/Select.stories.ts +223 -0
- package/src/components/Select/Select.vue +630 -0
- package/src/components/Sidebar/Sidebar.stories.ts +192 -0
- package/src/components/Sidebar/Sidebar.vue +382 -0
- package/src/components/Sidebar/sidebar.ts +20 -0
- package/src/components/Slideover/Slideover.stories.ts +225 -0
- package/src/components/Slideover/Slideover.vue +365 -0
- package/src/components/Spinner/Spinner.stories.ts +79 -0
- package/src/components/Spinner/Spinner.vue +97 -0
- package/src/components/StatTile/StatTile.stories.ts +75 -0
- package/src/components/StatTile/StatTile.vue +89 -0
- package/src/components/SummaryList/SummaryList.stories.ts +103 -0
- package/src/components/SummaryList/SummaryList.vue +127 -0
- package/src/components/Switch/Switch.stories.ts +100 -0
- package/src/components/Switch/Switch.vue +96 -0
- package/src/components/Table/Table.stories.ts +206 -0
- package/src/components/Table/Table.vue +220 -0
- package/src/components/Table/table.test.ts +65 -0
- package/src/components/Table/table.ts +70 -0
- package/src/components/Tooltip/Tooltip.stories.ts +57 -0
- package/src/components/Tooltip/Tooltip.vue +86 -0
- package/src/examples/AppPages.stories.ts +500 -0
- package/src/examples/FormLayout.stories.ts +185 -0
- package/src/examples/KestonIdPages.stories.ts +415 -0
- package/src/examples/SchoolPages.stories.ts +665 -0
- package/src/index.ts +114 -36
- package/src/lib/cn.ts +4 -0
- package/src/lib/dates.test.ts +68 -0
- package/src/lib/dates.ts +86 -0
- package/src/lib/initials.ts +8 -0
- package/src/lib/parseDate.test.ts +331 -0
- package/src/lib/parseDate.ts +561 -0
- package/src/lib/useNow.ts +20 -0
- package/src/styles/theme.css +101 -0
- package/dist/components/AppLauncher.vue.d.ts +0 -10
- package/dist/components/Avatar.vue.d.ts +0 -16
- package/dist/components/Button.vue.d.ts +0 -27
- package/dist/components/Checkbox.vue.d.ts +0 -18
- package/dist/components/CloseButton.vue.d.ts +0 -6
- package/dist/components/Dialog.vue.d.ts +0 -23
- package/dist/components/Drawer.vue.d.ts +0 -34
- package/dist/components/DropdownMenu.vue.d.ts +0 -21
- package/dist/components/DropdownMenuItem.vue.d.ts +0 -19
- package/dist/components/DropdownMenuSeparator.vue.d.ts +0 -6
- package/dist/components/Input.vue.d.ts +0 -14
- package/dist/components/Label.vue.d.ts +0 -16
- package/dist/components/NotificationsMenu.vue.d.ts +0 -3
- package/dist/components/Popover.vue.d.ts +0 -23
- package/dist/components/ProfileSwitcher.vue.d.ts +0 -24
- package/dist/components/Select.vue.d.ts +0 -28
- package/dist/components/Separator.vue.d.ts +0 -11
- package/dist/components/ToastRenderer.vue.d.ts +0 -3
- package/dist/components/Toaster.vue.d.ts +0 -3
- package/dist/components/Tooltip.vue.d.ts +0 -23
- package/dist/components/TopBar.vue.d.ts +0 -34
- package/dist/favicon-old.svg +0 -1
- package/dist/favicon.svg +0 -1
- package/dist/keston-ui.cjs +0 -15
- package/dist/lib/toast.d.ts +0 -29
- package/dist/lib/types.d.ts +0 -5
- package/src/components/AppLauncher.vue +0 -63
- package/src/components/Avatar.vue +0 -51
- package/src/components/Button.vue +0 -54
- package/src/components/Checkbox.vue +0 -47
- package/src/components/CloseButton.vue +0 -24
- package/src/components/Dialog.vue +0 -65
- package/src/components/Drawer.vue +0 -202
- package/src/components/DropdownMenu.vue +0 -41
- package/src/components/DropdownMenuItem.vue +0 -28
- package/src/components/DropdownMenuSeparator.vue +0 -12
- package/src/components/Input.vue +0 -21
- package/src/components/Label.vue +0 -15
- package/src/components/NotificationsMenu.vue +0 -115
- package/src/components/Popover.vue +0 -46
- package/src/components/ProfileSwitcher.vue +0 -113
- package/src/components/Select.vue +0 -97
- package/src/components/Separator.vue +0 -30
- package/src/components/ToastItem.vue +0 -158
- package/src/components/ToastRenderer.vue +0 -113
- package/src/components/Toaster.vue +0 -11
- package/src/components/Tooltip.vue +0 -48
- package/src/components/TopBar.vue +0 -52
- package/src/lib/toast.ts +0 -95
- package/src/lib/types.ts +0 -5
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, watch, type HTMLAttributes } from 'vue'
|
|
3
|
+
import { DatePickerContent, DatePickerRoot, DatePickerTrigger } from 'reka-ui'
|
|
4
|
+
import { getLocalTimeZone, parseDate, today, type DateValue } from '@internationalized/date'
|
|
5
|
+
import { CalendarDays } from '@lucide/vue'
|
|
6
|
+
import FormField, { type FormFieldStatus } from '../FormField/FormField.vue'
|
|
7
|
+
import Calendar from '../Calendar/Calendar.vue'
|
|
8
|
+
import { popoverContent } from '../Popover/popover'
|
|
9
|
+
import { parseDateText, type DatePart, type DatePreference } from '../../lib/parseDate'
|
|
10
|
+
|
|
11
|
+
// Attributes like name and placeholder go to the text <input>, not the wrapper.
|
|
12
|
+
defineOptions({ inheritAttrs: false })
|
|
13
|
+
|
|
14
|
+
export interface InputDateProps {
|
|
15
|
+
/** Visible label. Always set it: it is also the field's accessible name. */
|
|
16
|
+
label: string
|
|
17
|
+
/** Extra guidance about what to enter. */
|
|
18
|
+
helper?: string
|
|
19
|
+
/** Show helper text under the label, or behind a `?` icon next to it. */
|
|
20
|
+
helperPlacement?: 'below' | 'icon'
|
|
21
|
+
/** Error message, e.g. from a Zod schema. Overrides `status` / `statusText`. */
|
|
22
|
+
errorText?: string
|
|
23
|
+
/** Colours the field and the status text. */
|
|
24
|
+
status?: FormFieldStatus
|
|
25
|
+
/** Message under the field. */
|
|
26
|
+
statusText?: string
|
|
27
|
+
/** Earliest allowed date, as `YYYY-MM-DD`. */
|
|
28
|
+
min?: string
|
|
29
|
+
/** Latest allowed date, as `YYYY-MM-DD`. */
|
|
30
|
+
max?: string
|
|
31
|
+
/** Sets the order of day / month / year and the calendar's language. */
|
|
32
|
+
locale?: string
|
|
33
|
+
/**
|
|
34
|
+
* How typed dates that don't say which year, month or week are read
|
|
35
|
+
* ("5th march", "the 5th", "tuesday", "christmas"): 'future' (default)
|
|
36
|
+
* picks the next one, 'past' the last one, 'nearest' the closest. Use
|
|
37
|
+
* 'past' for things that already happened, e.g. an incident date.
|
|
38
|
+
*/
|
|
39
|
+
prefer?: DatePreference
|
|
40
|
+
disabled?: boolean
|
|
41
|
+
class?: HTMLAttributes['class']
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const props = withDefaults(defineProps<InputDateProps>(), {
|
|
45
|
+
helperPlacement: 'below',
|
|
46
|
+
locale: 'en-GB',
|
|
47
|
+
prefer: 'future'
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
/** The date as `YYYY-MM-DD`, or undefined when empty or incomplete. */
|
|
51
|
+
const model = defineModel<string | undefined>()
|
|
52
|
+
|
|
53
|
+
// Reka works with date objects; the component's value is a plain ISO string,
|
|
54
|
+
// which is easy to validate (e.g. with Zod) and send to a server.
|
|
55
|
+
function toDate(iso: string | undefined): DateValue | undefined {
|
|
56
|
+
if (!iso) return undefined
|
|
57
|
+
try {
|
|
58
|
+
return parseDate(iso)
|
|
59
|
+
} catch {
|
|
60
|
+
return undefined
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const dateValue = computed(() => toDate(model.value))
|
|
65
|
+
const minValue = computed(() => toDate(props.min))
|
|
66
|
+
const maxValue = computed(() => toDate(props.max))
|
|
67
|
+
|
|
68
|
+
// ── Range check ─────────────────────────────────────────────────────────────
|
|
69
|
+
// A typed date outside min / max is still passed to the model (so the form
|
|
70
|
+
// can see it), but the field explains what is allowed. errorText and
|
|
71
|
+
// status / statusText override this.
|
|
72
|
+
function formatDate(date: DateValue) {
|
|
73
|
+
return new Intl.DateTimeFormat(props.locale, { dateStyle: 'long' }).format(
|
|
74
|
+
new Date(date.year, date.month - 1, date.day)
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const rangeError = computed(() => {
|
|
79
|
+
const value = dateValue.value
|
|
80
|
+
if (!value) return undefined
|
|
81
|
+
const min = minValue.value
|
|
82
|
+
const max = maxValue.value
|
|
83
|
+
const tooEarly = min && value.compare(min) < 0
|
|
84
|
+
const tooLate = max && value.compare(max) > 0
|
|
85
|
+
if (!tooEarly && !tooLate) return undefined
|
|
86
|
+
if (min && max) return `Choose a date from ${formatDate(min)} to ${formatDate(max)}`
|
|
87
|
+
if (min) return `Choose a date on or after ${formatDate(min)}`
|
|
88
|
+
return `Choose a date on or before ${formatDate(max!)}`
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
// ── Typed text ──────────────────────────────────────────────────────────────
|
|
92
|
+
// The field is a plain text box. A date typed in almost any form ("26/01/2009",
|
|
93
|
+
// "5th of december", "tmrw", "monday week" …, see src/lib/parseDate.ts) sets
|
|
94
|
+
// the value straight away; on leaving the field it is tidied to 26/01/2009.
|
|
95
|
+
// Anything else leaves the value undefined and, once the user leaves the
|
|
96
|
+
// field, shows an example.
|
|
97
|
+
const shortFormat = computed(
|
|
98
|
+
() => new Intl.DateTimeFormat(props.locale, { day: '2-digit', month: '2-digit', year: 'numeric' })
|
|
99
|
+
)
|
|
100
|
+
// Day / month / year order and separator for the locale, e.g. en-GB → d/m/y.
|
|
101
|
+
const sample = computed(() => shortFormat.value.formatToParts(new Date(2009, 0, 26)))
|
|
102
|
+
const order = computed(
|
|
103
|
+
() => sample.value.filter((part) => part.type === 'day' || part.type === 'month' || part.type === 'year').map((part) => part.type) as DatePart[]
|
|
104
|
+
)
|
|
105
|
+
const separator = computed(() => sample.value.find((part) => part.type === 'literal')?.value ?? '/')
|
|
106
|
+
const placeholderText = computed(() =>
|
|
107
|
+
order.value.map((part) => ({ day: 'dd', month: 'mm', year: 'yyyy' })[part]).join(separator.value)
|
|
108
|
+
)
|
|
109
|
+
const example = computed(() => shortFormat.value.format(new Date(2009, 0, 26)))
|
|
110
|
+
|
|
111
|
+
function formatShort(date: DateValue) {
|
|
112
|
+
return shortFormat.value.format(new Date(date.year, date.month - 1, date.day))
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// The words and formats understood are listed in src/lib/parseDate.ts.
|
|
116
|
+
function parseText(input: string) {
|
|
117
|
+
return parseDateText(input, {
|
|
118
|
+
today: today(getLocalTimeZone()),
|
|
119
|
+
order: order.value,
|
|
120
|
+
prefer: props.prefer
|
|
121
|
+
})
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const text = ref(dateValue.value ? formatShort(dateValue.value) : '')
|
|
125
|
+
|
|
126
|
+
// While words are typed ("tmrw", "26 jan 2009"), show the date they mean
|
|
127
|
+
// inside the field. Purely numeric text doesn't need it.
|
|
128
|
+
const phrasePreview = computed(() => {
|
|
129
|
+
if (!/[a-z]/i.test(text.value)) return undefined
|
|
130
|
+
const date = parseText(text.value)
|
|
131
|
+
return date ? formatShort(date) : undefined
|
|
132
|
+
})
|
|
133
|
+
const formatError = ref<string>()
|
|
134
|
+
// The last value this text box set, so its own updates don't rewrite the text
|
|
135
|
+
// mid-typing; changes from elsewhere (calendar, parent) do update it.
|
|
136
|
+
let lastFromText: string | undefined = model.value
|
|
137
|
+
|
|
138
|
+
watch(model, (value) => {
|
|
139
|
+
if (value === lastFromText) return
|
|
140
|
+
lastFromText = value
|
|
141
|
+
const date = toDate(value)
|
|
142
|
+
text.value = date ? formatShort(date) : ''
|
|
143
|
+
formatError.value = undefined
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
function onTextInput() {
|
|
147
|
+
const date = parseText(text.value)
|
|
148
|
+
const value = date?.toString()
|
|
149
|
+
lastFromText = value
|
|
150
|
+
model.value = value
|
|
151
|
+
// Once an error is showing, clear it as soon as the text becomes valid.
|
|
152
|
+
if (formatError.value && (date || !text.value.trim())) formatError.value = undefined
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function onTextBlur() {
|
|
156
|
+
if (!text.value.trim()) {
|
|
157
|
+
formatError.value = undefined
|
|
158
|
+
return
|
|
159
|
+
}
|
|
160
|
+
const date = parseText(text.value)
|
|
161
|
+
if (date) {
|
|
162
|
+
text.value = formatShort(date)
|
|
163
|
+
formatError.value = undefined
|
|
164
|
+
} else {
|
|
165
|
+
formatError.value = `Enter a date like ${example.value}`
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Enter first settles the text, like leaving the field: "tmrw" or "26/1"
|
|
170
|
+
// becomes the full date it means, and the form isn't submitted. Once the text
|
|
171
|
+
// already shows that date (or is empty), Enter does its usual job, e.g.
|
|
172
|
+
// submitting the form. Text that isn't a date shows the example and stays.
|
|
173
|
+
function onTextEnter(event: KeyboardEvent) {
|
|
174
|
+
if (event.isComposing || !text.value.trim()) return
|
|
175
|
+
const date = parseText(text.value)
|
|
176
|
+
if (date && text.value === formatShort(date)) return
|
|
177
|
+
event.preventDefault()
|
|
178
|
+
onTextBlur()
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// errorText is handled by FormField; then status / statusText, the format check
|
|
182
|
+
// and the range check.
|
|
183
|
+
const fieldError = computed(() => formatError.value ?? rangeError.value)
|
|
184
|
+
const status = computed(() => props.status ?? (fieldError.value ? 'error' : undefined))
|
|
185
|
+
const statusText = computed(() => props.statusText ?? fieldError.value)
|
|
186
|
+
|
|
187
|
+
// ── Calendar ────────────────────────────────────────────────────────────────
|
|
188
|
+
// Opens on the chosen date (or today, or the nearest allowed date); choosing
|
|
189
|
+
// a day closes it. Reka's DatePicker is used only for the popover, so the
|
|
190
|
+
// chosen day (or today) gets focus when it opens.
|
|
191
|
+
const open = ref(false)
|
|
192
|
+
|
|
193
|
+
function onCalendarPick(value: string | undefined) {
|
|
194
|
+
model.value = value
|
|
195
|
+
open.value = false
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Calendar button: a full-height square segment at the right of the box, like
|
|
199
|
+
// InputNumber's + button. Negative margins cancel the box's padding.
|
|
200
|
+
const trigger = [
|
|
201
|
+
'flex w-9 shrink-0 -my-2 -mr-3 self-stretch items-center justify-center',
|
|
202
|
+
'rounded-r border-l border-black/15 bg-white cursor-pointer transition',
|
|
203
|
+
'not-disabled:hover:brightness-90 not-disabled:active:brightness-80 [&_svg]:opacity-100!',
|
|
204
|
+
'data-[state=open]:brightness-90 disabled:cursor-not-allowed',
|
|
205
|
+
'outline-2 -outline-offset-2 outline-transparent focus-visible:outline-focus'
|
|
206
|
+
]
|
|
207
|
+
</script>
|
|
208
|
+
|
|
209
|
+
<template>
|
|
210
|
+
<FormField
|
|
211
|
+
:label="label"
|
|
212
|
+
:helper="helper"
|
|
213
|
+
:helper-placement="helperPlacement"
|
|
214
|
+
:error-text="errorText"
|
|
215
|
+
:status="status"
|
|
216
|
+
:status-text="statusText"
|
|
217
|
+
:disabled="disabled"
|
|
218
|
+
:class="props.class"
|
|
219
|
+
>
|
|
220
|
+
<template #default="{ id, describedBy, invalid }">
|
|
221
|
+
<DatePickerRoot v-model:open="open" :disabled="disabled">
|
|
222
|
+
<!-- Plain text box: type or paste the whole date, e.g. 26/01/2009. -->
|
|
223
|
+
<input
|
|
224
|
+
:id="id"
|
|
225
|
+
v-model="text"
|
|
226
|
+
type="text"
|
|
227
|
+
autocomplete="off"
|
|
228
|
+
:placeholder="placeholderText"
|
|
229
|
+
v-bind="$attrs"
|
|
230
|
+
:disabled="disabled"
|
|
231
|
+
:aria-invalid="invalid"
|
|
232
|
+
:aria-describedby="describedBy"
|
|
233
|
+
class="h-5 min-w-0 flex-1 bg-transparent tabular-nums outline-none placeholder:text-black/55 disabled:cursor-not-allowed"
|
|
234
|
+
@input="onTextInput"
|
|
235
|
+
@blur="onTextBlur"
|
|
236
|
+
@keydown.enter="onTextEnter"
|
|
237
|
+
/>
|
|
238
|
+
|
|
239
|
+
<!-- The date a typed phrase means, e.g. "tmrw" → 11/11/2026. -->
|
|
240
|
+
<span v-if="phrasePreview" aria-hidden="true" class="shrink-0 tabular-nums text-black/55">
|
|
241
|
+
{{ phrasePreview }}
|
|
242
|
+
</span>
|
|
243
|
+
|
|
244
|
+
<DatePickerTrigger aria-label="Open calendar" :class="trigger">
|
|
245
|
+
<CalendarDays />
|
|
246
|
+
</DatePickerTrigger>
|
|
247
|
+
|
|
248
|
+
<DatePickerContent
|
|
249
|
+
:side-offset="6"
|
|
250
|
+
align="end"
|
|
251
|
+
:class="[popoverContent, 'p-3']"
|
|
252
|
+
>
|
|
253
|
+
<Calendar :model-value="model" :min="min" :max="max" :locale="locale" @update:model-value="onCalendarPick" />
|
|
254
|
+
</DatePickerContent>
|
|
255
|
+
</DatePickerRoot>
|
|
256
|
+
</template>
|
|
257
|
+
</FormField>
|
|
258
|
+
</template>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
|
2
|
+
import { ref } from "vue";
|
|
3
|
+
import InputNumber from "./InputNumber.vue";
|
|
4
|
+
|
|
5
|
+
const meta = {
|
|
6
|
+
title: "Components/Form/InputNumber",
|
|
7
|
+
component: InputNumber,
|
|
8
|
+
tags: ["autodocs"],
|
|
9
|
+
argTypes: {
|
|
10
|
+
helperPlacement: { options: ["below", "icon"], control: { type: "inline-radio" } },
|
|
11
|
+
status: { options: [undefined, "error", "success"], control: { type: "inline-radio" } },
|
|
12
|
+
},
|
|
13
|
+
args: {
|
|
14
|
+
label: "Quantity",
|
|
15
|
+
helperPlacement: "below",
|
|
16
|
+
step: 1,
|
|
17
|
+
disabled: false,
|
|
18
|
+
},
|
|
19
|
+
decorators: [() => ({ template: '<div class="max-w-50"><story /></div>' })],
|
|
20
|
+
render: (args) => ({
|
|
21
|
+
components: { InputNumber },
|
|
22
|
+
setup() {
|
|
23
|
+
const value = ref<number | undefined>(1);
|
|
24
|
+
return { args, value };
|
|
25
|
+
},
|
|
26
|
+
template: `
|
|
27
|
+
<InputNumber v-bind="args" v-model="value" />
|
|
28
|
+
<small class="mt-3 block text-xs text-black/60">
|
|
29
|
+
Value: {{ value === undefined ? "undefined" : value }}
|
|
30
|
+
</small>`,
|
|
31
|
+
}),
|
|
32
|
+
} satisfies Meta<typeof InputNumber>;
|
|
33
|
+
|
|
34
|
+
export default meta;
|
|
35
|
+
type Story = StoryObj<typeof meta>;
|
|
36
|
+
|
|
37
|
+
/** Playground: use the controls below. */
|
|
38
|
+
export const Default: Story = {};
|
|
39
|
+
|
|
40
|
+
/** − is disabled at 0 and + at 10. */
|
|
41
|
+
export const MinAndMax: Story = {
|
|
42
|
+
args: { label: "Siblings at the school", min: 0, max: 10, helper: "Between 0 and 10." },
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const StepOfFive: Story = {
|
|
46
|
+
args: { label: "Lesson length (minutes)", min: 0, max: 120, step: 5 },
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const Currency: Story = {
|
|
50
|
+
args: {
|
|
51
|
+
label: "Trip cost",
|
|
52
|
+
min: 0,
|
|
53
|
+
step: 0.5,
|
|
54
|
+
locale: "en-GB",
|
|
55
|
+
formatOptions: { style: "currency", currency: "GBP" },
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const WithError: Story = {
|
|
60
|
+
args: { label: "Year group", min: 7, max: 13, errorText: "Choose a year group from 7 to 13" },
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const Disabled: Story = { args: { disabled: true } };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, type HTMLAttributes } from 'vue'
|
|
3
|
+
import { NumberFieldDecrement, NumberFieldIncrement, NumberFieldInput, NumberFieldRoot } from 'reka-ui'
|
|
4
|
+
import { Minus, Plus } from '@lucide/vue'
|
|
5
|
+
import FormField, { type FormFieldStatus } from '../FormField/FormField.vue'
|
|
6
|
+
|
|
7
|
+
// Attributes like placeholder and name go to the <input>, not the wrapper.
|
|
8
|
+
defineOptions({ inheritAttrs: false })
|
|
9
|
+
|
|
10
|
+
export interface InputNumberProps {
|
|
11
|
+
/** Visible label. Always set it: it is also the input's accessible name. */
|
|
12
|
+
label: string
|
|
13
|
+
/** Extra guidance about what to enter. */
|
|
14
|
+
helper?: string
|
|
15
|
+
/** Show helper text under the label, or behind a `?` icon next to it. */
|
|
16
|
+
helperPlacement?: 'below' | 'icon'
|
|
17
|
+
/** Error message, e.g. from a Zod schema. Overrides `status` / `statusText`. */
|
|
18
|
+
errorText?: string
|
|
19
|
+
/** Colours the field and the status text. */
|
|
20
|
+
status?: FormFieldStatus
|
|
21
|
+
/** Message under the field. */
|
|
22
|
+
statusText?: string
|
|
23
|
+
/** Lowest allowed value. The − button is disabled when reached. */
|
|
24
|
+
min?: number
|
|
25
|
+
/** Highest allowed value. The + button is disabled when reached. */
|
|
26
|
+
max?: number
|
|
27
|
+
/** How much − / + and the arrow keys change the value. */
|
|
28
|
+
step?: number
|
|
29
|
+
/** How the number is displayed, e.g. `{ style: 'currency', currency: 'GBP' }`. */
|
|
30
|
+
formatOptions?: Intl.NumberFormatOptions
|
|
31
|
+
/** Locale for formatting. Defaults to the browser's. */
|
|
32
|
+
locale?: string
|
|
33
|
+
disabled?: boolean
|
|
34
|
+
class?: HTMLAttributes['class']
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const props = withDefaults(defineProps<InputNumberProps>(), {
|
|
38
|
+
helperPlacement: 'below',
|
|
39
|
+
step: 1
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
/** The number, or undefined when the field is empty. */
|
|
43
|
+
const model = defineModel<number | undefined>()
|
|
44
|
+
|
|
45
|
+
// What screen readers say for the value. Without it, VoiceOver reads a number
|
|
46
|
+
// field that has a min and max as a percentage of that range (year group 9 of
|
|
47
|
+
// 7–13 → "33%"). This is the number as displayed, e.g. "9" or "£12.50".
|
|
48
|
+
const valueText = computed(() =>
|
|
49
|
+
model.value === undefined
|
|
50
|
+
? undefined
|
|
51
|
+
: new Intl.NumberFormat(props.locale, props.formatOptions).format(model.value)
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
// The − / + buttons are full-height square segments at each end of the box,
|
|
55
|
+
// split from the value by a divider, so the field looks like
|
|
56
|
+
// [ − | value | + ]. Negative margins cancel the box's padding (px-3 py-2), so
|
|
57
|
+
// each button is 36×36 inside the 38px box. They behave like a basic Button:
|
|
58
|
+
// white fill that darkens on hover / press, icon at full colour (the box mutes
|
|
59
|
+
// decorative icons). When disabled (min / max reached) only the icon fades.
|
|
60
|
+
const stepButton = [
|
|
61
|
+
'flex w-9 shrink-0 -my-2 self-stretch items-center justify-center bg-white cursor-pointer transition',
|
|
62
|
+
'not-disabled:hover:brightness-90 not-disabled:active:brightness-80 [&_svg]:opacity-100!',
|
|
63
|
+
'disabled:cursor-not-allowed disabled:[&_svg]:opacity-40!'
|
|
64
|
+
]
|
|
65
|
+
const decrement = '-ml-3 rounded-l border-r border-black/15'
|
|
66
|
+
const increment = '-mr-3 rounded-r border-l border-black/15'
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<template>
|
|
70
|
+
<FormField
|
|
71
|
+
:label="label"
|
|
72
|
+
:helper="helper"
|
|
73
|
+
:helper-placement="helperPlacement"
|
|
74
|
+
:error-text="errorText"
|
|
75
|
+
:status="status"
|
|
76
|
+
:status-text="statusText"
|
|
77
|
+
:disabled="disabled"
|
|
78
|
+
:class="$props.class"
|
|
79
|
+
>
|
|
80
|
+
<template #default="{ id, describedBy, invalid }">
|
|
81
|
+
<!-- `contents` lets the buttons and input sit directly in the box's row. -->
|
|
82
|
+
<NumberFieldRoot
|
|
83
|
+
:id="id"
|
|
84
|
+
v-model="model"
|
|
85
|
+
:min="min"
|
|
86
|
+
:max="max"
|
|
87
|
+
:step="step"
|
|
88
|
+
:format-options="formatOptions"
|
|
89
|
+
:locale="locale"
|
|
90
|
+
:disabled="disabled"
|
|
91
|
+
class="contents"
|
|
92
|
+
>
|
|
93
|
+
<NumberFieldDecrement :class="[stepButton, decrement]">
|
|
94
|
+
<Minus />
|
|
95
|
+
</NumberFieldDecrement>
|
|
96
|
+
<NumberFieldInput
|
|
97
|
+
v-bind="$attrs"
|
|
98
|
+
:aria-invalid="invalid"
|
|
99
|
+
:aria-describedby="describedBy"
|
|
100
|
+
:aria-valuetext="valueText"
|
|
101
|
+
class="h-5 min-w-0 flex-1 bg-transparent text-center tabular-nums outline-none placeholder:text-black/55 disabled:cursor-not-allowed"
|
|
102
|
+
/>
|
|
103
|
+
<NumberFieldIncrement :class="[stepButton, increment]">
|
|
104
|
+
<Plus />
|
|
105
|
+
</NumberFieldIncrement>
|
|
106
|
+
</NumberFieldRoot>
|
|
107
|
+
</template>
|
|
108
|
+
</FormField>
|
|
109
|
+
</template>
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/vue3-vite";
|
|
2
|
+
import { Lock } from "@lucide/vue";
|
|
3
|
+
import { ref } from "vue";
|
|
4
|
+
import Button from "../Button/Button.vue";
|
|
5
|
+
import Input from "../Input/Input.vue";
|
|
6
|
+
import InputPassword, { type InputPasswordProps } from "./InputPassword.vue";
|
|
7
|
+
|
|
8
|
+
// Story-only controls on top of the real props.
|
|
9
|
+
type InputPasswordStoryArgs = InputPasswordProps & {
|
|
10
|
+
placeholder: string;
|
|
11
|
+
autocomplete: "current-password" | "new-password";
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const meta = {
|
|
15
|
+
title: "Components/Form/InputPassword",
|
|
16
|
+
component: InputPassword,
|
|
17
|
+
tags: ["autodocs"],
|
|
18
|
+
argTypes: {
|
|
19
|
+
placeholder: { control: "text", table: { category: "Content" } },
|
|
20
|
+
autocomplete: {
|
|
21
|
+
options: ["current-password", "new-password"],
|
|
22
|
+
control: { type: "inline-radio" },
|
|
23
|
+
table: { category: "Attributes" },
|
|
24
|
+
},
|
|
25
|
+
helperPlacement: { options: ["below", "icon"], control: { type: "inline-radio" } },
|
|
26
|
+
status: { options: [undefined, "error", "success", "loading"], control: { type: "inline-radio" } },
|
|
27
|
+
},
|
|
28
|
+
args: {
|
|
29
|
+
label: "Password",
|
|
30
|
+
placeholder: "",
|
|
31
|
+
helper: "",
|
|
32
|
+
helperPlacement: "below",
|
|
33
|
+
autocomplete: "current-password",
|
|
34
|
+
disabled: false,
|
|
35
|
+
},
|
|
36
|
+
decorators: [() => ({ template: '<div class="max-w-80"><story /></div>' })],
|
|
37
|
+
render: (args) => ({
|
|
38
|
+
components: { InputPassword },
|
|
39
|
+
setup: () => ({ args, value: ref("") }),
|
|
40
|
+
template: `<InputPassword v-bind="args" v-model="value" />`,
|
|
41
|
+
}),
|
|
42
|
+
} satisfies Meta<InputPasswordStoryArgs>;
|
|
43
|
+
|
|
44
|
+
export default meta;
|
|
45
|
+
type Story = StoryObj<typeof meta>;
|
|
46
|
+
|
|
47
|
+
/** Playground: type, then press the eye to show or hide the password. Turn Caps Lock on to see the note. */
|
|
48
|
+
export const Default: Story = {};
|
|
49
|
+
|
|
50
|
+
/** Choosing a password: `autocomplete="new-password"` lets password managers suggest and save one. */
|
|
51
|
+
export const NewPassword: Story = {
|
|
52
|
+
args: {
|
|
53
|
+
label: "New password",
|
|
54
|
+
helper: "At least 12 characters. A few unrelated words works well.",
|
|
55
|
+
autocomplete: "new-password",
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export const WithLeadingIcon: Story = {
|
|
60
|
+
render: (args) => ({
|
|
61
|
+
components: { InputPassword, Lock },
|
|
62
|
+
setup: () => ({ args, value: ref("") }),
|
|
63
|
+
template: `
|
|
64
|
+
<InputPassword v-bind="args" v-model="value">
|
|
65
|
+
<template #leading><Lock /></template>
|
|
66
|
+
</InputPassword>`,
|
|
67
|
+
}),
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/** `errorText`, e.g. after a failed sign-in. It replaces the Caps Lock note. */
|
|
71
|
+
export const WithErrorText: Story = {
|
|
72
|
+
args: { errorText: "Incorrect password" },
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
export const Disabled: Story = { args: { disabled: true } };
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A sign-in form. Show the password, then press Sign in: it's hidden again
|
|
79
|
+
* when the form is submitted.
|
|
80
|
+
*/
|
|
81
|
+
export const SignInForm: Story = {
|
|
82
|
+
render: () => ({
|
|
83
|
+
components: { InputPassword, Input, Button },
|
|
84
|
+
setup() {
|
|
85
|
+
const email = ref("");
|
|
86
|
+
const password = ref("");
|
|
87
|
+
const error = ref<string>();
|
|
88
|
+
const submitting = ref(false);
|
|
89
|
+
async function signIn() {
|
|
90
|
+
error.value = undefined;
|
|
91
|
+
submitting.value = true;
|
|
92
|
+
await new Promise((resolve) => setTimeout(resolve, 800));
|
|
93
|
+
submitting.value = false;
|
|
94
|
+
if (password.value !== "correct horse") error.value = "Incorrect email or password";
|
|
95
|
+
}
|
|
96
|
+
return { email, password, error, submitting, signIn };
|
|
97
|
+
},
|
|
98
|
+
template: `
|
|
99
|
+
<form class="flex flex-col gap-4" @submit.prevent="signIn">
|
|
100
|
+
<Input v-model="email" label="Email" type="email" autocomplete="username" />
|
|
101
|
+
<InputPassword v-model="password" label="Password" :error-text="error" />
|
|
102
|
+
<Button type="submit" variant="primary" :status="submitting ? 'loading' : 'idle'" loading-text="Signing in">Sign in</Button>
|
|
103
|
+
</form>`,
|
|
104
|
+
}),
|
|
105
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, onBeforeUnmount, onMounted, ref, useAttrs, type HTMLAttributes } from 'vue'
|
|
3
|
+
import { Eye, EyeOff } from '@lucide/vue'
|
|
4
|
+
import FormField, { type FormFieldStatus } from '../FormField/FormField.vue'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A password field: Input with a Show / Hide button at the end, a "Caps Lock
|
|
8
|
+
* is on" note while typing, and the password hidden again when its form is
|
|
9
|
+
* submitted (so it's never left on screen, and password managers still see
|
|
10
|
+
* a password field).
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Attributes like name, autocomplete and placeholder go to the <input>.
|
|
14
|
+
defineOptions({ inheritAttrs: false })
|
|
15
|
+
|
|
16
|
+
export type InputPasswordStatus = FormFieldStatus
|
|
17
|
+
|
|
18
|
+
export interface InputPasswordProps {
|
|
19
|
+
/** Visible label. Always set it: it is also the input's accessible name. */
|
|
20
|
+
label: string
|
|
21
|
+
/** Extra guidance, e.g. the password rules when choosing a new one. */
|
|
22
|
+
helper?: string
|
|
23
|
+
/** Show helper text under the label, or behind a `?` icon next to it. */
|
|
24
|
+
helperPlacement?: 'below' | 'icon'
|
|
25
|
+
/**
|
|
26
|
+
* Error message, e.g. from a Zod / VeeValidate schema or "Incorrect
|
|
27
|
+
* password". When set (and not empty) the field shows as an error with this
|
|
28
|
+
* text. Overrides `status`, `statusText` and the Caps Lock note.
|
|
29
|
+
*/
|
|
30
|
+
errorText?: string
|
|
31
|
+
/** Colours the field and the status text. */
|
|
32
|
+
status?: InputPasswordStatus
|
|
33
|
+
/** Message under the field. Overrides the Caps Lock note. */
|
|
34
|
+
statusText?: string
|
|
35
|
+
disabled?: boolean
|
|
36
|
+
class?: HTMLAttributes['class']
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const props = withDefaults(defineProps<InputPasswordProps>(), {
|
|
40
|
+
helperPlacement: 'below'
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const model = defineModel<string>({ default: '' })
|
|
44
|
+
const attrs = useAttrs()
|
|
45
|
+
|
|
46
|
+
// Signing in is the common case; pass autocomplete="new-password" when
|
|
47
|
+
// choosing one, so password managers offer to generate and save it.
|
|
48
|
+
const autocomplete = computed(() => (attrs.autocomplete as string | undefined) ?? 'current-password')
|
|
49
|
+
|
|
50
|
+
const input = ref<HTMLInputElement>()
|
|
51
|
+
const visible = ref(false)
|
|
52
|
+
|
|
53
|
+
// ── Hide on submit ──────────────────────────────────────────────────────────
|
|
54
|
+
// Submitting with the password shown would leave it on screen, and some
|
|
55
|
+
// password managers only save fields that are type="password".
|
|
56
|
+
const hide = () => (visible.value = false)
|
|
57
|
+
let form: HTMLFormElement | null = null
|
|
58
|
+
onMounted(() => {
|
|
59
|
+
form = input.value?.form ?? null
|
|
60
|
+
form?.addEventListener('submit', hide)
|
|
61
|
+
})
|
|
62
|
+
onBeforeUnmount(() => form?.removeEventListener('submit', hide))
|
|
63
|
+
|
|
64
|
+
// ── Caps Lock ───────────────────────────────────────────────────────────────
|
|
65
|
+
// Browsers only report Caps Lock on key and pointer events, so the note shows
|
|
66
|
+
// from the first key press and clears when the field loses focus.
|
|
67
|
+
const capsLock = ref(false)
|
|
68
|
+
function checkCapsLock(event: KeyboardEvent) {
|
|
69
|
+
capsLock.value = event.getModifierState?.('CapsLock') ?? false
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const statusText = computed(() => props.statusText ?? (capsLock.value ? 'Caps Lock is on' : undefined))
|
|
73
|
+
|
|
74
|
+
// Same square end segment as InputNumber's + button, so the field reads
|
|
75
|
+
// [ password | 👁 ]. Pressing it keeps focus (and the caret) in the input.
|
|
76
|
+
const toggle = [
|
|
77
|
+
'flex w-9 shrink-0 -my-2 -mr-3 self-stretch items-center justify-center',
|
|
78
|
+
'bg-white rounded-r border-l border-black/15 cursor-pointer transition',
|
|
79
|
+
'not-disabled:hover:brightness-90 not-disabled:active:brightness-80 [&_svg]:opacity-100!',
|
|
80
|
+
'outline-none focus-visible:bg-black/5 disabled:cursor-not-allowed'
|
|
81
|
+
]
|
|
82
|
+
</script>
|
|
83
|
+
|
|
84
|
+
<template>
|
|
85
|
+
<FormField
|
|
86
|
+
:label="label"
|
|
87
|
+
:helper="helper"
|
|
88
|
+
:helper-placement="helperPlacement"
|
|
89
|
+
:error-text="errorText"
|
|
90
|
+
:status="status"
|
|
91
|
+
:status-text="statusText"
|
|
92
|
+
:disabled="disabled"
|
|
93
|
+
:class="props.class"
|
|
94
|
+
>
|
|
95
|
+
<template v-if="$slots.leading" #leading><slot name="leading" /></template>
|
|
96
|
+
<!-- e.g. "Forgot password?": shown by the label, reached by Tab after the field. -->
|
|
97
|
+
<template v-if="$slots['label-trailing']" #label-trailing><slot name="label-trailing" /></template>
|
|
98
|
+
<template #default="{ id, describedBy, invalid }">
|
|
99
|
+
<input
|
|
100
|
+
:id="id"
|
|
101
|
+
ref="input"
|
|
102
|
+
v-model="model"
|
|
103
|
+
v-bind="$attrs"
|
|
104
|
+
:type="visible ? 'text' : 'password'"
|
|
105
|
+
:autocomplete="autocomplete"
|
|
106
|
+
autocapitalize="off"
|
|
107
|
+
autocorrect="off"
|
|
108
|
+
spellcheck="false"
|
|
109
|
+
:disabled="disabled"
|
|
110
|
+
:aria-invalid="invalid"
|
|
111
|
+
:aria-describedby="describedBy"
|
|
112
|
+
class="h-5 min-w-0 flex-1 bg-transparent outline-none placeholder:text-black/55 disabled:cursor-not-allowed"
|
|
113
|
+
@keydown="checkCapsLock"
|
|
114
|
+
@keyup="checkCapsLock"
|
|
115
|
+
@blur="capsLock = false"
|
|
116
|
+
/>
|
|
117
|
+
<button
|
|
118
|
+
type="button"
|
|
119
|
+
:class="toggle"
|
|
120
|
+
:aria-controls="id"
|
|
121
|
+
:aria-pressed="visible"
|
|
122
|
+
:disabled="disabled"
|
|
123
|
+
@pointerdown.prevent
|
|
124
|
+
@click="visible = !visible"
|
|
125
|
+
>
|
|
126
|
+
<span class="sr-only">Show password</span>
|
|
127
|
+
<EyeOff v-if="visible" aria-hidden="true" />
|
|
128
|
+
<Eye v-else aria-hidden="true" />
|
|
129
|
+
</button>
|
|
130
|
+
</template>
|
|
131
|
+
</FormField>
|
|
132
|
+
</template>
|