@strategicos/ui 0.7.0 → 0.9.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 +51 -2
- package/THIRD_PARTY_NOTICES.md +187 -0
- package/dist/components/calendar.d.ts +24 -0
- package/dist/components/calendar.d.ts.map +1 -0
- package/dist/components/calendar.js +81 -0
- package/dist/components/calendar.js.map +1 -0
- package/dist/components/combobox.d.ts +73 -0
- package/dist/components/combobox.d.ts.map +1 -0
- package/dist/components/combobox.js +193 -0
- package/dist/components/combobox.js.map +1 -0
- package/dist/components/date-input.d.ts +46 -0
- package/dist/components/date-input.d.ts.map +1 -0
- package/dist/components/date-input.js +202 -0
- package/dist/components/date-input.js.map +1 -0
- package/dist/components/date-picker-input.d.ts +49 -0
- package/dist/components/date-picker-input.d.ts.map +1 -0
- package/dist/components/date-picker-input.js +126 -0
- package/dist/components/date-picker-input.js.map +1 -0
- package/dist/components/date-time-picker.d.ts +27 -0
- package/dist/components/date-time-picker.d.ts.map +1 -0
- package/dist/components/date-time-picker.js +77 -0
- package/dist/components/date-time-picker.js.map +1 -0
- package/dist/components/dates.d.ts +94 -0
- package/dist/components/dates.d.ts.map +1 -0
- package/dist/components/dates.js +94 -0
- package/dist/components/dates.js.map +1 -0
- package/dist/components/multi-select.d.ts.map +1 -1
- package/dist/components/multi-select.js +2 -1
- package/dist/components/multi-select.js.map +1 -1
- package/dist/components/select.d.ts +16 -1
- package/dist/components/select.d.ts.map +1 -1
- package/dist/components/select.js +24 -2
- package/dist/components/select.js.map +1 -1
- package/dist/components/time-input.d.ts +16 -0
- package/dist/components/time-input.d.ts.map +1 -0
- package/dist/components/time-input.js +18 -0
- package/dist/components/time-input.js.map +1 -0
- package/package.json +2 -1
- package/src/components/calendar.tsx +139 -0
- package/src/components/combobox.tsx +390 -0
- package/src/components/date-input.tsx +287 -0
- package/src/components/date-picker-input.tsx +287 -0
- package/src/components/date-time-picker.tsx +152 -0
- package/src/components/dates.tsx +274 -0
- package/src/components/multi-select.tsx +3 -1
- package/src/components/select.tsx +29 -1
- package/src/components/time-input.tsx +34 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
// Derivado do DatePicker do Tremor (Apache-2.0) e modificado pela Strategicos.
|
|
4
|
+
// Ver THIRD_PARTY_NOTICES.md.
|
|
5
|
+
|
|
6
|
+
import * as React from "react"
|
|
7
|
+
|
|
8
|
+
import { Calendar } from "./calendar.js"
|
|
9
|
+
import {
|
|
10
|
+
clampDate, formatDateTime, outOfRange, parseDateValue, toDateValue,
|
|
11
|
+
PickerFooter, PickerTrigger, type PickerBaseProps,
|
|
12
|
+
} from "./dates.js"
|
|
13
|
+
import { useFieldControl } from "./field.js"
|
|
14
|
+
import { Popover, PopoverContent } from "./popover.js"
|
|
15
|
+
import { TimeInput } from "./time-input.js"
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Data e hora num calendário com campo de hora, como o DateTimePicker do
|
|
19
|
+
* Mantine. Para digitar a data e a hora direto, `DateInput withTime`.
|
|
20
|
+
*
|
|
21
|
+
* <Field label="Reunião">
|
|
22
|
+
* <DateTimePicker value={inicio} onValueChange={setInicio} />
|
|
23
|
+
* </Field>
|
|
24
|
+
*
|
|
25
|
+
* - Valor: "AAAA-MM-DD HH:mm:ss" ou `null`.
|
|
26
|
+
* - `withApplyButton` vem LIGADO (o botão de confirmar do Mantine): escolhe-se
|
|
27
|
+
* o dia e a hora e grava-se no Aplicar. Desligado, cada mudança já grava e o
|
|
28
|
+
* calendário fica aberto até sair dele.
|
|
29
|
+
* - `defaultTime`: hora usada quando ainda não há valor. Padrão: 00:00.
|
|
30
|
+
* - `minDate`/`maxDate` limitam o DIA ("AAAA-MM-DD").
|
|
31
|
+
*/
|
|
32
|
+
function DateTimePicker({
|
|
33
|
+
value,
|
|
34
|
+
onValueChange,
|
|
35
|
+
placeholder = "Selecione data e hora",
|
|
36
|
+
minDate,
|
|
37
|
+
maxDate,
|
|
38
|
+
clearable = false,
|
|
39
|
+
withApplyButton = true,
|
|
40
|
+
withSeconds = false,
|
|
41
|
+
defaultTime = "00:00",
|
|
42
|
+
valueFormatter = formatDateTime,
|
|
43
|
+
captionLayout,
|
|
44
|
+
size,
|
|
45
|
+
disabled,
|
|
46
|
+
className,
|
|
47
|
+
wrapperClassName,
|
|
48
|
+
align = "start",
|
|
49
|
+
onOpenChange,
|
|
50
|
+
...props
|
|
51
|
+
}: PickerBaseProps & {
|
|
52
|
+
value: string | null
|
|
53
|
+
onValueChange: (value: string | null) => void
|
|
54
|
+
/** Campo de hora com segundos. */
|
|
55
|
+
withSeconds?: boolean
|
|
56
|
+
/** "HH:mm" usada quando ainda não há valor. */
|
|
57
|
+
defaultTime?: string
|
|
58
|
+
}) {
|
|
59
|
+
const controlProps = useFieldControl(props, { withRequired: false })
|
|
60
|
+
const [open, setOpen] = React.useState(false)
|
|
61
|
+
const [draft, setDraft] = React.useState<string | null>(value)
|
|
62
|
+
// A hora existe antes do dia: dá para acertá-la e escolher o dia depois.
|
|
63
|
+
const [time, setTime] = React.useState(() => timeOf(value, defaultTime))
|
|
64
|
+
const shown = withApplyButton ? draft : value
|
|
65
|
+
|
|
66
|
+
const selected = parseDateValue(shown)
|
|
67
|
+
const committed = parseDateValue(value)
|
|
68
|
+
const min = parseDateValue(minDate)
|
|
69
|
+
const max = parseDateValue(maxDate)
|
|
70
|
+
|
|
71
|
+
function handleOpenChange(o: boolean) {
|
|
72
|
+
setOpen(o)
|
|
73
|
+
if (o) { setDraft(value); setTime(timeOf(value, defaultTime)) }
|
|
74
|
+
onOpenChange?.(o)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function update(v: string) {
|
|
78
|
+
if (withApplyButton) setDraft(v)
|
|
79
|
+
else onValueChange(v)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// `time` é sempre "HH:mm:ss" (timeOf e changeTime completam).
|
|
83
|
+
function pickDay(day: Date) {
|
|
84
|
+
update(`${toDateValue(day)} ${time}`)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function changeTime(t: string) {
|
|
88
|
+
// O campo nativo devolve "" enquanto a hora está pela metade.
|
|
89
|
+
if (!/^\d{2}:\d{2}(:\d{2})?$/.test(t)) return
|
|
90
|
+
const full = t.length === 5 ? `${t}:00` : t
|
|
91
|
+
setTime(full)
|
|
92
|
+
if (shown) update(`${shown.slice(0, 10)} ${full}`)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function apply() {
|
|
96
|
+
if (draft !== value) onValueChange(draft)
|
|
97
|
+
handleOpenChange(false)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<Popover open={open} onOpenChange={handleOpenChange}>
|
|
102
|
+
<PickerTrigger
|
|
103
|
+
slot="date-time-picker"
|
|
104
|
+
text={committed ? valueFormatter(committed) : null}
|
|
105
|
+
placeholder={placeholder}
|
|
106
|
+
open={open}
|
|
107
|
+
size={size}
|
|
108
|
+
disabled={disabled}
|
|
109
|
+
clearable={clearable}
|
|
110
|
+
onClear={() => onValueChange(null)}
|
|
111
|
+
className={className}
|
|
112
|
+
wrapperClassName={wrapperClassName}
|
|
113
|
+
controlProps={controlProps}
|
|
114
|
+
/>
|
|
115
|
+
<PopoverContent align={align} className="w-auto max-w-[calc(100vw-2rem)] p-0" onOpenAutoFocus={e => e.preventDefault()}>
|
|
116
|
+
<Calendar
|
|
117
|
+
mode="single"
|
|
118
|
+
required
|
|
119
|
+
autoFocus
|
|
120
|
+
selected={selected}
|
|
121
|
+
onSelect={pickDay}
|
|
122
|
+
defaultMonth={selected ?? clampDate(new Date(), min, max)}
|
|
123
|
+
startMonth={min}
|
|
124
|
+
endMonth={max}
|
|
125
|
+
disabled={outOfRange(min, max)}
|
|
126
|
+
captionLayout={captionLayout}
|
|
127
|
+
/>
|
|
128
|
+
<PickerFooter
|
|
129
|
+
onCancel={withApplyButton ? () => handleOpenChange(false) : undefined}
|
|
130
|
+
onApply={withApplyButton ? apply : undefined}
|
|
131
|
+
applyDisabled={!draft}
|
|
132
|
+
>
|
|
133
|
+
<TimeInput
|
|
134
|
+
aria-label="Hora"
|
|
135
|
+
withSeconds={withSeconds}
|
|
136
|
+
value={withSeconds ? time : time.slice(0, 5)}
|
|
137
|
+
onChange={e => changeTime(e.target.value)}
|
|
138
|
+
className="w-32"
|
|
139
|
+
/>
|
|
140
|
+
</PickerFooter>
|
|
141
|
+
</PopoverContent>
|
|
142
|
+
</Popover>
|
|
143
|
+
)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** "HH:mm:ss" do valor, ou a hora padrão. */
|
|
147
|
+
function timeOf(value: string | null, defaultTime: string) {
|
|
148
|
+
const t = value && value.length >= 16 ? value.slice(11, 19) : defaultTime
|
|
149
|
+
return t.length === 5 ? `${t}:00` : t
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export { DateTimePicker }
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
// Peças derivadas do DatePicker do Tremor (Apache-2.0) e modificadas pela
|
|
4
|
+
// Strategicos. Ver THIRD_PARTY_NOTICES.md.
|
|
5
|
+
|
|
6
|
+
import * as React from "react"
|
|
7
|
+
import { CalendarIcon, XIcon } from "lucide-react"
|
|
8
|
+
import type { Matcher } from "react-day-picker"
|
|
9
|
+
|
|
10
|
+
import { cn } from "../lib/utils.js"
|
|
11
|
+
import { Button } from "./button.js"
|
|
12
|
+
import { PopoverTrigger } from "./popover.js"
|
|
13
|
+
import { selectTriggerVariants } from "./select.js"
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Utilitários dos campos de data (DateInput, DatePickerInput, DateTimePicker).
|
|
17
|
+
*
|
|
18
|
+
* Os valores seguem o Mantine 8: texto, nunca `Date`.
|
|
19
|
+
* - data: "AAAA-MM-DD" (como o <input type="date">)
|
|
20
|
+
* - data e hora: "AAAA-MM-DD HH:mm:ss"
|
|
21
|
+
* Sem fuso: 2026-10-15 é 15/10 em qualquer lugar. Um Date à meia-noite UTC
|
|
22
|
+
* vira o dia 14 no Brasil.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const DATE_RE = /^(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?$/
|
|
26
|
+
|
|
27
|
+
/** "AAAA-MM-DD" ou "AAAA-MM-DD HH:mm[:ss]" → Date local. Vazio ou inválido →
|
|
28
|
+
* undefined. */
|
|
29
|
+
function parseDateValue(value: string | null | undefined): Date | undefined {
|
|
30
|
+
const m = value ? DATE_RE.exec(value) : null
|
|
31
|
+
if (!m) return undefined
|
|
32
|
+
const [y, mo, d, h = "0", mi = "0", s = "0"] = m.slice(1)
|
|
33
|
+
const date = new Date(Number(y), Number(mo) - 1, Number(d), Number(h), Number(mi), Number(s))
|
|
34
|
+
// 2026-02-31 não existe: o Date rolaria para março.
|
|
35
|
+
if (date.getMonth() !== Number(mo) - 1 || Number(h) > 23 || Number(mi) > 59 || Number(s) > 59) return undefined
|
|
36
|
+
return date
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const pad = (n: number) => String(n).padStart(2, "0")
|
|
40
|
+
|
|
41
|
+
/** Date → "AAAA-MM-DD" (dia local). */
|
|
42
|
+
function toDateValue(date: Date): string {
|
|
43
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Date → "AAAA-MM-DD HH:mm:ss" (hora local). */
|
|
47
|
+
function toDateTimeValue(date: Date): string {
|
|
48
|
+
return `${toDateValue(date)} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** 15/10/2026 */
|
|
52
|
+
const formatDate = (date: Date) => date.toLocaleDateString("pt-BR")
|
|
53
|
+
|
|
54
|
+
/** 15/10/2026 14:30 */
|
|
55
|
+
const formatDateTime = (date: Date) => `${formatDate(date)} ${pad(date.getHours())}:${pad(date.getMinutes())}`
|
|
56
|
+
|
|
57
|
+
// ── Limites ───────────────────────────────────────────────────────────────────
|
|
58
|
+
|
|
59
|
+
function clampDate(date: Date, min?: Date, max?: Date) {
|
|
60
|
+
if (min && date < min) return min
|
|
61
|
+
if (max && date > max) return max
|
|
62
|
+
return date
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Dias fora de [min, max] para o `disabled` do Calendar. */
|
|
66
|
+
function outOfRange(min?: Date, max?: Date): Matcher[] {
|
|
67
|
+
const m: Matcher[] = []
|
|
68
|
+
if (min) m.push({ before: min })
|
|
69
|
+
if (max) m.push({ after: max })
|
|
70
|
+
return m
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Compara só o dia ("AAAA-MM-DD…" ordena como texto). */
|
|
74
|
+
function inRange(value: string, minDate?: string, maxDate?: string) {
|
|
75
|
+
const day = value.slice(0, 10)
|
|
76
|
+
return (!minDate || day >= minDate.slice(0, 10)) && (!maxDate || day <= maxDate.slice(0, 10))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// ── Peças comuns ──────────────────────────────────────────────────────────────
|
|
80
|
+
|
|
81
|
+
type FieldControlProps = {
|
|
82
|
+
id?: string
|
|
83
|
+
"aria-label"?: string
|
|
84
|
+
"aria-describedby"?: string
|
|
85
|
+
"aria-invalid"?: React.AriaAttributes["aria-invalid"]
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Gatilho dos pickers: o visual do SelectTrigger, com ícone de calendário e,
|
|
89
|
+
* opcionalmente, um X para limpar. Vai dentro de um <Popover>. */
|
|
90
|
+
function PickerTrigger({
|
|
91
|
+
text,
|
|
92
|
+
placeholder,
|
|
93
|
+
open,
|
|
94
|
+
size = "default",
|
|
95
|
+
disabled,
|
|
96
|
+
clearable,
|
|
97
|
+
onClear,
|
|
98
|
+
className,
|
|
99
|
+
wrapperClassName,
|
|
100
|
+
slot,
|
|
101
|
+
controlProps,
|
|
102
|
+
}: {
|
|
103
|
+
text: string | null
|
|
104
|
+
placeholder: string
|
|
105
|
+
open: boolean
|
|
106
|
+
size?: "sm" | "default" | null
|
|
107
|
+
disabled?: boolean
|
|
108
|
+
clearable?: boolean
|
|
109
|
+
onClear: () => void
|
|
110
|
+
className?: string
|
|
111
|
+
wrapperClassName?: string
|
|
112
|
+
slot: string
|
|
113
|
+
controlProps: FieldControlProps
|
|
114
|
+
}) {
|
|
115
|
+
const showClear = clearable && !!text && !disabled
|
|
116
|
+
|
|
117
|
+
const trigger = (
|
|
118
|
+
<PopoverTrigger asChild disabled={disabled}>
|
|
119
|
+
<button
|
|
120
|
+
type="button"
|
|
121
|
+
aria-haspopup="dialog"
|
|
122
|
+
aria-expanded={open}
|
|
123
|
+
data-slot={slot}
|
|
124
|
+
data-size={size ?? "default"}
|
|
125
|
+
data-placeholder={text ? undefined : ""}
|
|
126
|
+
{...controlProps}
|
|
127
|
+
className={cn(
|
|
128
|
+
selectTriggerVariants({ size }),
|
|
129
|
+
"w-full min-w-0 cursor-pointer justify-start text-left tabular-nums",
|
|
130
|
+
showClear && "pr-9",
|
|
131
|
+
className
|
|
132
|
+
)}
|
|
133
|
+
>
|
|
134
|
+
<CalendarIcon className="text-muted-foreground" />
|
|
135
|
+
<span className="min-w-0 flex-1 truncate">{text ?? placeholder}</span>
|
|
136
|
+
</button>
|
|
137
|
+
</PopoverTrigger>
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
if (!clearable) return trigger
|
|
141
|
+
return (
|
|
142
|
+
<div data-slot={`${slot}-wrapper`} className={cn("relative w-full min-w-0", wrapperClassName)}>
|
|
143
|
+
{trigger}
|
|
144
|
+
{showClear && <ClearButton onClick={onClear} />}
|
|
145
|
+
</div>
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** X de limpar. Fica ao lado do gatilho, não dentro: botão dentro de botão não
|
|
150
|
+
* é HTML válido. */
|
|
151
|
+
function ClearButton({ onClick, className }: { onClick: () => void; className?: string }) {
|
|
152
|
+
return (
|
|
153
|
+
<button
|
|
154
|
+
type="button"
|
|
155
|
+
onClick={onClick}
|
|
156
|
+
aria-label="Limpar data"
|
|
157
|
+
className={cn(
|
|
158
|
+
"absolute inset-y-0 right-1.5 my-auto flex size-6 cursor-pointer items-center justify-center rounded text-muted-foreground outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50",
|
|
159
|
+
className
|
|
160
|
+
)}
|
|
161
|
+
>
|
|
162
|
+
<XIcon className="size-4" />
|
|
163
|
+
</button>
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Atalhos ao lado do calendário (no celular, uma faixa em cima). */
|
|
168
|
+
function PresetList<T>({
|
|
169
|
+
presets,
|
|
170
|
+
isActive,
|
|
171
|
+
isDisabled,
|
|
172
|
+
onSelect,
|
|
173
|
+
}: {
|
|
174
|
+
presets: { label: string; value: T }[]
|
|
175
|
+
isActive: (value: T) => boolean
|
|
176
|
+
isDisabled: (value: T) => boolean
|
|
177
|
+
onSelect: (value: T) => void
|
|
178
|
+
}) {
|
|
179
|
+
return (
|
|
180
|
+
<ul
|
|
181
|
+
data-slot="date-picker-presets"
|
|
182
|
+
className="flex gap-1 overflow-x-auto border-b border-border p-2 sm:w-40 sm:flex-col sm:overflow-visible sm:border-r sm:border-b-0"
|
|
183
|
+
>
|
|
184
|
+
{presets.map(p => (
|
|
185
|
+
<li key={p.label} className="shrink-0">
|
|
186
|
+
<button
|
|
187
|
+
type="button"
|
|
188
|
+
disabled={isDisabled(p.value)}
|
|
189
|
+
aria-pressed={isActive(p.value)}
|
|
190
|
+
onClick={() => onSelect(p.value)}
|
|
191
|
+
className="w-full cursor-pointer truncate rounded-md px-2.5 py-1.5 text-left text-sm whitespace-nowrap outline-none transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-pressed:bg-accent aria-pressed:font-medium"
|
|
192
|
+
>
|
|
193
|
+
{p.label}
|
|
194
|
+
</button>
|
|
195
|
+
</li>
|
|
196
|
+
))}
|
|
197
|
+
</ul>
|
|
198
|
+
)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Rodapé do calendário: algo à esquerda (dica, hora) e, com
|
|
202
|
+
* `withApplyButton`, Cancelar e Aplicar à direita. Para texto de dica, use
|
|
203
|
+
* <PickerHint>; o rodapé não tinge o que vai nele (a hora é um campo). */
|
|
204
|
+
function PickerFooter({
|
|
205
|
+
children,
|
|
206
|
+
onCancel,
|
|
207
|
+
onApply,
|
|
208
|
+
applyDisabled,
|
|
209
|
+
}: {
|
|
210
|
+
children?: React.ReactNode
|
|
211
|
+
onCancel?: () => void
|
|
212
|
+
onApply?: () => void
|
|
213
|
+
applyDisabled?: boolean
|
|
214
|
+
}) {
|
|
215
|
+
return (
|
|
216
|
+
<div data-slot="date-picker-footer" className="flex flex-wrap items-center gap-2 border-t border-border p-3">
|
|
217
|
+
<div className="min-w-0 flex-1">{children}</div>
|
|
218
|
+
{onApply && (
|
|
219
|
+
<div className="flex shrink-0 gap-2">
|
|
220
|
+
<Button type="button" variant="ghost" onClick={onCancel}>Cancelar</Button>
|
|
221
|
+
<Button type="button" onClick={onApply} disabled={applyDisabled}>Aplicar</Button>
|
|
222
|
+
</div>
|
|
223
|
+
)}
|
|
224
|
+
</div>
|
|
225
|
+
)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function PickerHint({ children }: { children: React.ReactNode }) {
|
|
229
|
+
return <span aria-live="polite" className="text-xs text-muted-foreground">{children}</span>
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Props comuns aos pickers (DatePickerInput e DateTimePicker). */
|
|
233
|
+
type PickerBaseProps = FieldControlProps & {
|
|
234
|
+
placeholder?: string
|
|
235
|
+
/** Primeiro dia que pode ser escolhido ("AAAA-MM-DD"). */
|
|
236
|
+
minDate?: string
|
|
237
|
+
/** Último dia que pode ser escolhido ("AAAA-MM-DD"). */
|
|
238
|
+
maxDate?: string
|
|
239
|
+
/** Um X no gatilho limpa o valor. */
|
|
240
|
+
clearable?: boolean
|
|
241
|
+
/** Rodapé com Cancelar e Aplicar: a escolha só vale ao aplicar, e fechar
|
|
242
|
+
* de outro jeito descarta. Sem ele, escolher já grava. */
|
|
243
|
+
withApplyButton?: boolean
|
|
244
|
+
/** Como o valor aparece no gatilho. */
|
|
245
|
+
valueFormatter?: (date: Date) => string
|
|
246
|
+
/** "dropdown" troca o título do mês por seletores de mês e ano. */
|
|
247
|
+
captionLayout?: "label" | "dropdown" | "dropdown-months" | "dropdown-years"
|
|
248
|
+
size?: "sm" | "default"
|
|
249
|
+
disabled?: boolean
|
|
250
|
+
/** Classes do gatilho. */
|
|
251
|
+
className?: string
|
|
252
|
+
/** Classes do invólucro, que só existe com `clearable`. */
|
|
253
|
+
wrapperClassName?: string
|
|
254
|
+
align?: "start" | "center" | "end"
|
|
255
|
+
onOpenChange?: (open: boolean) => void
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export {
|
|
259
|
+
parseDateValue,
|
|
260
|
+
toDateValue,
|
|
261
|
+
toDateTimeValue,
|
|
262
|
+
formatDate,
|
|
263
|
+
formatDateTime,
|
|
264
|
+
clampDate,
|
|
265
|
+
outOfRange,
|
|
266
|
+
inRange,
|
|
267
|
+
PickerTrigger,
|
|
268
|
+
ClearButton,
|
|
269
|
+
PresetList,
|
|
270
|
+
PickerFooter,
|
|
271
|
+
PickerHint,
|
|
272
|
+
type FieldControlProps,
|
|
273
|
+
type PickerBaseProps,
|
|
274
|
+
}
|
|
@@ -7,6 +7,7 @@ import { cn } from "../lib/utils.js"
|
|
|
7
7
|
import { Badge } from "./badge.js"
|
|
8
8
|
import { useFieldControl } from "./field.js"
|
|
9
9
|
import { Popover, PopoverContent, PopoverTrigger } from "./popover.js"
|
|
10
|
+
import { selectTriggerVariants } from "./select.js"
|
|
10
11
|
|
|
11
12
|
export type MultiSelectOption = {
|
|
12
13
|
value: string
|
|
@@ -111,7 +112,8 @@ function MultiSelect({
|
|
|
111
112
|
data-size={size}
|
|
112
113
|
{...controlProps}
|
|
113
114
|
className={cn(
|
|
114
|
-
|
|
115
|
+
selectTriggerVariants({ size }),
|
|
116
|
+
"w-full min-w-0 cursor-pointer text-left",
|
|
115
117
|
className
|
|
116
118
|
)}
|
|
117
119
|
>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from "react"
|
|
4
4
|
import { Select as SelectPrimitive } from "radix-ui"
|
|
5
|
+
import { cva } from "class-variance-authority"
|
|
5
6
|
|
|
6
7
|
import { cn } from "../lib/utils.js"
|
|
7
8
|
import { useFieldControl } from "./field.js"
|
|
@@ -32,6 +33,31 @@ function SelectValue({
|
|
|
32
33
|
return <SelectPrimitive.Value data-slot="select-value" {...props} />
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Visual do gatilho de seleção: borda, foco, aberto, desabilitado, erro e
|
|
38
|
+
* tamanhos. É o mesmo do SelectTrigger, exportado para os gatilhos que não são
|
|
39
|
+
* o Select do Radix (MultiSelect, Combobox, DatePicker ou um Popover próprio)
|
|
40
|
+
* não precisarem copiar as classes — cópia que fica para trás quando o kit
|
|
41
|
+
* muda.
|
|
42
|
+
*
|
|
43
|
+
* Placeholder: marque o gatilho com `data-placeholder` enquanto estiver vazio,
|
|
44
|
+
* como o Radix faz.
|
|
45
|
+
*
|
|
46
|
+
* <button className={cn(selectTriggerVariants({ size }), "w-full")} …>
|
|
47
|
+
*/
|
|
48
|
+
const selectTriggerVariants = cva(
|
|
49
|
+
"flex items-center justify-between gap-1.5 rounded-lg border border-input bg-transparent pr-2.5 pl-3 text-sm whitespace-nowrap transition-colors outline-none select-none focus-visible:border-ring data-[state=open]:border-ring disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-60 aria-invalid:border-destructive data-placeholder:text-muted-foreground dark:bg-input/30 dark:hover:bg-input/50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
50
|
+
{
|
|
51
|
+
variants: {
|
|
52
|
+
size: {
|
|
53
|
+
default: "h-9",
|
|
54
|
+
sm: "h-7.5 rounded-[min(var(--radius-md),10px)]",
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
defaultVariants: { size: "default" },
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
|
|
35
61
|
function SelectTrigger({
|
|
36
62
|
className,
|
|
37
63
|
size = "default",
|
|
@@ -45,7 +71,8 @@ function SelectTrigger({
|
|
|
45
71
|
data-slot="select-trigger"
|
|
46
72
|
data-size={size}
|
|
47
73
|
className={cn(
|
|
48
|
-
|
|
74
|
+
selectTriggerVariants({ size }),
|
|
75
|
+
"w-fit py-2 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5",
|
|
49
76
|
className
|
|
50
77
|
)}
|
|
51
78
|
{...useFieldControl(props, { withRequired: false })}
|
|
@@ -206,4 +233,5 @@ export {
|
|
|
206
233
|
SelectSeparator,
|
|
207
234
|
SelectTrigger,
|
|
208
235
|
SelectValue,
|
|
236
|
+
selectTriggerVariants,
|
|
209
237
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
|
|
5
|
+
import { cn } from "../lib/utils.js"
|
|
6
|
+
import { Input, type InputProps } from "./input.js"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Hora, como o TimeInput do Mantine: o <input type="time"> do navegador, no
|
|
10
|
+
* visual do Input. O valor é "HH:mm" (ou "HH:mm:ss" com `withSeconds`).
|
|
11
|
+
*
|
|
12
|
+
* <Field label="Horário"><TimeInput value={hora} onChange={e => setHora(e.target.value)} /></Field>
|
|
13
|
+
*
|
|
14
|
+
* O formato de 12 ou 24 horas segue o sistema do usuário — no Brasil, 24 horas.
|
|
15
|
+
* O relógio à direita é o do navegador (abre a lista de horas no Chrome).
|
|
16
|
+
*/
|
|
17
|
+
function TimeInput({
|
|
18
|
+
withSeconds = false,
|
|
19
|
+
className,
|
|
20
|
+
...props
|
|
21
|
+
}: Omit<InputProps, "type"> & {
|
|
22
|
+
withSeconds?: boolean
|
|
23
|
+
}) {
|
|
24
|
+
return (
|
|
25
|
+
<Input
|
|
26
|
+
type="time"
|
|
27
|
+
step={withSeconds ? 1 : 60}
|
|
28
|
+
className={cn("tabular-nums", className)}
|
|
29
|
+
{...props}
|
|
30
|
+
/>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { TimeInput }
|