@react-ui-org/react-ui 0.47.0 → 0.49.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. package/dist/lib.development.js +465 -93
  2. package/dist/lib.js +1 -1
  3. package/package.json +1 -1
  4. package/src/lib/components/Alert/Alert.jsx +3 -0
  5. package/src/lib/components/Alert/Alert.scss +10 -10
  6. package/src/lib/components/Alert/README.mdx +18 -2
  7. package/src/lib/components/Alert/index.js +1 -1
  8. package/src/lib/components/Badge/Badge.jsx +4 -8
  9. package/src/lib/components/Badge/Badge.scss +21 -21
  10. package/src/lib/components/Badge/README.mdx +15 -1
  11. package/src/lib/components/Badge/index.js +1 -1
  12. package/src/lib/components/Button/Button.jsx +23 -34
  13. package/src/lib/components/Button/README.mdx +21 -7
  14. package/src/lib/components/Button/_base.scss +20 -20
  15. package/src/lib/components/Button/_priorities.scss +35 -35
  16. package/src/lib/components/Button/helpers/getRootLabelVisibilityClassName.js +7 -7
  17. package/src/lib/components/Button/helpers/getRootPriorityClassName.js +3 -3
  18. package/src/lib/components/Button/index.js +1 -1
  19. package/src/lib/components/ButtonGroup/ButtonGroup.jsx +2 -8
  20. package/src/lib/components/ButtonGroup/README.mdx +18 -2
  21. package/src/lib/components/Card/Card.jsx +6 -10
  22. package/src/lib/components/Card/Card.scss +13 -13
  23. package/src/lib/components/Card/CardBody.jsx +6 -10
  24. package/src/lib/components/Card/CardFooter.jsx +6 -7
  25. package/src/lib/components/Card/README.mdx +21 -5
  26. package/src/lib/components/CheckboxField/CheckboxField.jsx +17 -44
  27. package/src/lib/components/CheckboxField/README.mdx +18 -6
  28. package/src/lib/components/CheckboxField/index.js +1 -1
  29. package/src/lib/components/FileInputField/FileInputField.jsx +20 -29
  30. package/src/lib/components/FileInputField/FileInputField.scss +3 -3
  31. package/src/lib/components/FileInputField/README.mdx +30 -28
  32. package/src/lib/components/FileInputField/index.js +1 -1
  33. package/src/lib/components/FormLayout/FormLayout.jsx +5 -9
  34. package/src/lib/components/FormLayout/FormLayout.scss +3 -3
  35. package/src/lib/components/FormLayout/FormLayoutCustomField.jsx +4 -1
  36. package/src/lib/components/FormLayout/FormLayoutCustomField.scss +8 -8
  37. package/src/lib/components/FormLayout/README.mdx +28 -13
  38. package/src/lib/components/Grid/Grid.jsx +31 -35
  39. package/src/lib/components/Grid/Grid.scss +10 -15
  40. package/src/lib/components/Grid/GridSpan.jsx +5 -11
  41. package/src/lib/components/Grid/README.mdx +48 -36
  42. package/src/lib/components/Grid/_helpers/generateResponsiveCustomProperties.js +11 -3
  43. package/src/lib/components/Grid/_settings.scss +18 -0
  44. package/src/lib/components/Grid/_tools.scss +5 -5
  45. package/src/lib/components/Modal/Modal.jsx +147 -254
  46. package/src/lib/components/Modal/Modal.scss +7 -55
  47. package/src/lib/components/Modal/ModalBody.jsx +60 -0
  48. package/src/lib/components/Modal/ModalBody.scss +18 -0
  49. package/src/lib/components/Modal/ModalCloseButton.jsx +45 -0
  50. package/src/lib/components/Modal/ModalCloseButton.scss +18 -0
  51. package/src/lib/components/Modal/ModalContent.jsx +39 -0
  52. package/src/lib/components/Modal/ModalContent.scss +5 -0
  53. package/src/lib/components/Modal/ModalFooter.jsx +42 -0
  54. package/src/lib/components/Modal/ModalFooter.scss +35 -0
  55. package/src/lib/components/Modal/ModalHeader.jsx +44 -0
  56. package/src/lib/components/Modal/ModalHeader.scss +30 -0
  57. package/src/lib/components/Modal/ModalTitle.jsx +44 -0
  58. package/src/lib/components/Modal/ModalTitle.scss +10 -0
  59. package/src/lib/components/Modal/README.mdx +865 -195
  60. package/src/lib/components/Modal/_helpers/getJustifyClassName.js +19 -0
  61. package/src/lib/components/Modal/_helpers/getScrollingClassName.js +11 -0
  62. package/src/lib/components/Modal/_settings.scss +1 -5
  63. package/src/lib/components/Modal/_theme.scss +6 -0
  64. package/src/lib/components/Modal/index.js +7 -1
  65. package/src/lib/components/Paper/Paper.jsx +5 -9
  66. package/src/lib/components/Paper/Paper.scss +2 -2
  67. package/src/lib/components/Paper/README.mdx +15 -1
  68. package/src/lib/components/Paper/index.js +1 -1
  69. package/src/lib/components/Popover/Popover.jsx +14 -30
  70. package/src/lib/components/Popover/Popover.scss +7 -6
  71. package/src/lib/components/Popover/PopoverWrapper.jsx +5 -12
  72. package/src/lib/components/Popover/PopoverWrapper.scss +3 -0
  73. package/src/lib/components/Popover/README.mdx +32 -11
  74. package/src/lib/components/Popover/_theme.scss +1 -1
  75. package/src/lib/components/Radio/README.mdx +13 -6
  76. package/src/lib/components/Radio/Radio.jsx +39 -29
  77. package/src/lib/components/Radio/Radio.scss +3 -3
  78. package/src/lib/components/Radio/index.js +1 -1
  79. package/src/lib/components/ScrollView/README.mdx +165 -84
  80. package/src/lib/components/ScrollView/ScrollView.jsx +115 -117
  81. package/src/lib/components/ScrollView/ScrollView.scss +18 -16
  82. package/src/lib/components/ScrollView/index.js +1 -1
  83. package/src/lib/components/SelectField/README.mdx +83 -7
  84. package/src/lib/components/SelectField/SelectField.jsx +86 -61
  85. package/src/lib/components/SelectField/SelectField.scss +8 -8
  86. package/src/lib/components/SelectField/_components/Option/Option.jsx +46 -0
  87. package/src/lib/components/SelectField/_components/Option/index.js +1 -0
  88. package/src/lib/components/SelectField/index.js +1 -1
  89. package/src/lib/components/Table/README.mdx +25 -9
  90. package/src/lib/components/Table/Table.jsx +43 -101
  91. package/src/lib/components/Table/Table.scss +0 -24
  92. package/src/lib/components/Table/_components/TableBodyCell/TableBodyCell.jsx +46 -0
  93. package/src/lib/components/Table/_components/TableBodyCell/index.js +1 -0
  94. package/src/lib/components/Table/_components/TableCell.scss +25 -0
  95. package/src/lib/components/Table/_components/TableHeaderCell/TableHeaderCell.jsx +71 -0
  96. package/src/lib/components/Table/_components/TableHeaderCell/index.js +1 -0
  97. package/src/lib/components/Table/index.js +1 -1
  98. package/src/lib/components/Tabs/README.mdx +21 -3
  99. package/src/lib/components/Tabs/Tabs.jsx +6 -1
  100. package/src/lib/components/Tabs/TabsItem.jsx +3 -0
  101. package/src/lib/components/Tabs/TabsItem.scss +1 -2
  102. package/src/lib/components/Text/README.mdx +25 -7
  103. package/src/lib/components/Text/Text.jsx +3 -7
  104. package/src/lib/components/Text/Text.scss +6 -6
  105. package/src/lib/components/Text/_helpers/getRootClampClassName.js +2 -2
  106. package/src/lib/components/Text/_helpers/getRootHyphensClassName.js +2 -2
  107. package/src/lib/components/Text/_helpers/getRootWordWrappingClassName.js +2 -2
  108. package/src/lib/components/Text/index.js +1 -1
  109. package/src/lib/components/TextArea/README.mdx +34 -31
  110. package/src/lib/components/TextArea/TextArea.jsx +23 -63
  111. package/src/lib/components/TextArea/TextArea.scss +8 -8
  112. package/src/lib/components/TextArea/index.js +1 -1
  113. package/src/lib/components/TextField/README.mdx +56 -54
  114. package/src/lib/components/TextField/TextField.jsx +25 -52
  115. package/src/lib/components/TextField/TextField.scss +9 -9
  116. package/src/lib/components/TextField/index.js +1 -1
  117. package/src/lib/components/TextLink/README.mdx +13 -6
  118. package/src/lib/components/TextLink/TextLink.jsx +0 -10
  119. package/src/lib/components/TextLink/index.js +1 -1
  120. package/src/lib/components/Toggle/README.mdx +18 -6
  121. package/src/lib/components/Toggle/Toggle.jsx +18 -44
  122. package/src/lib/components/Toggle/index.js +1 -1
  123. package/src/lib/components/Toolbar/README.mdx +21 -6
  124. package/src/lib/components/Toolbar/Toolbar.jsx +9 -43
  125. package/src/lib/components/Toolbar/Toolbar.scss +24 -12
  126. package/src/lib/components/Toolbar/ToolbarGroup.jsx +7 -26
  127. package/src/lib/components/Toolbar/ToolbarItem.jsx +3 -7
  128. package/src/lib/components/Toolbar/_helpers/getAlignClassName.js +19 -0
  129. package/src/lib/components/Toolbar/_helpers/getJustifyClassName.js +16 -0
  130. package/src/lib/components/_helpers/getRootColorClassName.js +10 -10
  131. package/src/lib/components/_helpers/getRootSizeClassName.js +3 -3
  132. package/src/lib/components/_helpers/transferProps.js +1 -1
  133. package/src/lib/index.js +24 -16
  134. package/src/lib/provider/withGlobalProps.jsx +20 -3
  135. package/src/lib/styles/tools/form-fields/_box-field-layout.scss +15 -15
  136. package/src/lib/styles/tools/form-fields/_inline-field-elements.scss +1 -1
  137. package/src/lib/styles/tools/form-fields/_inline-field-layout.scss +9 -9
  138. package/src/lib/theme.scss +18 -26
  139. package/src/lib/translations/en.js +1 -1
  140. package/src/lib/components/Grid/_theme.scss +0 -11
  141. package/src/lib/components/ScrollView/_theme.scss +0 -2
  142. package/src/lib/components/withForwardedRef.jsx +0 -11
@@ -12,7 +12,7 @@ import {
12
12
  Playground,
13
13
  Props,
14
14
  } from 'docz'
15
- import { TextField } from './TextField'
15
+ import { TextField } from '../..'
16
16
 
17
17
  ## Basic Usage
18
18
 
@@ -189,8 +189,8 @@ attribute to achieve that effect (doesn't work for `number` input type though).
189
189
  by `inputSize` API option) is
190
190
  [not available for `number` input type][input-number-size]. TextField supports
191
191
  `inputSize` option for all types of inputs, so you can use it whenever you find
192
- it suitable. Just keep in mind the `size` attribute will not be present for
193
- numeric inputs.
192
+ it suitable. Just keep in mind the `size` attribute will not be present in the
193
+ DOM for numeric inputs.
194
194
 
195
195
  <Playground>
196
196
  <TextField
@@ -215,47 +215,6 @@ numeric inputs.
215
215
  />
216
216
  </Playground>
217
217
 
218
- ## Forwarding HTML Attributes
219
-
220
- When you want to improve the accessibility of your text fields even further, you
221
- can **add whatever HTML attribute you like.** All attributes that don't
222
- interfere with [component's API](#api) are forwarded to the native HTML input.
223
-
224
- <Playground>
225
- <TextField
226
- label="Address"
227
- autoComplete="street-address"
228
- minLength={3}
229
- maxLength={80}
230
- />
231
- <TextField
232
- label="Address"
233
- variant="filled"
234
- autoComplete="street-address"
235
- minLength={3}
236
- maxLength={80}
237
- />
238
- <TextField
239
- inputSize={3}
240
- min={13}
241
- max={120}
242
- label="Age"
243
- type="number"
244
- />
245
- <TextField
246
- inputSize={3}
247
- min={13}
248
- max={120}
249
- label="Age"
250
- type="number"
251
- variant="filled"
252
- />
253
- </Playground>
254
-
255
- 👉 Refer to the MDN reference for the full list of supported attributes of the
256
- [text][input-text], [email][input-email], [number][input-number],
257
- [tel][input-tel], and [password][input-password] input types.
258
-
259
218
  ## Invisible Label
260
219
 
261
220
  In some cases, it may be convenient to visually hide the field label. The label
@@ -489,12 +448,54 @@ It's possible to disable the whole input.
489
448
  />
490
449
  </Playground>
491
450
 
492
- ## API
451
+ ## Forwarding HTML Attributes
493
452
 
494
- In addition to the options below, you can specify [React synthetic events] or
495
- any custom HTML attributes that do not interfere with the API, and they will be
496
- passed to the `<input>` HTML element. This enables making the component
497
- interactive and helps improve its [accessibility](#forwarding-html-attributes).
453
+ In addition to the options below in the [component's API](#api) section, you
454
+ can specify [React synthetic events] or you can **add whatever HTML attribute
455
+ you like.** All attributes that don't interfere with the API are forwarded to
456
+ the native HTML `<input>`. This enables making the component interactive and
457
+ helps to improve its accessibility.
458
+
459
+ <Playground>
460
+ <TextField
461
+ label="Address"
462
+ autoComplete="street-address"
463
+ minLength={3}
464
+ maxLength={80}
465
+ />
466
+ <TextField
467
+ label="Address"
468
+ variant="filled"
469
+ autoComplete="street-address"
470
+ minLength={3}
471
+ maxLength={80}
472
+ />
473
+ <TextField
474
+ inputSize={3}
475
+ min={13}
476
+ max={120}
477
+ label="Age"
478
+ type="number"
479
+ />
480
+ <TextField
481
+ inputSize={3}
482
+ min={13}
483
+ max={120}
484
+ label="Age"
485
+ type="number"
486
+ variant="filled"
487
+ />
488
+ </Playground>
489
+
490
+ 👉 Refer to the MDN reference for the full list of supported attributes of the
491
+ [text][input-text], [email][input-email], [number][input-number],
492
+ [tel][input-tel], and [password][input-password] input types.
493
+
494
+ ## Forwarding ref
495
+
496
+ If you provide [ref], it is forwarded to the native HTML `<input>` element.
497
+
498
+ ## API
498
499
 
499
500
  <Props table of={TextField} />
500
501
 
@@ -507,10 +508,11 @@ Head to [Forms Theming][theming-forms] to see shared form theming options.
507
508
  [size]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/text#size
508
509
  [max]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number#max
509
510
  [input-number-size]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number#Controlling_input_size
510
- [input-text]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/text
511
- [input-email]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email
512
- [input-number]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number
513
- [input-tel]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/tel
514
- [input-password]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/password
511
+ [input-text]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/text#additional_attributes
512
+ [input-email]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email#additional_attributes
513
+ [input-number]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number#additional_attributes
514
+ [input-tel]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/tel#additional_attributes
515
+ [input-password]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/password#additional_attributes
515
516
  [theming-forms]: /customize/theming/forms
516
517
  [React synthetic events]: https://reactjs.org/docs/events.html
518
+ [ref]: https://reactjs.org/docs/refs-and-the-dom.html
@@ -7,31 +7,28 @@ import { getRootValidationStateClassName } from '../_helpers/getRootValidationSt
7
7
  import { resolveContextOrProp } from '../_helpers/resolveContextOrProp';
8
8
  import { transferProps } from '../_helpers/transferProps';
9
9
  import { FormLayoutContext } from '../FormLayout';
10
- import withForwardedRef from '../withForwardedRef';
11
10
  import styles from './TextField.scss';
12
11
 
13
12
  const SMALL_INPUT_SIZE = 10;
14
13
 
15
- export const TextField = ({
16
- disabled,
17
- forwardedRef,
18
- fullWidth,
19
- helpText,
20
- id,
21
- inputSize,
22
- isLabelVisible,
23
- label,
24
- layout,
25
- placeholder,
26
- required,
27
- size,
28
- type,
29
- validationState,
30
- validationText,
31
- value,
32
- variant,
33
- ...restProps
34
- }) => {
14
+ export const TextField = React.forwardRef((props, ref) => {
15
+ const {
16
+ disabled,
17
+ fullWidth,
18
+ helpText,
19
+ id,
20
+ inputSize,
21
+ isLabelVisible,
22
+ label,
23
+ layout,
24
+ required,
25
+ size,
26
+ type,
27
+ validationState,
28
+ validationText,
29
+ variant,
30
+ ...restProps
31
+ } = props;
35
32
  const context = useContext(FormLayoutContext);
36
33
  const hasSmallInput = (inputSize !== null) && (inputSize <= SMALL_INPUT_SIZE);
37
34
 
@@ -44,13 +41,13 @@ export const TextField = ({
44
41
  inputSize && styles.hasRootCustomInputSize,
45
42
  context && styles.isRootInFormLayout,
46
43
  resolveContextOrProp(context && context.layout, layout) === 'horizontal'
47
- ? styles.rootLayoutHorizontal
48
- : styles.rootLayoutVertical,
44
+ ? styles.isRootLayoutHorizontal
45
+ : styles.isRootLayoutVertical,
49
46
  disabled && styles.isRootDisabled,
50
47
  required && styles.isRootRequired,
51
48
  getRootSizeClassName(size, styles),
52
49
  getRootValidationStateClassName(validationState, styles),
53
- variant === 'filled' ? styles.rootVariantFilled : styles.rootVariantOutline,
50
+ variant === 'filled' ? styles.isRootVariantFilled : styles.isRootVariantOutline,
54
51
  )}
55
52
  htmlFor={id}
56
53
  id={id && `${id}__label`}
@@ -72,12 +69,10 @@ export const TextField = ({
72
69
  className={styles.input}
73
70
  disabled={disabled}
74
71
  id={id}
75
- placeholder={placeholder}
76
- ref={forwardedRef}
72
+ ref={ref}
77
73
  required={required}
78
74
  size={type !== 'number' ? inputSize : null}
79
75
  type={type}
80
- value={value}
81
76
  />
82
77
  {variant === 'filled' && (
83
78
  <div className={styles.bottomLine} />
@@ -102,24 +97,21 @@ export const TextField = ({
102
97
  </div>
103
98
  </label>
104
99
  );
105
- };
100
+ });
106
101
 
107
102
  TextField.defaultProps = {
108
103
  disabled: false,
109
- forwardedRef: undefined,
110
104
  fullWidth: false,
111
105
  helpText: null,
112
106
  id: undefined,
113
107
  inputSize: null,
114
108
  isLabelVisible: true,
115
109
  layout: 'vertical',
116
- placeholder: null,
117
110
  required: false,
118
111
  size: 'medium',
119
112
  type: 'text',
120
113
  validationState: null,
121
114
  validationText: null,
122
- value: undefined,
123
115
  variant: 'outline',
124
116
  };
125
117
 
@@ -128,14 +120,6 @@ TextField.propTypes = {
128
120
  * If `true`, the input will be disabled.
129
121
  */
130
122
  disabled: PropTypes.bool,
131
- /**
132
- * Reference forwarded to the `input` element.
133
- */
134
- forwardedRef: PropTypes.oneOfType([
135
- PropTypes.func,
136
- // eslint-disable-next-line react/forbid-prop-types
137
- PropTypes.shape({ current: PropTypes.any }),
138
- ]),
139
123
  /**
140
124
  * If `true`, the field will span the full width of its parent.
141
125
  */
@@ -153,7 +137,7 @@ TextField.propTypes = {
153
137
  */
154
138
  id: PropTypes.string,
155
139
  /**
156
- * Treat the field differently when it's inside a FormLayout. Do not set manually!
140
+ * Width of the input field. Translated as `size` attribute for input types other than `number`.
157
141
  */
158
142
  inputSize: PropTypes.number,
159
143
  /**
@@ -172,10 +156,6 @@ TextField.propTypes = {
172
156
  * as the value is inherited in such case.
173
157
  */
174
158
  layout: PropTypes.oneOf(['horizontal', 'vertical']),
175
- /**
176
- * Optional example value.
177
- */
178
- placeholder: PropTypes.string,
179
159
  /**
180
160
  * If `true`, the input will be required.
181
161
  */
@@ -196,19 +176,12 @@ TextField.propTypes = {
196
176
  * Validation message to be displayed.
197
177
  */
198
178
  validationText: PropTypes.node,
199
- /**
200
- * Value of the input.
201
- */
202
- value: PropTypes.oneOfType([
203
- PropTypes.string,
204
- PropTypes.number,
205
- ]),
206
179
  /**
207
180
  * Design variant of the field, further customizable with CSS custom properties.
208
181
  */
209
182
  variant: PropTypes.oneOf(['filled', 'outline']),
210
183
  };
211
184
 
212
- export const TextFieldWithGlobalProps = withForwardedRef(withGlobalProps(TextField, 'TextField'));
185
+ export const TextFieldWithGlobalProps = withGlobalProps(TextField, 'TextField');
213
186
 
214
187
  export default TextFieldWithGlobalProps;
@@ -40,11 +40,11 @@
40
40
  }
41
41
 
42
42
  // Variants
43
- .rootVariantFilled {
43
+ .isRootVariantFilled {
44
44
  @include variants.visual(box, $variant: filled);
45
45
  }
46
46
 
47
- .rootVariantOutline {
47
+ .isRootVariantOutline {
48
48
  @include variants.visual(box, $variant: outline);
49
49
  }
50
50
 
@@ -67,12 +67,12 @@
67
67
  }
68
68
 
69
69
  // Layouts
70
- .rootLayoutVertical,
71
- .rootLayoutHorizontal {
70
+ .isRootLayoutVertical,
71
+ .isRootLayoutHorizontal {
72
72
  @include box-field-layout.vertical();
73
73
  }
74
74
 
75
- .rootLayoutHorizontal {
75
+ .isRootLayoutHorizontal {
76
76
  @include box-field-layout.horizontal();
77
77
  }
78
78
 
@@ -84,19 +84,19 @@
84
84
  @include box-field-layout.in-form-layout();
85
85
  }
86
86
 
87
- .hasRootSmallInput.rootLayoutHorizontal {
87
+ .hasRootSmallInput.isRootLayoutHorizontal {
88
88
  @include box-field-layout.horizontal-with-small-input();
89
89
  }
90
90
 
91
91
  // Sizes
92
- .rootSizeSmall {
92
+ .isRootSizeSmall {
93
93
  @include box-field-sizes.size(small);
94
94
  }
95
95
 
96
- .rootSizeMedium {
96
+ .isRootSizeMedium {
97
97
  @include box-field-sizes.size(medium);
98
98
  }
99
99
 
100
- .rootSizeLarge {
100
+ .isRootSizeLarge {
101
101
  @include box-field-sizes.size(large);
102
102
  }
@@ -1 +1 @@
1
- export { default } from './TextField';
1
+ export { default as TextField } from './TextField';
@@ -10,7 +10,7 @@ import {
10
10
  Playground,
11
11
  Props,
12
12
  } from 'docz'
13
- import { TextLink } from './TextLink'
13
+ import { TextLink } from '../..'
14
14
 
15
15
  TextLink allows users to follow navigation.
16
16
 
@@ -56,12 +56,18 @@ It's common to use custom function for routing within SPAs. Use the
56
56
  />
57
57
  </Playground>
58
58
 
59
- ## API
59
+ ## Forwarding HTML Attributes
60
+
61
+ In addition to the options below in the [component's API](#api) section, you
62
+ can specify [React synthetic events] or **any HTML attribute you like.** All
63
+ attributes that don't interfere with the API are forwarded to the `<a>` HTML
64
+ element. This enables making the component interactive and helps to improve its
65
+ accessibility.
60
66
 
61
- In addition to the options below, you can specify [React synthetic events] or
62
- any custom HTML attributes that do not interfere with the API, and they will be
63
- passed to the `<a>` HTML element. This enables making the component interactive
64
- and helps improve its accessibility.
67
+ 👉 Refer to the MDN reference for the full list of supported attributes of the
68
+ [a] element.
69
+
70
+ ## API
65
71
 
66
72
  <Props table of={TextLink} />
67
73
 
@@ -75,3 +81,4 @@ and helps improve its accessibility.
75
81
  | `--rui-TextLink--hover__text-decoration` | Text decoration on hover |
76
82
 
77
83
  [React synthetic events]: https://reactjs.org/docs/events.html
84
+ [a]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attributes
@@ -6,7 +6,6 @@ import styles from './TextLink.scss';
6
6
 
7
7
  export const TextLink = ({
8
8
  href,
9
- id,
10
9
  label,
11
10
  ...restProps
12
11
  }) => (
@@ -14,25 +13,16 @@ export const TextLink = ({
14
13
  {...transferProps(restProps)}
15
14
  href={href}
16
15
  className={styles.root}
17
- id={id}
18
16
  >
19
17
  {label}
20
18
  </a>
21
19
  );
22
20
 
23
- TextLink.defaultProps = {
24
- id: undefined,
25
- };
26
-
27
21
  TextLink.propTypes = {
28
22
  /**
29
23
  * Link's `href` attribute.
30
24
  */
31
25
  href: PropTypes.string.isRequired,
32
- /**
33
- * ID of the root HTML element.
34
- */
35
- id: PropTypes.string,
36
26
  /**
37
27
  * Link label.
38
28
  */
@@ -1 +1 @@
1
- export { default } from './TextLink';
1
+ export { default as TextLink } from './TextLink';
@@ -12,7 +12,7 @@ import {
12
12
  Playground,
13
13
  Props,
14
14
  } from 'docz'
15
- import { Toggle } from './Toggle'
15
+ import { Toggle } from '../..'
16
16
 
17
17
  ## Basic Usage
18
18
 
@@ -177,12 +177,22 @@ Disabled state makes the input unavailable.
177
177
  />
178
178
  </Playground>
179
179
 
180
- ## API
180
+ ## Forwarding HTML Attributes
181
+
182
+ In addition to the options below in the [component's API](#api) section, you
183
+ can specify [React synthetic events] or you can **add whatever HTML attribute
184
+ you like.** All attributes that don't interfere with the API are forwarded to
185
+ the native HTML `<input>`. This enables making the component interactive and
186
+ helps to improve its accessibility.
187
+
188
+ 👉 Refer to the MDN reference for the full list of supported attributes of the
189
+ [checkbox] input type.
181
190
 
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.
191
+ ## Forwarding ref
192
+
193
+ If you provide [ref], it is forwarded to the native HTML `<input>` element.
194
+
195
+ ## API
186
196
 
187
197
  <Props table of={Toggle} />
188
198
 
@@ -202,3 +212,5 @@ options. On top of that, the following options are available for Toggle.
202
212
  | `--rui-FormField--check__input--toggle--checked__background-position` | Background position of checked input |
203
213
 
204
214
  [React synthetic events]: https://reactjs.org/docs/events.html
215
+ [checkbox]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#additional_attributes
216
+ [ref]: https://reactjs.org/docs/refs-and-the-dom.html
@@ -5,24 +5,22 @@ import { classNames } from '../../utils/classNames';
5
5
  import { getRootValidationStateClassName } from '../_helpers/getRootValidationStateClassName';
6
6
  import { transferProps } from '../_helpers/transferProps';
7
7
  import { FormLayoutContext } from '../FormLayout';
8
- import withForwardedRef from '../withForwardedRef';
9
8
  import styles from './Toggle.scss';
10
9
 
11
- export const Toggle = ({
12
- checked,
13
- disabled,
14
- forwardedRef,
15
- helpText,
16
- id,
17
- isLabelVisible,
18
- label,
19
- labelPosition,
20
- required,
21
- validationState,
22
- validationText,
23
- value,
24
- ...restProps
25
- }) => {
10
+ export const Toggle = React.forwardRef((props, ref) => {
11
+ const {
12
+ disabled,
13
+ helpText,
14
+ id,
15
+ isLabelVisible,
16
+ label,
17
+ labelPosition,
18
+ required,
19
+ validationState,
20
+ validationText,
21
+ ...restProps
22
+ } = props;
23
+
26
24
  const context = useContext(FormLayoutContext);
27
25
 
28
26
  return (
@@ -30,7 +28,7 @@ export const Toggle = ({
30
28
  className={classNames(
31
29
  styles.root,
32
30
  context && styles.isRootInFormLayout,
33
- context && context.layout === 'horizontal' ? styles.rootLayoutHorizontal : styles.rootLayoutVertical,
31
+ context && context.layout === 'horizontal' ? styles.isRootLayoutHorizontal : styles.isRootLayoutVertical,
34
32
  labelPosition === 'before' && styles.hasRootLabelBefore,
35
33
  disabled && styles.isRootDisabled,
36
34
  required && styles.isRootRequired,
@@ -51,15 +49,13 @@ export const Toggle = ({
51
49
  </div>
52
50
  <input
53
51
  {...transferProps(restProps)}
54
- checked={checked}
55
52
  className={styles.input}
56
53
  disabled={disabled}
57
54
  id={id}
58
55
  name={id}
59
- ref={forwardedRef}
56
+ ref={ref}
60
57
  required={required}
61
58
  type="checkbox"
62
- value={value}
63
59
  />
64
60
  </div>
65
61
  {helpText && (
@@ -80,12 +76,10 @@ export const Toggle = ({
80
76
  )}
81
77
  </label>
82
78
  );
83
- };
79
+ });
84
80
 
85
81
  Toggle.defaultProps = {
86
- checked: undefined,
87
82
  disabled: false,
88
- forwardedRef: undefined,
89
83
  helpText: null,
90
84
  id: undefined,
91
85
  isLabelVisible: true,
@@ -93,26 +87,13 @@ Toggle.defaultProps = {
93
87
  required: false,
94
88
  validationState: null,
95
89
  validationText: null,
96
- value: undefined,
97
90
  };
98
91
 
99
92
  Toggle.propTypes = {
100
- /**
101
- * If `true`, the input will be checked.
102
- */
103
- checked: PropTypes.bool,
104
93
  /**
105
94
  * If `true`, the input will be disabled.
106
95
  */
107
96
  disabled: PropTypes.bool,
108
- /**
109
- * Reference forwarded to the `input` element.
110
- */
111
- forwardedRef: PropTypes.oneOfType([
112
- PropTypes.func,
113
- // eslint-disable-next-line react/forbid-prop-types
114
- PropTypes.shape({ current: PropTypes.any }),
115
- ]),
116
97
  /**
117
98
  * Optional help text.
118
99
  */
@@ -150,15 +131,8 @@ Toggle.propTypes = {
150
131
  * Validation message to be displayed.
151
132
  */
152
133
  validationText: PropTypes.node,
153
- /**
154
- * Value of the input.
155
- */
156
- value: PropTypes.oneOfType([
157
- PropTypes.string,
158
- PropTypes.number,
159
- ]),
160
134
  };
161
135
 
162
- export const ToggleWithGlobalProps = withForwardedRef(withGlobalProps(Toggle, 'Toggle'));
136
+ export const ToggleWithGlobalProps = withGlobalProps(Toggle, 'Toggle');
163
137
 
164
138
  export default ToggleWithGlobalProps;
@@ -1 +1 @@
1
- export { default } from './Toggle';
1
+ export { default as Toggle } from './Toggle';
@@ -11,12 +11,14 @@ import {
11
11
  Props,
12
12
  } from 'docz'
13
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
- import { Toolbar } from './Toolbar'
18
- import { ToolbarGroup } from './ToolbarGroup'
19
- import { ToolbarItem } from './ToolbarItem'
14
+ import {
15
+ CheckboxField,
16
+ Button,
17
+ ButtonGroup,
18
+ Toolbar,
19
+ ToolbarGroup,
20
+ ToolbarItem,
21
+ } from '../..'
20
22
 
21
23
  The responsive Toolbar layout is a versatile tool that allows spacing, grouping,
22
24
  and aligning inline items.
@@ -333,6 +335,17 @@ Or to build a classic media layout with image on the left and text on the right:
333
335
  </Toolbar>
334
336
  </Playground>
335
337
 
338
+ ## Forwarding HTML Attributes
339
+
340
+ In addition to the options below in the [component's API](#api) section, you
341
+ can specify [React synthetic events] or **any HTML attribute you like.** All
342
+ attributes that don't interfere with the API are forwarded to the root `<div>`
343
+ HTML element. This enables making the component interactive and helps to improve
344
+ its accessibility.
345
+
346
+ 👉 Refer to the MDN reference for the full list of supported attributes of the
347
+ [div] element.
348
+
336
349
  ## API
337
350
 
338
351
  <Props table of={Toolbar} />
@@ -361,3 +374,5 @@ A wrapper for individual toolbar items.
361
374
  [grid]: /components/grid
362
375
  [spacing]: /css-helpers/spacing
363
376
  [text]: /components/text
377
+ [React synthetic events]: https://reactjs.org/docs/events.html
378
+ [div]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div#attributes