@moises.ai/design-system 3.11.14 → 3.11.17
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,32 +1,11 @@
|
|
|
1
1
|
import classNames from 'classnames'
|
|
2
2
|
import { ContextMenu as ContextMenuRadix } from 'radix-ui'
|
|
3
|
-
import React, { forwardRef, memo
|
|
3
|
+
import React, { forwardRef, memo } from 'react'
|
|
4
4
|
import { createRenderItem, styles } from '../../lib/menu'
|
|
5
5
|
import { CanvasContextMenuTrigger } from './CanvasContextMenuTrigger'
|
|
6
6
|
|
|
7
7
|
const renderOption = createRenderItem(ContextMenuRadix)
|
|
8
8
|
|
|
9
|
-
function useLogPropChanged(label, props) {
|
|
10
|
-
const prevPropsRef = useRef({})
|
|
11
|
-
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
const prevProps = prevPropsRef.current
|
|
14
|
-
prevPropsRef.current = props
|
|
15
|
-
|
|
16
|
-
const changes = {}
|
|
17
|
-
|
|
18
|
-
for (const key in props) {
|
|
19
|
-
if (props[key] !== prevProps[key]) {
|
|
20
|
-
changes[key] = [prevProps[key], props[key]]
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (Object.keys(changes).length > 0) {
|
|
25
|
-
console.log(`>>> ${label}`, changes)
|
|
26
|
-
}
|
|
27
|
-
}, [label, props])
|
|
28
|
-
}
|
|
29
|
-
|
|
30
9
|
/**
|
|
31
10
|
* Variant of ContextMenu for programmatic opening from non-DOM event sources
|
|
32
11
|
* (e.g. Pixi canvas). Instead of wrapping a visible trigger element, it exposes
|
|
@@ -55,16 +34,6 @@ export const CanvasContextMenu = memo(
|
|
|
55
34
|
},
|
|
56
35
|
ref,
|
|
57
36
|
) {
|
|
58
|
-
useLogPropChanged('CanvasContextMenu', {
|
|
59
|
-
options,
|
|
60
|
-
className,
|
|
61
|
-
size,
|
|
62
|
-
side,
|
|
63
|
-
align,
|
|
64
|
-
onSelectionChange,
|
|
65
|
-
closeOnSelect,
|
|
66
|
-
})
|
|
67
|
-
|
|
68
37
|
return (
|
|
69
38
|
<ContextMenuRadix.Root>
|
|
70
39
|
<ContextMenuRadix.Trigger asChild>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
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,75 @@ export const Slider = ({
|
|
|
20
20
|
disabled = false,
|
|
21
21
|
highContrast = false,
|
|
22
22
|
markers = [],
|
|
23
|
+
orientation = 'horizontal',
|
|
24
|
+
verticalHeight = 200,
|
|
25
|
+
scrollWheel = false,
|
|
23
26
|
...props
|
|
24
27
|
}) => {
|
|
28
|
+
const { onWheel: onWheelProp, ...rootProps } = props
|
|
29
|
+
const isVertical = orientation === 'vertical'
|
|
30
|
+
|
|
25
31
|
// Calculate marker positions as percentages
|
|
26
32
|
const getMarkerPosition = (markerValue) => {
|
|
27
33
|
return ((markerValue - min) / (max - min)) * 100
|
|
28
34
|
}
|
|
29
35
|
|
|
36
|
+
const handleWheel = useCallback(
|
|
37
|
+
(event) => {
|
|
38
|
+
onWheelProp?.(event)
|
|
39
|
+
if (disabled || !handleValueChange || event.defaultPrevented) return
|
|
40
|
+
const primary =
|
|
41
|
+
isVertical
|
|
42
|
+
? event.deltaY
|
|
43
|
+
: Math.abs(event.deltaX) > Math.abs(event.deltaY)
|
|
44
|
+
? event.deltaX
|
|
45
|
+
: event.deltaY
|
|
46
|
+
if (primary === 0) return
|
|
47
|
+
event.preventDefault()
|
|
48
|
+
const current = value?.[0] ?? min
|
|
49
|
+
const direction = primary < 0 ? 1 : -1
|
|
50
|
+
const next = Math.min(
|
|
51
|
+
max,
|
|
52
|
+
Math.max(min, current + direction * step),
|
|
53
|
+
)
|
|
54
|
+
if (next !== current) handleValueChange([next])
|
|
55
|
+
},
|
|
56
|
+
[
|
|
57
|
+
disabled,
|
|
58
|
+
handleValueChange,
|
|
59
|
+
isVertical,
|
|
60
|
+
max,
|
|
61
|
+
min,
|
|
62
|
+
onWheelProp,
|
|
63
|
+
step,
|
|
64
|
+
value,
|
|
65
|
+
],
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
const verticalHeightStyle =
|
|
69
|
+
typeof verticalHeight === 'number'
|
|
70
|
+
? `${verticalHeight}px`
|
|
71
|
+
: verticalHeight
|
|
72
|
+
|
|
30
73
|
return (
|
|
31
|
-
<Box
|
|
74
|
+
<Box
|
|
75
|
+
width="100%"
|
|
76
|
+
className={classNames(isVertical && styles.boxVertical)}
|
|
77
|
+
style={
|
|
78
|
+
isVertical
|
|
79
|
+
? { ['--slider-vertical-height']: verticalHeightStyle }
|
|
80
|
+
: undefined
|
|
81
|
+
}
|
|
82
|
+
>
|
|
32
83
|
{title && (
|
|
33
|
-
<Flex
|
|
34
|
-
|
|
84
|
+
<Flex
|
|
85
|
+
mb="2"
|
|
86
|
+
width="100%"
|
|
87
|
+
justify={isVertical ? 'center' : 'between'}
|
|
88
|
+
align="center"
|
|
89
|
+
gap="2"
|
|
90
|
+
>
|
|
91
|
+
<Flex align="center" gap="2" wrap="wrap" justify="center">
|
|
35
92
|
<Text size="2" style={{ color: 'var(--white)' }}>
|
|
36
93
|
{title}
|
|
37
94
|
</Text>
|
|
@@ -40,8 +97,17 @@ export const Slider = ({
|
|
|
40
97
|
<TooltipWithInfoIcon content={tooltip} />
|
|
41
98
|
</Flex>
|
|
42
99
|
)}
|
|
100
|
+
{isVertical && info && (
|
|
101
|
+
<Text
|
|
102
|
+
size="2"
|
|
103
|
+
weight="regular"
|
|
104
|
+
style={{ color: 'var(--neutral-alpha-9)' }}
|
|
105
|
+
>
|
|
106
|
+
{info}
|
|
107
|
+
</Text>
|
|
108
|
+
)}
|
|
43
109
|
</Flex>
|
|
44
|
-
{info && (
|
|
110
|
+
{!isVertical && info && (
|
|
45
111
|
<Text
|
|
46
112
|
size="2"
|
|
47
113
|
weight="regular"
|
|
@@ -52,7 +118,7 @@ export const Slider = ({
|
|
|
52
118
|
)}
|
|
53
119
|
</Flex>
|
|
54
120
|
)}
|
|
55
|
-
<Flex direction="column">
|
|
121
|
+
<Flex direction="column" align={isVertical ? 'center' : undefined}>
|
|
56
122
|
<SliderRadix.Root
|
|
57
123
|
min={min}
|
|
58
124
|
max={max}
|
|
@@ -60,15 +126,27 @@ export const Slider = ({
|
|
|
60
126
|
value={value}
|
|
61
127
|
onValueChange={handleValueChange}
|
|
62
128
|
disabled={disabled}
|
|
63
|
-
|
|
64
|
-
{
|
|
129
|
+
orientation={orientation}
|
|
130
|
+
className={classNames(styles.sliderRoot, className, {
|
|
131
|
+
[styles.sliderRootVertical]: isVertical,
|
|
132
|
+
})}
|
|
133
|
+
onWheel={scrollWheel ? handleWheel : onWheelProp}
|
|
134
|
+
{...rootProps}
|
|
65
135
|
>
|
|
66
|
-
<Flex
|
|
136
|
+
<Flex
|
|
137
|
+
className={classNames(styles.sliderContainer, {
|
|
138
|
+
[styles.sliderContainerVertical]: isVertical,
|
|
139
|
+
})}
|
|
140
|
+
>
|
|
67
141
|
<SliderRadix.Track
|
|
68
142
|
className={classNames(styles.sliderTrack, {
|
|
69
143
|
[styles.sliderTrackSize1]: size === '1',
|
|
70
144
|
[styles.sliderTrackSize2]: size === '2',
|
|
71
145
|
[styles.sliderTrackSize3]: size === '3',
|
|
146
|
+
[styles.sliderTrackVertical]: isVertical,
|
|
147
|
+
[styles.sliderTrackVerticalSize1]: isVertical && size === '1',
|
|
148
|
+
[styles.sliderTrackVerticalSize2]: isVertical && size === '2',
|
|
149
|
+
[styles.sliderTrackVerticalSize3]: isVertical && size === '3',
|
|
72
150
|
})}
|
|
73
151
|
>
|
|
74
152
|
<SliderRadix.Range
|
|
@@ -96,10 +174,17 @@ export const Slider = ({
|
|
|
96
174
|
key={index}
|
|
97
175
|
className={classNames(styles.marker, {
|
|
98
176
|
[styles.markerSize3]: size === '3',
|
|
177
|
+
[styles.markerVertical]: isVertical,
|
|
99
178
|
})}
|
|
100
|
-
style={
|
|
101
|
-
|
|
102
|
-
|
|
179
|
+
style={
|
|
180
|
+
isVertical
|
|
181
|
+
? {
|
|
182
|
+
bottom: `${getMarkerPosition(markerValue)}%`,
|
|
183
|
+
}
|
|
184
|
+
: {
|
|
185
|
+
left: `${getMarkerPosition(markerValue)}%`,
|
|
186
|
+
}
|
|
187
|
+
}
|
|
103
188
|
/>
|
|
104
189
|
))}
|
|
105
190
|
</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,16 @@ import { Slider } from '@moises.ai/design-system'
|
|
|
25
26
|
step={1}
|
|
26
27
|
disabled={false}
|
|
27
28
|
size="2"
|
|
28
|
-
|
|
29
|
+
orientation="horizontal"
|
|
30
|
+
scrollWheel={false}
|
|
31
|
+
/>
|
|
32
|
+
|
|
33
|
+
<Slider
|
|
34
|
+
orientation="vertical"
|
|
35
|
+
verticalHeight={220}
|
|
36
|
+
value={[50]}
|
|
37
|
+
handleValueChange={(value) => console.log(value)}
|
|
38
|
+
/>
|
|
29
39
|
\`\`\`
|
|
30
40
|
|
|
31
41
|
## Component API
|
|
@@ -45,6 +55,9 @@ import { Slider } from '@moises.ai/design-system'
|
|
|
45
55
|
highContrast: boolean, // Whether the slider is in high contrast mode
|
|
46
56
|
size: '1' | '2' | '3', // Size of the slider (1: small, 2: medium, 3: large)
|
|
47
57
|
markers: number[], // Array of values where visual markers should be displayed
|
|
58
|
+
orientation: 'horizontal' | 'vertical', // Slider axis; vertical uses verticalHeight for track
|
|
59
|
+
verticalHeight: number | string, // Track height when vertical (number = px, or CSS length)
|
|
60
|
+
scrollWheel: boolean, // Wheel/trackpad adjusts value on hover/focus (use controlled value)
|
|
48
61
|
}
|
|
49
62
|
\`\`\`
|
|
50
63
|
`,
|
|
@@ -111,6 +124,20 @@ import { Slider } from '@moises.ai/design-system'
|
|
|
111
124
|
control: 'object',
|
|
112
125
|
description: 'Array of values where visual markers should be displayed',
|
|
113
126
|
},
|
|
127
|
+
orientation: {
|
|
128
|
+
control: 'select',
|
|
129
|
+
options: ['horizontal', 'vertical'],
|
|
130
|
+
description: 'Slider axis',
|
|
131
|
+
},
|
|
132
|
+
verticalHeight: {
|
|
133
|
+
control: 'number',
|
|
134
|
+
description: 'Track height in px when orientation is vertical (or pass a CSS length string)',
|
|
135
|
+
},
|
|
136
|
+
scrollWheel: {
|
|
137
|
+
control: 'boolean',
|
|
138
|
+
description:
|
|
139
|
+
'When true, wheel/trackpad adjusts value on hover/focus (use controlled value)',
|
|
140
|
+
},
|
|
114
141
|
},
|
|
115
142
|
}
|
|
116
143
|
|
|
@@ -123,6 +150,9 @@ export const Default = {
|
|
|
123
150
|
color: 'accent',
|
|
124
151
|
highContrast: false,
|
|
125
152
|
size: '2',
|
|
153
|
+
orientation: 'horizontal',
|
|
154
|
+
verticalHeight: 200,
|
|
155
|
+
scrollWheel: false,
|
|
126
156
|
},
|
|
127
157
|
render: (args) => (
|
|
128
158
|
<Flex width="300px">
|
|
@@ -197,3 +227,44 @@ export const WithMarkersDifferentSizes = {
|
|
|
197
227
|
</Flex>
|
|
198
228
|
),
|
|
199
229
|
}
|
|
230
|
+
|
|
231
|
+
export const Vertical = {
|
|
232
|
+
render: () => {
|
|
233
|
+
const [v, setV] = useState([35])
|
|
234
|
+
return (
|
|
235
|
+
<Flex height="280px" align="center" justify="center">
|
|
236
|
+
<Slider
|
|
237
|
+
title="Vertical"
|
|
238
|
+
orientation="vertical"
|
|
239
|
+
verticalHeight={220}
|
|
240
|
+
value={v}
|
|
241
|
+
handleValueChange={setV}
|
|
242
|
+
info={`${v[0]}%`}
|
|
243
|
+
color="accent"
|
|
244
|
+
size="2"
|
|
245
|
+
markers={[0, 25, 50, 75, 100]}
|
|
246
|
+
/>
|
|
247
|
+
</Flex>
|
|
248
|
+
)
|
|
249
|
+
},
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export const ScrollWheel = {
|
|
253
|
+
render: () => {
|
|
254
|
+
const [v, setV] = useState([50])
|
|
255
|
+
return (
|
|
256
|
+
<Flex width="320px" direction="column" gap="2">
|
|
257
|
+
<Slider
|
|
258
|
+
title="Scroll wheel (hover + roll)"
|
|
259
|
+
value={v}
|
|
260
|
+
handleValueChange={setV}
|
|
261
|
+
info={`${v[0]}`}
|
|
262
|
+
scrollWheel
|
|
263
|
+
min={0}
|
|
264
|
+
max={100}
|
|
265
|
+
step={1}
|
|
266
|
+
/>
|
|
267
|
+
</Flex>
|
|
268
|
+
)
|
|
269
|
+
},
|
|
270
|
+
}
|