@donotdev/components 0.2.3 → 0.3.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/CarouselContent-5W2E2F2I.js +1 -0
- package/dist/CarouselContent-EELYAALW.js +1 -0
- package/dist/CodeContent-7FWYPAB3.js +2 -0
- package/dist/CodeContent-E3HLW6BW.js +2 -0
- package/dist/advanced/Carousel/Carousel.d.ts +6 -4
- package/dist/advanced/Carousel/Carousel.d.ts.map +1 -1
- package/dist/advanced/Carousel/Carousel.js +10 -8
- package/dist/advanced/Carousel/CarouselContent.d.ts +35 -3
- package/dist/advanced/Carousel/CarouselContent.d.ts.map +1 -1
- package/dist/advanced/Carousel/CarouselContent.js +103 -67
- package/dist/advanced/Carousel/CarouselSkeleton.d.ts +3 -1
- package/dist/advanced/Carousel/CarouselSkeleton.d.ts.map +1 -1
- package/dist/advanced/Carousel/CarouselSkeleton.js +2 -2
- package/dist/atomic/ActionButton/index.d.ts +1 -1
- package/dist/atomic/ActionButton/index.js +1 -1
- package/dist/atomic/Alert/index.d.ts +1 -1
- package/dist/atomic/Badge/index.d.ts +1 -1
- package/dist/atomic/Button/index.d.ts +30 -1
- package/dist/atomic/Button/index.d.ts.map +1 -1
- package/dist/atomic/Button/index.js +38 -1
- package/dist/atomic/Card/index.d.ts +8 -2
- package/dist/atomic/Card/index.d.ts.map +1 -1
- package/dist/atomic/Card/index.js +19 -3
- package/dist/atomic/Collapsible/index.d.ts +7 -1
- package/dist/atomic/Collapsible/index.d.ts.map +1 -1
- package/dist/atomic/Collapsible/index.js +8 -3
- package/dist/atomic/Combobox/index.d.ts +11 -1
- package/dist/atomic/Combobox/index.d.ts.map +1 -1
- package/dist/atomic/Combobox/index.js +25 -9
- package/dist/atomic/DatePicker/index.d.ts +3 -1
- package/dist/atomic/DatePicker/index.d.ts.map +1 -1
- package/dist/atomic/DatePicker/index.js +2 -2
- package/dist/atomic/DateTimePicker/index.d.ts +3 -1
- package/dist/atomic/DateTimePicker/index.d.ts.map +1 -1
- package/dist/atomic/DateTimePicker/index.js +2 -2
- package/dist/atomic/HeroSection/index.d.ts +1 -1
- package/dist/atomic/Input/index.d.ts +3 -1
- package/dist/atomic/Input/index.d.ts.map +1 -1
- package/dist/atomic/Input/index.js +3 -3
- package/dist/atomic/Label/FieldInfo.d.ts +18 -0
- package/dist/atomic/Label/FieldInfo.d.ts.map +1 -0
- package/dist/atomic/Label/FieldInfo.js +34 -0
- package/dist/atomic/Label/FloatingLabel.d.ts +6 -1
- package/dist/atomic/Label/FloatingLabel.d.ts.map +1 -1
- package/dist/atomic/Label/FloatingLabel.js +6 -2
- package/dist/atomic/Label/index.d.ts +1 -0
- package/dist/atomic/Label/index.d.ts.map +1 -1
- package/dist/atomic/Label/index.js +1 -0
- package/dist/atomic/PasswordInput/index.d.ts +3 -1
- package/dist/atomic/PasswordInput/index.d.ts.map +1 -1
- package/dist/atomic/PasswordInput/index.js +2 -2
- package/dist/atomic/PinInput/index.d.ts +3 -1
- package/dist/atomic/PinInput/index.d.ts.map +1 -1
- package/dist/atomic/PinInput/index.js +2 -2
- package/dist/atomic/QuantityStepper/index.d.ts +19 -4
- package/dist/atomic/QuantityStepper/index.d.ts.map +1 -1
- package/dist/atomic/QuantityStepper/index.js +208 -5
- package/dist/atomic/QuantityStepper/quantity.d.ts +14 -0
- package/dist/atomic/QuantityStepper/quantity.d.ts.map +1 -0
- package/dist/atomic/QuantityStepper/quantity.js +35 -0
- package/dist/atomic/RangeInput/index.d.ts +3 -1
- package/dist/atomic/RangeInput/index.d.ts.map +1 -1
- package/dist/atomic/RangeInput/index.js +2 -2
- package/dist/atomic/Rating/index.d.ts +1 -1
- package/dist/atomic/Select/index.d.ts +3 -1
- package/dist/atomic/Select/index.d.ts.map +1 -1
- package/dist/atomic/Select/index.js +2 -2
- package/dist/atomic/Stepper/index.d.ts +1 -1
- package/dist/atomic/SwipeAction/gesture.d.ts +5 -0
- package/dist/atomic/SwipeAction/gesture.d.ts.map +1 -0
- package/dist/atomic/SwipeAction/gesture.js +10 -0
- package/dist/atomic/SwipeAction/index.d.ts +14 -0
- package/dist/atomic/SwipeAction/index.d.ts.map +1 -0
- package/dist/atomic/SwipeAction/index.js +67 -0
- package/dist/atomic/Table/editing.d.ts +3 -1
- package/dist/atomic/Table/editing.d.ts.map +1 -1
- package/dist/atomic/Table/editing.js +9 -6
- package/dist/atomic/Table/index.d.ts +9 -1
- package/dist/atomic/Table/index.d.ts.map +1 -1
- package/dist/atomic/Table/index.js +64 -48
- package/dist/atomic/Tabs/index.d.ts +1 -1
- package/dist/atomic/Tag/index.d.ts +3 -1
- package/dist/atomic/Tag/index.d.ts.map +1 -1
- package/dist/atomic/Tag/index.js +2 -2
- package/dist/atomic/Toaster/ToastPrimitive.d.ts +2 -2
- package/dist/atomic/Toaster/ToastPrimitive.d.ts.map +1 -1
- package/dist/atomic/Toggle/index.d.ts +1 -1
- package/dist/atomic/index.d.ts +6 -3
- package/dist/atomic/index.d.ts.map +1 -1
- package/dist/atomic/index.js +3 -1
- package/dist/chunk-SZNEXFUZ.js +3 -0
- package/dist/chunk-XK52GUFA.js +3 -0
- package/dist/hooks/useIntersectionObserver.d.ts +2 -1
- package/dist/hooks/useIntersectionObserver.d.ts.map +1 -1
- package/dist/hooks/useIntersectionObserver.js +6 -7
- package/dist/index.js +10 -10
- package/dist/styles/index.css +277 -45
- package/dist/symbol-index.json +1 -1
- package/dist/utils/sanitizeDom.browser.d.ts +8 -0
- package/dist/utils/sanitizeDom.browser.d.ts.map +1 -0
- package/dist/utils/sanitizeDom.browser.js +1 -0
- package/dist/utils/sanitizeDom.server.d.ts +9 -0
- package/dist/utils/sanitizeDom.server.d.ts.map +1 -0
- package/dist/utils/sanitizeDom.server.js +1 -0
- package/dist/utils/sanitizeHtml.d.ts.map +1 -1
- package/dist/utils/sanitizeHtml.js +7 -6
- package/dist/utils/variants.d.ts +1 -1
- package/guidelines/API_REFERENCE.md +3 -2
- package/guidelines/COMPONENTS.md +9 -4
- package/guidelines/QUANTITY_STEPPER.md +78 -0
- package/guidelines/SWIPE_ACTION.md +111 -0
- package/package.json +8 -2
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DOMPurify as Purifier } from 'dompurify';
|
|
2
|
+
/**
|
|
3
|
+
* DOMPurify bound to the page's `window`.
|
|
4
|
+
*
|
|
5
|
+
* @returns The DOMPurify instance (`isSupported` is false without a DOM)
|
|
6
|
+
*/
|
|
7
|
+
export declare function getPurifier(): Purifier;
|
|
8
|
+
//# sourceMappingURL=sanitizeDom.browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizeDom.browser.d.ts","sourceRoot":"","sources":["../../src/utils/sanitizeDom.browser.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,SAAS,IAAI,QAAQ,EAAE,MAAM,WAAW,CAAC;AAEvD;;;;GAIG;AACH,wBAAgB,WAAW,IAAI,QAAQ,CAEtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import r from"dompurify";function f(){return r}export{f as getPurifier};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { DOMPurify as Purifier } from 'dompurify';
|
|
2
|
+
/**
|
|
3
|
+
* DOMPurify bound to a jsdom window, created on the first call: a render that never
|
|
4
|
+
* sanitizes never builds the DOM.
|
|
5
|
+
*
|
|
6
|
+
* @returns The DOMPurify instance
|
|
7
|
+
*/
|
|
8
|
+
export declare function getPurifier(): Purifier;
|
|
9
|
+
//# sourceMappingURL=sanitizeDom.server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizeDom.server.d.ts","sourceRoot":"","sources":["../../src/utils/sanitizeDom.server.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,SAAS,IAAI,QAAQ,EAAc,MAAM,WAAW,CAAC;AAKnE;;;;;GAKG;AACH,wBAAgB,WAAW,IAAI,QAAQ,CAGtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import r from"dompurify";import{JSDOM as e}from"jsdom";var i;function n(){return i??(i=r(new e("").window)),i}export{n as getPurifier};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitizeHtml.d.ts","sourceRoot":"","sources":["../../src/utils/sanitizeHtml.ts"],"names":[],"mappings":"AAmBA,iFAAiF;AACjF,MAAM,WAAW,mBAAmB;IAClC,0EAA0E;IAC1E,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,sCAAsC;IACtC,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,mBAAwB,GAChC,MAAM,
|
|
1
|
+
{"version":3,"file":"sanitizeHtml.d.ts","sourceRoot":"","sources":["../../src/utils/sanitizeHtml.ts"],"names":[],"mappings":"AAmBA,iFAAiF;AACjF,MAAM,WAAW,mBAAmB;IAClC,0EAA0E;IAC1E,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,sCAAsC;IACtC,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,mBAAwB,GAChC,MAAM,CAgBR"}
|
|
@@ -4,16 +4,16 @@
|
|
|
4
4
|
* @description XSS-safe HTML sanitization for content rendered with
|
|
5
5
|
* `dangerouslySetInnerHTML` or parsed into React.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* DOMPurify from `@donotdev/components/sanitize-dom`, resolved by export condition:
|
|
8
|
+
* in the browser it runs on the real DOM (`sanitizeDom.browser.ts`); everywhere else
|
|
9
|
+
* (SSR, server components, tests) on jsdom (`sanitizeDom.server.ts`), the server setup
|
|
10
|
+
* DOMPurify recommends.
|
|
11
11
|
*
|
|
12
|
-
* @version 0.
|
|
12
|
+
* @version 0.3.0
|
|
13
13
|
* @since 0.0.1
|
|
14
14
|
* @author AMBROISE PARK Consulting
|
|
15
15
|
*/
|
|
16
|
-
import
|
|
16
|
+
import { getPurifier } from '@donotdev/components/sanitize-dom';
|
|
17
17
|
/**
|
|
18
18
|
* Sanitize untrusted HTML. Removes scripts, event handlers, `javascript:` /
|
|
19
19
|
* `data:` URIs, and every tag or attribute outside the allowlist.
|
|
@@ -27,6 +27,7 @@ import DOMPurify from 'isomorphic-dompurify';
|
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
29
|
export function sanitizeHtml(html, options = {}) {
|
|
30
|
+
const DOMPurify = getPurifier();
|
|
30
31
|
if (!DOMPurify.isSupported) {
|
|
31
32
|
throw new Error('sanitizeHtml: no DOM implementation available, refusing to return unsanitized HTML');
|
|
32
33
|
}
|
package/dist/utils/variants.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { type VariantProps } from 'class-variance-authority';
|
|
|
9
9
|
* Used by: Card, DualCard, StackedCards, Dialog, Sheet, Alert
|
|
10
10
|
*/
|
|
11
11
|
export declare const surfaceVariants: (props?: ({
|
|
12
|
-
variant?: "default" | "muted" | "
|
|
12
|
+
variant?: "default" | "muted" | "primary" | "secondary" | "accent" | "success" | "warning" | "destructive" | "outline" | "glass" | null | undefined;
|
|
13
13
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
14
14
|
/** CVA variant props for surface components (Card, DualCard, etc.). */
|
|
15
15
|
export type SurfaceVariantProps = VariantProps<typeof surfaceVariants>;
|
|
@@ -73,6 +73,7 @@
|
|
|
73
73
|
<Card title="Title">children</Card>
|
|
74
74
|
<Card onClick={fn}>children</Card>
|
|
75
75
|
```
|
|
76
|
+
`onClick` card: `role="button"`, focusable, Enter/Space activate (keep other interactive controls out; use `href` for navigation).
|
|
76
77
|
| Prop | Type | Default |
|
|
77
78
|
|------|------|---------|
|
|
78
79
|
| variant | `'default'` \| `'muted'` \| `'primary'` \| `'secondary'` \| `'accent'` | `'default'` |
|
|
@@ -176,8 +177,8 @@
|
|
|
176
177
|
|------|------|---------|
|
|
177
178
|
| entity | `Entity` | required |
|
|
178
179
|
| operation | `'create'` \| `'edit'` | `'create'` |
|
|
179
|
-
| onSubmit | `(data) => void` |
|
|
180
|
-
| defaultValues | `Record<string, unknown>` | - |
|
|
180
|
+
| onSubmit | `(data) => void` (data = the fields the form writes) | - (default writer: record + joined child rows) |
|
|
181
|
+
| defaultValues | `Record<string, unknown>` (edit: the stored row as read) | - |
|
|
181
182
|
| loading | `boolean` | `false` |
|
|
182
183
|
| submitText | `string` | - |
|
|
183
184
|
| cancelText | `string` | - |
|
package/guidelines/COMPONENTS.md
CHANGED
|
@@ -36,22 +36,26 @@ These are the only ways one should handle layout to get to quick results functio
|
|
|
36
36
|
|
|
37
37
|
- **Button** - Accessible button with variants, icons, tooltips, and render prop composition.
|
|
38
38
|
- **ActionButton** - Button with async action handling and loading states.
|
|
39
|
+
- **Button `intent`** (`Button`, `ActionButton`) - `intent="save" | "publish" | "unpublish" | "delete" | "preview" | "reload" | "add" | "edit" | "cancel"` (`BUTTON_INTENT`) sets the action's icon, and `delete` the destructive variant; an explicit `icon` or `variant` wins. With the default `display` (auto), phones show the icon only. Equal-width action bar: a `Grid` with one column per button and `fullWidth` buttons.
|
|
39
40
|
- **FileButton** - Button that triggers file input selection.
|
|
40
41
|
- **PortalButton** - Button that opens content in a portal overlay.
|
|
41
42
|
- **ButtonGroup** - Visual grouping of buttons with joined borders. Supports horizontal/vertical orientation, variant propagation, and items-based API.
|
|
43
|
+
- **SwipeAction** - Swipe-to-reveal trailing destructive action with a keyboard-accessible toggle; only explicit action-button activation invokes `onAction`. Exported with `SwipeActionProps` from `@donotdev/components`. Supply translated `actionLabel`, `revealLabel`, and `closeLabel`. See [SwipeAction](./SWIPE_ACTION.md).
|
|
42
44
|
|
|
43
45
|
---
|
|
44
46
|
|
|
45
47
|
## Form Components
|
|
46
48
|
|
|
47
49
|
- **Input** - Accessible input with mobile-friendly touch targets and key state styling.
|
|
50
|
+
- **QuantityStepper** - Controlled lot-aware quantity editor via `onChange`, or legacy increment/decrement callbacks. Supports zero, collapsed presentation, and vertical orientation. Editable mode requires safe-integer lot bounds and a valid controlled quantity; reconcile invalid persisted quantities before enabling it. See [QuantityStepper](./QUANTITY_STEPPER.md).
|
|
48
51
|
- **PasswordInput** - Password field with show/hide toggle functionality.
|
|
49
52
|
- **Textarea** - Multi-line text input component.
|
|
50
53
|
- **Label** - Accessible label with icon support and various positions.
|
|
54
|
+
- **Field help (`info`)** - Opt-in: `info="…"` on `Input`, `PasswordInput`, `Select`, `Combobox`, `DatePicker`, `DateTimePicker`, `RangeInput`, `PinInput` or `FloatingLabel` (needs `label`) adds an (i) after the label; hover or keyboard focus shows the text, a tap pins it on touch screens. Without `info`, nothing is rendered. For a label you render yourself, place `<FieldInfo text="…" />` next to it.
|
|
51
55
|
- **Checkbox** - Accessible checkbox with custom styling.
|
|
52
56
|
- **RadioGroup** - Accessible radio group with multiple visual variants.
|
|
53
57
|
- **Select** - Accessible select dropdown with search and multi-select support.
|
|
54
|
-
- **Combobox** - Searchable combobox with autocomplete functionality.
|
|
58
|
+
- **Combobox** - Searchable combobox with autocomplete functionality. `multiple` without `chips` shows the selection: one value's label, `selectedLabel` (`{{count}}` = count, default `'{{count}} selected'`) for several. `clearLabel`: clear button label (default `'Clear'`).
|
|
55
59
|
- **Switch** - Toggle switch component.
|
|
56
60
|
- **Slider** - Range slider for numeric input.
|
|
57
61
|
- **ColorPicker** - Color selection with preset swatch grid, native color input, and ARIA radiogroup pattern. Built-in palettes: basic, material, pastel.
|
|
@@ -96,11 +100,11 @@ These are the only ways one should handle layout to get to quick results functio
|
|
|
96
100
|
## Data Display Components
|
|
97
101
|
|
|
98
102
|
- **Table** - Accessible table component with sorting and selection.
|
|
99
|
-
- **DataTable** - High-level table with built-in sorting, filtering, search, and pagination. `editable` (+ `getRowId`, `pendingChanges`, `onPendingChange`) edits the columns that declare `edit: { type: 'text' | 'number' | 'select', options }` in place: checked rows take one value from the bulk bar, Excel blocks paste across cells, Enter / arrows move, Esc cancels, Ctrl+Z undoes. The table never saves; the consumer writes `pendingChanges`.
|
|
103
|
+
- **DataTable** - High-level table with built-in sorting, filtering, search, and pagination. `editable` (+ `getRowId`, `pendingChanges`, `onPendingChange`) edits the columns that declare `edit: { type: 'text' | 'number' | 'select', options }` in place: checked rows take one value from the bulk bar, Excel blocks paste across cells, Enter / arrows move, Esc cancels, Ctrl+Z undoes. The table never saves; the consumer writes `pendingChanges`. `cellErrors={{ [rowId]: { [columnKey]: message } }}` (+ `getRowId`, translated messages) marks cells that break a rule, like a value that does not parse: `data-invalid`, editors `aria-invalid` + `aria-describedby` to the message shown under the value (read-only cells show the message too).
|
|
100
104
|
- **Card / ImageGallery images** - Pass the `{ fullUrl, thumbUrl }` pair (CRUD `Picture`) as `cover` / `coverHover` / `images`: phones (below 768px) download the thumbnail, larger screens the full image (`<picture>`). No width props.
|
|
101
105
|
- **Avatar** - Accessible avatar with image and fallback support.
|
|
102
106
|
- **Badge** - Status indicator with semantic variants (polymorphic: div, span, mark).
|
|
103
|
-
- **Tag** - Tag component for labels and categories.
|
|
107
|
+
- **Tag** - Tag component for labels and categories. `removeLabel`: remove button label (default `'Remove'`).
|
|
104
108
|
- **Calendar** - Accessible date picker built on react-day-picker.
|
|
105
109
|
|
|
106
110
|
---
|
|
@@ -157,7 +161,8 @@ import { Link } from '@donotdev/ui';
|
|
|
157
161
|
/>
|
|
158
162
|
</Link>
|
|
159
163
|
|
|
160
|
-
// Card with onClick only (no middle-click support)
|
|
164
|
+
// Card with onClick only (no middle-click support).
|
|
165
|
+
// Renders role="button", focusable; Enter/Space activate. Use href for navigation cards.
|
|
161
166
|
<Card
|
|
162
167
|
title="Action Card"
|
|
163
168
|
onClick={() => handleAction()}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# QuantityStepper
|
|
2
|
+
|
|
3
|
+
Standalone cart/catalogue quantity control. Caller owns `value`; no internal quantity state or per-keystroke React updates.
|
|
4
|
+
|
|
5
|
+
**Press and hold** − / + to repeat: first repeat after 400 ms, then every 150 ms, faster after 5 and 15 repeats; stops at the bounds. Editable mode steps a draft in the DOM and calls `onChange` **once** on release (one save, not one per tick); a click following a repeating hold is not applied twice. Legacy mode calls `onIncrement` / `onDecrement` per repeat. Long press opens no touch callout or text selection.
|
|
6
|
+
|
|
7
|
+
## Editable mode
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
<QuantityStepper
|
|
11
|
+
value={quantity}
|
|
12
|
+
onChange={setQuantity}
|
|
13
|
+
min={3}
|
|
14
|
+
step={4}
|
|
15
|
+
max={14}
|
|
16
|
+
allowZero
|
|
17
|
+
collapseWhenZero
|
|
18
|
+
aria-label={t('cart.quantity')}
|
|
19
|
+
decrementLabel={t('cart.removeLot')}
|
|
20
|
+
incrementLabel={t('cart.addLot')}
|
|
21
|
+
valueLabel={t('cart.editQuantity')}
|
|
22
|
+
/>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
For vertical controls, add `vertical`: **plus above quantity above minus**, including DOM/tab order. Default horizontal order: minus, quantity, plus.
|
|
26
|
+
|
|
27
|
+
### API
|
|
28
|
+
|
|
29
|
+
| Prop | Default | Behavior |
|
|
30
|
+
| --- | --- | --- |
|
|
31
|
+
| `value: number` | required | Controlled committed quantity. |
|
|
32
|
+
| `onChange?: (value: number) => void` | absent | Enables editable mode. Takes precedence over `onIncrement`, `onDecrement`, and `onValueClick`. |
|
|
33
|
+
| `min?: number` | `1` | First positive lot. Positive safe integer. |
|
|
34
|
+
| `step?: number` | `1` | Positive safe-integer lot size. |
|
|
35
|
+
| `max?: number` | `Number.MAX_SAFE_INTEGER` | Safe integer at least `min`; effective maximum rounds down to a complete lot. |
|
|
36
|
+
| `allowZero?: boolean` | `false` | Allows committing zero, separate from positive lots. |
|
|
37
|
+
| `collapseWhenZero?: boolean` | `false` | At zero, shows a large accessible plus, reserving the entire expanded footprint. |
|
|
38
|
+
| `vertical?: boolean` | `false` | Plus, quantity, minus stacked; changes visual and keyboard traversal order. |
|
|
39
|
+
| `disabled?: boolean` | `false` | Disables all controls. |
|
|
40
|
+
| `fullWidth?: boolean` | `false` | Fills available inline width, horizontal or vertical. |
|
|
41
|
+
| `aria-label: string` | required | Accessible group name; also the editor name unless `valueLabel` is supplied. |
|
|
42
|
+
| `decrementLabel: string` | required | Accessible minus name. |
|
|
43
|
+
| `incrementLabel: string` | required | Accessible plus name, including collapsed state. |
|
|
44
|
+
| `valueLabel?: string` | absent | Accessible editor or legacy clickable-value name. |
|
|
45
|
+
| `className` / div attributes | absent | Applied to the group. Component owns group role and state attributes. |
|
|
46
|
+
|
|
47
|
+
### Validation and commits
|
|
48
|
+
|
|
49
|
+
- Valid positive quantities: `min + k * step`, for nonnegative integer `k`.
|
|
50
|
+
- Typed quantities round **up** to a complete lot, then clamp to the effective maximum (rounded **down**). Example: `min=3, step=4, max=14` permits `3, 7, 11`; typing `8` commits `11`.
|
|
51
|
+
- `allowZero` adds `0`; positive values below `min` normalize to `min`.
|
|
52
|
+
- Zero is accepted as an initial/external not-yet-added sentinel even without `allowZero`. Plus starts at `min`. Without `allowZero`, decrementing a positive quantity never removes it.
|
|
53
|
+
- Configuration and controlled values must be safe integers. Invalid configuration, negative/fractional/nonfinite controlled values, or positive controlled values outside the lot lattice/bounds throw `RangeError`. Bounds apply to editable mode only; legacy callbacks retain their own rules.
|
|
54
|
+
- Editor is a native **uncontrolled text input**, `inputMode="numeric"`, with spinbutton semantics. Bulk typing/paste stays in the DOM. Leaving the control group or Enter commits; Escape reverts. Moving focus from the editor to a direction button preserves the draft; activating that button applies its step to the draft in a single callback, including with an asynchronous parent. Enter does not submit an enclosing form. Repeated blur after Enter does not duplicate a commit.
|
|
55
|
+
- While typing, DOM `aria-valuenow` reflects the displayed numeric draft, not a stale committed value. Out-of-range/off-lot drafts expose `aria-invalid`; malformed/empty drafts omit the numeric value. Commit, Escape and parent updates restore both visual and accessible state without per-keystroke React state.
|
|
56
|
+
- Only decimal integer text is accepted (surrounding whitespace allowed). Empty, signed, fractional, scientific notation, nonfinite, unsafe integers, and malformed input revert without a callback. No `NaN` commits.
|
|
57
|
+
- Arrow Up/Down moves one lot; Page Up/Down moves ten lots; Home selects zero when permitted, otherwise `min`; End selects the effective maximum. Text-editing shortcuts and composition are preserved.
|
|
58
|
+
- Changes emit only when different from `value`. The parent must accept by updating `value`; until then the editor returns to the controlled quantity. External value changes synchronize the editor. Unrelated rerenders preserve an in-progress draft.
|
|
59
|
+
|
|
60
|
+
## Legacy mode (unchanged)
|
|
61
|
+
|
|
62
|
+
Without `onChange`, `onIncrement?: () => void` and `onDecrement?: () => void` drive the buttons. An omitted callback disables that direction. The quantity is a live output, or a button when `onValueClick?: () => void` is provided. Caller owns bounds, lots, and all arithmetic. Existing value-click and disabled/fullWidth behavior is retained. New collapse/vertical options also work in legacy mode.
|
|
63
|
+
|
|
64
|
+
## Accessibility, layout, SSR
|
|
65
|
+
|
|
66
|
+
Supply localized labels. All enabled visible buttons and the editor are keyboard reachable; boundary buttons are natively disabled outside an editing session. While editing, directions stay reachable to apply a step to a replacement draft, even when the controlled value is at a bound. Hidden collapsed controls leave the accessibility tree and tab order. The same plus DOM node survives expansion/collapse; collapsing while the editor/minus has focus transfers focus to plus, without stealing focus from outside the group.
|
|
67
|
+
|
|
68
|
+
Touch targets use `max(var(--touch-target), 44px)`. Density/theme tokens drive size, spacing, icons, borders, and focus. The expanded grid footprint is reserved in both states, horizontal and vertical: collapse never removes its grid tracks. Cell sizing includes the larger collapsed icon, inherited line height, and padding before grid placement; fixed block tracks prevent intrinsic icon sizing from changing the footprint. Enlarged text can grow cells without clipping. The same sizing applies on mobile, tablet, and desktop; `fullWidth` stretches the available inline space without reducing target sizes. Reduced-motion users receive no button transition. Native buttons are `type="button"`; the only timers are the press-and-hold repeat, cleared on release, disable and unmount; no browser globals during render or SSR-only branches.
|
|
69
|
+
|
|
70
|
+
CSS is loaded by the existing component stylesheet import and framework styles index; no new export or style-index entries are required.
|
|
71
|
+
|
|
72
|
+
## Regression tests
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
bun test packages/components/src/atomic/QuantityStepper/__tests__/quantity.test.ts packages/components/src/atomic/QuantityStepper/__tests__/QuantityStepper.dom.test.tsx
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
DOM tests use `bun:test`, Happy DOM, and React `act`, exercising the actual component rather than a mock. They cover legacy value-button focus across collapse/expansion, horizontal and vertical, and guard the shared sizing, focus-visible, and enabled-only hover CSS. Happy DOM does not measure layout; browser regressions must verify equal collapsed/expanded bounds, fullWidth, enlarged text, and target sizes across mobile/tablet/desktop.
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# SwipeAction
|
|
2
|
+
|
|
3
|
+
Standalone cart-row swipe-to-reveal control. Swiping **never invokes `onAction`**.
|
|
4
|
+
Only explicit activation of the revealed trash button invokes it.
|
|
5
|
+
|
|
6
|
+
## API
|
|
7
|
+
|
|
8
|
+
Default export: `SwipeAction`. Named type export: `SwipeActionProps`.
|
|
9
|
+
|
|
10
|
+
```tsx
|
|
11
|
+
interface SwipeActionProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onAction'> {
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
onAction: () => void;
|
|
14
|
+
actionLabel: string;
|
|
15
|
+
revealLabel: string;
|
|
16
|
+
closeLabel: string;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Pass translated labels from the application. Native div attributes and event
|
|
22
|
+
handlers apply to the outer wrapper. No routing, cart state, confirmation,
|
|
23
|
+
persistence, dependencies, or translation provider are introduced.
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
<SwipeAction
|
|
27
|
+
actionLabel={t('cart.removeItem')}
|
|
28
|
+
revealLabel={t('cart.showActions')}
|
|
29
|
+
closeLabel={t('cart.hideActions')}
|
|
30
|
+
onAction={() => removeItem(item.id)}
|
|
31
|
+
>
|
|
32
|
+
<CartItem item={item} />
|
|
33
|
+
</SwipeAction>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Interaction and accessibility
|
|
37
|
+
|
|
38
|
+
- The ellipsis toggle remains visible independently of gesture support. Native
|
|
39
|
+
buttons support keyboard and assistive-technology activation.
|
|
40
|
+
- The toggle exposes `aria-expanded` and `aria-controls`; its label switches
|
|
41
|
+
between `revealLabel` and `closeLabel`.
|
|
42
|
+
- Native overflow clips the closed action. During a partial swipe the destructive
|
|
43
|
+
background, trash icon and `actionLabel` progressively paint into view. Until
|
|
44
|
+
fully open, the action remains inert, hidden from accessibility APIs, disabled,
|
|
45
|
+
outside tab order and excluded from hit testing; visual reveal alone cannot delete.
|
|
46
|
+
- The action follows row content and immediately precedes its toggle in tab
|
|
47
|
+
order. Focusing row content closes an open reveal so links/editors are not clipped.
|
|
48
|
+
- Escape closes and restores toggle focus. Activating the trash button closes
|
|
49
|
+
and restores focus before invoking `onAction`. If that callback removes the row,
|
|
50
|
+
the owning list must move focus to a surviving row or its empty state.
|
|
51
|
+
- Swiping toward inline-start reveals the action at inline-end. Reverse motion
|
|
52
|
+
closes. Direction is inherited from the document or set using native `dir`.
|
|
53
|
+
- A native horizontal overflow viewport uses CSS scroll snapping. The browser
|
|
54
|
+
owns gesture direction, momentum, cancellation, vertical scrolling and pinch.
|
|
55
|
+
Interactive descendants use `touch-action: pan-y pinch-zoom`, scoped within
|
|
56
|
+
content: enclosing focusable containers (including `Stack tabIndex={-1}`) do
|
|
57
|
+
not block swipe. Disabling resets native scroll and closes without invoking the action.
|
|
58
|
+
- Only pointers with `pointerType === 'touch'` may reveal/close by swiping.
|
|
59
|
+
Mouse, pen, and unknown pointers never drag the row, including on hybrid
|
|
60
|
+
touchscreen computers. Do not infer input mode from screen width.
|
|
61
|
+
The persistent toggle and explicit action work without swiping. ShopKB also
|
|
62
|
+
retains a directly visible remove button on its cart rows.
|
|
63
|
+
- Both controls have minimum touch targets of 44 CSS pixels. Explicit toggles
|
|
64
|
+
scroll instantly, so trash is immediately usable. There are no custom
|
|
65
|
+
transitions; reduced-motion CSS keeps programmatic scrolling non-animated.
|
|
66
|
+
|
|
67
|
+
## Styling and integration
|
|
68
|
+
|
|
69
|
+
The entry declares `'use client'` for hook-based interaction in Next applications.
|
|
70
|
+
`SwipeAction.css` is imported locally by the component. It uses existing
|
|
71
|
+
`--background`, `--foreground`, `--destructive`, `--destructive-foreground`,
|
|
72
|
+
`--ring`, `--gap-sm`, and `--icon-md` tokens. The root defines
|
|
73
|
+
`--swipe-action-width` for the trailing action width; increase it via themed CSS
|
|
74
|
+
when translated labels need more room. Labels wrap within that width.
|
|
75
|
+
|
|
76
|
+
The public atomic barrel exports `SwipeAction` and `SwipeActionProps`; the central stylesheet imports its CSS. The component also imports its own CSS.
|
|
77
|
+
|
|
78
|
+
No pointer-move tracking, transforms, pointer capture, touchmove cancellation,
|
|
79
|
+
axis math, or second gesture engine is used. Native scroll position synchronizes
|
|
80
|
+
ARIA, inertness, and action availability only when the trailing snap endpoint is
|
|
81
|
+
reached. Pointerdown classifies actual input (not media queries): non-touch
|
|
82
|
+
pointers temporarily disable user scrolling while programmatic toggles still
|
|
83
|
+
work. A non-passive wheel listener excludes horizontal/Shift-wheel scrolling;
|
|
84
|
+
vertical wheel scrolling and Ctrl-wheel browser zoom remain native. Both action
|
|
85
|
+
buttons use `touch-action: manipulation`.
|
|
86
|
+
|
|
87
|
+
## Verification
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
bun test ./packages/components/src/atomic/SwipeAction/__tests__/
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
Happy-dom tests model scroll geometry/state, RTL, disabling, inertness,
|
|
94
|
+
explicit deletion, focus restoration, input classification, wheel exclusion and
|
|
95
|
+
SSR. It does not implement layout or native scrolling.
|
|
96
|
+
|
|
97
|
+
```sh
|
|
98
|
+
bun packages/components/tests/quantity-cart/run.ts
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The Chromium runner exercises trusted CDP touch, mouse/pen and wheel input,
|
|
102
|
+
including hybrid desktop/touch profiles, a real enclosing `Stack tabIndex={-1}`,
|
|
103
|
+
reverse swipes, held partial-touch pixel checks for destructive paint, closed
|
|
104
|
+
clipping/accessibility/hit-test checks, immediate explicit trash, interactive exclusions, focus, RTL,
|
|
105
|
+
responsive geometry, CSS zoom, reduced motion and scoped axe checks.
|
|
106
|
+
These are emulated inputs, not physical-device certification. CDP pinch did not
|
|
107
|
+
increase visual viewport scale on either the fixture or a plain control page;
|
|
108
|
+
the runner verifies pinch permissions through all ancestors and absence of
|
|
109
|
+
accidental reveal/deletion, not physical pinch zoom. WebKit/Firefox and physical
|
|
110
|
+
trackpads remain unverified. No full accessibility, Lighthouse or performance
|
|
111
|
+
certification is claimed.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@donotdev/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Styled UI components for DoNotDev",
|
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
"import": "./dist/index.js",
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
13
|
},
|
|
14
|
+
"./sanitize-dom": {
|
|
15
|
+
"types": "./dist/utils/sanitizeDom.server.d.ts",
|
|
16
|
+
"browser": "./dist/utils/sanitizeDom.browser.js",
|
|
17
|
+
"default": "./dist/utils/sanitizeDom.server.js"
|
|
18
|
+
},
|
|
14
19
|
"./styles": "./dist/styles/index.css"
|
|
15
20
|
},
|
|
16
21
|
"sideEffects": [
|
|
@@ -78,7 +83,8 @@
|
|
|
78
83
|
"@radix-ui/react-visually-hidden": "^1.2.13",
|
|
79
84
|
"class-variance-authority": "^0.7.1",
|
|
80
85
|
"clsx": "^2.1.1",
|
|
81
|
-
"
|
|
86
|
+
"dompurify": "^3.4.18",
|
|
87
|
+
"jsdom": "^26.1.0",
|
|
82
88
|
"react-day-picker": "^9.14.0"
|
|
83
89
|
},
|
|
84
90
|
"peerDependencies": {
|