@plexui/ui 0.29.0 → 0.30.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/dist/es/components/Alert/Alert.js +2 -2
- package/dist/es/components/Alert/Alert.js.map +1 -1
- package/dist/es/components/Avatar/Avatar.js +3 -1
- package/dist/es/components/Avatar/Avatar.js.map +1 -1
- package/dist/es/components/Checkbox/Checkbox.js +1 -3
- package/dist/es/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/es/components/ColorPicker/ColorPicker.js +227 -0
- package/dist/es/components/ColorPicker/ColorPicker.js.map +1 -0
- package/dist/es/components/ColorPicker/ColorWell.js +58 -0
- package/dist/es/components/ColorPicker/ColorWell.js.map +1 -0
- package/dist/es/components/ColorPicker/index.js +3 -0
- package/dist/es/components/ColorPicker/index.js.map +1 -0
- package/dist/es/components/ColorPicker/shared.js +132 -0
- package/dist/es/components/ColorPicker/shared.js.map +1 -0
- package/dist/es/components/ContextMenu/ContextMenu.js +164 -0
- package/dist/es/components/ContextMenu/ContextMenu.js.map +1 -0
- package/dist/es/components/ContextMenu/index.js +2 -0
- package/dist/es/components/ContextMenu/index.js.map +1 -0
- package/dist/es/components/ContextMenu/shared.js +56 -0
- package/dist/es/components/ContextMenu/shared.js.map +1 -0
- package/dist/es/components/DatePicker/DatePicker.js +4 -2
- package/dist/es/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/es/components/DateRangePicker/DateRangePicker.js.map +1 -1
- package/dist/es/components/Dialog/Dialog.js +97 -16
- package/dist/es/components/Dialog/Dialog.js.map +1 -1
- package/dist/es/components/Field/Field.js +3 -3
- package/dist/es/components/Field/Field.js.map +1 -1
- package/dist/es/components/FieldGroup/FieldGroup.js +4 -2
- package/dist/es/components/FieldGroup/FieldGroup.js.map +1 -1
- package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js +2 -2
- package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js.map +1 -1
- package/dist/es/components/Icon/index.js +1 -0
- package/dist/es/components/Icon/index.js.map +1 -1
- package/dist/es/components/Icon/svg/Eyedropper.js +6 -0
- package/dist/es/components/Icon/svg/Eyedropper.js.map +1 -0
- package/dist/es/components/Indicator/LoadingIndicator.js.map +1 -1
- package/dist/es/components/Input/Input.js +2 -2
- package/dist/es/components/Input/Input.js.map +1 -1
- package/dist/es/components/Menu/Menu.js +106 -27
- package/dist/es/components/Menu/Menu.js.map +1 -1
- package/dist/es/components/Page/Page.js +42 -15
- package/dist/es/components/Page/Page.js.map +1 -1
- package/dist/es/components/PageControl/PageControl.js +146 -0
- package/dist/es/components/PageControl/PageControl.js.map +1 -0
- package/dist/es/components/PageControl/index.js +2 -0
- package/dist/es/components/PageControl/index.js.map +1 -0
- package/dist/es/components/Popover/Popover.js +2 -1
- package/dist/es/components/Popover/Popover.js.map +1 -1
- package/dist/es/components/Select/Select.js +11 -6
- package/dist/es/components/Select/Select.js.map +1 -1
- package/dist/es/components/SelectControl/SelectControl.js +1 -1
- package/dist/es/components/SelectControl/SelectControl.js.map +1 -1
- package/dist/es/components/Sidebar/Sidebar.js +21 -8
- package/dist/es/components/Sidebar/Sidebar.js.map +1 -1
- package/dist/es/components/Slider/Slider.js +10 -5
- package/dist/es/components/Slider/Slider.js.map +1 -1
- package/dist/es/components/Stepper/Stepper.js +114 -0
- package/dist/es/components/Stepper/Stepper.js.map +1 -0
- package/dist/es/components/Stepper/index.js +2 -0
- package/dist/es/components/Stepper/index.js.map +1 -0
- package/dist/es/components/TabBar/TabBar.js +128 -0
- package/dist/es/components/TabBar/TabBar.js.map +1 -0
- package/dist/es/components/TabBar/index.js +2 -0
- package/dist/es/components/TabBar/index.js.map +1 -0
- package/dist/es/components/Tabs/Tabs.js +13 -6
- package/dist/es/components/Tabs/Tabs.js.map +1 -1
- package/dist/es/components/Textarea/Textarea.js +1 -1
- package/dist/es/components/Textarea/Textarea.js.map +1 -1
- package/dist/es/components/Toolbar/Toolbar.js +31 -5
- package/dist/es/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/es/components/Toolbar/index.js.map +1 -1
- package/dist/es/lib/fieldRow.js +7 -1
- package/dist/es/lib/fieldRow.js.map +1 -1
- package/dist/es/lib/menuSubmenuPlacement.js +51 -6
- package/dist/es/lib/menuSubmenuPlacement.js.map +1 -1
- package/dist/es/lib/menuTriggerCover.js +70 -0
- package/dist/es/lib/menuTriggerCover.js.map +1 -0
- package/dist/es/lib/scrollEdges.js +34 -0
- package/dist/es/lib/scrollEdges.js.map +1 -0
- package/dist/types/components/ColorPicker/ColorPicker.d.ts +34 -0
- package/dist/types/components/ColorPicker/ColorWell.d.ts +32 -0
- package/dist/types/components/ColorPicker/index.d.ts +3 -0
- package/dist/types/components/ColorPicker/shared.d.ts +69 -0
- package/dist/types/components/ContextMenu/ContextMenu.d.ts +78 -0
- package/dist/types/components/ContextMenu/index.d.ts +1 -0
- package/dist/types/components/ContextMenu/shared.d.ts +50 -0
- package/dist/types/components/DatePicker/DatePicker.d.ts +6 -1
- package/dist/types/components/DateRangePicker/DateRangePicker.d.ts +1 -0
- package/dist/types/components/Dialog/Dialog.d.ts +5 -1
- package/dist/types/components/Field/Field.d.ts +11 -2
- package/dist/types/components/FieldGroup/FieldGroup.d.ts +11 -2
- package/dist/types/components/Icon/index.d.ts +1 -0
- package/dist/types/components/Icon/svg/Eyedropper.d.ts +6 -0
- package/dist/types/components/Indicator/LoadingIndicator.d.ts +1 -1
- package/dist/types/components/Menu/Menu.d.ts +73 -8
- package/dist/types/components/Page/Page.d.ts +8 -4
- package/dist/types/components/PageControl/PageControl.d.ts +52 -0
- package/dist/types/components/PageControl/index.d.ts +1 -0
- package/dist/types/components/Select/Select.d.ts +3 -3
- package/dist/types/components/Stepper/Stepper.d.ts +56 -0
- package/dist/types/components/Stepper/index.d.ts +1 -0
- package/dist/types/components/TabBar/TabBar.d.ts +74 -0
- package/dist/types/components/TabBar/index.d.ts +1 -0
- package/dist/types/components/Toolbar/Toolbar.d.ts +17 -5
- package/dist/types/components/Toolbar/index.d.ts +1 -1
- package/dist/types/lib/fieldRow.d.ts +6 -0
- package/dist/types/lib/menuSubmenuPlacement.d.ts +14 -1
- package/dist/types/lib/menuTriggerCover.d.ts +23 -0
- package/dist/types/lib/scrollEdges.d.ts +16 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/ColorPicker/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAyB,MAAM,eAAe,CAAA;AAClE,OAAO,EAAE,SAAS,EAAuB,MAAM,aAAa,CAAA","sourcesContent":["export { ColorPicker, type ColorPickerProps } from \"./ColorPicker\"\nexport { ColorWell, type ColorWellProps } from \"./ColorWell\"\nexport type { ColorPickerMode } from \"./shared\"\n"]}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
export const COLOR_PICKER_MODES = [
|
|
2
|
+
{ value: "grid", label: "Grid" },
|
|
3
|
+
{ value: "spectrum", label: "Spectrum" },
|
|
4
|
+
{ value: "sliders", label: "Sliders" },
|
|
5
|
+
];
|
|
6
|
+
/** The kit's Color Grid (515:48178): a row of grays, then nine rows from dark to light, twelve hues across. */
|
|
7
|
+
export const COLOR_PICKER_GRID = [
|
|
8
|
+
["#fefffe", "#ebebeb", "#d6d6d6", "#c2c2c2", "#adadad", "#999999", "#858585", "#707070", "#5c5c5c", "#474747", "#333333", "#000000"],
|
|
9
|
+
["#00374a", "#011d57", "#11053b", "#2e063d", "#3c071b", "#5c0701", "#5a1c00", "#583300", "#563d00", "#666100", "#4f5504", "#263e0f"],
|
|
10
|
+
["#004d65", "#012f7b", "#1a0a52", "#450d59", "#551029", "#831100", "#7b2900", "#7a4a00", "#785800", "#8d8602", "#6f760a", "#38571a"],
|
|
11
|
+
["#016e8f", "#0042a9", "#2c0977", "#61187c", "#791a3d", "#b51a00", "#ad3e00", "#a96800", "#a67b01", "#c4bc00", "#9ba50e", "#4e7a27"],
|
|
12
|
+
["#008cb4", "#0056d6", "#371a94", "#7a219e", "#99244f", "#e22400", "#da5100", "#d38301", "#d19d01", "#f5ec00", "#c3d117", "#669d34"],
|
|
13
|
+
["#00a1d8", "#0061fd", "#4d22b2", "#982abc", "#b92d5d", "#ff4015", "#ff6a00", "#ffab01", "#fcc700", "#fefb41", "#d9ec37", "#76bb40"],
|
|
14
|
+
["#01c7fc", "#3a87fd", "#5e30eb", "#be38f3", "#e63b7a", "#fe6250", "#fe8648", "#feb43f", "#fecb3e", "#fff76b", "#e4ef65", "#96d35f"],
|
|
15
|
+
["#52d6fc", "#74a7ff", "#864ffd", "#d357fe", "#ee719e", "#ff8c82", "#fea57d", "#fec777", "#fed977", "#fff994", "#eaf28f", "#b1dd8b"],
|
|
16
|
+
["#93e3fc", "#a7c6ff", "#b18cfe", "#e292fe", "#f4a4c0", "#ffb5af", "#ffc5ab", "#fed9a8", "#fde4a8", "#fffbb9", "#f1f7b7", "#cde8b5"],
|
|
17
|
+
["#cbf0ff", "#d2e2fe", "#d8c9fe", "#efcafe", "#f9d3e0", "#ffdad8", "#ffe2d6", "#feecd4", "#fef1d5", "#fdfbdd", "#f6fadb", "#deeed4"],
|
|
18
|
+
];
|
|
19
|
+
export const COLOR_PICKER_GRID_COLUMNS = 12;
|
|
20
|
+
const GRID = COLOR_PICKER_GRID.flat();
|
|
21
|
+
/** Saved colors fill pages of two rows of five, with the Add button after the last one (kit Swatches 515:52724). */
|
|
22
|
+
export const COLOR_PICKER_SWATCHES_PER_PAGE = 10;
|
|
23
|
+
export const COLOR_PICKER_SWATCHES_PER_ROW = 5;
|
|
24
|
+
const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
25
|
+
const byte = (value) => clamp(Math.round(value), 0, 255);
|
|
26
|
+
/** Reads `#rgb`, `#rgba`, `#rrggbb` or `#rrggbbaa`, in either case; anything else is `null`. */
|
|
27
|
+
export function parseColor(input) {
|
|
28
|
+
const match = /^#?([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec((input ?? "").trim());
|
|
29
|
+
if (!match)
|
|
30
|
+
return null;
|
|
31
|
+
let hex = match[1];
|
|
32
|
+
if (hex.length <= 4)
|
|
33
|
+
hex = [...hex].map((digit) => digit + digit).join("");
|
|
34
|
+
const channel = (index) => Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);
|
|
35
|
+
return { r: channel(0), g: channel(1), b: channel(2), a: hex.length === 8 ? channel(3) / 255 : 1 };
|
|
36
|
+
}
|
|
37
|
+
const two = (value) => byte(value).toString(16).padStart(2, "0");
|
|
38
|
+
/** `#rrggbb`, or `#rrggbbaa` when the color is not opaque. */
|
|
39
|
+
export function formatColor({ r, g, b, a }) {
|
|
40
|
+
const opaque = Math.round(clamp(a, 0, 1) * 255) === 255;
|
|
41
|
+
return `#${two(r)}${two(g)}${two(b)}${opaque ? "" : two(clamp(a, 0, 1) * 255)}`;
|
|
42
|
+
}
|
|
43
|
+
/** The six digits the Hex field shows, as the system picker does: upper case, no `#`. */
|
|
44
|
+
export const hexDigits = ({ r, g, b }) => `${two(r)}${two(g)}${two(b)}`.toUpperCase();
|
|
45
|
+
/** A CSS color for a fill. */
|
|
46
|
+
export const cssColor = ({ r, g, b, a }, alpha = a) => `rgb(${byte(r)} ${byte(g)} ${byte(b)} / ${Math.round(clamp(alpha, 0, 1) * 1000) / 10}%)`;
|
|
47
|
+
export const sameRgb = (one, other) => byte(one.r) === byte(other.r) && byte(one.g) === byte(other.g) && byte(one.b) === byte(other.b);
|
|
48
|
+
/** Whole percent of opacity, as the Opacity field shows it. */
|
|
49
|
+
export const alphaPercent = (a) => Math.round(clamp(a, 0, 1) * 100);
|
|
50
|
+
/** The grid cell of a color, or -1 when the grid has no such color. */
|
|
51
|
+
export const gridIndex = (color) => GRID.findIndex((hex) => {
|
|
52
|
+
const cell = parseColor(hex);
|
|
53
|
+
return cell !== null && sameRgb(cell, color);
|
|
54
|
+
});
|
|
55
|
+
export const gridColor = (index) => GRID[index];
|
|
56
|
+
/** The cell an arrow key, Home or End moves to from `index`, or `index` itself at an edge. */
|
|
57
|
+
export function gridMove(index, key) {
|
|
58
|
+
const columns = COLOR_PICKER_GRID_COLUMNS;
|
|
59
|
+
const column = index % columns;
|
|
60
|
+
const next = {
|
|
61
|
+
ArrowRight: column < columns - 1 ? index + 1 : index,
|
|
62
|
+
ArrowLeft: column > 0 ? index - 1 : index,
|
|
63
|
+
ArrowDown: index + columns < GRID.length ? index + columns : index,
|
|
64
|
+
ArrowUp: index - columns >= 0 ? index - columns : index,
|
|
65
|
+
Home: index - column,
|
|
66
|
+
End: index - column + columns - 1,
|
|
67
|
+
};
|
|
68
|
+
return next[key] ?? index;
|
|
69
|
+
}
|
|
70
|
+
/** The item a key moves to in a list of `count` items (saved colors), or `index` itself. */
|
|
71
|
+
export function listMove(index, count, key) {
|
|
72
|
+
const next = {
|
|
73
|
+
ArrowRight: Math.min(count - 1, index + 1),
|
|
74
|
+
ArrowDown: Math.min(count - 1, index + 1),
|
|
75
|
+
ArrowLeft: Math.max(0, index - 1),
|
|
76
|
+
ArrowUp: Math.max(0, index - 1),
|
|
77
|
+
Home: 0,
|
|
78
|
+
End: count - 1,
|
|
79
|
+
};
|
|
80
|
+
return next[key] ?? index;
|
|
81
|
+
}
|
|
82
|
+
/** Pages of saved colors: the colors and the Add button after them, ten to a page. */
|
|
83
|
+
export const swatchPageCount = (count) => Math.max(1, Math.ceil((count + 1) / COLOR_PICKER_SWATCHES_PER_PAGE));
|
|
84
|
+
function rgbToHsl({ r, g, b }) {
|
|
85
|
+
const [red, green, blue] = [r / 255, g / 255, b / 255];
|
|
86
|
+
const max = Math.max(red, green, blue);
|
|
87
|
+
const min = Math.min(red, green, blue);
|
|
88
|
+
const lightness = (max + min) / 2;
|
|
89
|
+
const delta = max - min;
|
|
90
|
+
if (delta === 0)
|
|
91
|
+
return { h: null, s: 0, l: lightness };
|
|
92
|
+
const saturation = delta / (1 - Math.abs(2 * lightness - 1));
|
|
93
|
+
const sector = max === red ? ((green - blue) / delta + 6) % 6 : max === green ? (blue - red) / delta + 2 : (red - green) / delta + 4;
|
|
94
|
+
return { h: sector * 60, s: saturation, l: lightness };
|
|
95
|
+
}
|
|
96
|
+
function hslToRgb(hue, saturation, lightness) {
|
|
97
|
+
const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation;
|
|
98
|
+
const sector = (((hue % 360) + 360) % 360) / 60;
|
|
99
|
+
const second = chroma * (1 - Math.abs((sector % 2) - 1));
|
|
100
|
+
const [red, green, blue] = sector < 1 ? [chroma, second, 0] : sector < 2 ? [second, chroma, 0] : sector < 3 ? [0, chroma, second]
|
|
101
|
+
: sector < 4 ? [0, second, chroma] : sector < 5 ? [second, 0, chroma] : [chroma, 0, second];
|
|
102
|
+
const match = lightness - chroma / 2;
|
|
103
|
+
return { r: byte((red + match) * 255), g: byte((green + match) * 255), b: byte((blue + match) * 255) };
|
|
104
|
+
}
|
|
105
|
+
export function spectrumColor({ x, y }, alpha) {
|
|
106
|
+
return { ...hslToRgb(clamp(y, 0, 1) * 360, 1, 1 - clamp(x, 0, 1)), a: alpha };
|
|
107
|
+
}
|
|
108
|
+
/** Where a color sits on the spectrum; a gray keeps the hue of `previous`, as it has none. */
|
|
109
|
+
export function spectrumPoint(color, previous) {
|
|
110
|
+
const { h, l } = rgbToHsl(color);
|
|
111
|
+
return { x: 1 - l, y: h === null ? previous?.y ?? 0 : h / 360 };
|
|
112
|
+
}
|
|
113
|
+
/** The track of the Opacity slider: the color from clear to opaque over the kit's 12% to 88% (515:47434). */
|
|
114
|
+
export const opacityTrack = (color) => `linear-gradient(to right, ${cssColor(color, 0)} 12%, ${cssColor(color, 1)} 88%)`;
|
|
115
|
+
export const COLOR_PICKER_CHANNELS = [
|
|
116
|
+
{ channel: "r", label: "Red" },
|
|
117
|
+
{ channel: "g", label: "Green" },
|
|
118
|
+
{ channel: "b", label: "Blue" },
|
|
119
|
+
];
|
|
120
|
+
/** The track of a channel slider: the color with that channel from 0 to 255. */
|
|
121
|
+
export const channelTrack = (color, channel) => `linear-gradient(to right, ${cssColor({ ...color, [channel]: 0 }, 1)}, ${cssColor({ ...color, [channel]: 255 }, 1)})`;
|
|
122
|
+
/** A number typed in a field, kept within `min` and `max`; text with no number is `null`. */
|
|
123
|
+
export function parseNumber(text, min, max) {
|
|
124
|
+
const number = Number.parseFloat(text.replace(/[%\s]/g, ""));
|
|
125
|
+
return Number.isFinite(number) ? clamp(Math.round(number), min, max) : null;
|
|
126
|
+
}
|
|
127
|
+
export function eyeDropper() {
|
|
128
|
+
if (typeof window === "undefined")
|
|
129
|
+
return null;
|
|
130
|
+
return window.EyeDropper ?? null;
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../../src/components/ColorPicker/shared.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,MAAM,kBAAkB,GAAyD;IACtF,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE;IAChC,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE;IACxC,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE;CACvC,CAAA;AAED,+GAA+G;AAC/G,MAAM,CAAC,MAAM,iBAAiB,GAAmC;IAC/D,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC;IACpI,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC;IACpI,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,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G,EAAE,KAAK,EAAE,KAAK,EAAE;IAC9B,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE;IAChC,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE;CAChC,CAAA;AAED,gFAAgF;AAChF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAW,EAAE,OAAqB,EAAE,EAAE,CACjE,6BAA6B,QAAQ,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAA;AAEvH,6FAA6F;AAC7F,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,GAAW,EAAE,GAAW;IAChE,MAAM,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAA;IAC5D,OAAO,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AAC7E,CAAC;AAKD,MAAM,UAAU,UAAU;IACxB,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,IAAI,CAAA;IAC9C,OAAQ,MAA0D,CAAC,UAAU,IAAI,IAAI,CAAA;AACvF,CAAC","sourcesContent":["/** A color as the picker holds it: channels 0 to 255 and an alpha from 0 to 1. */\nexport type Rgba = { r: number; g: number; b: number; a: number }\n\n/** The three ways to choose a color, as the segments of the system picker. */\nexport type ColorPickerMode = \"grid\" | \"spectrum\" | \"sliders\"\n\nexport const COLOR_PICKER_MODES: readonly { value: ColorPickerMode; label: string }[] = [\n { value: \"grid\", label: \"Grid\" },\n { value: \"spectrum\", label: \"Spectrum\" },\n { value: \"sliders\", label: \"Sliders\" },\n]\n\n/** The kit's Color Grid (515:48178): a row of grays, then nine rows from dark to light, twelve hues across. */\nexport const COLOR_PICKER_GRID: readonly (readonly string[])[] = [\n [\"#fefffe\", \"#ebebeb\", \"#d6d6d6\", \"#c2c2c2\", \"#adadad\", \"#999999\", \"#858585\", \"#707070\", \"#5c5c5c\", \"#474747\", \"#333333\", \"#000000\"],\n [\"#00374a\", \"#011d57\", \"#11053b\", \"#2e063d\", \"#3c071b\", \"#5c0701\", \"#5a1c00\", \"#583300\", \"#563d00\", \"#666100\", \"#4f5504\", \"#263e0f\"],\n [\"#004d65\", \"#012f7b\", \"#1a0a52\", \"#450d59\", \"#551029\", \"#831100\", \"#7b2900\", \"#7a4a00\", \"#785800\", \"#8d8602\", \"#6f760a\", \"#38571a\"],\n [\"#016e8f\", \"#0042a9\", \"#2c0977\", \"#61187c\", \"#791a3d\", \"#b51a00\", \"#ad3e00\", \"#a96800\", \"#a67b01\", \"#c4bc00\", \"#9ba50e\", \"#4e7a27\"],\n [\"#008cb4\", \"#0056d6\", \"#371a94\", \"#7a219e\", \"#99244f\", \"#e22400\", \"#da5100\", \"#d38301\", \"#d19d01\", \"#f5ec00\", \"#c3d117\", \"#669d34\"],\n [\"#00a1d8\", \"#0061fd\", \"#4d22b2\", \"#982abc\", \"#b92d5d\", \"#ff4015\", \"#ff6a00\", \"#ffab01\", \"#fcc700\", \"#fefb41\", \"#d9ec37\", \"#76bb40\"],\n [\"#01c7fc\", \"#3a87fd\", \"#5e30eb\", \"#be38f3\", \"#e63b7a\", \"#fe6250\", \"#fe8648\", \"#feb43f\", \"#fecb3e\", \"#fff76b\", \"#e4ef65\", \"#96d35f\"],\n [\"#52d6fc\", \"#74a7ff\", \"#864ffd\", \"#d357fe\", \"#ee719e\", \"#ff8c82\", \"#fea57d\", \"#fec777\", \"#fed977\", \"#fff994\", \"#eaf28f\", \"#b1dd8b\"],\n [\"#93e3fc\", \"#a7c6ff\", \"#b18cfe\", \"#e292fe\", \"#f4a4c0\", \"#ffb5af\", \"#ffc5ab\", \"#fed9a8\", \"#fde4a8\", \"#fffbb9\", \"#f1f7b7\", \"#cde8b5\"],\n [\"#cbf0ff\", \"#d2e2fe\", \"#d8c9fe\", \"#efcafe\", \"#f9d3e0\", \"#ffdad8\", \"#ffe2d6\", \"#feecd4\", \"#fef1d5\", \"#fdfbdd\", \"#f6fadb\", \"#deeed4\"],\n]\n\nexport const COLOR_PICKER_GRID_COLUMNS = 12\nconst GRID = COLOR_PICKER_GRID.flat()\n\n/** Saved colors fill pages of two rows of five, with the Add button after the last one (kit Swatches 515:52724). */\nexport const COLOR_PICKER_SWATCHES_PER_PAGE = 10\nexport const COLOR_PICKER_SWATCHES_PER_ROW = 5\n\nconst clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value))\nconst byte = (value: number) => clamp(Math.round(value), 0, 255)\n\n/** Reads `#rgb`, `#rgba`, `#rrggbb` or `#rrggbbaa`, in either case; anything else is `null`. */\nexport function parseColor(input: string | null | undefined): Rgba | null {\n const match = /^#?([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec((input ?? \"\").trim())\n if (!match) return null\n let hex = match[1]\n if (hex.length <= 4) hex = [...hex].map((digit) => digit + digit).join(\"\")\n const channel = (index: number) => Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16)\n return { r: channel(0), g: channel(1), b: channel(2), a: hex.length === 8 ? channel(3) / 255 : 1 }\n}\n\nconst two = (value: number) => byte(value).toString(16).padStart(2, \"0\")\n\n/** `#rrggbb`, or `#rrggbbaa` when the color is not opaque. */\nexport function formatColor({ r, g, b, a }: Rgba): string {\n const opaque = Math.round(clamp(a, 0, 1) * 255) === 255\n return `#${two(r)}${two(g)}${two(b)}${opaque ? \"\" : two(clamp(a, 0, 1) * 255)}`\n}\n\n/** The six digits the Hex field shows, as the system picker does: upper case, no `#`. */\nexport const hexDigits = ({ r, g, b }: Rgba) => `${two(r)}${two(g)}${two(b)}`.toUpperCase()\n\n/** A CSS color for a fill. */\nexport const cssColor = ({ r, g, b, a }: Rgba, alpha = a) => `rgb(${byte(r)} ${byte(g)} ${byte(b)} / ${Math.round(clamp(alpha, 0, 1) * 1000) / 10}%)`\n\nexport const sameRgb = (one: Rgba, other: Rgba) => byte(one.r) === byte(other.r) && byte(one.g) === byte(other.g) && byte(one.b) === byte(other.b)\n\n/** Whole percent of opacity, as the Opacity field shows it. */\nexport const alphaPercent = (a: number) => Math.round(clamp(a, 0, 1) * 100)\n\n/** The grid cell of a color, or -1 when the grid has no such color. */\nexport const gridIndex = (color: Rgba) => GRID.findIndex((hex) => {\n const cell = parseColor(hex)\n return cell !== null && sameRgb(cell, color)\n})\n\nexport const gridColor = (index: number) => GRID[index]\n\n/** The cell an arrow key, Home or End moves to from `index`, or `index` itself at an edge. */\nexport function gridMove(index: number, key: string): number {\n const columns = COLOR_PICKER_GRID_COLUMNS\n const column = index % columns\n const next: Record<string, number> = {\n ArrowRight: column < columns - 1 ? index + 1 : index,\n ArrowLeft: column > 0 ? index - 1 : index,\n ArrowDown: index + columns < GRID.length ? index + columns : index,\n ArrowUp: index - columns >= 0 ? index - columns : index,\n Home: index - column,\n End: index - column + columns - 1,\n }\n return next[key] ?? index\n}\n\n/** The item a key moves to in a list of `count` items (saved colors), or `index` itself. */\nexport function listMove(index: number, count: number, key: string): number {\n const next: Record<string, number> = {\n ArrowRight: Math.min(count - 1, index + 1),\n ArrowDown: Math.min(count - 1, index + 1),\n ArrowLeft: Math.max(0, index - 1),\n ArrowUp: Math.max(0, index - 1),\n Home: 0,\n End: count - 1,\n }\n return next[key] ?? index\n}\n\n/** Pages of saved colors: the colors and the Add button after them, ten to a page. */\nexport const swatchPageCount = (count: number) => Math.max(1, Math.ceil((count + 1) / COLOR_PICKER_SWATCHES_PER_PAGE))\n\nfunction rgbToHsl({ r, g, b }: Rgba) {\n const [red, green, blue] = [r / 255, g / 255, b / 255]\n const max = Math.max(red, green, blue)\n const min = Math.min(red, green, blue)\n const lightness = (max + min) / 2\n const delta = max - min\n if (delta === 0) return { h: null, s: 0, l: lightness }\n const saturation = delta / (1 - Math.abs(2 * lightness - 1))\n const sector = max === red ? ((green - blue) / delta + 6) % 6 : max === green ? (blue - red) / delta + 2 : (red - green) / delta + 4\n return { h: sector * 60, s: saturation, l: lightness }\n}\n\nfunction hslToRgb(hue: number, saturation: number, lightness: number) {\n const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation\n const sector = (((hue % 360) + 360) % 360) / 60\n const second = chroma * (1 - Math.abs((sector % 2) - 1))\n const [red, green, blue] =\n sector < 1 ? [chroma, second, 0] : sector < 2 ? [second, chroma, 0] : sector < 3 ? [0, chroma, second]\n : sector < 4 ? [0, second, chroma] : sector < 5 ? [second, 0, chroma] : [chroma, 0, second]\n const match = lightness - chroma / 2\n return { r: byte((red + match) * 255), g: byte((green + match) * 255), b: byte((blue + match) * 255) }\n}\n\n/**\n * A point of the spectrum: hue from top to bottom, and from white at the leading edge through the full hue at the\n * middle to black at the trailing edge, as the system picker draws it (UIColorPickerViewController overview image).\n */\nexport type SpectrumPoint = { x: number; y: number }\n\nexport function spectrumColor({ x, y }: SpectrumPoint, alpha: number): Rgba {\n return { ...hslToRgb(clamp(y, 0, 1) * 360, 1, 1 - clamp(x, 0, 1)), a: alpha }\n}\n\n/** Where a color sits on the spectrum; a gray keeps the hue of `previous`, as it has none. */\nexport function spectrumPoint(color: Rgba, previous?: SpectrumPoint): SpectrumPoint {\n const { h, l } = rgbToHsl(color)\n return { x: 1 - l, y: h === null ? previous?.y ?? 0 : h / 360 }\n}\n\n/** The track of the Opacity slider: the color from clear to opaque over the kit's 12% to 88% (515:47434). */\nexport const opacityTrack = (color: Rgba) => `linear-gradient(to right, ${cssColor(color, 0)} 12%, ${cssColor(color, 1)} 88%)`\n\nexport type ColorChannel = \"r\" | \"g\" | \"b\"\n\nexport const COLOR_PICKER_CHANNELS: readonly { channel: ColorChannel; label: string }[] = [\n { channel: \"r\", label: \"Red\" },\n { channel: \"g\", label: \"Green\" },\n { channel: \"b\", label: \"Blue\" },\n]\n\n/** The track of a channel slider: the color with that channel from 0 to 255. */\nexport const channelTrack = (color: Rgba, channel: ColorChannel) =>\n `linear-gradient(to right, ${cssColor({ ...color, [channel]: 0 }, 1)}, ${cssColor({ ...color, [channel]: 255 }, 1)})`\n\n/** A number typed in a field, kept within `min` and `max`; text with no number is `null`. */\nexport function parseNumber(text: string, min: number, max: number): number | null {\n const number = Number.parseFloat(text.replace(/[%\\s]/g, \"\"))\n return Number.isFinite(number) ? clamp(Math.round(number), min, max) : null\n}\n\n/** The EyeDropper API (Chromium), when the browser has it. */\ntype EyeDropperConstructor = new () => { open: () => Promise<{ sRGBHex: string }> }\n\nexport function eyeDropper(): EyeDropperConstructor | null {\n if (typeof window === \"undefined\") return null\n return (window as Window & { EyeDropper?: EyeDropperConstructor }).EyeDropper ?? null\n}\n"]}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Portal, Slot } from "radix-ui";
|
|
4
|
+
import { createContext, useContext, useEffect, useMemo, useRef, useState, } from "react";
|
|
5
|
+
import s from "@plexui/styles/components/ContextMenu/ContextMenu.module.css";
|
|
6
|
+
import { Menu, useMenuContext } from "../Menu/Menu.js";
|
|
7
|
+
import { TransitionGroup } from "../Transition/index.js";
|
|
8
|
+
import { overlayTiming } from "../Transition/shared.js";
|
|
9
|
+
import { CONTEXT_MENU_LONG_PRESS, CONTEXT_MENU_LONG_PRESS_SLOP, contextMenuHoleMask, contextMenuPlacement, contextMenuPreview, } from "./shared.js";
|
|
10
|
+
const ContextMenuContext = createContext(null);
|
|
11
|
+
function useContextMenuContext(part) {
|
|
12
|
+
const context = useContext(ContextMenuContext);
|
|
13
|
+
if (!context)
|
|
14
|
+
throw new Error(`${part} must be used within ContextMenu`);
|
|
15
|
+
return context;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A menu of actions for an element, after the iOS 26 kit Context Menu (507:25994): a secondary click opens it at
|
|
19
|
+
* the pointer, a touch and hold opens it beside the element, which stays clear above a dimmed, blurred page, as
|
|
20
|
+
* iOS lifts the preview. The items are the ones of `Menu`.
|
|
21
|
+
*/
|
|
22
|
+
function ContextMenuRoot({ children, onOpen, onClose }) {
|
|
23
|
+
const [presentation, setPresentation] = useState(null);
|
|
24
|
+
const regionRef = useRef(null);
|
|
25
|
+
const value = useMemo(() => ({ presentation, setPresentation, regionRef }), [presentation]);
|
|
26
|
+
return (_jsx(ContextMenuContext.Provider, { value: value, children: _jsx(Menu, { onOpen: onOpen, onClose: onClose, children: children }) }));
|
|
27
|
+
}
|
|
28
|
+
ContextMenuRoot.displayName = "ContextMenu";
|
|
29
|
+
/**
|
|
30
|
+
* Swallows the mouse events a browser sends after the touch and hold that opened the menu: the compatibility mousedown
|
|
31
|
+
* would focus the element under the finger, and focus leaving the menu closes it (inside a Dialog or a Sheet, whose
|
|
32
|
+
* content takes the press), and the click would activate the element.
|
|
33
|
+
*/
|
|
34
|
+
const suppressNextClick = (doc) => {
|
|
35
|
+
const hold = (event) => {
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
event.stopPropagation();
|
|
38
|
+
};
|
|
39
|
+
const swallow = (event) => {
|
|
40
|
+
hold(event);
|
|
41
|
+
stop();
|
|
42
|
+
};
|
|
43
|
+
const stop = () => {
|
|
44
|
+
doc.removeEventListener("mousedown", hold, true);
|
|
45
|
+
doc.removeEventListener("click", swallow, true);
|
|
46
|
+
doc.removeEventListener("pointerdown", stop, true);
|
|
47
|
+
window.clearTimeout(timer);
|
|
48
|
+
};
|
|
49
|
+
// A browser that sends no click after the hold must not swallow the next tap: a new press ends the wait too.
|
|
50
|
+
const timer = window.setTimeout(stop, 600);
|
|
51
|
+
doc.addEventListener("mousedown", hold, true);
|
|
52
|
+
doc.addEventListener("click", swallow, true);
|
|
53
|
+
doc.addEventListener("pointerdown", stop, true);
|
|
54
|
+
};
|
|
55
|
+
function ContextMenuTrigger({ children, disabled = false }) {
|
|
56
|
+
const menu = useMenuContext();
|
|
57
|
+
const { setPresentation, regionRef } = useContextMenuContext("ContextMenu.Trigger");
|
|
58
|
+
const press = useRef(null);
|
|
59
|
+
const cancel = () => {
|
|
60
|
+
if (press.current)
|
|
61
|
+
window.clearTimeout(press.current.timer);
|
|
62
|
+
press.current = null;
|
|
63
|
+
};
|
|
64
|
+
useEffect(() => () => {
|
|
65
|
+
if (press.current)
|
|
66
|
+
window.clearTimeout(press.current.timer);
|
|
67
|
+
}, []);
|
|
68
|
+
const open = (presentation) => {
|
|
69
|
+
setPresentation(presentation);
|
|
70
|
+
menu.setOpen(true);
|
|
71
|
+
};
|
|
72
|
+
const openPreview = (element, x) => {
|
|
73
|
+
regionRef.current = element;
|
|
74
|
+
open(contextMenuPreview(element, x));
|
|
75
|
+
};
|
|
76
|
+
const handlers = {
|
|
77
|
+
onPointerDown: (event) => {
|
|
78
|
+
if (event.defaultPrevented || disabled || event.pointerType !== "touch" || !event.isPrimary)
|
|
79
|
+
return;
|
|
80
|
+
cancel();
|
|
81
|
+
const element = event.currentTarget;
|
|
82
|
+
const x = event.clientX;
|
|
83
|
+
const timer = window.setTimeout(() => {
|
|
84
|
+
const current = press.current;
|
|
85
|
+
if (!current || current.timer !== timer)
|
|
86
|
+
return;
|
|
87
|
+
current.opened = true;
|
|
88
|
+
openPreview(element, x);
|
|
89
|
+
}, CONTEXT_MENU_LONG_PRESS);
|
|
90
|
+
press.current = { id: event.pointerId, x, y: event.clientY, timer, opened: false };
|
|
91
|
+
},
|
|
92
|
+
onPointerMove: (event) => {
|
|
93
|
+
const current = press.current;
|
|
94
|
+
if (!current || current.id !== event.pointerId || current.opened)
|
|
95
|
+
return;
|
|
96
|
+
if (Math.hypot(event.clientX - current.x, event.clientY - current.y) > CONTEXT_MENU_LONG_PRESS_SLOP)
|
|
97
|
+
cancel();
|
|
98
|
+
},
|
|
99
|
+
onPointerUp: (event) => {
|
|
100
|
+
const current = press.current;
|
|
101
|
+
if (!current || current.id !== event.pointerId)
|
|
102
|
+
return;
|
|
103
|
+
if (current.opened)
|
|
104
|
+
suppressNextClick(event.currentTarget.ownerDocument);
|
|
105
|
+
cancel();
|
|
106
|
+
},
|
|
107
|
+
onPointerCancel: (event) => {
|
|
108
|
+
if (press.current?.id === event.pointerId)
|
|
109
|
+
cancel();
|
|
110
|
+
},
|
|
111
|
+
onContextMenu: (event) => {
|
|
112
|
+
if (event.defaultPrevented || disabled)
|
|
113
|
+
return;
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
const element = event.currentTarget;
|
|
116
|
+
regionRef.current = element;
|
|
117
|
+
// A touch and hold that the browser reports as a context menu (Android) opens the preview once.
|
|
118
|
+
const current = press.current;
|
|
119
|
+
if (current) {
|
|
120
|
+
if (current.opened)
|
|
121
|
+
return;
|
|
122
|
+
window.clearTimeout(current.timer);
|
|
123
|
+
current.opened = true;
|
|
124
|
+
return openPreview(element, current.x);
|
|
125
|
+
}
|
|
126
|
+
if (menu.isUsingKeyboard.current)
|
|
127
|
+
return open({ kind: "keyboard", rect: element.getBoundingClientRect() });
|
|
128
|
+
open({ kind: "pointer", rect: { x: event.clientX, y: event.clientY, width: 0, height: 0 } });
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
return _jsx(Slot.Root, { className: s.Trigger, ...handlers, children: children });
|
|
132
|
+
}
|
|
133
|
+
ContextMenuTrigger.displayName = "ContextMenu.Trigger";
|
|
134
|
+
function ContextMenuContent(props) {
|
|
135
|
+
const { open } = useMenuContext();
|
|
136
|
+
const { presentation, regionRef } = useContextMenuContext("ContextMenu.Content");
|
|
137
|
+
const rect = presentation?.rect;
|
|
138
|
+
const placement = contextMenuPlacement(presentation);
|
|
139
|
+
const preview = presentation?.kind === "preview" ? presentation : null;
|
|
140
|
+
const dimmed = open && preview !== null;
|
|
141
|
+
return (_jsxs(_Fragment, { children: [_jsx(Portal.Root, { asChild: true, children: _jsx(Menu.Trigger, { children: _jsx("span", { "aria-hidden": "true", tabIndex: -1, className: s.Anchor, style: rect ? { left: rect.x, top: rect.y, width: rect.width, height: rect.height } : undefined }) }) }), _jsx(Portal.Root, { asChild: true, children: _jsx(TransitionGroup, { className: s.Dimming, ...overlayTiming, children: dimmed && (_jsx("div", { "data-context-menu-dimming": "", className: s.Overlay, style: contextMenuHoleMask(preview), children: _jsx("div", { className: s.Preview, style: { left: preview.rect.x, top: preview.rect.y, width: preview.rect.width, height: preview.rect.height, borderRadius: preview.radius } }) }, "dimming")) }) }), _jsx(Menu.Content, { ...props, ...placement, onCloseAutoFocus: (event) => {
|
|
142
|
+
// Focus goes back to the element only when the keyboard opened the menu; a pointer leaves it where it was.
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
if (presentation?.kind === "keyboard")
|
|
145
|
+
regionRef.current?.focus({ preventScroll: true });
|
|
146
|
+
} })] }));
|
|
147
|
+
}
|
|
148
|
+
ContextMenuContent.displayName = "ContextMenu.Content";
|
|
149
|
+
export const ContextMenu = Object.assign(ContextMenuRoot, {
|
|
150
|
+
Trigger: ContextMenuTrigger,
|
|
151
|
+
Content: ContextMenuContent,
|
|
152
|
+
Item: Menu.Item,
|
|
153
|
+
Link: Menu.Link,
|
|
154
|
+
Separator: Menu.Separator,
|
|
155
|
+
Label: Menu.Label,
|
|
156
|
+
Group: Menu.Group,
|
|
157
|
+
Sub: Menu.Sub,
|
|
158
|
+
SubTrigger: Menu.SubTrigger,
|
|
159
|
+
SubContent: Menu.SubContent,
|
|
160
|
+
CheckboxItem: Menu.CheckboxItem,
|
|
161
|
+
RadioGroup: Menu.RadioGroup,
|
|
162
|
+
RadioItem: Menu.RadioItem,
|
|
163
|
+
});
|
|
164
|
+
//# sourceMappingURL=ContextMenu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContextMenu.js","sourceRoot":"","sources":["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AC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,CAAC,MAAM,EAAE,GAC1I,IAJK,SAAS,CAKZ,CACP,GACe,GACN,EACd,KAAC,IAAI,CAAC,OAAO,OACP,KAAK,KACL,SAAS,EACb,gBAAgB,EAAE,CAAC,KAAK,EAAE,EAAE;oBAC1B,2GAA2G;oBAC3G,KAAK,CAAC,cAAc,EAAE,CAAA;oBACtB,IAAI,YAAY,EAAE,IAAI,KAAK,UAAU;wBAAE,SAAS,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAA;gBAC1F,CAAC,GACD,IACD,CACJ,CAAA;AACH,CAAC;AACD,kBAAkB,CAAC,WAAW,GAAG,qBAAqB,CAAA;AAEtD,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE;IACxD,OAAO,EAAE,kBAAkB;IAC3B,OAAO,EAAE,kBAAkB;IAC3B,IAAI,EAAE,IAAI,CAAC,IAAI;IACf,IAAI,EAAE,IAAI,CAAC,IAAI;IACf,SAAS,EAAE,IAAI,CAAC,SAAS;IACzB,KAAK,EAAE,IAAI,CAAC,KAAK;IACjB,KAAK,EAAE,IAAI,CAAC,KAAK;IACjB,GAAG,EAAE,IAAI,CAAC,GAAG;IACb,UAAU,EAAE,IAAI,CAAC,UAAU;IAC3B,UAAU,EAAE,IAAI,CAAC,UAAU;IAC3B,YAAY,EAAE,IAAI,CAAC,YAAY;IAC/B,UAAU,EAAE,IAAI,CAAC,UAAU;IAC3B,SAAS,EAAE,IAAI,CAAC,SAAS;CAC1B,CAAC,CAAA","sourcesContent":["\"use client\"\n\nimport { Portal, Slot } from \"radix-ui\"\nimport {\n createContext,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n type CSSProperties,\n type MouseEvent as ReactMouseEvent,\n type PointerEvent as ReactPointerEvent,\n type ReactElement,\n type ReactNode,\n type RefObject,\n} from \"react\"\nimport s from \"@plexui/styles/components/ContextMenu/ContextMenu.module.css\"\nimport { Menu, useMenuContext, type MenuContentProps } from \"../Menu/Menu\"\nimport { TransitionGroup } from \"../Transition\"\nimport { overlayTiming } from \"../Transition/shared\"\nimport {\n CONTEXT_MENU_LONG_PRESS,\n CONTEXT_MENU_LONG_PRESS_SLOP,\n contextMenuHoleMask,\n contextMenuPlacement,\n contextMenuPreview,\n type ContextMenuPresentation,\n} from \"./shared\"\n\ntype ContextMenuContextValue = {\n presentation: ContextMenuPresentation | null\n setPresentation: (presentation: ContextMenuPresentation) => void\n regionRef: RefObject<HTMLElement | null>\n}\n\nconst ContextMenuContext = createContext<ContextMenuContextValue | null>(null)\n\nfunction useContextMenuContext(part: string) {\n const context = useContext(ContextMenuContext)\n if (!context) throw new Error(`${part} must be used within ContextMenu`)\n return context\n}\n\nexport type ContextMenuProps = {\n /** `ContextMenu.Trigger` and `ContextMenu.Content`. */\n children: ReactNode\n /** Called when the menu opens. */\n onOpen?: () => void\n /** Called when the menu closes. */\n onClose?: () => void\n}\n\n/**\n * A menu of actions for an element, after the iOS 26 kit Context Menu (507:25994): a secondary click opens it at\n * the pointer, a touch and hold opens it beside the element, which stays clear above a dimmed, blurred page, as\n * iOS lifts the preview. The items are the ones of `Menu`.\n */\nfunction ContextMenuRoot({ children, onOpen, onClose }: ContextMenuProps) {\n const [presentation, setPresentation] = useState<ContextMenuPresentation | null>(null)\n const regionRef = useRef<HTMLElement | null>(null)\n const value = useMemo(() => ({ presentation, setPresentation, regionRef }), [presentation])\n return (\n <ContextMenuContext.Provider value={value}>\n <Menu onOpen={onOpen} onClose={onClose}>{children}</Menu>\n </ContextMenuContext.Provider>\n )\n}\nContextMenuRoot.displayName = \"ContextMenu\"\n\nexport type ContextMenuTriggerProps = {\n /** The element the menu is for; it receives the handlers, so it keeps its own role and focus. */\n children: ReactElement\n /** When `true`, the element keeps the browser's own context menu. */\n disabled?: boolean\n}\n\ntype Press = { id: number; x: number; y: number; timer: number; opened: boolean }\n\n/**\n * Swallows the mouse events a browser sends after the touch and hold that opened the menu: the compatibility mousedown\n * would focus the element under the finger, and focus leaving the menu closes it (inside a Dialog or a Sheet, whose\n * content takes the press), and the click would activate the element.\n */\nconst suppressNextClick = (doc: Document) => {\n const hold = (event: Event) => {\n event.preventDefault()\n event.stopPropagation()\n }\n const swallow = (event: Event) => {\n hold(event)\n stop()\n }\n const stop = () => {\n doc.removeEventListener(\"mousedown\", hold, true)\n doc.removeEventListener(\"click\", swallow, true)\n doc.removeEventListener(\"pointerdown\", stop, true)\n window.clearTimeout(timer)\n }\n // A browser that sends no click after the hold must not swallow the next tap: a new press ends the wait too.\n const timer = window.setTimeout(stop, 600)\n doc.addEventListener(\"mousedown\", hold, true)\n doc.addEventListener(\"click\", swallow, true)\n doc.addEventListener(\"pointerdown\", stop, true)\n}\n\nfunction ContextMenuTrigger({ children, disabled = false }: ContextMenuTriggerProps) {\n const menu = useMenuContext()\n const { setPresentation, regionRef } = useContextMenuContext(\"ContextMenu.Trigger\")\n const press = useRef<Press | null>(null)\n\n const cancel = () => {\n if (press.current) window.clearTimeout(press.current.timer)\n press.current = null\n }\n useEffect(() => () => {\n if (press.current) window.clearTimeout(press.current.timer)\n }, [])\n\n const open = (presentation: ContextMenuPresentation) => {\n setPresentation(presentation)\n menu.setOpen(true)\n }\n const openPreview = (element: HTMLElement, x: number) => {\n regionRef.current = element\n open(contextMenuPreview(element, x))\n }\n\n const handlers = {\n onPointerDown: (event: ReactPointerEvent<HTMLElement>) => {\n if (event.defaultPrevented || disabled || event.pointerType !== \"touch\" || !event.isPrimary) return\n cancel()\n const element = event.currentTarget\n const x = event.clientX\n const timer = window.setTimeout(() => {\n const current = press.current\n if (!current || current.timer !== timer) return\n current.opened = true\n openPreview(element, x)\n }, CONTEXT_MENU_LONG_PRESS)\n press.current = { id: event.pointerId, x, y: event.clientY, timer, opened: false }\n },\n onPointerMove: (event: ReactPointerEvent<HTMLElement>) => {\n const current = press.current\n if (!current || current.id !== event.pointerId || current.opened) return\n if (Math.hypot(event.clientX - current.x, event.clientY - current.y) > CONTEXT_MENU_LONG_PRESS_SLOP) cancel()\n },\n onPointerUp: (event: ReactPointerEvent<HTMLElement>) => {\n const current = press.current\n if (!current || current.id !== event.pointerId) return\n if (current.opened) suppressNextClick(event.currentTarget.ownerDocument)\n cancel()\n },\n onPointerCancel: (event: ReactPointerEvent<HTMLElement>) => {\n if (press.current?.id === event.pointerId) cancel()\n },\n onContextMenu: (event: ReactMouseEvent<HTMLElement>) => {\n if (event.defaultPrevented || disabled) return\n event.preventDefault()\n const element = event.currentTarget\n regionRef.current = element\n // A touch and hold that the browser reports as a context menu (Android) opens the preview once.\n const current = press.current\n if (current) {\n if (current.opened) return\n window.clearTimeout(current.timer)\n current.opened = true\n return openPreview(element, current.x)\n }\n if (menu.isUsingKeyboard.current) return open({ kind: \"keyboard\", rect: element.getBoundingClientRect() })\n open({ kind: \"pointer\", rect: { x: event.clientX, y: event.clientY, width: 0, height: 0 } })\n },\n }\n\n return <Slot.Root className={s.Trigger} {...handlers}>{children}</Slot.Root>\n}\nContextMenuTrigger.displayName = \"ContextMenu.Trigger\"\n\n/** The props of `Menu.Content` but its placement, which follows how the menu opened. */\nexport type ContextMenuContentProps = Omit<MenuContentProps, \"side\" | \"sideOffset\" | \"align\" | \"alignOffset\" | \"onCloseAutoFocus\" | \"layout\" | \"size\">\n\nfunction ContextMenuContent(props: ContextMenuContentProps) {\n const { open } = useMenuContext()\n const { presentation, regionRef } = useContextMenuContext(\"ContextMenu.Content\")\n const rect = presentation?.rect\n const placement = contextMenuPlacement(presentation)\n const preview = presentation?.kind === \"preview\" ? presentation : null\n const dimmed = open && preview !== null\n\n return (\n <>\n {/* The menu is placed against this invisible box: the pointer, or the element. */}\n <Portal.Root asChild>\n <Menu.Trigger>\n <span\n aria-hidden=\"true\"\n tabIndex={-1}\n className={s.Anchor}\n style={rect ? { left: rect.x, top: rect.y, width: rect.width, height: rect.height } : undefined}\n />\n </Menu.Trigger>\n </Portal.Root>\n <Portal.Root asChild>\n <TransitionGroup className={s.Dimming} {...overlayTiming}>\n {dimmed && (\n <div key=\"dimming\" data-context-menu-dimming=\"\" className={s.Overlay} style={contextMenuHoleMask(preview) as CSSProperties}>\n <div\n className={s.Preview}\n style={{ left: preview.rect.x, top: preview.rect.y, width: preview.rect.width, height: preview.rect.height, borderRadius: preview.radius }}\n />\n </div>\n )}\n </TransitionGroup>\n </Portal.Root>\n <Menu.Content\n {...props}\n {...placement}\n onCloseAutoFocus={(event) => {\n // Focus goes back to the element only when the keyboard opened the menu; a pointer leaves it where it was.\n event.preventDefault()\n if (presentation?.kind === \"keyboard\") regionRef.current?.focus({ preventScroll: true })\n }}\n />\n </>\n )\n}\nContextMenuContent.displayName = \"ContextMenu.Content\"\n\nexport const ContextMenu = Object.assign(ContextMenuRoot, {\n Trigger: ContextMenuTrigger,\n Content: ContextMenuContent,\n Item: Menu.Item,\n Link: Menu.Link,\n Separator: Menu.Separator,\n Label: Menu.Label,\n Group: Menu.Group,\n Sub: Menu.Sub,\n SubTrigger: Menu.SubTrigger,\n SubContent: Menu.SubContent,\n CheckboxItem: Menu.CheckboxItem,\n RadioGroup: Menu.RadioGroup,\n RadioItem: Menu.RadioItem,\n})\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/ContextMenu/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAqF,MAAM,eAAe,CAAA","sourcesContent":["export { ContextMenu, type ContextMenuContentProps, type ContextMenuProps, type ContextMenuTriggerProps } from \"./ContextMenu\"\n"]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** A touch held this long opens the menu, as a UIKit long press (0.5 s). */
|
|
2
|
+
export const CONTEXT_MENU_LONG_PRESS = 500;
|
|
3
|
+
/** A touch that moves farther than this before then scrolls or drags instead. */
|
|
4
|
+
export const CONTEXT_MENU_LONG_PRESS_SLOP = 10;
|
|
5
|
+
/** The kit's gap between the preview and the menu (Context Menu, Alignment=Vertical: 160 + 18 = 178). */
|
|
6
|
+
export const CONTEXT_MENU_PREVIEW_GAP = 18;
|
|
7
|
+
/** The kit's preview corner (Content Area, radius 30), for an element without corners of its own. */
|
|
8
|
+
const PREVIEW_RADIUS = 30;
|
|
9
|
+
const px = (value, base) => {
|
|
10
|
+
const number = Number.parseFloat(value);
|
|
11
|
+
if (!Number.isFinite(number))
|
|
12
|
+
return 0;
|
|
13
|
+
return value.trim().endsWith("%") ? (number / 100) * base : number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The preview of a touch and hold: the element's box and corner (its own, or `--context-menu-preview-radius`), and
|
|
17
|
+
* the edge the menu keeps to, the one on the side of the touch, as the kit's Side=Leading and Side=Trailing.
|
|
18
|
+
*/
|
|
19
|
+
export function contextMenuPreview(element, touchX) {
|
|
20
|
+
const box = element.getBoundingClientRect();
|
|
21
|
+
const rect = { x: box.left, y: box.top, width: box.width, height: box.height };
|
|
22
|
+
const style = getComputedStyle(element);
|
|
23
|
+
const short = Math.min(rect.width, rect.height);
|
|
24
|
+
const own = px(style.borderTopLeftRadius, short);
|
|
25
|
+
const fallback = px(style.getPropertyValue("--context-menu-preview-radius"), short) || PREVIEW_RADIUS;
|
|
26
|
+
const radius = Math.min(own > 0 ? own : fallback, short / 2);
|
|
27
|
+
const width = element.ownerDocument.defaultView?.innerWidth ?? rect.x + rect.width;
|
|
28
|
+
return { kind: "preview", rect, radius, align: touchX < width / 2 ? "start" : "end" };
|
|
29
|
+
}
|
|
30
|
+
/** The menu's side, alignment and offsets for a presentation. */
|
|
31
|
+
export function contextMenuPlacement(presentation) {
|
|
32
|
+
if (presentation?.kind === "preview")
|
|
33
|
+
return { side: "bottom", align: presentation.align, sideOffset: CONTEXT_MENU_PREVIEW_GAP, alignOffset: 0 };
|
|
34
|
+
if (presentation?.kind === "keyboard")
|
|
35
|
+
return { side: "bottom", align: "start", sideOffset: 5, alignOffset: 0 };
|
|
36
|
+
// As a desktop context menu, its corner at the pointer.
|
|
37
|
+
return { side: "bottom", align: "start", sideOffset: 2, alignOffset: 0 };
|
|
38
|
+
}
|
|
39
|
+
const round = (value) => Math.round(value * 100) / 100;
|
|
40
|
+
/**
|
|
41
|
+
* The dimming covers the page but the element: an SVG mask with the element's rounded box cut out, written to
|
|
42
|
+
* `--context-menu-hole`, so the element stays clear above the dimmed, blurred page.
|
|
43
|
+
*/
|
|
44
|
+
export function contextMenuHoleMask(preview, viewport) {
|
|
45
|
+
const width = round(viewport?.width ?? window.innerWidth);
|
|
46
|
+
const height = round(viewport?.height ?? window.innerHeight);
|
|
47
|
+
const x = round(preview.rect.x);
|
|
48
|
+
const y = round(preview.rect.y);
|
|
49
|
+
const w = round(preview.rect.width);
|
|
50
|
+
const h = round(preview.rect.height);
|
|
51
|
+
const r = round(preview.radius);
|
|
52
|
+
const hole = `M${x + r} ${y}H${round(x + w - r)}A${r} ${r} 0 0 1 ${x + w} ${round(y + r)}V${round(y + h - r)}A${r} ${r} 0 0 1 ${round(x + w - r)} ${round(y + h)}H${round(x + r)}A${r} ${r} 0 0 1 ${x} ${round(y + h - r)}V${round(y + r)}A${r} ${r} 0 0 1 ${round(x + r)} ${y}Z`;
|
|
53
|
+
const svg = `<svg xmlns='http://www.w3.org/2000/svg' width='${width}' height='${height}' viewBox='0 0 ${width} ${height}'><path fill-rule='evenodd' d='M0 0H${width}V${height}H0Z${hole}'/></svg>`;
|
|
54
|
+
return { "--context-menu-hole": `url("data:image/svg+xml,${encodeURIComponent(svg)}")` };
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../../src/components/ContextMenu/shared.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAA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,IAAI,MAAM,uCAAuC,KAAK,IAAI,MAAM,MAAM,IAAI,WAAW,CAAA;IAClM,OAAO,EAAE,qBAAqB,EAAE,2BAA2B,kBAAkB,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;AAC1F,CAAC","sourcesContent":["/** A touch held this long opens the menu, as a UIKit long press (0.5 s). */\nexport const CONTEXT_MENU_LONG_PRESS = 500\n/** A touch that moves farther than this before then scrolls or drags instead. */\nexport const CONTEXT_MENU_LONG_PRESS_SLOP = 10\n/** The kit's gap between the preview and the menu (Context Menu, Alignment=Vertical: 160 + 18 = 178). */\nexport const CONTEXT_MENU_PREVIEW_GAP = 18\n/** The kit's preview corner (Content Area, radius 30), for an element without corners of its own. */\nconst PREVIEW_RADIUS = 30\n\ntype Rect = { x: number; y: number; width: number; height: number }\n\n/** Where the menu opens: at the pointer, under the element for the keyboard, or beside a touch-and-hold preview. */\nexport type ContextMenuPresentation =\n | { kind: \"pointer\"; rect: Rect }\n | { kind: \"keyboard\"; rect: Rect }\n | { kind: \"preview\"; rect: Rect; radius: number; align: \"start\" | \"end\" }\n\nconst px = (value: string, base: number) => {\n const number = Number.parseFloat(value)\n if (!Number.isFinite(number)) return 0\n return value.trim().endsWith(\"%\") ? (number / 100) * base : number\n}\n\n/**\n * The preview of a touch and hold: the element's box and corner (its own, or `--context-menu-preview-radius`), and\n * the edge the menu keeps to, the one on the side of the touch, as the kit's Side=Leading and Side=Trailing.\n */\nexport function contextMenuPreview(element: HTMLElement, touchX: number): ContextMenuPresentation {\n const box = element.getBoundingClientRect()\n const rect = { x: box.left, y: box.top, width: box.width, height: box.height }\n const style = getComputedStyle(element)\n const short = Math.min(rect.width, rect.height)\n const own = px(style.borderTopLeftRadius, short)\n const fallback = px(style.getPropertyValue(\"--context-menu-preview-radius\"), short) || PREVIEW_RADIUS\n const radius = Math.min(own > 0 ? own : fallback, short / 2)\n const width = element.ownerDocument.defaultView?.innerWidth ?? rect.x + rect.width\n return { kind: \"preview\", rect, radius, align: touchX < width / 2 ? \"start\" : \"end\" }\n}\n\n/** The menu's side, alignment and offsets for a presentation. */\nexport function contextMenuPlacement(presentation: ContextMenuPresentation | null) {\n if (presentation?.kind === \"preview\")\n return { side: \"bottom\" as const, align: presentation.align, sideOffset: CONTEXT_MENU_PREVIEW_GAP, alignOffset: 0 }\n if (presentation?.kind === \"keyboard\") return { side: \"bottom\" as const, align: \"start\" as const, sideOffset: 5, alignOffset: 0 }\n // As a desktop context menu, its corner at the pointer.\n return { side: \"bottom\" as const, align: \"start\" as const, sideOffset: 2, alignOffset: 0 }\n}\n\nconst round = (value: number) => Math.round(value * 100) / 100\n\n/**\n * The dimming covers the page but the element: an SVG mask with the element's rounded box cut out, written to\n * `--context-menu-hole`, so the element stays clear above the dimmed, blurred page.\n */\nexport function contextMenuHoleMask(preview: Extract<ContextMenuPresentation, { kind: \"preview\" }>, viewport?: { width: number; height: number }) {\n const width = round(viewport?.width ?? window.innerWidth)\n const height = round(viewport?.height ?? window.innerHeight)\n const x = round(preview.rect.x)\n const y = round(preview.rect.y)\n const w = round(preview.rect.width)\n const h = round(preview.rect.height)\n const r = round(preview.radius)\n const hole = `M${x + r} ${y}H${round(x + w - r)}A${r} ${r} 0 0 1 ${x + w} ${round(y + r)}V${round(y + h - r)}A${r} ${r} 0 0 1 ${round(x + w - r)} ${round(y + h)}H${round(x + r)}A${r} ${r} 0 0 1 ${x} ${round(y + h - r)}V${round(y + r)}A${r} ${r} 0 0 1 ${round(x + r)} ${y}Z`\n const svg = `<svg xmlns='http://www.w3.org/2000/svg' width='${width}' height='${height}' viewBox='0 0 ${width} ${height}'><path fill-rule='evenodd' d='M0 0H${width}V${height}H0Z${hole}'/></svg>`\n return { \"--context-menu-hole\": `url(\"data:image/svg+xml,${encodeURIComponent(svg)}\")` }\n}\n"]}
|
|
@@ -13,7 +13,7 @@ import { DateCalendar } from "./Calendar.js";
|
|
|
13
13
|
import { useCalendarGutter } from "./useCalendarGutter.js";
|
|
14
14
|
import { DateContext } from "./context.js";
|
|
15
15
|
export const DatePicker = (props) => {
|
|
16
|
-
const { id, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, value, onChange, min, max, side = "bottom", sideOffset = 8, align = "center", alignOffset, variant = "outline", size = "md", clearable = false, disabled = false, dropdownIconType, placeholder = "Select date...", pill = true, block = false, triggerClassName, triggerShowIcon = true, captionLayout = "buttons", showTime = false, yearRange, triggerDateFormat = showTime ? "MM/dd/yy HH:mm" : "MM/dd/yy", } = props;
|
|
16
|
+
const { id, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, value, onChange, min, max, side = "bottom", sideOffset = 8, align = "center", alignOffset, variant = "outline", size = "md", clearable = false, disabled = false, dropdownIconType, placeholder = "Select date...", pill = true, block = false, triggerClassName, triggerShowIcon = true, captionLayout = "buttons", showTime = false, yearRange, triggerTimeFormat, triggerDateFormat = showTime && !triggerTimeFormat ? "MM/dd/yy HH:mm" : "MM/dd/yy", } = props;
|
|
17
17
|
// min and max are inclusive, so equal bounds allow one date
|
|
18
18
|
if (min && max && isAfter(min, max)) {
|
|
19
19
|
throw new Error("DatePicker error: `min` date must not be after the `max` date");
|
|
@@ -67,6 +67,8 @@ export const DatePicker = (props) => {
|
|
|
67
67
|
const handleClearClick = () => {
|
|
68
68
|
onChangeRef.current(null);
|
|
69
69
|
};
|
|
70
|
-
|
|
70
|
+
// With a time format the date and the time are two parts, apart by a space; a phone row draws each as a capsule
|
|
71
|
+
const triggerValue = !value ? placeholder : showTime && triggerTimeFormat ? (_jsxs("span", { "data-date-parts": "", children: [_jsx("span", { "data-date-part": "date", children: value.toFormat(triggerDateFormat) }), " ", _jsx("span", { "data-date-part": "time", children: value.toFormat(triggerTimeFormat) })] })) : value.toFormat(triggerDateFormat);
|
|
72
|
+
return (_jsx(DateContext, { value: store, children: _jsxs(Popover, { children: [_jsx(Popover.Trigger, { children: _jsx(SelectControl, { id: id, "aria-label": ariaLabel, "aria-labelledby": ariaLabelledBy ? `${ariaLabelledBy} ${valueId}` : undefined, "aria-describedby": ariaDescribedBy, "aria-invalid": ariaInvalid, className: triggerClassName, "data-date-picker": "", selected: !!value, variant: variant, pill: pill, block: block, size: size, disabled: disabled, interactOnEnter: true, StartIcon: triggerShowIcon ? Calendar : undefined, dropdownIconType: dropdownIconType, onClearClick: clearable ? handleClearClick : undefined, children: ariaLabelledBy ? _jsx("span", { id: valueId, children: triggerValue }) : triggerValue }) }), _jsx(Popover.Content, { className: s.Popover, minWidth: 230, collisionPadding: wide ? 20 : calendarGutter, side: wide || side === "top" ? side : "bottom", sideOffset: sideOffset, align: align, alignOffset: alignOffset ?? (align === "center" ? 0 : -5), children: _jsx(DateCalendar, {}) })] }) }));
|
|
71
73
|
};
|
|
72
74
|
//# sourceMappingURL=DatePicker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker.js","sourceRoot":"","sources":["../../../../src/components/DatePicker/DatePicker.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,CAAC,MAAM,0DAA0D,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,OAAO,EAA4B,MAAM,YAAY,CAAA;AAC9D,OAAO,EAAE,aAAa,EAA2B,MAAM,kBAAkB,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,EAAE,iBAAiB,EAAE,MA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AAC,CAAC,SAAS,YAErD,cAAc,CAAC,CAAC,CAAC,CAChB,eAAM,EAAE,EAAE,OAAO,YAAG,KAAK,EAAE,QAAQ,CAAC,iBAAiB,CAAC,IAAI,WAAW,GAAQ,CAC9E,CAAC,CAAC,CAAC,KAAK,EAAE,QAAQ,CAAC,iBAAiB,CAAC,IAAI,WAAW,GACvC,GACA,EAClB,KAAC,OAAO,CAAC,OAAO,IACd,SAAS,EAAE,CAAC,CAAC,OAAO,EACpB,QAAQ,EAAE,GAAG,EACb,gBAAgB,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc,EAC5C,IAAI,EAAE,IAAI,IAAI,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,EAC9C,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,IAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAEzD,KAAC,YAAY,KAAG,GACA,IACV,GACE,CACf,CAAA;AACH,CAAC,CAAA","sourcesContent":["\"use client\"\n\nimport s from \"@plexui/styles/components/DatePicker/Calendar.module.css\"\nimport { DateTime } from \"luxon\"\nimport { useId, useMemo } from \"react\"\nimport { useBreakpoint } from \"../../hooks/useBreakpoints\"\nimport { useLatestValue } from \"../../hooks/useLatestValue\"\nimport { isAfter } from \"../../lib/dateUtils\"\nimport { Calendar } from \"../Icon\"\nimport { Popover, type PopoverContentProps } from \"../Popover\"\nimport { SelectControl, type SelectControlProps } from \"../SelectControl\"\nimport { DateCalendar } from \"./Calendar\"\nimport { useCalendarGutter } from \"./useCalendarGutter\"\nimport { DateContext, type DateContextValue } from \"./context\"\n\nexport type DatePickerProps = Pick<SelectControlProps, \"aria-label\" | \"aria-labelledby\" | \"aria-describedby\" | \"aria-invalid\"> & {\n /**\n * Allow targeting the input for forms and accessibility.\n */\n id?: string\n /**\n * The selected date value.\n */\n value: DateTime | null\n /**\n * Handler that is triggered when the date changes.\n */\n onChange: (nextValue: DateTime | null) => void\n /**\n * Defines the earliest selectable date (inclusive).\n */\n min?: DateTime\n /**\n * Defines the latest selectable date (inclusive).\n */\n max?: DateTime\n /**\n * The preferred side of the trigger to render against when open. Will be reversed when collisions occur.\n * On phones, left and right prefer bottom so all seven 44px day targets fit.\n * @default bottom\n */\n side?: PopoverContentProps[\"side\"]\n /**\n * The distance in pixels from the trigger.\n * @default 8\n */\n sideOffset?: PopoverContentProps[\"sideOffset\"]\n /**\n * The preferred alignment against the trigger. May change when collisions occur.\n * @default center\n */\n align?: PopoverContentProps[\"align\"]\n /**\n * An offset in pixels from the \"start\" or \"end\" alignment options.\n * @default 0\n */\n alignOffset?: PopoverContentProps[\"alignOffset\"]\n\n /**\n * Disables the select visually and from interactions\n * @default false\n */\n disabled?: boolean\n /**\n * Placeholder text for the select\n * @default Select date...\n */\n placeholder?: string\n /**\n * Style variant for the select trigger\n * @default outline\n */\n variant?: SelectControlProps[\"variant\"]\n /**\n * Determines if the select trigger should be a fully rounded pill shape\n * @default true\n */\n pill?: boolean\n /**\n * Determines size of the size and spacing of the control.\n *\n * | 3xs | 2xs | xs | sm | md | lg | xl | 2xl | 3xl |\n * | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- |\n * | `22px` | `24px` | `26px` | `28px` | `32px` | `36px` | `40px` | `44px` | `48px` |\n * @default md\n */\n size?: SelectControlProps[\"size\"]\n /**\n * Icon displayed in the far right of the select trigger\n * @default dropdown\n */\n dropdownIconType?: SelectControlProps[\"dropdownIconType\"]\n /**\n * Custom class applied to the select trigger\n */\n triggerClassName?: string\n /**\n * Display calendar icon at the start of the trigger\n * @default true\n */\n triggerShowIcon?: boolean\n /**\n * Format of dates displayed in the trigger\n * @default \"MM/dd/yy\", or \"MM/dd/yy HH:mm\" with showTime\n */\n triggerDateFormat?: string\n /**\n * Display a clear action that allows the select to be unset.\n * @default false\n */\n clearable?: boolean\n /**\n * Extends select to 100% of available width.\n * @default false\n */\n block?: boolean\n /**\n * Controls how the calendar header is rendered.\n * - `\"buttons\"` — Arrow navigation between months (default)\n * - `\"dropdown\"` — Month and year dropdown selects (ideal for date of birth)\n * @default buttons\n */\n captionLayout?: \"buttons\" | \"dropdown\"\n /**\n * Show time input below the calendar for combined date and time selection.\n * @default false\n */\n showTime?: boolean\n /**\n * Range of selectable years when `captionLayout` is `\"dropdown\"`.\n * @default [currentYear - 120, currentYear]\n */\n yearRange?: [number, number]\n}\n\nexport const DatePicker = (props: DatePickerProps) => {\n const {\n id,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-invalid\": ariaInvalid,\n value,\n onChange,\n min,\n max,\n side = \"bottom\",\n sideOffset = 8,\n align = \"center\",\n alignOffset,\n variant = \"outline\",\n size = \"md\",\n clearable = false,\n disabled = false,\n dropdownIconType,\n placeholder = \"Select date...\",\n pill = true,\n block = false,\n triggerClassName,\n triggerShowIcon = true,\n captionLayout = \"buttons\",\n showTime = false,\n yearRange,\n triggerDateFormat = showTime ? \"MM/dd/yy HH:mm\" : \"MM/dd/yy\",\n } = props\n\n // min and max are inclusive, so equal bounds allow one date\n if (min && max && isAfter(min, max)) {\n throw new Error(\"DatePicker error: `min` date must not be after the `max` date\")\n }\n\n // The value text needs an id for aria-labelledby, also when `id` is not set\n const generatedId = useId()\n const wide = useBreakpoint(\"md\")\n const calendarGutter = useCalendarGutter()\n const valueId = `${id ?? generatedId}-value`\n\n // Create stable, mutable references to avoid memoization requirements from consumers\n const onChangeRef = useLatestValue(onChange)\n\n const store = useMemo<DateContextValue>(\n () => ({\n value,\n min,\n max,\n variant,\n size,\n dropdownIconType,\n clearable,\n disabled,\n placeholder,\n block,\n pill,\n triggerClassName,\n triggerShowIcon,\n triggerDateFormat,\n captionLayout,\n showTime,\n yearRange,\n onChangeRef,\n }),\n [\n value,\n min,\n max,\n variant,\n size,\n dropdownIconType,\n clearable,\n disabled,\n placeholder,\n block,\n pill,\n triggerClassName,\n triggerShowIcon,\n triggerDateFormat,\n captionLayout,\n showTime,\n yearRange,\n onChangeRef,\n ],\n )\n\n const handleClearClick = () => {\n onChangeRef.current(null)\n }\n\n return (\n <DateContext value={store}>\n <Popover>\n <Popover.Trigger>\n <SelectControl\n id={id}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy ? `${ariaLabelledBy} ${valueId}` : undefined}\n aria-describedby={ariaDescribedBy}\n aria-invalid={ariaInvalid}\n className={triggerClassName}\n selected={!!value}\n variant={variant}\n pill={pill}\n block={block}\n size={size}\n disabled={disabled}\n interactOnEnter\n StartIcon={triggerShowIcon ? Calendar : undefined}\n dropdownIconType={dropdownIconType}\n onClearClick={clearable ? handleClearClick : undefined}\n >\n {ariaLabelledBy ? (\n <span id={valueId}>{value?.toFormat(triggerDateFormat) ?? placeholder}</span>\n ) : value?.toFormat(triggerDateFormat) ?? placeholder}\n </SelectControl>\n </Popover.Trigger>\n <Popover.Content\n className={s.Popover}\n minWidth={230}\n collisionPadding={wide ? 20 : calendarGutter}\n side={wide || side === \"top\" ? side : \"bottom\"}\n sideOffset={sideOffset}\n align={align}\n alignOffset={alignOffset ?? (align === \"center\" ? 0 : -5)}\n >\n <DateCalendar />\n </Popover.Content>\n </Popover>\n </DateContext>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DatePicker.js","sourceRoot":"","sources":["../../../../src/components/DatePicker/DatePicker.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,CAAC,MAAM,0DAA0D,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,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CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAEzD,KAAC,YAAY,KAAG,GACA,IACV,GACE,CACf,CAAA;AACH,CAAC,CAAA","sourcesContent":["\"use client\"\n\nimport s from \"@plexui/styles/components/DatePicker/Calendar.module.css\"\nimport { DateTime } from \"luxon\"\nimport { useId, useMemo } from \"react\"\nimport { useBreakpoint } from \"../../hooks/useBreakpoints\"\nimport { useLatestValue } from \"../../hooks/useLatestValue\"\nimport { isAfter } from \"../../lib/dateUtils\"\nimport { Calendar } from \"../Icon\"\nimport { Popover, type PopoverContentProps } from \"../Popover\"\nimport { SelectControl, type SelectControlProps } from \"../SelectControl\"\nimport { DateCalendar } from \"./Calendar\"\nimport { useCalendarGutter } from \"./useCalendarGutter\"\nimport { DateContext, type DateContextValue } from \"./context\"\n\nexport type DatePickerProps = Pick<SelectControlProps, \"aria-label\" | \"aria-labelledby\" | \"aria-describedby\" | \"aria-invalid\"> & {\n /**\n * Allow targeting the input for forms and accessibility.\n */\n id?: string\n /**\n * The selected date value.\n */\n value: DateTime | null\n /**\n * Handler that is triggered when the date changes.\n */\n onChange: (nextValue: DateTime | null) => void\n /**\n * Defines the earliest selectable date (inclusive).\n */\n min?: DateTime\n /**\n * Defines the latest selectable date (inclusive).\n */\n max?: DateTime\n /**\n * The preferred side of the trigger to render against when open. Will be reversed when collisions occur.\n * On phones, left and right prefer bottom so all seven 44px day targets fit.\n * @default bottom\n */\n side?: PopoverContentProps[\"side\"]\n /**\n * The distance in pixels from the trigger.\n * @default 8\n */\n sideOffset?: PopoverContentProps[\"sideOffset\"]\n /**\n * The preferred alignment against the trigger. May change when collisions occur.\n * @default center\n */\n align?: PopoverContentProps[\"align\"]\n /**\n * An offset in pixels from the \"start\" or \"end\" alignment options.\n * @default 0\n */\n alignOffset?: PopoverContentProps[\"alignOffset\"]\n\n /**\n * Disables the select visually and from interactions\n * @default false\n */\n disabled?: boolean\n /**\n * Placeholder text for the select\n * @default Select date...\n */\n placeholder?: string\n /**\n * Style variant for the select trigger\n * @default outline\n */\n variant?: SelectControlProps[\"variant\"]\n /**\n * Determines if the select trigger should be a fully rounded pill shape\n * @default true\n */\n pill?: boolean\n /**\n * Determines size of the size and spacing of the control.\n *\n * | 3xs | 2xs | xs | sm | md | lg | xl | 2xl | 3xl |\n * | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- |\n * | `22px` | `24px` | `26px` | `28px` | `32px` | `36px` | `40px` | `44px` | `48px` |\n * @default md\n */\n size?: SelectControlProps[\"size\"]\n /**\n * Icon displayed in the far right of the select trigger\n * @default dropdown\n */\n dropdownIconType?: SelectControlProps[\"dropdownIconType\"]\n /**\n * Custom class applied to the select trigger\n */\n triggerClassName?: string\n /**\n * Display calendar icon at the start of the trigger\n * @default true\n */\n triggerShowIcon?: boolean\n /**\n * Format of dates displayed in the trigger\n * @default \"MM/dd/yy\", or \"MM/dd/yy HH:mm\" with showTime and no triggerTimeFormat\n */\n triggerDateFormat?: string\n /**\n * With `showTime`, the format of the time shown after the date in the trigger. The date and the time are\n * then two parts: in a row of a `FieldGroup` on a phone, the two capsules of iOS's compact date and time.\n */\n triggerTimeFormat?: string\n /**\n * Display a clear action that allows the select to be unset.\n * @default false\n */\n clearable?: boolean\n /**\n * Extends select to 100% of available width.\n * @default false\n */\n block?: boolean\n /**\n * Controls how the calendar header is rendered.\n * - `\"buttons\"` — Arrow navigation between months (default)\n * - `\"dropdown\"` — Month and year dropdown selects (ideal for date of birth)\n * @default buttons\n */\n captionLayout?: \"buttons\" | \"dropdown\"\n /**\n * Show time input below the calendar for combined date and time selection.\n * @default false\n */\n showTime?: boolean\n /**\n * Range of selectable years when `captionLayout` is `\"dropdown\"`.\n * @default [currentYear - 120, currentYear]\n */\n yearRange?: [number, number]\n}\n\nexport const DatePicker = (props: DatePickerProps) => {\n const {\n id,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy,\n \"aria-describedby\": ariaDescribedBy,\n \"aria-invalid\": ariaInvalid,\n value,\n onChange,\n min,\n max,\n side = \"bottom\",\n sideOffset = 8,\n align = \"center\",\n alignOffset,\n variant = \"outline\",\n size = \"md\",\n clearable = false,\n disabled = false,\n dropdownIconType,\n placeholder = \"Select date...\",\n pill = true,\n block = false,\n triggerClassName,\n triggerShowIcon = true,\n captionLayout = \"buttons\",\n showTime = false,\n yearRange,\n triggerTimeFormat,\n triggerDateFormat = showTime && !triggerTimeFormat ? \"MM/dd/yy HH:mm\" : \"MM/dd/yy\",\n } = props\n\n // min and max are inclusive, so equal bounds allow one date\n if (min && max && isAfter(min, max)) {\n throw new Error(\"DatePicker error: `min` date must not be after the `max` date\")\n }\n\n // The value text needs an id for aria-labelledby, also when `id` is not set\n const generatedId = useId()\n const wide = useBreakpoint(\"md\")\n const calendarGutter = useCalendarGutter()\n const valueId = `${id ?? generatedId}-value`\n\n // Create stable, mutable references to avoid memoization requirements from consumers\n const onChangeRef = useLatestValue(onChange)\n\n const store = useMemo<DateContextValue>(\n () => ({\n value,\n min,\n max,\n variant,\n size,\n dropdownIconType,\n clearable,\n disabled,\n placeholder,\n block,\n pill,\n triggerClassName,\n triggerShowIcon,\n triggerDateFormat,\n captionLayout,\n showTime,\n yearRange,\n onChangeRef,\n }),\n [\n value,\n min,\n max,\n variant,\n size,\n dropdownIconType,\n clearable,\n disabled,\n placeholder,\n block,\n pill,\n triggerClassName,\n triggerShowIcon,\n triggerDateFormat,\n captionLayout,\n showTime,\n yearRange,\n onChangeRef,\n ],\n )\n\n const handleClearClick = () => {\n onChangeRef.current(null)\n }\n\n // With a time format the date and the time are two parts, apart by a space; a phone row draws each as a capsule\n const triggerValue = !value ? placeholder : showTime && triggerTimeFormat ? (\n <span data-date-parts=\"\">\n <span data-date-part=\"date\">{value.toFormat(triggerDateFormat)}</span>{\" \"}\n <span data-date-part=\"time\">{value.toFormat(triggerTimeFormat)}</span>\n </span>\n ) : value.toFormat(triggerDateFormat)\n\n return (\n <DateContext value={store}>\n <Popover>\n <Popover.Trigger>\n <SelectControl\n id={id}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy ? `${ariaLabelledBy} ${valueId}` : undefined}\n aria-describedby={ariaDescribedBy}\n aria-invalid={ariaInvalid}\n className={triggerClassName}\n data-date-picker=\"\"\n selected={!!value}\n variant={variant}\n pill={pill}\n block={block}\n size={size}\n disabled={disabled}\n interactOnEnter\n StartIcon={triggerShowIcon ? Calendar : undefined}\n dropdownIconType={dropdownIconType}\n onClearClick={clearable ? handleClearClick : undefined}\n >\n {ariaLabelledBy ? <span id={valueId}>{triggerValue}</span> : triggerValue}\n </SelectControl>\n </Popover.Trigger>\n <Popover.Content\n className={s.Popover}\n minWidth={230}\n collisionPadding={wide ? 20 : calendarGutter}\n side={wide || side === \"top\" ? side : \"bottom\"}\n sideOffset={sideOffset}\n align={align}\n alignOffset={alignOffset ?? (align === \"center\" ? 0 : -5)}\n >\n <DateCalendar />\n </Popover.Content>\n </Popover>\n </DateContext>\n )\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateRangePicker.js","sourceRoot":"","sources":["../../../../src/components/DateRangePicker/DateRangePicker.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,CAAC,MAAM,+DAA+D,CAAA;AAC7E,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAA4B,MAAM,YAAY,CAAA;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAEnE,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAClE,OAAO,EA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O,EACpB,QAAQ,EAAE,GAAG,EACb,gBAAgB,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc,EAC5C,IAAI,EAAE,IAAI,IAAI,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,EAC9C,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,KAAK,EACZ,WAAW,EAAE,WAAW,IAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAEzD,eAAK,SAAS,EAAC,MAAM,aACnB,KAAC,kBAAkB,IAAC,SAAS,EAAE,SAAS,GAAI,EAC5C,KAAC,iBAAiB,KAAG,IACjB,GACU,IACV,GACO,CACpB,CAAA;AACH,CAAC,CAAA","sourcesContent":["\"use client\"\n\nimport s from \"@plexui/styles/components/DateRangePicker/Calendar.module.css\"\nimport { DateTime } from \"luxon\"\nimport { useMemo } from \"react\"\nimport { useBreakpoint } from \"../../hooks/useBreakpoints\"\nimport { useLatestValue } from \"../../hooks/useLatestValue\"\nimport { isAfter } from \"../../lib/dateUtils\"\nimport { Popover, type PopoverContentProps } from \"../Popover\"\nimport { useCalendarGutter } from \"../DatePicker/useCalendarGutter\"\nimport type { SelectControlProps } from \"../SelectControl\"\nimport { DateRangeCalendar, DateRangeShortcuts } from \"./Calendar\"\nimport { DateRangeContext, type DateRangeContextValue } from \"./context\"\nimport { DateRangeTrigger } from \"./Trigger\"\nimport { type DateRange, type DateRangeShortcut, type WeekStart } from \"./types\"\n\nexport type DateRangePickerProps = {\n /**\n * The selected date range value.\n */\n value: DateRange | null\n /**\n * Handler that is triggered when the date range changes.\n */\n onChange: (nextValue: DateRange | null, shortcut?: DateRangeShortcut) => void\n /**\n * Defines the earliest selectable date (inclusive).\n */\n min?: DateTime\n /**\n * Defines the latest selectable date (inclusive).\n */\n max?: DateTime\n /**\n * Maximum length of the selectable range in days (inclusive).\n * When set, the end date cannot be more than this many days after the start date.\n */\n maxRangeDays?: number\n /**\n * The day each week starts on, from 0 (Sunday) to 6 (Saturday).\n * @default 0\n */\n weekStartsOn?: WeekStart\n /**\n * List of date range shortcuts displayed for quick selection, shown to the left of the calendar.\n * Not shown below the md breakpoint: on a phone, offer them in a row of their own (see the docs).\n */\n shortcuts?: DateRangeShortcut[]\n /**\n * The preferred side of the trigger to render against when open. Will be reversed when collisions occur.\n * On phones, left and right prefer bottom so all seven 44px day targets fit.\n * @default bottom\n */\n side?: PopoverContentProps[\"side\"]\n /**\n * The distance in pixels from the trigger.\n * @default 8\n */\n sideOffset?: PopoverContentProps[\"sideOffset\"]\n /**\n * The preferred alignment against the trigger. May change when collisions occur.\n * @default center\n */\n align?: PopoverContentProps[\"align\"]\n /**\n * An offset in pixels from the \"start\" or \"end\" alignment options.\n * @default 0\n */\n alignOffset?: PopoverContentProps[\"alignOffset\"]\n\n /**\n * Disables the select visually and from interactions\n * @default false\n */\n disabled?: boolean\n /**\n * Placeholder text for the select\n * @default Select date range...\n */\n placeholder?: string\n /**\n * Style variant for the select trigger\n * @default outline\n */\n variant?: SelectControlProps[\"variant\"]\n /**\n * Determines if the select trigger should be a fully rounded pill shape\n * @default true\n */\n pill?: boolean\n /**\n * Determines size of the size and spacing of the control.\n *\n * | 3xs | 2xs | xs | sm | md | lg | xl | 2xl | 3xl |\n * | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- | ------- |\n * | `22px` | `24px` | `26px` | `28px` | `32px` | `36px` | `40px` | `44px` | `48px` |\n * @default md\n */\n size?: SelectControlProps[\"size\"]\n /**\n * Icon displayed in the far right of the select trigger\n * @default dropdown\n */\n dropdownIconType?: SelectControlProps[\"dropdownIconType\"]\n /**\n * Custom class applied to the select trigger\n */\n triggerClassName?: string\n /**\n * Display calendar icon at the start of the trigger\n * @default true\n */\n triggerShowIcon?: boolean\n /**\n * Allows the trigger to display as a stepper when the selected date matches the unit.\n * Currently 'month' is the only supported unit.\n */\n triggerStepperUnit?: \"month\"\n /**\n * Format of dates displayed in the trigger\n * @default \"MM/dd/yy\"\n */\n triggerDateFormat?: string\n /**\n * Display a clear action that allows the select to be unset.\n * @default false\n */\n clearable?: boolean\n /**\n * Extends select to 100% of available width.\n * @default false\n */\n block?: boolean\n}\n\nexport const DateRangePicker = (props: DateRangePickerProps) => {\n const {\n value,\n onChange,\n min,\n max,\n maxRangeDays,\n weekStartsOn = 0,\n shortcuts,\n side = \"bottom\",\n sideOffset = 8,\n align = \"center\",\n alignOffset,\n variant = \"outline\",\n size = \"md\",\n clearable = false,\n disabled = false,\n dropdownIconType,\n placeholder = \"Select date range...\",\n pill = true,\n block = false,\n triggerStepperUnit,\n triggerClassName,\n triggerShowIcon = true,\n triggerDateFormat = \"MM/dd/yy\",\n } = props\n\n // min and max are inclusive, so equal bounds allow one date\n if (min && max && isAfter(min, max)) {\n throw new Error(\"DateRangePicker error: `min` date must not be after the `max` date\")\n }\n\n // Create stable, mutable references to avoid memoization requirements from consumers\n const wide = useBreakpoint(\"md\")\n const calendarGutter = useCalendarGutter()\n const onChangeRef = useLatestValue(onChange)\n\n const store = useMemo<DateRangeContextValue>(\n () => ({\n value,\n min,\n max,\n maxRangeDays,\n weekStartsOn,\n variant,\n size,\n dropdownIconType,\n clearable,\n disabled,\n placeholder,\n block,\n pill,\n shortcuts,\n triggerStepperUnit,\n triggerClassName,\n triggerShowIcon,\n triggerDateFormat,\n onChangeRef,\n }),\n [\n value,\n min,\n max,\n maxRangeDays,\n weekStartsOn,\n variant,\n size,\n dropdownIconType,\n clearable,\n disabled,\n placeholder,\n block,\n pill,\n shortcuts,\n triggerStepperUnit,\n triggerClassName,\n triggerShowIcon,\n triggerDateFormat,\n onChangeRef,\n ],\n )\n\n return (\n <DateRangeContext value={store}>\n <Popover>\n <Popover.Trigger>\n <DateRangeTrigger />\n </Popover.Trigger>\n <Popover.Content\n className={s.Popover}\n minWidth={230}\n collisionPadding={wide ? 20 : calendarGutter}\n side={wide || side === \"top\" ? side : \"bottom\"}\n sideOffset={sideOffset}\n align={align}\n alignOffset={alignOffset ?? (align === \"center\" ? 0 : -5)}\n >\n <div className=\"flex\">\n <DateRangeShortcuts shortcuts={shortcuts} />\n <DateRangeCalendar />\n </div>\n </Popover.Content>\n </Popover>\n </DateRangeContext>\n )\n}\n"]}
|