@purpurds/slider 5.11.0 → 5.11.1

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,16 +1,8 @@
1
1
  import React from "react";
2
- import { useArgs } from "@storybook/client-api";
2
+ import { useArgs } from "@storybook/preview-api";
3
3
  import type { Meta, StoryObj } from "@storybook/react";
4
4
 
5
- import { Slider } from "./slider";
6
-
7
- const meta: Meta<typeof Slider> = {
8
- title: "Inputs/Slider",
9
- component: Slider,
10
- };
11
-
12
- export default meta;
13
- type Story = StoryObj<typeof Slider>;
5
+ import { ORIENTATION, Slider } from "./slider";
14
6
 
15
7
  const decorators: Story["decorators"] = [
16
8
  (Story) => (
@@ -20,30 +12,49 @@ const decorators: Story["decorators"] = [
20
12
  ),
21
13
  ];
22
14
 
23
- const parameters = {
24
- // Design is missing and component is in Alpha-phase.
25
- // TODO: [Flamingo] - Uncomment once design is approved
26
- // design: [
27
- // {
28
- // name: "Slider",
29
- // type: "figma",
30
- // url: "https://www.figma.com/file/...",
31
- // },
32
- // ],
33
- };
34
-
35
- export const ControlledSingle: Story = {
15
+ const meta = {
16
+ title: "Inputs/Slider",
17
+ component: Slider,
18
+ decorators,
19
+ parameters: {
20
+ // Design is missing and component is in Alpha-phase.
21
+ // TODO: [Flamingo] - Uncomment once design is approved
22
+ // design: [
23
+ // {
24
+ // name: "Slider",
25
+ // type: "figma",
26
+ // url: "https://www.figma.com/file/...",
27
+ // },
28
+ // ],
29
+ },
30
+ argTypes: {
31
+ orientation: {
32
+ table: {
33
+ type: {
34
+ summary: ORIENTATION.map((x) => `"${x}"`).join(" | "),
35
+ },
36
+ },
37
+ },
38
+ },
36
39
  args: {
37
40
  "data-testid": "test-id",
38
41
  "aria-label": "Slider thumb",
39
- id: "slider",
40
42
  max: 100,
41
43
  min: 0,
42
- minStepsBetweenThumbs: 0,
43
44
  name: "slider",
45
+ id: "slider",
46
+ orientation: "horizontal",
44
47
  step: 1,
48
+ minStepsBetweenThumbs: 0,
49
+ },
50
+ } satisfies Meta<typeof Slider>;
51
+
52
+ export default meta;
53
+ type Story = StoryObj<typeof Slider>;
54
+
55
+ export const ControlledSingle: Story = {
56
+ args: {
45
57
  value: [25],
46
- orientation: "horizontal",
47
58
  },
48
59
  argTypes: {
49
60
  defaultValue: {
@@ -52,8 +63,6 @@ export const ControlledSingle: Story = {
52
63
  },
53
64
  },
54
65
  },
55
- parameters,
56
- decorators,
57
66
  render: ({ ...args }) => {
58
67
  const [{ value = args.defaultValue }, updateArgs] = useArgs(); // eslint-disable-line react-hooks/rules-of-hooks
59
68
  const setValue = (value: [number] | [number, number]) => updateArgs({ value });
@@ -69,16 +78,7 @@ export const ControlledSingle: Story = {
69
78
 
70
79
  export const ControlledMulti: Story = {
71
80
  args: {
72
- "data-testid": "test-id",
73
- "aria-label": "Slider thumb",
74
- id: "slider",
75
- max: 100,
76
- min: 0,
77
- minStepsBetweenThumbs: 0,
78
- name: "slider",
79
- step: 1,
80
81
  value: [25, 75],
81
- orientation: "horizontal",
82
82
  },
83
83
  argTypes: {
84
84
  defaultValue: {
@@ -87,8 +87,6 @@ export const ControlledMulti: Story = {
87
87
  },
88
88
  },
89
89
  },
90
- parameters,
91
- decorators,
92
90
  render: ({ ...args }) => {
93
91
  const [{ value = args.defaultValue }, updateArgs] = useArgs(); // eslint-disable-line react-hooks/rules-of-hooks
94
92
  const setValue = (value: [number] | [number, number]) => updateArgs({ value });
@@ -105,15 +103,7 @@ export const ControlledMulti: Story = {
105
103
 
106
104
  export const UncontrolledSingle: Story = {
107
105
  args: {
108
- "data-testid": "test-id",
109
- "aria-label": "Slider thumb",
110
106
  defaultValue: [50],
111
- max: 100,
112
- min: 0,
113
- minStepsBetweenThumbs: 0,
114
- name: "slider",
115
- step: 1,
116
- orientation: "horizontal",
117
107
  onValueChange: undefined,
118
108
  },
119
109
  argTypes: {
@@ -128,8 +118,6 @@ export const UncontrolledSingle: Story = {
128
118
  },
129
119
  },
130
120
  },
131
- parameters,
132
- decorators,
133
121
  render: ({ ...args }) => {
134
122
  return (
135
123
  <form style={{ height: "100%" }}>
@@ -142,15 +130,7 @@ export const UncontrolledSingle: Story = {
142
130
 
143
131
  export const UncontrolledMulti: Story = {
144
132
  args: {
145
- "data-testid": "test-id",
146
- "aria-label": "Slider thumb",
147
133
  defaultValue: [25, 75],
148
- max: 100,
149
- min: 0,
150
- minStepsBetweenThumbs: 0,
151
- name: "slider",
152
- step: 1,
153
- orientation: "horizontal",
154
134
  },
155
135
  argTypes: {
156
136
  onValueChange: {
@@ -164,8 +144,6 @@ export const UncontrolledMulti: Story = {
164
144
  },
165
145
  },
166
146
  },
167
- parameters,
168
- decorators,
169
147
  render: ({ ...args }) => {
170
148
  return (
171
149
  <form style={{ height: "100%" }}>
package/src/slider.tsx CHANGED
@@ -6,6 +6,7 @@ import styles from "./slider.module.scss";
6
6
  const cx = c.bind(styles);
7
7
 
8
8
  type SliderValue = [number] | [number, number];
9
+ export const ORIENTATION = ["horizontal", "vertical"] as const;
9
10
 
10
11
  export type SliderProps<T extends SliderValue> = {
11
12
  ["data-testid"]?: string;
@@ -14,7 +15,10 @@ export type SliderProps<T extends SliderValue> = {
14
15
  /* Human-readable text alternative for aria-valuenow (aria-valuenow is set to `value` by radix under the hood). Use when the numeric value alone doesn't clearly represent the actual value. */
15
16
  ["aria-valuetext"]: string;
16
17
  className?: string;
17
- /* The value of the slider when initially rendered. Use when you do not need to control the state of the slider. */
18
+ /**
19
+ * The value of the slider when initially rendered. Use when you do not need to control the state of the slider.
20
+ `T = <T extends [number] | [number, number]>`
21
+ */
18
22
  defaultValue?: T;
19
23
  /* The id of the slider. */
20
24
  id?: string;
@@ -27,7 +31,7 @@ export type SliderProps<T extends SliderValue> = {
27
31
  /* The name of the slider. Submitted with its owning form as part of a name/value pair. */
28
32
  name?: string;
29
33
  /* The orientation of the slider. */
30
- orientation?: "horizontal" | "vertical";
34
+ orientation?: (typeof ORIENTATION)[number];
31
35
  /* The stepping interval. */
32
36
  step?: number;
33
37
  /* The controlled value of the slider. Must be used in conjunction with onValueChange. */