@instructure/ui-radio-input 11.6.0 → 11.6.1-snapshot-129
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/CHANGELOG.md +45 -299
- package/es/RadioInput/{index.js → v1/index.js} +1 -1
- package/es/RadioInput/v2/index.js +189 -0
- package/{src/index.ts → es/RadioInput/v2/props.js} +2 -4
- package/es/RadioInput/v2/styles.js +268 -0
- package/es/RadioInputGroup/{index.js → v1/index.js} +3 -3
- package/es/RadioInputGroup/v2/index.js +146 -0
- package/es/RadioInputGroup/v2/props.js +26 -0
- package/es/{index.js → exports/a.js} +2 -2
- package/es/exports/b.js +25 -0
- package/lib/RadioInput/{index.js → v1/index.js} +1 -1
- package/lib/RadioInput/v2/index.js +195 -0
- package/lib/RadioInput/v2/props.js +31 -0
- package/lib/RadioInput/v2/styles.js +274 -0
- package/lib/RadioInputGroup/{index.js → v1/index.js} +6 -6
- package/lib/RadioInputGroup/v2/index.js +154 -0
- package/lib/RadioInputGroup/v2/props.js +31 -0
- package/lib/{index.js → exports/a.js} +4 -4
- package/lib/exports/b.js +19 -0
- package/package.json +40 -18
- package/src/RadioInput/{index.tsx → v1/index.tsx} +1 -1
- package/src/RadioInput/v2/README.md +110 -0
- package/src/RadioInput/v2/index.tsx +223 -0
- package/src/RadioInput/v2/props.ts +126 -0
- package/src/RadioInput/v2/styles.ts +304 -0
- package/src/RadioInputGroup/{index.tsx → v1/index.tsx} +4 -4
- package/src/RadioInputGroup/{props.ts → v1/props.ts} +1 -1
- package/src/RadioInputGroup/{styles.ts → v1/styles.ts} +3 -1
- package/src/RadioInputGroup/v2/README.md +241 -0
- package/src/RadioInputGroup/v2/index.tsx +178 -0
- package/src/RadioInputGroup/v2/props.ts +122 -0
- package/src/exports/a.ts +28 -0
- package/src/exports/b.ts +28 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/RadioInput/v1/index.d.ts.map +1 -0
- package/types/RadioInput/v1/props.d.ts.map +1 -0
- package/types/RadioInput/v1/styles.d.ts.map +1 -0
- package/types/RadioInput/v1/theme.d.ts.map +1 -0
- package/types/RadioInput/v2/index.d.ts +64 -0
- package/types/RadioInput/v2/index.d.ts.map +1 -0
- package/types/RadioInput/v2/props.d.ts +77 -0
- package/types/RadioInput/v2/props.d.ts.map +1 -0
- package/types/RadioInput/v2/styles.d.ts +24 -0
- package/types/RadioInput/v2/styles.d.ts.map +1 -0
- package/types/RadioInputGroup/{index.d.ts → v1/index.d.ts} +3 -3
- package/types/RadioInputGroup/v1/index.d.ts.map +1 -0
- package/types/RadioInputGroup/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/RadioInputGroup/v1/props.d.ts.map +1 -0
- package/types/RadioInputGroup/v1/styles.d.ts.map +1 -0
- package/types/RadioInputGroup/v1/theme.d.ts.map +1 -0
- package/types/RadioInputGroup/v2/index.d.ts +47 -0
- package/types/RadioInputGroup/v2/index.d.ts.map +1 -0
- package/types/RadioInputGroup/v2/props.d.ts +63 -0
- package/types/RadioInputGroup/v2/props.d.ts.map +1 -0
- package/types/exports/a.d.ts +5 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +5 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/RadioInput/index.d.ts.map +0 -1
- package/types/RadioInput/props.d.ts.map +0 -1
- package/types/RadioInput/styles.d.ts.map +0 -1
- package/types/RadioInput/theme.d.ts.map +0 -1
- package/types/RadioInputGroup/index.d.ts.map +0 -1
- package/types/RadioInputGroup/props.d.ts.map +0 -1
- package/types/RadioInputGroup/styles.d.ts.map +0 -1
- package/types/RadioInputGroup/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -5
- package/types/index.d.ts.map +0 -1
- /package/es/RadioInput/{props.js → v1/props.js} +0 -0
- /package/es/RadioInput/{styles.js → v1/styles.js} +0 -0
- /package/es/RadioInput/{theme.js → v1/theme.js} +0 -0
- /package/es/RadioInputGroup/{props.js → v1/props.js} +0 -0
- /package/es/RadioInputGroup/{styles.js → v1/styles.js} +0 -0
- /package/es/RadioInputGroup/{theme.js → v1/theme.js} +0 -0
- /package/lib/RadioInput/{props.js → v1/props.js} +0 -0
- /package/lib/RadioInput/{styles.js → v1/styles.js} +0 -0
- /package/lib/RadioInput/{theme.js → v1/theme.js} +0 -0
- /package/lib/RadioInputGroup/{props.js → v1/props.js} +0 -0
- /package/lib/RadioInputGroup/{styles.js → v1/styles.js} +0 -0
- /package/lib/RadioInputGroup/{theme.js → v1/theme.js} +0 -0
- /package/src/RadioInput/{README.md → v1/README.md} +0 -0
- /package/src/RadioInput/{props.ts → v1/props.ts} +0 -0
- /package/src/RadioInput/{styles.ts → v1/styles.ts} +0 -0
- /package/src/RadioInput/{theme.ts → v1/theme.ts} +0 -0
- /package/src/RadioInputGroup/{README.md → v1/README.md} +0 -0
- /package/src/RadioInputGroup/{theme.ts → v1/theme.ts} +0 -0
- /package/types/RadioInput/{index.d.ts → v1/index.d.ts} +0 -0
- /package/types/RadioInput/{props.d.ts → v1/props.d.ts} +0 -0
- /package/types/RadioInput/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/RadioInput/{theme.d.ts → v1/theme.d.ts} +0 -0
- /package/types/RadioInputGroup/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/RadioInputGroup/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
const _excluded = ["variant", "size", "disabled", "inline", "context", "readOnly", "id", "label", "value", "name", "checked", "onClick", "onChange", "inputRef", "themeOverride"];
|
|
4
|
+
/*
|
|
5
|
+
* The MIT License (MIT)
|
|
6
|
+
*
|
|
7
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
8
|
+
*
|
|
9
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
* in the Software without restriction, including without limitation the rights
|
|
12
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
* furnished to do so, subject to the following conditions:
|
|
15
|
+
*
|
|
16
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
* copies or substantial portions of the Software.
|
|
18
|
+
*
|
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
* SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { useState, useRef, useImperativeHandle, forwardRef, useCallback, useEffect } from 'react';
|
|
29
|
+
import { passthroughProps, useDeterministicId } from '@instructure/ui-react-utils';
|
|
30
|
+
import { isActiveElement } from '@instructure/ui-dom-utils';
|
|
31
|
+
import { useStyle } from '@instructure/emotion';
|
|
32
|
+
import generateStyle from "./styles.js";
|
|
33
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
34
|
+
/**
|
|
35
|
+
---
|
|
36
|
+
category: components
|
|
37
|
+
---
|
|
38
|
+
**/
|
|
39
|
+
const RadioInput = /*#__PURE__*/forwardRef((props, ref) => {
|
|
40
|
+
const _props$variant = props.variant,
|
|
41
|
+
variant = _props$variant === void 0 ? 'simple' : _props$variant,
|
|
42
|
+
_props$size = props.size,
|
|
43
|
+
size = _props$size === void 0 ? 'medium' : _props$size,
|
|
44
|
+
_props$disabled = props.disabled,
|
|
45
|
+
disabled = _props$disabled === void 0 ? false : _props$disabled,
|
|
46
|
+
_props$inline = props.inline,
|
|
47
|
+
inline = _props$inline === void 0 ? false : _props$inline,
|
|
48
|
+
_props$context = props.context,
|
|
49
|
+
context = _props$context === void 0 ? 'success' : _props$context,
|
|
50
|
+
_props$readOnly = props.readOnly,
|
|
51
|
+
readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
|
|
52
|
+
idProp = props.id,
|
|
53
|
+
label = props.label,
|
|
54
|
+
value = props.value,
|
|
55
|
+
name = props.name,
|
|
56
|
+
checkedProp = props.checked,
|
|
57
|
+
onClick = props.onClick,
|
|
58
|
+
onChange = props.onChange,
|
|
59
|
+
inputRef = props.inputRef,
|
|
60
|
+
themeOverride = props.themeOverride,
|
|
61
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
62
|
+
const _useState = useState(false),
|
|
63
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
64
|
+
hovered = _useState2[0],
|
|
65
|
+
setHovered = _useState2[1];
|
|
66
|
+
// State for uncontrolled mode
|
|
67
|
+
const _useState3 = useState(false),
|
|
68
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
69
|
+
internalChecked = _useState4[0],
|
|
70
|
+
setInternalChecked = _useState4[1];
|
|
71
|
+
|
|
72
|
+
// Refs
|
|
73
|
+
const containerRef = useRef(null);
|
|
74
|
+
const inputElementRef = useRef(null);
|
|
75
|
+
|
|
76
|
+
// Deterministic ID generation
|
|
77
|
+
const _useState5 = useState(),
|
|
78
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
79
|
+
deterministicId = _useState6[0],
|
|
80
|
+
setDeterministicId = _useState6[1];
|
|
81
|
+
const getId = useDeterministicId('RadioInput');
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
setDeterministicId(getId());
|
|
84
|
+
}, []);
|
|
85
|
+
const id = idProp || deterministicId;
|
|
86
|
+
|
|
87
|
+
// Computed checked value
|
|
88
|
+
const checked = typeof checkedProp === 'undefined' ? internalChecked : checkedProp;
|
|
89
|
+
|
|
90
|
+
// Styles - pass props with defaults applied for generateStyle
|
|
91
|
+
const styles = useStyle({
|
|
92
|
+
generateStyle,
|
|
93
|
+
themeOverride,
|
|
94
|
+
params: {
|
|
95
|
+
disabled,
|
|
96
|
+
context,
|
|
97
|
+
inline,
|
|
98
|
+
hovered,
|
|
99
|
+
readOnly,
|
|
100
|
+
size,
|
|
101
|
+
variant
|
|
102
|
+
},
|
|
103
|
+
componentId: 'RadioInput',
|
|
104
|
+
displayName: 'RadioInput'
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// Event handlers
|
|
108
|
+
const handleInputRef = useCallback(el => {
|
|
109
|
+
inputElementRef.current = el;
|
|
110
|
+
if (typeof inputRef === 'function') {
|
|
111
|
+
inputRef(el);
|
|
112
|
+
}
|
|
113
|
+
}, [inputRef]);
|
|
114
|
+
const handleClick = useCallback(e => {
|
|
115
|
+
if (disabled || readOnly) {
|
|
116
|
+
e.preventDefault();
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (typeof onClick === 'function') {
|
|
120
|
+
onClick(e);
|
|
121
|
+
}
|
|
122
|
+
}, [disabled, readOnly, onClick]);
|
|
123
|
+
const handleChange = useCallback(e => {
|
|
124
|
+
if (disabled || readOnly) {
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (typeof checkedProp === 'undefined') {
|
|
129
|
+
setInternalChecked(!internalChecked);
|
|
130
|
+
}
|
|
131
|
+
if (typeof onChange === 'function') {
|
|
132
|
+
onChange(e);
|
|
133
|
+
}
|
|
134
|
+
}, [disabled, readOnly, checkedProp, internalChecked, onChange]);
|
|
135
|
+
|
|
136
|
+
// Expose imperative API via ref
|
|
137
|
+
useImperativeHandle(ref, () => ({
|
|
138
|
+
focus: () => {
|
|
139
|
+
var _inputElementRef$curr;
|
|
140
|
+
(_inputElementRef$curr = inputElementRef.current) === null || _inputElementRef$curr === void 0 ? void 0 : _inputElementRef$curr.focus();
|
|
141
|
+
},
|
|
142
|
+
get focused() {
|
|
143
|
+
return isActiveElement(inputElementRef.current);
|
|
144
|
+
},
|
|
145
|
+
get checked() {
|
|
146
|
+
return checked;
|
|
147
|
+
},
|
|
148
|
+
get id() {
|
|
149
|
+
return id;
|
|
150
|
+
}
|
|
151
|
+
}), [checked, id]);
|
|
152
|
+
const handleMouseOver = () => {
|
|
153
|
+
setHovered(true);
|
|
154
|
+
};
|
|
155
|
+
const handleMouseOut = () => {
|
|
156
|
+
setHovered(false);
|
|
157
|
+
};
|
|
158
|
+
const passedProps = passthroughProps(rest);
|
|
159
|
+
return _jsxs("div", {
|
|
160
|
+
css: styles === null || styles === void 0 ? void 0 : styles.radioInput,
|
|
161
|
+
"data-cid": "RadioInput",
|
|
162
|
+
ref: containerRef
|
|
163
|
+
/* eslint-disable-next-line jsx-a11y/mouse-events-have-key-events */,
|
|
164
|
+
onMouseOver: handleMouseOver
|
|
165
|
+
/* eslint-disable-next-line jsx-a11y/mouse-events-have-key-events */,
|
|
166
|
+
onMouseOut: handleMouseOut,
|
|
167
|
+
children: [_jsx("input", {
|
|
168
|
+
...passedProps,
|
|
169
|
+
id: id,
|
|
170
|
+
ref: handleInputRef,
|
|
171
|
+
value: value,
|
|
172
|
+
name: name,
|
|
173
|
+
checked: checked,
|
|
174
|
+
type: "radio",
|
|
175
|
+
css: styles === null || styles === void 0 ? void 0 : styles.input,
|
|
176
|
+
readOnly: readOnly,
|
|
177
|
+
disabled: disabled,
|
|
178
|
+
onChange: handleChange,
|
|
179
|
+
onClick: handleClick
|
|
180
|
+
}), _jsx("label", {
|
|
181
|
+
htmlFor: id,
|
|
182
|
+
css: styles === null || styles === void 0 ? void 0 : styles.label,
|
|
183
|
+
children: label
|
|
184
|
+
})]
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
RadioInput.displayName = 'RadioInput';
|
|
188
|
+
export default RadioInput;
|
|
189
|
+
export { RadioInput };
|
|
@@ -21,8 +21,6 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
export { RadioInput } from './RadioInput'
|
|
25
|
-
export { RadioInputGroup } from './RadioInputGroup'
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
export
|
|
25
|
+
const allowedProps = ['label', 'value', 'id', 'name', 'checked', 'disabled', 'readOnly', 'variant', 'size', 'context', 'inline', 'onClick', 'onChange', 'inputRef'];
|
|
26
|
+
export { allowedProps };
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { boxShadowObjectsToCSSString } from '@instructure/ui-themes';
|
|
26
|
+
import { calcFocusOutlineStyles } from '@instructure/emotion';
|
|
27
|
+
/**
|
|
28
|
+
* ---
|
|
29
|
+
* private: true
|
|
30
|
+
* ---
|
|
31
|
+
* Generates the style object from the theme and provided additional information
|
|
32
|
+
* @param componentTheme The theme variable object.
|
|
33
|
+
* @param params Additional parameters to customize the style.
|
|
34
|
+
* @param sharedTokens Shared token object that stores common values for the theme.
|
|
35
|
+
* @return The final style object, which will be used in the component
|
|
36
|
+
*/
|
|
37
|
+
const generateStyle = (componentTheme, params, sharedTokens) => {
|
|
38
|
+
var _toggleContextBackgro;
|
|
39
|
+
const disabled = params.disabled,
|
|
40
|
+
inline = params.inline,
|
|
41
|
+
hovered = params.hovered,
|
|
42
|
+
size = params.size,
|
|
43
|
+
readOnly = params.readOnly,
|
|
44
|
+
variant = params.variant,
|
|
45
|
+
context = params.context;
|
|
46
|
+
|
|
47
|
+
// 4*2 states: base, hover, disabled, readonly X none/selected
|
|
48
|
+
const insetSizes = {
|
|
49
|
+
small: componentTheme.checkedInsetSm,
|
|
50
|
+
medium: componentTheme.checkedInsetMd,
|
|
51
|
+
large: componentTheme.checkedInsetLg
|
|
52
|
+
};
|
|
53
|
+
const labelColors = {
|
|
54
|
+
// the states here are mutually exclusive
|
|
55
|
+
color: componentTheme.labelBaseColor,
|
|
56
|
+
...(hovered && {
|
|
57
|
+
color: componentTheme.labelHoverColor
|
|
58
|
+
}),
|
|
59
|
+
...(readOnly && {
|
|
60
|
+
color: componentTheme.labelReadonlyColor
|
|
61
|
+
}),
|
|
62
|
+
...(disabled && {
|
|
63
|
+
color: componentTheme.labelDisabledColor
|
|
64
|
+
})
|
|
65
|
+
};
|
|
66
|
+
const getInputColors = () => {
|
|
67
|
+
if (disabled) {
|
|
68
|
+
return {
|
|
69
|
+
background: componentTheme.backgroundDisabledColor,
|
|
70
|
+
borderColor: componentTheme.borderDisabledColor,
|
|
71
|
+
checkedBoxShadow: `inset 0 0 0 ${insetSizes[size]} ${componentTheme.borderDisabledColor}`
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (readOnly) {
|
|
75
|
+
return {
|
|
76
|
+
background: componentTheme.backgroundReadonlyColor,
|
|
77
|
+
borderColor: componentTheme.borderReadonlyColor,
|
|
78
|
+
checkedBoxShadow: `inset 0 0 0 ${insetSizes[size]} ${componentTheme.borderSelectedColor}`
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (hovered) {
|
|
82
|
+
return {
|
|
83
|
+
background: componentTheme.backgroundHoverColor,
|
|
84
|
+
borderColor: componentTheme.borderHoverColor,
|
|
85
|
+
checkedBoxShadow: `inset 0 0 0 ${insetSizes[size]} ${componentTheme.borderSelectedColor}`
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
background: componentTheme.backgroundColor,
|
|
90
|
+
borderColor: componentTheme.borderColor,
|
|
91
|
+
checkedBoxShadow: `inset 0 0 0 ${insetSizes[size]} ${componentTheme.borderSelectedColor}`
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
const inputColors = getInputColors();
|
|
95
|
+
const toggleContextBackgrounds = {
|
|
96
|
+
success: componentTheme.toggleBackgroundSuccess,
|
|
97
|
+
warning: componentTheme.toggleBackgroundWarning,
|
|
98
|
+
danger: componentTheme.toggleBackgroundDanger,
|
|
99
|
+
off: componentTheme.toggleBackgroundOff
|
|
100
|
+
};
|
|
101
|
+
const toggleBackground = (_toggleContextBackgro = toggleContextBackgrounds[context !== null && context !== void 0 ? context : 'success']) !== null && _toggleContextBackgro !== void 0 ? _toggleContextBackgro : toggleContextBackgrounds['success'];
|
|
102
|
+
const focusOutline = calcFocusOutlineStyles(sharedTokens.focusOutline);
|
|
103
|
+
focusOutline.transition += ', box-shadow 0.2s';
|
|
104
|
+
const inputVariants = {
|
|
105
|
+
simple: {
|
|
106
|
+
base: {
|
|
107
|
+
all: 'initial',
|
|
108
|
+
boxSizing: 'border-box',
|
|
109
|
+
appearance: 'none',
|
|
110
|
+
display: 'block',
|
|
111
|
+
position: 'relative',
|
|
112
|
+
marginInlineEnd: componentTheme.gap,
|
|
113
|
+
marginInlineStart: '0',
|
|
114
|
+
flexShrink: 0,
|
|
115
|
+
minWidth: '1rem',
|
|
116
|
+
borderRadius: '100%',
|
|
117
|
+
borderWidth: componentTheme.borderWidth,
|
|
118
|
+
borderStyle: 'solid',
|
|
119
|
+
background: inputColors.background,
|
|
120
|
+
borderColor: inputColors.borderColor,
|
|
121
|
+
cursor: disabled ? 'not-allowed' : 'pointer',
|
|
122
|
+
'&:checked': {
|
|
123
|
+
borderColor: disabled ? componentTheme.borderDisabledColor : componentTheme.borderSelectedColor,
|
|
124
|
+
boxShadow: inputColors.checkedBoxShadow
|
|
125
|
+
},
|
|
126
|
+
marginTop: componentTheme.controlVerticalMargin,
|
|
127
|
+
marginBottom: componentTheme.controlVerticalMargin,
|
|
128
|
+
...focusOutline
|
|
129
|
+
},
|
|
130
|
+
small: {
|
|
131
|
+
width: componentTheme.controlSizeSm,
|
|
132
|
+
height: componentTheme.controlSizeSm
|
|
133
|
+
},
|
|
134
|
+
medium: {
|
|
135
|
+
width: componentTheme.controlSizeMd,
|
|
136
|
+
height: componentTheme.controlSizeMd
|
|
137
|
+
},
|
|
138
|
+
large: {
|
|
139
|
+
width: componentTheme.controlSizeLg,
|
|
140
|
+
height: componentTheme.controlSizeLg
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
toggle: {
|
|
144
|
+
base: {
|
|
145
|
+
all: 'initial',
|
|
146
|
+
boxSizing: 'border-box',
|
|
147
|
+
// Visually hidden but accessible (screen reader, focus, keyboard)
|
|
148
|
+
position: 'absolute',
|
|
149
|
+
opacity: 0.0001 /* selenium cannot find fully transparent elements */,
|
|
150
|
+
width: '1px',
|
|
151
|
+
height: '1px',
|
|
152
|
+
overflow: 'hidden',
|
|
153
|
+
margin: 0,
|
|
154
|
+
padding: 0
|
|
155
|
+
},
|
|
156
|
+
small: {},
|
|
157
|
+
medium: {},
|
|
158
|
+
large: {}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const labelVariants = {
|
|
162
|
+
simple: {
|
|
163
|
+
base: {},
|
|
164
|
+
small: {
|
|
165
|
+
fontSize: componentTheme.fontSizeSm,
|
|
166
|
+
lineHeight: componentTheme.lineHeightSm
|
|
167
|
+
},
|
|
168
|
+
medium: {
|
|
169
|
+
fontSize: componentTheme.fontSizeMd,
|
|
170
|
+
lineHeight: componentTheme.lineHeightMd
|
|
171
|
+
},
|
|
172
|
+
large: {
|
|
173
|
+
fontSize: componentTheme.fontSizeLg,
|
|
174
|
+
lineHeight: componentTheme.lineHeightLg
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
toggle: {
|
|
178
|
+
base: {
|
|
179
|
+
flex: '0 0 auto',
|
|
180
|
+
position: 'relative',
|
|
181
|
+
zIndex: 1,
|
|
182
|
+
textTransform: 'uppercase',
|
|
183
|
+
overflow: 'hidden',
|
|
184
|
+
whiteSpace: 'nowrap',
|
|
185
|
+
textOverflow: 'ellipsis',
|
|
186
|
+
lineHeight: 1,
|
|
187
|
+
display: 'flex',
|
|
188
|
+
alignItems: 'center',
|
|
189
|
+
justifyContent: 'center',
|
|
190
|
+
minWidth: '0.0625rem',
|
|
191
|
+
borderRadius: componentTheme.toggleBorderRadius,
|
|
192
|
+
color: disabled ? componentTheme.labelDisabledColor : componentTheme.labelBaseColor,
|
|
193
|
+
background: 'transparent',
|
|
194
|
+
'input:checked + &': {
|
|
195
|
+
color: componentTheme.toggleHandleText,
|
|
196
|
+
background: toggleBackground,
|
|
197
|
+
boxShadow: disabled ? 'none' : boxShadowObjectsToCSSString(componentTheme.toggleShadow)
|
|
198
|
+
},
|
|
199
|
+
...calcFocusOutlineStyles(sharedTokens.focusOutline, {
|
|
200
|
+
customCSSSelector: 'input:focus + &&'
|
|
201
|
+
}),
|
|
202
|
+
'input:focus + &': {
|
|
203
|
+
textDecoration: 'underline'
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
small: {
|
|
207
|
+
fontSize: componentTheme.toggleSmallFontSize,
|
|
208
|
+
height: componentTheme.toggleSmallHeight,
|
|
209
|
+
padding: '0 0.5rem',
|
|
210
|
+
svg: {
|
|
211
|
+
fontSize: `calc(${componentTheme.toggleSmallFontSize} + 0.375rem)`
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
medium: {
|
|
215
|
+
fontSize: componentTheme.toggleMediumFontSize,
|
|
216
|
+
height: componentTheme.toggleMediumHeight,
|
|
217
|
+
padding: '0 0.875rem',
|
|
218
|
+
svg: {
|
|
219
|
+
fontSize: `calc(${componentTheme.toggleMediumFontSize} + 0.375rem)`
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
large: {
|
|
223
|
+
fontSize: componentTheme.toggleLargeFontSize,
|
|
224
|
+
height: componentTheme.toggleLargeHeight,
|
|
225
|
+
padding: '0 1rem',
|
|
226
|
+
svg: {
|
|
227
|
+
fontSize: `calc(${componentTheme.toggleLargeFontSize} + 0.375rem)`
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
return {
|
|
233
|
+
radioInput: {
|
|
234
|
+
label: 'radioInput',
|
|
235
|
+
position: 'relative',
|
|
236
|
+
display: 'flex',
|
|
237
|
+
alignItems: 'flex-start',
|
|
238
|
+
width: inline ? 'auto' : '100%',
|
|
239
|
+
...(inline && {
|
|
240
|
+
display: 'inline-flex',
|
|
241
|
+
verticalAlign: 'middle'
|
|
242
|
+
}),
|
|
243
|
+
'&:hover': {
|
|
244
|
+
cursor: 'default',
|
|
245
|
+
...(disabled && {
|
|
246
|
+
cursor: 'not-allowed'
|
|
247
|
+
})
|
|
248
|
+
}
|
|
249
|
+
},
|
|
250
|
+
input: {
|
|
251
|
+
label: 'radioInput__input',
|
|
252
|
+
...inputVariants[variant].base,
|
|
253
|
+
...inputVariants[variant][size]
|
|
254
|
+
},
|
|
255
|
+
label: {
|
|
256
|
+
label: 'radioInput__label',
|
|
257
|
+
flex: '1 1 auto',
|
|
258
|
+
alignSelf: 'center',
|
|
259
|
+
...labelColors,
|
|
260
|
+
fontFamily: componentTheme.fontFamily,
|
|
261
|
+
fontWeight: componentTheme.fontWeight,
|
|
262
|
+
...labelVariants[variant].base,
|
|
263
|
+
...labelVariants[variant][size],
|
|
264
|
+
cursor: disabled ? 'not-allowed' : 'pointer'
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
export default generateStyle;
|
|
@@ -24,11 +24,11 @@ var _dec, _dec2, _class, _RadioInputGroup;
|
|
|
24
24
|
*/
|
|
25
25
|
|
|
26
26
|
import { Fragment, Children, Component } from 'react';
|
|
27
|
-
import { FormFieldGroup } from '@instructure/ui-form-field';
|
|
27
|
+
import { FormFieldGroup } from '@instructure/ui-form-field/v11_6';
|
|
28
28
|
import { matchComponentTypes, safeCloneElement, omitProps, pickProps, withDeterministicId } from '@instructure/ui-react-utils';
|
|
29
29
|
import { hasVisibleChildren } from '@instructure/ui-a11y-utils';
|
|
30
|
-
import { RadioInput } from "
|
|
31
|
-
import { withStyle } from '@instructure/emotion';
|
|
30
|
+
import { RadioInput } from "../../RadioInput/v1/index.js";
|
|
31
|
+
import { withStyleLegacy as withStyle } from '@instructure/emotion';
|
|
32
32
|
import generateStyle from "./styles.js";
|
|
33
33
|
import generateComponentTheme from "./theme.js";
|
|
34
34
|
import { allowedProps } from "./props.js";
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
var _dec, _class, _RadioInputGroup;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { Children, Component } from 'react';
|
|
27
|
+
import { FormFieldGroup } from '@instructure/ui-form-field/latest';
|
|
28
|
+
import { matchComponentTypes, safeCloneElement, omitProps, pickProps, withDeterministicId } from '@instructure/ui-react-utils';
|
|
29
|
+
import { RadioInput } from "../../RadioInput/v2/index.js";
|
|
30
|
+
import { allowedProps } from "./props.js";
|
|
31
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
32
|
+
/**
|
|
33
|
+
---
|
|
34
|
+
category: components
|
|
35
|
+
---
|
|
36
|
+
**/
|
|
37
|
+
let RadioInputGroup = (_dec = withDeterministicId(), _dec(_class = (_RadioInputGroup = class RadioInputGroup extends Component {
|
|
38
|
+
constructor(props) {
|
|
39
|
+
super(props);
|
|
40
|
+
this.ref = null;
|
|
41
|
+
this._messagesId = void 0;
|
|
42
|
+
this.handleRef = el => {
|
|
43
|
+
this.ref = el;
|
|
44
|
+
};
|
|
45
|
+
this.handleChange = e => {
|
|
46
|
+
const value = e.target.value;
|
|
47
|
+
if (this.props.disabled || this.props.readOnly) {
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (typeof this.props.value === 'undefined') {
|
|
52
|
+
this.setState({
|
|
53
|
+
value
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (typeof this.props.onChange === 'function') {
|
|
57
|
+
this.props.onChange(e, value);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
if (typeof props.value === 'undefined') {
|
|
61
|
+
this.state = {
|
|
62
|
+
value: props.defaultValue
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
this._messagesId = props.deterministicId('RadioInputGroup-messages');
|
|
66
|
+
}
|
|
67
|
+
get hasMessages() {
|
|
68
|
+
return !!this.props.messages && this.props.messages.length > 0;
|
|
69
|
+
}
|
|
70
|
+
get invalid() {
|
|
71
|
+
var _this$props$messages;
|
|
72
|
+
return !!((_this$props$messages = this.props.messages) !== null && _this$props$messages !== void 0 && _this$props$messages.find(m => m.type === 'newError' || m.type === 'error'));
|
|
73
|
+
}
|
|
74
|
+
get value() {
|
|
75
|
+
return typeof this.props.value === 'undefined' ? this.state.value : this.props.value;
|
|
76
|
+
}
|
|
77
|
+
renderChildren() {
|
|
78
|
+
const _this$props = this.props,
|
|
79
|
+
children = _this$props.children,
|
|
80
|
+
name = _this$props.name,
|
|
81
|
+
variant = _this$props.variant,
|
|
82
|
+
size = _this$props.size,
|
|
83
|
+
disabled = _this$props.disabled,
|
|
84
|
+
readOnly = _this$props.readOnly;
|
|
85
|
+
|
|
86
|
+
// This adds the passed in name property to each RadioInput component
|
|
87
|
+
// and checks the input whose value matches the value property
|
|
88
|
+
return Children.map(children, (child, index) => {
|
|
89
|
+
if (matchComponentTypes(child, [RadioInput])) {
|
|
90
|
+
const isChecked = this.value === child.props.value;
|
|
91
|
+
const defaultFocus = !this.value && index === 0;
|
|
92
|
+
return safeCloneElement(child, {
|
|
93
|
+
name,
|
|
94
|
+
disabled: disabled || child.props.disabled,
|
|
95
|
+
variant,
|
|
96
|
+
size,
|
|
97
|
+
checked: isChecked,
|
|
98
|
+
onChange: this.handleChange,
|
|
99
|
+
readOnly: readOnly || child.props.readOnly,
|
|
100
|
+
width: child.props.width || 'auto',
|
|
101
|
+
'aria-describedby': this.hasMessages ? this._messagesId : void 0,
|
|
102
|
+
// only one radio in a group should be considered tabbable
|
|
103
|
+
// if a radio is checked, it should be the input to receive focus when tabbed to
|
|
104
|
+
// if none of the inputs are checked, the first should receive the focus
|
|
105
|
+
tabIndex: isChecked || defaultFocus ? 0 : -1,
|
|
106
|
+
label: child.props.label
|
|
107
|
+
});
|
|
108
|
+
} else {
|
|
109
|
+
return child; // ignore (but preserve) children that aren't RadioInput
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
render() {
|
|
114
|
+
const _this$props2 = this.props,
|
|
115
|
+
variant = _this$props2.variant,
|
|
116
|
+
layout = _this$props2.layout,
|
|
117
|
+
description = _this$props2.description,
|
|
118
|
+
isRequired = _this$props2.isRequired;
|
|
119
|
+
return _jsx(FormFieldGroup, {
|
|
120
|
+
...omitProps(this.props, RadioInputGroup.allowedProps),
|
|
121
|
+
...pickProps(this.props, FormFieldGroup.allowedProps),
|
|
122
|
+
description: description,
|
|
123
|
+
layout: layout === 'columns' && variant === 'toggle' ? 'stacked' : layout // toggles already display in cols
|
|
124
|
+
,
|
|
125
|
+
vAlign: variant === 'toggle' ? 'middle' : 'top',
|
|
126
|
+
rowSpacing: "small",
|
|
127
|
+
colSpacing: variant === 'toggle' ? 'none' : 'small' // keep toggles close together
|
|
128
|
+
,
|
|
129
|
+
startAt: variant === 'toggle' ? 'small' : void 0,
|
|
130
|
+
messagesId: this._messagesId,
|
|
131
|
+
elementRef: this.handleRef,
|
|
132
|
+
role: "radiogroup",
|
|
133
|
+
isRequired: isRequired,
|
|
134
|
+
"data-cid": "RadioInputGroup",
|
|
135
|
+
children: this.renderChildren()
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}, _RadioInputGroup.displayName = "RadioInputGroup", _RadioInputGroup.componentId = 'RadioInputGroup', _RadioInputGroup.allowedProps = allowedProps, _RadioInputGroup.defaultProps = {
|
|
139
|
+
disabled: false,
|
|
140
|
+
variant: 'simple',
|
|
141
|
+
size: 'medium',
|
|
142
|
+
layout: 'stacked',
|
|
143
|
+
readOnly: false
|
|
144
|
+
}, _RadioInputGroup)) || _class);
|
|
145
|
+
export default RadioInputGroup;
|
|
146
|
+
export { RadioInputGroup };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const allowedProps = ['name', 'description', 'defaultValue', 'value', 'onChange', 'disabled', 'readOnly', 'messages', 'children', 'variant', 'size', 'layout', 'isRequired'];
|
|
26
|
+
export { allowedProps };
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
export { RadioInput } from "
|
|
25
|
-
export { RadioInputGroup } from "
|
|
24
|
+
export { RadioInput } from "../RadioInput/v1/index.js";
|
|
25
|
+
export { RadioInputGroup } from "../RadioInputGroup/v1/index.js";
|
package/es/exports/b.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
export { RadioInput } from "../RadioInput/v2/index.js";
|
|
25
|
+
export { RadioInputGroup } from "../RadioInputGroup/v2/index.js";
|