@react-ui-org/react-ui 0.42.1 → 0.44.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.
- package/CONTRIBUTING.md +44 -25
- package/README.md +1 -1
- package/dist/lib.development.js +1597 -651
- package/dist/lib.js +1 -9
- package/package.json +47 -46
- package/src/lib/components/{ui/Alert → Alert}/Alert.jsx +17 -14
- package/src/lib/components/{ui/Alert → Alert}/Alert.scss +3 -3
- package/src/lib/components/{ui/Alert → Alert}/README.mdx +6 -6
- package/src/lib/components/{ui/Alert → Alert}/_settings.scss +1 -1
- package/src/lib/components/{ui/Alert → Alert}/_theme.scss +0 -0
- package/src/lib/components/{ui/Alert → Alert}/_tools.scss +0 -0
- package/src/lib/components/{ui/Alert → Alert}/index.js +0 -0
- package/src/lib/components/{ui/Badge → Badge}/Badge.jsx +2 -2
- package/src/lib/components/{ui/Badge → Badge}/Badge.scss +3 -3
- package/src/lib/components/{ui/Badge → Badge}/README.mdx +3 -3
- package/src/lib/components/{ui/Badge → Badge}/index.js +0 -0
- package/src/lib/components/Button/Button.jsx +198 -0
- package/src/lib/components/{ui/Button → Button}/Button.scss +0 -0
- package/src/lib/components/{ui/Button → Button}/README.mdx +161 -76
- package/src/lib/components/Button/_base.scss +148 -0
- package/src/lib/components/{ui/Button → Button}/_priorities.scss +0 -4
- package/src/lib/components/{ui/Button → Button}/_settings.scss +2 -3
- package/src/lib/components/{ui/Button → Button}/_theme.scss +3 -11
- package/src/lib/components/{ui/Button → Button}/_tools.scss +27 -44
- package/src/lib/components/Button/helpers/getRootLabelVisibilityClassName.js +33 -0
- package/src/lib/components/{ui/Button → Button}/helpers/getRootPriorityClassName.js +0 -4
- package/src/lib/components/{ui/Button → Button}/index.js +0 -0
- package/src/lib/components/{ui/ButtonGroup → ButtonGroup}/ButtonGroup.jsx +9 -11
- package/src/lib/components/{ui/ButtonGroup → ButtonGroup}/ButtonGroup.scss +0 -0
- package/src/lib/components/ButtonGroup/ButtonGroupContext.js +3 -0
- package/src/lib/components/{ui/ButtonGroup → ButtonGroup}/README.mdx +30 -6
- package/src/lib/components/ButtonGroup/index.js +2 -0
- package/src/lib/components/{layout/CTA → CTA}/CTA.jsx +5 -2
- package/src/lib/components/{layout/CTA → CTA}/CTA.scss +2 -2
- package/src/lib/components/{layout/CTA → CTA}/CTACenter.jsx +1 -1
- package/src/lib/components/{layout/CTA → CTA}/CTAEnd.jsx +1 -1
- package/src/lib/components/{layout/CTA → CTA}/CTAStart.jsx +1 -1
- package/src/lib/components/{layout/CTA → CTA}/README.mdx +4 -4
- package/src/lib/components/{layout/CTA → CTA}/index.js +0 -0
- package/src/lib/components/{ui/Card → Card}/Card.jsx +6 -4
- package/src/lib/components/{ui/Card → Card}/Card.scss +1 -1
- package/src/lib/components/{ui/Card → Card}/CardBody.jsx +1 -1
- package/src/lib/components/{ui/Card → Card}/CardFooter.jsx +1 -1
- package/src/lib/components/{ui/Card → Card}/README.mdx +4 -4
- package/src/lib/components/{ui/Card → Card}/_theme.scss +0 -0
- package/src/lib/components/{ui/Card → Card}/_tools.scss +0 -0
- package/src/lib/components/{ui/Card → Card}/index.js +0 -0
- package/src/lib/components/{layout/Center → Center}/Center.jsx +1 -1
- package/src/lib/components/{layout/Center → Center}/Center.scss +0 -0
- package/src/lib/components/{layout/Center → Center}/README.mdx +2 -2
- package/src/lib/components/{layout/Center → Center}/index.js +0 -0
- package/src/lib/components/CheckboxField/CheckboxField.jsx +164 -0
- package/src/lib/components/{ui/CheckboxField → CheckboxField}/CheckboxField.scss +5 -5
- package/src/lib/components/{ui/CheckboxField → CheckboxField}/README.mdx +17 -14
- package/src/lib/components/{ui/CheckboxField → CheckboxField}/index.js +0 -0
- package/src/lib/components/FileInputField/FileInputField.jsx +162 -0
- package/src/lib/components/{ui/FileInputField → FileInputField}/FileInputField.scss +5 -5
- package/src/lib/components/{ui/FileInputField → FileInputField}/README.mdx +8 -6
- package/src/lib/components/{ui/FileInputField → FileInputField}/index.js +0 -0
- package/src/lib/components/{layout/FormLayout → FormLayout}/FormLayout.jsx +16 -18
- package/src/lib/components/{layout/FormLayout → FormLayout}/FormLayout.scss +3 -3
- package/src/lib/components/FormLayout/FormLayoutContext.js +3 -0
- package/src/lib/components/{layout/FormLayout → FormLayout}/FormLayoutCustomField.jsx +33 -30
- package/src/lib/components/{layout/FormLayout → FormLayout}/FormLayoutCustomField.scss +4 -4
- package/src/lib/components/{layout/FormLayout → FormLayout}/README.mdx +37 -47
- package/src/lib/components/{layout/FormLayout → FormLayout}/_theme.scss +0 -0
- package/src/lib/components/{layout/FormLayout → FormLayout}/index.js +1 -0
- package/src/lib/components/{layout/Grid → Grid}/Grid.jsx +23 -5
- package/src/lib/components/{layout/Grid → Grid}/Grid.scss +13 -4
- package/src/lib/components/{layout/Grid → Grid}/GridSpan.jsx +10 -3
- package/src/lib/components/{layout/Grid → Grid}/README.mdx +42 -38
- package/src/lib/components/{layout/Grid → Grid}/_theme.scss +1 -2
- package/src/lib/components/{layout/Grid → Grid}/_tools.scss +2 -2
- package/src/lib/components/{layout/Grid → Grid}/helpers/generateResponsiveCustomProperties.js +0 -0
- package/src/lib/components/{layout/Grid → Grid}/index.js +0 -0
- package/src/lib/components/Link/Link.jsx +45 -0
- package/src/lib/components/Link/Link.scss +11 -0
- package/src/lib/components/Link/README.mdx +85 -0
- package/src/lib/components/Link/_theme.scss +4 -0
- package/src/lib/components/Link/index.js +1 -0
- package/src/lib/components/{layout/List → List}/List.jsx +1 -1
- package/src/lib/components/{layout/List → List}/List.scss +2 -2
- package/src/lib/components/{layout/List → List}/ListItem.jsx +1 -1
- package/src/lib/components/{layout/List → List}/README.mdx +3 -3
- package/src/lib/components/{layout/List → List}/_theme.scss +0 -0
- package/src/lib/components/{layout/List → List}/index.js +0 -0
- package/src/lib/components/{layout/Media → Media}/Media.jsx +4 -2
- package/src/lib/components/{layout/Media → Media}/Media.scss +1 -1
- package/src/lib/components/{layout/Media → Media}/MediaBody.jsx +1 -1
- package/src/lib/components/{layout/Media → Media}/MediaObject.jsx +1 -1
- package/src/lib/components/{layout/Media → Media}/README.mdx +2 -2
- package/src/lib/components/{layout/Media → Media}/index.js +0 -0
- package/src/lib/components/{ui/Modal → Modal}/Modal.jsx +28 -27
- package/src/lib/components/{ui/Modal → Modal}/Modal.scss +5 -5
- package/src/lib/components/{ui/Modal → Modal}/README.mdx +42 -42
- package/src/lib/components/{ui/Modal → Modal}/_settings.scss +4 -4
- package/src/lib/components/{ui/Modal → Modal}/_theme.scss +0 -0
- package/src/lib/components/{ui/Modal → Modal}/index.js +0 -0
- package/src/lib/components/{ui/Paper → Paper}/Paper.jsx +8 -1
- package/src/lib/components/{ui/Paper → Paper}/Paper.scss +5 -0
- package/src/lib/components/{ui/Paper → Paper}/README.mdx +15 -3
- package/src/lib/components/{ui/Paper → Paper}/_theme.scss +2 -0
- package/src/lib/components/{ui/Paper → Paper}/index.js +0 -0
- package/src/lib/components/{ui/Radio → Radio}/README.mdx +20 -17
- package/src/lib/components/Radio/Radio.jsx +188 -0
- package/src/lib/components/{ui/Radio → Radio}/Radio.scss +9 -9
- package/src/lib/components/{ui/Radio → Radio}/index.js +0 -0
- package/src/lib/components/{ui/ScrollView → ScrollView}/README.mdx +11 -11
- package/src/lib/components/{ui/ScrollView → ScrollView}/ScrollView.jsx +9 -10
- package/src/lib/components/{ui/ScrollView → ScrollView}/ScrollView.scss +6 -6
- package/src/lib/components/{ui/ScrollView → ScrollView}/_theme.scss +0 -0
- package/src/lib/components/{ui/ScrollView → ScrollView}/index.js +0 -0
- package/src/lib/components/{ui/SelectField → SelectField}/README.mdx +47 -44
- package/src/lib/components/SelectField/SelectField.jsx +219 -0
- package/src/lib/components/{ui/SelectField → SelectField}/SelectField.scss +6 -6
- package/src/lib/components/{ui/SelectField → SelectField}/index.js +0 -0
- package/src/lib/components/{ui/Table → Table}/README.mdx +10 -10
- package/src/lib/components/{ui/Table → Table}/Table.jsx +9 -13
- package/src/lib/components/{ui/Table → Table}/Table.scss +1 -1
- package/src/lib/components/{ui/Table → Table}/_settings.scss +4 -4
- package/src/lib/components/{ui/Table → Table}/index.js +0 -0
- package/src/lib/components/{ui/Tabs → Tabs}/README.mdx +4 -4
- package/src/lib/components/{ui/Tabs → Tabs}/Tabs.jsx +4 -4
- package/src/lib/components/{ui/Tabs → Tabs}/Tabs.scss +1 -1
- package/src/lib/components/{ui/Tabs → Tabs}/TabsItem.jsx +4 -3
- package/src/lib/components/{ui/Tabs → Tabs}/TabsItem.scss +3 -3
- package/src/lib/components/{ui/Tabs → Tabs}/_theme.scss +0 -0
- package/src/lib/components/{ui/Tabs → Tabs}/index.js +0 -0
- package/src/lib/components/{ui/Text → Text}/README.mdx +19 -19
- package/src/lib/components/{ui/Text → Text}/Text.jsx +1 -1
- package/src/lib/components/{ui/Text → Text}/Text.scss +0 -0
- package/src/lib/components/{ui/Text → Text}/helpers/getRootHyphensClassName.js +0 -0
- package/src/lib/components/{ui/Text → Text}/helpers/getRootWordWrappingClassName.js +0 -0
- package/src/lib/components/{ui/Text → Text}/index.js +0 -0
- package/src/lib/components/{ui/TextArea → TextArea}/README.mdx +8 -6
- package/src/lib/components/{ui/TextArea → TextArea}/TextArea.jsx +78 -78
- package/src/lib/components/{ui/TextArea → TextArea}/TextArea.scss +6 -6
- package/src/lib/components/{ui/TextArea → TextArea}/index.js +0 -0
- package/src/lib/components/{ui/TextField → TextField}/README.mdx +7 -6
- package/src/lib/components/{ui/TextField → TextField}/TextField.jsx +20 -22
- package/src/lib/components/{ui/TextField → TextField}/TextField.scss +6 -6
- package/src/lib/components/{ui/TextField → TextField}/index.js +0 -0
- package/src/lib/components/{ui/Toggle → Toggle}/README.mdx +17 -14
- package/src/lib/components/Toggle/Toggle.jsx +163 -0
- package/src/lib/components/{ui/Toggle → Toggle}/Toggle.scss +5 -5
- package/src/lib/components/{ui/Toggle → Toggle}/index.js +0 -0
- package/src/lib/components/{layout/Toolbar → Toolbar}/README.mdx +29 -29
- package/src/lib/components/{layout/Toolbar → Toolbar}/Toolbar.jsx +1 -1
- package/src/lib/components/{layout/Toolbar → Toolbar}/Toolbar.scss +1 -1
- package/src/lib/components/{layout/Toolbar → Toolbar}/ToolbarGroup.jsx +1 -1
- package/src/lib/components/{layout/Toolbar → Toolbar}/ToolbarItem.jsx +1 -1
- package/src/lib/components/{layout/Toolbar → Toolbar}/_theme.scss +0 -0
- package/src/lib/components/{layout/Toolbar → Toolbar}/index.js +0 -0
- package/src/lib/components/{ui/withForwardedRef.jsx → withForwardedRef.jsx} +0 -0
- package/src/lib/helpers/resolveContextOrProp.js +7 -0
- package/src/lib/index.js +34 -35
- package/src/lib/styles/tools/_accessibility.scss +9 -0
- package/src/lib/theme.scss +25 -7
- package/src/lib/components/ui/Button/Button.jsx +0 -191
- package/src/lib/components/ui/Button/_base.scss +0 -154
- package/src/lib/components/ui/Button/helpers/getRootLabelVisibilityClassName.js +0 -11
- package/src/lib/components/ui/ButtonGroup/index.js +0 -1
- package/src/lib/components/ui/CheckboxField/CheckboxField.jsx +0 -173
- package/src/lib/components/ui/FileInputField/FileInputField.jsx +0 -158
- package/src/lib/components/ui/Radio/Radio.jsx +0 -179
- package/src/lib/components/ui/SelectField/SelectField.jsx +0 -214
- package/src/lib/components/ui/Toggle/Toggle.jsx +0 -174
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import PropTypes from 'prop-types';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import getRootSizeClassName from '
|
|
4
|
-
import getRootValidationStateClassName from '
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
2
|
+
import React, { useContext } from 'react';
|
|
3
|
+
import getRootSizeClassName from '../../helpers/getRootSizeClassName';
|
|
4
|
+
import getRootValidationStateClassName from '../../helpers/getRootValidationStateClassName';
|
|
5
|
+
import { resolveContextOrProp } from '../../helpers/resolveContextOrProp';
|
|
6
|
+
import { withProviderContext } from '../../provider';
|
|
7
|
+
import transferProps from '../../utils/transferProps';
|
|
8
|
+
import { FormLayoutContext } from '../FormLayout';
|
|
7
9
|
import withForwardedRef from '../withForwardedRef';
|
|
8
10
|
import styles from './TextField.scss';
|
|
9
11
|
|
|
10
12
|
const SMALL_INPUT_SIZE = 10;
|
|
11
13
|
|
|
12
14
|
export const TextField = ({
|
|
13
|
-
changeHandler,
|
|
14
15
|
disabled,
|
|
15
16
|
forwardedRef,
|
|
16
17
|
fullWidth,
|
|
17
18
|
helpText,
|
|
18
19
|
id,
|
|
19
|
-
inFormLayout,
|
|
20
20
|
inputSize,
|
|
21
21
|
isLabelVisible,
|
|
22
22
|
label,
|
|
@@ -31,6 +31,7 @@ export const TextField = ({
|
|
|
31
31
|
variant,
|
|
32
32
|
...restProps
|
|
33
33
|
}) => {
|
|
34
|
+
const context = useContext(FormLayoutContext);
|
|
34
35
|
const hasSmallInput = (inputSize !== null) && (inputSize <= SMALL_INPUT_SIZE);
|
|
35
36
|
|
|
36
37
|
return (
|
|
@@ -39,9 +40,11 @@ export const TextField = ({
|
|
|
39
40
|
styles.root,
|
|
40
41
|
fullWidth ? styles.isRootFullWidth : '',
|
|
41
42
|
hasSmallInput ? styles.hasRootSmallInput : '',
|
|
42
|
-
inFormLayout ? styles.isRootInFormLayout : '',
|
|
43
43
|
inputSize ? styles.hasRootCustomInputSize : '',
|
|
44
|
-
|
|
44
|
+
context ? styles.isRootInFormLayout : '',
|
|
45
|
+
resolveContextOrProp(context && context.layout, layout) === 'horizontal'
|
|
46
|
+
? styles.rootLayoutHorizontal
|
|
47
|
+
: styles.rootLayoutVertical,
|
|
45
48
|
disabled ? styles.isRootDisabled : '',
|
|
46
49
|
required ? styles.isRootRequired : '',
|
|
47
50
|
getRootSizeClassName(size, styles),
|
|
@@ -68,7 +71,6 @@ export const TextField = ({
|
|
|
68
71
|
className={styles.input}
|
|
69
72
|
disabled={disabled}
|
|
70
73
|
id={id}
|
|
71
|
-
onChange={changeHandler}
|
|
72
74
|
placeholder={placeholder}
|
|
73
75
|
ref={forwardedRef}
|
|
74
76
|
required={required}
|
|
@@ -102,13 +104,11 @@ export const TextField = ({
|
|
|
102
104
|
};
|
|
103
105
|
|
|
104
106
|
TextField.defaultProps = {
|
|
105
|
-
changeHandler: null,
|
|
106
107
|
disabled: false,
|
|
107
108
|
forwardedRef: undefined,
|
|
108
109
|
fullWidth: false,
|
|
109
110
|
helpText: null,
|
|
110
111
|
id: undefined,
|
|
111
|
-
inFormLayout: false,
|
|
112
112
|
inputSize: null,
|
|
113
113
|
isLabelVisible: true,
|
|
114
114
|
layout: 'vertical',
|
|
@@ -123,10 +123,6 @@ TextField.defaultProps = {
|
|
|
123
123
|
};
|
|
124
124
|
|
|
125
125
|
TextField.propTypes = {
|
|
126
|
-
/**
|
|
127
|
-
* Function to call when the input has changed.
|
|
128
|
-
*/
|
|
129
|
-
changeHandler: PropTypes.func,
|
|
130
126
|
/**
|
|
131
127
|
* If `true`, the input will be disabled.
|
|
132
128
|
*/
|
|
@@ -148,17 +144,16 @@ TextField.propTypes = {
|
|
|
148
144
|
*/
|
|
149
145
|
helpText: PropTypes.node,
|
|
150
146
|
/**
|
|
151
|
-
* ID of the input HTML element. It also serves as a prefix for
|
|
152
|
-
* `<ID>__label
|
|
147
|
+
* ID of the input HTML element. It also serves as a prefix for nested elements:
|
|
148
|
+
* * `<ID>__label`
|
|
149
|
+
* * `<ID>__labelText`
|
|
150
|
+
* * `<ID>__helpText`
|
|
151
|
+
* * `<ID>__validationText`
|
|
153
152
|
*/
|
|
154
153
|
id: PropTypes.string,
|
|
155
154
|
/**
|
|
156
155
|
* Treat the field differently when it's inside a FormLayout. Do not set manually!
|
|
157
156
|
*/
|
|
158
|
-
inFormLayout: PropTypes.bool,
|
|
159
|
-
/**
|
|
160
|
-
* Width of the input field. Translated as `size` attribute for input types other than `number`.
|
|
161
|
-
*/
|
|
162
157
|
inputSize: PropTypes.number,
|
|
163
158
|
/**
|
|
164
159
|
* If `false`, the label will be visually hidden (but remains accessible by assistive
|
|
@@ -171,6 +166,9 @@ TextField.propTypes = {
|
|
|
171
166
|
label: PropTypes.string.isRequired,
|
|
172
167
|
/**
|
|
173
168
|
* Layout of the field.
|
|
169
|
+
*
|
|
170
|
+
* Ignored if the component is rendered within `FormLayout` component
|
|
171
|
+
* as the value is inherited in such case.
|
|
174
172
|
*/
|
|
175
173
|
layout: PropTypes.oneOf(['horizontal', 'vertical']),
|
|
176
174
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
@use '
|
|
2
|
-
@use '
|
|
3
|
-
@use '
|
|
4
|
-
@use '
|
|
5
|
-
@use '
|
|
6
|
-
@use '
|
|
1
|
+
@use '../../styles/tools/form-fields/box-field-elements';
|
|
2
|
+
@use '../../styles/tools/form-fields/box-field-layout';
|
|
3
|
+
@use '../../styles/tools/form-fields/box-field-sizes';
|
|
4
|
+
@use '../../styles/tools/form-fields/foundation';
|
|
5
|
+
@use '../../styles/tools/form-fields/variants';
|
|
6
|
+
@use '../../styles/tools/accessibility';
|
|
7
7
|
|
|
8
8
|
// Foundation
|
|
9
9
|
.root {
|
|
File without changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: Toggle
|
|
3
|
-
menu: '
|
|
4
|
-
route: /components/
|
|
3
|
+
menu: 'Inputs'
|
|
4
|
+
route: /components/toggle
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# Toggle
|
|
@@ -29,9 +29,9 @@ And use it:
|
|
|
29
29
|
const [studioQuality, setStudioQuality] = React.useState(true);
|
|
30
30
|
return (
|
|
31
31
|
<Toggle
|
|
32
|
-
changeHandler={() => setStudioQuality(!studioQuality)}
|
|
33
32
|
checked={studioQuality}
|
|
34
33
|
label="Listen in studio quality"
|
|
34
|
+
onChange={() => setStudioQuality(!studioQuality)}
|
|
35
35
|
/>
|
|
36
36
|
);
|
|
37
37
|
}}
|
|
@@ -44,7 +44,7 @@ See [API](#api) for all available options.
|
|
|
44
44
|
- Use the toggle only for boolean (true/false) input **with an immediate effect
|
|
45
45
|
(without confirmation)**. To toggle things on or off in forms that require to
|
|
46
46
|
be submitted by a button, use rather the
|
|
47
|
-
[CheckboxField](/components/
|
|
47
|
+
[CheckboxField](/components/checkbox-field) component.
|
|
48
48
|
|
|
49
49
|
- **Use positive wording for the toggle label,** so that it's clear what will
|
|
50
50
|
happen when the user turns on the toggle. Avoid negations such as “Don't send
|
|
@@ -63,7 +63,7 @@ See [API](#api) for all available options.
|
|
|
63
63
|
- The toggle is designed for **switching things on and off.** Don't use it to
|
|
64
64
|
switch between two different things that cannot be described as on or off
|
|
65
65
|
using a single label, e.g. different viewing modes. In such cases, consider
|
|
66
|
-
using the [ButtonGroup](/components/
|
|
66
|
+
using the [ButtonGroup](/components/button-group) component.
|
|
67
67
|
|
|
68
68
|
## Help Text
|
|
69
69
|
|
|
@@ -75,13 +75,13 @@ turning the toggle on or off.
|
|
|
75
75
|
const [studioQuality, setStudioQuality] = React.useState(true);
|
|
76
76
|
return (
|
|
77
77
|
<Toggle
|
|
78
|
-
changeHandler={() => setStudioQuality(!studioQuality)}
|
|
79
78
|
checked={studioQuality}
|
|
80
79
|
helpText={
|
|
81
80
|
'Unrivaled audio quality. Uses the MQA audio format. '
|
|
82
81
|
+ 'Transfers a lot of data.'
|
|
83
82
|
}
|
|
84
83
|
label="Listen in studio quality"
|
|
84
|
+
onChange={() => setStudioQuality(!studioQuality)}
|
|
85
85
|
/>
|
|
86
86
|
);
|
|
87
87
|
}}
|
|
@@ -97,10 +97,10 @@ remains accessible to assistive technologies.
|
|
|
97
97
|
const [studioQuality, setStudioQuality] = React.useState(true);
|
|
98
98
|
return (
|
|
99
99
|
<Toggle
|
|
100
|
-
changeHandler={() => setStudioQuality(!studioQuality)}
|
|
101
100
|
checked={studioQuality}
|
|
102
101
|
isLabelVisible={false}
|
|
103
102
|
label="You cannot see this"
|
|
103
|
+
onChange={() => setStudioQuality(!studioQuality)}
|
|
104
104
|
/>
|
|
105
105
|
);
|
|
106
106
|
}}
|
|
@@ -113,10 +113,10 @@ It's also possible to display the label before the input:
|
|
|
113
113
|
const [studioQuality, setStudioQuality] = React.useState(true);
|
|
114
114
|
return (
|
|
115
115
|
<Toggle
|
|
116
|
-
changeHandler={() => setStudioQuality(!studioQuality)}
|
|
117
116
|
checked={studioQuality}
|
|
118
117
|
label="Listen in studio quality"
|
|
119
118
|
labelPosition="before"
|
|
119
|
+
onChange={() => setStudioQuality(!studioQuality)}
|
|
120
120
|
/>
|
|
121
121
|
);
|
|
122
122
|
}}
|
|
@@ -137,15 +137,15 @@ have.
|
|
|
137
137
|
return (
|
|
138
138
|
<>
|
|
139
139
|
<Toggle
|
|
140
|
-
changeHandler={() => setStudioQuality(!studioQuality)}
|
|
141
140
|
checked={studioQuality}
|
|
142
141
|
label="Listen in studio quality"
|
|
142
|
+
onChange={() => setStudioQuality(!studioQuality)}
|
|
143
143
|
validationState="valid"
|
|
144
144
|
/>
|
|
145
145
|
<Toggle
|
|
146
|
-
changeHandler={() => setStudioQuality(!studioQuality)}
|
|
147
146
|
checked={studioQuality}
|
|
148
147
|
label="Listen in studio quality"
|
|
148
|
+
onChange={() => setStudioQuality(!studioQuality)}
|
|
149
149
|
validationState="warning"
|
|
150
150
|
validationText={
|
|
151
151
|
'Looks like you are connected over cellular network. '
|
|
@@ -153,9 +153,9 @@ have.
|
|
|
153
153
|
}
|
|
154
154
|
/>
|
|
155
155
|
<Toggle
|
|
156
|
-
changeHandler={() => setStudioQuality(!studioQuality)}
|
|
157
156
|
checked={studioQuality}
|
|
158
157
|
label="Listen in studio quality"
|
|
158
|
+
onChange={() => setStudioQuality(!studioQuality)}
|
|
159
159
|
validationState="invalid"
|
|
160
160
|
validationText="Please upgrade your plan to make this option available."
|
|
161
161
|
/>
|
|
@@ -179,9 +179,10 @@ Disabled state makes the input unavailable.
|
|
|
179
179
|
|
|
180
180
|
## API
|
|
181
181
|
|
|
182
|
-
In addition to the options below, you can
|
|
183
|
-
interfere with the API, and they will be
|
|
184
|
-
|
|
182
|
+
In addition to the options below, you can specify [React synthetic events] or
|
|
183
|
+
any custom HTML attributes that do not interfere with the API, and they will be
|
|
184
|
+
passed to the `input` HTML element. This enables making the component
|
|
185
|
+
interactive and helps improve its accessibility.
|
|
185
186
|
|
|
186
187
|
<Props table of={Toggle} />
|
|
187
188
|
|
|
@@ -199,3 +200,5 @@ options. On top of that, the following options are available for Toggle.
|
|
|
199
200
|
| `--rui-FormField--check__input--toggle--default__background-position` | Background position of unchecked input |
|
|
200
201
|
| `--rui-FormField--check__input--toggle--checked__background-image` | Background image of checked input |
|
|
201
202
|
| `--rui-FormField--check__input--toggle--checked__background-position` | Background position of checked input |
|
|
203
|
+
|
|
204
|
+
[React synthetic events]: https://reactjs.org/docs/events.html
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import React, { useContext } from 'react';
|
|
3
|
+
import getRootValidationStateClassName from '../../helpers/getRootValidationStateClassName';
|
|
4
|
+
import { withProviderContext } from '../../provider';
|
|
5
|
+
import transferProps from '../../utils/transferProps';
|
|
6
|
+
import { FormLayoutContext } from '../FormLayout';
|
|
7
|
+
import withForwardedRef from '../withForwardedRef';
|
|
8
|
+
import styles from './Toggle.scss';
|
|
9
|
+
|
|
10
|
+
export const Toggle = ({
|
|
11
|
+
checked,
|
|
12
|
+
disabled,
|
|
13
|
+
forwardedRef,
|
|
14
|
+
helpText,
|
|
15
|
+
id,
|
|
16
|
+
isLabelVisible,
|
|
17
|
+
label,
|
|
18
|
+
labelPosition,
|
|
19
|
+
required,
|
|
20
|
+
validationState,
|
|
21
|
+
validationText,
|
|
22
|
+
value,
|
|
23
|
+
...restProps
|
|
24
|
+
}) => {
|
|
25
|
+
const context = useContext(FormLayoutContext);
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<label
|
|
29
|
+
className={[
|
|
30
|
+
styles.root,
|
|
31
|
+
context ? styles.isRootInFormLayout : '',
|
|
32
|
+
context && context.layout === 'horizontal' ? styles.rootLayoutHorizontal : styles.rootLayoutVertical,
|
|
33
|
+
labelPosition === 'before' ? styles.hasRootLabelBefore : '',
|
|
34
|
+
disabled ? styles.isRootDisabled : '',
|
|
35
|
+
required ? styles.isRootRequired : '',
|
|
36
|
+
getRootValidationStateClassName(validationState, styles),
|
|
37
|
+
].join(' ')}
|
|
38
|
+
htmlFor={id}
|
|
39
|
+
id={id && `${id}__label`}
|
|
40
|
+
>
|
|
41
|
+
<div className={styles.field}>
|
|
42
|
+
<input
|
|
43
|
+
{...transferProps(restProps)}
|
|
44
|
+
checked={checked}
|
|
45
|
+
className={styles.input}
|
|
46
|
+
disabled={disabled}
|
|
47
|
+
id={id}
|
|
48
|
+
name={id}
|
|
49
|
+
ref={forwardedRef}
|
|
50
|
+
required={required}
|
|
51
|
+
type="checkbox"
|
|
52
|
+
value={value}
|
|
53
|
+
/>
|
|
54
|
+
<div
|
|
55
|
+
className={[
|
|
56
|
+
styles.label,
|
|
57
|
+
isLabelVisible ? '' : styles.isLabelHidden,
|
|
58
|
+
].join(' ')}
|
|
59
|
+
id={id && `${id}__labelText`}
|
|
60
|
+
>
|
|
61
|
+
{label}
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
{helpText && (
|
|
65
|
+
<div
|
|
66
|
+
className={styles.helpText}
|
|
67
|
+
id={id && `${id}__helpText`}
|
|
68
|
+
>
|
|
69
|
+
{helpText}
|
|
70
|
+
</div>
|
|
71
|
+
)}
|
|
72
|
+
{validationText && (
|
|
73
|
+
<div
|
|
74
|
+
className={styles.validationText}
|
|
75
|
+
id={id && `${id}__validationText`}
|
|
76
|
+
>
|
|
77
|
+
{validationText}
|
|
78
|
+
</div>
|
|
79
|
+
)}
|
|
80
|
+
</label>
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
Toggle.defaultProps = {
|
|
85
|
+
checked: undefined,
|
|
86
|
+
disabled: false,
|
|
87
|
+
forwardedRef: undefined,
|
|
88
|
+
helpText: null,
|
|
89
|
+
id: undefined,
|
|
90
|
+
isLabelVisible: true,
|
|
91
|
+
labelPosition: 'after',
|
|
92
|
+
required: false,
|
|
93
|
+
validationState: null,
|
|
94
|
+
validationText: null,
|
|
95
|
+
value: undefined,
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
Toggle.propTypes = {
|
|
99
|
+
/**
|
|
100
|
+
* If `true`, the input will be checked.
|
|
101
|
+
*/
|
|
102
|
+
checked: PropTypes.bool,
|
|
103
|
+
/**
|
|
104
|
+
* If `true`, the input will be disabled.
|
|
105
|
+
*/
|
|
106
|
+
disabled: PropTypes.bool,
|
|
107
|
+
/**
|
|
108
|
+
* Reference forwarded to the `input` element.
|
|
109
|
+
*/
|
|
110
|
+
forwardedRef: PropTypes.oneOfType([
|
|
111
|
+
PropTypes.func,
|
|
112
|
+
// eslint-disable-next-line react/forbid-prop-types
|
|
113
|
+
PropTypes.shape({ current: PropTypes.any }),
|
|
114
|
+
]),
|
|
115
|
+
/**
|
|
116
|
+
* Optional help text.
|
|
117
|
+
*/
|
|
118
|
+
helpText: PropTypes.node,
|
|
119
|
+
/**
|
|
120
|
+
* ID of the input HTML element. It also serves as a prefix for nested elements:
|
|
121
|
+
* * `<ID>__label`
|
|
122
|
+
* * `<ID>__labelText`
|
|
123
|
+
* * `<ID>__helpText`
|
|
124
|
+
* * `<ID>__validationText`
|
|
125
|
+
*/
|
|
126
|
+
id: PropTypes.string,
|
|
127
|
+
/**
|
|
128
|
+
* If `false`, the label will be visually hidden (but remains accessible by assistive
|
|
129
|
+
* technologies).
|
|
130
|
+
*/
|
|
131
|
+
isLabelVisible: PropTypes.bool,
|
|
132
|
+
/**
|
|
133
|
+
* Toggle label.
|
|
134
|
+
*/
|
|
135
|
+
label: PropTypes.string.isRequired,
|
|
136
|
+
/**
|
|
137
|
+
* Placement of the label relative to the input.
|
|
138
|
+
*/
|
|
139
|
+
labelPosition: PropTypes.oneOf(['before', 'after']),
|
|
140
|
+
/**
|
|
141
|
+
* If `true`, the input will be required.
|
|
142
|
+
*/
|
|
143
|
+
required: PropTypes.bool,
|
|
144
|
+
/**
|
|
145
|
+
* Alter the field to provide feedback based on validation result.
|
|
146
|
+
*/
|
|
147
|
+
validationState: PropTypes.oneOf(['invalid', 'valid', 'warning']),
|
|
148
|
+
/**
|
|
149
|
+
* Validation message to be displayed.
|
|
150
|
+
*/
|
|
151
|
+
validationText: PropTypes.node,
|
|
152
|
+
/**
|
|
153
|
+
* Value of the input.
|
|
154
|
+
*/
|
|
155
|
+
value: PropTypes.oneOfType([
|
|
156
|
+
PropTypes.string,
|
|
157
|
+
PropTypes.number,
|
|
158
|
+
]),
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export const ToggleWithContext = withForwardedRef(withProviderContext(Toggle, 'Toggle'));
|
|
162
|
+
|
|
163
|
+
export default ToggleWithContext;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
@use '
|
|
2
|
-
@use '
|
|
3
|
-
@use '
|
|
4
|
-
@use '
|
|
5
|
-
@use '
|
|
1
|
+
@use '../../styles/tools/form-fields/foundation';
|
|
2
|
+
@use '../../styles/tools/form-fields/inline-field-elements';
|
|
3
|
+
@use '../../styles/tools/form-fields/inline-field-layout';
|
|
4
|
+
@use '../../styles/tools/form-fields/variants';
|
|
5
|
+
@use '../../styles/tools/accessibility';
|
|
6
6
|
|
|
7
7
|
// Foundation
|
|
8
8
|
.root {
|
|
File without changes
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: Toolbar
|
|
3
3
|
menu: 'Layouts'
|
|
4
|
-
route: /components/
|
|
4
|
+
route: /components/toolbar
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# Toolbar
|
|
@@ -10,10 +10,10 @@ import {
|
|
|
10
10
|
Playground,
|
|
11
11
|
Props,
|
|
12
12
|
} from 'docz'
|
|
13
|
-
import { Placeholder } from '
|
|
14
|
-
import { CheckboxField } from '
|
|
15
|
-
import { Button } from '
|
|
16
|
-
import { ButtonGroup } from '
|
|
13
|
+
import { Placeholder } from '../../../docs/_components/Placeholder/Placeholder'
|
|
14
|
+
import { CheckboxField } from '../CheckboxField/CheckboxField'
|
|
15
|
+
import { Button } from '../Button/Button'
|
|
16
|
+
import { ButtonGroup } from '../ButtonGroup/ButtonGroup'
|
|
17
17
|
import { Toolbar } from './Toolbar'
|
|
18
18
|
import { ToolbarGroup } from './ToolbarGroup'
|
|
19
19
|
import { ToolbarItem } from './ToolbarItem'
|
|
@@ -90,24 +90,24 @@ of `right`.
|
|
|
90
90
|
<ToolbarItem>
|
|
91
91
|
<ButtonGroup aria-labelledby="#alignment-label">
|
|
92
92
|
<Button
|
|
93
|
-
label="top"
|
|
94
|
-
clickHandler={() => setAlignment('top')}
|
|
95
93
|
color={alignment === 'top' ? 'dark' : 'primary'}
|
|
94
|
+
label="top"
|
|
95
|
+
onClick={() => setAlignment('top')}
|
|
96
96
|
/>
|
|
97
97
|
<Button
|
|
98
|
-
label="middle"
|
|
99
|
-
clickHandler={() => setAlignment('middle')}
|
|
100
98
|
color={alignment === 'middle' ? 'dark' : 'primary'}
|
|
99
|
+
label="middle"
|
|
100
|
+
onClick={() => setAlignment('middle')}
|
|
101
101
|
/>
|
|
102
102
|
<Button
|
|
103
|
-
label="bottom"
|
|
104
|
-
clickHandler={() => setAlignment('bottom')}
|
|
105
103
|
color={alignment === 'bottom' ? 'dark' : 'primary'}
|
|
104
|
+
label="bottom"
|
|
105
|
+
onClick={() => setAlignment('bottom')}
|
|
106
106
|
/>
|
|
107
107
|
<Button
|
|
108
|
-
label="baseline"
|
|
109
|
-
clickHandler={() => setAlignment('baseline')}
|
|
110
108
|
color={alignment === 'baseline' ? 'dark' : 'primary'}
|
|
109
|
+
label="baseline"
|
|
110
|
+
onClick={() => setAlignment('baseline')}
|
|
111
111
|
/>
|
|
112
112
|
</ButtonGroup>
|
|
113
113
|
</ToolbarItem>
|
|
@@ -119,24 +119,24 @@ of `right`.
|
|
|
119
119
|
<ToolbarItem>
|
|
120
120
|
<ButtonGroup aria-labelledby="#justification-label">
|
|
121
121
|
<Button
|
|
122
|
-
label="start"
|
|
123
|
-
clickHandler={() => setJustification('start')}
|
|
124
122
|
color={justification === 'start' ? 'dark' : 'primary'}
|
|
123
|
+
label="start"
|
|
124
|
+
onClick={() => setJustification('start')}
|
|
125
125
|
/>
|
|
126
126
|
<Button
|
|
127
|
-
label="center"
|
|
128
|
-
clickHandler={() => setJustification('center')}
|
|
129
127
|
color={justification === 'center' ? 'dark' : 'primary'}
|
|
128
|
+
label="center"
|
|
129
|
+
onClick={() => setJustification('center')}
|
|
130
130
|
/>
|
|
131
131
|
<Button
|
|
132
|
-
label="end"
|
|
133
|
-
clickHandler={() => setJustification('end')}
|
|
134
132
|
color={justification === 'end' ? 'dark' : 'primary'}
|
|
133
|
+
label="end"
|
|
134
|
+
onClick={() => setJustification('end')}
|
|
135
135
|
/>
|
|
136
136
|
<Button
|
|
137
|
-
label="space-between"
|
|
138
|
-
clickHandler={() => setJustification('space-between')}
|
|
139
137
|
color={justification === 'space-between' ? 'dark' : 'primary'}
|
|
138
|
+
label="space-between"
|
|
139
|
+
onClick={() => setJustification('space-between')}
|
|
140
140
|
/>
|
|
141
141
|
</ButtonGroup>
|
|
142
142
|
</ToolbarItem>
|
|
@@ -207,16 +207,16 @@ toolbar groups, or on the entire toolbar.
|
|
|
207
207
|
<Toolbar>
|
|
208
208
|
<ToolbarItem>
|
|
209
209
|
<CheckboxField
|
|
210
|
-
label="Dense ToolbarGroup"
|
|
211
|
-
changeHandler={(e) => setIsGroupDense(e.target.checked)}
|
|
212
210
|
checked={isGroupDense}
|
|
211
|
+
label="Dense ToolbarGroup"
|
|
212
|
+
onChange={(e) => setIsGroupDense(e.target.checked)}
|
|
213
213
|
/>
|
|
214
214
|
</ToolbarItem>
|
|
215
215
|
<ToolbarItem>
|
|
216
216
|
<CheckboxField
|
|
217
|
-
label="Dense Toolbar"
|
|
218
|
-
changeHandler={(e) => setIsToolbarDense(e.target.checked)}
|
|
219
217
|
checked={isToolbarDense}
|
|
218
|
+
label="Dense Toolbar"
|
|
219
|
+
onChange={(e) => setIsToolbarDense(e.target.checked)}
|
|
220
220
|
/>
|
|
221
221
|
</ToolbarItem>
|
|
222
222
|
</Toolbar>
|
|
@@ -249,7 +249,7 @@ set the `nowrap` option on the Toolbar or on individual ToolbarGroups. Note that
|
|
|
249
249
|
ToolbarGroups can still wrap when the wrapping is disabled just on their parent
|
|
250
250
|
Toolbar.
|
|
251
251
|
|
|
252
|
-
Try resizing the playground below to see how it works.
|
|
252
|
+
📐 Try resizing the playground below to see how it works.
|
|
253
253
|
|
|
254
254
|
<Playground>
|
|
255
255
|
<>
|
|
@@ -329,7 +329,7 @@ A wrapper for individual toolbar items.
|
|
|
329
329
|
|
|
330
330
|
[inline-elements]: https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
|
|
331
331
|
[block-elements]: https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements
|
|
332
|
-
[grid]: /components/
|
|
333
|
-
[list]: /components/
|
|
332
|
+
[grid]: /components/grid
|
|
333
|
+
[list]: /components/list
|
|
334
334
|
[spacing]: /css-helpers/spacing
|
|
335
|
-
[text]: /components/
|
|
335
|
+
[text]: /components/text
|
|
File without changes
|
|
File without changes
|
|
File without changes
|