@invoiceonline/ui-react 0.1.0 → 0.2.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/AGENTS.md +4 -3
- package/CHANGELOG.md +18 -0
- package/dist/components/date-picker/DatePicker.js +1 -1
- package/dist/components/field/Field.d.ts +2 -1
- package/dist/components/field/Field.js +13 -8
- package/dist/components/field-pair/FieldPair.d.ts +29 -13
- package/dist/components/field-pair/FieldPair.js +20 -6
- package/dist/components/text-field/TextField.d.ts +97 -2
- package/dist/components/text-field/TextField.js +76 -5
- package/dist/components/text-field/index.d.ts +2 -2
- package/dist/components/textarea/Textarea.js +1 -1
- package/dist/components/unit-field/UnitField.js +1 -1
- package/dist/index.d.ts +3 -5
- package/dist/index.js +2 -3
- package/dist/internal/useDateFieldTrigger.d.ts +60 -0
- package/dist/internal/useDateFieldTrigger.js +68 -16
- package/dist/internal/useFormReset.js +10 -3
- package/docs/Consuming.mdx +20 -3
- package/llms.txt +7 -13
- package/package.json +1 -5
- package/src/components/date-picker/DatePicker.mdx +18 -14
- package/src/components/date-picker/DatePicker.stories.tsx +1 -1
- package/src/components/field/Field.tsx +40 -18
- package/src/components/field-pair/FieldPair.mdx +13 -9
- package/src/components/field-pair/FieldPair.stories.tsx +11 -2
- package/src/components/field-pair/FieldPair.tsx +76 -27
- package/src/components/filter-facet/FilterFacet.tsx +1 -1
- package/src/components/subject-lookup-field/SubjectLookupField.tsx +3 -3
- package/src/components/text-field/TextField.mdx +258 -38
- package/src/components/text-field/TextField.stories.tsx +311 -3
- package/src/components/text-field/TextField.tsx +259 -5
- package/src/components/text-field/index.ts +3 -0
- package/src/components/textarea/Textarea.mdx +2 -2
- package/src/components/textarea/Textarea.tsx +1 -1
- package/src/components/unit-field/UnitField.mdx +1 -1
- package/src/components/unit-field/UnitField.tsx +1 -1
- package/src/index.ts +0 -1
- package/src/internal/useDateFieldTrigger.tsx +178 -38
- package/src/internal/useFormReset.ts +13 -3
- package/src/recipes/Form.stories.tsx +5 -0
- package/dist/components/date-field/DateField.d.ts +0 -52
- package/dist/components/date-field/DateField.js +0 -45
- package/dist/components/date-field/index.d.ts +0 -2
- package/dist/components/date-field/index.js +0 -1
- package/src/components/date-field/DateField.mdx +0 -340
- package/src/components/date-field/DateField.stories.tsx +0 -221
- package/src/components/date-field/DateField.tsx +0 -176
- package/src/components/date-field/index.ts +0 -1
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import * as React from 'react';
|
|
4
|
-
import type { Locale } from 'date-fns';
|
|
5
|
-
import { TextField, type TextFieldSize, type TextFieldState } from '../text-field/TextField';
|
|
6
|
-
import { type DatePickerNavLabels } from '../date-picker/DatePicker';
|
|
7
|
-
import { useDateFieldTrigger } from '../../internal/useDateFieldTrigger';
|
|
8
|
-
import { cn } from '../../internal/utils';
|
|
9
|
-
|
|
10
|
-
// =============================================================================
|
|
11
|
-
// DateField — the field a Date Picker opens from (spec 04-molecules/date-picker
|
|
12
|
-
// § Cross-references, 06-patterns/field-readonly § Date Picker).
|
|
13
|
-
//
|
|
14
|
-
// A date field is a TEXT FIELD SIBLING, not a Select. The Text Field inventory
|
|
15
|
-
// lists "Date — issue date, taxable date" as a Text Field kind while Selects sit
|
|
16
|
-
// in a separate "Adjacent — not a Text Field" section, and the planning doc
|
|
17
|
-
// resolves Textarea + Date Picker as "separate siblings that reuse `_inputShell`".
|
|
18
|
-
// So this is a real editable `<input>`: a typist can key the date straight in
|
|
19
|
-
// instead of paging a calendar. The Select-trigger pattern (`SelectField`, a
|
|
20
|
-
// read-only `<button role="combobox">`) is deliberately NOT reused — it would
|
|
21
|
-
// take typing away.
|
|
22
|
-
//
|
|
23
|
-
// THE WHOLE FIELD IS THE TRIGGER, and the calendar glyph in the leading slot is
|
|
24
|
-
// decorative. No spec file states which side the glyph sits on — `text-field.md`
|
|
25
|
-
// describes leading as a "contextual glyph" and trailing as "clear /
|
|
26
|
-
// password-reveal", neither naming a calendar — so this follows the design.
|
|
27
|
-
// `field-readonly.md` § Date Picker is the one place the glyph is mentioned and
|
|
28
|
-
// it matches: "a quiet affordance, NOT an active control, and the TRIGGER does
|
|
29
|
-
// not open the calendar". Hence `role="combobox"` on the input (APG Date Picker
|
|
30
|
-
// Combobox), not `aria-haspopup` on a button that no longer exists.
|
|
31
|
-
//
|
|
32
|
-
// "Whole field" is literal: the open handler sits on the WRAPPER, not on the
|
|
33
|
-
// `<input>`. The glyph and the shell padding are siblings of the input, so a
|
|
34
|
-
// handler on the input alone would leave the two visually largest parts of the
|
|
35
|
-
// trigger dead. A click that did not land in the input also moves focus there —
|
|
36
|
-
// the field is typeable, and a trigger that opens the calendar while focus sits
|
|
37
|
-
// nowhere would strand the keyboard.
|
|
38
|
-
//
|
|
39
|
-
// Layering: the field is the anchor, `useDateFieldTrigger` owns every bit of
|
|
40
|
-
// date behaviour (draft/commit, the ArrowDown route, the blur-into-panel guard,
|
|
41
|
-
// the panel itself) and `useAnchoredPanel` beneath it positions and dismisses.
|
|
42
|
-
// This file is only the chrome — a `FieldPair` cell in `format="date"` renders
|
|
43
|
-
// the same hook in a borderless Field Segment instead.
|
|
44
|
-
// =============================================================================
|
|
45
|
-
|
|
46
|
-
export interface DateFieldProps {
|
|
47
|
-
/** The chosen date. Controlled. */
|
|
48
|
-
value?: Date;
|
|
49
|
-
onValueChange?: (value: Date | undefined) => void;
|
|
50
|
-
/** Field height — Medium (48) standalone, Small (40) dense rows. */
|
|
51
|
-
size?: TextFieldSize;
|
|
52
|
-
/**
|
|
53
|
-
* Visual state. `readonly` shows the value but never opens the calendar.
|
|
54
|
-
* `success` is here because `Field` injects it when given a `success` message.
|
|
55
|
-
*/
|
|
56
|
-
state?: Extract<
|
|
57
|
-
TextFieldState,
|
|
58
|
-
'default' | 'focused' | 'error' | 'success' | 'disabled' | 'readonly'
|
|
59
|
-
>;
|
|
60
|
-
/**
|
|
61
|
-
* Display + parse pattern, date-fns syntax (e.g. `dd. MM. yyyy` for CZ,
|
|
62
|
-
* `MM/dd/yyyy` for US). Per-market values come from the consumer's locale config.
|
|
63
|
-
*/
|
|
64
|
-
dateFormat?: string;
|
|
65
|
-
/** Locale driving the panel's week start, weekday names and month caption. */
|
|
66
|
-
locale?: Locale;
|
|
67
|
-
/** Earliest / latest selectable date. */
|
|
68
|
-
minDate?: Date;
|
|
69
|
-
maxDate?: Date;
|
|
70
|
-
placeholder?: string;
|
|
71
|
-
id?: string;
|
|
72
|
-
name?: string;
|
|
73
|
-
disabled?: boolean;
|
|
74
|
-
readOnly?: boolean;
|
|
75
|
-
/**
|
|
76
|
-
* Accessible name for the calendar panel (`role="dialog"`). Required and never
|
|
77
|
-
* defaulted — the design system is locale-agnostic, and a name invisible to
|
|
78
|
-
* sighted review is exactly the kind that ships untranslated.
|
|
79
|
-
*/
|
|
80
|
-
panelLabel: string;
|
|
81
|
-
/** Accessible names for the panel's four navigation chevrons. */
|
|
82
|
-
navLabels: DatePickerNavLabels;
|
|
83
|
-
className?: string;
|
|
84
|
-
onFocus?: React.FocusEventHandler<HTMLInputElement>;
|
|
85
|
-
onBlur?: React.FocusEventHandler<HTMLInputElement>;
|
|
86
|
-
/**
|
|
87
|
-
* Injected by `Field` when it owns the label / helper / error line. Declared
|
|
88
|
-
* explicitly because the props interface has no index signature — without
|
|
89
|
-
* these two the helper-text association and the error wiring would be
|
|
90
|
-
* silently dropped by the clone.
|
|
91
|
-
*/
|
|
92
|
-
'aria-invalid'?: boolean;
|
|
93
|
-
'aria-describedby'?: string;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const DateField = React.forwardRef<HTMLInputElement, DateFieldProps>(
|
|
97
|
-
(
|
|
98
|
-
{
|
|
99
|
-
value,
|
|
100
|
-
onValueChange,
|
|
101
|
-
size = 'md',
|
|
102
|
-
state,
|
|
103
|
-
dateFormat,
|
|
104
|
-
locale,
|
|
105
|
-
minDate,
|
|
106
|
-
maxDate,
|
|
107
|
-
placeholder,
|
|
108
|
-
id,
|
|
109
|
-
name,
|
|
110
|
-
disabled,
|
|
111
|
-
readOnly,
|
|
112
|
-
panelLabel,
|
|
113
|
-
navLabels,
|
|
114
|
-
className,
|
|
115
|
-
onFocus,
|
|
116
|
-
onBlur,
|
|
117
|
-
'aria-invalid': ariaInvalid,
|
|
118
|
-
'aria-describedby': ariaDescribedBy,
|
|
119
|
-
},
|
|
120
|
-
ref,
|
|
121
|
-
) => {
|
|
122
|
-
const isDisabled = disabled ?? state === 'disabled';
|
|
123
|
-
const isReadOnly = readOnly ?? state === 'readonly';
|
|
124
|
-
|
|
125
|
-
const trigger = useDateFieldTrigger({
|
|
126
|
-
value,
|
|
127
|
-
onValueChange,
|
|
128
|
-
dateFormat,
|
|
129
|
-
locale,
|
|
130
|
-
minDate,
|
|
131
|
-
maxDate,
|
|
132
|
-
disabled: isDisabled,
|
|
133
|
-
readOnly: isReadOnly,
|
|
134
|
-
panelLabel,
|
|
135
|
-
navLabels,
|
|
136
|
-
inputRef: ref,
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
return (
|
|
140
|
-
<>
|
|
141
|
-
{/* The whole field is the trigger — hence the click handler here and not
|
|
142
|
-
on the input, whose siblings (the glyph, the shell padding) would
|
|
143
|
-
otherwise be dead area. No keyboard handler pairs with it: the wrapper
|
|
144
|
-
only widens the hit area of the <input> inside, which is the real
|
|
145
|
-
control and carries the keyboard route (ArrowDown) itself. */}
|
|
146
|
-
<div {...trigger.triggerProps} className={cn('w-full', className)}>
|
|
147
|
-
<TextField
|
|
148
|
-
ref={trigger.setInputRef}
|
|
149
|
-
id={id}
|
|
150
|
-
name={name}
|
|
151
|
-
size={size}
|
|
152
|
-
state={state}
|
|
153
|
-
placeholder={placeholder}
|
|
154
|
-
disabled={isDisabled}
|
|
155
|
-
readOnly={isReadOnly}
|
|
156
|
-
aria-invalid={ariaInvalid}
|
|
157
|
-
aria-describedby={ariaDescribedBy}
|
|
158
|
-
onFocus={onFocus}
|
|
159
|
-
// The calendar sits in the LEADING slot and is decorative — the FIELD
|
|
160
|
-
// is the trigger, which is how the read-only pattern phrases it
|
|
161
|
-
// ("a quiet affordance, not an active control, and the trigger does
|
|
162
|
-
// not open the calendar"). TextField steps it down to --icon-muted
|
|
163
|
-
// when read-only.
|
|
164
|
-
leadingIcon="calendar-dots"
|
|
165
|
-
{...trigger.getInputProps({ onBlur })}
|
|
166
|
-
/>
|
|
167
|
-
</div>
|
|
168
|
-
|
|
169
|
-
{trigger.panel}
|
|
170
|
-
</>
|
|
171
|
-
);
|
|
172
|
-
},
|
|
173
|
-
);
|
|
174
|
-
DateField.displayName = 'DateField';
|
|
175
|
-
|
|
176
|
-
export { DateField };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { DateField, type DateFieldProps } from './DateField';
|