@instructure/ui-radio-input 10.4.2-snapshot-9 → 10.4.2-snapshot-11

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 CHANGED
@@ -3,9 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [10.4.2-snapshot-9](https://github.com/instructure/instructure-ui/compare/v10.4.1...v10.4.2-snapshot-9) (2024-11-05)
6
+ ## [10.4.2-snapshot-11](https://github.com/instructure/instructure-ui/compare/v10.4.1...v10.4.2-snapshot-11) (2024-11-06)
7
7
 
8
- **Note:** Version bump only for package @instructure/ui-radio-input
8
+
9
+ ### Features
10
+
11
+ * **many:** add new form field error msg style + add asterisk for required fields ([9b03683](https://github.com/instructure/instructure-ui/commit/9b03683dadeef4c5deae2c60bea10686f143ff5d))
9
12
 
10
13
 
11
14
 
@@ -1,4 +1,4 @@
1
- var _dec, _dec2, _class, _RadioInputGroup;
1
+ var _dec, _dec2, _dec3, _class, _RadioInputGroup;
2
2
  /*
3
3
  * The MIT License (MIT)
4
4
  *
@@ -23,18 +23,22 @@ var _dec, _dec2, _class, _RadioInputGroup;
23
23
  * SOFTWARE.
24
24
  */
25
25
 
26
+ /** @jsx jsx */
26
27
  import React, { Children, Component } from 'react';
27
28
  import { FormFieldGroup } from '@instructure/ui-form-field';
28
29
  import { testable } from '@instructure/ui-testable';
29
30
  import { matchComponentTypes, safeCloneElement, omitProps, pickProps, withDeterministicId } from '@instructure/ui-react-utils';
30
31
  import { RadioInput } from '../RadioInput';
32
+ import { jsx, withStyle } from '@instructure/emotion';
33
+ import generateStyle from './styles';
34
+ import generateComponentTheme from './theme';
31
35
  import { allowedProps, propTypes } from './props';
32
36
  /**
33
37
  ---
34
38
  category: components
35
39
  ---
36
40
  **/
37
- let RadioInputGroup = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_class = _dec2(_class = (_RadioInputGroup = class RadioInputGroup extends Component {
41
+ let RadioInputGroup = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec3 = testable(), _dec(_class = _dec2(_class = _dec3(_class = (_RadioInputGroup = class RadioInputGroup extends Component {
38
42
  constructor(props) {
39
43
  super(props);
40
44
  this.ref = null;
@@ -67,6 +71,10 @@ let RadioInputGroup = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_c
67
71
  get hasMessages() {
68
72
  return !!this.props.messages && this.props.messages.length > 0;
69
73
  }
74
+ get invalid() {
75
+ var _this$props$messages;
76
+ return !!((_this$props$messages = this.props.messages) !== null && _this$props$messages !== void 0 && _this$props$messages.find(m => m.type === 'newError' || m.type === 'error'));
77
+ }
70
78
  get value() {
71
79
  return typeof this.props.value === 'undefined' ? this.state.value : this.props.value;
72
80
  }
@@ -110,9 +118,14 @@ let RadioInputGroup = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_c
110
118
  const _this$props2 = this.props,
111
119
  variant = _this$props2.variant,
112
120
  layout = _this$props2.layout,
113
- description = _this$props2.description;
114
- return /*#__PURE__*/React.createElement(FormFieldGroup, Object.assign({}, omitProps(this.props, RadioInputGroup.allowedProps), pickProps(this.props, FormFieldGroup.allowedProps), {
115
- description: description,
121
+ description = _this$props2.description,
122
+ isRequired = _this$props2.isRequired,
123
+ styles = _this$props2.styles;
124
+ const descriptionWithRequired = jsx(React.Fragment, null, description, isRequired && jsx("span", {
125
+ css: this.invalid ? styles === null || styles === void 0 ? void 0 : styles.invalidAsterisk : {}
126
+ }, " *"));
127
+ return jsx(FormFieldGroup, Object.assign({}, omitProps(this.props, RadioInputGroup.allowedProps), pickProps(this.props, FormFieldGroup.allowedProps), {
128
+ description: descriptionWithRequired,
116
129
  layout: layout === 'columns' && variant === 'toggle' ? 'stacked' : layout // toggles already display in cols
117
130
  ,
118
131
  vAlign: variant === 'toggle' ? 'middle' : 'top',
@@ -131,6 +144,6 @@ let RadioInputGroup = (_dec = withDeterministicId(), _dec2 = testable(), _dec(_c
131
144
  size: 'medium',
132
145
  layout: 'stacked',
133
146
  readOnly: false
134
- }, _RadioInputGroup)) || _class) || _class);
147
+ }, _RadioInputGroup)) || _class) || _class) || _class);
135
148
  export default RadioInputGroup;
136
149
  export { RadioInputGroup };
@@ -37,7 +37,8 @@ const propTypes = {
37
37
  children: PropTypes.node,
38
38
  variant: PropTypes.oneOf(['simple', 'toggle']),
39
39
  size: PropTypes.oneOf(['small', 'medium', 'large']),
40
- layout: PropTypes.oneOf(['stacked', 'columns', 'inline'])
40
+ layout: PropTypes.oneOf(['stacked', 'columns', 'inline']),
41
+ isRequired: PropTypes.bool
41
42
  };
42
43
  const allowedProps = ['name', 'description', 'defaultValue', 'value', 'onChange', 'disabled', 'readOnly', 'messages', 'children', 'variant', 'size', 'layout'];
43
44
  export { propTypes, allowedProps };
@@ -0,0 +1,41 @@
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
+ /**
26
+ * ---
27
+ * private: true
28
+ * ---
29
+ * Generates the style object from the theme and provided additional information
30
+ * @param {Object} componentTheme The theme variable object.
31
+ * @return {Object} The final style object, which will be used in the component
32
+ */
33
+ const generateStyle = componentTheme => {
34
+ const invalidAsteriskColor = componentTheme.invalidAsteriskColor;
35
+ return {
36
+ invalidAsterisk: {
37
+ color: invalidAsteriskColor
38
+ }
39
+ };
40
+ };
41
+ export default generateStyle;
@@ -0,0 +1,39 @@
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
+ /**
26
+ * Generates the theme object for the component from the theme and provided additional information
27
+ * @param {Object} theme The actual theme object.
28
+ * @return {Object} The final theme object with the overrides and component variables
29
+ */
30
+ const generateComponentTheme = theme => {
31
+ const colors = theme.colors;
32
+ const componentVariables = {
33
+ invalidAsteriskColor: colors.primitives.red57
34
+ };
35
+ return {
36
+ ...componentVariables
37
+ };
38
+ };
39
+ export default generateComponentTheme;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
@@ -14,8 +15,11 @@ var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
14
15
  var _pickProps = require("@instructure/ui-react-utils/lib/pickProps.js");
15
16
  var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
16
17
  var _RadioInput = require("../RadioInput");
18
+ var _emotion = require("@instructure/emotion");
19
+ var _styles = _interopRequireDefault(require("./styles"));
20
+ var _theme = _interopRequireDefault(require("./theme"));
17
21
  var _props = require("./props");
18
- var _dec, _dec2, _class, _RadioInputGroup;
22
+ var _dec, _dec2, _dec3, _class, _RadioInputGroup;
19
23
  /*
20
24
  * The MIT License (MIT)
21
25
  *
@@ -39,12 +43,13 @@ var _dec, _dec2, _class, _RadioInputGroup;
39
43
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40
44
  * SOFTWARE.
41
45
  */
46
+ /** @jsx jsx */
42
47
  /**
43
48
  ---
44
49
  category: components
45
50
  ---
46
51
  **/
47
- let RadioInputGroup = exports.RadioInputGroup = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_RadioInputGroup = class RadioInputGroup extends _react.Component {
52
+ let RadioInputGroup = exports.RadioInputGroup = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec3 = (0, _testable.testable)(), _dec(_class = _dec2(_class = _dec3(_class = (_RadioInputGroup = class RadioInputGroup extends _react.Component {
48
53
  constructor(props) {
49
54
  super(props);
50
55
  this.ref = null;
@@ -77,6 +82,10 @@ let RadioInputGroup = exports.RadioInputGroup = (_dec = (0, _withDeterministicId
77
82
  get hasMessages() {
78
83
  return !!this.props.messages && this.props.messages.length > 0;
79
84
  }
85
+ get invalid() {
86
+ var _this$props$messages;
87
+ return !!((_this$props$messages = this.props.messages) !== null && _this$props$messages !== void 0 && _this$props$messages.find(m => m.type === 'newError' || m.type === 'error'));
88
+ }
80
89
  get value() {
81
90
  return typeof this.props.value === 'undefined' ? this.state.value : this.props.value;
82
91
  }
@@ -120,9 +129,14 @@ let RadioInputGroup = exports.RadioInputGroup = (_dec = (0, _withDeterministicId
120
129
  const _this$props2 = this.props,
121
130
  variant = _this$props2.variant,
122
131
  layout = _this$props2.layout,
123
- description = _this$props2.description;
124
- return /*#__PURE__*/_react.default.createElement(_FormFieldGroup.FormFieldGroup, Object.assign({}, (0, _omitProps.omitProps)(this.props, RadioInputGroup.allowedProps), (0, _pickProps.pickProps)(this.props, _FormFieldGroup.FormFieldGroup.allowedProps), {
125
- description: description,
132
+ description = _this$props2.description,
133
+ isRequired = _this$props2.isRequired,
134
+ styles = _this$props2.styles;
135
+ const descriptionWithRequired = (0, _emotion.jsx)(_react.default.Fragment, null, description, isRequired && (0, _emotion.jsx)("span", {
136
+ css: this.invalid ? styles === null || styles === void 0 ? void 0 : styles.invalidAsterisk : {}
137
+ }, " *"));
138
+ return (0, _emotion.jsx)(_FormFieldGroup.FormFieldGroup, Object.assign({}, (0, _omitProps.omitProps)(this.props, RadioInputGroup.allowedProps), (0, _pickProps.pickProps)(this.props, _FormFieldGroup.FormFieldGroup.allowedProps), {
139
+ description: descriptionWithRequired,
126
140
  layout: layout === 'columns' && variant === 'toggle' ? 'stacked' : layout // toggles already display in cols
127
141
  ,
128
142
  vAlign: variant === 'toggle' ? 'middle' : 'top',
@@ -141,5 +155,5 @@ let RadioInputGroup = exports.RadioInputGroup = (_dec = (0, _withDeterministicId
141
155
  size: 'medium',
142
156
  layout: 'stacked',
143
157
  readOnly: false
144
- }, _RadioInputGroup)) || _class) || _class);
158
+ }, _RadioInputGroup)) || _class) || _class) || _class);
145
159
  var _default = exports.default = RadioInputGroup;
@@ -44,6 +44,7 @@ const propTypes = exports.propTypes = {
44
44
  children: _propTypes.default.node,
45
45
  variant: _propTypes.default.oneOf(['simple', 'toggle']),
46
46
  size: _propTypes.default.oneOf(['small', 'medium', 'large']),
47
- layout: _propTypes.default.oneOf(['stacked', 'columns', 'inline'])
47
+ layout: _propTypes.default.oneOf(['stacked', 'columns', 'inline']),
48
+ isRequired: _propTypes.default.bool
48
49
  };
49
50
  const allowedProps = exports.allowedProps = ['name', 'description', 'defaultValue', 'value', 'onChange', 'disabled', 'readOnly', 'messages', 'children', 'variant', 'size', 'layout'];
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = 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
+ /**
32
+ * ---
33
+ * private: true
34
+ * ---
35
+ * Generates the style object from the theme and provided additional information
36
+ * @param {Object} componentTheme The theme variable object.
37
+ * @return {Object} The final style object, which will be used in the component
38
+ */
39
+ const generateStyle = componentTheme => {
40
+ const invalidAsteriskColor = componentTheme.invalidAsteriskColor;
41
+ return {
42
+ invalidAsterisk: {
43
+ color: invalidAsteriskColor
44
+ }
45
+ };
46
+ };
47
+ var _default = exports.default = generateStyle;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = 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
+ /**
32
+ * Generates the theme object for the component from the theme and provided additional information
33
+ * @param {Object} theme The actual theme object.
34
+ * @return {Object} The final theme object with the overrides and component variables
35
+ */
36
+ const generateComponentTheme = theme => {
37
+ const colors = theme.colors;
38
+ const componentVariables = {
39
+ invalidAsteriskColor: colors.primitives.red57
40
+ };
41
+ return {
42
+ ...componentVariables
43
+ };
44
+ };
45
+ var _default = exports.default = generateComponentTheme;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-radio-input",
3
- "version": "10.4.2-snapshot-9",
3
+ "version": "10.4.2-snapshot-11",
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",
@@ -24,21 +24,21 @@
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.25.6",
27
- "@instructure/emotion": "10.4.2-snapshot-9",
28
- "@instructure/shared-types": "10.4.2-snapshot-9",
29
- "@instructure/ui-dom-utils": "10.4.2-snapshot-9",
30
- "@instructure/ui-form-field": "10.4.2-snapshot-9",
31
- "@instructure/ui-prop-types": "10.4.2-snapshot-9",
32
- "@instructure/ui-react-utils": "10.4.2-snapshot-9",
33
- "@instructure/ui-testable": "10.4.2-snapshot-9",
27
+ "@instructure/emotion": "10.4.2-snapshot-11",
28
+ "@instructure/shared-types": "10.4.2-snapshot-11",
29
+ "@instructure/ui-dom-utils": "10.4.2-snapshot-11",
30
+ "@instructure/ui-form-field": "10.4.2-snapshot-11",
31
+ "@instructure/ui-prop-types": "10.4.2-snapshot-11",
32
+ "@instructure/ui-react-utils": "10.4.2-snapshot-11",
33
+ "@instructure/ui-testable": "10.4.2-snapshot-11",
34
34
  "prop-types": "^15.8.1"
35
35
  },
36
36
  "devDependencies": {
37
- "@instructure/ui-babel-preset": "10.4.2-snapshot-9",
38
- "@instructure/ui-color-utils": "10.4.2-snapshot-9",
39
- "@instructure/ui-test-locator": "10.4.2-snapshot-9",
40
- "@instructure/ui-test-utils": "10.4.2-snapshot-9",
41
- "@instructure/ui-themes": "10.4.2-snapshot-9"
37
+ "@instructure/ui-babel-preset": "10.4.2-snapshot-11",
38
+ "@instructure/ui-color-utils": "10.4.2-snapshot-11",
39
+ "@instructure/ui-test-locator": "10.4.2-snapshot-11",
40
+ "@instructure/ui-test-utils": "10.4.2-snapshot-11",
41
+ "@instructure/ui-themes": "10.4.2-snapshot-11"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "react": ">=16.8 <=18"
@@ -22,6 +22,7 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
+ /** @jsx jsx */
25
26
  import React, { Children, Component } from 'react'
26
27
 
27
28
  import { FormFieldGroup } from '@instructure/ui-form-field'
@@ -37,6 +38,11 @@ import {
37
38
  import { RadioInput } from '../RadioInput'
38
39
  import type { RadioInputProps } from '../RadioInput/props'
39
40
 
41
+ import { jsx, withStyle } from '@instructure/emotion'
42
+
43
+ import generateStyle from './styles'
44
+ import generateComponentTheme from './theme'
45
+
40
46
  import type { RadioInputGroupProps, RadioInputGroupState } from './props'
41
47
  import { allowedProps, propTypes } from './props'
42
48
 
@@ -48,6 +54,7 @@ category: components
48
54
  ---
49
55
  **/
50
56
  @withDeterministicId()
57
+ @withStyle(generateStyle, generateComponentTheme)
51
58
  @testable()
52
59
  class RadioInputGroup extends Component<
53
60
  RadioInputGroupProps,
@@ -90,6 +97,12 @@ class RadioInputGroup extends Component<
90
97
  return !!this.props.messages && this.props.messages.length > 0
91
98
  }
92
99
 
100
+ get invalid() {
101
+ return !!this.props.messages?.find(
102
+ (m) => m.type === 'newError' || m.type === 'error'
103
+ )
104
+ }
105
+
93
106
  handleChange: RadioInputProps['onChange'] = (e) => {
94
107
  const value = e.target.value
95
108
 
@@ -145,13 +158,22 @@ class RadioInputGroup extends Component<
145
158
  }
146
159
 
147
160
  render() {
148
- const { variant, layout, description } = this.props
161
+ const { variant, layout, description, isRequired, styles } = this.props
162
+
163
+ const descriptionWithRequired = (
164
+ <React.Fragment>
165
+ {description}
166
+ {isRequired && (
167
+ <span css={this.invalid ? styles?.invalidAsterisk : {}}> *</span>
168
+ )}
169
+ </React.Fragment>
170
+ )
149
171
 
150
172
  return (
151
173
  <FormFieldGroup
152
174
  {...omitProps(this.props, RadioInputGroup.allowedProps)}
153
175
  {...pickProps(this.props, FormFieldGroup.allowedProps)}
154
- description={description}
176
+ description={descriptionWithRequired}
155
177
  layout={
156
178
  layout === 'columns' && variant === 'toggle' ? 'stacked' : layout
157
179
  } // toggles already display in cols
@@ -28,10 +28,15 @@ import PropTypes from 'prop-types'
28
28
  import { controllable } from '@instructure/ui-prop-types'
29
29
  import { FormPropTypes } from '@instructure/ui-form-field'
30
30
 
31
+ import type {
32
+ WithStyleProps,
33
+ ComponentStyle
34
+ } from '@instructure/emotion'
31
35
  import type { FormMessage } from '@instructure/ui-form-field'
32
36
  import type {
33
37
  OtherHTMLAttributes,
34
- PropValidators
38
+ PropValidators,
39
+ RadioInputGroupTheme
35
40
  } from '@instructure/shared-types'
36
41
  import type { WithDeterministicIdProps } from '@instructure/ui-react-utils'
37
42
 
@@ -72,7 +77,7 @@ type RadioInputGroupOwnProps = {
72
77
  /**
73
78
  * Array of objects with shape: `{
74
79
  * text: ReactNode,
75
- * type: One of: ['error', 'hint', 'success', 'screenreader-only']
80
+ * type: One of: ['error', 'newError', 'hint', 'success', 'screenreader-only']
76
81
  * }`
77
82
  */
78
83
  messages?: FormMessage[]
@@ -87,6 +92,11 @@ type RadioInputGroupOwnProps = {
87
92
  * any children (ones that aren't `RadioInput` are passed through)
88
93
  */
89
94
  children?: React.ReactNode
95
+
96
+ /**
97
+ * Setting this to `true` adds and asterisk after the description (group label). It does not cause any behavioural change.
98
+ */
99
+ isRequired?: boolean
90
100
  }
91
101
 
92
102
  type PropKeys = keyof RadioInputGroupOwnProps
@@ -94,6 +104,7 @@ type PropKeys = keyof RadioInputGroupOwnProps
94
104
  type AllowedPropKeys = Readonly<Array<PropKeys>>
95
105
 
96
106
  type RadioInputGroupProps = RadioInputGroupOwnProps &
107
+ WithStyleProps<RadioInputGroupTheme, RadioInputGroupStyle> &
97
108
  OtherHTMLAttributes<RadioInputGroupOwnProps> &
98
109
  WithDeterministicIdProps
99
110
 
@@ -101,6 +112,8 @@ type RadioInputGroupState = {
101
112
  value?: string | number
102
113
  }
103
114
 
115
+ type RadioInputGroupStyle = ComponentStyle<'invalidAsterisk'>
116
+
104
117
  const propTypes: PropValidators<PropKeys> = {
105
118
  name: PropTypes.string.isRequired,
106
119
  description: PropTypes.node.isRequired,
@@ -115,7 +128,8 @@ const propTypes: PropValidators<PropKeys> = {
115
128
  children: PropTypes.node,
116
129
  variant: PropTypes.oneOf(['simple', 'toggle']),
117
130
  size: PropTypes.oneOf(['small', 'medium', 'large']),
118
- layout: PropTypes.oneOf(['stacked', 'columns', 'inline'])
131
+ layout: PropTypes.oneOf(['stacked', 'columns', 'inline']),
132
+ isRequired: PropTypes.bool
119
133
  }
120
134
 
121
135
  const allowedProps: AllowedPropKeys = [
@@ -133,5 +147,5 @@ const allowedProps: AllowedPropKeys = [
133
147
  'layout'
134
148
  ]
135
149
 
136
- export type { RadioInputGroupProps, RadioInputGroupState }
150
+ export type { RadioInputGroupProps, RadioInputGroupState, RadioInputGroupStyle }
137
151
  export { propTypes, allowedProps }
@@ -0,0 +1,46 @@
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 type { RadioInputGroupTheme } from '@instructure/shared-types'
26
+ import type { RadioInputGroupStyle } from './props'
27
+
28
+ /**
29
+ * ---
30
+ * private: true
31
+ * ---
32
+ * Generates the style object from the theme and provided additional information
33
+ * @param {Object} componentTheme The theme variable object.
34
+ * @return {Object} The final style object, which will be used in the component
35
+ */
36
+ const generateStyle = (componentTheme: RadioInputGroupTheme): RadioInputGroupStyle => {
37
+ const { invalidAsteriskColor } = componentTheme
38
+
39
+ return {
40
+ invalidAsterisk: {
41
+ color: invalidAsteriskColor
42
+ }
43
+ }
44
+ }
45
+
46
+ export default generateStyle
@@ -0,0 +1,45 @@
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 type { Theme } from '@instructure/ui-themes'
26
+ import { RadioInputGroupTheme } from '@instructure/shared-types'
27
+
28
+ /**
29
+ * Generates the theme object for the component from the theme and provided additional information
30
+ * @param {Object} theme The actual theme object.
31
+ * @return {Object} The final theme object with the overrides and component variables
32
+ */
33
+ const generateComponentTheme = (theme: Theme): RadioInputGroupTheme => {
34
+ const { colors } = theme
35
+
36
+ const componentVariables: RadioInputGroupTheme = {
37
+ invalidAsteriskColor: colors.primitives.red57
38
+ }
39
+
40
+ return {
41
+ ...componentVariables
42
+ }
43
+ }
44
+
45
+ export default generateComponentTheme