@aleph-alpha/ui-library 7.0.2 → 7.2.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/system/components/UiPagination/UiPagination.vue.d.ts +19 -0
- package/dist/system/components/UiPagination/constants.d.ts +6 -0
- package/dist/system/components/UiPagination/index.d.ts +3 -0
- package/dist/system/components/UiPagination/types.d.ts +81 -0
- package/dist/system/components/UiSlider/step-marks.d.ts +45 -0
- package/dist/system/components/UiSlider/types.d.ts +28 -0
- package/dist/system/components/core/pagination/Pagination.vue.d.ts +29 -0
- package/dist/system/components/core/pagination/PaginationContent.vue.d.ts +29 -0
- package/dist/system/components/core/pagination/PaginationEllipsis.vue.d.ts +22 -0
- package/dist/system/components/core/pagination/PaginationFirst.vue.d.ts +22 -0
- package/dist/system/components/core/pagination/PaginationItem.vue.d.ts +26 -0
- package/dist/system/components/core/pagination/PaginationLast.vue.d.ts +22 -0
- package/dist/system/components/core/pagination/PaginationNext.vue.d.ts +22 -0
- package/dist/system/components/core/pagination/PaginationPrevious.vue.d.ts +22 -0
- package/dist/system/components/core/pagination/index.d.ts +8 -0
- package/dist/system/components/core/slider/Slider.vue.d.ts +21 -1
- package/dist/system/components/index.d.ts +1 -0
- package/dist/system/icons/story-sidebar-icons.json +4 -0
- package/dist/system/lib.js +11762 -10952
- package/dist/system/patterns/UiBulkAction/UiBulkAction.vue.d.ts +43 -0
- package/dist/system/patterns/UiBulkAction/index.d.ts +3 -0
- package/dist/system/patterns/UiBulkAction/types.d.ts +109 -0
- package/dist/system/patterns/UiBulkAction/useBulkAction.d.ts +7 -0
- package/dist/system/patterns/UiDataTable/constants.d.ts +10 -0
- package/dist/system/patterns/index.d.ts +1 -0
- package/dist/system/story-sidebar-icons.json +4 -0
- package/package.json +8 -8
- package/src/components/UiPagination/UiPagination.guidance.md +60 -0
- package/src/components/UiPagination/UiPagination.stories.ts +1070 -0
- package/src/components/UiPagination/UiPagination.vue +109 -0
- package/src/components/UiPagination/__tests__/UiPagination.test.ts +203 -0
- package/src/components/UiPagination/constants.ts +17 -0
- package/src/components/UiPagination/index.ts +3 -0
- package/src/components/UiPagination/types.ts +82 -0
- package/src/components/UiSlider/UiSlider.stories.ts +710 -2
- package/src/components/UiSlider/UiSlider.vue +109 -1
- package/src/components/UiSlider/__tests__/UiSliderValueAndSteps.test.ts +210 -0
- package/src/components/UiSlider/__tests__/step-marks.test.ts +94 -0
- package/src/components/UiSlider/step-marks.ts +96 -0
- package/src/components/UiSlider/types.ts +32 -0
- package/src/components/core/pagination/Pagination.vue +26 -0
- package/src/components/core/pagination/PaginationContent.vue +24 -0
- package/src/components/core/pagination/PaginationEllipsis.vue +30 -0
- package/src/components/core/pagination/PaginationFirst.vue +30 -0
- package/src/components/core/pagination/PaginationItem.vue +39 -0
- package/src/components/core/pagination/PaginationLast.vue +30 -0
- package/src/components/core/pagination/PaginationNext.vue +35 -0
- package/src/components/core/pagination/PaginationPrevious.vue +35 -0
- package/src/components/core/pagination/index.ts +8 -0
- package/src/components/core/slider/Slider.vue +16 -6
- package/src/components/index.ts +1 -0
- package/src/patterns/UiBulkAction/UiBulkAction.guidance.md +59 -0
- package/src/patterns/UiBulkAction/UiBulkAction.stories.ts +2238 -0
- package/src/patterns/UiBulkAction/UiBulkAction.vue +62 -0
- package/src/patterns/UiBulkAction/__tests__/useBulkAction.test.ts +78 -0
- package/src/patterns/UiBulkAction/index.ts +3 -0
- package/src/patterns/UiBulkAction/types.ts +126 -0
- package/src/patterns/UiBulkAction/useBulkAction.ts +50 -0
- package/src/patterns/UiDataTable/UiDataTable.stories.ts +375 -1
- package/src/patterns/UiDataTable/UiDataTablePagination.vue +43 -60
- package/src/patterns/UiDataTable/__tests__/UiDataTablePagination.test.ts +58 -29
- package/src/patterns/UiDataTable/constants.ts +10 -0
- package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +12 -12
- package/src/patterns/index.ts +1 -0
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { SliderRootEmits } from 'reka-ui';
|
|
3
|
+
import { useDirection } from 'reka-ui';
|
|
4
|
+
import { computed, toRef } from 'vue';
|
|
3
5
|
import { Slider as ShadcnSlider } from '@/components/core/slider';
|
|
6
|
+
import { cn } from '@/lib/utils';
|
|
7
|
+
import {
|
|
8
|
+
stepMarkPercents,
|
|
9
|
+
stepsIntervalOrDefault,
|
|
10
|
+
trackStartEdge,
|
|
11
|
+
type TrackStartEdge,
|
|
12
|
+
} from './step-marks';
|
|
4
13
|
import type { UiSliderProps, UiSliderEmits } from './types';
|
|
5
14
|
|
|
6
15
|
defineOptions({
|
|
@@ -21,6 +30,81 @@ function handleModelValueUpdate(
|
|
|
21
30
|
// reka-ui can emit undefined in some cases; keep our public API stable.
|
|
22
31
|
emit('update:modelValue', []);
|
|
23
32
|
}
|
|
33
|
+
|
|
34
|
+
const isVertical = computed(() => props.orientation === 'vertical');
|
|
35
|
+
|
|
36
|
+
// Room above the track for the shown value. The handle overhangs the thin
|
|
37
|
+
// track, so this is taller than the value's own line.
|
|
38
|
+
const rootClass = computed(() =>
|
|
39
|
+
cn(props.showValue && !isVertical.value && 'pt-6'),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
function valueText(value: number): string {
|
|
43
|
+
return props.formatValue ? props.formatValue(value) : String(value);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// The same direction the vendor slider uses: the prop, else the app's
|
|
47
|
+
// ConfigProvider, else left to right.
|
|
48
|
+
const direction = useDirection(toRef(props, 'dir'));
|
|
49
|
+
|
|
50
|
+
const startEdge = computed(() =>
|
|
51
|
+
trackStartEdge(
|
|
52
|
+
props.orientation ?? 'horizontal',
|
|
53
|
+
direction.value,
|
|
54
|
+
props.inverted,
|
|
55
|
+
),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// Defaults match the vendor slider's, so the marks line up with what it draws.
|
|
59
|
+
const markPercents = computed(() => {
|
|
60
|
+
const min = props.min ?? 0;
|
|
61
|
+
const max = props.max ?? 100;
|
|
62
|
+
const interval = stepsIntervalOrDefault(
|
|
63
|
+
min,
|
|
64
|
+
max,
|
|
65
|
+
props.step ?? 1,
|
|
66
|
+
props.stepsInterval,
|
|
67
|
+
);
|
|
68
|
+
return stepMarkPercents(min, max, interval);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Lies over the track, centred on it the way the vendor centres the handle.
|
|
72
|
+
// In 'contain' mode the handle's centre stops half a handle short of each end,
|
|
73
|
+
// so the marks are inset by the same amount.
|
|
74
|
+
const marksLayerClass = computed(() =>
|
|
75
|
+
cn(
|
|
76
|
+
'pointer-events-none absolute',
|
|
77
|
+
isVertical.value ? 'inset-y-0 w-1.5' : 'inset-x-0 h-1.5',
|
|
78
|
+
props.thumbAlignment !== 'overflow' &&
|
|
79
|
+
(isVertical.value
|
|
80
|
+
? 'my-[calc(var(--slider-thumb-size)/2)]'
|
|
81
|
+
: 'mx-[calc(var(--slider-thumb-size)/2)]'),
|
|
82
|
+
),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// Centres each mark on its position, the way the vendor centres the handle.
|
|
86
|
+
const markCentring: Record<TrackStartEdge, string> = {
|
|
87
|
+
left: 'top-1/2 -translate-x-1/2 -translate-y-1/2',
|
|
88
|
+
right: 'top-1/2 translate-x-1/2 -translate-y-1/2',
|
|
89
|
+
bottom: 'left-1/2 -translate-x-1/2 translate-y-1/2',
|
|
90
|
+
top: 'left-1/2 -translate-x-1/2 -translate-y-1/2',
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const markClass = computed(() =>
|
|
94
|
+
cn(
|
|
95
|
+
'bg-background-accent-soft absolute size-1 rounded-full',
|
|
96
|
+
markCentring[startEdge.value],
|
|
97
|
+
),
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
const valueLabelClass = computed(() =>
|
|
101
|
+
cn(
|
|
102
|
+
'label-xs-regular text-content-on-surface-primary pointer-events-none absolute whitespace-nowrap',
|
|
103
|
+
isVertical.value
|
|
104
|
+
? 'top-1/2 left-full ml-2 -translate-y-1/2'
|
|
105
|
+
: 'bottom-full left-1/2 mb-1 -translate-x-1/2',
|
|
106
|
+
),
|
|
107
|
+
);
|
|
24
108
|
</script>
|
|
25
109
|
|
|
26
110
|
<template>
|
|
@@ -38,7 +122,31 @@ function handleModelValueUpdate(
|
|
|
38
122
|
:thumb-alignment="props.thumbAlignment"
|
|
39
123
|
:name="props.name"
|
|
40
124
|
:required="props.required"
|
|
125
|
+
:class="rootClass"
|
|
126
|
+
:thumb-value-text="props.formatValue"
|
|
41
127
|
@update:model-value="handleModelValueUpdate"
|
|
42
128
|
@value-commit="emit('valueCommit', $event)"
|
|
43
|
-
|
|
129
|
+
>
|
|
130
|
+
<template v-if="props.showSteps" #track-overlay>
|
|
131
|
+
<div aria-hidden="true" :class="marksLayerClass">
|
|
132
|
+
<span
|
|
133
|
+
v-for="percent in markPercents"
|
|
134
|
+
:key="percent"
|
|
135
|
+
data-slot="slider-step-mark"
|
|
136
|
+
:class="markClass"
|
|
137
|
+
:style="{ [startEdge]: `${percent}%` }"
|
|
138
|
+
/>
|
|
139
|
+
</div>
|
|
140
|
+
</template>
|
|
141
|
+
|
|
142
|
+
<template v-if="props.showValue" #thumb="{ value }">
|
|
143
|
+
<span
|
|
144
|
+
aria-hidden="true"
|
|
145
|
+
data-slot="slider-value"
|
|
146
|
+
:class="valueLabelClass"
|
|
147
|
+
>
|
|
148
|
+
{{ valueText(value) }}
|
|
149
|
+
</span>
|
|
150
|
+
</template>
|
|
151
|
+
</ShadcnSlider>
|
|
44
152
|
</template>
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { render } from '@testing-library/vue';
|
|
2
|
+
import { ConfigProvider } from 'reka-ui';
|
|
3
|
+
import { describe, expect, test } from 'vitest';
|
|
4
|
+
import { h } from 'vue';
|
|
5
|
+
import { Slider as ShadcnSlider } from '@/components/core/slider';
|
|
6
|
+
import { UiSlider } from '../index';
|
|
7
|
+
|
|
8
|
+
// Mounted against the real vendor slider, unlike `UiSlider.test.ts`, which
|
|
9
|
+
// stubs it to exercise the payload guard.
|
|
10
|
+
|
|
11
|
+
const valueLabels = (container: Element) =>
|
|
12
|
+
[...container.querySelectorAll('[data-slot="slider-value"]')].map(
|
|
13
|
+
(label) => label.textContent,
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const stepMarks = (container: Element) => [
|
|
17
|
+
...container.querySelectorAll<HTMLElement>('[data-slot="slider-step-mark"]'),
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
describe('UiSlider value and step marks', () => {
|
|
21
|
+
test('renders exactly what the base slider renders unless asked for more', () => {
|
|
22
|
+
const props = { modelValue: [25, 75], min: 0, max: 100, step: 10 };
|
|
23
|
+
|
|
24
|
+
const wrapped = render(UiSlider, { props }).container.innerHTML;
|
|
25
|
+
const base = render(ShadcnSlider, { props }).container.innerHTML;
|
|
26
|
+
|
|
27
|
+
expect(wrapped).toBe(base);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('draws neither a value nor step marks unless asked to', () => {
|
|
31
|
+
const { container } = render(UiSlider, { props: { modelValue: [50] } });
|
|
32
|
+
|
|
33
|
+
expect(valueLabels(container)).toEqual([]);
|
|
34
|
+
expect(stepMarks(container)).toHaveLength(0);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('shows the value above each handle', () => {
|
|
38
|
+
const { container } = render(UiSlider, {
|
|
39
|
+
props: { modelValue: [25, 75], showValue: true },
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(valueLabels(container)).toEqual(['25', '75']);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('writes the value the way formatValue says', () => {
|
|
46
|
+
const { container } = render(UiSlider, {
|
|
47
|
+
props: {
|
|
48
|
+
modelValue: [70],
|
|
49
|
+
showValue: true,
|
|
50
|
+
formatValue: (value: number) => `${value}%`,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
expect(valueLabels(container)).toEqual(['70%']);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// That the handle still announces the value is checked by the stories: under
|
|
58
|
+
// jsdom the vendor renders the handle without its slider role and values.
|
|
59
|
+
test('keeps the shown value hidden from screen readers', () => {
|
|
60
|
+
const { container } = render(UiSlider, {
|
|
61
|
+
props: { modelValue: [70], showValue: true },
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const label = container.querySelector('[data-slot="slider-value"]');
|
|
65
|
+
expect(label).toHaveAttribute('aria-hidden', 'true');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('updates the shown value when the model changes', async () => {
|
|
69
|
+
const { container, rerender } = render(UiSlider, {
|
|
70
|
+
props: { modelValue: [10], showValue: true },
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
await rerender({ modelValue: [40], showValue: true });
|
|
74
|
+
|
|
75
|
+
expect(valueLabels(container)).toEqual(['40']);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('draws one mark per reachable step, hidden from screen readers', () => {
|
|
79
|
+
const { container } = render(UiSlider, {
|
|
80
|
+
props: { modelValue: [50], min: 0, max: 100, step: 10, showSteps: true },
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const marks = stepMarks(container);
|
|
84
|
+
expect(marks).toHaveLength(11);
|
|
85
|
+
expect(marks[0].closest('[aria-hidden="true"]')).not.toBeNull();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('places the marks from the edge the track starts at', () => {
|
|
89
|
+
const { container } = render(UiSlider, {
|
|
90
|
+
props: {
|
|
91
|
+
modelValue: [50],
|
|
92
|
+
step: 50,
|
|
93
|
+
dir: 'rtl',
|
|
94
|
+
showSteps: true,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const marks = stepMarks(container);
|
|
99
|
+
expect(marks.map((mark) => mark.style.right)).toEqual([
|
|
100
|
+
'0%',
|
|
101
|
+
'50%',
|
|
102
|
+
'100%',
|
|
103
|
+
]);
|
|
104
|
+
expect(marks.every((mark) => mark.style.left === '')).toBe(true);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('mirrors the marks for an inverted slider when no direction is given', () => {
|
|
108
|
+
const { container } = render(UiSlider, {
|
|
109
|
+
props: { modelValue: [50], step: 50, inverted: true, showSteps: true },
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const marks = stepMarks(container);
|
|
113
|
+
expect(marks.map((mark) => mark.style.right)).toEqual([
|
|
114
|
+
'0%',
|
|
115
|
+
'50%',
|
|
116
|
+
'100%',
|
|
117
|
+
]);
|
|
118
|
+
expect(marks.every((mark) => mark.style.left === '')).toBe(true);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test('places the marks from the right when the app reads right to left', () => {
|
|
122
|
+
const { container } = render({
|
|
123
|
+
render: () =>
|
|
124
|
+
h(ConfigProvider, { dir: 'rtl' }, () =>
|
|
125
|
+
h(UiSlider, { modelValue: [50], step: 50, showSteps: true }),
|
|
126
|
+
),
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
expect(stepMarks(container).map((mark) => mark.style.right)).toEqual([
|
|
130
|
+
'0%',
|
|
131
|
+
'50%',
|
|
132
|
+
'100%',
|
|
133
|
+
]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test('places the marks from the bottom of a vertical slider', () => {
|
|
137
|
+
const { container } = render(UiSlider, {
|
|
138
|
+
props: {
|
|
139
|
+
modelValue: [50],
|
|
140
|
+
step: 50,
|
|
141
|
+
orientation: 'vertical',
|
|
142
|
+
showSteps: true,
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
expect(stepMarks(container).map((mark) => mark.style.bottom)).toEqual([
|
|
147
|
+
'0%',
|
|
148
|
+
'50%',
|
|
149
|
+
'100%',
|
|
150
|
+
]);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
// The track clips what it holds, which would cut the end marks in half
|
|
154
|
+
// where the handle runs to the very ends.
|
|
155
|
+
test('draws the marks outside the track, so the end marks are not cut off', () => {
|
|
156
|
+
const { container } = render(UiSlider, {
|
|
157
|
+
props: { modelValue: [50], showSteps: true },
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const track = container.querySelector('[data-slot="slider-track"]');
|
|
161
|
+
expect(stepMarks(container).length).toBeGreaterThan(0);
|
|
162
|
+
expect(stepMarks(container).some((mark) => track?.contains(mark))).toBe(
|
|
163
|
+
false,
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test('draws the marks at their own interval when it differs from the step', () => {
|
|
168
|
+
const { container } = render(UiSlider, {
|
|
169
|
+
props: {
|
|
170
|
+
modelValue: [50],
|
|
171
|
+
step: 1,
|
|
172
|
+
stepsInterval: 10,
|
|
173
|
+
showSteps: true,
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
expect(stepMarks(container).map((mark) => mark.style.left)).toEqual(
|
|
178
|
+
Array.from({ length: 11 }, (_, index) => `${index * 10}%`),
|
|
179
|
+
);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test('spaces the marks of a fine slider out to a tenth of its range by default', () => {
|
|
183
|
+
const { container } = render(UiSlider, {
|
|
184
|
+
props: { modelValue: [50], step: 1, showSteps: true },
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
expect(stepMarks(container)).toHaveLength(11);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test('keeps an interval as fine as a hundredth of the range', () => {
|
|
191
|
+
const { container } = render(UiSlider, {
|
|
192
|
+
props: { modelValue: [50], step: 1, stepsInterval: 1, showSteps: true },
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
expect(stepMarks(container)).toHaveLength(101);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('falls back to the default spacing for an interval finer than a hundredth of the range', () => {
|
|
199
|
+
const { container } = render(UiSlider, {
|
|
200
|
+
props: {
|
|
201
|
+
modelValue: [50],
|
|
202
|
+
step: 0.5,
|
|
203
|
+
stepsInterval: 0.5,
|
|
204
|
+
showSteps: true,
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
expect(stepMarks(container)).toHaveLength(11);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
defaultStepsInterval,
|
|
4
|
+
stepMarkPercents,
|
|
5
|
+
stepsIntervalOrDefault,
|
|
6
|
+
trackStartEdge,
|
|
7
|
+
} from '../step-marks';
|
|
8
|
+
|
|
9
|
+
describe('stepMarkPercents', () => {
|
|
10
|
+
test('places one mark per step, from the start to the end of the track', () => {
|
|
11
|
+
expect(stepMarkPercents(0, 100, 10)).toEqual([
|
|
12
|
+
0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100,
|
|
13
|
+
]);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('ends with a mark at the maximum when the interval does not divide the range', () => {
|
|
17
|
+
// The handle reaches the maximum too: a step past 90 is clamped to it.
|
|
18
|
+
expect(stepMarkPercents(0, 100, 30)).toEqual([0, 30, 60, 90, 100]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('keeps the last mark at the end of the track for fractional steps', () => {
|
|
22
|
+
const percents = stepMarkPercents(0, 1, 0.1);
|
|
23
|
+
|
|
24
|
+
expect(percents).toHaveLength(11);
|
|
25
|
+
expect(percents.at(-1)).toBe(100);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('measures from min when the range does not start at zero', () => {
|
|
29
|
+
expect(stepMarkPercents(20, 60, 10)).toEqual([0, 25, 50, 75, 100]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('returns no marks for an interval or range that cannot be drawn', () => {
|
|
33
|
+
expect(stepMarkPercents(0, 100, 0)).toEqual([]);
|
|
34
|
+
expect(stepMarkPercents(0, 100, -5)).toEqual([]);
|
|
35
|
+
expect(stepMarkPercents(50, 50, 1)).toEqual([]);
|
|
36
|
+
expect(stepMarkPercents(100, 0, 1)).toEqual([]);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('defaultStepsInterval', () => {
|
|
41
|
+
test('keeps the step when it already gives at most a dot every tenth of the range', () => {
|
|
42
|
+
expect(defaultStepsInterval(0, 100, 10)).toBe(10);
|
|
43
|
+
expect(defaultStepsInterval(0, 100, 30)).toBe(30);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('spaces a fine slider out to a tenth of its range', () => {
|
|
47
|
+
expect(defaultStepsInterval(0, 100, 1)).toBe(10);
|
|
48
|
+
expect(defaultStepsInterval(0, 1, 0.01)).toBe(0.1);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('stays on values the handle can reach when a tenth is not a whole number of steps', () => {
|
|
52
|
+
expect(defaultStepsInterval(0, 100, 3)).toBe(12);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('stepsIntervalOrDefault', () => {
|
|
57
|
+
test('uses the requested gap down to a hundredth of the range', () => {
|
|
58
|
+
expect(stepsIntervalOrDefault(0, 100, 1, 5)).toBe(5);
|
|
59
|
+
expect(stepsIntervalOrDefault(0, 100, 1, 1)).toBe(1);
|
|
60
|
+
expect(stepsIntervalOrDefault(0, 1, 0.01, 0.01)).toBe(0.01);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('uses the default gap when none is requested or it is finer than a hundredth', () => {
|
|
64
|
+
expect(stepsIntervalOrDefault(0, 100, 1)).toBe(10);
|
|
65
|
+
expect(stepsIntervalOrDefault(0, 100, 1, 0.001)).toBe(10);
|
|
66
|
+
expect(stepsIntervalOrDefault(0, 100, 1, 0)).toBe(10);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('keeps a gap of exactly a hundredth when floating-point rounding makes the range a hair larger', () => {
|
|
70
|
+
// 0.4 - 0.1 is 0.30000000000000004 in floating point.
|
|
71
|
+
expect(stepsIntervalOrDefault(0.1, 0.4, 0.003, 0.003)).toBe(0.003);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('holds the hundredth limit on a very small range too', () => {
|
|
75
|
+
expect(stepsIntervalOrDefault(0, 1e-8, 1e-9, 1e-15)).toBe(1e-9);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('trackStartEdge', () => {
|
|
80
|
+
test('a horizontal track starts on the left, or the right when it reads right to left', () => {
|
|
81
|
+
expect(trackStartEdge('horizontal', 'ltr', false)).toBe('left');
|
|
82
|
+
expect(trackStartEdge('horizontal', 'rtl', false)).toBe('right');
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('inverting a horizontal track swaps its start edge', () => {
|
|
86
|
+
expect(trackStartEdge('horizontal', 'ltr', true)).toBe('right');
|
|
87
|
+
expect(trackStartEdge('horizontal', 'rtl', true)).toBe('left');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('a vertical track starts at the bottom, or the top when inverted', () => {
|
|
91
|
+
expect(trackStartEdge('vertical', 'ltr', false)).toBe('bottom');
|
|
92
|
+
expect(trackStartEdge('vertical', 'ltr', true)).toBe('top');
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { UiSliderProps } from './types';
|
|
2
|
+
|
|
3
|
+
/** The track edge the lowest value sits at. */
|
|
4
|
+
export type TrackStartEdge = 'left' | 'right' | 'top' | 'bottom';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Where each mark sits along the track, as a percentage from the start edge:
|
|
8
|
+
* one every `interval` from `min`, and one at `max`.
|
|
9
|
+
* @param min Lowest value of the range.
|
|
10
|
+
* @param max Highest value of the range.
|
|
11
|
+
* @param interval Gap between two marks, in the slider's own units.
|
|
12
|
+
* @returns One percentage per mark, or none when the range or interval cannot
|
|
13
|
+
* be drawn.
|
|
14
|
+
*/
|
|
15
|
+
export function stepMarkPercents(
|
|
16
|
+
min: number,
|
|
17
|
+
max: number,
|
|
18
|
+
interval: number,
|
|
19
|
+
): number[] {
|
|
20
|
+
const range = max - min;
|
|
21
|
+
if (interval <= 0 || range <= 0) return [];
|
|
22
|
+
// The small tolerance keeps a fractional interval such as 0.1 from losing a
|
|
23
|
+
// mark to floating-point rounding.
|
|
24
|
+
const intervalCount = Math.floor(range / interval + 1e-9);
|
|
25
|
+
const percents = Array.from({ length: intervalCount + 1 }, (_, index) =>
|
|
26
|
+
// Rounding drops floating-point noise such as 30.000000000000004.
|
|
27
|
+
Number(((index * interval * 100) / range).toFixed(6)),
|
|
28
|
+
);
|
|
29
|
+
// The handle can always reach max, even when the interval does not divide
|
|
30
|
+
// the range: a step past the last mark is clamped to it.
|
|
31
|
+
return percents.at(-1) === 100 ? percents : [...percents, 100];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The gap between dots: the one the caller asked for, unless it would put the
|
|
36
|
+
* dots closer than a hundredth of the range, where they would run together and
|
|
37
|
+
* could number in the millions. Then the default gap is used instead.
|
|
38
|
+
* @param min Lowest value of the range.
|
|
39
|
+
* @param max Highest value of the range.
|
|
40
|
+
* @param step The slider's stepping interval.
|
|
41
|
+
* @param requested The gap the caller set, if any.
|
|
42
|
+
* @returns The gap between two dots, in the slider's own units.
|
|
43
|
+
*/
|
|
44
|
+
export function stepsIntervalOrDefault(
|
|
45
|
+
min: number,
|
|
46
|
+
max: number,
|
|
47
|
+
step: number,
|
|
48
|
+
requested?: number,
|
|
49
|
+
): number {
|
|
50
|
+
const finestInterval = (max - min) / 100;
|
|
51
|
+
// Relative, so the tolerance never outweighs the limit on a tiny range.
|
|
52
|
+
return requested !== undefined && requested >= finestInterval * (1 - 1e-9)
|
|
53
|
+
? requested
|
|
54
|
+
: defaultStepsInterval(min, max, step);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The gap between dots when the caller sets none: every step, but no closer
|
|
59
|
+
* together than a tenth of the range, so a fine slider gets about 11 dots.
|
|
60
|
+
* The gap stays a whole number of steps, so every dot is a reachable value.
|
|
61
|
+
* @param min Lowest value of the range.
|
|
62
|
+
* @param max Highest value of the range.
|
|
63
|
+
* @param step The slider's stepping interval.
|
|
64
|
+
* @returns The gap between two dots, in the slider's own units.
|
|
65
|
+
*/
|
|
66
|
+
export function defaultStepsInterval(
|
|
67
|
+
min: number,
|
|
68
|
+
max: number,
|
|
69
|
+
step: number,
|
|
70
|
+
): number {
|
|
71
|
+
const tenth = (max - min) / 10;
|
|
72
|
+
if (step <= 0 || step >= tenth) return step;
|
|
73
|
+
// The tolerance keeps 0.1 / 0.01 from rounding up to 11 steps.
|
|
74
|
+
const stepsPerDot = Math.ceil(tenth / step - 1e-9);
|
|
75
|
+
return Number((stepsPerDot * step).toFixed(10));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The edge the track starts from. reka-ui works this out for the handle but
|
|
80
|
+
* does not export it, so this follows the same rule as its `SliderHorizontal`
|
|
81
|
+
* and `SliderVertical`.
|
|
82
|
+
* @param orientation Slider orientation.
|
|
83
|
+
* @param dir Reading direction, already resolved as reka-ui's `useDirection`
|
|
84
|
+
* resolves it.
|
|
85
|
+
* @param inverted Whether the slider is visually inverted.
|
|
86
|
+
* @returns The edge the lowest value sits at.
|
|
87
|
+
*/
|
|
88
|
+
export function trackStartEdge(
|
|
89
|
+
orientation: NonNullable<UiSliderProps['orientation']>,
|
|
90
|
+
dir: NonNullable<UiSliderProps['dir']>,
|
|
91
|
+
inverted: boolean,
|
|
92
|
+
): TrackStartEdge {
|
|
93
|
+
if (orientation === 'vertical') return inverted ? 'top' : 'bottom';
|
|
94
|
+
const startsLeft = (dir === 'ltr') !== inverted;
|
|
95
|
+
return startsLeft ? 'left' : 'right';
|
|
96
|
+
}
|
|
@@ -85,6 +85,38 @@ export interface UiSliderProps {
|
|
|
85
85
|
* @default false
|
|
86
86
|
*/
|
|
87
87
|
required?: boolean;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Shows each handle's current value in text, above the handle (beside it
|
|
91
|
+
* when vertical), moving with it while dragging. The text is hidden from
|
|
92
|
+
* screen readers, which read the value from the handle itself. A vertical
|
|
93
|
+
* slider reserves no room beside itself, so leave space for the text there.
|
|
94
|
+
* @default false
|
|
95
|
+
*/
|
|
96
|
+
showValue?: boolean;
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Turns a value into text, e.g. `(value) => \`${value}%\``. Used for the text
|
|
100
|
+
* `showValue` shows, and announced by screen readers as the handle's value
|
|
101
|
+
* (`aria-valuetext`). Without it the plain number is used.
|
|
102
|
+
*/
|
|
103
|
+
formatValue?: (value: number) => string;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Shows a dot on the track for every value the handle can reach, but no
|
|
107
|
+
* closer together than a tenth of the range, plus one at `max`. Set
|
|
108
|
+
* `stepsInterval` to choose the gap yourself.
|
|
109
|
+
* @default false
|
|
110
|
+
*/
|
|
111
|
+
showSteps?: boolean;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The gap between two dots drawn by `showSteps`, in the slider's own units.
|
|
115
|
+
* A gap smaller than a hundredth of the range falls back to the default.
|
|
116
|
+
* @default every `step`, but no closer than a tenth of the range: a 0 to 100
|
|
117
|
+
* slider in steps of 1 gets a dot every 10
|
|
118
|
+
*/
|
|
119
|
+
stepsInterval?: number;
|
|
88
120
|
}
|
|
89
121
|
|
|
90
122
|
export interface UiSliderEmits {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { PaginationRootEmits, PaginationRootProps } from 'reka-ui';
|
|
3
|
+
import type { HTMLAttributes } from 'vue';
|
|
4
|
+
import { reactiveOmit } from '@vueuse/core';
|
|
5
|
+
import { PaginationRoot, useForwardPropsEmits } from 'reka-ui';
|
|
6
|
+
import { cn } from '@/lib/utils';
|
|
7
|
+
|
|
8
|
+
const props = defineProps<
|
|
9
|
+
PaginationRootProps & { class?: HTMLAttributes['class'] }
|
|
10
|
+
>();
|
|
11
|
+
const emits = defineEmits<PaginationRootEmits>();
|
|
12
|
+
|
|
13
|
+
const delegatedProps = reactiveOmit(props, 'class');
|
|
14
|
+
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<template>
|
|
18
|
+
<PaginationRoot
|
|
19
|
+
v-slot="slotProps"
|
|
20
|
+
data-slot="pagination"
|
|
21
|
+
v-bind="forwarded"
|
|
22
|
+
:class="cn('mx-auto flex w-full justify-center', props.class)"
|
|
23
|
+
>
|
|
24
|
+
<slot v-bind="slotProps" />
|
|
25
|
+
</PaginationRoot>
|
|
26
|
+
</template>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { PaginationListProps } from 'reka-ui';
|
|
3
|
+
import type { HTMLAttributes } from 'vue';
|
|
4
|
+
import { reactiveOmit } from '@vueuse/core';
|
|
5
|
+
import { PaginationList } from 'reka-ui';
|
|
6
|
+
import { cn } from '@/lib/utils';
|
|
7
|
+
|
|
8
|
+
const props = defineProps<
|
|
9
|
+
PaginationListProps & { class?: HTMLAttributes['class'] }
|
|
10
|
+
>();
|
|
11
|
+
|
|
12
|
+
const delegatedProps = reactiveOmit(props, 'class');
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<PaginationList
|
|
17
|
+
v-slot="slotProps"
|
|
18
|
+
data-slot="pagination-content"
|
|
19
|
+
v-bind="delegatedProps"
|
|
20
|
+
:class="cn('flex flex-row items-center gap-1', props.class)"
|
|
21
|
+
>
|
|
22
|
+
<slot v-bind="slotProps" />
|
|
23
|
+
</PaginationList>
|
|
24
|
+
</template>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { PaginationEllipsisProps } from 'reka-ui';
|
|
3
|
+
import type { HTMLAttributes } from 'vue';
|
|
4
|
+
import { reactiveOmit } from '@vueuse/core';
|
|
5
|
+
import { PaginationEllipsis } from 'reka-ui';
|
|
6
|
+
import { UiIcon } from '@/components/UiIcon';
|
|
7
|
+
import { EllipsisIcon } from '@/icons/lucide';
|
|
8
|
+
import { cn } from '@/lib/utils';
|
|
9
|
+
|
|
10
|
+
const props = defineProps<
|
|
11
|
+
PaginationEllipsisProps & { class?: HTMLAttributes['class'] }
|
|
12
|
+
>();
|
|
13
|
+
|
|
14
|
+
const delegatedProps = reactiveOmit(props, 'class');
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<template>
|
|
18
|
+
<PaginationEllipsis
|
|
19
|
+
data-slot="pagination-ellipsis"
|
|
20
|
+
v-bind="delegatedProps"
|
|
21
|
+
:class="
|
|
22
|
+
cn('flex size-9 items-center justify-center text-foreground', props.class)
|
|
23
|
+
"
|
|
24
|
+
>
|
|
25
|
+
<slot>
|
|
26
|
+
<UiIcon :name="EllipsisIcon" size="s" />
|
|
27
|
+
<span class="sr-only">More pages</span>
|
|
28
|
+
</slot>
|
|
29
|
+
</PaginationEllipsis>
|
|
30
|
+
</template>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { PaginationFirstProps } from 'reka-ui';
|
|
3
|
+
import type { HTMLAttributes } from 'vue';
|
|
4
|
+
import { reactiveOmit } from '@vueuse/core';
|
|
5
|
+
import { PaginationFirst } from 'reka-ui';
|
|
6
|
+
import { buttonVariants } from '@/components/core/button';
|
|
7
|
+
import { UiIcon } from '@/components/UiIcon';
|
|
8
|
+
import { ChevronsLeftIcon } from '@/icons/lucide';
|
|
9
|
+
import { cn } from '@/lib/utils';
|
|
10
|
+
|
|
11
|
+
const props = defineProps<
|
|
12
|
+
PaginationFirstProps & { class?: HTMLAttributes['class'] }
|
|
13
|
+
>();
|
|
14
|
+
|
|
15
|
+
const delegatedProps = reactiveOmit(props, 'class');
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<template>
|
|
19
|
+
<PaginationFirst
|
|
20
|
+
data-slot="pagination-first"
|
|
21
|
+
v-bind="delegatedProps"
|
|
22
|
+
:class="
|
|
23
|
+
cn(buttonVariants({ variant: 'ghost' }), 'min-w-9 px-2', props.class)
|
|
24
|
+
"
|
|
25
|
+
>
|
|
26
|
+
<slot>
|
|
27
|
+
<UiIcon :name="ChevronsLeftIcon" size="s" />
|
|
28
|
+
</slot>
|
|
29
|
+
</PaginationFirst>
|
|
30
|
+
</template>
|