@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,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.RadioInputGroup = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _latest = require("@instructure/ui-form-field/latest");
|
|
9
|
+
var _matchComponentTypes = require("@instructure/ui-react-utils/lib/matchComponentTypes.js");
|
|
10
|
+
var _safeCloneElement = require("@instructure/ui-react-utils/lib/safeCloneElement.js");
|
|
11
|
+
var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
|
|
12
|
+
var _pickProps = require("@instructure/ui-react-utils/lib/pickProps.js");
|
|
13
|
+
var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
|
|
14
|
+
var _v = require("../../RadioInput/v2");
|
|
15
|
+
var _props = require("./props");
|
|
16
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
17
|
+
var _dec, _class, _RadioInputGroup;
|
|
18
|
+
/*
|
|
19
|
+
* The MIT License (MIT)
|
|
20
|
+
*
|
|
21
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
22
|
+
*
|
|
23
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
24
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
25
|
+
* in the Software without restriction, including without limitation the rights
|
|
26
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
27
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
28
|
+
* furnished to do so, subject to the following conditions:
|
|
29
|
+
*
|
|
30
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
31
|
+
* copies or substantial portions of the Software.
|
|
32
|
+
*
|
|
33
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
34
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
35
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
36
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
37
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
38
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
39
|
+
* SOFTWARE.
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
---
|
|
43
|
+
category: components
|
|
44
|
+
---
|
|
45
|
+
**/
|
|
46
|
+
let RadioInputGroup = exports.RadioInputGroup = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec(_class = (_RadioInputGroup = class RadioInputGroup extends _react.Component {
|
|
47
|
+
constructor(props) {
|
|
48
|
+
super(props);
|
|
49
|
+
this.ref = null;
|
|
50
|
+
this._messagesId = void 0;
|
|
51
|
+
this.handleRef = el => {
|
|
52
|
+
this.ref = el;
|
|
53
|
+
};
|
|
54
|
+
this.handleChange = e => {
|
|
55
|
+
const value = e.target.value;
|
|
56
|
+
if (this.props.disabled || this.props.readOnly) {
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (typeof this.props.value === 'undefined') {
|
|
61
|
+
this.setState({
|
|
62
|
+
value
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (typeof this.props.onChange === 'function') {
|
|
66
|
+
this.props.onChange(e, value);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
if (typeof props.value === 'undefined') {
|
|
70
|
+
this.state = {
|
|
71
|
+
value: props.defaultValue
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
this._messagesId = props.deterministicId('RadioInputGroup-messages');
|
|
75
|
+
}
|
|
76
|
+
get hasMessages() {
|
|
77
|
+
return !!this.props.messages && this.props.messages.length > 0;
|
|
78
|
+
}
|
|
79
|
+
get invalid() {
|
|
80
|
+
var _this$props$messages;
|
|
81
|
+
return !!((_this$props$messages = this.props.messages) !== null && _this$props$messages !== void 0 && _this$props$messages.find(m => m.type === 'newError' || m.type === 'error'));
|
|
82
|
+
}
|
|
83
|
+
get value() {
|
|
84
|
+
return typeof this.props.value === 'undefined' ? this.state.value : this.props.value;
|
|
85
|
+
}
|
|
86
|
+
renderChildren() {
|
|
87
|
+
const _this$props = this.props,
|
|
88
|
+
children = _this$props.children,
|
|
89
|
+
name = _this$props.name,
|
|
90
|
+
variant = _this$props.variant,
|
|
91
|
+
size = _this$props.size,
|
|
92
|
+
disabled = _this$props.disabled,
|
|
93
|
+
readOnly = _this$props.readOnly;
|
|
94
|
+
|
|
95
|
+
// This adds the passed in name property to each RadioInput component
|
|
96
|
+
// and checks the input whose value matches the value property
|
|
97
|
+
return _react.Children.map(children, (child, index) => {
|
|
98
|
+
if ((0, _matchComponentTypes.matchComponentTypes)(child, [_v.RadioInput])) {
|
|
99
|
+
const isChecked = this.value === child.props.value;
|
|
100
|
+
const defaultFocus = !this.value && index === 0;
|
|
101
|
+
return (0, _safeCloneElement.safeCloneElement)(child, {
|
|
102
|
+
name,
|
|
103
|
+
disabled: disabled || child.props.disabled,
|
|
104
|
+
variant,
|
|
105
|
+
size,
|
|
106
|
+
checked: isChecked,
|
|
107
|
+
onChange: this.handleChange,
|
|
108
|
+
readOnly: readOnly || child.props.readOnly,
|
|
109
|
+
width: child.props.width || 'auto',
|
|
110
|
+
'aria-describedby': this.hasMessages ? this._messagesId : void 0,
|
|
111
|
+
// only one radio in a group should be considered tabbable
|
|
112
|
+
// if a radio is checked, it should be the input to receive focus when tabbed to
|
|
113
|
+
// if none of the inputs are checked, the first should receive the focus
|
|
114
|
+
tabIndex: isChecked || defaultFocus ? 0 : -1,
|
|
115
|
+
label: child.props.label
|
|
116
|
+
});
|
|
117
|
+
} else {
|
|
118
|
+
return child; // ignore (but preserve) children that aren't RadioInput
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
render() {
|
|
123
|
+
const _this$props2 = this.props,
|
|
124
|
+
variant = _this$props2.variant,
|
|
125
|
+
layout = _this$props2.layout,
|
|
126
|
+
description = _this$props2.description,
|
|
127
|
+
isRequired = _this$props2.isRequired;
|
|
128
|
+
return (0, _jsxRuntime.jsx)(_latest.FormFieldGroup, {
|
|
129
|
+
...(0, _omitProps.omitProps)(this.props, RadioInputGroup.allowedProps),
|
|
130
|
+
...(0, _pickProps.pickProps)(this.props, _latest.FormFieldGroup.allowedProps),
|
|
131
|
+
description: description,
|
|
132
|
+
layout: layout === 'columns' && variant === 'toggle' ? 'stacked' : layout // toggles already display in cols
|
|
133
|
+
,
|
|
134
|
+
vAlign: variant === 'toggle' ? 'middle' : 'top',
|
|
135
|
+
rowSpacing: "small",
|
|
136
|
+
colSpacing: variant === 'toggle' ? 'none' : 'small' // keep toggles close together
|
|
137
|
+
,
|
|
138
|
+
startAt: variant === 'toggle' ? 'small' : void 0,
|
|
139
|
+
messagesId: this._messagesId,
|
|
140
|
+
elementRef: this.handleRef,
|
|
141
|
+
role: "radiogroup",
|
|
142
|
+
isRequired: isRequired,
|
|
143
|
+
"data-cid": "RadioInputGroup",
|
|
144
|
+
children: this.renderChildren()
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}, _RadioInputGroup.displayName = "RadioInputGroup", _RadioInputGroup.componentId = 'RadioInputGroup', _RadioInputGroup.allowedProps = _props.allowedProps, _RadioInputGroup.defaultProps = {
|
|
148
|
+
disabled: false,
|
|
149
|
+
variant: 'simple',
|
|
150
|
+
size: 'medium',
|
|
151
|
+
layout: 'stacked',
|
|
152
|
+
readOnly: false
|
|
153
|
+
}, _RadioInputGroup)) || _class);
|
|
154
|
+
var _default = exports.default = RadioInputGroup;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.allowedProps = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* The MIT License (MIT)
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
* in the Software without restriction, including without limitation the rights
|
|
15
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
* furnished to do so, subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
* copies or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
* SOFTWARE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const allowedProps = exports.allowedProps = ['name', 'description', 'defaultValue', 'value', 'onChange', 'disabled', 'readOnly', 'messages', 'children', 'variant', 'size', 'layout', 'isRequired'];
|
|
@@ -6,14 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
Object.defineProperty(exports, "RadioInput", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _v.RadioInput;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "RadioInputGroup", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function () {
|
|
15
|
-
return
|
|
15
|
+
return _v2.RadioInputGroup;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
|
-
var
|
|
19
|
-
var
|
|
18
|
+
var _v = require("../RadioInput/v1");
|
|
19
|
+
var _v2 = require("../RadioInputGroup/v1");
|
package/lib/exports/b.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "RadioInput", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _v.RadioInput;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "RadioInputGroup", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _v2.RadioInputGroup;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _v = require("../RadioInput/v2");
|
|
19
|
+
var _v2 = require("../RadioInputGroup/v2");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-radio-input",
|
|
3
|
-
"version": "11.6.
|
|
3
|
+
"version": "11.6.1-snapshot-129",
|
|
4
4
|
"description": "A styled HTML input type='radio' element",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -15,22 +15,22 @@
|
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@babel/runtime": "^7.27.6",
|
|
18
|
-
"@instructure/
|
|
19
|
-
"@instructure/
|
|
20
|
-
"@instructure/
|
|
21
|
-
"@instructure/ui-
|
|
22
|
-
"@instructure/
|
|
23
|
-
"@instructure/ui-react-utils": "11.6.
|
|
18
|
+
"@instructure/emotion": "11.6.1-snapshot-129",
|
|
19
|
+
"@instructure/shared-types": "11.6.1-snapshot-129",
|
|
20
|
+
"@instructure/ui-dom-utils": "11.6.1-snapshot-129",
|
|
21
|
+
"@instructure/ui-a11y-utils": "11.6.1-snapshot-129",
|
|
22
|
+
"@instructure/ui-form-field": "11.6.1-snapshot-129",
|
|
23
|
+
"@instructure/ui-react-utils": "11.6.1-snapshot-129"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@testing-library/jest-dom": "^6.6.3",
|
|
27
27
|
"@testing-library/react": "15.0.7",
|
|
28
28
|
"@testing-library/user-event": "^14.6.1",
|
|
29
29
|
"vitest": "^3.2.2",
|
|
30
|
-
"@instructure/ui-axe-check": "11.6.
|
|
31
|
-
"@instructure/ui-
|
|
32
|
-
"@instructure/ui-
|
|
33
|
-
"@instructure/ui-
|
|
30
|
+
"@instructure/ui-axe-check": "11.6.1-snapshot-129",
|
|
31
|
+
"@instructure/ui-color-utils": "11.6.1-snapshot-129",
|
|
32
|
+
"@instructure/ui-babel-preset": "11.6.1-snapshot-129",
|
|
33
|
+
"@instructure/ui-themes": "11.6.1-snapshot-129"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"react": ">=18 <=19"
|
|
@@ -40,17 +40,39 @@
|
|
|
40
40
|
},
|
|
41
41
|
"sideEffects": false,
|
|
42
42
|
"exports": {
|
|
43
|
-
".": {
|
|
44
|
-
"types": "./types/index.d.ts",
|
|
45
|
-
"import": "./es/index.js",
|
|
46
|
-
"require": "./lib/index.js",
|
|
47
|
-
"default": "./es/index.js"
|
|
48
|
-
},
|
|
49
43
|
"./lib/*": "./lib/*",
|
|
50
44
|
"./es/*": "./es/*",
|
|
51
45
|
"./types/*": "./types/*",
|
|
52
46
|
"./package.json": "./package.json",
|
|
53
|
-
"./src/*": "./src/*"
|
|
47
|
+
"./src/*": "./src/*",
|
|
48
|
+
".": {
|
|
49
|
+
"src": "./src/exports/a.ts",
|
|
50
|
+
"types": "./types/exports/a.d.ts",
|
|
51
|
+
"import": "./es/exports/a.js",
|
|
52
|
+
"require": "./lib/exports/a.js",
|
|
53
|
+
"default": "./es/exports/a.js"
|
|
54
|
+
},
|
|
55
|
+
"./v11_6": {
|
|
56
|
+
"src": "./src/exports/a.ts",
|
|
57
|
+
"types": "./types/exports/a.d.ts",
|
|
58
|
+
"import": "./es/exports/a.js",
|
|
59
|
+
"require": "./lib/exports/a.js",
|
|
60
|
+
"default": "./es/exports/a.js"
|
|
61
|
+
},
|
|
62
|
+
"./v11_7": {
|
|
63
|
+
"src": "./src/exports/b.ts",
|
|
64
|
+
"types": "./types/exports/b.d.ts",
|
|
65
|
+
"import": "./es/exports/b.js",
|
|
66
|
+
"require": "./lib/exports/b.js",
|
|
67
|
+
"default": "./es/exports/b.js"
|
|
68
|
+
},
|
|
69
|
+
"./latest": {
|
|
70
|
+
"src": "./src/exports/b.ts",
|
|
71
|
+
"types": "./types/exports/b.d.ts",
|
|
72
|
+
"import": "./es/exports/b.js",
|
|
73
|
+
"require": "./lib/exports/b.js",
|
|
74
|
+
"default": "./es/exports/b.js"
|
|
75
|
+
}
|
|
54
76
|
},
|
|
55
77
|
"scripts": {
|
|
56
78
|
"lint": "ui-scripts lint",
|
|
@@ -27,7 +27,7 @@ import { Component } from 'react'
|
|
|
27
27
|
import { omitProps, withDeterministicId } from '@instructure/ui-react-utils'
|
|
28
28
|
import { isActiveElement } from '@instructure/ui-dom-utils'
|
|
29
29
|
|
|
30
|
-
import { withStyle } from '@instructure/emotion'
|
|
30
|
+
import { withStyleLegacy as withStyle } from '@instructure/emotion'
|
|
31
31
|
|
|
32
32
|
import generateStyle from './styles'
|
|
33
33
|
import generateComponentTheme from './theme'
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
---
|
|
2
|
+
describes: RadioInput
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
By default, the RadioInput component is a custom styled HTML radio button.
|
|
6
|
+
|
|
7
|
+
Adjust the size of the RadioInput and its label text via the `size` prop. The default size is
|
|
8
|
+
`medium`. See [RadioInputGroup](/RadioInputGroup) for more details
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
---
|
|
12
|
+
type: example
|
|
13
|
+
---
|
|
14
|
+
<InstUISettingsProvider>
|
|
15
|
+
<Flex>
|
|
16
|
+
<Flex direction="column" margin="medium" gap="medium">
|
|
17
|
+
<RadioInput
|
|
18
|
+
label="small"
|
|
19
|
+
value="foo"
|
|
20
|
+
name="bar"
|
|
21
|
+
size="small"
|
|
22
|
+
/>
|
|
23
|
+
<RadioInput
|
|
24
|
+
label="medium"
|
|
25
|
+
value="foo2"
|
|
26
|
+
name="bar2"
|
|
27
|
+
/>
|
|
28
|
+
<RadioInput
|
|
29
|
+
label="large"
|
|
30
|
+
value="foo3"
|
|
31
|
+
name="bar3"
|
|
32
|
+
size="large"
|
|
33
|
+
/>
|
|
34
|
+
<RadioInput
|
|
35
|
+
label="large disabled"
|
|
36
|
+
value="foo4"
|
|
37
|
+
name="bar4"
|
|
38
|
+
size="large"
|
|
39
|
+
disabled
|
|
40
|
+
/>
|
|
41
|
+
<RadioInput
|
|
42
|
+
label="large readonly"
|
|
43
|
+
value="foo5"
|
|
44
|
+
name="bar5"
|
|
45
|
+
size="large"
|
|
46
|
+
readOnly
|
|
47
|
+
/>
|
|
48
|
+
</Flex>
|
|
49
|
+
<Flex direction="column" margin="medium" gap="medium">
|
|
50
|
+
<RadioInput
|
|
51
|
+
label="small"
|
|
52
|
+
value="foo6"
|
|
53
|
+
name="bar6"
|
|
54
|
+
checked
|
|
55
|
+
size="small"
|
|
56
|
+
checked
|
|
57
|
+
/>
|
|
58
|
+
<RadioInput
|
|
59
|
+
label="medium"
|
|
60
|
+
value="foo7"
|
|
61
|
+
name="bar7"
|
|
62
|
+
checked
|
|
63
|
+
/>
|
|
64
|
+
<RadioInput
|
|
65
|
+
label="large"
|
|
66
|
+
value="foo8"
|
|
67
|
+
name="bar8"
|
|
68
|
+
size="large"
|
|
69
|
+
checked
|
|
70
|
+
/>
|
|
71
|
+
<RadioInput
|
|
72
|
+
label="large disabled checked"
|
|
73
|
+
value="foo9"
|
|
74
|
+
name="bar9"
|
|
75
|
+
size="large"
|
|
76
|
+
disabled
|
|
77
|
+
checked
|
|
78
|
+
/>
|
|
79
|
+
<RadioInput
|
|
80
|
+
label="large readonly"
|
|
81
|
+
value="foo10"
|
|
82
|
+
name="bar10"
|
|
83
|
+
size="large"
|
|
84
|
+
readOnly
|
|
85
|
+
checked
|
|
86
|
+
/>
|
|
87
|
+
</Flex>
|
|
88
|
+
</Flex>
|
|
89
|
+
</InstUISettingsProvider>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Guidelines
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
---
|
|
96
|
+
type: embed
|
|
97
|
+
---
|
|
98
|
+
<Guidelines>
|
|
99
|
+
<Figure recommendation="yes" title="Do">
|
|
100
|
+
<Figure.Item>Use sentence-style capitalization</Figure.Item>
|
|
101
|
+
<Figure.Item>Use a clear and concise label for RadioInput</Figure.Item>
|
|
102
|
+
<Figure.Item>Optionally include a heading to provide further clarity</Figure.Item>
|
|
103
|
+
</Figure>
|
|
104
|
+
<Figure recommendation="no" title="Don't">
|
|
105
|
+
<Figure.Item>Have a single RadioInput</Figure.Item>
|
|
106
|
+
<Figure.Item>Use long labels for RadioInput</Figure.Item>
|
|
107
|
+
<Figure.Item>Display more than two radio inputs horizontally</Figure.Item>
|
|
108
|
+
</Figure>
|
|
109
|
+
</Guidelines>
|
|
110
|
+
```
|
|
@@ -0,0 +1,223 @@
|
|
|
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 {
|
|
26
|
+
useState,
|
|
27
|
+
useRef,
|
|
28
|
+
useImperativeHandle,
|
|
29
|
+
forwardRef,
|
|
30
|
+
useCallback,
|
|
31
|
+
useEffect
|
|
32
|
+
} from 'react'
|
|
33
|
+
|
|
34
|
+
import {
|
|
35
|
+
passthroughProps,
|
|
36
|
+
useDeterministicId
|
|
37
|
+
} from '@instructure/ui-react-utils'
|
|
38
|
+
import { isActiveElement } from '@instructure/ui-dom-utils'
|
|
39
|
+
|
|
40
|
+
import { useStyle } from '@instructure/emotion'
|
|
41
|
+
|
|
42
|
+
import generateStyle from './styles'
|
|
43
|
+
|
|
44
|
+
import type { RadioInputProps } from './props'
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
---
|
|
48
|
+
category: components
|
|
49
|
+
---
|
|
50
|
+
**/
|
|
51
|
+
const RadioInput = forwardRef<RadioInputHandle, RadioInputProps>(
|
|
52
|
+
(props, ref) => {
|
|
53
|
+
const {
|
|
54
|
+
variant = 'simple',
|
|
55
|
+
size = 'medium',
|
|
56
|
+
disabled = false,
|
|
57
|
+
inline = false,
|
|
58
|
+
context = 'success',
|
|
59
|
+
readOnly = false,
|
|
60
|
+
id: idProp,
|
|
61
|
+
label,
|
|
62
|
+
value,
|
|
63
|
+
name,
|
|
64
|
+
checked: checkedProp,
|
|
65
|
+
onClick,
|
|
66
|
+
onChange,
|
|
67
|
+
inputRef,
|
|
68
|
+
themeOverride,
|
|
69
|
+
...rest
|
|
70
|
+
} = props
|
|
71
|
+
const [hovered, setHovered] = useState(false)
|
|
72
|
+
// State for uncontrolled mode
|
|
73
|
+
const [internalChecked, setInternalChecked] = useState(false)
|
|
74
|
+
|
|
75
|
+
// Refs
|
|
76
|
+
const containerRef = useRef<HTMLDivElement | null>(null)
|
|
77
|
+
const inputElementRef = useRef<HTMLInputElement | null>(null)
|
|
78
|
+
|
|
79
|
+
// Deterministic ID generation
|
|
80
|
+
const [deterministicId, setDeterministicId] = useState<string | undefined>()
|
|
81
|
+
const getId = useDeterministicId('RadioInput')
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
setDeterministicId(getId())
|
|
84
|
+
}, [])
|
|
85
|
+
const id = idProp || deterministicId
|
|
86
|
+
|
|
87
|
+
// Computed checked value
|
|
88
|
+
const checked =
|
|
89
|
+
typeof checkedProp === 'undefined' ? internalChecked : checkedProp
|
|
90
|
+
|
|
91
|
+
// Styles - pass props with defaults applied for generateStyle
|
|
92
|
+
const styles = useStyle({
|
|
93
|
+
generateStyle,
|
|
94
|
+
themeOverride,
|
|
95
|
+
params: {
|
|
96
|
+
disabled,
|
|
97
|
+
context,
|
|
98
|
+
inline,
|
|
99
|
+
hovered,
|
|
100
|
+
readOnly,
|
|
101
|
+
size,
|
|
102
|
+
variant
|
|
103
|
+
},
|
|
104
|
+
componentId: 'RadioInput',
|
|
105
|
+
displayName: 'RadioInput'
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
// Event handlers
|
|
109
|
+
const handleInputRef = useCallback(
|
|
110
|
+
(el: HTMLInputElement | null) => {
|
|
111
|
+
inputElementRef.current = el
|
|
112
|
+
if (typeof inputRef === 'function') {
|
|
113
|
+
inputRef(el)
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
[inputRef]
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
const handleClick: React.MouseEventHandler<HTMLInputElement> = useCallback(
|
|
120
|
+
(e) => {
|
|
121
|
+
if (disabled || readOnly) {
|
|
122
|
+
e.preventDefault()
|
|
123
|
+
return
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (typeof onClick === 'function') {
|
|
127
|
+
onClick(e)
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
[disabled, readOnly, onClick]
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
const handleChange: React.ChangeEventHandler<HTMLInputElement> =
|
|
134
|
+
useCallback(
|
|
135
|
+
(e) => {
|
|
136
|
+
if (disabled || readOnly) {
|
|
137
|
+
e.preventDefault()
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (typeof checkedProp === 'undefined') {
|
|
142
|
+
setInternalChecked(!internalChecked)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (typeof onChange === 'function') {
|
|
146
|
+
onChange(e)
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
[disabled, readOnly, checkedProp, internalChecked, onChange]
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
// Expose imperative API via ref
|
|
153
|
+
useImperativeHandle(
|
|
154
|
+
ref,
|
|
155
|
+
() => ({
|
|
156
|
+
focus: () => {
|
|
157
|
+
inputElementRef.current?.focus()
|
|
158
|
+
},
|
|
159
|
+
get focused() {
|
|
160
|
+
return isActiveElement(inputElementRef.current)
|
|
161
|
+
},
|
|
162
|
+
get checked() {
|
|
163
|
+
return checked
|
|
164
|
+
},
|
|
165
|
+
get id() {
|
|
166
|
+
return id
|
|
167
|
+
}
|
|
168
|
+
}),
|
|
169
|
+
[checked, id]
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
const handleMouseOver = () => {
|
|
173
|
+
setHovered(true)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const handleMouseOut = () => {
|
|
177
|
+
setHovered(false)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const passedProps = passthroughProps(rest)
|
|
181
|
+
return (
|
|
182
|
+
<div
|
|
183
|
+
css={styles?.radioInput}
|
|
184
|
+
data-cid="RadioInput"
|
|
185
|
+
ref={containerRef}
|
|
186
|
+
/* eslint-disable-next-line jsx-a11y/mouse-events-have-key-events */
|
|
187
|
+
onMouseOver={handleMouseOver}
|
|
188
|
+
/* eslint-disable-next-line jsx-a11y/mouse-events-have-key-events */
|
|
189
|
+
onMouseOut={handleMouseOut}
|
|
190
|
+
>
|
|
191
|
+
<input
|
|
192
|
+
{...passedProps}
|
|
193
|
+
id={id}
|
|
194
|
+
ref={handleInputRef}
|
|
195
|
+
value={value}
|
|
196
|
+
name={name}
|
|
197
|
+
checked={checked}
|
|
198
|
+
type="radio"
|
|
199
|
+
css={styles?.input}
|
|
200
|
+
readOnly={readOnly}
|
|
201
|
+
disabled={disabled}
|
|
202
|
+
onChange={handleChange}
|
|
203
|
+
onClick={handleClick}
|
|
204
|
+
/>
|
|
205
|
+
<label htmlFor={id} css={styles?.label}>
|
|
206
|
+
{label}
|
|
207
|
+
</label>
|
|
208
|
+
</div>
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
RadioInput.displayName = 'RadioInput'
|
|
214
|
+
|
|
215
|
+
export interface RadioInputHandle {
|
|
216
|
+
focus: () => void
|
|
217
|
+
readonly focused: boolean
|
|
218
|
+
readonly checked: boolean
|
|
219
|
+
readonly id: string | undefined
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export default RadioInput
|
|
223
|
+
export { RadioInput }
|