@sincpro/web-ui 2.11.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -20
- package/dist/components/activity/Messages.d.ts +3 -23
- package/dist/components/activity/Messages.js +3 -17
- package/dist/components/activity/index.d.ts +2 -1
- package/dist/components/activity/index.js +2 -1
- package/dist/components/activity/messageKind.d.ts +23 -0
- package/dist/components/activity/messageKind.js +17 -0
- package/dist/components/assist/assist.d.ts +1 -1
- package/dist/components/assist/assist.js +1 -1
- package/dist/components/frame/model.js +1 -1
- package/dist/components/guide/index.d.ts +2 -1
- package/dist/components/guide/index.js +2 -1
- package/dist/components/guide/selector.d.ts +25 -0
- package/dist/components/guide/selector.js +14 -0
- package/dist/components/guide/target.d.ts +3 -25
- package/dist/components/guide/target.js +2 -14
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/listing/AxisLevels.d.ts +2 -5
- package/dist/components/listing/AxisLevels.js +5 -22
- package/dist/components/listing/BoardColumns.js +10 -6
- package/dist/components/listing/ColumnsMenu.d.ts +3 -7
- package/dist/components/listing/ColumnsMenu.js +4 -8
- package/dist/components/listing/Listing.js +3 -1
- package/dist/components/listing/ListingBar.d.ts +16 -94
- package/dist/components/listing/ListingBar.js +24 -2
- package/dist/components/listing/RecordCard.d.ts +41 -3
- package/dist/components/listing/RecordCard.js +63 -22
- package/dist/components/listing/Row.js +5 -2
- package/dist/components/listing/collapsed.d.ts +2 -0
- package/dist/components/listing/collapsed.js +8 -0
- package/dist/components/listing/columnSpecs.d.ts +34 -0
- package/dist/components/listing/columnSpecs.js +54 -0
- package/dist/components/listing/columns.d.ts +3 -21
- package/dist/components/listing/columns.js +2 -39
- package/dist/components/listing/index.d.ts +11 -7
- package/dist/components/listing/index.js +15 -8
- package/dist/components/listing/levels.d.ts +9 -0
- package/dist/components/listing/levels.js +27 -0
- package/dist/components/listing/pageSizes.d.ts +9 -0
- package/dist/components/listing/pageSizes.js +11 -0
- package/dist/components/listing/pages.d.ts +2 -9
- package/dist/components/listing/pages.js +5 -9
- package/dist/components/listing/set.d.ts +1 -1
- package/dist/components/listing/tree.d.ts +2 -1
- package/dist/components/listing/tree.js +4 -5
- package/dist/components/preview/FilePreview.d.ts +3 -3
- package/dist/components/preview/FilePreview.js +3 -15
- package/dist/components/preview/index.d.ts +2 -1
- package/dist/components/preview/index.js +2 -1
- package/dist/components/preview/previewKind.d.ts +3 -0
- package/dist/components/preview/previewKind.js +17 -0
- package/dist/components/receipt/Receipt.d.ts +51 -0
- package/dist/components/receipt/Receipt.js +23 -0
- package/dist/components/receipt/index.d.ts +1 -0
- package/dist/components/receipt/index.js +3 -0
- package/dist/components/search/CriteriaChips.js +5 -3
- package/dist/components/search/FilterBuilder.d.ts +5 -139
- package/dist/components/search/FilterBuilder.js +5 -579
- package/dist/components/search/JsonEditor.d.ts +2 -8
- package/dist/components/search/JsonEditor.js +5 -15
- package/dist/components/search/RuleValue.d.ts +2 -2
- package/dist/components/search/RuleValue.js +5 -4
- package/dist/components/search/datePeriods.js +1 -1
- package/dist/components/search/filterTree.d.ts +183 -0
- package/dist/components/search/filterTree.js +570 -0
- package/dist/components/search/formatJson.d.ts +8 -0
- package/dist/components/search/formatJson.js +17 -0
- package/dist/components/search/index.d.ts +5 -3
- package/dist/components/search/index.js +7 -3
- package/dist/components/search/query.js +1 -1
- package/dist/components/shell/KioskFrame.d.ts +35 -0
- package/dist/components/shell/KioskFrame.js +39 -0
- package/dist/components/shell/SearchEntry.js +1 -1
- package/dist/components/shell/index.d.ts +1 -0
- package/dist/components/shell/index.js +1 -0
- package/dist/foundations/calendar.js +1 -1
- package/dist/foundations/catalog.d.ts +7 -8
- package/dist/foundations/catalog.js +10 -35
- package/dist/foundations/chart.js +1 -1
- package/dist/foundations/clock.d.ts +3 -0
- package/dist/foundations/clock.js +41 -0
- package/dist/foundations/controlName.d.ts +12 -0
- package/dist/foundations/controlName.js +14 -0
- package/dist/foundations/copy.d.ts +3 -1130
- package/dist/foundations/copy.es.d.ts +1 -1
- package/dist/foundations/copy.es.js +26 -0
- package/dist/foundations/copy.js +13 -747
- package/dist/foundations/copyStore.d.ts +21 -0
- package/dist/foundations/copyStore.js +47 -0
- package/dist/foundations/density.d.ts +4 -8
- package/dist/foundations/density.js +2 -9
- package/dist/foundations/form.d.ts +2 -12
- package/dist/foundations/form.js +4 -14
- package/dist/foundations/idle.d.ts +1 -0
- package/dist/foundations/idle.js +34 -0
- package/dist/foundations/index.d.ts +21 -11
- package/dist/foundations/index.js +28 -11
- package/dist/foundations/keys.d.ts +8 -0
- package/dist/foundations/keys.js +6 -0
- package/dist/foundations/pickBy.d.ts +16 -0
- package/dist/foundations/pickBy.js +17 -0
- package/dist/foundations/pivotSheet.js +0 -0
- package/dist/foundations/pointer.d.ts +25 -0
- package/dist/foundations/pointer.js +28 -0
- package/dist/foundations/shortcut.d.ts +3 -9
- package/dist/foundations/shortcut.js +2 -7
- package/dist/foundations/sticky.d.ts +2 -6
- package/dist/foundations/sticky.js +5 -8
- package/dist/foundations/stickyStyle.d.ts +12 -0
- package/dist/foundations/stickyStyle.js +13 -0
- package/dist/foundations/surface.d.ts +2 -2
- package/dist/foundations/surface.js +4 -2
- package/dist/foundations/theme.d.ts +3 -13
- package/dist/foundations/theme.js +2 -15
- package/dist/foundations/themeChoice.d.ts +19 -0
- package/dist/foundations/themeChoice.js +22 -0
- package/dist/foundations/types.d.ts +3 -0
- package/dist/foundations/uiCopy.d.ts +1173 -0
- package/dist/foundations/uiCopy.js +775 -0
- package/dist/foundations/xlsx.d.ts +4 -10
- package/dist/foundations/xlsx.js +0 -0
- package/dist/foundations/xlsxDownload.d.ts +8 -0
- package/dist/foundations/xlsxDownload.js +28 -0
- package/dist/primitives/button/Button.d.ts +3 -15
- package/dist/primitives/button/Button.js +2 -65
- package/dist/primitives/button/classes.d.ts +21 -0
- package/dist/primitives/button/classes.js +65 -0
- package/dist/primitives/button/index.d.ts +2 -1
- package/dist/primitives/button/index.js +3 -1
- package/dist/primitives/choice/RadioGroup.d.ts +8 -1
- package/dist/primitives/choice/RadioGroup.js +9 -1
- package/dist/primitives/choice/options.d.ts +3 -0
- package/dist/primitives/field/Field.d.ts +2 -6
- package/dist/primitives/field/Field.js +4 -10
- package/dist/primitives/field/Keypad.d.ts +43 -0
- package/dist/primitives/field/Keypad.js +62 -0
- package/dist/primitives/field/Stepper.d.ts +28 -0
- package/dist/primitives/field/Stepper.js +52 -0
- package/dist/primitives/field/classes.d.ts +6 -0
- package/dist/primitives/field/classes.js +13 -0
- package/dist/primitives/field/clipboard.js +1 -1
- package/dist/primitives/field/index.d.ts +5 -1
- package/dist/primitives/field/index.js +9 -1
- package/dist/primitives/field/keypadKeys.d.ts +24 -0
- package/dist/primitives/field/keypadKeys.js +80 -0
- package/dist/primitives/hint/Hint.js +1 -1
- package/dist/primitives/menu/Menu.d.ts +2 -19
- package/dist/primitives/menu/Menu.js +4 -30
- package/dist/primitives/menu/classes.d.ts +18 -0
- package/dist/primitives/menu/classes.js +33 -0
- package/dist/primitives/menu/index.d.ts +2 -1
- package/dist/primitives/menu/index.js +3 -1
- package/dist/primitives/notice/Flag.js +1 -1
- package/dist/primitives/notice/Outcome.d.ts +28 -0
- package/dist/primitives/notice/Outcome.js +28 -0
- package/dist/primitives/notice/index.d.ts +1 -0
- package/dist/primitives/notice/index.js +2 -0
- package/dist/primitives/table/CellCopy.js +1 -1
- package/dist/primitives/table/EditableTable.d.ts +3 -37
- package/dist/primitives/table/EditableTable.js +2 -47
- package/dist/primitives/table/ReportTable.js +1 -1
- package/dist/primitives/table/RowActions.js +1 -1
- package/dist/primitives/table/Table.d.ts +2 -4
- package/dist/primitives/table/Table.js +13 -16
- package/dist/primitives/table/cellTone.d.ts +5 -0
- package/dist/primitives/table/cellTone.js +13 -0
- package/dist/primitives/table/editRules.d.ts +43 -0
- package/dist/primitives/table/editRules.js +53 -0
- package/dist/primitives/table/index.d.ts +4 -2
- package/dist/primitives/table/index.js +4 -2
- package/dist/primitives/tag/Count.d.ts +2 -3
- package/dist/primitives/tag/Count.js +4 -5
- package/dist/primitives/tag/Tags.d.ts +22 -1
- package/dist/primitives/tag/Tags.js +57 -14
- package/dist/primitives/tag/countText.d.ts +3 -0
- package/dist/primitives/tag/countText.js +7 -0
- package/dist/primitives/tag/index.d.ts +3 -2
- package/dist/primitives/tag/index.js +2 -1
- package/dist/primitives/value/DateValue.d.ts +2 -5
- package/dist/primitives/value/DateValue.js +6 -44
- package/dist/primitives/value/Elapsed.d.ts +16 -0
- package/dist/primitives/value/Elapsed.js +37 -0
- package/dist/primitives/value/Meter.d.ts +3 -8
- package/dist/primitives/value/Meter.js +2 -9
- package/dist/primitives/value/RichText.d.ts +2 -4
- package/dist/primitives/value/RichText.js +5 -20
- package/dist/primitives/value/Value.d.ts +10 -7
- package/dist/primitives/value/Value.js +7 -24
- package/dist/primitives/value/elapsedTime.d.ts +26 -0
- package/dist/primitives/value/elapsedTime.js +32 -0
- package/dist/primitives/value/format.d.ts +16 -0
- package/dist/primitives/value/format.js +81 -0
- package/dist/primitives/value/index.d.ts +9 -4
- package/dist/primitives/value/index.js +13 -4
- package/dist/primitives/value/meterLevel.d.ts +10 -0
- package/dist/primitives/value/meterLevel.js +12 -0
- package/dist/primitives/value/richTextPlain.d.ts +4 -0
- package/dist/primitives/value/richTextPlain.js +23 -0
- package/dist/tokens.css +87 -1
- package/dist/views/list/List.d.ts +11 -0
- package/dist/views/list/List.js +14 -3
- package/dist/views/list/ListView.d.ts +1 -1
- package/dist/views/list/ListView.js +26 -6
- package/dist/views/list/types.d.ts +7 -0
- package/dist/views/record/Record.js +1 -1
- package/package.json +1 -1
|
@@ -29,8 +29,9 @@
|
|
|
29
29
|
*
|
|
30
30
|
* `writeXlsx` returns BYTES and not a file: `Uint8Array` exists
|
|
31
31
|
* everywhere, and so the same thing serves to download a file, to send it over the network or
|
|
32
|
-
* to write it in a test. Downloading it is `downloadXlsx`,
|
|
33
|
-
*
|
|
32
|
+
* to write it in a test. Downloading it is `downloadXlsx`, the only piece that needs a
|
|
33
|
+
* browser — so it lives in `xlsxDownload.ts`, with `"use client"`, and this module stays
|
|
34
|
+
* without it: a server component (a route that answers with the file) calls `writeXlsx`.
|
|
34
35
|
*/
|
|
35
36
|
/** A cell. The position goes in the cell and not in a matrix because a grid
|
|
36
37
|
* with holes is mostly empty, and a matrix of 288 positions for 40
|
|
@@ -76,11 +77,4 @@ export type XlsxSheet = {
|
|
|
76
77
|
export declare function columnName(index: number): string;
|
|
77
78
|
/** The bytes of an `.xlsx` with one sheet. */
|
|
78
79
|
export declare function writeXlsx(sheet: XlsxSheet): Uint8Array<ArrayBuffer>;
|
|
79
|
-
|
|
80
|
-
* Download the bytes as a file.
|
|
81
|
-
*
|
|
82
|
-
* It is the only function of this file that needs a browser, and that is why it is
|
|
83
|
-
* separate from `writeXlsx`: what is written and what is downloaded are two things, and
|
|
84
|
-
* on the other side —the server, a phone, a test— the second does not exist.
|
|
85
|
-
*/
|
|
86
|
-
export declare function downloadXlsx(name: string, bytes: Uint8Array): void;
|
|
80
|
+
export { downloadXlsx } from "./xlsxDownload.js";
|
package/dist/foundations/xlsx.js
CHANGED
|
Binary file
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Download the bytes as a file.
|
|
3
|
+
*
|
|
4
|
+
* It is the only piece of the spreadsheet that needs a browser, and that is why it is
|
|
5
|
+
* separate from `writeXlsx` (`xlsx.ts`): what is written and what is downloaded are two
|
|
6
|
+
* things, and on the other side —the server, a phone, a test— the second does not exist.
|
|
7
|
+
*/
|
|
8
|
+
export declare function downloadXlsx(name: string, bytes: Uint8Array): void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
/**
|
|
3
|
+
* Download the bytes as a file.
|
|
4
|
+
*
|
|
5
|
+
* It is the only piece of the spreadsheet that needs a browser, and that is why it is
|
|
6
|
+
* separate from `writeXlsx` (`xlsx.ts`): what is written and what is downloaded are two
|
|
7
|
+
* things, and on the other side —the server, a phone, a test— the second does not exist.
|
|
8
|
+
*/
|
|
9
|
+
export function downloadXlsx(name, bytes) {
|
|
10
|
+
const file = name.endsWith(".xlsx") ? name : `${name}.xlsx`;
|
|
11
|
+
/* A copy, and not the bytes that arrived: a `Blob` only accepts a view
|
|
12
|
+
over a plain `ArrayBuffer`, and what comes through the door might be
|
|
13
|
+
over a shared one. It is a few kilobytes and the alternative is an
|
|
14
|
+
assertion that says it cannot happen. */
|
|
15
|
+
const blob = new Blob([new Uint8Array(bytes)], {
|
|
16
|
+
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
17
|
+
});
|
|
18
|
+
const url = URL.createObjectURL(blob);
|
|
19
|
+
const link = document.createElement("a");
|
|
20
|
+
link.href = url;
|
|
21
|
+
link.download = file;
|
|
22
|
+
link.click();
|
|
23
|
+
/* The URL is released after the click, not before: releasing it in the same turn
|
|
24
|
+
cancels the download in some browsers. */
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
URL.revokeObjectURL(url);
|
|
27
|
+
}, 0);
|
|
28
|
+
}
|
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
import type { Surface } from "../../foundations/types.js";
|
|
2
|
+
import { buttonClasses, type ButtonRole, type ButtonSize } from "./classes.js";
|
|
2
3
|
import { type LucideIcon } from "lucide-react";
|
|
3
4
|
import type { ComponentPropsWithRef, ReactNode } from "react";
|
|
4
|
-
export type ButtonRole = "primary" | "secondary" | "ghost" | "danger";
|
|
5
|
-
export type ButtonSize = "sm" | "md" | "lg";
|
|
6
5
|
export type { Surface };
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
* Size `sm` (12px) on the small button and `md` (16px) on the medium one, with
|
|
10
|
-
* the stroke that belongs to each — see the iconography scale: what stays
|
|
11
|
-
* constant is the optical weight, not the number. */
|
|
12
|
-
/** The look of a button, without the button.
|
|
13
|
-
*
|
|
14
|
-
* Context: it exists because there are things that LOOK like a button and are
|
|
15
|
-
* not — a menu trigger is the case. Without this, each one copies the classes
|
|
16
|
-
* and by the third copy they no longer match: that is exactly what happened
|
|
17
|
-
* with «+ Crear», which was the only primary button in the product with a
|
|
18
|
-
* different height. */
|
|
19
|
-
export declare function buttonClasses(role?: ButtonRole, size?: ButtonSize, surface?: Surface): string;
|
|
6
|
+
export type { ButtonRole, ButtonSize };
|
|
7
|
+
export { buttonClasses };
|
|
20
8
|
/** What kind of thing a trigger opens. `menu` is the default because it is what the
|
|
21
9
|
* `expanded` prop always announced; a `PopoverTrigger` opens a `dialog`, a picker a
|
|
22
10
|
* `listbox`. */
|
|
@@ -59,78 +59,15 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
59
59
|
* it would not be a primitive.
|
|
60
60
|
* ==================================================================== */
|
|
61
61
|
import { useSurface } from "../../foundations/surface.js";
|
|
62
|
+
import { buttonClasses, } from "./classes.js";
|
|
62
63
|
import { Tooltip, TooltipTrigger, useInTooltipTrigger, } from "../overlay/Tooltip.js";
|
|
63
64
|
import { LoaderCircle } from "lucide-react";
|
|
64
|
-
|
|
65
|
-
*
|
|
66
|
-
* sm a row, the header of a block
|
|
67
|
-
* md the working size — the action bar of a record
|
|
68
|
-
* lg a SINGLE, prominent action: a dialog's CTA, an empty state
|
|
69
|
-
*
|
|
70
|
-
* **Every button in the same row measures the same.** `lg` is not «the
|
|
71
|
-
* primary»: it is for when the button is alone. Mixing heights in a bar looks
|
|
72
|
-
* like an alignment mistake, not like hierarchy — and hierarchy is already
|
|
73
|
-
* done by the color and the weight, which work without changing the size of
|
|
74
|
-
* anything.
|
|
75
|
-
*
|
|
76
|
-
* The padding grows FASTER than the height (3 → 4 → 6). A tall, narrow button
|
|
77
|
-
* reads as a stretched icon; what gives it presence is the air on the sides of
|
|
78
|
-
* the label, not the height alone. */
|
|
79
|
-
const SIZE = {
|
|
80
|
-
sm: "h-(--size-control-sm) px-3 gap-1.5 text-meta",
|
|
81
|
-
md: "h-(--size-control-md) px-4 gap-2 text-body",
|
|
82
|
-
lg: "h-(--size-control-lg) px-6 gap-2 text-lead",
|
|
83
|
-
};
|
|
84
|
-
/** The weight per role. See the header note: it is not aesthetics, it is half
|
|
85
|
-
* of the hierarchy — the half that keeps working out of the corner of your
|
|
86
|
-
* eye. */
|
|
87
|
-
const WEIGHT = {
|
|
88
|
-
primary: "font-semibold",
|
|
89
|
-
secondary: "font-medium",
|
|
90
|
-
ghost: "font-medium",
|
|
91
|
-
danger: "font-semibold",
|
|
92
|
-
};
|
|
93
|
-
/** Each role on its two surfaces. The table exists so that adding a third
|
|
94
|
-
* surface is one column here and not an `if` scattered across the tree — and
|
|
95
|
-
* so that the day a combination is missing, the compiler says so. */
|
|
96
|
-
const ROLE = {
|
|
97
|
-
primary: {
|
|
98
|
-
// `btn-accent` is the brand gradient, use 3 of 4. Barely a glint of metal:
|
|
99
|
-
// a strong gradient turns a tool into a landing page.
|
|
100
|
-
canvas: "btn-accent border border-transparent hover:brightness-[1.04] active:brightness-95",
|
|
101
|
-
chrome: "btn-accent border border-transparent hover:brightness-[1.04] active:brightness-95",
|
|
102
|
-
},
|
|
103
|
-
secondary: {
|
|
104
|
-
// Quiet on purpose. The blue belongs to `ghost` (go) and the gold to
|
|
105
|
-
// `primary` (do). A secondary painted in the action color is a second
|
|
106
|
-
// primary, which is the defect this file exists to stop.
|
|
107
|
-
canvas: "border border-line-strong bg-ink/6 text-ink hover:bg-ink/10",
|
|
108
|
-
chrome: "border border-chrome-muted/30 bg-chrome-raised text-chrome-ink hover:bg-chrome-ink/10",
|
|
109
|
-
},
|
|
110
|
-
ghost: {
|
|
111
|
-
canvas: "border border-transparent text-primary hover:bg-primary/8",
|
|
112
|
-
chrome: "border border-transparent text-chrome-link hover:bg-chrome-ink/8",
|
|
113
|
-
},
|
|
114
|
-
danger: {
|
|
115
|
-
canvas: "border border-transparent bg-danger text-surface hover:bg-danger-hover",
|
|
116
|
-
chrome: "border border-transparent bg-danger text-surface hover:bg-danger-hover",
|
|
117
|
-
},
|
|
118
|
-
};
|
|
65
|
+
export { buttonClasses };
|
|
119
66
|
/** The icon accompanies the label and never replaces it.
|
|
120
67
|
*
|
|
121
68
|
* Size `sm` (12px) on the small button and `md` (16px) on the medium one, with
|
|
122
69
|
* the stroke that belongs to each — see the iconography scale: what stays
|
|
123
70
|
* constant is the optical weight, not the number. */
|
|
124
|
-
/** The look of a button, without the button.
|
|
125
|
-
*
|
|
126
|
-
* Context: it exists because there are things that LOOK like a button and are
|
|
127
|
-
* not — a menu trigger is the case. Without this, each one copies the classes
|
|
128
|
-
* and by the third copy they no longer match: that is exactly what happened
|
|
129
|
-
* with «+ Crear», which was the only primary button in the product with a
|
|
130
|
-
* different height. */
|
|
131
|
-
export function buttonClasses(role = "secondary", size = "md", surface = "canvas") {
|
|
132
|
-
return `inline-flex shrink-0 items-center justify-center rounded-ui-button whitespace-nowrap transition-[background-color,border-color,filter,color] duration-(--duration-instant) ease-(--ease-out) disabled:pointer-events-none disabled:opacity-45 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary ${SIZE[size]} ${WEIGHT[role]} ${ROLE[role][surface]}`;
|
|
133
|
-
}
|
|
134
71
|
const ICON = {
|
|
135
72
|
sm: { size: "size-(--size-icon-sm)", stroke: 2 },
|
|
136
73
|
md: { size: "size-(--size-icon-md)", stroke: 1.75 },
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Surface } from "../../foundations/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* THE LOOK OF A BUTTON, as classes — the four roles, the three sizes, the two surfaces. See
|
|
4
|
+
* the long note at the top of `Button.tsx` for why there are four roles and not one more.
|
|
5
|
+
*
|
|
6
|
+
* Context: it lives apart from `Button` because `Button.tsx` carries `"use client"` (a button
|
|
7
|
+
* reads its surface from context), and a React Server Components bundler turns every export
|
|
8
|
+
* of a client module into a client reference: `buttonClasses("primary", "md")` called from a
|
|
9
|
+
* server component returned a reference instead of a class string. Here, without the
|
|
10
|
+
* directive, it is a function anywhere.
|
|
11
|
+
*/
|
|
12
|
+
export type ButtonRole = "primary" | "secondary" | "ghost" | "danger";
|
|
13
|
+
export type ButtonSize = "sm" | "md" | "lg";
|
|
14
|
+
/** The look of a button, without the button.
|
|
15
|
+
*
|
|
16
|
+
* Context: it exists because there are things that LOOK like a button and are
|
|
17
|
+
* not — a menu trigger is the case. Without this, each one copies the classes
|
|
18
|
+
* and by the third copy they no longer match: that is exactly what happened
|
|
19
|
+
* with «+ Crear», which was the only primary button in the product with a
|
|
20
|
+
* different height. */
|
|
21
|
+
export declare function buttonClasses(role?: ButtonRole, size?: ButtonSize, surface?: Surface): string;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** The height comes from `--size-control-*`; the padding and the type follow.
|
|
2
|
+
*
|
|
3
|
+
* sm a row, the header of a block
|
|
4
|
+
* md the working size — the action bar of a record
|
|
5
|
+
* lg a SINGLE, prominent action: a dialog's CTA, an empty state
|
|
6
|
+
*
|
|
7
|
+
* **Every button in the same row measures the same.** `lg` is not «the
|
|
8
|
+
* primary»: it is for when the button is alone. Mixing heights in a bar looks
|
|
9
|
+
* like an alignment mistake, not like hierarchy — and hierarchy is already
|
|
10
|
+
* done by the color and the weight, which work without changing the size of
|
|
11
|
+
* anything.
|
|
12
|
+
*
|
|
13
|
+
* The padding grows FASTER than the height (3 → 4 → 6). A tall, narrow button
|
|
14
|
+
* reads as a stretched icon; what gives it presence is the air on the sides of
|
|
15
|
+
* the label, not the height alone. */
|
|
16
|
+
const SIZE = {
|
|
17
|
+
sm: "h-(--size-control-sm) px-3 gap-1.5 text-meta",
|
|
18
|
+
md: "h-(--size-control-md) px-4 gap-2 text-body",
|
|
19
|
+
lg: "h-(--size-control-lg) px-6 gap-2 text-lead",
|
|
20
|
+
};
|
|
21
|
+
/** The weight per role. See the header note: it is not aesthetics, it is half
|
|
22
|
+
* of the hierarchy — the half that keeps working out of the corner of your
|
|
23
|
+
* eye. */
|
|
24
|
+
const WEIGHT = {
|
|
25
|
+
primary: "font-semibold",
|
|
26
|
+
secondary: "font-medium",
|
|
27
|
+
ghost: "font-medium",
|
|
28
|
+
danger: "font-semibold",
|
|
29
|
+
};
|
|
30
|
+
/** Each role on its two surfaces. The table exists so that adding a third
|
|
31
|
+
* surface is one column here and not an `if` scattered across the tree — and
|
|
32
|
+
* so that the day a combination is missing, the compiler says so. */
|
|
33
|
+
const ROLE = {
|
|
34
|
+
primary: {
|
|
35
|
+
// `btn-accent` is the brand gradient, use 3 of 4. Barely a glint of metal:
|
|
36
|
+
// a strong gradient turns a tool into a landing page.
|
|
37
|
+
canvas: "btn-accent border border-transparent hover:brightness-[1.04] active:brightness-95",
|
|
38
|
+
chrome: "btn-accent border border-transparent hover:brightness-[1.04] active:brightness-95",
|
|
39
|
+
},
|
|
40
|
+
secondary: {
|
|
41
|
+
// Quiet on purpose. The blue belongs to `ghost` (go) and the gold to
|
|
42
|
+
// `primary` (do). A secondary painted in the action color is a second
|
|
43
|
+
// primary, which is the defect this file exists to stop.
|
|
44
|
+
canvas: "border border-line-strong bg-ink/6 text-ink hover:bg-ink/10",
|
|
45
|
+
chrome: "border border-chrome-muted/30 bg-chrome-raised text-chrome-ink hover:bg-chrome-ink/10",
|
|
46
|
+
},
|
|
47
|
+
ghost: {
|
|
48
|
+
canvas: "border border-transparent text-primary hover:bg-primary/8",
|
|
49
|
+
chrome: "border border-transparent text-chrome-link hover:bg-chrome-ink/8",
|
|
50
|
+
},
|
|
51
|
+
danger: {
|
|
52
|
+
canvas: "border border-transparent bg-danger text-surface hover:bg-danger-hover",
|
|
53
|
+
chrome: "border border-transparent bg-danger text-surface hover:bg-danger-hover",
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
/** The look of a button, without the button.
|
|
57
|
+
*
|
|
58
|
+
* Context: it exists because there are things that LOOK like a button and are
|
|
59
|
+
* not — a menu trigger is the case. Without this, each one copies the classes
|
|
60
|
+
* and by the third copy they no longer match: that is exactly what happened
|
|
61
|
+
* with «+ Crear», which was the only primary button in the product with a
|
|
62
|
+
* different height. */
|
|
63
|
+
export function buttonClasses(role = "secondary", size = "md", surface = "canvas") {
|
|
64
|
+
return `inline-flex shrink-0 items-center justify-center rounded-ui-button whitespace-nowrap transition-[background-color,border-color,filter,color] duration-(--duration-instant) ease-(--ease-out) disabled:pointer-events-none disabled:opacity-45 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary ${SIZE[size]} ${WEIGHT[role]} ${ROLE[role][surface]}`;
|
|
65
|
+
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { Button,
|
|
1
|
+
export { Button, ButtonLink, type ButtonLinkProps, type ButtonPopup, type ButtonProps, IconButton, type IconButtonProps, IconLink, type IconLinkProps, type IconTone, } from "./Button.js";
|
|
2
|
+
export { buttonClasses, type ButtonRole, type ButtonSize, } from "./classes.js";
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
/* DO. Four roles, three sizes, two surfaces. */
|
|
2
|
-
export { Button,
|
|
2
|
+
export { Button, ButtonLink, IconButton, IconLink, } from "./Button.js";
|
|
3
|
+
/* The look without the button, without `"use client"`: a server component calls it. */
|
|
4
|
+
export { buttonClasses, } from "./classes.js";
|
|
@@ -14,5 +14,12 @@ export type RadioGroupProps = {
|
|
|
14
14
|
invalid?: boolean;
|
|
15
15
|
/** Forces the mode. By default it inherits the form's: in read mode it draws the label. */
|
|
16
16
|
mode?: FormMode;
|
|
17
|
+
/**
|
|
18
|
+
* `cards` draws each option as a box pressed whole, with its icon — the payment methods of
|
|
19
|
+
* a till, «Comer aquí / Para llevar» on a kiosk, the shipping of a shop: few options, chosen
|
|
20
|
+
* by a finger, where the dot of a list is too small a target. The grid fits as many as the
|
|
21
|
+
* width takes. It is still one radio group: arrows move, one is chosen.
|
|
22
|
+
*/
|
|
23
|
+
look?: "list" | "cards";
|
|
17
24
|
};
|
|
18
|
-
export declare function RadioGroup({ value, onChange, options, orientation, disabled, id: ownId, describedBy: ownDescribedBy, invalid: ownInvalid, mode, }: RadioGroupProps): import("react").JSX.Element;
|
|
25
|
+
export declare function RadioGroup({ value, onChange, options, orientation, disabled, id: ownId, describedBy: ownDescribedBy, invalid: ownInvalid, mode, look, }: RadioGroupProps): import("react").JSX.Element;
|
|
@@ -33,7 +33,7 @@ const mark = tv({
|
|
|
33
33
|
},
|
|
34
34
|
},
|
|
35
35
|
});
|
|
36
|
-
export function RadioGroup({ value, onChange, options, orientation = "vertical", disabled = false, id: ownId, describedBy: ownDescribedBy, invalid: ownInvalid, mode, }) {
|
|
36
|
+
export function RadioGroup({ value, onChange, options, orientation = "vertical", disabled = false, id: ownId, describedBy: ownDescribedBy, invalid: ownInvalid, mode, look = "list", }) {
|
|
37
37
|
const { id, labelledBy, describedBy, invalid } = useFieldIds({
|
|
38
38
|
id: ownId,
|
|
39
39
|
describedBy: ownDescribedBy,
|
|
@@ -41,6 +41,14 @@ export function RadioGroup({ value, onChange, options, orientation = "vertical",
|
|
|
41
41
|
});
|
|
42
42
|
if (useFormMode(mode) === "read")
|
|
43
43
|
return _jsx(ReadValue, { value: labelOf(options, value) });
|
|
44
|
+
if (look === "cards") {
|
|
45
|
+
return (_jsx(AriaRadioGroup, { id: id, "aria-labelledby": labelledBy, "aria-describedby": describedBy, value: value, onChange: (next) => onChange?.(next), isInvalid: invalid, isDisabled: disabled, "data-ui": "radio-group", "data-look": "cards", className: "grid min-w-0 grid-cols-(--grid-tiles-sm) gap-2", children: options.map((o) => {
|
|
46
|
+
const Icon = o.icon;
|
|
47
|
+
return (_jsx(RadioField, { value: o.value, isDisabled: o.disabled, className: "flex min-w-0", children: _jsx(RadioButton, { "data-ui": "radio-group.card", className: ({ isSelected, isFocusVisible, isDisabled }) => `relative flex min-h-(--size-control-lg) w-full min-w-0 cursor-pointer flex-col items-start gap-1 rounded-ui-record-card border p-3 text-left transition-colors duration-(--duration-instant) ${isSelected
|
|
48
|
+
? "border-primary bg-primary/6 ring-1 ring-primary"
|
|
49
|
+
: "border-line-strong bg-surface hover:border-ink/40"} ${isFocusVisible ? "outline-2 outline-offset-2 outline-primary" : ""} ${isDisabled ? "cursor-not-allowed opacity-45" : ""}`, children: (state) => (_jsxs(_Fragment, { children: [_jsx("span", { className: `absolute top-3 right-3 ${mark(state)}`, children: _jsx("span", { className: `size-1.5 rounded-pill bg-surface transition-transform duration-(--duration-instant) ${state.isSelected ? "scale-100" : "scale-0"}` }) }), Icon === undefined ? null : (_jsx(Icon, { "aria-hidden": true, className: `size-(--size-icon-lg) ${state.isSelected ? "text-primary" : "text-muted"}`, strokeWidth: 1.75 })), _jsx("span", { className: "min-w-0 pr-6 text-body font-medium text-ink", children: o.label }), o.description === undefined ? null : (_jsx("span", { className: "min-w-0 text-micro text-muted", children: o.description }))] })) }) }, o.value));
|
|
50
|
+
}) }));
|
|
51
|
+
}
|
|
44
52
|
return (_jsx(AriaRadioGroup, { id: id, "aria-labelledby": labelledBy, "aria-describedby": describedBy, value: value, onChange: (next) => onChange?.(next), orientation: orientation, isInvalid: invalid, isDisabled: disabled,
|
|
45
53
|
/* `py-2` puts the first label on the same line a text input's would sit on, so the
|
|
46
54
|
field does not look shorter than its neighbours in the same row. */
|
|
@@ -12,6 +12,9 @@ export interface ChoiceOption {
|
|
|
12
12
|
/** A second, muted line: what the option IS (a tax id, a city), not a second name. */
|
|
13
13
|
description?: string;
|
|
14
14
|
disabled?: boolean;
|
|
15
|
+
/** Drawn on the option when the choice is shown as cards (`RadioGroup look="cards"`): the
|
|
16
|
+
* card of «Efectivo», «QR», «Tarjeta». Beside the label, never instead of it. */
|
|
17
|
+
icon?: LucideIcon;
|
|
15
18
|
}
|
|
16
19
|
/** One segment of a `SegmentedControl`. The icon goes before the label, never instead of it. */
|
|
17
20
|
export interface SegmentOption {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type FieldIds } from "../../foundations/form.js";
|
|
2
2
|
import { type FormMode } from "../../foundations/form.js";
|
|
3
|
+
import { controlClasses } from "./classes.js";
|
|
3
4
|
import { type FieldNote } from "./note.js";
|
|
4
5
|
import { type Rounding } from "../value/rounding.js";
|
|
5
6
|
import { type ReactNode } from "react";
|
|
@@ -82,12 +83,7 @@ export declare function ReadValue({ value, mono }: {
|
|
|
82
83
|
value: ReactNode;
|
|
83
84
|
mono?: boolean;
|
|
84
85
|
}): import("react").JSX.Element;
|
|
85
|
-
|
|
86
|
-
*
|
|
87
|
-
* It exists as a function and not as a loose class so that a new control cannot
|
|
88
|
-
* be born with another height, another radius or another focus. That was the
|
|
89
|
-
* original defect: every file wrote its own `<input className="…">`. */
|
|
90
|
-
export declare function controlClasses(invalid?: boolean): string;
|
|
86
|
+
export { controlClasses };
|
|
91
87
|
/** What every text control shares: the field's wiring, overridable prop by prop. Exported for
|
|
92
88
|
* the family's other controls (`PasswordInput`, `CardNumberInput`), not from the barrel. */
|
|
93
89
|
export type ControlProps = {
|
|
@@ -7,6 +7,7 @@ import { FieldIdsContext, useFieldIds, } from "../../foundations/form.js";
|
|
|
7
7
|
import { controlName, FormModeProvider, useFormMode, useFormStyle, } from "../../foundations/form.js";
|
|
8
8
|
import { focusRing, tv } from "../../foundations/variants.js";
|
|
9
9
|
import { FieldGroup, listOptionStyles } from "./aria.js";
|
|
10
|
+
import { controlClasses } from "./classes.js";
|
|
10
11
|
import { FieldCopy, useFieldCopy } from "./clipboard.js";
|
|
11
12
|
import { useSheetLayout } from "./layout.js";
|
|
12
13
|
import { describedByOf, NoteCard, NoteFlag, } from "./note.js";
|
|
@@ -151,16 +152,9 @@ export function ReadValue({ value, mono = false }) {
|
|
|
151
152
|
const empty = value === undefined || value === null || value === "";
|
|
152
153
|
return (_jsx("span", { className: `flex min-h-(--size-control-md) min-w-0 items-center text-meta ${empty ? "text-muted italic" : "text-ink"} ${mono ? "font-mono tabular-nums" : ""}`, children: empty ? unset : value }));
|
|
153
154
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
* be born with another height, another radius or another focus. That was the
|
|
158
|
-
* original defect: every file wrote its own `<input className="…">`. */
|
|
159
|
-
export function controlClasses(invalid = false) {
|
|
160
|
-
return `h-(--size-control-md) w-full min-w-0 rounded-ui-control border bg-ui-control px-2.5 text-meta text-ink transition-colors duration-(--duration-instant) placeholder:text-muted focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:bg-ground disabled:text-muted ${invalid
|
|
161
|
-
? "border-danger focus-visible:border-danger focus-visible:outline-danger"
|
|
162
|
-
: "border-ui-control-border focus-visible:border-primary focus-visible:outline-primary"}`;
|
|
163
|
-
}
|
|
155
|
+
/* `controlClasses` is a plain function (`classes.ts`), without the directive, so a server
|
|
156
|
+
component reads it; re-exported so every path that read it here keeps reading it. */
|
|
157
|
+
export { controlClasses };
|
|
164
158
|
/* `aria-describedby` goes on the INPUT and not on React Aria's field: the field adds the ids
|
|
165
159
|
of its own description and error slots, which this system never renders (`Field` draws
|
|
166
160
|
them), and the input's own prop replaces that list with the field's real one. */
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
export type KeypadProps = {
|
|
3
|
+
/** The number being typed, in the machine's form: «1250.5». */
|
|
4
|
+
value: string;
|
|
5
|
+
onChange: (next: string) => void;
|
|
6
|
+
/** Decimals the number takes — `0` for units (no decimal key), `2` for money. */
|
|
7
|
+
decimals?: number;
|
|
8
|
+
/** The key beside the zero: the decimal point (default, unless `decimals` is 0), «00» for a
|
|
9
|
+
* till that types prices in cents, or «±» for an amount that can be negative. */
|
|
10
|
+
extra?: "decimal" | "double-zero" | "sign";
|
|
11
|
+
/** `lg` for a till or a kiosk — keys a thumb hits without looking; `md` beside a form. */
|
|
12
|
+
size?: "md" | "lg";
|
|
13
|
+
/** A wide key under the pad: «Cantidad», «Cobrar» — what the number is FOR. */
|
|
14
|
+
children?: ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* The pad's screen, on top, as a calculator has: what is being typed, big and right-aligned,
|
|
17
|
+
* and what it is («Capuchino · Cant.»). Without it the screen is the application's. `value`
|
|
18
|
+
* is already written for the person (`«12,50»`), the pad does not format it.
|
|
19
|
+
*/
|
|
20
|
+
screen?: {
|
|
21
|
+
label?: ReactNode;
|
|
22
|
+
value: ReactNode;
|
|
23
|
+
};
|
|
24
|
+
/** The pad's accessible name, when no `Field` names it. */
|
|
25
|
+
"aria-label"?: string;
|
|
26
|
+
id?: string;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The on-screen number pad of a till, a kiosk, a scale — the calculator's layout (7 8 9 on
|
|
31
|
+
* top), keys a thumb hits.
|
|
32
|
+
*
|
|
33
|
+
* Context: a cashier types quantities and prices all day on a touch screen with no keyboard,
|
|
34
|
+
* and the phone's numeric keyboard covers half the ticket. The pad is a CONTROL: it edits a
|
|
35
|
+
* value (`value` / `onChange`, the machine's «1250.5»), and what it is for — quantity,
|
|
36
|
+
* discount, price — is the screen's, as a `SegmentedControl` over it. The rules of each key
|
|
37
|
+
* are pure (`applyKey`), the same ones a physical keyboard follows here: with the pad
|
|
38
|
+
* focused, digits, «,» or «.», Backspace, Delete and «-» do what their key does.
|
|
39
|
+
*
|
|
40
|
+
* The decimal key shows the person's separator («,» in Bolivia) but writes «.»: the screen
|
|
41
|
+
* formats, the value travels in one form.
|
|
42
|
+
*/
|
|
43
|
+
export declare function Keypad({ value, onChange, decimals, extra, size, children, "aria-label": ariaLabel, id: ownId, disabled, screen, }: KeypadProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useUiCopy } from "../../foundations/copy.js";
|
|
4
|
+
import { useFieldIds } from "../../foundations/form.js";
|
|
5
|
+
import { buttonClasses } from "../button/classes.js";
|
|
6
|
+
import { applyKey, keyOfKeyboard, } from "./keypadKeys.js";
|
|
7
|
+
import { Delete } from "lucide-react";
|
|
8
|
+
const ROWS = [
|
|
9
|
+
["7", "8", "9"],
|
|
10
|
+
["4", "5", "6"],
|
|
11
|
+
["1", "2", "3"],
|
|
12
|
+
];
|
|
13
|
+
/**
|
|
14
|
+
* The on-screen number pad of a till, a kiosk, a scale — the calculator's layout (7 8 9 on
|
|
15
|
+
* top), keys a thumb hits.
|
|
16
|
+
*
|
|
17
|
+
* Context: a cashier types quantities and prices all day on a touch screen with no keyboard,
|
|
18
|
+
* and the phone's numeric keyboard covers half the ticket. The pad is a CONTROL: it edits a
|
|
19
|
+
* value (`value` / `onChange`, the machine's «1250.5»), and what it is for — quantity,
|
|
20
|
+
* discount, price — is the screen's, as a `SegmentedControl` over it. The rules of each key
|
|
21
|
+
* are pure (`applyKey`), the same ones a physical keyboard follows here: with the pad
|
|
22
|
+
* focused, digits, «,» or «.», Backspace, Delete and «-» do what their key does.
|
|
23
|
+
*
|
|
24
|
+
* The decimal key shows the person's separator («,» in Bolivia) but writes «.»: the screen
|
|
25
|
+
* formats, the value travels in one form.
|
|
26
|
+
*/
|
|
27
|
+
export function Keypad({ value, onChange, decimals, extra = decimals === 0 ? "double-zero" : "decimal", size = "lg", children, "aria-label": ariaLabel, id: ownId, disabled = false, screen, }) {
|
|
28
|
+
const copy = useUiCopy();
|
|
29
|
+
const { id, labelledBy, describedBy } = useFieldIds({ id: ownId });
|
|
30
|
+
const rules = decimals === undefined ? {} : { decimals };
|
|
31
|
+
const press = (key) => onChange(applyKey(value, key, rules));
|
|
32
|
+
const separator = new Intl.NumberFormat(copy.locale).formatToParts(1.5).find((p) => p.type === "decimal")
|
|
33
|
+
?.value ?? ".";
|
|
34
|
+
const onKeyDown = (event) => {
|
|
35
|
+
if (disabled || event.altKey || event.ctrlKey || event.metaKey)
|
|
36
|
+
return;
|
|
37
|
+
const key = keyOfKeyboard(event.key);
|
|
38
|
+
if (key === null)
|
|
39
|
+
return;
|
|
40
|
+
if (key === "decimal" && extra !== "decimal")
|
|
41
|
+
return;
|
|
42
|
+
if (key === "sign" && extra !== "sign")
|
|
43
|
+
return;
|
|
44
|
+
event.preventDefault();
|
|
45
|
+
press(key);
|
|
46
|
+
};
|
|
47
|
+
const keyClass = `${buttonClasses("secondary", size)} w-full font-medium tabular-nums ${size === "lg" ? "h-14 text-title" : "text-lead"}`;
|
|
48
|
+
const key = (k, face, label) => (_jsx("button", { type: "button", disabled: disabled, onClick: () => press(k), ...(label === undefined ? {} : { "aria-label": label }), "data-ui": "keypad.key", className: keyClass, children: face }, k));
|
|
49
|
+
const extraKey = extra === "decimal"
|
|
50
|
+
? key("decimal", separator, copy.keypad.decimal)
|
|
51
|
+
: extra === "sign"
|
|
52
|
+
? key("sign", "±", copy.keypad.sign)
|
|
53
|
+
: key("00", "00");
|
|
54
|
+
return (
|
|
55
|
+
/* A group, not a grid: the keys are reached by Tab in reading order, and the group itself
|
|
56
|
+
takes the physical keyboard while focus is inside it. */
|
|
57
|
+
_jsxs("div", { role: "group", "data-ui": "keypad", "data-size": size, ...(id === undefined ? {} : { id }), ...(labelledBy === undefined
|
|
58
|
+
? { "aria-label": ariaLabel ?? copy.keypad.label }
|
|
59
|
+
: { "aria-labelledby": labelledBy }), ...(describedBy === undefined ? {} : { "aria-describedby": describedBy }), onKeyDown: onKeyDown, className: "grid w-full min-w-0 grid-cols-3 gap-1.5", children: [screen === undefined ? null : (
|
|
60
|
+
/* Live, so a screen reader hears the number as it is typed. */
|
|
61
|
+
_jsxs("div", { "data-ui": "keypad.screen", "aria-live": "polite", className: "col-span-3 flex min-w-0 flex-col items-end rounded-control border border-line bg-ink/4 px-3 py-2", children: [screen.label === undefined ? null : (_jsx("span", { className: "min-w-0 max-w-full truncate text-micro text-muted", children: screen.label })), _jsx("span", { className: "text-display leading-none font-semibold text-ink tabular-nums", children: screen.value })] })), ROWS.flat().map((k) => key(k, k)), extraKey, key("0", "0"), key("backspace", _jsx(Delete, { "aria-hidden": true, className: "size-(--size-icon-lg)" }), copy.keypad.backspace), children === undefined ? null : (_jsx("div", { className: "col-span-3 flex min-w-0", children: children }))] }));
|
|
62
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type ControlProps } from "./Field.js";
|
|
2
|
+
export type StepperProps = Omit<ControlProps, "describedBy" | "invalid"> & {
|
|
3
|
+
value: number;
|
|
4
|
+
onChange: (next: number) => void;
|
|
5
|
+
min?: number;
|
|
6
|
+
max?: number;
|
|
7
|
+
step?: number;
|
|
8
|
+
/** `lg` for a kiosk or a till — targets a thumb hits; `md` in a line of a form or a cart. */
|
|
9
|
+
size?: "md" | "lg";
|
|
10
|
+
/**
|
|
11
|
+
* At the minimum, «−» becomes «remove» (a bin) and calls this: a cart's line goes from 1 to
|
|
12
|
+
* nothing in the same place, the way a shop's and a kiosk's do. Without it, «−» stops at
|
|
13
|
+
* `min`.
|
|
14
|
+
*/
|
|
15
|
+
onRemove?: () => void;
|
|
16
|
+
/** What one unit is called, for the buttons' names: «Quitar un Capuchino». */
|
|
17
|
+
unitLabel?: string;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* A quantity with «−» and «+» — a cart's line, a kiosk's item, the people at a table.
|
|
21
|
+
*
|
|
22
|
+
* Context: `NumberInput` is for typing a number; its small step buttons are for a mouse.
|
|
23
|
+
* On a touch screen a quantity is changed by pressing, not typing: two targets as big as a
|
|
24
|
+
* control, the figure between them in tabular digits so it does not jump. The arrows step it
|
|
25
|
+
* from the keyboard (the group is one stop, a spin button), Home and End go to the limits.
|
|
26
|
+
* With `onRemove`, «−» at the minimum is a bin and takes the line away — no second control.
|
|
27
|
+
*/
|
|
28
|
+
export declare function Stepper({ value, onChange, min, max, step, size, onRemove, unitLabel, id: ownId, disabled, mode, "aria-label": ariaLabel, }: StepperProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { controlName } from "../../foundations/controlName.js";
|
|
4
|
+
import { useUiCopy } from "../../foundations/copy.js";
|
|
5
|
+
import { useFieldIds, useFormMode } from "../../foundations/form.js";
|
|
6
|
+
import { buttonClasses } from "../button/classes.js";
|
|
7
|
+
import { ReadValue } from "./Field.js";
|
|
8
|
+
import { Minus, Plus, Trash2 } from "lucide-react";
|
|
9
|
+
/**
|
|
10
|
+
* A quantity with «−» and «+» — a cart's line, a kiosk's item, the people at a table.
|
|
11
|
+
*
|
|
12
|
+
* Context: `NumberInput` is for typing a number; its small step buttons are for a mouse.
|
|
13
|
+
* On a touch screen a quantity is changed by pressing, not typing: two targets as big as a
|
|
14
|
+
* control, the figure between them in tabular digits so it does not jump. The arrows step it
|
|
15
|
+
* from the keyboard (the group is one stop, a spin button), Home and End go to the limits.
|
|
16
|
+
* With `onRemove`, «−» at the minimum is a bin and takes the line away — no second control.
|
|
17
|
+
*/
|
|
18
|
+
export function Stepper({ value, onChange, min = 0, max, step = 1, size = "md", onRemove, unitLabel, id: ownId, disabled = false, mode, "aria-label": ariaLabel, }) {
|
|
19
|
+
const copy = useUiCopy();
|
|
20
|
+
const { id, labelledBy, describedBy } = useFieldIds({ id: ownId });
|
|
21
|
+
if (useFormMode(mode) === "read")
|
|
22
|
+
return _jsx(ReadValue, { value: value });
|
|
23
|
+
const atMin = value <= min;
|
|
24
|
+
const atMax = max !== undefined && value >= max;
|
|
25
|
+
const removes = atMin && onRemove !== undefined;
|
|
26
|
+
const clamp = (n) => Math.min(max ?? Number.POSITIVE_INFINITY, Math.max(min, n));
|
|
27
|
+
/* «Sumar uno: Capuchino» — the unit after the verb, so a list of steppers is told apart. */
|
|
28
|
+
const named = (verb) => (unitLabel === undefined ? verb : `${verb}: ${unitLabel}`);
|
|
29
|
+
const lower = () => (removes ? onRemove() : onChange(clamp(value - step)));
|
|
30
|
+
const raise = () => onChange(clamp(value + step));
|
|
31
|
+
const onKeyDown = (event) => {
|
|
32
|
+
if (disabled)
|
|
33
|
+
return;
|
|
34
|
+
const keys = {
|
|
35
|
+
ArrowUp: raise,
|
|
36
|
+
ArrowRight: raise,
|
|
37
|
+
ArrowDown: () => !atMin && onChange(clamp(value - step)),
|
|
38
|
+
ArrowLeft: () => !atMin && onChange(clamp(value - step)),
|
|
39
|
+
Home: () => onChange(min),
|
|
40
|
+
...(max === undefined ? {} : { End: () => onChange(max) }),
|
|
41
|
+
};
|
|
42
|
+
const run = keys[event.key];
|
|
43
|
+
if (run === undefined)
|
|
44
|
+
return;
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
run();
|
|
47
|
+
};
|
|
48
|
+
const button = `${buttonClasses("secondary", size === "lg" ? "lg" : "sm")} aspect-square px-0`;
|
|
49
|
+
return (_jsxs("div", { "data-ui": "stepper", "data-size": size, className: "inline-flex min-w-0 items-center gap-1.5", children: [_jsx("button", { type: "button", tabIndex: -1, disabled: disabled || (atMin && !removes), onClick: lower, "aria-label": named(removes ? copy.stepper.remove : copy.stepper.decrease), className: button, children: removes ? (_jsx(Trash2, { "aria-hidden": true, className: "size-(--size-icon-md)" })) : (_jsx(Minus, { "aria-hidden": true, className: "size-(--size-icon-md)" })) }), _jsx("div", { role: "spinbutton", tabIndex: disabled ? -1 : 0, ...(id === undefined ? {} : { id }), "aria-valuenow": value, "aria-valuemin": min, ...(max === undefined ? {} : { "aria-valuemax": max }), ...(labelledBy === undefined
|
|
50
|
+
? { "aria-label": controlName(undefined, ariaLabel, copy.stepper.label) }
|
|
51
|
+
: { "aria-labelledby": labelledBy }), ...(describedBy === undefined ? {} : { "aria-describedby": describedBy }), "aria-disabled": disabled || undefined, onKeyDown: onKeyDown, className: `min-w-8 rounded-control text-center font-semibold text-ink tabular-nums outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary ${size === "lg" ? "text-title" : "text-body"}`, children: value }), _jsx("button", { type: "button", tabIndex: -1, disabled: disabled || atMax, onClick: raise, "aria-label": named(copy.stepper.increase), className: button, children: _jsx(Plus, { "aria-hidden": true, className: "size-(--size-icon-md)" }) })] }));
|
|
52
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The shared look of everything that is written into or chosen from.
|
|
2
|
+
*
|
|
3
|
+
* It exists as a function and not as a loose class so that a new control cannot
|
|
4
|
+
* be born with another height, another radius or another focus. That was the
|
|
5
|
+
* original defect: every file wrote its own `<input className="…">`. */
|
|
6
|
+
export declare function controlClasses(invalid?: boolean): string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* Without `"use client"`: `Field.tsx` carries it (a control reads its field from context), and
|
|
2
|
+
a React Server Components bundler turns every export of a client module into a client
|
|
3
|
+
reference — the class string a server component asked for came back as a reference. */
|
|
4
|
+
/** The shared look of everything that is written into or chosen from.
|
|
5
|
+
*
|
|
6
|
+
* It exists as a function and not as a loose class so that a new control cannot
|
|
7
|
+
* be born with another height, another radius or another focus. That was the
|
|
8
|
+
* original defect: every file wrote its own `<input className="…">`. */
|
|
9
|
+
export function controlClasses(invalid = false) {
|
|
10
|
+
return `h-(--size-control-md) w-full min-w-0 rounded-ui-control border bg-ui-control px-2.5 text-meta text-ink transition-colors duration-(--duration-instant) placeholder:text-muted focus-visible:outline-2 focus-visible:outline-offset-2 disabled:cursor-not-allowed disabled:bg-ground disabled:text-muted ${invalid
|
|
11
|
+
? "border-danger focus-visible:border-danger focus-visible:outline-danger"
|
|
12
|
+
: "border-ui-control-border focus-visible:border-primary focus-visible:outline-primary"}`;
|
|
13
|
+
}
|
|
@@ -66,5 +66,5 @@ export function shownText(root) {
|
|
|
66
66
|
/** The button by a field's label. `scope` is the field's value area. */
|
|
67
67
|
export function FieldCopy({ label, scope, value, }) {
|
|
68
68
|
const ui = useUiCopy();
|
|
69
|
-
return (_jsx("span", { "data-copy-skip": "", className: "inline-flex shrink-0 opacity-0 transition-opacity duration-(--duration-instant) group-hover/field:opacity-100 focus-within:opacity-100
|
|
69
|
+
return (_jsx("span", { "data-copy-skip": "", className: "inline-flex shrink-0 opacity-0 transition-opacity duration-(--duration-instant) group-hover/field:opacity-100 focus-within:opacity-100 touch:opacity-100", children: _jsx(CopyButton, { label: fillCopy(ui.copyable.field, { label }), value: () => value ?? (scope.current === null ? "" : shownText(scope.current)) }) }));
|
|
70
70
|
}
|
|
@@ -5,11 +5,15 @@ export { CodeInput } from "./CodeInput.js";
|
|
|
5
5
|
export { ColorInput } from "./ColorInput.js";
|
|
6
6
|
export { emailHref, isEmail, isUrl, telHref, urlHref, urlLabel, whatsappHref, } from "./contact.js";
|
|
7
7
|
export { EmailInput, PhoneInput, UrlInput, } from "./ContactInputs.js";
|
|
8
|
+
export { Keypad, type KeypadProps } from "./Keypad.js";
|
|
9
|
+
export { applyKey, isKeypadKey, keyOfKeyboard, type KeypadKey, type KeypadRules, } from "./keypadKeys.js";
|
|
10
|
+
export { Stepper, type StepperProps } from "./Stepper.js";
|
|
8
11
|
export { FieldCopyProvider, shownText, useFieldCopy, } from "./clipboard.js";
|
|
9
12
|
export { DropZone, type DropZoneProps } from "./DropZone.js";
|
|
10
13
|
export { formatDuration, parseDuration } from "./duration.js";
|
|
11
14
|
export { DurationInput } from "./DurationInput.js";
|
|
12
|
-
export { controlClasses
|
|
15
|
+
export { controlClasses } from "./classes.js";
|
|
16
|
+
export { DataField, Field, NumberInput, ReadValue, Select, type SelectOption, TextArea, TextInput, } from "./Field.js";
|
|
13
17
|
export { type ImageChange, ImageInput } from "./ImageInput.js";
|
|
14
18
|
export { type FieldLayout, FieldLayoutProvider, useSheetLayout, } from "./layout.js";
|
|
15
19
|
export { PasswordInput } from "./PasswordInput.js";
|