@ultraviolet/ui 1.8.4 → 1.10.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/index.d.ts +56 -73
- package/dist/src/components/Checkbox/index.js +266 -146
- package/dist/src/components/Modal/Dialog.js +151 -0
- package/dist/src/components/Modal/Disclosure.js +38 -0
- package/dist/src/components/Modal/Modal.js +110 -0
- package/dist/src/components/Modal/constants.js +50 -0
- package/dist/src/components/RadioGroup/index.js +131 -0
- package/dist/src/components/Toggle/index.js +70 -40
- package/dist/src/index.js +2 -1
- package/package.json +3 -3
- package/dist/src/components/Modal/index.js +0 -283
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultraviolet/ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Ultraviolet UI",
|
|
5
5
|
"homepage": "https://github.com/scaleway/ultraviolet#readme",
|
|
6
6
|
"repository": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"react-dom": "18.2.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@babel/core": "7.22.
|
|
42
|
+
"@babel/core": "7.22.11",
|
|
43
43
|
"@emotion/babel-plugin": "11.11.0",
|
|
44
44
|
"@emotion/react": "11.11.1",
|
|
45
45
|
"@emotion/styled": "11.11.0",
|
|
@@ -68,6 +68,6 @@
|
|
|
68
68
|
"react-use-clipboard": "1.0.9",
|
|
69
69
|
"reakit": "1.3.11",
|
|
70
70
|
"@ultraviolet/themes": "1.2.1",
|
|
71
|
-
"@ultraviolet/icons": "1.
|
|
71
|
+
"@ultraviolet/icons": "1.3.1"
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
import _styled from '@emotion/styled/base';
|
|
2
|
-
import { css } from '@emotion/react';
|
|
3
|
-
import { memo, useEffect, useCallback, isValidElement, useRef, cloneElement } from 'react';
|
|
4
|
-
import { useDialogState, DialogBackdrop, Dialog, DialogDisclosure } from 'reakit/Dialog';
|
|
5
|
-
import { Button } from '../Button/index.js';
|
|
6
|
-
import { jsxs, Fragment, jsx } from '@emotion/react/jsx-runtime';
|
|
7
|
-
import { unfoldIn, unfoldOut, scaleForward, scaleBack, scaleUp, scaleDown, sketchIn, sketchOut, slideFromBottom, slideToBottom, slideFromLeft, slideToLeft, slideFromRight, slideToRight, slideFromTop, slideToTop, zoomIn, zoomOut } from '../../utils/animations.js';
|
|
8
|
-
|
|
9
|
-
function _EMOTION_STRINGIFIED_CSS_ERROR__() { return "You have tried to stringify object returned from `css` function. It isn't supposed to be used directly (e.g. as value of the `className` prop), but rather handed to emotion so it can handle it (e.g. as value of `css` prop)."; }
|
|
10
|
-
const MODAL_WIDTH = {
|
|
11
|
-
large: 850,
|
|
12
|
-
medium: 708,
|
|
13
|
-
small: 616,
|
|
14
|
-
xsmall: 400,
|
|
15
|
-
xxsmall: 360
|
|
16
|
-
};
|
|
17
|
-
const MODAL_PLACEMENT = {
|
|
18
|
-
bottom: `
|
|
19
|
-
margin: auto;
|
|
20
|
-
margin-bottom: 0;
|
|
21
|
-
`,
|
|
22
|
-
'bottom-left': `
|
|
23
|
-
margin: auto;
|
|
24
|
-
margin-left: 0;
|
|
25
|
-
margin-bottom: 0;
|
|
26
|
-
`,
|
|
27
|
-
'bottom-right': `
|
|
28
|
-
margin: auto;
|
|
29
|
-
margin-right: 0;
|
|
30
|
-
margin-bottom: 0;
|
|
31
|
-
`,
|
|
32
|
-
center: `
|
|
33
|
-
margin: auto;
|
|
34
|
-
`,
|
|
35
|
-
left: `
|
|
36
|
-
margin: auto;
|
|
37
|
-
margin-left: 0;
|
|
38
|
-
`,
|
|
39
|
-
right: `
|
|
40
|
-
margin: auto;
|
|
41
|
-
margin-right: 0;
|
|
42
|
-
`,
|
|
43
|
-
top: `
|
|
44
|
-
margin: auto;
|
|
45
|
-
margin-top: 0px;
|
|
46
|
-
`,
|
|
47
|
-
'top-left': `
|
|
48
|
-
margin: auto;
|
|
49
|
-
margin-left: 0;
|
|
50
|
-
margin-top: 0;
|
|
51
|
-
`,
|
|
52
|
-
'top-right': `
|
|
53
|
-
margin: auto;
|
|
54
|
-
margin-right: 0;
|
|
55
|
-
margin-top: 0;
|
|
56
|
-
`
|
|
57
|
-
};
|
|
58
|
-
const MODAL_ANIMATION = {
|
|
59
|
-
fold: {
|
|
60
|
-
enter: unfoldIn,
|
|
61
|
-
leave: unfoldOut
|
|
62
|
-
},
|
|
63
|
-
scaleBack: {
|
|
64
|
-
enter: scaleForward,
|
|
65
|
-
leave: scaleBack
|
|
66
|
-
},
|
|
67
|
-
scaleUp: {
|
|
68
|
-
enter: scaleUp,
|
|
69
|
-
leave: scaleDown
|
|
70
|
-
},
|
|
71
|
-
sketch: {
|
|
72
|
-
enter: sketchIn,
|
|
73
|
-
leave: sketchOut
|
|
74
|
-
},
|
|
75
|
-
slideBottom: {
|
|
76
|
-
enter: slideFromBottom,
|
|
77
|
-
leave: slideToBottom
|
|
78
|
-
},
|
|
79
|
-
slideLeft: {
|
|
80
|
-
enter: slideFromLeft,
|
|
81
|
-
leave: slideToLeft
|
|
82
|
-
},
|
|
83
|
-
slideRight: {
|
|
84
|
-
enter: slideFromRight,
|
|
85
|
-
leave: slideToRight
|
|
86
|
-
},
|
|
87
|
-
slideTop: {
|
|
88
|
-
enter: slideFromTop,
|
|
89
|
-
leave: slideToTop
|
|
90
|
-
},
|
|
91
|
-
zoom: {
|
|
92
|
-
enter: zoomIn,
|
|
93
|
-
leave: zoomOut
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
const backdropAnimatedStyle = `
|
|
97
|
-
opacity: 0;
|
|
98
|
-
transition: opacity 250ms ease-in-out;
|
|
99
|
-
&[data-enter] {
|
|
100
|
-
opacity: 1;
|
|
101
|
-
transition: opacity 250ms ease-in-out;
|
|
102
|
-
}
|
|
103
|
-
&[data-leave] {
|
|
104
|
-
opacity: 0;
|
|
105
|
-
transition: opacity 400ms ease-in-out;
|
|
106
|
-
}
|
|
107
|
-
`;
|
|
108
|
-
const dialogAnimatedStyle = _ref => {
|
|
109
|
-
let {
|
|
110
|
-
animation
|
|
111
|
-
} = _ref;
|
|
112
|
-
return /*#__PURE__*/css("opacity:0;&[data-enter]{opacity:1;transition:opacity 500ms ease-in-out;animation:", MODAL_ANIMATION[animation].enter, " 500ms cubic-bezier(0.165, 0.84, 0.44, 1) forwards;}&[data-leave]{opacity:0;transition:opacity 500ms ease-in-out;animation:", MODAL_ANIMATION[animation].leave, " 500ms cubic-bezier(0.165, 0.84, 0.44, 1) forwards;}");
|
|
113
|
-
};
|
|
114
|
-
const Disclosure = _ref2 => {
|
|
115
|
-
let {
|
|
116
|
-
disclosure,
|
|
117
|
-
dialog
|
|
118
|
-
} = _ref2;
|
|
119
|
-
// if you need dialog inside your component, use function, otherwise component is fine
|
|
120
|
-
const target = /*#__PURE__*/isValidElement(disclosure) ? disclosure : disclosure(dialog);
|
|
121
|
-
const innerRef = useRef(target);
|
|
122
|
-
return (
|
|
123
|
-
// @ts-expect-error reakit types are invalid, no need to pass as something, default is div
|
|
124
|
-
jsx(DialogDisclosure, {
|
|
125
|
-
...dialog,
|
|
126
|
-
onClick: event => {
|
|
127
|
-
// This allow to use onClick for speficique case like traking.
|
|
128
|
-
target?.props?.onClick?.(event);
|
|
129
|
-
},
|
|
130
|
-
ref: innerRef,
|
|
131
|
-
children: disclosureProps => /*#__PURE__*/cloneElement(target, disclosureProps)
|
|
132
|
-
})
|
|
133
|
-
);
|
|
134
|
-
};
|
|
135
|
-
const MemoDisclosure = /*#__PURE__*/memo(Disclosure);
|
|
136
|
-
const StyledDialogBackdrop = /*#__PURE__*/_styled(DialogBackdrop, {
|
|
137
|
-
target: "ebywm9u2"
|
|
138
|
-
})("display:flex;position:fixed;overflow:auto;padding:16px;top:0;bottom:0;right:0;left:0;opacity:1;background-color:", _ref3 => {
|
|
139
|
-
let {
|
|
140
|
-
theme
|
|
141
|
-
} = _ref3;
|
|
142
|
-
return theme.colors.overlay;
|
|
143
|
-
}, ";", _ref4 => {
|
|
144
|
-
let {
|
|
145
|
-
animated
|
|
146
|
-
} = _ref4;
|
|
147
|
-
return animated && backdropAnimatedStyle;
|
|
148
|
-
}, ";");
|
|
149
|
-
const StyledDialog = /*#__PURE__*/_styled(Dialog, {
|
|
150
|
-
shouldForwardProp: prop => !['animation', 'placement', 'width', 'height', 'bordered'].includes(prop),
|
|
151
|
-
target: "ebywm9u1"
|
|
152
|
-
})("background-color:", _ref5 => {
|
|
153
|
-
let {
|
|
154
|
-
theme
|
|
155
|
-
} = _ref5;
|
|
156
|
-
return theme.colors.neutral.backgroundWeakElevated;
|
|
157
|
-
}, ";position:relative;border-radius:", _ref6 => {
|
|
158
|
-
let {
|
|
159
|
-
bordered,
|
|
160
|
-
theme
|
|
161
|
-
} = _ref6;
|
|
162
|
-
return bordered ? theme.radii.default : theme.radii.none;
|
|
163
|
-
}, ";border:0;padding:32px;", _ref7 => {
|
|
164
|
-
let {
|
|
165
|
-
placement
|
|
166
|
-
} = _ref7;
|
|
167
|
-
return MODAL_PLACEMENT[placement];
|
|
168
|
-
}, " width:", _ref8 => {
|
|
169
|
-
let {
|
|
170
|
-
width
|
|
171
|
-
} = _ref8;
|
|
172
|
-
return MODAL_WIDTH[width];
|
|
173
|
-
}, "px;min-height:", _ref9 => {
|
|
174
|
-
let {
|
|
175
|
-
height
|
|
176
|
-
} = _ref9;
|
|
177
|
-
return height;
|
|
178
|
-
}, ";box-shadow:", _ref10 => {
|
|
179
|
-
let {
|
|
180
|
-
theme
|
|
181
|
-
} = _ref10;
|
|
182
|
-
return theme.shadows.modal;
|
|
183
|
-
}, ";opacity:1;&::before{content:'';height:100%;width:100%;}", _ref11 => {
|
|
184
|
-
let {
|
|
185
|
-
animated,
|
|
186
|
-
animation
|
|
187
|
-
} = _ref11;
|
|
188
|
-
return animated && dialogAnimatedStyle({
|
|
189
|
-
animation
|
|
190
|
-
});
|
|
191
|
-
}, ";");
|
|
192
|
-
const StyledContainer = /*#__PURE__*/_styled("div", {
|
|
193
|
-
target: "ebywm9u0"
|
|
194
|
-
})(process.env.NODE_ENV === "production" ? {
|
|
195
|
-
name: "et21s3",
|
|
196
|
-
styles: "display:flex;flex-grow:1;flex-wrap:wrap;justify-content:flex-end;position:absolute;top:16px;right:16px;left:16px"
|
|
197
|
-
} : {
|
|
198
|
-
name: "et21s3",
|
|
199
|
-
styles: "display:flex;flex-grow:1;flex-wrap:wrap;justify-content:flex-end;position:absolute;top:16px;right:16px;left:16px",
|
|
200
|
-
toString: _EMOTION_STRINGIFIED_CSS_ERROR__
|
|
201
|
-
});
|
|
202
|
-
const Modal = /*#__PURE__*/memo(_ref12 => {
|
|
203
|
-
let {
|
|
204
|
-
animated = false,
|
|
205
|
-
animation = 'zoom',
|
|
206
|
-
ariaLabel = 'modal',
|
|
207
|
-
id,
|
|
208
|
-
bordered = true,
|
|
209
|
-
children,
|
|
210
|
-
customDialogBackdropStyles,
|
|
211
|
-
customDialogStyles = {},
|
|
212
|
-
disclosure,
|
|
213
|
-
height = 'initial',
|
|
214
|
-
hideOnClickOutside = true,
|
|
215
|
-
hideOnEsc = true,
|
|
216
|
-
isClosable = true,
|
|
217
|
-
modal = true,
|
|
218
|
-
onClose,
|
|
219
|
-
onBeforeClose,
|
|
220
|
-
opened = false,
|
|
221
|
-
placement = 'center',
|
|
222
|
-
preventBodyScroll = true,
|
|
223
|
-
width = 'small',
|
|
224
|
-
className,
|
|
225
|
-
'data-testid': dataTestId
|
|
226
|
-
} = _ref12;
|
|
227
|
-
const dialog = useDialogState({
|
|
228
|
-
animated,
|
|
229
|
-
baseId: id,
|
|
230
|
-
modal,
|
|
231
|
-
visible: opened
|
|
232
|
-
});
|
|
233
|
-
const {
|
|
234
|
-
setVisible
|
|
235
|
-
} = dialog;
|
|
236
|
-
useEffect(() => setVisible(opened), [setVisible, opened]);
|
|
237
|
-
const onCloseCallBack = useCallback(async () => {
|
|
238
|
-
await onBeforeClose?.();
|
|
239
|
-
dialog.toggle();
|
|
240
|
-
}, [dialog, onBeforeClose]);
|
|
241
|
-
return jsxs(Fragment, {
|
|
242
|
-
children: [disclosure && jsx(MemoDisclosure, {
|
|
243
|
-
dialog: dialog,
|
|
244
|
-
disclosure: disclosure
|
|
245
|
-
}), jsx(StyledDialogBackdrop, {
|
|
246
|
-
...dialog,
|
|
247
|
-
css: customDialogBackdropStyles,
|
|
248
|
-
children: jsx(StyledDialog, {
|
|
249
|
-
"aria-label": ariaLabel,
|
|
250
|
-
role: "dialog",
|
|
251
|
-
tabIndex: 0,
|
|
252
|
-
animation: animation,
|
|
253
|
-
bordered: bordered,
|
|
254
|
-
height: height,
|
|
255
|
-
placement: placement,
|
|
256
|
-
width: width,
|
|
257
|
-
css: customDialogStyles,
|
|
258
|
-
hideOnClickOutside: hideOnClickOutside,
|
|
259
|
-
hideOnEsc: hideOnEsc,
|
|
260
|
-
preventBodyScroll: preventBodyScroll,
|
|
261
|
-
...dialog,
|
|
262
|
-
hide: onClose || onCloseCallBack,
|
|
263
|
-
className: className,
|
|
264
|
-
"data-testid": dataTestId,
|
|
265
|
-
children: jsxs(Fragment, {
|
|
266
|
-
children: [dialog.visible && (typeof children === 'function' ? children(dialog) : children), jsx(StyledContainer, {
|
|
267
|
-
children: isClosable && jsx(Button, {
|
|
268
|
-
"data-testid": dataTestId ? `${dataTestId}-close-button` : undefined,
|
|
269
|
-
onClick: onClose || onCloseCallBack,
|
|
270
|
-
variant: "ghost",
|
|
271
|
-
size: "small",
|
|
272
|
-
icon: "close",
|
|
273
|
-
sentiment: "neutral",
|
|
274
|
-
"aria-label": "close"
|
|
275
|
-
})
|
|
276
|
-
})]
|
|
277
|
-
})
|
|
278
|
-
})
|
|
279
|
-
})]
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
export { MODAL_ANIMATION, MODAL_PLACEMENT, MODAL_WIDTH, Modal };
|