@milktop/react-ui 0.3.22 → 0.3.24
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 +2 -1
- package/dist/card/Card.d.ts +1 -1
- package/dist/chart/AreaChart.d.ts +2 -1
- package/dist/chart/AreaChart.js +9 -3
- package/dist/date-range-filter/DateRangeFilter.d.ts +42 -0
- package/dist/date-range-filter/DateRangeFilter.js +135 -0
- package/dist/date-range-filter/date-range-filter.css +27 -0
- package/dist/format/messages.d.ts +6 -0
- package/dist/format/messages.js +20 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,7 +57,8 @@ So far:
|
|
|
57
57
|
- Inputs: Input · Textarea · Editor (rich text on TipTap, with image uploads) · NumberInput · PasswordInput · PinInput · TagsInput ·
|
|
58
58
|
Slider · FileUpload
|
|
59
59
|
- Pickers: TimeInput · NativeSelect · SwatchPicker · Select (one component: searchable, server `load`, `onCreate`,
|
|
60
|
-
multiple, tags; Combobox's parts for building one by hand) · DatePicker
|
|
60
|
+
multiple, tags; Combobox's parts for building one by hand) · DatePicker ·
|
|
61
|
+
DateRangeFilter (preset ranges beside a range calendar, for filtering a list)
|
|
61
62
|
- Choices: Checkbox · CheckboxGroup · Switch · RadioGroup · Segmented ·
|
|
62
63
|
ThemeToggle (`colorScheme`, `useColorScheme`) · Appearance (light and dark, the accent and the
|
|
63
64
|
sidebar style behind one button; `appearance`, `useAppearance`)
|
package/dist/card/Card.d.ts
CHANGED
|
@@ -64,9 +64,9 @@ declare function CardShortcut({ heading, description, icon, actions, footer, var
|
|
|
64
64
|
key?: import("react").Key | null | undefined;
|
|
65
65
|
slot?: string | undefined | undefined;
|
|
66
66
|
style?: import("react").CSSProperties | undefined;
|
|
67
|
+
defaultValue?: string | number | readonly string[] | undefined;
|
|
67
68
|
ref?: import("react").Ref<HTMLDivElement> | undefined;
|
|
68
69
|
defaultChecked?: boolean | undefined | undefined;
|
|
69
|
-
defaultValue?: string | number | readonly string[] | undefined;
|
|
70
70
|
suppressContentEditableWarning?: boolean | undefined | undefined;
|
|
71
71
|
suppressHydrationWarning?: boolean | undefined | undefined;
|
|
72
72
|
accessKey?: string | undefined | undefined;
|
|
@@ -18,6 +18,7 @@ export type AreaChartProps = ChartProps & {
|
|
|
18
18
|
zero?: boolean;
|
|
19
19
|
time?: boolean;
|
|
20
20
|
formatX?: ((value: unknown) => string) | null;
|
|
21
|
+
xTicks?: (Date | string)[] | null;
|
|
21
22
|
tooltipLabel?: ((row: ChartRow) => string) | null;
|
|
22
23
|
};
|
|
23
|
-
export declare function AreaChart({ data, x, y, series, height, format, label: labelProp, grid, curve, stacked, zero, time, formatX, tooltipLabel, classes, ...rest }: AreaChartProps): import("react").JSX.Element;
|
|
24
|
+
export declare function AreaChart({ data, x, y, series, height, format, label: labelProp, grid, curve, stacked, zero, time, formatX, xTicks, tooltipLabel, classes, ...rest }: AreaChartProps): import("react").JSX.Element;
|
package/dist/chart/AreaChart.js
CHANGED
|
@@ -14,6 +14,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
14
14
|
* - `time`: `x` holds dates (Date, or '2024-03-08'), rows in date order: each point sits by its
|
|
15
15
|
* date, so a year's gap looks like one, and the axis is marked in months and years
|
|
16
16
|
* - `formatX(value)`: the axis' labels (a Date when `time`); `tooltipLabel(row)`: the tooltip's heading
|
|
17
|
+
* - `xTicks`: where `time` marks its axis (dates), in place of its months and years: a birthday a year
|
|
17
18
|
* - `height` (240 px), `format(value)` for ticks and tooltips, `grid` (lines; true)
|
|
18
19
|
* - `label`: what it shows, for assistive tech (a hidden table of the data)
|
|
19
20
|
*/
|
|
@@ -24,7 +25,7 @@ import { area, line, curveMonotoneX, curveLinear } from 'd3-shape';
|
|
|
24
25
|
import { ChartFrame } from './ChartFrame.js';
|
|
25
26
|
import { seriesOf, formatter, pad, yScale, fitScale, leftFor, labelStep, num, toDate } from './chart.js';
|
|
26
27
|
import { partsOf } from '../utils.js';
|
|
27
|
-
export function AreaChart({ data = [], x = 'label', y = null, series = null, height = 240, format = null, label: labelProp, grid = true, curve = 'smooth', stacked = false, zero = true, time = false, formatX = null, tooltipLabel = null, classes, ...rest }) {
|
|
28
|
+
export function AreaChart({ data = [], x = 'label', y = null, series = null, height = 240, format = null, label: labelProp, grid = true, curve = 'smooth', stacked = false, zero = true, time = false, formatX = null, xTicks = null, tooltipLabel = null, classes, ...rest }) {
|
|
28
29
|
const t = useMessages();
|
|
29
30
|
const label = labelProp ?? t.chart.label;
|
|
30
31
|
const part = partsOf('chart', classes);
|
|
@@ -61,7 +62,12 @@ export function AreaChart({ data = [], x = 'label', y = null, series = null, hei
|
|
|
61
62
|
: (value) => String(value ?? ''));
|
|
62
63
|
const labelOf = tooltipLabel ?? ((row) => time ? toDate(row[x]).toLocaleDateString(locale, { dateStyle: 'medium' }) : tickLabel(row[x]));
|
|
63
64
|
// About one date every 80px, on whole months and years
|
|
64
|
-
const
|
|
65
|
+
const [start, end] = byDate.domain();
|
|
66
|
+
const timeTicks = !time || rows.length < 2 ? []
|
|
67
|
+
: xTicks ? xTicks.map(toDate).filter((tick) => tick >= start && tick <= end)
|
|
68
|
+
: byDate.ticks(Math.max(2, Math.floor(innerW / 80)));
|
|
69
|
+
// A mark near an end is drawn inward from it, so its label stays inside the chart
|
|
70
|
+
const anchorAt = (pos) => (pos < 40 ? 'start' : pos > innerW - 40 ? 'end' : 'middle');
|
|
65
71
|
const shape = curve === 'linear' ? curveLinear : curveMonotoneX;
|
|
66
72
|
// Fitted, the fill runs down to the axis' foot rather than to 0, which is off the chart
|
|
67
73
|
const fill = area().x((_, i) => at(i)).y0((d) => (fitted ? innerH : ys(d[0]))).y1((d) => ys(d[1])).curve(shape);
|
|
@@ -77,5 +83,5 @@ export function AreaChart({ data = [], x = 'label', y = null, series = null, hei
|
|
|
77
83
|
nearest = i; });
|
|
78
84
|
setHover(nearest);
|
|
79
85
|
}
|
|
80
|
-
return (_jsx(ChartFrame, { ...rest, rows: rows, x: x, labelOf: labelOf, list: list, fmt: fmt, height: height, label: label, classes: classes, hover: hover, onHover: setHover, onMove: move, width: width, onWidth: setWidth, tipLeft: hover == null ? 0 : left + at(hover), flip: hover != null && at(hover) > innerW * 0.6, children: _jsxs("svg", { ...part('svg'), width: width, height: height, "aria-hidden": "true", children: [_jsx("defs", { children: list.map((s, i) => (_jsxs("linearGradient", { id: `${id}-${i}`, x1: "0", x2: "0", y1: "0", y2: "1", children: [_jsx("stop", { offset: "0%", stopColor: s.color, stopOpacity: "0.28" }), _jsx("stop", { offset: "100%", stopColor: s.color, stopOpacity: "0.02" })] }, s.key))) }), _jsxs("g", { transform: `translate(${left},${pad.top})`, children: [ticks.map((tick) => (_jsxs("g", { children: [grid && _jsx("line", { ...part('grid'), x1: "0", x2: innerW, y1: ys(tick), y2: ys(tick) }), _jsx("text", { ...part('tick'), x: "-8", y: ys(tick), dy: "0.32em", textAnchor: "end", children: fmt(tick) })] }, tick))), time ? timeTicks.map((tick) => (_jsx("text", { ...part('tick'), x: byDate(tick), y: innerH + 18, textAnchor:
|
|
86
|
+
return (_jsx(ChartFrame, { ...rest, rows: rows, x: x, labelOf: labelOf, list: list, fmt: fmt, height: height, label: label, classes: classes, hover: hover, onHover: setHover, onMove: move, width: width, onWidth: setWidth, tipLeft: hover == null ? 0 : left + at(hover), flip: hover != null && at(hover) > innerW * 0.6, children: _jsxs("svg", { ...part('svg'), width: width, height: height, "aria-hidden": "true", children: [_jsx("defs", { children: list.map((s, i) => (_jsxs("linearGradient", { id: `${id}-${i}`, x1: "0", x2: "0", y1: "0", y2: "1", children: [_jsx("stop", { offset: "0%", stopColor: s.color, stopOpacity: "0.28" }), _jsx("stop", { offset: "100%", stopColor: s.color, stopOpacity: "0.02" })] }, s.key))) }), _jsxs("g", { transform: `translate(${left},${pad.top})`, children: [ticks.map((tick) => (_jsxs("g", { children: [grid && _jsx("line", { ...part('grid'), x1: "0", x2: innerW, y1: ys(tick), y2: ys(tick) }), _jsx("text", { ...part('tick'), x: "-8", y: ys(tick), dy: "0.32em", textAnchor: "end", children: fmt(tick) })] }, tick))), time ? timeTicks.map((tick) => (_jsx("text", { ...part('tick'), x: byDate(tick), y: innerH + 18, textAnchor: anchorAt(byDate(tick)), children: tickLabel(tick) }, +tick))) : rows.map((row, i) => i % step === 0 && (_jsx("text", { ...part('tick'), x: at(i), y: innerH + 18, textAnchor: i === 0 ? 'start' : i === rows.length - 1 ? 'end' : 'middle', children: tickLabel(row[x]) }, i))), list.map((s, i) => (_jsxs("g", { children: [_jsx("path", { ...part('area'), d: fill(bands[i]) ?? '', fill: `url(#${id}-${i})` }), _jsx("path", { ...part('line'), d: stroke(bands[i]) ?? '', stroke: s.color })] }, s.key))), hover != null && _jsxs(_Fragment, { children: [_jsx("line", { ...part('cursor'), x1: at(hover), x2: at(hover), y1: "0", y2: innerH }), list.map((s, i) => _jsx("circle", { ...part('dot'), cx: at(hover), cy: ys(bands[i][hover][1]), r: "4", fill: s.color }, s.key))] })] })] }) }));
|
|
81
87
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type PopoverProps } from '../popover/Popover.js';
|
|
2
|
+
import { type Classes } from '../utils.js';
|
|
3
|
+
import '../theme.css';
|
|
4
|
+
import './date-range-filter.css';
|
|
5
|
+
export type DateRangeKey = keyof typeof dateRanges;
|
|
6
|
+
export type DateRangePreset = {
|
|
7
|
+
label: string;
|
|
8
|
+
range: (firstDay: number) => (Date | string)[];
|
|
9
|
+
};
|
|
10
|
+
export type DateRangeFilterProps = {
|
|
11
|
+
value?: string[];
|
|
12
|
+
defaultValue?: string[];
|
|
13
|
+
onValueChange?: (value: string[]) => void;
|
|
14
|
+
presets?: (DateRangeKey | DateRangePreset)[];
|
|
15
|
+
placeholder?: string | null;
|
|
16
|
+
placement?: PopoverProps['placement'];
|
|
17
|
+
locale?: string | null;
|
|
18
|
+
className?: string;
|
|
19
|
+
classes?: Classes<'trigger' | 'panel' | 'presets' | 'preset' | 'clear' | 'calendar'>;
|
|
20
|
+
};
|
|
21
|
+
export declare const dateRanges: {
|
|
22
|
+
today: () => Date[];
|
|
23
|
+
yesterday: () => Date[];
|
|
24
|
+
tomorrow: () => Date[];
|
|
25
|
+
last7: () => Date[];
|
|
26
|
+
last30: () => Date[];
|
|
27
|
+
next7: () => Date[];
|
|
28
|
+
next30: () => Date[];
|
|
29
|
+
thisWeek: (firstDay: number) => Date[];
|
|
30
|
+
lastWeek: (firstDay: number) => Date[];
|
|
31
|
+
nextWeek: (firstDay: number) => Date[];
|
|
32
|
+
thisMonth: () => Date[];
|
|
33
|
+
lastMonth: () => Date[];
|
|
34
|
+
nextMonth: () => Date[];
|
|
35
|
+
thisQuarter: () => Date[];
|
|
36
|
+
lastQuarter: () => Date[];
|
|
37
|
+
thisYear: () => Date[];
|
|
38
|
+
lastYear: () => Date[];
|
|
39
|
+
};
|
|
40
|
+
declare function DateRangeFilterShortcut({ value, defaultValue, onValueChange, presets, placeholder, placement, locale: localeProp, className, classes, }: DateRangeFilterProps): import("react").JSX.Element;
|
|
41
|
+
export declare const DateRangeFilter: typeof DateRangeFilterShortcut;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* A date range filter: a button that opens preset ranges beside a range
|
|
4
|
+
* calendar, for narrowing a list to some dates.
|
|
5
|
+
*
|
|
6
|
+
* <DateRangeFilter value={dates} onValueChange={setDates} />
|
|
7
|
+
* <DateRangeFilter presets={['today', 'next7', 'nextMonth']} value={dates} onValueChange={setDates} />
|
|
8
|
+
*
|
|
9
|
+
* - `value`, `defaultValue`: [from, to] as ISO dates ('YYYY-MM-DD'), empty for all dates
|
|
10
|
+
* - `onValueChange`: called with [from, to] once both ends are picked, or [] when cleared
|
|
11
|
+
* - `presets`: keys of the built-in ranges, or `{ label, range }` for one of
|
|
12
|
+
* your own (below), mixed in any order
|
|
13
|
+
* - `placeholder`: the button's text with no dates ("All dates")
|
|
14
|
+
* - `placement`: where the panel opens ('bottom-end')
|
|
15
|
+
* - `locale`: for the dates on the button and the calendar (the
|
|
16
|
+
* LocaleProvider's, or 'en-GB')
|
|
17
|
+
*
|
|
18
|
+
* A preset fills in the calendar, and dates picked there light up the preset
|
|
19
|
+
* they match. The panel stays open until Escape or a click outside.
|
|
20
|
+
*
|
|
21
|
+
* A preset of your own is a `label` for its button (and the trigger, once
|
|
22
|
+
* picked) and a `range` function returning [from, to] as local Dates or ISO
|
|
23
|
+
* strings, both days included. It runs each time it's used, so it can't go
|
|
24
|
+
* stale, and it's given the locale's first day of the week (1 Monday to 7
|
|
25
|
+
* Sunday) for ranges that care. Its label is yours to translate.
|
|
26
|
+
*
|
|
27
|
+
* Built-in ranges: today, yesterday, tomorrow, last7, last30, next7, next30,
|
|
28
|
+
* thisWeek, lastWeek, nextWeek, thisMonth, lastMonth, nextMonth, thisQuarter,
|
|
29
|
+
* lastQuarter, thisYear, lastYear; their labels are the messages'
|
|
30
|
+
* `dateRangeFilter.ranges`.
|
|
31
|
+
*/
|
|
32
|
+
import { useState } from 'react';
|
|
33
|
+
import { Button } from '../button/Button.js';
|
|
34
|
+
import { DatePicker } from '../date-picker/DatePicker.js';
|
|
35
|
+
import { Popover } from '../popover/Popover.js';
|
|
36
|
+
import { useLocale, useMessages } from '../format/LocaleProvider.js';
|
|
37
|
+
import { cx, partsOf, useControllable } from '../utils.js';
|
|
38
|
+
import '../theme.css';
|
|
39
|
+
import './date-range-filter.css';
|
|
40
|
+
const day = (y, m, d) => new Date(y, m, d);
|
|
41
|
+
// Days from today, e.g. days(-6, 0) for the last 7.
|
|
42
|
+
function days(from, to) {
|
|
43
|
+
const now = new Date();
|
|
44
|
+
return [day(now.getFullYear(), now.getMonth(), now.getDate() + from), day(now.getFullYear(), now.getMonth(), now.getDate() + to)];
|
|
45
|
+
}
|
|
46
|
+
function week(offset, firstDay) {
|
|
47
|
+
const now = new Date();
|
|
48
|
+
const start = now.getDate() - ((now.getDay() - (firstDay % 7) + 7) % 7) + offset * 7;
|
|
49
|
+
return [day(now.getFullYear(), now.getMonth(), start), day(now.getFullYear(), now.getMonth(), start + 6)];
|
|
50
|
+
}
|
|
51
|
+
// Whole months from a month index in this year; Date rolls over past 0–11.
|
|
52
|
+
function months(start, length) {
|
|
53
|
+
const year = new Date().getFullYear();
|
|
54
|
+
return [day(year, start, 1), day(year, start + length, 0)];
|
|
55
|
+
}
|
|
56
|
+
const month = () => new Date().getMonth();
|
|
57
|
+
const quarter = () => Math.floor(month() / 3) * 3;
|
|
58
|
+
export const dateRanges = {
|
|
59
|
+
today: () => days(0, 0),
|
|
60
|
+
yesterday: () => days(-1, -1),
|
|
61
|
+
tomorrow: () => days(1, 1),
|
|
62
|
+
last7: () => days(-6, 0),
|
|
63
|
+
last30: () => days(-29, 0),
|
|
64
|
+
next7: () => days(0, 6),
|
|
65
|
+
next30: () => days(0, 29),
|
|
66
|
+
thisWeek: (firstDay) => week(0, firstDay),
|
|
67
|
+
lastWeek: (firstDay) => week(-1, firstDay),
|
|
68
|
+
nextWeek: (firstDay) => week(1, firstDay),
|
|
69
|
+
thisMonth: () => months(month(), 1),
|
|
70
|
+
lastMonth: () => months(month() - 1, 1),
|
|
71
|
+
nextMonth: () => months(month() + 1, 1),
|
|
72
|
+
thisQuarter: () => months(quarter(), 3),
|
|
73
|
+
lastQuarter: () => months(quarter() - 3, 3),
|
|
74
|
+
thisYear: () => months(0, 12),
|
|
75
|
+
lastYear: () => months(-12, 12),
|
|
76
|
+
};
|
|
77
|
+
// Local 'YYYY-MM-DD'; toISOString would shift it to UTC.
|
|
78
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
79
|
+
const iso = (date) => typeof date === 'string' ? date : `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
80
|
+
function fromIso(value) {
|
|
81
|
+
const [y, m, d] = value.split('-').map(Number);
|
|
82
|
+
return new Date(y, m - 1, d);
|
|
83
|
+
}
|
|
84
|
+
// 1 Monday to 7 Sunday; Monday where the browser can't say.
|
|
85
|
+
function firstDayOf(locale) {
|
|
86
|
+
try {
|
|
87
|
+
const info = new Intl.Locale(locale);
|
|
88
|
+
return (info.getWeekInfo ? info.getWeekInfo() : info.weekInfo)?.firstDay ?? 1;
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return 1;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function DateRangeFilterShortcut({ value, defaultValue, onValueChange, presets = ['today', 'last7', 'last30', 'thisMonth', 'lastMonth', 'thisQuarter', 'lastQuarter', 'thisYear', 'lastYear'], placeholder = null, placement = 'bottom-end', locale: localeProp = null, className, classes, }) {
|
|
95
|
+
const t = useMessages();
|
|
96
|
+
const app = useLocale();
|
|
97
|
+
const locale = localeProp ?? app ?? 'en-GB';
|
|
98
|
+
const part = partsOf('date-range-filter', classes);
|
|
99
|
+
const [dates, setDates] = useControllable(value, defaultValue ?? [], undefined);
|
|
100
|
+
// The calendar's own range while it's being picked: one end, until the other
|
|
101
|
+
const [picking, setPicking] = useState(dates);
|
|
102
|
+
// Bumped to start the calendar afresh on the range's first month (Zag keeps
|
|
103
|
+
// the month shown when its value changes from outside, as a preset does)
|
|
104
|
+
const [shown, setShown] = useState(0);
|
|
105
|
+
const firstDay = firstDayOf(locale);
|
|
106
|
+
const items = presets.map((preset) => typeof preset === 'string'
|
|
107
|
+
? { label: t.dateRangeFilter.ranges[preset], range: dateRanges[preset] } : preset);
|
|
108
|
+
const datesOf = (item) => item.range(firstDay).map(iso);
|
|
109
|
+
const [from, to] = dates;
|
|
110
|
+
const matches = (item) => !!to && String(datesOf(item)) === String([from, to]);
|
|
111
|
+
const active = items.find(matches);
|
|
112
|
+
const format = new Intl.DateTimeFormat(locale, { day: 'numeric', month: 'short', year: 'numeric' });
|
|
113
|
+
const label = !from ? placeholder ?? t.dateRangeFilter.placeholder
|
|
114
|
+
: active ? active.label
|
|
115
|
+
: !to || from === to ? format.format(fromIso(from))
|
|
116
|
+
: format.formatRange(fromIso(from), fromIso(to));
|
|
117
|
+
function change(next) {
|
|
118
|
+
setPicking(next);
|
|
119
|
+
setShown((n) => n + 1);
|
|
120
|
+
setDates(next);
|
|
121
|
+
onValueChange?.(next);
|
|
122
|
+
}
|
|
123
|
+
function picked(next) {
|
|
124
|
+
setPicking(next);
|
|
125
|
+
if (next.length !== 2)
|
|
126
|
+
return;
|
|
127
|
+
setDates(next);
|
|
128
|
+
onValueChange?.(next);
|
|
129
|
+
}
|
|
130
|
+
return (_jsx(Popover, { placement: placement, "data-date-range-filter": "", onOpenChange: (open) => { if (open) {
|
|
131
|
+
setPicking(dates);
|
|
132
|
+
setShown((n) => n + 1);
|
|
133
|
+
} }, trigger: _jsx(Button, { icon: "lucide:calendar", iconEnd: "lucide:chevron-down", className: cx(className, classes?.trigger), children: label }), children: _jsxs("div", { ...part('panel'), children: [_jsxs("div", { ...part('presets'), children: [items.map((item, i) => (_jsx(Button, { block: true, size: "sm", variant: "ghost", className: classes?.preset, "aria-pressed": matches(item), onClick: () => change(datesOf(item)), children: item.label }, i))), _jsx(Button, { block: true, size: "sm", icon: "lucide:x", className: classes?.clear, "data-clear": "", disabled: !dates.length, onClick: () => change([]), children: t.dateRangeFilter.clear })] }), _jsx(DatePicker, { inline: true, range: true, locale: locale, value: picking, onValueChange: picked, className: classes?.calendar }, shown)] }) }));
|
|
134
|
+
}
|
|
135
|
+
export const DateRangeFilter = DateRangeFilterShortcut;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
@layer ui {
|
|
2
|
+
/* The popover is the card; the panel inside it sets the size. */
|
|
3
|
+
[data-scope=popover][data-part=content][data-date-range-filter] { width: auto; padding: 0; }
|
|
4
|
+
[data-scope=date-range-filter][data-part=panel] { display: flex; }
|
|
5
|
+
/* As tall as the calendar, with Clear at the bottom. */
|
|
6
|
+
[data-scope=date-range-filter][data-part=presets] { display: flex; flex-direction: column; gap: 0.125rem; width: 11rem;
|
|
7
|
+
padding: 0.5rem; border-right: 1px solid var(--ui-border); box-sizing: border-box;
|
|
8
|
+
/* Its buttons are Buttons (scope button), so they're found by place. Choices in a list: they don't dip when pressed. */
|
|
9
|
+
> [data-scope=button] { justify-content: flex-start; font-weight: 400; font-size: 13px;
|
|
10
|
+
&:active { filter: none; } }
|
|
11
|
+
> [data-scope=button][data-variant=ghost] { color: var(--ui-text);
|
|
12
|
+
/* The picked one: a quiet tint rather than the soft button's fill. Set
|
|
13
|
+
--ui-date-range-filter-active-bg and -text for another (e.g. var(--ui-hover)). */
|
|
14
|
+
&[aria-pressed=true] { font-weight: 500; color: var(--ui-date-range-filter-active-text, var(--ui-text));
|
|
15
|
+
background: var(--ui-date-range-filter-active-bg, color-mix(in srgb, var(--ui-accent) 10%, transparent)); } }
|
|
16
|
+
> [data-clear] { margin-top: auto; color: var(--ui-muted); } }
|
|
17
|
+
[data-scope=date-range-filter][data-part=panel] > [data-scope=date-picker] { padding: 0.75rem; }
|
|
18
|
+
|
|
19
|
+
/* On a phone: the presets in two columns above the calendar. */
|
|
20
|
+
@media (max-width: 639px) {
|
|
21
|
+
[data-scope=date-range-filter][data-part=panel] { flex-direction: column; }
|
|
22
|
+
[data-scope=date-range-filter][data-part=presets] { display: grid; grid-template-columns: 1fr 1fr; width: auto;
|
|
23
|
+
border-right: none; border-bottom: 1px solid var(--ui-border);
|
|
24
|
+
> [data-clear] { grid-column: span 2; margin-top: 0.25rem; } }
|
|
25
|
+
[data-scope=date-range-filter][data-part=panel] > [data-scope=date-picker] { align-self: center; }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -26,6 +26,7 @@ import type { Clipboard } from '@ark-ui/react/clipboard';
|
|
|
26
26
|
import type { TreeView } from '@ark-ui/react/tree-view';
|
|
27
27
|
import type { Editable } from '@ark-ui/react/editable';
|
|
28
28
|
import type { PinInput } from '@ark-ui/react/pin-input';
|
|
29
|
+
import type { DateRangeKey } from '../date-range-filter/DateRangeFilter.js';
|
|
29
30
|
export type CalendarMessages = {
|
|
30
31
|
today: string;
|
|
31
32
|
previous: string;
|
|
@@ -112,6 +113,11 @@ export type Messages = {
|
|
|
112
113
|
max: (date: string) => string;
|
|
113
114
|
unavailable: string;
|
|
114
115
|
};
|
|
116
|
+
dateRangeFilter: {
|
|
117
|
+
placeholder: string;
|
|
118
|
+
clear: string;
|
|
119
|
+
ranges: Record<DateRangeKey, string>;
|
|
120
|
+
};
|
|
115
121
|
swatchPicker: {
|
|
116
122
|
placeholder: string;
|
|
117
123
|
colors: Record<string, string>;
|
package/dist/format/messages.js
CHANGED
|
@@ -26,6 +26,16 @@ export const en = {
|
|
|
26
26
|
format: (pattern) => `Enter a date as ${pattern}`, min: (date) => `Pick a date from ${date}`, max: (date) => `Pick a date up to ${date}`,
|
|
27
27
|
unavailable: 'That date isn’t available',
|
|
28
28
|
},
|
|
29
|
+
dateRangeFilter: {
|
|
30
|
+
placeholder: 'All dates', clear: 'Clear',
|
|
31
|
+
ranges: {
|
|
32
|
+
today: 'Today', yesterday: 'Yesterday', tomorrow: 'Tomorrow',
|
|
33
|
+
last7: 'Last 7 days', last30: 'Last 30 days', next7: 'Next 7 days', next30: 'Next 30 days',
|
|
34
|
+
thisWeek: 'This week', lastWeek: 'Last week', nextWeek: 'Next week',
|
|
35
|
+
thisMonth: 'This month', lastMonth: 'Last month', nextMonth: 'Next month',
|
|
36
|
+
thisQuarter: 'This quarter', lastQuarter: 'Last quarter', thisYear: 'This year', lastYear: 'Last year',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
29
39
|
swatchPicker: { placeholder: 'Choose a colour', colors: Object.fromEntries(swatchNames.map((name) => [name, capital(name)])) },
|
|
30
40
|
command: {
|
|
31
41
|
label: 'Command menu', placeholder: 'Type a command or search…', empty: 'No results', loading: 'Searching…',
|
|
@@ -108,6 +118,16 @@ export const fr = {
|
|
|
108
118
|
min: (date) => `Choisissez une date à partir du ${date}`, max: (date) => `Choisissez une date jusqu’au ${date}`,
|
|
109
119
|
unavailable: 'Cette date n’est pas disponible',
|
|
110
120
|
},
|
|
121
|
+
dateRangeFilter: {
|
|
122
|
+
placeholder: 'Toutes les dates', clear: 'Effacer',
|
|
123
|
+
ranges: {
|
|
124
|
+
today: 'Aujourd’hui', yesterday: 'Hier', tomorrow: 'Demain',
|
|
125
|
+
last7: '7 derniers jours', last30: '30 derniers jours', next7: '7 prochains jours', next30: '30 prochains jours',
|
|
126
|
+
thisWeek: 'Cette semaine', lastWeek: 'Semaine dernière', nextWeek: 'Semaine prochaine',
|
|
127
|
+
thisMonth: 'Ce mois-ci', lastMonth: 'Mois dernier', nextMonth: 'Mois prochain',
|
|
128
|
+
thisQuarter: 'Ce trimestre', lastQuarter: 'Trimestre dernier', thisYear: 'Cette année', lastYear: 'Année dernière',
|
|
129
|
+
},
|
|
130
|
+
},
|
|
111
131
|
swatchPicker: {
|
|
112
132
|
placeholder: 'Choisir une couleur',
|
|
113
133
|
colors: {
|
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export { Field, Fields } from './field/Field.js';
|
|
|
21
21
|
export { useFieldReport } from './field/report.js';
|
|
22
22
|
export { Select, Combobox, createListCollection } from './select/Select.js';
|
|
23
23
|
export { DatePicker, parseDate } from './date-picker/DatePicker.js';
|
|
24
|
+
export { DateRangeFilter, dateRanges, type DateRangeFilterProps, type DateRangeKey, type DateRangePreset } from './date-range-filter/DateRangeFilter.js';
|
|
24
25
|
export { Checkbox } from './checkbox/Checkbox.js';
|
|
25
26
|
export { CheckboxGroup } from './checkbox/CheckboxGroup.js';
|
|
26
27
|
export { Switch } from './switch/Switch.js';
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ export { Field, Fields } from './field/Field.js';
|
|
|
22
22
|
export { useFieldReport } from './field/report.js';
|
|
23
23
|
export { Select, Combobox, createListCollection } from './select/Select.js';
|
|
24
24
|
export { DatePicker, parseDate } from './date-picker/DatePicker.js';
|
|
25
|
+
export { DateRangeFilter, dateRanges } from './date-range-filter/DateRangeFilter.js';
|
|
25
26
|
export { Checkbox } from './checkbox/Checkbox.js';
|
|
26
27
|
export { CheckboxGroup } from './checkbox/CheckboxGroup.js';
|
|
27
28
|
export { Switch } from './switch/Switch.js';
|