@instructure/ui-checkbox 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.
Files changed (158) hide show
  1. package/CHANGELOG.md +44 -297
  2. package/es/Checkbox/{CheckboxFacade → v1/CheckboxFacade}/index.js +1 -1
  3. package/es/Checkbox/{ToggleFacade → v1/ToggleFacade}/index.js +1 -1
  4. package/es/Checkbox/{index.js → v1/index.js} +3 -3
  5. package/es/Checkbox/v2/CheckboxFacade/index.js +104 -0
  6. package/es/Checkbox/v2/CheckboxFacade/props.js +26 -0
  7. package/es/Checkbox/v2/CheckboxFacade/styles.js +177 -0
  8. package/es/Checkbox/v2/ToggleFacade/index.js +116 -0
  9. package/es/Checkbox/v2/ToggleFacade/props.js +26 -0
  10. package/es/Checkbox/v2/ToggleFacade/styles.js +232 -0
  11. package/es/Checkbox/v2/index.js +289 -0
  12. package/es/Checkbox/v2/props.js +26 -0
  13. package/es/Checkbox/v2/styles.js +102 -0
  14. package/es/CheckboxGroup/{index.js → v1/index.js} +2 -2
  15. package/es/CheckboxGroup/v2/index.js +125 -0
  16. package/es/CheckboxGroup/v2/props.js +26 -0
  17. package/es/{index.js → exports/a.js} +2 -2
  18. package/es/exports/b.js +25 -0
  19. package/lib/Checkbox/{CheckboxFacade → v1/CheckboxFacade}/index.js +2 -2
  20. package/lib/Checkbox/{ToggleFacade → v1/ToggleFacade}/index.js +3 -3
  21. package/lib/Checkbox/{index.js → v1/index.js} +5 -5
  22. package/lib/Checkbox/v2/CheckboxFacade/index.js +109 -0
  23. package/lib/Checkbox/v2/CheckboxFacade/props.js +31 -0
  24. package/lib/Checkbox/v2/CheckboxFacade/styles.js +183 -0
  25. package/lib/Checkbox/v2/ToggleFacade/index.js +121 -0
  26. package/lib/Checkbox/v2/ToggleFacade/props.js +31 -0
  27. package/lib/Checkbox/v2/ToggleFacade/styles.js +238 -0
  28. package/lib/Checkbox/v2/index.js +308 -0
  29. package/lib/Checkbox/v2/props.js +31 -0
  30. package/lib/Checkbox/v2/styles.js +108 -0
  31. package/lib/CheckboxGroup/{index.js → v1/index.js} +5 -5
  32. package/lib/CheckboxGroup/v2/index.js +133 -0
  33. package/lib/CheckboxGroup/v2/props.js +31 -0
  34. package/lib/{index.js → exports/a.js} +6 -6
  35. package/lib/exports/b.js +31 -0
  36. package/package.json +45 -23
  37. package/src/Checkbox/{CheckboxFacade → v1/CheckboxFacade}/index.tsx +1 -1
  38. package/src/Checkbox/{CheckboxFacade → v1/CheckboxFacade}/styles.ts +3 -1
  39. package/src/Checkbox/{ToggleFacade → v1/ToggleFacade}/index.tsx +1 -1
  40. package/src/Checkbox/{index.tsx → v1/index.tsx} +3 -3
  41. package/src/Checkbox/{props.ts → v1/props.ts} +1 -1
  42. package/src/Checkbox/{styles.ts → v1/styles.ts} +1 -1
  43. package/src/Checkbox/{theme.ts → v1/theme.ts} +1 -1
  44. package/src/Checkbox/v2/CheckboxFacade/index.tsx +113 -0
  45. package/src/Checkbox/v2/CheckboxFacade/props.ts +67 -0
  46. package/src/Checkbox/v2/CheckboxFacade/styles.ts +209 -0
  47. package/src/Checkbox/v2/README.md +193 -0
  48. package/src/Checkbox/v2/ToggleFacade/index.tsx +124 -0
  49. package/src/Checkbox/v2/ToggleFacade/props.ts +67 -0
  50. package/src/Checkbox/v2/ToggleFacade/styles.ts +301 -0
  51. package/src/Checkbox/v2/index.tsx +376 -0
  52. package/src/Checkbox/v2/props.ts +132 -0
  53. package/src/Checkbox/v2/styles.ts +118 -0
  54. package/src/CheckboxGroup/{index.tsx → v1/index.tsx} +2 -2
  55. package/src/CheckboxGroup/{props.ts → v1/props.ts} +3 -3
  56. package/src/CheckboxGroup/v2/README.md +111 -0
  57. package/src/CheckboxGroup/v2/index.tsx +157 -0
  58. package/src/CheckboxGroup/v2/props.ts +77 -0
  59. package/src/{index.ts → exports/a.ts} +6 -6
  60. package/src/exports/b.ts +30 -0
  61. package/tsconfig.build.tsbuildinfo +1 -1
  62. package/types/Checkbox/v1/CheckboxFacade/index.d.ts.map +1 -0
  63. package/types/Checkbox/v1/CheckboxFacade/props.d.ts.map +1 -0
  64. package/types/Checkbox/v1/CheckboxFacade/styles.d.ts.map +1 -0
  65. package/types/Checkbox/v1/CheckboxFacade/theme.d.ts.map +1 -0
  66. package/types/Checkbox/v1/ToggleFacade/index.d.ts.map +1 -0
  67. package/types/Checkbox/v1/ToggleFacade/props.d.ts.map +1 -0
  68. package/types/Checkbox/v1/ToggleFacade/styles.d.ts.map +1 -0
  69. package/types/Checkbox/v1/ToggleFacade/theme.d.ts.map +1 -0
  70. package/types/Checkbox/{index.d.ts → v1/index.d.ts} +1 -1
  71. package/types/Checkbox/v1/index.d.ts.map +1 -0
  72. package/types/Checkbox/{props.d.ts → v1/props.d.ts} +1 -1
  73. package/types/Checkbox/v1/props.d.ts.map +1 -0
  74. package/types/Checkbox/v1/styles.d.ts.map +1 -0
  75. package/types/Checkbox/v1/theme.d.ts.map +1 -0
  76. package/types/Checkbox/v2/CheckboxFacade/index.d.ts +39 -0
  77. package/types/Checkbox/v2/CheckboxFacade/index.d.ts.map +1 -0
  78. package/types/Checkbox/v2/CheckboxFacade/props.d.ts +27 -0
  79. package/types/Checkbox/v2/CheckboxFacade/props.d.ts.map +1 -0
  80. package/types/Checkbox/v2/CheckboxFacade/styles.d.ts +16 -0
  81. package/types/Checkbox/v2/CheckboxFacade/styles.d.ts.map +1 -0
  82. package/types/Checkbox/v2/ToggleFacade/index.d.ts +40 -0
  83. package/types/Checkbox/v2/ToggleFacade/index.d.ts.map +1 -0
  84. package/types/Checkbox/v2/ToggleFacade/props.d.ts +25 -0
  85. package/types/Checkbox/v2/ToggleFacade/props.d.ts.map +1 -0
  86. package/types/Checkbox/v2/ToggleFacade/styles.d.ts +16 -0
  87. package/types/Checkbox/v2/ToggleFacade/styles.d.ts.map +1 -0
  88. package/types/Checkbox/v2/index.d.ts +71 -0
  89. package/types/Checkbox/v2/index.d.ts.map +1 -0
  90. package/types/Checkbox/v2/props.d.ts +64 -0
  91. package/types/Checkbox/v2/props.d.ts.map +1 -0
  92. package/types/Checkbox/v2/styles.d.ts +16 -0
  93. package/types/Checkbox/v2/styles.d.ts.map +1 -0
  94. package/types/CheckboxGroup/{index.d.ts → v1/index.d.ts} +1 -1
  95. package/types/CheckboxGroup/v1/index.d.ts.map +1 -0
  96. package/types/CheckboxGroup/{props.d.ts → v1/props.d.ts} +3 -3
  97. package/types/CheckboxGroup/v1/props.d.ts.map +1 -0
  98. package/types/CheckboxGroup/v2/index.d.ts +42 -0
  99. package/types/CheckboxGroup/v2/index.d.ts.map +1 -0
  100. package/types/CheckboxGroup/v2/props.d.ts +30 -0
  101. package/types/CheckboxGroup/v2/props.d.ts.map +1 -0
  102. package/types/exports/a.d.ts +7 -0
  103. package/types/exports/a.d.ts.map +1 -0
  104. package/types/exports/b.d.ts +7 -0
  105. package/types/exports/b.d.ts.map +1 -0
  106. package/types/Checkbox/CheckboxFacade/index.d.ts.map +0 -1
  107. package/types/Checkbox/CheckboxFacade/props.d.ts.map +0 -1
  108. package/types/Checkbox/CheckboxFacade/styles.d.ts.map +0 -1
  109. package/types/Checkbox/CheckboxFacade/theme.d.ts.map +0 -1
  110. package/types/Checkbox/ToggleFacade/index.d.ts.map +0 -1
  111. package/types/Checkbox/ToggleFacade/props.d.ts.map +0 -1
  112. package/types/Checkbox/ToggleFacade/styles.d.ts.map +0 -1
  113. package/types/Checkbox/ToggleFacade/theme.d.ts.map +0 -1
  114. package/types/Checkbox/index.d.ts.map +0 -1
  115. package/types/Checkbox/props.d.ts.map +0 -1
  116. package/types/Checkbox/styles.d.ts.map +0 -1
  117. package/types/Checkbox/theme.d.ts.map +0 -1
  118. package/types/CheckboxGroup/index.d.ts.map +0 -1
  119. package/types/CheckboxGroup/props.d.ts.map +0 -1
  120. package/types/index.d.ts +0 -7
  121. package/types/index.d.ts.map +0 -1
  122. /package/es/Checkbox/{CheckboxFacade → v1/CheckboxFacade}/props.js +0 -0
  123. /package/es/Checkbox/{CheckboxFacade → v1/CheckboxFacade}/styles.js +0 -0
  124. /package/es/Checkbox/{CheckboxFacade → v1/CheckboxFacade}/theme.js +0 -0
  125. /package/es/Checkbox/{ToggleFacade → v1/ToggleFacade}/props.js +0 -0
  126. /package/es/Checkbox/{ToggleFacade → v1/ToggleFacade}/styles.js +0 -0
  127. /package/es/Checkbox/{ToggleFacade → v1/ToggleFacade}/theme.js +0 -0
  128. /package/es/Checkbox/{props.js → v1/props.js} +0 -0
  129. /package/es/Checkbox/{styles.js → v1/styles.js} +0 -0
  130. /package/es/Checkbox/{theme.js → v1/theme.js} +0 -0
  131. /package/es/CheckboxGroup/{props.js → v1/props.js} +0 -0
  132. /package/lib/Checkbox/{CheckboxFacade → v1/CheckboxFacade}/props.js +0 -0
  133. /package/lib/Checkbox/{CheckboxFacade → v1/CheckboxFacade}/styles.js +0 -0
  134. /package/lib/Checkbox/{CheckboxFacade → v1/CheckboxFacade}/theme.js +0 -0
  135. /package/lib/Checkbox/{ToggleFacade → v1/ToggleFacade}/props.js +0 -0
  136. /package/lib/Checkbox/{ToggleFacade → v1/ToggleFacade}/styles.js +0 -0
  137. /package/lib/Checkbox/{ToggleFacade → v1/ToggleFacade}/theme.js +0 -0
  138. /package/lib/Checkbox/{props.js → v1/props.js} +0 -0
  139. /package/lib/Checkbox/{styles.js → v1/styles.js} +0 -0
  140. /package/lib/Checkbox/{theme.js → v1/theme.js} +0 -0
  141. /package/lib/CheckboxGroup/{props.js → v1/props.js} +0 -0
  142. /package/src/Checkbox/{CheckboxFacade → v1/CheckboxFacade}/props.ts +0 -0
  143. /package/src/Checkbox/{CheckboxFacade → v1/CheckboxFacade}/theme.ts +0 -0
  144. /package/src/Checkbox/{README.md → v1/README.md} +0 -0
  145. /package/src/Checkbox/{ToggleFacade → v1/ToggleFacade}/props.ts +0 -0
  146. /package/src/Checkbox/{ToggleFacade → v1/ToggleFacade}/styles.ts +0 -0
  147. /package/src/Checkbox/{ToggleFacade → v1/ToggleFacade}/theme.ts +0 -0
  148. /package/src/CheckboxGroup/{README.md → v1/README.md} +0 -0
  149. /package/types/Checkbox/{CheckboxFacade → v1/CheckboxFacade}/index.d.ts +0 -0
  150. /package/types/Checkbox/{CheckboxFacade → v1/CheckboxFacade}/props.d.ts +0 -0
  151. /package/types/Checkbox/{CheckboxFacade → v1/CheckboxFacade}/styles.d.ts +0 -0
  152. /package/types/Checkbox/{CheckboxFacade → v1/CheckboxFacade}/theme.d.ts +0 -0
  153. /package/types/Checkbox/{ToggleFacade → v1/ToggleFacade}/index.d.ts +0 -0
  154. /package/types/Checkbox/{ToggleFacade → v1/ToggleFacade}/props.d.ts +0 -0
  155. /package/types/Checkbox/{ToggleFacade → v1/ToggleFacade}/styles.d.ts +0 -0
  156. /package/types/Checkbox/{ToggleFacade → v1/ToggleFacade}/theme.d.ts +0 -0
  157. /package/types/Checkbox/{styles.d.ts → v1/styles.d.ts} +0 -0
  158. /package/types/Checkbox/{theme.d.ts → v1/theme.d.ts} +0 -0
@@ -0,0 +1,289 @@
1
+ var _dec, _dec2, _class, _Checkbox;
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 { Component } from 'react';
27
+ import keycode from 'keycode';
28
+ import { FormFieldMessages } from '@instructure/ui-form-field/latest';
29
+ import { createChainedFunction } from '@instructure/ui-utils';
30
+ import { logError as error } from '@instructure/console';
31
+ import { isActiveElement } from '@instructure/ui-dom-utils';
32
+ import { omitProps, withDeterministicId } from '@instructure/ui-react-utils';
33
+ import { View } from '@instructure/ui-view/latest';
34
+ import { withStyle } from '@instructure/emotion';
35
+ import { CheckboxFacade } from "./CheckboxFacade/index.js";
36
+ import { ToggleFacade } from "./ToggleFacade/index.js";
37
+ import generateStyle from "./styles.js";
38
+ import { allowedProps } from "./props.js";
39
+ import { jsxs as _jsxs, jsx as _jsx } from "@emotion/react/jsx-runtime";
40
+ /**
41
+ ---
42
+ category: components
43
+ tags: toggle, switch
44
+ ---
45
+ **/
46
+ let Checkbox = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec(_class = _dec2(_class = (_Checkbox = class Checkbox extends Component {
47
+ constructor(props) {
48
+ super(props);
49
+ this._defaultId = void 0;
50
+ this._input = null;
51
+ this.ref = null;
52
+ this.handleRef = el => {
53
+ this.ref = el;
54
+ };
55
+ this.handleInputRef = el => {
56
+ this._input = el;
57
+ if (typeof this.props.inputRef === 'function') {
58
+ this.props.inputRef(el);
59
+ }
60
+ };
61
+ this.handleChange = e => {
62
+ const _this$props = this.props,
63
+ onChange = _this$props.onChange,
64
+ disabled = _this$props.disabled,
65
+ checked = _this$props.checked,
66
+ readOnly = _this$props.readOnly;
67
+ if (disabled || readOnly) {
68
+ e.preventDefault();
69
+ return;
70
+ }
71
+ if (typeof checked === 'undefined') {
72
+ this.setState({
73
+ checked: !this.state.checked
74
+ });
75
+ }
76
+ if (typeof onChange === 'function') {
77
+ onChange(e);
78
+ }
79
+ };
80
+ this.handleKeyDown = e => {
81
+ if (this.props.variant === 'toggle' && e.keyCode === keycode.codes.enter) {
82
+ this._input && this._input.click();
83
+ e.preventDefault();
84
+ }
85
+ };
86
+ this.handleFocus = () => {
87
+ this.setState({
88
+ focused: true
89
+ });
90
+ };
91
+ this.handleBlur = () => {
92
+ this.setState({
93
+ focused: false
94
+ });
95
+ };
96
+ this.handleMouseOver = () => {
97
+ !this.props.disabled && this.setState({
98
+ hovered: true
99
+ });
100
+ };
101
+ this.handleMouseOut = () => {
102
+ this.setState({
103
+ hovered: false
104
+ });
105
+ };
106
+ this.state = {
107
+ focused: false,
108
+ hovered: false,
109
+ checked: typeof props.checked === 'undefined' ? !!props.defaultChecked : void 0
110
+ };
111
+ if (typeof props.checked === 'undefined') {
112
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'checked' does not exist on type 'Readonl... Remove this comment to see the full error message
113
+ this.state.checked = !!props.defaultChecked;
114
+ }
115
+ this._defaultId = props.deterministicId();
116
+ }
117
+ componentDidMount() {
118
+ var _this$props$makeStyle, _this$props2;
119
+ if (this._input) {
120
+ this._input.indeterminate = this.props.indeterminate;
121
+ }
122
+ (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
123
+ }
124
+ componentDidUpdate(prevProps) {
125
+ var _this$props$makeStyle2, _this$props3;
126
+ if (prevProps.indeterminate !== this.props.indeterminate && this._input) {
127
+ this._input.indeterminate = this.props.indeterminate || false;
128
+ }
129
+ (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
130
+ }
131
+ get id() {
132
+ return this.props.id || this._defaultId;
133
+ }
134
+ get checked() {
135
+ return typeof this.props.checked === 'undefined' ? this.state.checked : this.props.checked;
136
+ }
137
+ get focused() {
138
+ return isActiveElement(this._input);
139
+ }
140
+ get isError() {
141
+ var _this$props$messages;
142
+ return !!((_this$props$messages = this.props.messages) !== null && _this$props$messages !== void 0 && _this$props$messages.find(m => m.type === 'error' || m.type === 'newError'));
143
+ }
144
+ get invalid() {
145
+ var _this$props$messages2;
146
+ return !!((_this$props$messages2 = this.props.messages) !== null && _this$props$messages2 !== void 0 && _this$props$messages2.find(m => m.type === 'newError' || m.type === 'error'));
147
+ }
148
+ focus() {
149
+ this._input && this._input.focus();
150
+ }
151
+ renderFacade() {
152
+ const _this$props4 = this.props,
153
+ size = _this$props4.size,
154
+ disabled = _this$props4.disabled,
155
+ variant = _this$props4.variant,
156
+ label = _this$props4.label,
157
+ readOnly = _this$props4.readOnly,
158
+ indeterminate = _this$props4.indeterminate,
159
+ labelPlacement = _this$props4.labelPlacement,
160
+ themeOverride = _this$props4.themeOverride,
161
+ isRequired = _this$props4.isRequired,
162
+ styles = _this$props4.styles;
163
+ const _this$state = this.state,
164
+ hovered = _this$state.hovered,
165
+ focused = _this$state.focused;
166
+ error(!(variant === 'simple' && labelPlacement !== 'end'), `[Checkbox] The \`simple\` variant does not support the \`labelPlacement\` property. Use the \`toggle\` variant instead.`);
167
+ if (variant === 'toggle') {
168
+ return _jsxs(ToggleFacade, {
169
+ disabled: disabled,
170
+ size: size,
171
+ hovered: hovered,
172
+ focused: focused,
173
+ checked: this.checked,
174
+ readOnly: readOnly,
175
+ labelPlacement: labelPlacement,
176
+ themeOverride: themeOverride,
177
+ invalid: this.invalid,
178
+ children: [label, isRequired && label && _jsxs("span", {
179
+ css: this.invalid ? styles === null || styles === void 0 ? void 0 : styles.requiredInvalid : {},
180
+ "aria-hidden": true,
181
+ children: [' ', "*"]
182
+ })]
183
+ });
184
+ } else {
185
+ return _jsxs(CheckboxFacade, {
186
+ disabled: disabled,
187
+ size: size,
188
+ hovered: hovered,
189
+ focused: focused,
190
+ checked: this.checked,
191
+ readOnly: readOnly,
192
+ indeterminate: indeterminate,
193
+ themeOverride: themeOverride,
194
+ invalid: this.invalid,
195
+ children: [label, isRequired && label && _jsxs("span", {
196
+ css: this.invalid ? styles === null || styles === void 0 ? void 0 : styles.requiredInvalid : {},
197
+ "aria-hidden": true,
198
+ children: [' ', "*"]
199
+ })]
200
+ });
201
+ }
202
+ }
203
+ renderMessages() {
204
+ const _this$props5 = this.props,
205
+ messages = _this$props5.messages,
206
+ styles = _this$props5.styles,
207
+ variant = _this$props5.variant;
208
+ return messages && messages.length > 0 ? _jsx(View, {
209
+ display: "block",
210
+ margin: "small 0 0",
211
+ css: this.isError && (variant === 'toggle' ? styles === null || styles === void 0 ? void 0 : styles.indentedToggleError : styles === null || styles === void 0 ? void 0 : styles.indentedError),
212
+ children: _jsx(FormFieldMessages, {
213
+ messages: messages
214
+ })
215
+ }) : null;
216
+ }
217
+ render() {
218
+ const _this$props6 = this.props,
219
+ disabled = _this$props6.disabled,
220
+ readOnly = _this$props6.readOnly,
221
+ value = _this$props6.value,
222
+ onKeyDown = _this$props6.onKeyDown,
223
+ onFocus = _this$props6.onFocus,
224
+ onBlur = _this$props6.onBlur,
225
+ onMouseOver = _this$props6.onMouseOver,
226
+ onMouseOut = _this$props6.onMouseOut,
227
+ indeterminate = _this$props6.indeterminate,
228
+ variant = _this$props6.variant,
229
+ styles = _this$props6.styles,
230
+ isRequired = _this$props6.isRequired;
231
+ const props = omitProps(this.props, Checkbox.allowedProps);
232
+ error(!(variant === 'toggle' && indeterminate), `[Checkbox] The \`toggle\` variant does not support the \`indeterminate\` property. Use the \`simple\` variant instead.`);
233
+ return _jsx("div", {
234
+ css: styles === null || styles === void 0 ? void 0 : styles.checkbox
235
+ /* eslint-disable-next-line jsx-a11y/mouse-events-have-key-events */,
236
+ onMouseOver: createChainedFunction(onMouseOver, this.handleMouseOver)
237
+ /* eslint-disable-next-line jsx-a11y/mouse-events-have-key-events */,
238
+ onMouseOut: createChainedFunction(onMouseOut, this.handleMouseOut),
239
+ ref: this.handleRef,
240
+ "data-cid": "Checkbox",
241
+ children: _jsxs("div", {
242
+ css: styles === null || styles === void 0 ? void 0 : styles.container,
243
+ children: [_jsx("input", {
244
+ ...props,
245
+ id: this.id,
246
+ value: value,
247
+ type: "checkbox",
248
+ ref: this.handleInputRef,
249
+ required: isRequired,
250
+ disabled: disabled,
251
+ readOnly: readOnly,
252
+ "aria-readonly": readOnly ? true : void 0,
253
+ "aria-checked": indeterminate ? 'mixed' : void 0,
254
+ css: styles === null || styles === void 0 ? void 0 : styles.input,
255
+ onClickCapture: e => {
256
+ if (readOnly) {
257
+ e.stopPropagation();
258
+ e.preventDefault();
259
+ }
260
+ },
261
+ onChange: this.handleChange,
262
+ onKeyDown: createChainedFunction(onKeyDown, this.handleKeyDown),
263
+ onFocus: createChainedFunction(onFocus, this.handleFocus),
264
+ onBlur: createChainedFunction(onBlur, this.handleBlur),
265
+ checked: this.checked
266
+ }), _jsxs("label", {
267
+ htmlFor: this.id,
268
+ css: styles === null || styles === void 0 ? void 0 : styles.control,
269
+ onMouseDown: e => {
270
+ var _this$_input;
271
+ e.preventDefault();
272
+ (_this$_input = this._input) === null || _this$_input === void 0 ? void 0 : _this$_input.focus();
273
+ },
274
+ children: [this.renderFacade(), this.renderMessages()]
275
+ })]
276
+ })
277
+ });
278
+ }
279
+ }, _Checkbox.displayName = "Checkbox", _Checkbox.componentId = 'Checkbox', _Checkbox.allowedProps = allowedProps, _Checkbox.defaultProps = {
280
+ size: 'medium',
281
+ variant: 'simple',
282
+ disabled: false,
283
+ inline: false,
284
+ indeterminate: false,
285
+ readOnly: false,
286
+ labelPlacement: 'end'
287
+ }, _Checkbox)) || _class) || _class);
288
+ export default Checkbox;
289
+ export { Checkbox, CheckboxFacade, ToggleFacade };
@@ -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 = ['label', 'id', 'value', 'messages', 'defaultChecked', 'checked', 'onChange', 'onKeyDown', 'onFocus', 'onBlur', 'onMouseOver', 'onMouseOut', 'disabled', 'readOnly', 'indeterminate', 'size', 'variant', 'inline', 'labelPlacement', 'isRequired', 'inputRef'];
26
+ export { allowedProps };
@@ -0,0 +1,102 @@
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
+ * @param {Object} props the props of the component, the style is applied to
32
+ * @param {Object} sharedTokens Shared theme token object
33
+ * @param {Object} state the state of the component, the style is applied to
34
+ * @return {Object} The final style object, which will be used in the component
35
+ */
36
+ const generateStyle = (componentTheme, props) => {
37
+ var _sizeVariants;
38
+ const inline = props.inline,
39
+ size = props.size,
40
+ variant = props.variant;
41
+
42
+ // toggleFullWidth calculation based on Toggle facade width (1.625rem * 1.5) and the marginInlineEnd (0.75rem)
43
+ const toggleFullWidth = `calc(1.625rem * 1.5 + 0.75rem)`;
44
+ const sizeVariants = {
45
+ small: {
46
+ paddingLeft: variant === 'toggle' ? toggleFullWidth : `calc(${componentTheme.gap} + ${componentTheme.controlSizeSm})`
47
+ },
48
+ medium: {
49
+ paddingLeft: variant === 'toggle' ? toggleFullWidth : `calc(${componentTheme.gap} + ${componentTheme.controlSizeMd})`
50
+ },
51
+ large: {
52
+ paddingLeft: variant === 'toggle' ? toggleFullWidth : `calc(${componentTheme.gap} + ${componentTheme.controlSizeLg})`
53
+ }
54
+ };
55
+ const sizeVariant = (_sizeVariants = sizeVariants[size]) !== null && _sizeVariants !== void 0 ? _sizeVariants : sizeVariants.medium;
56
+ return {
57
+ requiredInvalid: {
58
+ color: componentTheme.asteriskColor
59
+ },
60
+ indentedError: {
61
+ paddingLeft: sizeVariant.paddingLeft
62
+ },
63
+ indentedToggleError: {
64
+ paddingLeft: sizeVariant.paddingLeft
65
+ },
66
+ checkbox: {
67
+ label: 'checkbox',
68
+ position: 'relative',
69
+ width: '100%',
70
+ ...(inline && {
71
+ display: 'inline-block',
72
+ verticalAlign: 'middle',
73
+ width: 'auto'
74
+ })
75
+ },
76
+ // this container is added to reduce the clickable area of the checkbox to the actual checkbox and label
77
+ container: {
78
+ width: 'fit-content'
79
+ },
80
+ input: {
81
+ label: 'checkbox__input',
82
+ padding: 0,
83
+ margin: 0,
84
+ fontSize: 'inherit',
85
+ lineHeight: 'inherit',
86
+ width: 'auto',
87
+ position: 'absolute',
88
+ top: 0,
89
+ insetInlineStart: 0,
90
+ insetInlineEnd: 'auto',
91
+ opacity: 0.0001 /* selenium cannot find fully transparent elements */
92
+ },
93
+ control: {
94
+ label: 'checkbox__control',
95
+ all: 'initial',
96
+ display: 'block',
97
+ direction: 'inherit',
98
+ textAlign: 'start'
99
+ }
100
+ };
101
+ };
102
+ export default generateStyle;
@@ -24,9 +24,9 @@ var _dec, _class, _CheckboxGroup;
24
24
  */
25
25
 
26
26
  import { 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, pickProps, omitProps, withDeterministicId } from '@instructure/ui-react-utils';
29
- import { Checkbox } from "../Checkbox/index.js";
29
+ import { Checkbox } from "../../Checkbox/v1/index.js";
30
30
  import { allowedProps } from "./props.js";
31
31
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
32
32
  /**
@@ -0,0 +1,125 @@
1
+ var _dec, _class, _CheckboxGroup;
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, pickProps, omitProps, withDeterministicId } from '@instructure/ui-react-utils';
29
+ import { Checkbox } from "../../Checkbox/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 CheckboxGroup = (_dec = withDeterministicId(), _dec(_class = (_CheckboxGroup = class CheckboxGroup extends Component {
38
+ constructor(props) {
39
+ super(props);
40
+ this._messagesId = void 0;
41
+ this.ref = null;
42
+ this.handleRef = el => {
43
+ this.ref = el;
44
+ };
45
+ this.handleChange = e => {
46
+ const newValue = this.value;
47
+ if (this.props.disabled || this.props.readOnly) {
48
+ e.preventDefault();
49
+ return;
50
+ }
51
+ if (e.target.checked) {
52
+ newValue.push(e.target.value);
53
+ } else {
54
+ newValue.splice(newValue.indexOf(e.target.value), 1);
55
+ }
56
+ if (typeof this.props.value === 'undefined') {
57
+ this.setState({
58
+ value: newValue
59
+ });
60
+ }
61
+ if (typeof this.props.onChange === 'function') {
62
+ this.props.onChange(newValue);
63
+ }
64
+ };
65
+ if (typeof props.value === 'undefined') {
66
+ this.state = {
67
+ value: props.defaultValue || []
68
+ };
69
+ }
70
+ this._messagesId = props.deterministicId();
71
+ }
72
+ get hasMessages() {
73
+ return this.props.messages && this.props.messages.length > 0;
74
+ }
75
+ get value() {
76
+ return typeof this.props.value === 'undefined' ? [...this.state.value] : [...this.props.value];
77
+ }
78
+ renderChildren() {
79
+ const _this$props = this.props,
80
+ children = _this$props.children,
81
+ name = _this$props.name,
82
+ size = _this$props.size,
83
+ disabled = _this$props.disabled,
84
+ readOnly = _this$props.readOnly;
85
+ return Children.map(children, child => {
86
+ if (matchComponentTypes(child, [Checkbox])) {
87
+ return safeCloneElement(child, {
88
+ key: `${child.props.name}`,
89
+ name,
90
+ label: child.props.label,
91
+ disabled: disabled || child.props.disabled,
92
+ readOnly: readOnly || child.props.readOnly,
93
+ size,
94
+ checked: this.value.indexOf(child.props.value) > -1,
95
+ onChange: this.handleChange,
96
+ width: child.props.width || 'auto',
97
+ 'aria-describedby': this.hasMessages ? this._messagesId : void 0
98
+ });
99
+ } else {
100
+ return child;
101
+ }
102
+ });
103
+ }
104
+ render() {
105
+ return _jsx(FormFieldGroup, {
106
+ ...omitProps(this.props, CheckboxGroup.allowedProps),
107
+ ...pickProps(this.props, FormFieldGroup.allowedProps),
108
+ description: this.props.description,
109
+ rowSpacing: "small",
110
+ vAlign: "top",
111
+ messagesId: this._messagesId,
112
+ elementRef: this.handleRef,
113
+ "data-cid": "CheckboxGroup",
114
+ children: this.renderChildren()
115
+ });
116
+ }
117
+ }, _CheckboxGroup.displayName = "CheckboxGroup", _CheckboxGroup.componentId = 'CheckboxGroup', _CheckboxGroup.allowedProps = allowedProps, _CheckboxGroup.defaultProps = {
118
+ disabled: false,
119
+ readOnly: false,
120
+ size: 'medium',
121
+ layout: 'stacked',
122
+ children: null
123
+ }, _CheckboxGroup)) || _class);
124
+ export default CheckboxGroup;
125
+ export { CheckboxGroup };
@@ -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', 'size', 'layout'];
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 { Checkbox, CheckboxFacade, ToggleFacade } from "./Checkbox/index.js";
25
- export { CheckboxGroup } from "./CheckboxGroup/index.js";
24
+ export { Checkbox, CheckboxFacade, ToggleFacade } from "../Checkbox/v1/index.js";
25
+ export { CheckboxGroup } from "../CheckboxGroup/v1/index.js";
@@ -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 { Checkbox, CheckboxFacade, ToggleFacade } from "../Checkbox/v2/index.js";
25
+ export { CheckboxGroup } from "../CheckboxGroup/v2/index.js";
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = exports.CheckboxFacade = void 0;
8
8
  var _react = require("react");
9
9
  var _SVGIcon2 = require("@instructure/ui-svg-images/lib/SVGIcon");
10
- var _IconCheckMarkSolid2 = require("@instructure/ui-icons/lib/IconCheckMarkSolid.js");
10
+ var _IconCheckMarkSolid2 = require("@instructure/ui-icons/lib/generated/IconCheckMarkSolid.js");
11
11
  var _emotion = require("@instructure/emotion");
12
12
  var _styles = _interopRequireDefault(require("./styles"));
13
13
  var _theme = _interopRequireDefault(require("./theme"));
@@ -42,7 +42,7 @@ var _dec, _class, _CheckboxFacade, _SVGIcon, _IconCheckMarkSolid;
42
42
  parent: Checkbox
43
43
  ---
44
44
  **/
45
- let CheckboxFacade = exports.CheckboxFacade = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = (_CheckboxFacade = class CheckboxFacade extends _react.Component {
45
+ let CheckboxFacade = exports.CheckboxFacade = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = (_CheckboxFacade = class CheckboxFacade extends _react.Component {
46
46
  constructor(...args) {
47
47
  super(...args);
48
48
  this.ref = null;
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = exports.ToggleFacade = void 0;
8
8
  var _react = require("react");
9
- var _IconCheckSolid = require("@instructure/ui-icons/lib/IconCheckSolid.js");
10
- var _IconXSolid = require("@instructure/ui-icons/lib/IconXSolid.js");
9
+ var _IconCheckSolid = require("@instructure/ui-icons/lib/generated/IconCheckSolid.js");
10
+ var _IconXSolid = require("@instructure/ui-icons/lib/generated/IconXSolid.js");
11
11
  var _emotion = require("@instructure/emotion");
12
12
  var _styles = _interopRequireDefault(require("./styles"));
13
13
  var _theme = _interopRequireDefault(require("./theme"));
@@ -42,7 +42,7 @@ var _dec, _class, _ToggleFacade;
42
42
  parent: Checkbox
43
43
  ---
44
44
  **/
45
- let ToggleFacade = exports.ToggleFacade = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = (_ToggleFacade = class ToggleFacade extends _react.Component {
45
+ let ToggleFacade = exports.ToggleFacade = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = (_ToggleFacade = class ToggleFacade extends _react.Component {
46
46
  constructor(...args) {
47
47
  super(...args);
48
48
  this.ref = null;