-
-
Notifications
You must be signed in to change notification settings - Fork 589
Expand file tree
/
Copy pathRSlider.stories.ts
More file actions
163 lines (142 loc) · 5.48 KB
/
Copy pathRSlider.stories.ts
File metadata and controls
163 lines (142 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import type { Meta, StoryObj } from "@storybook/vue3-vite";
import { ref } from "vue";
import RSlider from "./RSlider.vue";
const meta: Meta<typeof RSlider> = {
title: "Forms/RSlider",
component: RSlider,
// RSlider has no visible label, so every instance needs `ariaLabel`.
args: { ariaLabel: "Value" },
argTypes: {
min: { control: "number" },
max: { control: "number" },
step: { control: "number" },
color: { control: "text" },
valuePosition: {
control: "inline-radio",
options: ["none", "left", "right", "thumb"],
},
valueSuffix: { control: "text" },
showTicks: { control: "boolean" },
disabled: { control: "boolean" },
readonly: { control: "boolean" },
},
render: (args) => ({
components: { RSlider },
setup: () => {
const value = ref(args.modelValue ?? 50);
return { args, value };
},
template: `
<div style="padding:24px;min-width:380px">
<RSlider v-bind="args" v-model="value" />
<div style="margin-top:12px;font-size:11px;color:var(--r-color-fg-muted)">
value: {{ value }}
</div>
</div>
`,
}),
};
export default meta;
type Story = StoryObj<typeof RSlider>;
// ── Defaults ────────────────────────────────────────────────────────
export const Default: Story = { args: { modelValue: 50 } };
// ── Value badges ───────────────────────────────────────────────────
export const ValueRight: Story = {
name: "Badge · right",
args: { modelValue: 42, valuePosition: "right", valueSuffix: "%" },
};
export const ValueLeft: Story = {
name: "Badge · left",
args: { modelValue: 42, valuePosition: "left", valueSuffix: "%" },
};
export const ValueThumb: Story = {
name: "Badge · floating thumb",
args: { modelValue: 30, valuePosition: "thumb", valueSuffix: "%" },
};
// ── Steps + ticks ──────────────────────────────────────────────────
export const Stepped: Story = {
name: "Stepped (10s)",
args: { modelValue: 30, step: 10, showTicks: true },
};
export const FineSteps: Story = {
name: "Fine steps (0.5)",
args: { modelValue: 50, min: 0, max: 100, step: 0.5 },
};
// ── Range examples ─────────────────────────────────────────────────
export const Volume: Story = {
name: "Volume (0–100)",
args: {
modelValue: 65,
valuePosition: "right",
valueSuffix: "%",
color: "accent",
},
};
export const Temperature: Story = {
name: "Temperature",
args: {
modelValue: 22,
min: 16,
max: 30,
step: 1,
valuePosition: "thumb",
valueSuffix: "°",
color: "warning",
},
};
// ── Color tones ────────────────────────────────────────────────────
export const ColorLadder: Story = {
name: "Color ladder",
render: () => ({
components: { RSlider },
setup: () => ({
primary: ref(70),
success: ref(70),
warning: ref(70),
danger: ref(70),
info: ref(70),
}),
template: `
<div style="display:flex;flex-direction:column;gap:18px;padding:24px;min-width:380px">
<RSlider v-model="primary" color="primary" value-position="right" value-suffix="%" aria-label="Primary" />
<RSlider v-model="success" color="success" value-position="right" value-suffix="%" aria-label="Success" />
<RSlider v-model="warning" color="warning" value-position="right" value-suffix="%" aria-label="Warning" />
<RSlider v-model="danger" color="danger" value-position="right" value-suffix="%" aria-label="Danger" />
<RSlider v-model="info" color="info" value-position="right" value-suffix="%" aria-label="Info" />
</div>
`,
}),
};
// ── States ─────────────────────────────────────────────────────────
export const Disabled: Story = {
args: { modelValue: 40, disabled: true, valuePosition: "right" },
};
export const Readonly: Story = {
args: { modelValue: 40, readonly: true, valuePosition: "right" },
};
// ── Commit-on-end pattern ──────────────────────────────────────────
export const CommitOnEnd: Story = {
name: "Commit-on-end (@end)",
render: () => ({
components: { RSlider },
setup: () => {
const preview = ref(50);
const committed = ref(50);
function onEnd(v: number) {
committed.value = v;
}
return { preview, committed, onEnd };
},
template: `
<div style="padding:24px;min-width:380px;display:flex;flex-direction:column;gap:10px">
<RSlider v-model="preview" value-position="thumb" value-suffix="%" aria-label="Volume" @end="onEnd" />
<div style="font:12px sans-serif;color:var(--r-color-fg-muted)">
previewing: {{ preview }} · last committed: {{ committed }}
</div>
<div style="font:11px sans-serif;color:var(--r-color-fg-faint)">
Drag the thumb — preview updates live, committed only fires on release.
</div>
</div>
`,
}),
};