@plexui/vue 0.35.0 → 0.36.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { computed, defineComponent, h, onBeforeUnmount, ref } from "vue";
|
|
2
2
|
import s from "@plexui/styles/components/Stepper/Stepper.module.css";
|
|
3
|
-
import { Minus, Plus } from "../Icon/index.js";
|
|
3
|
+
import { Minus, Plus, RemoveTrash } from "../Icon/index.js";
|
|
4
4
|
// Vue port of packages/ui/src/components/Stepper/Stepper.tsx: the same DOM (a spin button with two
|
|
5
5
|
// unfocusable segments and an optional hidden input), keys, hold-to-repeat and clamped or wrapped steps.
|
|
6
6
|
// React's `value` + `onChange` become `value` + `update:value` (`v-model:value`) and `change`.
|
|
@@ -49,6 +49,13 @@ const StepperComponent = defineComponent({
|
|
|
49
49
|
decrementLabel: { type: String, default: "Decrease" },
|
|
50
50
|
/** Accessible name of the increment segment. @default "Increase" */
|
|
51
51
|
incrementLabel: { type: String, default: "Increase" },
|
|
52
|
+
/**
|
|
53
|
+
* Called (`@remove`) when the decrement segment is pressed at `min`. With it, the segment shows a trash can there
|
|
54
|
+
* and removes the item, as a cart's stepper does at a quantity of one (without `wrap`).
|
|
55
|
+
*/
|
|
56
|
+
onRemove: Function,
|
|
57
|
+
/** Accessible name of the decrement segment when it removes. @default "Remove" */
|
|
58
|
+
removeLabel: { type: String, default: "Remove" },
|
|
52
59
|
/** The name of the stepper. Submits its value with the owning form. */
|
|
53
60
|
name: String,
|
|
54
61
|
/** Accessible name of the value the stepper changes, when no visible label names it. */
|
|
@@ -96,9 +103,19 @@ const StepperComponent = defineComponent({
|
|
|
96
103
|
onBeforeUnmount(stopRepeat);
|
|
97
104
|
const atMin = computed(() => !props.wrap && value.value <= props.min);
|
|
98
105
|
const atMax = computed(() => !props.wrap && value.value >= props.max);
|
|
106
|
+
// At the minimum the decrement segment removes the item, when the owner can remove it
|
|
107
|
+
const removes = computed(() => atMin.value && props.onRemove !== undefined);
|
|
99
108
|
const startPress = (segment, event) => {
|
|
100
109
|
if (event.button !== 0 || props.disabled)
|
|
101
110
|
return;
|
|
111
|
+
if (segment === "decrement" && removes.value) {
|
|
112
|
+
const target = event.currentTarget;
|
|
113
|
+
if (target instanceof HTMLElement)
|
|
114
|
+
target.setPointerCapture?.(event.pointerId);
|
|
115
|
+
pressed.value = segment;
|
|
116
|
+
props.onRemove?.();
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
102
119
|
if (segment === "decrement" ? atMin.value : atMax.value)
|
|
103
120
|
return;
|
|
104
121
|
const target = event.currentTarget;
|
|
@@ -120,6 +137,8 @@ const StepperComponent = defineComponent({
|
|
|
120
137
|
const handleClick = (segment, event) => {
|
|
121
138
|
if (event.detail !== 0 || props.disabled)
|
|
122
139
|
return;
|
|
140
|
+
if (segment === "decrement" && removes.value)
|
|
141
|
+
return props.onRemove?.();
|
|
123
142
|
stepBy(segment === "decrement" ? -1 : 1);
|
|
124
143
|
};
|
|
125
144
|
const handleKeyDown = (event) => {
|
|
@@ -132,6 +151,8 @@ const StepperComponent = defineComponent({
|
|
|
132
151
|
PageDown: () => stepBy(-1, 10),
|
|
133
152
|
Home: () => commit(props.min),
|
|
134
153
|
End: () => commit(props.max),
|
|
154
|
+
// At the minimum Delete or Backspace removes, as the trash can does; the arrows never do
|
|
155
|
+
...(removes.value && { Delete: () => props.onRemove?.(), Backspace: () => props.onRemove?.() }),
|
|
135
156
|
};
|
|
136
157
|
const action = keys[event.key];
|
|
137
158
|
if (!action)
|
|
@@ -140,15 +161,17 @@ const StepperComponent = defineComponent({
|
|
|
140
161
|
action();
|
|
141
162
|
};
|
|
142
163
|
const segment = (kind) => {
|
|
143
|
-
const
|
|
164
|
+
const remove = kind === "decrement" && removes.value;
|
|
165
|
+
const atEnd = !remove && (kind === "decrement" ? atMin.value : atMax.value);
|
|
144
166
|
return h("button", {
|
|
145
167
|
"type": "button",
|
|
146
168
|
"tabindex": -1,
|
|
147
|
-
"aria-label": kind === "decrement" ? props.decrementLabel : props.incrementLabel,
|
|
169
|
+
"aria-label": remove ? props.removeLabel : kind === "decrement" ? props.decrementLabel : props.incrementLabel,
|
|
148
170
|
"aria-disabled": atEnd || undefined,
|
|
149
171
|
"disabled": props.disabled,
|
|
150
172
|
"class": s.Segment,
|
|
151
173
|
"data-segment": kind,
|
|
174
|
+
"data-remove": remove ? "" : undefined,
|
|
152
175
|
"data-disabled": atEnd || props.disabled ? "" : undefined,
|
|
153
176
|
"data-pressed": pressed.value === kind && !props.disabled ? "" : undefined,
|
|
154
177
|
// Keeps the focus where it is, as a native stepper takes none.
|
|
@@ -158,7 +181,7 @@ const StepperComponent = defineComponent({
|
|
|
158
181
|
"onPointercancel": stopRepeat,
|
|
159
182
|
"onLostpointercapture": stopRepeat,
|
|
160
183
|
"onClick": (event) => handleClick(kind, event),
|
|
161
|
-
}, [h(kind === "decrement" ? Minus : Plus, { class: s.Icon })]);
|
|
184
|
+
}, [h(remove ? RemoveTrash : kind === "decrement" ? Minus : Plus, { class: s.Icon })]);
|
|
162
185
|
};
|
|
163
186
|
return () => h("div", {
|
|
164
187
|
...attrs,
|
|
@@ -171,6 +194,7 @@ const StepperComponent = defineComponent({
|
|
|
171
194
|
"aria-label": props.ariaLabel,
|
|
172
195
|
"aria-labelledby": props.ariaLabelledby,
|
|
173
196
|
"aria-describedby": props.ariaDescribedby,
|
|
197
|
+
"aria-keyshortcuts": removes.value ? "Delete" : undefined,
|
|
174
198
|
"aria-disabled": props.disabled || undefined,
|
|
175
199
|
"class": [s.Stepper, attrs.class],
|
|
176
200
|
"data-disabled": props.disabled ? "" : undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Stepper.js","sourceRoot":"","sources":["../../../../src/components/Stepper/Stepper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,KA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C,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;YAC1D,OAAO,CAAC,WAAW,CAAC;YACpB,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI;SACjI,CAAC,CAAA;IACJ,CAAC;CACF,CAAC,CAAA;AAOF;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAA","sourcesContent":["import { computed, defineComponent, h, onBeforeUnmount, ref } from \"vue\"\nimport s from \"@plexui/styles/components/Stepper/Stepper.module.css\"\nimport { Minus, Plus } from \"../Icon/index.js\"\n\n// Vue port of packages/ui/src/components/Stepper/Stepper.tsx: the same DOM (a spin button with two\n// unfocusable segments and an optional hidden input), keys, hold-to-repeat and clamped or wrapped steps.\n// React's `value` + `onChange` become `value` + `update:value` (`v-model:value`) and `change`.\n\n/** Delay before a held segment starts repeating, and the time between repeats, in ms. */\nconst REPEAT_DELAY = 400\nconst REPEAT_INTERVAL = 100\n\nconst decimals = (n: number) => {\n const [, fraction = \"\"] = String(n).split(\".\")\n return fraction.length\n}\n\n/** The value one step away, clamped to the range or wrapped, without floating point drift. */\nexport const stepValue = (current: number, direction: 1 | -1, { min, max, step, wrap }: { min: number; max: number; step: number; wrap: boolean }) => {\n const precision = Math.max(decimals(step), decimals(min), decimals(current))\n const next = Number((current + direction * step).toFixed(precision))\n if (next > max) return wrap ? min : max\n if (next < min) return wrap ? max : min\n return next\n}\n\ntype Segment = \"decrement\" | \"increment\"\n\nconst StepperComponent = defineComponent({\n name: \"Stepper\",\n inheritAttrs: false,\n props: {\n /** The `id` of the stepper. */\n id: String,\n /** The controlled value. Bind with `v-model:value`. */\n value: { type: Number, default: undefined },\n /** The value when it is initially rendered. Use when you do not need to control the value. @default min */\n defaultValue: { type: Number, default: undefined },\n /** The lowest value. @default 0 */\n min: { type: Number, default: 0 },\n /** The highest value. @default 100 */\n max: { type: Number, default: 100 },\n /** The amount each step adds or removes. @default 1 */\n step: { type: Number, default: 1 },\n /** A step past `max` continues from `min`, and one below `min` from `max`. @default false */\n wrap: { type: Boolean, default: false },\n /** Holding a segment keeps stepping, as a native stepper does. @default true */\n autoRepeat: { type: Boolean, default: true },\n /** When `true`, prevents the user from interacting with the stepper. */\n disabled: { type: Boolean, default: false },\n /** Fully rounded ends. @default true */\n pill: { type: Boolean, default: true },\n /** Accessible name of the decrement segment. @default \"Decrease\" */\n decrementLabel: { type: String, default: \"Decrease\" },\n /** Accessible name of the increment segment. @default \"Increase\" */\n incrementLabel: { type: String, default: \"Increase\" },\n /** The name of the stepper. Submits its value with the owning form. */\n name: String,\n /** Accessible name of the value the stepper changes, when no visible label names it. */\n ariaLabel: String,\n /** The `id` of the visible label of the value the stepper changes. */\n ariaLabelledby: String,\n /** The `id` of an element that describes the stepper, such as the text that shows its value. */\n ariaDescribedby: String,\n },\n emits: {\n /** The value changed */\n \"update:value\": (value: number) => typeof value === \"number\",\n /** The value changed (React `onChange`) */\n change: (value: number) => typeof value === \"number\",\n /** The stepper gained focus */\n focus: (event: FocusEvent) => event.type === \"focus\",\n /** The stepper lost focus */\n blur: (event: FocusEvent) => event.type === \"blur\",\n },\n setup(props, { attrs, emit }) {\n const internalValue = ref(props.defaultValue ?? props.min)\n const value = computed(() => props.value ?? internalValue.value)\n const pressed = ref<Segment | null>(null)\n let timer: ReturnType<typeof setTimeout> | undefined\n\n const commit = (next: number) => {\n if (next === value.value) return false\n if (props.value === undefined) internalValue.value = next\n emit(\"update:value\", next)\n emit(\"change\", next)\n return true\n }\n\n const stepBy = (direction: 1 | -1, times = 1) => {\n let next = value.value\n for (let i = 0; i < times; i++) next = stepValue(next, direction, props)\n return commit(next)\n }\n\n const stopRepeat = () => {\n clearTimeout(timer)\n timer = undefined\n pressed.value = null\n }\n onBeforeUnmount(stopRepeat)\n\n const atMin = computed(() => !props.wrap && value.value <= props.min)\n const atMax = computed(() => !props.wrap && value.value >= props.max)\n\n const startPress = (segment: Segment, event: PointerEvent) => {\n if (event.button !== 0 || props.disabled) return\n if (segment === \"decrement\" ? atMin.value : atMax.value) return\n const target = event.currentTarget\n if (target instanceof HTMLElement) target.setPointerCapture?.(event.pointerId)\n pressed.value = segment\n const direction = segment === \"decrement\" ? -1 : 1\n stepBy(direction)\n if (!props.autoRepeat) return\n const repeat = () => {\n if (props.disabled || !stepBy(direction)) return stopRepeat()\n timer = setTimeout(repeat, REPEAT_INTERVAL)\n }\n timer = setTimeout(repeat, REPEAT_DELAY)\n }\n\n // A pointer steps on press, so only a click without one (assistive technology, `element.click()`) steps here.\n const handleClick = (segment: Segment, event: MouseEvent) => {\n if (event.detail !== 0 || props.disabled) return\n stepBy(segment === \"decrement\" ? -1 : 1)\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (props.disabled || event.altKey || event.ctrlKey || event.metaKey) return\n const keys: Record<string, () => void> = {\n ArrowUp: () => stepBy(1),\n ArrowDown: () => stepBy(-1),\n PageUp: () => stepBy(1, 10),\n PageDown: () => stepBy(-1, 10),\n Home: () => commit(props.min),\n End: () => commit(props.max),\n }\n const action = keys[event.key]\n if (!action) return\n event.preventDefault()\n action()\n }\n\n const segment = (kind: Segment) => {\n const atEnd = kind === \"decrement\" ? atMin.value : atMax.value\n return h(\"button\", {\n \"type\": \"button\",\n \"tabindex\": -1,\n \"aria-label\": kind === \"decrement\" ? props.decrementLabel : props.incrementLabel,\n \"aria-disabled\": atEnd || undefined,\n \"disabled\": props.disabled,\n \"class\": s.Segment,\n \"data-segment\": kind,\n \"data-disabled\": atEnd || props.disabled ? \"\" : undefined,\n \"data-pressed\": pressed.value === kind && !props.disabled ? \"\" : undefined,\n // Keeps the focus where it is, as a native stepper takes none.\n \"onMousedown\": (event: MouseEvent) => event.preventDefault(),\n \"onPointerdown\": (event: PointerEvent) => startPress(kind, event),\n \"onPointerup\": stopRepeat,\n \"onPointercancel\": stopRepeat,\n \"onLostpointercapture\": stopRepeat,\n \"onClick\": (event: MouseEvent) => handleClick(kind, event),\n }, [h(kind === \"decrement\" ? Minus : Plus, { class: s.Icon })])\n }\n\n return () => h(\"div\", {\n ...attrs,\n \"id\": props.id,\n \"role\": \"spinbutton\",\n \"tabindex\": props.disabled ? -1 : 0,\n \"aria-valuenow\": value.value,\n \"aria-valuemin\": props.min,\n \"aria-valuemax\": props.max,\n \"aria-label\": props.ariaLabel,\n \"aria-labelledby\": props.ariaLabelledby,\n \"aria-describedby\": props.ariaDescribedby,\n \"aria-disabled\": props.disabled || undefined,\n \"class\": [s.Stepper, attrs.class],\n \"data-disabled\": props.disabled ? \"\" : undefined,\n \"data-pill\": props.pill ? \"\" : undefined,\n \"onKeydown\": handleKeyDown,\n \"onFocus\": (event: FocusEvent) => emit(\"focus\", event),\n \"onBlur\": (event: FocusEvent) => emit(\"blur\", event),\n }, [\n segment(\"decrement\"),\n h(\"span\", { \"class\": s.Separator, \"aria-hidden\": \"true\" }),\n segment(\"increment\"),\n props.name !== undefined ? h(\"input\", { type: \"hidden\", name: props.name, value: value.value, disabled: props.disabled }) : null,\n ])\n },\n})\n\ntype StepperOwnProps = InstanceType<typeof StepperComponent>[\"$props\"]\n\n/** Stepper props. */\nexport type StepperProps = StepperOwnProps\n\n/**\n * Two segments that decrease and increase a number, as the iOS 26 stepper does. It shows no value of its own:\n * name it with `aria-label` or `aria-labelledby` and show the value beside it. Keyboard focus lands on the\n * stepper, a spin button: Up and Down step, Page Up and Page Down step ten times, Home and End go to the range ends.\n */\nexport const Stepper = StepperComponent\n"]}
|
|
1
|
+
{"version":3,"file":"Stepper.js","sourceRoot":"","sources":["../../../../src/components/Stepper/Stepper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,EAAE,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,EAAE;YACD,OAAO,CAAC,WAAW,CAAC;YACpB,CAAC,CAAC,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,SAAS,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC;YAC1D,OAAO,CAAC,WAAW,CAAC;YACpB,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI;SACjI,CAAC,CAAA;IACJ,CAAC;CACF,CAAC,CAAA;AAOF;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,gBAAgB,CAAA","sourcesContent":["import { computed, defineComponent, h, onBeforeUnmount, type PropType, ref } from \"vue\"\nimport s from \"@plexui/styles/components/Stepper/Stepper.module.css\"\nimport { Minus, Plus, RemoveTrash } from \"../Icon/index.js\"\n\n// Vue port of packages/ui/src/components/Stepper/Stepper.tsx: the same DOM (a spin button with two\n// unfocusable segments and an optional hidden input), keys, hold-to-repeat and clamped or wrapped steps.\n// React's `value` + `onChange` become `value` + `update:value` (`v-model:value`) and `change`.\n\n/** Delay before a held segment starts repeating, and the time between repeats, in ms. */\nconst REPEAT_DELAY = 400\nconst REPEAT_INTERVAL = 100\n\nconst decimals = (n: number) => {\n const [, fraction = \"\"] = String(n).split(\".\")\n return fraction.length\n}\n\n/** The value one step away, clamped to the range or wrapped, without floating point drift. */\nexport const stepValue = (current: number, direction: 1 | -1, { min, max, step, wrap }: { min: number; max: number; step: number; wrap: boolean }) => {\n const precision = Math.max(decimals(step), decimals(min), decimals(current))\n const next = Number((current + direction * step).toFixed(precision))\n if (next > max) return wrap ? min : max\n if (next < min) return wrap ? max : min\n return next\n}\n\ntype Segment = \"decrement\" | \"increment\"\n\nconst StepperComponent = defineComponent({\n name: \"Stepper\",\n inheritAttrs: false,\n props: {\n /** The `id` of the stepper. */\n id: String,\n /** The controlled value. Bind with `v-model:value`. */\n value: { type: Number, default: undefined },\n /** The value when it is initially rendered. Use when you do not need to control the value. @default min */\n defaultValue: { type: Number, default: undefined },\n /** The lowest value. @default 0 */\n min: { type: Number, default: 0 },\n /** The highest value. @default 100 */\n max: { type: Number, default: 100 },\n /** The amount each step adds or removes. @default 1 */\n step: { type: Number, default: 1 },\n /** A step past `max` continues from `min`, and one below `min` from `max`. @default false */\n wrap: { type: Boolean, default: false },\n /** Holding a segment keeps stepping, as a native stepper does. @default true */\n autoRepeat: { type: Boolean, default: true },\n /** When `true`, prevents the user from interacting with the stepper. */\n disabled: { type: Boolean, default: false },\n /** Fully rounded ends. @default true */\n pill: { type: Boolean, default: true },\n /** Accessible name of the decrement segment. @default \"Decrease\" */\n decrementLabel: { type: String, default: \"Decrease\" },\n /** Accessible name of the increment segment. @default \"Increase\" */\n incrementLabel: { type: String, default: \"Increase\" },\n /**\n * Called (`@remove`) when the decrement segment is pressed at `min`. With it, the segment shows a trash can there\n * and removes the item, as a cart's stepper does at a quantity of one (without `wrap`).\n */\n onRemove: Function as PropType<() => void>,\n /** Accessible name of the decrement segment when it removes. @default \"Remove\" */\n removeLabel: { type: String, default: \"Remove\" },\n /** The name of the stepper. Submits its value with the owning form. */\n name: String,\n /** Accessible name of the value the stepper changes, when no visible label names it. */\n ariaLabel: String,\n /** The `id` of the visible label of the value the stepper changes. */\n ariaLabelledby: String,\n /** The `id` of an element that describes the stepper, such as the text that shows its value. */\n ariaDescribedby: String,\n },\n emits: {\n /** The value changed */\n \"update:value\": (value: number) => typeof value === \"number\",\n /** The value changed (React `onChange`) */\n change: (value: number) => typeof value === \"number\",\n /** The stepper gained focus */\n focus: (event: FocusEvent) => event.type === \"focus\",\n /** The stepper lost focus */\n blur: (event: FocusEvent) => event.type === \"blur\",\n },\n setup(props, { attrs, emit }) {\n const internalValue = ref(props.defaultValue ?? props.min)\n const value = computed(() => props.value ?? internalValue.value)\n const pressed = ref<Segment | null>(null)\n let timer: ReturnType<typeof setTimeout> | undefined\n\n const commit = (next: number) => {\n if (next === value.value) return false\n if (props.value === undefined) internalValue.value = next\n emit(\"update:value\", next)\n emit(\"change\", next)\n return true\n }\n\n const stepBy = (direction: 1 | -1, times = 1) => {\n let next = value.value\n for (let i = 0; i < times; i++) next = stepValue(next, direction, props)\n return commit(next)\n }\n\n const stopRepeat = () => {\n clearTimeout(timer)\n timer = undefined\n pressed.value = null\n }\n onBeforeUnmount(stopRepeat)\n\n const atMin = computed(() => !props.wrap && value.value <= props.min)\n const atMax = computed(() => !props.wrap && value.value >= props.max)\n // At the minimum the decrement segment removes the item, when the owner can remove it\n const removes = computed(() => atMin.value && props.onRemove !== undefined)\n\n const startPress = (segment: Segment, event: PointerEvent) => {\n if (event.button !== 0 || props.disabled) return\n if (segment === \"decrement\" && removes.value) {\n const target = event.currentTarget\n if (target instanceof HTMLElement) target.setPointerCapture?.(event.pointerId)\n pressed.value = segment\n props.onRemove?.()\n return\n }\n if (segment === \"decrement\" ? atMin.value : atMax.value) return\n const target = event.currentTarget\n if (target instanceof HTMLElement) target.setPointerCapture?.(event.pointerId)\n pressed.value = segment\n const direction = segment === \"decrement\" ? -1 : 1\n stepBy(direction)\n if (!props.autoRepeat) return\n const repeat = () => {\n if (props.disabled || !stepBy(direction)) return stopRepeat()\n timer = setTimeout(repeat, REPEAT_INTERVAL)\n }\n timer = setTimeout(repeat, REPEAT_DELAY)\n }\n\n // A pointer steps on press, so only a click without one (assistive technology, `element.click()`) steps here.\n const handleClick = (segment: Segment, event: MouseEvent) => {\n if (event.detail !== 0 || props.disabled) return\n if (segment === \"decrement\" && removes.value) return props.onRemove?.()\n stepBy(segment === \"decrement\" ? -1 : 1)\n }\n\n const handleKeyDown = (event: KeyboardEvent) => {\n if (props.disabled || event.altKey || event.ctrlKey || event.metaKey) return\n const keys: Record<string, () => void> = {\n ArrowUp: () => stepBy(1),\n ArrowDown: () => stepBy(-1),\n PageUp: () => stepBy(1, 10),\n PageDown: () => stepBy(-1, 10),\n Home: () => commit(props.min),\n End: () => commit(props.max),\n // At the minimum Delete or Backspace removes, as the trash can does; the arrows never do\n ...(removes.value && { Delete: () => props.onRemove?.(), Backspace: () => props.onRemove?.() }),\n }\n const action = keys[event.key]\n if (!action) return\n event.preventDefault()\n action()\n }\n\n const segment = (kind: Segment) => {\n const remove = kind === \"decrement\" && removes.value\n const atEnd = !remove && (kind === \"decrement\" ? atMin.value : atMax.value)\n return h(\"button\", {\n \"type\": \"button\",\n \"tabindex\": -1,\n \"aria-label\": remove ? props.removeLabel : kind === \"decrement\" ? props.decrementLabel : props.incrementLabel,\n \"aria-disabled\": atEnd || undefined,\n \"disabled\": props.disabled,\n \"class\": s.Segment,\n \"data-segment\": kind,\n \"data-remove\": remove ? \"\" : undefined,\n \"data-disabled\": atEnd || props.disabled ? \"\" : undefined,\n \"data-pressed\": pressed.value === kind && !props.disabled ? \"\" : undefined,\n // Keeps the focus where it is, as a native stepper takes none.\n \"onMousedown\": (event: MouseEvent) => event.preventDefault(),\n \"onPointerdown\": (event: PointerEvent) => startPress(kind, event),\n \"onPointerup\": stopRepeat,\n \"onPointercancel\": stopRepeat,\n \"onLostpointercapture\": stopRepeat,\n \"onClick\": (event: MouseEvent) => handleClick(kind, event),\n }, [h(remove ? RemoveTrash : kind === \"decrement\" ? Minus : Plus, { class: s.Icon })])\n }\n\n return () => h(\"div\", {\n ...attrs,\n \"id\": props.id,\n \"role\": \"spinbutton\",\n \"tabindex\": props.disabled ? -1 : 0,\n \"aria-valuenow\": value.value,\n \"aria-valuemin\": props.min,\n \"aria-valuemax\": props.max,\n \"aria-label\": props.ariaLabel,\n \"aria-labelledby\": props.ariaLabelledby,\n \"aria-describedby\": props.ariaDescribedby,\n \"aria-keyshortcuts\": removes.value ? \"Delete\" : undefined,\n \"aria-disabled\": props.disabled || undefined,\n \"class\": [s.Stepper, attrs.class],\n \"data-disabled\": props.disabled ? \"\" : undefined,\n \"data-pill\": props.pill ? \"\" : undefined,\n \"onKeydown\": handleKeyDown,\n \"onFocus\": (event: FocusEvent) => emit(\"focus\", event),\n \"onBlur\": (event: FocusEvent) => emit(\"blur\", event),\n }, [\n segment(\"decrement\"),\n h(\"span\", { \"class\": s.Separator, \"aria-hidden\": \"true\" }),\n segment(\"increment\"),\n props.name !== undefined ? h(\"input\", { type: \"hidden\", name: props.name, value: value.value, disabled: props.disabled }) : null,\n ])\n },\n})\n\ntype StepperOwnProps = InstanceType<typeof StepperComponent>[\"$props\"]\n\n/** Stepper props. */\nexport type StepperProps = StepperOwnProps\n\n/**\n * Two segments that decrease and increase a number, as the iOS 26 stepper does. It shows no value of its own:\n * name it with `aria-label` or `aria-labelledby` and show the value beside it. Keyboard focus lands on the\n * stepper, a spin button: Up and Down step, Page Up and Page Down step ten times, Home and End go to the range ends.\n */\nexport const Stepper = StepperComponent\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type PropType } from "vue";
|
|
1
2
|
/** The value one step away, clamped to the range or wrapped, without floating point drift. */
|
|
2
3
|
export declare const stepValue: (current: number, direction: 1 | -1, { min, max, step, wrap }: {
|
|
3
4
|
min: number;
|
|
@@ -63,6 +64,16 @@ declare const StepperComponent: import("vue").DefineComponent<import("vue").Extr
|
|
|
63
64
|
type: StringConstructor;
|
|
64
65
|
default: string;
|
|
65
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* Called (`@remove`) when the decrement segment is pressed at `min`. With it, the segment shows a trash can there
|
|
69
|
+
* and removes the item, as a cart's stepper does at a quantity of one (without `wrap`).
|
|
70
|
+
*/
|
|
71
|
+
onRemove: PropType<() => void>;
|
|
72
|
+
/** Accessible name of the decrement segment when it removes. @default "Remove" */
|
|
73
|
+
removeLabel: {
|
|
74
|
+
type: StringConstructor;
|
|
75
|
+
default: string;
|
|
76
|
+
};
|
|
66
77
|
/** The name of the stepper. Submits its value with the owning form. */
|
|
67
78
|
name: StringConstructor;
|
|
68
79
|
/** Accessible name of the value the stepper changes, when no visible label names it. */
|
|
@@ -140,6 +151,16 @@ declare const StepperComponent: import("vue").DefineComponent<import("vue").Extr
|
|
|
140
151
|
type: StringConstructor;
|
|
141
152
|
default: string;
|
|
142
153
|
};
|
|
154
|
+
/**
|
|
155
|
+
* Called (`@remove`) when the decrement segment is pressed at `min`. With it, the segment shows a trash can there
|
|
156
|
+
* and removes the item, as a cart's stepper does at a quantity of one (without `wrap`).
|
|
157
|
+
*/
|
|
158
|
+
onRemove: PropType<() => void>;
|
|
159
|
+
/** Accessible name of the decrement segment when it removes. @default "Remove" */
|
|
160
|
+
removeLabel: {
|
|
161
|
+
type: StringConstructor;
|
|
162
|
+
default: string;
|
|
163
|
+
};
|
|
143
164
|
/** The name of the stepper. Submits its value with the owning form. */
|
|
144
165
|
name: StringConstructor;
|
|
145
166
|
/** Accessible name of the value the stepper changes, when no visible label names it. */
|
|
@@ -161,6 +182,7 @@ declare const StepperComponent: import("vue").DefineComponent<import("vue").Extr
|
|
|
161
182
|
pill: boolean;
|
|
162
183
|
max: number;
|
|
163
184
|
min: number;
|
|
185
|
+
removeLabel: string;
|
|
164
186
|
step: number;
|
|
165
187
|
autoRepeat: boolean;
|
|
166
188
|
decrementLabel: string;
|
|
@@ -232,6 +254,16 @@ export declare const Stepper: import("vue").DefineComponent<import("vue").Extrac
|
|
|
232
254
|
type: StringConstructor;
|
|
233
255
|
default: string;
|
|
234
256
|
};
|
|
257
|
+
/**
|
|
258
|
+
* Called (`@remove`) when the decrement segment is pressed at `min`. With it, the segment shows a trash can there
|
|
259
|
+
* and removes the item, as a cart's stepper does at a quantity of one (without `wrap`).
|
|
260
|
+
*/
|
|
261
|
+
onRemove: PropType<() => void>;
|
|
262
|
+
/** Accessible name of the decrement segment when it removes. @default "Remove" */
|
|
263
|
+
removeLabel: {
|
|
264
|
+
type: StringConstructor;
|
|
265
|
+
default: string;
|
|
266
|
+
};
|
|
235
267
|
/** The name of the stepper. Submits its value with the owning form. */
|
|
236
268
|
name: StringConstructor;
|
|
237
269
|
/** Accessible name of the value the stepper changes, when no visible label names it. */
|
|
@@ -309,6 +341,16 @@ export declare const Stepper: import("vue").DefineComponent<import("vue").Extrac
|
|
|
309
341
|
type: StringConstructor;
|
|
310
342
|
default: string;
|
|
311
343
|
};
|
|
344
|
+
/**
|
|
345
|
+
* Called (`@remove`) when the decrement segment is pressed at `min`. With it, the segment shows a trash can there
|
|
346
|
+
* and removes the item, as a cart's stepper does at a quantity of one (without `wrap`).
|
|
347
|
+
*/
|
|
348
|
+
onRemove: PropType<() => void>;
|
|
349
|
+
/** Accessible name of the decrement segment when it removes. @default "Remove" */
|
|
350
|
+
removeLabel: {
|
|
351
|
+
type: StringConstructor;
|
|
352
|
+
default: string;
|
|
353
|
+
};
|
|
312
354
|
/** The name of the stepper. Submits its value with the owning form. */
|
|
313
355
|
name: StringConstructor;
|
|
314
356
|
/** Accessible name of the value the stepper changes, when no visible label names it. */
|
|
@@ -330,6 +372,7 @@ export declare const Stepper: import("vue").DefineComponent<import("vue").Extrac
|
|
|
330
372
|
pill: boolean;
|
|
331
373
|
max: number;
|
|
332
374
|
min: number;
|
|
375
|
+
removeLabel: string;
|
|
333
376
|
step: number;
|
|
334
377
|
autoRepeat: boolean;
|
|
335
378
|
decrementLabel: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plexui/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.0",
|
|
4
4
|
"description": "Plex UI components for Vue 3, built on Reka UI and the shared @plexui/styles CSS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
"@maskito/core": "5.2.2",
|
|
78
78
|
"@maskito/kit": "5.2.2",
|
|
79
79
|
"@maskito/vue": "5.2.2",
|
|
80
|
-
"@plexui/styles": "^0.
|
|
80
|
+
"@plexui/styles": "^0.14.0",
|
|
81
81
|
"@tanstack/table-core": "8.21.3",
|
|
82
82
|
"@tanstack/vue-table": "8.21.3",
|
|
83
83
|
"@tiptap/core": "3.21.0",
|