@tangible/ui 0.0.21 → 0.1.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/components/Button/Button.js +6 -8
- package/components/Button/types.d.ts +0 -5
- package/components/DatePicker/Calendar.d.ts +12 -0
- package/components/DatePicker/Calendar.js +145 -0
- package/components/DatePicker/DatePicker.d.ts +23 -0
- package/components/DatePicker/DatePicker.js +123 -0
- package/components/DatePicker/DateRangePicker.d.ts +16 -0
- package/components/DatePicker/DateRangePicker.js +114 -0
- package/components/DatePicker/date-utils.d.ts +51 -0
- package/components/DatePicker/date-utils.js +228 -0
- package/components/DatePicker/index.d.ts +8 -0
- package/components/DatePicker/index.js +6 -0
- package/components/DatePicker/presets.d.ts +3 -0
- package/components/DatePicker/presets.js +37 -0
- package/components/DatePicker/types.d.ts +138 -0
- package/components/DatePicker/types.js +39 -0
- package/components/Popover/Popover.js +16 -2
- package/components/SegmentedControl/types.d.ts +2 -2
- package/components/index.d.ts +1 -0
- package/components/index.js +1 -0
- package/package.json +5 -1
- package/styles/all.css +1 -1
- package/styles/all.expanded.css +384 -47
- package/styles/all.expanded.unlayered.css +384 -47
- package/styles/all.unlayered.css +1 -1
- package/styles/components/_bundle.scss +2 -0
- package/styles/components/button.scss +14 -8
- package/styles/components/card.scss +1 -1
- package/styles/components/chip.scss +27 -10
- package/styles/components/date-picker.scss +400 -0
- package/styles/components/icon-button.scss +4 -4
- package/styles/components/notice.scss +15 -6
- package/styles/components/popover.scss +6 -0
- package/styles/components/progress.scss +22 -5
- package/styles/components/segmented-control.scss +13 -1
- package/styles/core.css +1 -1
- package/styles/core.unlayered.css +1 -1
- package/styles/system/_control.scss +9 -8
- package/styles/system/_tokens.scss +3 -0
- package/tui-manifest.json +98 -10
- package/utils/portal.d.ts +0 -4
- package/utils/portal.js +38 -5
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// =============================================================================
|
|
2
|
+
// Date utilities — wall-clock, timezone-agnostic
|
|
3
|
+
// =============================================================================
|
|
4
|
+
//
|
|
5
|
+
// All math uses local (wall-clock) accessors on plain Date objects: the
|
|
6
|
+
// pickers edit "what the clock on the wall says", and the host owns
|
|
7
|
+
// interpretation (site timezone, serialisation). No UTC normalisation, no
|
|
8
|
+
// timezone conversion — ever. Day arithmetic goes through setDate/setMonth,
|
|
9
|
+
// which stays date-correct across DST transitions.
|
|
10
|
+
//
|
|
11
|
+
// Formatting and weekday/month names come from Intl.DateTimeFormat, so any
|
|
12
|
+
// locale tag works for display. Parsing accepts numeric dates in the
|
|
13
|
+
// locale's own part order (derived from formatToParts, not hardcoded).
|
|
14
|
+
//
|
|
15
|
+
// =============================================================================
|
|
16
|
+
export function isSameDay(a, b) {
|
|
17
|
+
if (!a || !b)
|
|
18
|
+
return false;
|
|
19
|
+
return (a.getFullYear() === b.getFullYear() &&
|
|
20
|
+
a.getMonth() === b.getMonth() &&
|
|
21
|
+
a.getDate() === b.getDate());
|
|
22
|
+
}
|
|
23
|
+
export function isSameMonth(a, b) {
|
|
24
|
+
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();
|
|
25
|
+
}
|
|
26
|
+
/** Strictly before, comparing calendar days (time-of-day ignored). */
|
|
27
|
+
export function isBeforeDay(a, b) {
|
|
28
|
+
if (a.getFullYear() !== b.getFullYear())
|
|
29
|
+
return a.getFullYear() < b.getFullYear();
|
|
30
|
+
if (a.getMonth() !== b.getMonth())
|
|
31
|
+
return a.getMonth() < b.getMonth();
|
|
32
|
+
return a.getDate() < b.getDate();
|
|
33
|
+
}
|
|
34
|
+
export function isAfterDay(a, b) {
|
|
35
|
+
return isBeforeDay(b, a);
|
|
36
|
+
}
|
|
37
|
+
/** Day is within [from, to] inclusive, comparing calendar days. */
|
|
38
|
+
export function isWithinDays(day, from, to) {
|
|
39
|
+
return !isBeforeDay(day, from) && !isAfterDay(day, to);
|
|
40
|
+
}
|
|
41
|
+
/** New Date shifted by n days; preserves time-of-day. */
|
|
42
|
+
export function addDays(date, n) {
|
|
43
|
+
const next = new Date(date);
|
|
44
|
+
next.setDate(next.getDate() + n);
|
|
45
|
+
return next;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* New Date shifted by n months; clamps the day-of-month so Jan 31 + 1 month
|
|
49
|
+
* lands on Feb 28/29 rather than overflowing into March.
|
|
50
|
+
*/
|
|
51
|
+
export function addMonths(date, n) {
|
|
52
|
+
const next = new Date(date);
|
|
53
|
+
const day = next.getDate();
|
|
54
|
+
next.setDate(1);
|
|
55
|
+
next.setMonth(next.getMonth() + n);
|
|
56
|
+
next.setDate(Math.min(day, daysInMonth(next)));
|
|
57
|
+
return next;
|
|
58
|
+
}
|
|
59
|
+
export function addYears(date, n) {
|
|
60
|
+
return addMonths(date, n * 12);
|
|
61
|
+
}
|
|
62
|
+
export function daysInMonth(date) {
|
|
63
|
+
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
|
|
64
|
+
}
|
|
65
|
+
export function startOfMonth(date) {
|
|
66
|
+
const next = new Date(date);
|
|
67
|
+
next.setDate(1);
|
|
68
|
+
return next;
|
|
69
|
+
}
|
|
70
|
+
export function startOfWeek(date, weekStartsOn) {
|
|
71
|
+
const diff = (date.getDay() - weekStartsOn + 7) % 7;
|
|
72
|
+
return addDays(date, -diff);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The visible day grid for a month: always 6 rows of 7 (42 days), starting
|
|
76
|
+
* on the locale's week start, so the popover height never jumps between
|
|
77
|
+
* months. Time-of-day on the returned dates is noon — callers merge their
|
|
78
|
+
* own time when committing a selection.
|
|
79
|
+
*/
|
|
80
|
+
export function getMonthGrid(month, weekStartsOn) {
|
|
81
|
+
const first = new Date(month.getFullYear(), month.getMonth(), 1, 12);
|
|
82
|
+
const gridStart = startOfWeek(first, weekStartsOn);
|
|
83
|
+
const rows = [];
|
|
84
|
+
for (let row = 0; row < 6; row++) {
|
|
85
|
+
const cells = [];
|
|
86
|
+
for (let col = 0; col < 7; col++) {
|
|
87
|
+
cells.push(addDays(gridStart, row * 7 + col));
|
|
88
|
+
}
|
|
89
|
+
rows.push(cells);
|
|
90
|
+
}
|
|
91
|
+
return rows;
|
|
92
|
+
}
|
|
93
|
+
/** New Date with the given calendar day but this date's time-of-day. */
|
|
94
|
+
export function withDay(time, day) {
|
|
95
|
+
const next = new Date(day);
|
|
96
|
+
if (time) {
|
|
97
|
+
next.setHours(time.getHours(), time.getMinutes(), 0, 0);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
next.setHours(0, 0, 0, 0);
|
|
101
|
+
}
|
|
102
|
+
return next;
|
|
103
|
+
}
|
|
104
|
+
export function clampDay(date, min, max) {
|
|
105
|
+
if (min && isBeforeDay(date, min))
|
|
106
|
+
return withDay(date, min);
|
|
107
|
+
if (max && isAfterDay(date, max))
|
|
108
|
+
return withDay(date, max);
|
|
109
|
+
return date;
|
|
110
|
+
}
|
|
111
|
+
// -----------------------------------------------------------------------------
|
|
112
|
+
// Locale-derived names (cached per locale)
|
|
113
|
+
// -----------------------------------------------------------------------------
|
|
114
|
+
const monthNameCache = new Map();
|
|
115
|
+
export function getMonthNames(locale, width = 'long') {
|
|
116
|
+
const key = `${locale}|${width}`;
|
|
117
|
+
let names = monthNameCache.get(key);
|
|
118
|
+
if (!names) {
|
|
119
|
+
const fmt = new Intl.DateTimeFormat(locale, { month: width });
|
|
120
|
+
names = Array.from({ length: 12 }, (_, m) => fmt.format(new Date(2024, m, 1, 12)));
|
|
121
|
+
monthNameCache.set(key, names);
|
|
122
|
+
}
|
|
123
|
+
return names;
|
|
124
|
+
}
|
|
125
|
+
const weekdayCache = new Map();
|
|
126
|
+
/** Weekday labels in grid order for the given week start. */
|
|
127
|
+
export function getWeekdayLabels(locale, weekStartsOn) {
|
|
128
|
+
const key = `${locale}|${weekStartsOn}`;
|
|
129
|
+
let labels = weekdayCache.get(key);
|
|
130
|
+
if (!labels) {
|
|
131
|
+
const narrow = new Intl.DateTimeFormat(locale, { weekday: 'narrow' });
|
|
132
|
+
const long = new Intl.DateTimeFormat(locale, { weekday: 'long' });
|
|
133
|
+
labels = Array.from({ length: 7 }, (_, i) => {
|
|
134
|
+
// 2024-09-01 is a Sunday; offset into the wanted weekday.
|
|
135
|
+
const day = new Date(2024, 8, 1 + ((weekStartsOn + i) % 7), 12);
|
|
136
|
+
return { narrow: narrow.format(day), long: long.format(day) };
|
|
137
|
+
});
|
|
138
|
+
weekdayCache.set(key, labels);
|
|
139
|
+
}
|
|
140
|
+
return labels;
|
|
141
|
+
}
|
|
142
|
+
// -----------------------------------------------------------------------------
|
|
143
|
+
// Formatting
|
|
144
|
+
// -----------------------------------------------------------------------------
|
|
145
|
+
export function formatDay(date, locale) {
|
|
146
|
+
return new Intl.DateTimeFormat(locale, { dateStyle: 'medium' }).format(date);
|
|
147
|
+
}
|
|
148
|
+
export function formatDayTime(date, locale) {
|
|
149
|
+
return new Intl.DateTimeFormat(locale, {
|
|
150
|
+
dateStyle: 'medium',
|
|
151
|
+
timeStyle: 'short',
|
|
152
|
+
hour12: false,
|
|
153
|
+
}).format(date);
|
|
154
|
+
}
|
|
155
|
+
/** Numeric form for text fields, e.g. "08/08/2024" or "08/08/2024, 00:00". */
|
|
156
|
+
export function formatNumeric(date, locale, withTime) {
|
|
157
|
+
const day = new Intl.DateTimeFormat(locale, {
|
|
158
|
+
year: 'numeric',
|
|
159
|
+
month: '2-digit',
|
|
160
|
+
day: '2-digit',
|
|
161
|
+
}).format(date);
|
|
162
|
+
if (!withTime)
|
|
163
|
+
return day;
|
|
164
|
+
const time = new Intl.DateTimeFormat(locale, {
|
|
165
|
+
hour: '2-digit',
|
|
166
|
+
minute: '2-digit',
|
|
167
|
+
hour12: false,
|
|
168
|
+
}).format(date);
|
|
169
|
+
return `${day}, ${time}`;
|
|
170
|
+
}
|
|
171
|
+
// -----------------------------------------------------------------------------
|
|
172
|
+
// Parsing — numeric dates in the locale's own part order
|
|
173
|
+
// -----------------------------------------------------------------------------
|
|
174
|
+
const partOrderCache = new Map();
|
|
175
|
+
function getPartOrder(locale) {
|
|
176
|
+
let order = partOrderCache.get(locale);
|
|
177
|
+
if (!order) {
|
|
178
|
+
const parts = new Intl.DateTimeFormat(locale, {
|
|
179
|
+
year: 'numeric',
|
|
180
|
+
month: '2-digit',
|
|
181
|
+
day: '2-digit',
|
|
182
|
+
}).formatToParts(new Date(2024, 0, 15, 12));
|
|
183
|
+
order = parts
|
|
184
|
+
.filter((p) => ['year', 'month', 'day'].includes(p.type))
|
|
185
|
+
.map((p) => p.type);
|
|
186
|
+
partOrderCache.set(locale, order);
|
|
187
|
+
}
|
|
188
|
+
return order;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Parse a numeric date string ("08/08/2024", "8.8.2024, 14:30") using the
|
|
192
|
+
* locale's part order. Returns null on anything that doesn't resolve to a
|
|
193
|
+
* real calendar day. Two-digit years are rejected rather than guessed.
|
|
194
|
+
*/
|
|
195
|
+
export function parseNumeric(text, locale) {
|
|
196
|
+
const groups = text.match(/\d+/g);
|
|
197
|
+
if (!groups || groups.length < 3 || groups.length > 5)
|
|
198
|
+
return null;
|
|
199
|
+
const order = getPartOrder(locale);
|
|
200
|
+
const dateParts = { year: 0, month: 0, day: 0 };
|
|
201
|
+
order.forEach((type, i) => {
|
|
202
|
+
dateParts[type] = Number(groups[i]);
|
|
203
|
+
});
|
|
204
|
+
const { year, month, day } = dateParts;
|
|
205
|
+
if (String(year).length < 4 || month < 1 || month > 12 || day < 1 || day > 31)
|
|
206
|
+
return null;
|
|
207
|
+
const hour = groups.length >= 4 ? Number(groups[3]) : 0;
|
|
208
|
+
const minute = groups.length >= 5 ? Number(groups[4]) : 0;
|
|
209
|
+
if (hour > 23 || minute > 59)
|
|
210
|
+
return null;
|
|
211
|
+
const parsed = new Date(year, month - 1, day, hour, minute, 0, 0);
|
|
212
|
+
// Reject overflowed days (e.g. Feb 31 rolling into March).
|
|
213
|
+
if (parsed.getMonth() !== month - 1 || parsed.getDate() !== day)
|
|
214
|
+
return null;
|
|
215
|
+
return parsed;
|
|
216
|
+
}
|
|
217
|
+
// -----------------------------------------------------------------------------
|
|
218
|
+
// Locale resolution + shared preset config (lives here so component files
|
|
219
|
+
// export only components — react-refresh constraint).
|
|
220
|
+
// -----------------------------------------------------------------------------
|
|
221
|
+
export function resolveLocale(locale) {
|
|
222
|
+
if (locale)
|
|
223
|
+
return locale;
|
|
224
|
+
if (typeof document !== 'undefined' && document.documentElement.lang) {
|
|
225
|
+
return document.documentElement.lang;
|
|
226
|
+
}
|
|
227
|
+
return 'en-US';
|
|
228
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { Calendar } from './Calendar';
|
|
2
|
+
export { DatePicker } from './DatePicker';
|
|
3
|
+
export { DateRangePicker } from './DateRangePicker';
|
|
4
|
+
export { defaultDateRangePresets } from './presets';
|
|
5
|
+
export { addDays, addMonths, addYears, isSameDay, withDay, } from './date-utils';
|
|
6
|
+
export type { DateRange, WeekStart } from './date-utils';
|
|
7
|
+
export type { CalendarProps, CalendarLabels, DatePickerProps, DatePickerLabels, DateRangePickerProps, DateRangePickerLabels, DateRangePreset, } from './types';
|
|
8
|
+
export { defaultCalendarLabels, defaultDatePickerLabels, defaultDateRangePickerLabels, } from './types';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { Calendar } from './Calendar.js';
|
|
2
|
+
export { DatePicker } from './DatePicker.js';
|
|
3
|
+
export { DateRangePicker } from './DateRangePicker.js';
|
|
4
|
+
export { defaultDateRangePresets } from './presets.js';
|
|
5
|
+
export { addDays, addMonths, addYears, isSameDay, withDay, } from './date-utils.js';
|
|
6
|
+
export { defaultCalendarLabels, defaultDatePickerLabels, defaultDateRangePickerLabels, } from './types.js';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { addDays, addMonths, startOfMonth, startOfWeek } from './date-utils.js';
|
|
2
|
+
/** The standard quick-range rail: Today … Last month. */
|
|
3
|
+
export const defaultDateRangePresets = [
|
|
4
|
+
{
|
|
5
|
+
label: 'Today',
|
|
6
|
+
getRange: (now) => ({ from: now, to: now }),
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
label: 'Yesterday',
|
|
10
|
+
getRange: (now) => ({ from: addDays(now, -1), to: addDays(now, -1) }),
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
label: 'Last week',
|
|
14
|
+
getRange: (now) => {
|
|
15
|
+
const thisWeek = startOfWeek(now, 1);
|
|
16
|
+
return { from: addDays(thisWeek, -7), to: addDays(thisWeek, -1) };
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
label: 'Last 2 weeks',
|
|
21
|
+
getRange: (now) => {
|
|
22
|
+
const thisWeek = startOfWeek(now, 1);
|
|
23
|
+
return { from: addDays(thisWeek, -14), to: addDays(thisWeek, -1) };
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
label: 'This month',
|
|
28
|
+
getRange: (now) => ({ from: startOfMonth(now), to: now }),
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
label: 'Last month',
|
|
32
|
+
getRange: (now) => {
|
|
33
|
+
const first = startOfMonth(addMonths(now, -1));
|
|
34
|
+
return { from: first, to: addDays(startOfMonth(now), -1) };
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
];
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { DateRange, WeekStart } from './date-utils';
|
|
3
|
+
export type { DateRange, WeekStart };
|
|
4
|
+
/**
|
|
5
|
+
* Props shared by everything that renders a day grid. All values are plain
|
|
6
|
+
* Date objects with wall-clock semantics — the components never do timezone
|
|
7
|
+
* math; the host owns interpretation.
|
|
8
|
+
*/
|
|
9
|
+
export type CalendarBaseProps = {
|
|
10
|
+
/** Earliest selectable day (inclusive, time-of-day ignored). */
|
|
11
|
+
min?: Date;
|
|
12
|
+
/** Latest selectable day (inclusive, time-of-day ignored). */
|
|
13
|
+
max?: Date;
|
|
14
|
+
/** Per-day disable hook, applied on top of min/max. */
|
|
15
|
+
isDayDisabled?: (day: Date) => boolean;
|
|
16
|
+
/** First day of the week. 0 = Sunday … 6 = Saturday. @default 1 (Monday) */
|
|
17
|
+
weekStartsOn?: WeekStart;
|
|
18
|
+
/**
|
|
19
|
+
* BCP 47 locale for month/weekday names and numeric formats.
|
|
20
|
+
* @default the document language, falling back to 'en-US'
|
|
21
|
+
*/
|
|
22
|
+
locale?: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Overridable strings for Calendar i18n. Month and weekday *names* come from
|
|
26
|
+
* Intl via `locale`; these cover the chrome.
|
|
27
|
+
*/
|
|
28
|
+
export type CalendarLabels = {
|
|
29
|
+
prevMonth?: string;
|
|
30
|
+
nextMonth?: string;
|
|
31
|
+
prevYear?: string;
|
|
32
|
+
nextYear?: string;
|
|
33
|
+
/** Accessible label for the caption button that opens the month picker. */
|
|
34
|
+
openMonthPicker?: (caption: string) => string;
|
|
35
|
+
/** Accessible label for a day cell. */
|
|
36
|
+
day?: (formatted: string) => string;
|
|
37
|
+
today?: string;
|
|
38
|
+
selected?: string;
|
|
39
|
+
};
|
|
40
|
+
export declare const defaultCalendarLabels: Required<CalendarLabels>;
|
|
41
|
+
export type CalendarProps = CalendarBaseProps & {
|
|
42
|
+
/** Selected day. */
|
|
43
|
+
value?: Date | null;
|
|
44
|
+
/**
|
|
45
|
+
* Day clicked/chosen. Receives the calendar day at noon; callers merge
|
|
46
|
+
* their own time-of-day (see `withDay`).
|
|
47
|
+
*/
|
|
48
|
+
onChange?: (day: Date) => void;
|
|
49
|
+
/** Controlled visible month (any day within it). */
|
|
50
|
+
month?: Date;
|
|
51
|
+
/** Initial visible month for uncontrolled usage. */
|
|
52
|
+
defaultMonth?: Date;
|
|
53
|
+
onMonthChange?: (month: Date) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Range to paint (endpoints + in-between fill). Painting only — range
|
|
56
|
+
* *selection* logic lives in DateRangePicker.
|
|
57
|
+
*/
|
|
58
|
+
range?: DateRange | null;
|
|
59
|
+
/** Hide the caption/nav bar (for multi-month layouts that render their own). */
|
|
60
|
+
labels?: CalendarLabels;
|
|
61
|
+
'aria-label'?: string;
|
|
62
|
+
className?: string;
|
|
63
|
+
};
|
|
64
|
+
export type DatePickerLabels = {
|
|
65
|
+
/** Popover heading. */
|
|
66
|
+
title?: string;
|
|
67
|
+
titleWithTime?: string;
|
|
68
|
+
now?: string;
|
|
69
|
+
close?: string;
|
|
70
|
+
/** Placeholder on the trigger when empty. */
|
|
71
|
+
placeholder?: string;
|
|
72
|
+
timeSection?: string;
|
|
73
|
+
dateSection?: string;
|
|
74
|
+
month?: string;
|
|
75
|
+
dayOfMonth?: string;
|
|
76
|
+
year?: string;
|
|
77
|
+
hour?: string;
|
|
78
|
+
minute?: string;
|
|
79
|
+
am?: string;
|
|
80
|
+
pm?: string;
|
|
81
|
+
meridiem?: string;
|
|
82
|
+
/** Trigger aria-label when a value is set: `label(formattedValue)`. */
|
|
83
|
+
trigger?: (formatted: string) => string;
|
|
84
|
+
triggerEmpty?: string;
|
|
85
|
+
};
|
|
86
|
+
export declare const defaultDatePickerLabels: Required<DatePickerLabels>;
|
|
87
|
+
export type DatePickerProps = CalendarBaseProps & {
|
|
88
|
+
value?: Date | null;
|
|
89
|
+
defaultValue?: Date | null;
|
|
90
|
+
onChange?: (value: Date) => void;
|
|
91
|
+
/** Include the time field (and format the trigger with time). */
|
|
92
|
+
withTime?: boolean;
|
|
93
|
+
/** 12-hour time UI with an AM/PM toggle. @default true */
|
|
94
|
+
hour12?: boolean;
|
|
95
|
+
/** Display-only zone badge next to the time field, e.g. "UTC+0". */
|
|
96
|
+
zoneLabel?: ReactNode;
|
|
97
|
+
disabled?: boolean;
|
|
98
|
+
labels?: DatePickerLabels;
|
|
99
|
+
calendarLabels?: CalendarLabels;
|
|
100
|
+
'aria-label'?: string;
|
|
101
|
+
className?: string;
|
|
102
|
+
id?: string;
|
|
103
|
+
};
|
|
104
|
+
export type DateRangePreset = {
|
|
105
|
+
label: string;
|
|
106
|
+
/** Resolve the preset against "now" so stories/tests can pin the clock. */
|
|
107
|
+
getRange: (now: Date) => DateRange;
|
|
108
|
+
};
|
|
109
|
+
export type DateRangePickerLabels = {
|
|
110
|
+
from?: string;
|
|
111
|
+
to?: string;
|
|
112
|
+
apply?: string;
|
|
113
|
+
cancel?: string;
|
|
114
|
+
placeholder?: string;
|
|
115
|
+
presets?: string;
|
|
116
|
+
trigger?: (formatted: string) => string;
|
|
117
|
+
triggerEmpty?: string;
|
|
118
|
+
};
|
|
119
|
+
export declare const defaultDateRangePickerLabels: Required<DateRangePickerLabels>;
|
|
120
|
+
export type DateRangePickerProps = CalendarBaseProps & {
|
|
121
|
+
value?: DateRange | null;
|
|
122
|
+
defaultValue?: DateRange | null;
|
|
123
|
+
/** Fires on Apply with a complete range. */
|
|
124
|
+
onChange?: (range: DateRange) => void;
|
|
125
|
+
/** Show times in the trigger and From/To fields. */
|
|
126
|
+
withTime?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Quick-range presets for the side rail; `false` hides the rail.
|
|
129
|
+
* @default the standard six (Today … Last month)
|
|
130
|
+
*/
|
|
131
|
+
presets?: DateRangePreset[] | false;
|
|
132
|
+
disabled?: boolean;
|
|
133
|
+
labels?: DateRangePickerLabels;
|
|
134
|
+
calendarLabels?: CalendarLabels;
|
|
135
|
+
'aria-label'?: string;
|
|
136
|
+
className?: string;
|
|
137
|
+
id?: string;
|
|
138
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export const defaultCalendarLabels = {
|
|
2
|
+
prevMonth: 'Previous month',
|
|
3
|
+
nextMonth: 'Next month',
|
|
4
|
+
prevYear: 'Previous year',
|
|
5
|
+
nextYear: 'Next year',
|
|
6
|
+
openMonthPicker: (caption) => `${caption} — choose month and year`,
|
|
7
|
+
day: (formatted) => formatted,
|
|
8
|
+
today: 'today',
|
|
9
|
+
selected: 'selected',
|
|
10
|
+
};
|
|
11
|
+
export const defaultDatePickerLabels = {
|
|
12
|
+
title: 'Pick a Date',
|
|
13
|
+
titleWithTime: 'Pick a Date and Time',
|
|
14
|
+
now: 'Now',
|
|
15
|
+
close: 'Close',
|
|
16
|
+
placeholder: 'Select date',
|
|
17
|
+
timeSection: 'Time',
|
|
18
|
+
dateSection: 'Date',
|
|
19
|
+
month: 'Month',
|
|
20
|
+
dayOfMonth: 'Day',
|
|
21
|
+
year: 'Year',
|
|
22
|
+
hour: 'Hour',
|
|
23
|
+
minute: 'Minute',
|
|
24
|
+
am: 'AM',
|
|
25
|
+
pm: 'PM',
|
|
26
|
+
meridiem: 'AM or PM',
|
|
27
|
+
trigger: (formatted) => `Change date, ${formatted}`,
|
|
28
|
+
triggerEmpty: 'Select date',
|
|
29
|
+
};
|
|
30
|
+
export const defaultDateRangePickerLabels = {
|
|
31
|
+
from: 'From',
|
|
32
|
+
to: 'To',
|
|
33
|
+
apply: 'Apply',
|
|
34
|
+
cancel: 'Cancel',
|
|
35
|
+
placeholder: 'Select date range',
|
|
36
|
+
presets: 'Quick ranges',
|
|
37
|
+
trigger: (formatted) => `Change date range, ${formatted}`,
|
|
38
|
+
triggerEmpty: 'Select date range',
|
|
39
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import React, { useCallback, useEffect, useId, useMemo, useRef, useState, cloneElement, isValidElement, } from 'react';
|
|
3
|
-
import { useFloating, offset, flip, shift, autoUpdate, FloatingPortal, useDismiss, useInteractions, useRole, FloatingFocusManager, } from '@floating-ui/react';
|
|
3
|
+
import { useFloating, offset, flip, shift, size, autoUpdate, FloatingPortal, useDismiss, useInteractions, useRole, FloatingFocusManager, } from '@floating-ui/react';
|
|
4
4
|
import { cx } from '../../utils/cx.js';
|
|
5
5
|
import { getPortalRootFor } from '../../utils/portal.js';
|
|
6
6
|
import { PopoverContext, usePopoverContext } from './PopoverContext.js';
|
|
@@ -114,7 +114,21 @@ function PopoverContentInner({ side = 'bottom', align = 'start', sideOffset = 4,
|
|
|
114
114
|
placement: toPlacement(side, align),
|
|
115
115
|
open: true, // Always true when mounted (gate handles the conditional)
|
|
116
116
|
onOpenChange: setOpen,
|
|
117
|
-
middleware: [
|
|
117
|
+
middleware: [
|
|
118
|
+
offset(sideOffset),
|
|
119
|
+
flip(),
|
|
120
|
+
shift({ padding: 8 }),
|
|
121
|
+
// When even the best placement can't fit the content, expose the
|
|
122
|
+
// available height so the panel can cap itself and scroll (see
|
|
123
|
+
// --tui-popover-available-height in styles.scss). Output var, not an
|
|
124
|
+
// API token — the middleware writes it, the stylesheet reads it.
|
|
125
|
+
size({
|
|
126
|
+
padding: 8,
|
|
127
|
+
apply({ availableHeight, elements }) {
|
|
128
|
+
elements.floating.style.setProperty('--tui-popover-available-height', `${Math.floor(availableHeight)}px`);
|
|
129
|
+
},
|
|
130
|
+
}),
|
|
131
|
+
],
|
|
118
132
|
whileElementsMounted: autoUpdate,
|
|
119
133
|
});
|
|
120
134
|
// Sync reference element
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { ReactNode } from 'react';
|
|
2
2
|
import type { RovingItemRecord } from '../../utils/use-roving-group';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Size } from '../../types/sizes';
|
|
4
4
|
export type SegmentedControlValue = string | number;
|
|
5
5
|
export type SegmentedControlVariant = 'pill' | 'outline' | 'underline';
|
|
6
|
-
export type SegmentedControlSize =
|
|
6
|
+
export type SegmentedControlSize = Size;
|
|
7
7
|
export type SegmentedControlOrientation = 'horizontal' | 'vertical';
|
|
8
8
|
export type SegmentedControlProps = {
|
|
9
9
|
/** Controlled selected value */
|
package/components/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export { Chip } from './Chip';
|
|
|
10
10
|
export { ChipGroup } from './ChipGroup';
|
|
11
11
|
export { Chips } from './Chips';
|
|
12
12
|
export { ContentIndicator } from './ContentIndicator';
|
|
13
|
+
export { Calendar, DatePicker, DateRangePicker, defaultDateRangePresets, defaultCalendarLabels, defaultDatePickerLabels, defaultDateRangePickerLabels, } from './DatePicker';
|
|
13
14
|
export { Combobox, ComboboxContent, ComboboxOption, ComboboxGroup, ComboboxLabel, useCombobox } from './Combobox';
|
|
14
15
|
export { Dropdown, DropdownTrigger, DropdownContent, DropdownItem, DropdownSeparator, DropdownHeader, useDropdown } from './Dropdown';
|
|
15
16
|
export { Field } from './Field';
|
package/components/index.js
CHANGED
|
@@ -8,6 +8,7 @@ export { Chip } from './Chip/index.js';
|
|
|
8
8
|
export { ChipGroup } from './ChipGroup/index.js';
|
|
9
9
|
export { Chips } from './Chips/index.js';
|
|
10
10
|
export { ContentIndicator } from './ContentIndicator/index.js';
|
|
11
|
+
export { Calendar, DatePicker, DateRangePicker, defaultDateRangePresets, defaultCalendarLabels, defaultDatePickerLabels, defaultDateRangePickerLabels, } from './DatePicker/index.js';
|
|
11
12
|
export { Combobox, ComboboxContent, ComboboxOption, ComboboxGroup, ComboboxLabel, useCombobox } from './Combobox/index.js';
|
|
12
13
|
export { Dropdown, DropdownTrigger, DropdownContent, DropdownItem, DropdownSeparator, DropdownHeader, useDropdown } from './Dropdown/index.js';
|
|
13
14
|
export { Field } from './Field/index.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tangible/ui",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Tangible Design System",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./components/index.js",
|
|
@@ -88,6 +88,10 @@
|
|
|
88
88
|
"import": "./components/ContentIndicator/index.js",
|
|
89
89
|
"types": "./components/ContentIndicator/index.d.ts"
|
|
90
90
|
},
|
|
91
|
+
"./components/DatePicker": {
|
|
92
|
+
"import": "./components/DatePicker/index.js",
|
|
93
|
+
"types": "./components/DatePicker/index.d.ts"
|
|
94
|
+
},
|
|
91
95
|
"./components/Dropdown": {
|
|
92
96
|
"import": "./components/Dropdown/index.js",
|
|
93
97
|
"types": "./components/Dropdown/index.d.ts"
|