@automattic/vip-design-system 0.27.0 → 0.27.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.
|
@@ -21,7 +21,7 @@ export const backgrounds = {
|
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
function ThemeChanger( { background } ) {
|
|
24
|
-
const [
|
|
24
|
+
const [ _, setColorMode ] = useColorMode();
|
|
25
25
|
const newColorMode = darkBackground === background ? 'dark' : 'default';
|
|
26
26
|
|
|
27
27
|
useEffect( () => {
|
|
@@ -9,7 +9,7 @@ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runt
|
|
|
9
9
|
|
|
10
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
11
|
|
|
12
|
-
var _react =
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
13
|
|
|
14
14
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
15
15
|
|
|
@@ -21,7 +21,13 @@ var _ScreenReaderText = require("../ScreenReaderText/ScreenReaderText");
|
|
|
21
21
|
|
|
22
22
|
var _jsxRuntime = require("theme-ui/jsx-runtime");
|
|
23
23
|
|
|
24
|
-
var _excluded = ["disabled", "defaultValue", "onChange", "name", "options", "className"]
|
|
24
|
+
var _excluded = ["disabled", "defaultValue", "onChange", "name", "options", "className"],
|
|
25
|
+
_excluded2 = ["id", "className", "value", "label", "labelProps"];
|
|
26
|
+
|
|
27
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
28
|
+
|
|
29
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
30
|
+
|
|
25
31
|
var inputStyle = (0, _extends2["default"])({}, _ScreenReaderText.screenReaderTextClass, {
|
|
26
32
|
width: '16px',
|
|
27
33
|
height: '16px',
|
|
@@ -92,12 +98,7 @@ var CustomLabel = function CustomLabel(_ref) {
|
|
|
92
98
|
};
|
|
93
99
|
|
|
94
100
|
CustomLabel.propTypes = {
|
|
95
|
-
children: _propTypes["default"].
|
|
96
|
-
props: {
|
|
97
|
-
className: _propTypes["default"].any,
|
|
98
|
-
sx: _propTypes["default"].object
|
|
99
|
-
}
|
|
100
|
-
}).isRequired
|
|
101
|
+
children: _propTypes["default"].any
|
|
101
102
|
};
|
|
102
103
|
|
|
103
104
|
var Radio = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, forwardRef) {
|
|
@@ -110,7 +111,20 @@ var Radio = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, forwardRe
|
|
|
110
111
|
options = _ref2$options === void 0 ? [] : _ref2$options,
|
|
111
112
|
className = _ref2.className,
|
|
112
113
|
props = (0, _objectWithoutPropertiesLoose2["default"])(_ref2, _excluded);
|
|
113
|
-
var
|
|
114
|
+
var onChangeHandler = (0, _react.useCallback)(function (e) {
|
|
115
|
+
var optionTriggered = options.find(function (option) {
|
|
116
|
+
return "" + option.value === "" + e.target.value;
|
|
117
|
+
});
|
|
118
|
+
onChange(e, optionTriggered);
|
|
119
|
+
}, []);
|
|
120
|
+
var renderedOptions = options.map(function (_ref3) {
|
|
121
|
+
var id = _ref3.id,
|
|
122
|
+
optionClassName = _ref3.className,
|
|
123
|
+
value = _ref3.value,
|
|
124
|
+
label = _ref3.label,
|
|
125
|
+
_ref3$labelProps = _ref3.labelProps,
|
|
126
|
+
labelProps = _ref3$labelProps === void 0 ? {} : _ref3$labelProps,
|
|
127
|
+
restOption = (0, _objectWithoutPropertiesLoose2["default"])(_ref3, _excluded2);
|
|
114
128
|
return (0, _jsxRuntime.jsxs)("div", {
|
|
115
129
|
sx: {
|
|
116
130
|
display: 'flex',
|
|
@@ -119,25 +133,26 @@ var Radio = /*#__PURE__*/_react["default"].forwardRef(function (_ref2, forwardRe
|
|
|
119
133
|
return theme.space[4] - theme.space[2] + "px";
|
|
120
134
|
}
|
|
121
135
|
},
|
|
122
|
-
className: (0, _classnames["default"])('vip-radio-component-item', "vip-radio-component-item-" +
|
|
123
|
-
children: [(0, _jsxRuntime.jsx)("input", {
|
|
136
|
+
className: (0, _classnames["default"])('vip-radio-component-item', "vip-radio-component-item-" + id),
|
|
137
|
+
children: [(0, _jsxRuntime.jsx)("input", (0, _extends2["default"])({
|
|
124
138
|
type: "radio",
|
|
125
|
-
id:
|
|
139
|
+
id: id,
|
|
126
140
|
name: name,
|
|
127
|
-
value: "" +
|
|
141
|
+
value: "" + value,
|
|
128
142
|
sx: inputStyle,
|
|
129
|
-
onChange:
|
|
130
|
-
className: (0, _classnames["default"])('vip-radio-component-item-input',
|
|
131
|
-
checked: "" +
|
|
132
|
-
}), typeof
|
|
133
|
-
className: (0, _classnames["default"])('vip-radio-component-item-label',
|
|
134
|
-
htmlFor:
|
|
135
|
-
sx: labelStyle
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
onChange: onChangeHandler,
|
|
144
|
+
className: (0, _classnames["default"])('vip-radio-component-item-input', optionClassName),
|
|
145
|
+
checked: "" + value === "" + defaultValue
|
|
146
|
+
}, restOption)), typeof label === 'string' ? (0, _jsxRuntime.jsx)(_Label.Label, (0, _extends2["default"])({
|
|
147
|
+
className: (0, _classnames["default"])('vip-radio-component-item-label', optionClassName),
|
|
148
|
+
htmlFor: id,
|
|
149
|
+
sx: labelStyle
|
|
150
|
+
}, labelProps, {
|
|
151
|
+
children: label
|
|
152
|
+
})) : (0, _jsxRuntime.jsx)(CustomLabel, (0, _extends2["default"])({}, labelProps, {
|
|
153
|
+
children: label
|
|
154
|
+
}))]
|
|
155
|
+
}, id);
|
|
141
156
|
});
|
|
142
157
|
return (0, _jsxRuntime.jsx)("div", (0, _extends2["default"])({
|
|
143
158
|
className: (0, _classnames["default"])('vip-radio-component', "vip-radio-component-" + name, className),
|
|
@@ -153,7 +168,7 @@ Radio.propTypes = {
|
|
|
153
168
|
disabled: _propTypes["default"].bool,
|
|
154
169
|
defaultValue: _propTypes["default"].any,
|
|
155
170
|
onChange: _propTypes["default"].func,
|
|
156
|
-
options: _propTypes["default"].
|
|
171
|
+
options: _propTypes["default"].any,
|
|
157
172
|
name: _propTypes["default"].string,
|
|
158
173
|
className: _propTypes["default"].any
|
|
159
174
|
};
|
|
@@ -5,7 +5,7 @@ exports["default"] = exports.Default = void 0;
|
|
|
5
5
|
|
|
6
6
|
var _react = require("react");
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _2 = require("..");
|
|
9
9
|
|
|
10
10
|
var _Radio = require("./Radio");
|
|
11
11
|
|
|
@@ -35,11 +35,11 @@ var Default = function Default() {
|
|
|
35
35
|
checked = _useState[0],
|
|
36
36
|
setChecked = _useState[1];
|
|
37
37
|
|
|
38
|
-
var _useState2 = (0, _react.useState)('
|
|
38
|
+
var _useState2 = (0, _react.useState)('b'),
|
|
39
39
|
checked2 = _useState2[0],
|
|
40
40
|
setChecked2 = _useState2[1];
|
|
41
41
|
|
|
42
|
-
return (0, _jsxRuntime.jsxs)(
|
|
42
|
+
return (0, _jsxRuntime.jsxs)(_2.Form.Root, {
|
|
43
43
|
children: [(0, _jsxRuntime.jsxs)("p", {
|
|
44
44
|
children: ["Per recommendation, if you have a Radio button, use a Fieldset with a legend as wrapper to your options.", ' ', (0, _jsxRuntime.jsx)("a", {
|
|
45
45
|
href: "https://a11y-collective.github.io/demos/en/accessible-code/form-fieldsets.html",
|
|
@@ -95,7 +95,7 @@ var Default = function Default() {
|
|
|
95
95
|
htmlFor: "option-custom-a",
|
|
96
96
|
className: "custom-class",
|
|
97
97
|
sx: {
|
|
98
|
-
color: '
|
|
98
|
+
color: 'error'
|
|
99
99
|
},
|
|
100
100
|
children: "(Custom) All domains listed on this environment, and all subdomains"
|
|
101
101
|
}),
|
|
@@ -103,14 +103,24 @@ var Default = function Default() {
|
|
|
103
103
|
}, {
|
|
104
104
|
value: 'b',
|
|
105
105
|
label: 'All domains listed on this environment',
|
|
106
|
+
labelProps: {
|
|
107
|
+
id: 'label-option-custom-b-custom-props'
|
|
108
|
+
},
|
|
106
109
|
className: 'custom-class-for-this',
|
|
110
|
+
'aria-describedby': 'describe-radio-all-domains-subdomains',
|
|
107
111
|
id: 'option-custom-b'
|
|
108
112
|
}],
|
|
109
|
-
onChange: function onChange(
|
|
110
|
-
return setChecked2(
|
|
113
|
+
onChange: function onChange(_, option) {
|
|
114
|
+
return setChecked2(option.value);
|
|
111
115
|
}
|
|
112
116
|
})
|
|
113
117
|
})]
|
|
118
|
+
}), (0, _jsxRuntime.jsx)("p", {
|
|
119
|
+
id: "describe-radio-all-domains-subdomains",
|
|
120
|
+
sx: {
|
|
121
|
+
mt: 2
|
|
122
|
+
},
|
|
123
|
+
children: "This is a explanation for custom option b"
|
|
114
124
|
})]
|
|
115
125
|
});
|
|
116
126
|
};
|
package/package.json
CHANGED
package/src/system/Form/Radio.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* External dependencies
|
|
6
6
|
*/
|
|
7
|
-
import React from 'react';
|
|
7
|
+
import React, { useCallback } from 'react';
|
|
8
8
|
import PropTypes from 'prop-types';
|
|
9
9
|
import classNames from 'classnames';
|
|
10
10
|
import { Label } from './Label';
|
|
@@ -68,19 +68,20 @@ const labelStyle = {
|
|
|
68
68
|
},
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
-
const CustomLabel = ( { children } ) =>
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
71
|
+
const CustomLabel = ( { children } ) => {
|
|
72
|
+
return (
|
|
73
|
+
<>
|
|
74
|
+
{ React.cloneElement( React.Children.only( children ), {
|
|
75
|
+
...children.props,
|
|
76
|
+
sx: { ...labelStyle, ...children.props.sx },
|
|
77
|
+
className: `${ children.props.className } vip-radio-component-item-label`,
|
|
78
|
+
} ) }
|
|
79
|
+
</>
|
|
80
|
+
);
|
|
81
|
+
};
|
|
80
82
|
|
|
81
83
|
CustomLabel.propTypes = {
|
|
82
|
-
children: PropTypes.
|
|
83
|
-
.isRequired,
|
|
84
|
+
children: PropTypes.any,
|
|
84
85
|
};
|
|
85
86
|
|
|
86
87
|
const Radio = React.forwardRef(
|
|
@@ -88,43 +89,51 @@ const Radio = React.forwardRef(
|
|
|
88
89
|
{ disabled, defaultValue, onChange, name = '', options = [], className, ...props },
|
|
89
90
|
forwardRef
|
|
90
91
|
) => {
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
} }
|
|
98
|
-
key={ option.id }
|
|
99
|
-
className={ classNames(
|
|
100
|
-
'vip-radio-component-item',
|
|
101
|
-
`vip-radio-component-item-${ option.id }`
|
|
102
|
-
) }
|
|
103
|
-
>
|
|
104
|
-
<input
|
|
105
|
-
type="radio"
|
|
106
|
-
id={ option.id }
|
|
107
|
-
name={ name }
|
|
108
|
-
value={ `${ option.value }` }
|
|
109
|
-
sx={ inputStyle }
|
|
110
|
-
onChange={ onChange }
|
|
111
|
-
className={ classNames( 'vip-radio-component-item-input', option?.className ) }
|
|
112
|
-
checked={ `${ option.value }` === `${ defaultValue }` }
|
|
113
|
-
/>
|
|
92
|
+
const onChangeHandler = useCallback( e => {
|
|
93
|
+
const optionTriggered = options.find(
|
|
94
|
+
option => `${ option.value }` === `${ e.target.value }`
|
|
95
|
+
);
|
|
96
|
+
onChange( e, optionTriggered );
|
|
97
|
+
}, [] );
|
|
114
98
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
{
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
99
|
+
const renderedOptions = options.map(
|
|
100
|
+
( { id, className: optionClassName, value, label, labelProps = {}, ...restOption } ) => (
|
|
101
|
+
<div
|
|
102
|
+
sx={ {
|
|
103
|
+
display: 'flex',
|
|
104
|
+
alignItems: 'center',
|
|
105
|
+
minHeight: theme => `${ theme.space[ 4 ] - theme.space[ 2 ] }px`,
|
|
106
|
+
} }
|
|
107
|
+
key={ id }
|
|
108
|
+
className={ classNames( 'vip-radio-component-item', `vip-radio-component-item-${ id }` ) }
|
|
109
|
+
>
|
|
110
|
+
<input
|
|
111
|
+
type="radio"
|
|
112
|
+
id={ id }
|
|
113
|
+
name={ name }
|
|
114
|
+
value={ `${ value }` }
|
|
115
|
+
sx={ inputStyle }
|
|
116
|
+
onChange={ onChangeHandler }
|
|
117
|
+
className={ classNames( 'vip-radio-component-item-input', optionClassName ) }
|
|
118
|
+
checked={ `${ value }` === `${ defaultValue }` }
|
|
119
|
+
{ ...restOption }
|
|
120
|
+
/>
|
|
121
|
+
|
|
122
|
+
{ typeof label === 'string' ? (
|
|
123
|
+
<Label
|
|
124
|
+
className={ classNames( 'vip-radio-component-item-label', optionClassName ) }
|
|
125
|
+
htmlFor={ id }
|
|
126
|
+
sx={ labelStyle }
|
|
127
|
+
{ ...labelProps }
|
|
128
|
+
>
|
|
129
|
+
{ label }
|
|
130
|
+
</Label>
|
|
131
|
+
) : (
|
|
132
|
+
<CustomLabel { ...labelProps }>{ label }</CustomLabel>
|
|
133
|
+
) }
|
|
134
|
+
</div>
|
|
135
|
+
)
|
|
136
|
+
);
|
|
128
137
|
|
|
129
138
|
return (
|
|
130
139
|
<div
|
|
@@ -148,7 +157,7 @@ Radio.propTypes = {
|
|
|
148
157
|
disabled: PropTypes.bool,
|
|
149
158
|
defaultValue: PropTypes.any,
|
|
150
159
|
onChange: PropTypes.func,
|
|
151
|
-
options: PropTypes.
|
|
160
|
+
options: PropTypes.any,
|
|
152
161
|
name: PropTypes.string,
|
|
153
162
|
className: PropTypes.any,
|
|
154
163
|
};
|
|
@@ -20,7 +20,7 @@ export default {
|
|
|
20
20
|
|
|
21
21
|
export const Default = () => {
|
|
22
22
|
const [ checked, setChecked ] = useState( 'a' );
|
|
23
|
-
const [ checked2, setChecked2 ] = useState( '
|
|
23
|
+
const [ checked2, setChecked2 ] = useState( 'b' );
|
|
24
24
|
|
|
25
25
|
return (
|
|
26
26
|
<Form.Root>
|
|
@@ -67,7 +67,7 @@ export const Default = () => {
|
|
|
67
67
|
<Label
|
|
68
68
|
htmlFor="option-custom-a"
|
|
69
69
|
className="custom-class"
|
|
70
|
-
sx={ { color: '
|
|
70
|
+
sx={ { color: 'error' } }
|
|
71
71
|
>
|
|
72
72
|
(Custom) All domains listed on this environment, and all subdomains
|
|
73
73
|
</Label>
|
|
@@ -77,14 +77,22 @@ export const Default = () => {
|
|
|
77
77
|
{
|
|
78
78
|
value: 'b',
|
|
79
79
|
label: 'All domains listed on this environment',
|
|
80
|
+
labelProps: {
|
|
81
|
+
id: 'label-option-custom-b-custom-props',
|
|
82
|
+
},
|
|
80
83
|
className: 'custom-class-for-this',
|
|
84
|
+
'aria-describedby': 'describe-radio-all-domains-subdomains',
|
|
81
85
|
id: 'option-custom-b',
|
|
82
86
|
},
|
|
83
87
|
] }
|
|
84
|
-
onChange={
|
|
88
|
+
onChange={ ( _, option ) => setChecked2( option.value ) }
|
|
85
89
|
/>
|
|
86
90
|
</Flex>
|
|
87
91
|
</fieldset>
|
|
92
|
+
|
|
93
|
+
<p id="describe-radio-all-domains-subdomains" sx={ { mt: 2 } }>
|
|
94
|
+
This is a explanation for custom option b
|
|
95
|
+
</p>
|
|
88
96
|
</Form.Root>
|
|
89
97
|
);
|
|
90
98
|
};
|