@ultraviolet/ui 1.10.1 → 1.11.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 CHANGED
@@ -1453,6 +1453,25 @@ type NoticeProps = {
1453
1453
  };
1454
1454
  declare const Notice: ({ children, className, "data-testid": dataTestId, }: NoticeProps) => _emotion_react_jsx_runtime.JSX.Element;
1455
1455
 
1456
+ type CheckboxGroupCheckboxProps = Omit<ComponentProps<typeof Checkbox>, 'onChange' | 'checked' | 'required'> & {
1457
+ value: string;
1458
+ };
1459
+ declare const CheckboxGroupCheckbox: ({ onFocus, onBlur, disabled, error, name, value, children, helper, className, autoFocus, "data-testid": dataTestId, }: CheckboxGroupCheckboxProps) => _emotion_react_jsx_runtime.JSX.Element;
1460
+ type CheckboxGroupProps = {
1461
+ legend: string;
1462
+ value?: string[];
1463
+ className?: string;
1464
+ helper?: ReactNode;
1465
+ error?: ReactNode;
1466
+ direction?: 'row' | 'column';
1467
+ children: ReactNode;
1468
+ required?: boolean;
1469
+ } & Required<Pick<InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'name'>> & Pick<InputHTMLAttributes<HTMLInputElement>, 'required'>;
1470
+ declare const CheckboxGroup: {
1471
+ ({ legend, value, className, helper, error, direction, children, onChange, name, required, }: CheckboxGroupProps): _emotion_react_jsx_runtime.JSX.Element;
1472
+ Checkbox: ({ onFocus, onBlur, disabled, error, name, value, children, helper, className, autoFocus, "data-testid": dataTestId, }: CheckboxGroupCheckboxProps) => _emotion_react_jsx_runtime.JSX.Element;
1473
+ };
1474
+
1456
1475
  declare const containerSizes: {
1457
1476
  large: number;
1458
1477
  medium: number;
@@ -2285,25 +2304,42 @@ type ToastContainerProps = {
2285
2304
  };
2286
2305
  declare const ToastContainer: ({ newestOnTop, limit, position, "data-testid": dataTestId, }: ToastContainerProps) => _emotion_react_jsx_runtime.JSX.Element;
2287
2306
 
2288
- type ToggleProps = {
2289
- id?: string;
2290
- checked?: boolean;
2307
+ declare const Toggle: react.ForwardRefExoticComponent<{
2308
+ id?: string | undefined;
2309
+ checked?: boolean | undefined;
2291
2310
  name: string;
2292
- tooltip?: string;
2311
+ tooltip?: string | undefined;
2293
2312
  /**
2294
2313
  * If `onChange` is given component will work as a controlled component if not it will work as an uncontrolled component.
2295
2314
  */
2296
- onChange?: ChangeEventHandler<HTMLInputElement>;
2297
- size?: 'large' | 'small';
2298
- labelPosition?: 'left' | 'right';
2315
+ onChange?: ChangeEventHandler<HTMLInputElement> | undefined;
2316
+ size?: "large" | "small" | undefined;
2317
+ labelPosition?: "left" | "right" | undefined;
2299
2318
  label?: ReactNode;
2300
2319
  helper?: ReactNode;
2301
- disabled?: boolean;
2320
+ disabled?: boolean | undefined;
2321
+ className?: string | undefined;
2322
+ required?: boolean | undefined;
2323
+ 'data-testid'?: string | undefined;
2324
+ } & Pick<InputHTMLAttributes<HTMLInputElement>, "value"> & react.RefAttributes<HTMLInputElement>>;
2325
+
2326
+ type ToggleGroupToggleProps = Omit<ComponentProps<typeof Toggle>, 'onChange' | 'checked' | 'required'> & {
2327
+ value: string;
2328
+ };
2329
+ type ToggleGroupProps = {
2330
+ legend: string;
2331
+ value?: string[];
2302
2332
  className?: string;
2333
+ helper?: ReactNode;
2334
+ error?: ReactNode;
2335
+ direction?: 'row' | 'column';
2336
+ children: ReactNode;
2303
2337
  required?: boolean;
2304
- 'data-testid'?: string;
2338
+ } & Required<Pick<InputHTMLAttributes<HTMLInputElement>, 'onChange' | 'name'>> & Pick<InputHTMLAttributes<HTMLInputElement>, 'required'>;
2339
+ declare const ToggleGroup: {
2340
+ ({ legend, value, className, helper, error, direction, children, onChange, name, required, }: ToggleGroupProps): _emotion_react_jsx_runtime.JSX.Element;
2341
+ Toggle: ({ disabled, name, value, label, helper, className, "data-testid": dataTestId, }: ToggleGroupToggleProps) => _emotion_react_jsx_runtime.JSX.Element;
2305
2342
  };
2306
- declare const Toggle: react.ForwardRefExoticComponent<ToggleProps & react.RefAttributes<HTMLInputElement>>;
2307
2343
 
2308
2344
  type TooltipProps = Pick<ComponentProps<typeof Popup>, 'id' | 'children' | 'maxWidth' | 'placement' | 'text' | 'className' | 'visible' | 'innerRef' | 'role' | 'data-testid' | 'containerFullWidth'>;
2309
2345
  declare const Tooltip: react.ForwardRefExoticComponent<TooltipProps & react.RefAttributes<HTMLDivElement>>;
@@ -2396,4 +2432,4 @@ declare const down: (size: ScreenSize, rules: string) => string;
2396
2432
 
2397
2433
  declare const normalize: () => string;
2398
2434
 
2399
- export { ActionBar, Alert, Avatar, Badge, Banner, BarChart, BarStack, Breadcrumbs, Breakpoint, Bullet, Button, Card, Carousel, Checkbox, CopyButton, DateInput, EmptyState, Expandable, LineChart, Link, List, Loader, Menu, Meter, Modal, Notice, NumberInput, Pagination, PasswordCheck, PasswordStrengthMeter, PieChart, Popover, ProgressBar, Radio, RadioGroup, Row, SCWUITheme, SelectInput, SelectableCard, Separator, Skeleton, Snippet, Stack, Status, StepList, Stepper, SwitchButton, Table, Tabs, Tag, TagInput, TagList, Text, TextInput, TimeInput, ToastContainer, Toggle, Tooltip, VerificationCode, bounce, down, extendTheme, fadeIn, fadeOut, flash, getUUID, normalize, ping, pulse, quickScaleDown, scaleBack, scaleDown, scaleForward, scaleUp, sketchIn, sketchOut, slideDownLarge, slideFromBottom, slideFromLeft, slideFromRight, slideFromTop, slideToBottom, slideToLeft, slideToRight, slideToTop, slideUpLarge, toast, unfoldIn, unfoldOut, up, zoomIn, zoomOut };
2435
+ export { ActionBar, Alert, Avatar, Badge, Banner, BarChart, BarStack, Breadcrumbs, Breakpoint, Bullet, Button, Card, Carousel, Checkbox, CheckboxGroup, CheckboxGroupCheckbox, CopyButton, DateInput, EmptyState, Expandable, LineChart, Link, List, Loader, Menu, Meter, Modal, Notice, NumberInput, Pagination, PasswordCheck, PasswordStrengthMeter, PieChart, Popover, ProgressBar, Radio, RadioGroup, Row, type SCWUITheme, SelectInput, SelectableCard, Separator, Skeleton, Snippet, Stack, Status, StepList, Stepper, SwitchButton, Table, Tabs, Tag, TagInput, TagList, Text, TextInput, TimeInput, ToastContainer, Toggle, ToggleGroup, Tooltip, VerificationCode, bounce, down, extendTheme, fadeIn, fadeOut, flash, getUUID, normalize, ping, pulse, quickScaleDown, scaleBack, scaleDown, scaleForward, scaleUp, sketchIn, sketchOut, slideDownLarge, slideFromBottom, slideFromLeft, slideFromRight, slideFromTop, slideToBottom, slideToLeft, slideToRight, slideToTop, slideUpLarge, toast, unfoldIn, unfoldOut, up, zoomIn, zoomOut };
@@ -0,0 +1,129 @@
1
+ import _styled from '@emotion/styled/base';
2
+ import { Icon } from '@ultraviolet/icons';
3
+ import { useContext, useMemo, createContext } from 'react';
4
+ import { Checkbox } from '../Checkbox/index.js';
5
+ import { Stack } from '../Stack/index.js';
6
+ import { Text } from '../Text/index.js';
7
+ import { jsx, jsxs } from '@emotion/react/jsx-runtime';
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 CheckboxGroupContext = /*#__PURE__*/createContext(undefined);
11
+ const CheckboxGroupCheckbox = _ref => {
12
+ let {
13
+ onFocus,
14
+ onBlur,
15
+ disabled,
16
+ error,
17
+ name,
18
+ value,
19
+ children,
20
+ helper,
21
+ className,
22
+ autoFocus,
23
+ 'data-testid': dataTestId
24
+ } = _ref;
25
+ const context = useContext(CheckboxGroupContext);
26
+ if (!context) {
27
+ throw new Error('CheckboxGroup.Checkbox can only be used inside a CheckboxGroup');
28
+ }
29
+ const {
30
+ groupName,
31
+ onChange,
32
+ groupValues
33
+ } = context;
34
+ const checkboxName = `${groupName}.${name ?? ''}`;
35
+ const checkboxValue = `${value}`;
36
+ return jsx(Checkbox, {
37
+ onChange: onChange,
38
+ checked: groupValues?.includes(checkboxValue),
39
+ onFocus: onFocus,
40
+ onBlur: onBlur,
41
+ disabled: disabled,
42
+ error: error,
43
+ name: checkboxName,
44
+ value: checkboxValue,
45
+ helper: helper,
46
+ className: className,
47
+ autoFocus: autoFocus,
48
+ "data-testid": dataTestId,
49
+ children: children
50
+ });
51
+ };
52
+ const FieldSet = /*#__PURE__*/_styled("fieldset", {
53
+ target: "e1k5uyng1"
54
+ })(process.env.NODE_ENV === "production" ? {
55
+ name: "7o2an9",
56
+ styles: "border:none;padding:0;margin:0"
57
+ } : {
58
+ name: "7o2an9",
59
+ styles: "border:none;padding:0;margin:0",
60
+ toString: _EMOTION_STRINGIFIED_CSS_ERROR__
61
+ });
62
+ const StyledRequiredIcon = /*#__PURE__*/_styled(Icon, {
63
+ target: "e1k5uyng0"
64
+ })(process.env.NODE_ENV === "production" ? {
65
+ name: "1nglpc5",
66
+ styles: "vertical-align:super"
67
+ } : {
68
+ name: "1nglpc5",
69
+ styles: "vertical-align:super",
70
+ toString: _EMOTION_STRINGIFIED_CSS_ERROR__
71
+ });
72
+ const CheckboxGroup = _ref2 => {
73
+ let {
74
+ legend,
75
+ value,
76
+ className,
77
+ helper,
78
+ error,
79
+ direction = 'column',
80
+ children,
81
+ onChange,
82
+ name,
83
+ required = false
84
+ } = _ref2;
85
+ const contextValue = useMemo(() => ({
86
+ groupName: name,
87
+ groupValues: value ?? [],
88
+ onChange
89
+ }), [name, value, onChange]);
90
+ return jsx(CheckboxGroupContext.Provider, {
91
+ value: contextValue,
92
+ children: jsxs(Stack, {
93
+ gap: 1,
94
+ children: [jsx(FieldSet, {
95
+ className: className,
96
+ children: jsxs(Stack, {
97
+ gap: 1.5,
98
+ children: [jsxs(Text, {
99
+ as: "legend",
100
+ variant: "bodyStrong",
101
+ children: [legend, "\xA0", required ? jsx(StyledRequiredIcon, {
102
+ name: "asterisk",
103
+ color: "danger",
104
+ size: 8
105
+ }) : null]
106
+ }), jsx(Stack, {
107
+ gap: direction === 'column' ? 1 : 2,
108
+ direction: direction,
109
+ children: children
110
+ })]
111
+ })
112
+ }), helper ? jsx(Text, {
113
+ as: "p",
114
+ variant: "bodySmall",
115
+ prominence: "weak",
116
+ children: helper
117
+ }) : null, error ? jsx(Text, {
118
+ as: "p",
119
+ variant: "bodySmall",
120
+ sentiment: "danger",
121
+ prominence: "weak",
122
+ children: error
123
+ }) : null]
124
+ })
125
+ });
126
+ };
127
+ CheckboxGroup.Checkbox = CheckboxGroupCheckbox;
128
+
129
+ export { CheckboxGroup, CheckboxGroupCheckbox };
@@ -1,5 +1,5 @@
1
1
  import _styled from '@emotion/styled/base';
2
- import { useState, useId, useCallback } from 'react';
2
+ import { useState, useId, useCallback, useEffect } from 'react';
3
3
  import { Button } from '../Button/index.js';
4
4
  import { Dialog } from './Dialog.js';
5
5
  import { Disclosure } from './Disclosure.js';
@@ -61,6 +61,9 @@ const Modal = _ref3 => {
61
61
  }, []);
62
62
  const finalId = id ?? controlId;
63
63
  const finalSize = size ?? width;
64
+ useEffect(() => {
65
+ setVisible(opened);
66
+ }, [opened]);
64
67
  return jsxs(Fragment, {
65
68
  children: [jsx(Disclosure, {
66
69
  id: finalId,
@@ -167,7 +167,8 @@ const Toggle = /*#__PURE__*/forwardRef((_ref23, ref) => {
167
167
  helper,
168
168
  required,
169
169
  className,
170
- 'data-testid': dataTestId
170
+ 'data-testid': dataTestId,
171
+ value
171
172
  } = _ref23;
172
173
  const [state, setState] = useState(checked);
173
174
  const uniqueId = useId();
@@ -212,7 +213,8 @@ const Toggle = /*#__PURE__*/forwardRef((_ref23, ref) => {
212
213
  name: name,
213
214
  onChange: onLocalChange,
214
215
  type: "checkbox",
215
- ref: ref
216
+ ref: ref,
217
+ value: value
216
218
  })
217
219
  })]
218
220
  })
@@ -0,0 +1,121 @@
1
+ import _styled from '@emotion/styled/base';
2
+ import { Icon } from '@ultraviolet/icons';
3
+ import { useMemo, createContext, useContext } from 'react';
4
+ import { Stack } from '../Stack/index.js';
5
+ import { Text } from '../Text/index.js';
6
+ import { Toggle } from '../Toggle/index.js';
7
+ import { jsx, jsxs } from '@emotion/react/jsx-runtime';
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 ToggleGroupContext = /*#__PURE__*/createContext(undefined);
11
+ const ToggleGroupToggle = _ref => {
12
+ let {
13
+ disabled,
14
+ name,
15
+ value,
16
+ label,
17
+ helper,
18
+ className,
19
+ 'data-testid': dataTestId
20
+ } = _ref;
21
+ const context = useContext(ToggleGroupContext);
22
+ if (!context) {
23
+ throw new Error('ToggleGroup.Toggle can only be used inside a ToggleGroup');
24
+ }
25
+ const {
26
+ groupName,
27
+ onChange,
28
+ groupValues
29
+ } = context;
30
+ const ToggleName = `${groupName}.${name}`;
31
+ const ToggleValue = `${value}`;
32
+ return jsx(Toggle, {
33
+ onChange: onChange,
34
+ checked: groupValues?.includes(ToggleValue),
35
+ disabled: disabled,
36
+ name: ToggleName,
37
+ value: ToggleValue,
38
+ helper: helper,
39
+ className: className,
40
+ "data-testid": dataTestId,
41
+ label: label
42
+ });
43
+ };
44
+ const FieldSet = /*#__PURE__*/_styled("fieldset", {
45
+ target: "e1qvneex1"
46
+ })(process.env.NODE_ENV === "production" ? {
47
+ name: "7o2an9",
48
+ styles: "border:none;padding:0;margin:0"
49
+ } : {
50
+ name: "7o2an9",
51
+ styles: "border:none;padding:0;margin:0",
52
+ toString: _EMOTION_STRINGIFIED_CSS_ERROR__
53
+ });
54
+ const StyledRequiredIcon = /*#__PURE__*/_styled(Icon, {
55
+ target: "e1qvneex0"
56
+ })(process.env.NODE_ENV === "production" ? {
57
+ name: "1nglpc5",
58
+ styles: "vertical-align:super"
59
+ } : {
60
+ name: "1nglpc5",
61
+ styles: "vertical-align:super",
62
+ toString: _EMOTION_STRINGIFIED_CSS_ERROR__
63
+ });
64
+ const ToggleGroup = _ref2 => {
65
+ let {
66
+ legend,
67
+ value,
68
+ className,
69
+ helper,
70
+ error,
71
+ direction = 'column',
72
+ children,
73
+ onChange,
74
+ name,
75
+ required = false
76
+ } = _ref2;
77
+ const contextValue = useMemo(() => ({
78
+ groupName: name,
79
+ groupValues: value ?? [],
80
+ onChange
81
+ }), [name, value, onChange]);
82
+ return jsx(ToggleGroupContext.Provider, {
83
+ value: contextValue,
84
+ children: jsxs(Stack, {
85
+ gap: 1,
86
+ children: [jsx(FieldSet, {
87
+ className: className,
88
+ children: jsxs(Stack, {
89
+ gap: 1.5,
90
+ children: [jsxs(Text, {
91
+ as: "legend",
92
+ variant: "bodyStrong",
93
+ children: [legend, "\xA0", required ? jsx(StyledRequiredIcon, {
94
+ name: "asterisk",
95
+ color: "danger",
96
+ size: 8
97
+ }) : null]
98
+ }), jsx(Stack, {
99
+ gap: 2,
100
+ direction: direction,
101
+ children: children
102
+ })]
103
+ })
104
+ }), helper ? jsx(Text, {
105
+ as: "p",
106
+ variant: "bodySmall",
107
+ prominence: "weak",
108
+ children: helper
109
+ }) : null, error ? jsx(Text, {
110
+ as: "p",
111
+ variant: "bodySmall",
112
+ sentiment: "danger",
113
+ prominence: "weak",
114
+ children: error
115
+ }) : null]
116
+ })
117
+ });
118
+ };
119
+ ToggleGroup.Toggle = ToggleGroupToggle;
120
+
121
+ export { ToggleGroup, ToggleGroupToggle };
package/dist/src/index.js CHANGED
@@ -30,6 +30,7 @@ export { Menu } from './components/Menu/index.js';
30
30
  export { Meter } from './components/Meter/Meter.js';
31
31
  export { Modal } from './components/Modal/Modal.js';
32
32
  export { Notice } from './components/Notice/index.js';
33
+ export { CheckboxGroup, CheckboxGroupCheckbox } from './components/CheckboxGroup/index.js';
33
34
  export { NumberInput } from './components/NumberInput/index.js';
34
35
  export { Pagination } from './components/Pagination/index.js';
35
36
  export { PasswordCheck } from './components/PasswordCheck/index.js';
@@ -59,6 +60,7 @@ export { TextInput } from './components/TextInput/index.js';
59
60
  export { TimeInput } from './components/TimeInput/index.js';
60
61
  export { ToastContainer, toast } from './components/Toaster/index.js';
61
62
  export { Toggle } from './components/Toggle/index.js';
63
+ export { ToggleGroup } from './components/ToggleGroup/index.js';
62
64
  export { Tooltip } from './components/Tooltip/index.js';
63
65
  export { VerificationCode } from './components/VerificationCode/index.js';
64
66
  export { RadioGroup } from './components/RadioGroup/index.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultraviolet/ui",
3
- "version": "1.10.1",
3
+ "version": "1.11.0",
4
4
  "description": "Ultraviolet UI",
5
5
  "homepage": "https://github.com/scaleway/ultraviolet#readme",
6
6
  "repository": {