@moises.ai/design-system 3.11.16 → 3.11.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moises.ai/design-system",
3
- "version": "3.11.16",
3
+ "version": "3.11.18",
4
4
  "description": "Design System package based on @radix-ui/themes with custom defaults",
5
5
  "private": false,
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
- import { Box, Flex, Text, Tooltip } from '@radix-ui/themes'
1
+ import { useCallback } from 'react'
2
+ import { Box, Flex, Text } from '@radix-ui/themes'
2
3
  import { Slider as SliderRadix } from 'radix-ui'
3
- import { InfoIcon } from '../../icons/InfoIcon'
4
4
  import styles from './Slider.module.css'
5
5
  import classNames from 'classnames'
6
6
  import { TooltipWithInfoIcon } from '../TooltipWithInfoIcon/TooltipWithInfoIcon'
@@ -20,18 +20,80 @@ export const Slider = ({
20
20
  disabled = false,
21
21
  highContrast = false,
22
22
  markers = [],
23
+ orientation = 'horizontal',
24
+ horizontalWidth = '100%',
25
+ verticalHeight = 200,
26
+ scrollWheel = false,
23
27
  ...props
24
28
  }) => {
29
+ const { onWheel: onWheelProp, ...rootProps } = props
30
+ const isVertical = orientation === 'vertical'
31
+
25
32
  // Calculate marker positions as percentages
26
33
  const getMarkerPosition = (markerValue) => {
27
34
  return ((markerValue - min) / (max - min)) * 100
28
35
  }
29
36
 
37
+ const handleWheel = useCallback(
38
+ (event) => {
39
+ onWheelProp?.(event)
40
+ if (disabled || !handleValueChange || event.defaultPrevented) return
41
+ const primary =
42
+ isVertical
43
+ ? event.deltaY
44
+ : Math.abs(event.deltaX) > Math.abs(event.deltaY)
45
+ ? event.deltaX
46
+ : event.deltaY
47
+ if (primary === 0) return
48
+ event.preventDefault()
49
+ const current = value?.[0] ?? min
50
+ const direction = primary < 0 ? 1 : -1
51
+ const next = Math.min(
52
+ max,
53
+ Math.max(min, current + direction * step),
54
+ )
55
+ if (next !== current) handleValueChange([next])
56
+ },
57
+ [
58
+ disabled,
59
+ handleValueChange,
60
+ isVertical,
61
+ max,
62
+ min,
63
+ onWheelProp,
64
+ step,
65
+ value,
66
+ ],
67
+ )
68
+
69
+ const verticalHeightStyle =
70
+ typeof verticalHeight === 'number'
71
+ ? `${verticalHeight}px`
72
+ : verticalHeight
73
+ const horizontalWidthStyle =
74
+ typeof horizontalWidth === 'number'
75
+ ? `${horizontalWidth}px`
76
+ : horizontalWidth
77
+
30
78
  return (
31
- <Box width="100%">
79
+ <Box
80
+ width={isVertical ? '100%' : horizontalWidthStyle}
81
+ className={classNames(isVertical && styles.boxVertical)}
82
+ style={
83
+ isVertical
84
+ ? { ['--slider-vertical-height']: verticalHeightStyle }
85
+ : undefined
86
+ }
87
+ >
32
88
  {title && (
33
- <Flex mb="2" justify="between" align="center">
34
- <Flex align="center" gap="2">
89
+ <Flex
90
+ mb="2"
91
+ width="100%"
92
+ justify={isVertical ? 'center' : 'between'}
93
+ align="center"
94
+ gap="2"
95
+ >
96
+ <Flex align="center" gap="2" wrap="wrap" justify="center">
35
97
  <Text size="2" style={{ color: 'var(--white)' }}>
36
98
  {title}
37
99
  </Text>
@@ -40,8 +102,17 @@ export const Slider = ({
40
102
  <TooltipWithInfoIcon content={tooltip} />
41
103
  </Flex>
42
104
  )}
105
+ {isVertical && info && (
106
+ <Text
107
+ size="2"
108
+ weight="regular"
109
+ style={{ color: 'var(--neutral-alpha-9)' }}
110
+ >
111
+ {info}
112
+ </Text>
113
+ )}
43
114
  </Flex>
44
- {info && (
115
+ {!isVertical && info && (
45
116
  <Text
46
117
  size="2"
47
118
  weight="regular"
@@ -52,7 +123,7 @@ export const Slider = ({
52
123
  )}
53
124
  </Flex>
54
125
  )}
55
- <Flex direction="column">
126
+ <Flex direction="column" align={isVertical ? 'center' : undefined}>
56
127
  <SliderRadix.Root
57
128
  min={min}
58
129
  max={max}
@@ -60,15 +131,27 @@ export const Slider = ({
60
131
  value={value}
61
132
  onValueChange={handleValueChange}
62
133
  disabled={disabled}
63
- className={className}
64
- {...props}
134
+ orientation={orientation}
135
+ className={classNames(styles.sliderRoot, className, {
136
+ [styles.sliderRootVertical]: isVertical,
137
+ })}
138
+ onWheel={scrollWheel ? handleWheel : onWheelProp}
139
+ {...rootProps}
65
140
  >
66
- <Flex className={styles.sliderContainer}>
141
+ <Flex
142
+ className={classNames(styles.sliderContainer, {
143
+ [styles.sliderContainerVertical]: isVertical,
144
+ })}
145
+ >
67
146
  <SliderRadix.Track
68
147
  className={classNames(styles.sliderTrack, {
69
148
  [styles.sliderTrackSize1]: size === '1',
70
149
  [styles.sliderTrackSize2]: size === '2',
71
150
  [styles.sliderTrackSize3]: size === '3',
151
+ [styles.sliderTrackVertical]: isVertical,
152
+ [styles.sliderTrackVerticalSize1]: isVertical && size === '1',
153
+ [styles.sliderTrackVerticalSize2]: isVertical && size === '2',
154
+ [styles.sliderTrackVerticalSize3]: isVertical && size === '3',
72
155
  })}
73
156
  >
74
157
  <SliderRadix.Range
@@ -96,10 +179,17 @@ export const Slider = ({
96
179
  key={index}
97
180
  className={classNames(styles.marker, {
98
181
  [styles.markerSize3]: size === '3',
182
+ [styles.markerVertical]: isVertical,
99
183
  })}
100
- style={{
101
- left: `${getMarkerPosition(markerValue)}%`,
102
- }}
184
+ style={
185
+ isVertical
186
+ ? {
187
+ bottom: `${getMarkerPosition(markerValue)}%`,
188
+ }
189
+ : {
190
+ left: `${getMarkerPosition(markerValue)}%`,
191
+ }
192
+ }
103
193
  />
104
194
  ))}
105
195
  </div>
@@ -18,6 +18,12 @@
18
18
  position: relative;
19
19
  }
20
20
  }
21
+ .boxVertical {
22
+ display: flex;
23
+ flex-direction: column;
24
+ align-items: center;
25
+ }
26
+
21
27
  .sliderRoot {
22
28
  position: relative;
23
29
  display: flex;
@@ -26,6 +32,15 @@
26
32
  touch-action: none;
27
33
  }
28
34
 
35
+ .sliderRootVertical {
36
+ flex-direction: column;
37
+ align-items: center;
38
+ width: max-content;
39
+ max-width: 100%;
40
+ margin-inline: auto;
41
+ min-height: var(--slider-vertical-height, 200px);
42
+ }
43
+
29
44
  .sliderTrack {
30
45
  position: relative;
31
46
  flex-grow: 1;
@@ -53,16 +68,47 @@
53
68
  cursor: default;
54
69
  }
55
70
 
71
+ /* Radix thumb outer wrapper: só recebe `bottom`; centraliza no trilho vertical */
72
+ .sliderTrack[data-orientation='vertical'] > span:not([data-orientation]) {
73
+ left: 50% !important;
74
+ transform: translate(-50%, 50%) !important;
75
+ }
76
+
77
+ .sliderTrackVertical {
78
+ flex: 1 1 auto;
79
+ width: 100%;
80
+ height: 100%;
81
+ min-height: 0;
82
+ align-self: center;
83
+ }
84
+
85
+ .sliderTrackVerticalSize1 {
86
+ width: 4px;
87
+ }
88
+
89
+ .sliderTrackVerticalSize2 {
90
+ width: 6px;
91
+ }
92
+
93
+ .sliderTrackVerticalSize3 {
94
+ width: 10px;
95
+ }
96
+
56
97
  .sliderRange {
57
98
  position: absolute;
58
- height: 100%;
59
- width: var(--radix-slider-range);
60
99
  border-radius: 9999px;
61
- /* background-color: var(--aqua-alpha-8); */
62
100
  &:hover {
63
101
  cursor: pointer;
64
102
  }
65
103
  }
104
+
105
+ .sliderRange[data-orientation='horizontal'] {
106
+ height: 100%;
107
+ }
108
+
109
+ .sliderRange[data-orientation='vertical'] {
110
+ width: 100%;
111
+ }
66
112
  .sliderRangeAccent {
67
113
  background-color: var(--aqua-alpha-8);
68
114
  }
@@ -117,6 +163,13 @@
117
163
  top: 1px;
118
164
  }
119
165
 
166
+ .sliderThumb[data-orientation='vertical'] {
167
+ left: 50%;
168
+ top: 50%;
169
+ right: auto;
170
+ transform: translate(-50%, -50%);
171
+ }
172
+
120
173
  .sliderThumb[data-disabled] {
121
174
  border: 1px solid var(--neutral-7);
122
175
  background: var(--neutral-2);
@@ -133,6 +186,16 @@
133
186
  }
134
187
  }
135
188
 
189
+ .sliderContainerVertical {
190
+ flex: 1;
191
+ flex-direction: column;
192
+ align-items: stretch;
193
+ justify-content: center;
194
+ min-height: var(--slider-vertical-height, 200px);
195
+ width: max-content;
196
+ max-width: 100%;
197
+ }
198
+
136
199
  .markersContainer {
137
200
  position: absolute;
138
201
  top: 0;
@@ -154,6 +217,17 @@
154
217
  z-index: 1;
155
218
  }
156
219
 
220
+ .markerVertical {
221
+ width: 12px;
222
+ height: 1px;
223
+ left: 50%;
224
+ transform: translate(-50%, 50%);
225
+ }
226
+
157
227
  .markerSize3 {
158
228
  height: 18px;
159
229
  }
230
+
231
+ .markerVertical.markerSize3 {
232
+ width: 18px;
233
+ }
@@ -1,3 +1,4 @@
1
+ import { useState } from 'react'
1
2
  import { Flex } from '@radix-ui/themes'
2
3
  import { Slider } from './Slider'
3
4
 
@@ -25,7 +26,17 @@ import { Slider } from '@moises.ai/design-system'
25
26
  step={1}
26
27
  disabled={false}
27
28
  size="2"
28
- />
29
+ orientation="horizontal"
30
+ horizontalWidth={320}
31
+ scrollWheel={false}
32
+ />
33
+
34
+ <Slider
35
+ orientation="vertical"
36
+ verticalHeight={220}
37
+ value={[50]}
38
+ handleValueChange={(value) => console.log(value)}
39
+ />
29
40
  \`\`\`
30
41
 
31
42
  ## Component API
@@ -45,6 +56,10 @@ import { Slider } from '@moises.ai/design-system'
45
56
  highContrast: boolean, // Whether the slider is in high contrast mode
46
57
  size: '1' | '2' | '3', // Size of the slider (1: small, 2: medium, 3: large)
47
58
  markers: number[], // Array of values where visual markers should be displayed
59
+ orientation: 'horizontal' | 'vertical', // Slider axis; vertical uses verticalHeight for track
60
+ horizontalWidth: number | string, // Track width when horizontal (number = px, or CSS length)
61
+ verticalHeight: number | string, // Track height when vertical (number = px, or CSS length)
62
+ scrollWheel: boolean, // Wheel/trackpad adjusts value on hover/focus (use controlled value)
48
63
  }
49
64
  \`\`\`
50
65
  `,
@@ -111,6 +126,24 @@ import { Slider } from '@moises.ai/design-system'
111
126
  control: 'object',
112
127
  description: 'Array of values where visual markers should be displayed',
113
128
  },
129
+ orientation: {
130
+ control: 'select',
131
+ options: ['horizontal', 'vertical'],
132
+ description: 'Slider axis',
133
+ },
134
+ horizontalWidth: {
135
+ control: 'number',
136
+ description: 'Track width in px when orientation is horizontal (or pass a CSS length string)',
137
+ },
138
+ verticalHeight: {
139
+ control: 'number',
140
+ description: 'Track height in px when orientation is vertical (or pass a CSS length string)',
141
+ },
142
+ scrollWheel: {
143
+ control: 'boolean',
144
+ description:
145
+ 'When true, wheel/trackpad adjusts value on hover/focus (use controlled value)',
146
+ },
114
147
  },
115
148
  }
116
149
 
@@ -123,6 +156,10 @@ export const Default = {
123
156
  color: 'accent',
124
157
  highContrast: false,
125
158
  size: '2',
159
+ orientation: 'horizontal',
160
+ horizontalWidth: 300,
161
+ verticalHeight: 200,
162
+ scrollWheel: false,
126
163
  },
127
164
  render: (args) => (
128
165
  <Flex width="300px">
@@ -197,3 +234,44 @@ export const WithMarkersDifferentSizes = {
197
234
  </Flex>
198
235
  ),
199
236
  }
237
+
238
+ export const Vertical = {
239
+ render: () => {
240
+ const [v, setV] = useState([35])
241
+ return (
242
+ <Flex height="280px" align="center" justify="center">
243
+ <Slider
244
+ title="Vertical"
245
+ orientation="vertical"
246
+ verticalHeight={220}
247
+ value={v}
248
+ handleValueChange={setV}
249
+ info={`${v[0]}%`}
250
+ color="accent"
251
+ size="2"
252
+ markers={[0, 25, 50, 75, 100]}
253
+ />
254
+ </Flex>
255
+ )
256
+ },
257
+ }
258
+
259
+ export const ScrollWheel = {
260
+ render: () => {
261
+ const [v, setV] = useState([50])
262
+ return (
263
+ <Flex width="320px" direction="column" gap="2">
264
+ <Slider
265
+ title="Scroll wheel (hover + roll)"
266
+ value={v}
267
+ handleValueChange={setV}
268
+ info={`${v[0]}`}
269
+ scrollWheel
270
+ min={0}
271
+ max={100}
272
+ step={1}
273
+ />
274
+ </Flex>
275
+ )
276
+ },
277
+ }