@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,238 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _uiThemes = require("@instructure/ui-themes");
8
+ var _emotion = require("@instructure/emotion");
9
+ /*
10
+ * The MIT License (MIT)
11
+ *
12
+ * Copyright (c) 2015 - present Instructure, Inc.
13
+ *
14
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
15
+ * of this software and associated documentation files (the "Software"), to deal
16
+ * in the Software without restriction, including without limitation the rights
17
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
18
+ * copies of the Software, and to permit persons to whom the Software is
19
+ * furnished to do so, subject to the following conditions:
20
+ *
21
+ * The above copyright notice and this permission notice shall be included in all
22
+ * copies or substantial portions of the Software.
23
+ *
24
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30
+ * SOFTWARE.
31
+ */
32
+
33
+ /**
34
+ * ---
35
+ * private: true
36
+ * ---
37
+ * Generates the style object from the theme and provided additional information
38
+ * @param {Object} componentTheme The theme variable object.
39
+ * @param {Object} props the props of the component, the style is applied to
40
+ * @param {Object} sharedTokens Shared theme token object
41
+ * @param {Object} state the state of the component, the style is applied to
42
+ * @return {Object} The final style object, which will be used in the component
43
+ */
44
+ const generateStyle = (componentTheme, props, sharedTokens) => {
45
+ var _labelPlacementVarian, _labelSizeVariants;
46
+ const disabled = props.disabled,
47
+ size = props.size,
48
+ checked = props.checked,
49
+ readOnly = props.readOnly,
50
+ focused = props.focused,
51
+ hovered = props.hovered,
52
+ labelPlacement = props.labelPlacement,
53
+ invalid = props.invalid;
54
+ const labelPlacementVariants = {
55
+ start: {
56
+ facade: {
57
+ marginInlineEnd: componentTheme.marginEnd,
58
+ marginInlineStart: componentTheme.marginStart
59
+ },
60
+ label: {
61
+ textAlign: 'end'
62
+ }
63
+ },
64
+ end: {
65
+ facade: {
66
+ marginInlineEnd: componentTheme.marginEnd
67
+ },
68
+ label: {}
69
+ },
70
+ top: {
71
+ facade: {
72
+ marginTop: componentTheme.marginVertical
73
+ },
74
+ label: {
75
+ display: 'block'
76
+ }
77
+ }
78
+ };
79
+ const labelPlacementVariant = (_labelPlacementVarian = labelPlacementVariants[labelPlacement]) !== null && _labelPlacementVarian !== void 0 ? _labelPlacementVarian : labelPlacementVariants.end;
80
+ const labelSizeVariants = {
81
+ small: {
82
+ fontSize: componentTheme.labelFontSizeSm,
83
+ lineHeight: componentTheme.labelLineHeightSm
84
+ },
85
+ medium: {
86
+ fontSize: componentTheme.labelFontSizeMd,
87
+ lineHeight: componentTheme.labelLineHeightMd
88
+ },
89
+ large: {
90
+ fontSize: componentTheme.labelFontSizeLg,
91
+ lineHeight: componentTheme.labelLineHeightLg
92
+ }
93
+ };
94
+ const sizeVariant = (_labelSizeVariants = labelSizeVariants[size]) !== null && _labelSizeVariants !== void 0 ? _labelSizeVariants : labelSizeVariants.medium;
95
+ const getIconBorderColor = () => {
96
+ if (disabled) {
97
+ return checked ? componentTheme.checkedIconBorderDisabledColor : componentTheme.uncheckedIconBorderDisabledColor;
98
+ }
99
+ if (readOnly) {
100
+ return checked ? componentTheme.checkedIconBorderReadonlyColor : componentTheme.uncheckedIconBorderReadonlyColor;
101
+ }
102
+ if (invalid && !checked) {
103
+ return hovered ? componentTheme.uncheckedIconBorderHoverColor : componentTheme.uncheckedIconErrorBorderColor;
104
+ }
105
+ if (checked) {
106
+ return hovered ? componentTheme.checkedIconBorderHoverColor : componentTheme.checkedIconBorderColor;
107
+ }
108
+
109
+ // DEFAULT (unchecked) state
110
+ return hovered ? componentTheme.uncheckedIconBorderHoverColor : componentTheme.uncheckedIconBorderColor;
111
+ };
112
+ const getFacadeStyles = () => {
113
+ const baseStyles = {
114
+ display: 'inline-block',
115
+ userSelect: 'none',
116
+ position: 'relative',
117
+ borderRadius: componentTheme.borderRadius,
118
+ verticalAlign: 'middle',
119
+ height: componentTheme.toggleSize,
120
+ width: componentTheme.toggleWidth,
121
+ ...labelPlacementVariant.facade
122
+ };
123
+ if (disabled) {
124
+ return {
125
+ ...baseStyles,
126
+ background: checked ? componentTheme.checkedBackgroundDisabledColor : componentTheme.backgroundDisabledColor,
127
+ boxShadow: `inset 0 0 0 ${componentTheme.borderWidth} ${checked ? componentTheme.checkedBorderDisabledColor : componentTheme.borderDisabledColor}`,
128
+ opacity: componentTheme.disabledOpacity
129
+ };
130
+ }
131
+ if (readOnly) {
132
+ return {
133
+ ...baseStyles,
134
+ background: checked ? componentTheme.checkedBackgroundReadonlyColor : componentTheme.backgroundReadonlyColor,
135
+ boxShadow: `inset 0 0 0 ${componentTheme.borderWidth} ${checked ? componentTheme.checkedBorderReadonlyColor : componentTheme.borderReadonlyColor}`,
136
+ pointerEvents: 'none'
137
+ };
138
+ }
139
+ if (invalid) {
140
+ return {
141
+ ...baseStyles,
142
+ ...(checked && {
143
+ background: hovered ? componentTheme.checkedBackgroundHoverColor : componentTheme.checkedBackgroundColor,
144
+ boxShadow: `inset 0 0 0 ${componentTheme.borderWidth} ${componentTheme.errorBorderColor}`
145
+ }),
146
+ ...(!checked && {
147
+ background: hovered ? componentTheme.errorBackgroundHoverColor : componentTheme.errorBackgroundColor,
148
+ boxShadow: `inset 0 0 0 ${componentTheme.borderWidth} ${componentTheme.errorBorderColor}`
149
+ })
150
+ };
151
+ }
152
+ if (checked) {
153
+ return {
154
+ ...baseStyles,
155
+ background: hovered ? componentTheme.checkedBackgroundHoverColor : componentTheme.checkedBackgroundColor,
156
+ boxShadow: `inset 0 0 0 ${componentTheme.borderWidth} ${hovered ? componentTheme.checkedBorderHoverColor : componentTheme.checkedBorderColor}`
157
+ };
158
+ }
159
+
160
+ // DEFAULT (unchecked) state
161
+ return {
162
+ ...baseStyles,
163
+ background: hovered ? componentTheme.backgroundHoverColor : componentTheme.backgroundColor,
164
+ boxShadow: `inset 0 0 0 ${componentTheme.borderWidth} ${hovered ? componentTheme.borderHoverColor : componentTheme.borderColor}`
165
+ };
166
+ };
167
+ return {
168
+ toggleFacade: {
169
+ label: 'toggleFacade',
170
+ display: 'flex',
171
+ alignItems: 'center',
172
+ cursor: disabled ? 'not-allowed' : readOnly ? 'default' : 'pointer',
173
+ ...(labelPlacement === 'top' && {
174
+ display: 'block'
175
+ })
176
+ },
177
+ facade: {
178
+ label: 'toggleFacade__facade',
179
+ ...getFacadeStyles(),
180
+ ...(sharedTokens !== null && sharedTokens !== void 0 && sharedTokens.focusOutline ? (0, _emotion.calcFocusOutlineStyles)(sharedTokens.focusOutline, {
181
+ withFocusOutline: focused
182
+ }) : {})
183
+ },
184
+ icon: {
185
+ label: 'toggleFacade__icon',
186
+ display: 'block',
187
+ textAlign: 'center',
188
+ position: 'absolute',
189
+ top: '0',
190
+ insetInlineStart: '0',
191
+ insetInlineEnd: 'auto',
192
+ transition: 'all 0.2s',
193
+ transform: 'translate3d(0, 0, 0)',
194
+ height: componentTheme.toggleSize,
195
+ width: componentTheme.toggleSize,
196
+ ...(checked && {
197
+ transform: `translateX(calc(${componentTheme.toggleWidth} - ${componentTheme.toggleSize}))`,
198
+ '[dir="rtl"] &': {
199
+ transform: `translateX(calc(-1 * (${componentTheme.toggleWidth} - ${componentTheme.toggleSize})))`
200
+ }
201
+ })
202
+ },
203
+ iconToggle: {
204
+ label: 'toggleFacade__iconToggle',
205
+ position: 'relative',
206
+ height: '100%',
207
+ width: '100%',
208
+ display: 'flex',
209
+ alignItems: 'center',
210
+ justifyContent: 'center',
211
+ '&::before': {
212
+ content: '""',
213
+ position: 'absolute',
214
+ height: `calc(100% - (${componentTheme.borderWidth} * 6))`,
215
+ width: `calc(100% - (${componentTheme.borderWidth} * 6))`,
216
+ background: componentTheme.toggleBackground,
217
+ boxShadow: (0, _uiThemes.boxShadowObjectsToCSSString)(componentTheme.toggleShadow),
218
+ borderRadius: '100%',
219
+ border: `${componentTheme.borderWidth} solid ${getIconBorderColor()}`
220
+ },
221
+ '& [class*="lucideIcon"] svg': {
222
+ position: 'relative',
223
+ zIndex: 1
224
+ }
225
+ },
226
+ label: {
227
+ label: 'toggleFacade__label',
228
+ flex: 1,
229
+ minWidth: '0.0625rem',
230
+ color: disabled ? componentTheme.labelDisabledColor : componentTheme.labelColor,
231
+ fontFamily: componentTheme.labelFontFamily,
232
+ fontWeight: componentTheme.labelFontWeight,
233
+ ...sizeVariant,
234
+ ...labelPlacementVariant.label
235
+ }
236
+ };
237
+ };
238
+ var _default = exports.default = generateStyle;
@@ -0,0 +1,308 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.Checkbox = void 0;
8
+ Object.defineProperty(exports, "CheckboxFacade", {
9
+ enumerable: true,
10
+ get: function () {
11
+ return _CheckboxFacade.CheckboxFacade;
12
+ }
13
+ });
14
+ Object.defineProperty(exports, "ToggleFacade", {
15
+ enumerable: true,
16
+ get: function () {
17
+ return _ToggleFacade.ToggleFacade;
18
+ }
19
+ });
20
+ exports.default = void 0;
21
+ var _react = require("react");
22
+ var _keycode = _interopRequireDefault(require("keycode"));
23
+ var _latest = require("@instructure/ui-form-field/latest");
24
+ var _createChainedFunction = require("@instructure/ui-utils/lib/createChainedFunction.js");
25
+ var _console = require("@instructure/console");
26
+ var _isActiveElement = require("@instructure/ui-dom-utils/lib/isActiveElement.js");
27
+ var _omitProps = require("@instructure/ui-react-utils/lib/omitProps.js");
28
+ var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
29
+ var _latest2 = require("@instructure/ui-view/latest");
30
+ var _emotion = require("@instructure/emotion");
31
+ var _CheckboxFacade = require("./CheckboxFacade");
32
+ var _ToggleFacade = require("./ToggleFacade");
33
+ var _styles = _interopRequireDefault(require("./styles"));
34
+ var _props = require("./props");
35
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
36
+ var _dec, _dec2, _class, _Checkbox;
37
+ /*
38
+ * The MIT License (MIT)
39
+ *
40
+ * Copyright (c) 2015 - present Instructure, Inc.
41
+ *
42
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
43
+ * of this software and associated documentation files (the "Software"), to deal
44
+ * in the Software without restriction, including without limitation the rights
45
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
46
+ * copies of the Software, and to permit persons to whom the Software is
47
+ * furnished to do so, subject to the following conditions:
48
+ *
49
+ * The above copyright notice and this permission notice shall be included in all
50
+ * copies or substantial portions of the Software.
51
+ *
52
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
53
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
54
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
55
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
56
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
57
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
58
+ * SOFTWARE.
59
+ */
60
+ /**
61
+ ---
62
+ category: components
63
+ tags: toggle, switch
64
+ ---
65
+ **/
66
+ let Checkbox = exports.Checkbox = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyle)(_styles.default), _dec(_class = _dec2(_class = (_Checkbox = class Checkbox extends _react.Component {
67
+ constructor(props) {
68
+ super(props);
69
+ this._defaultId = void 0;
70
+ this._input = null;
71
+ this.ref = null;
72
+ this.handleRef = el => {
73
+ this.ref = el;
74
+ };
75
+ this.handleInputRef = el => {
76
+ this._input = el;
77
+ if (typeof this.props.inputRef === 'function') {
78
+ this.props.inputRef(el);
79
+ }
80
+ };
81
+ this.handleChange = e => {
82
+ const _this$props = this.props,
83
+ onChange = _this$props.onChange,
84
+ disabled = _this$props.disabled,
85
+ checked = _this$props.checked,
86
+ readOnly = _this$props.readOnly;
87
+ if (disabled || readOnly) {
88
+ e.preventDefault();
89
+ return;
90
+ }
91
+ if (typeof checked === 'undefined') {
92
+ this.setState({
93
+ checked: !this.state.checked
94
+ });
95
+ }
96
+ if (typeof onChange === 'function') {
97
+ onChange(e);
98
+ }
99
+ };
100
+ this.handleKeyDown = e => {
101
+ if (this.props.variant === 'toggle' && e.keyCode === _keycode.default.codes.enter) {
102
+ this._input && this._input.click();
103
+ e.preventDefault();
104
+ }
105
+ };
106
+ this.handleFocus = () => {
107
+ this.setState({
108
+ focused: true
109
+ });
110
+ };
111
+ this.handleBlur = () => {
112
+ this.setState({
113
+ focused: false
114
+ });
115
+ };
116
+ this.handleMouseOver = () => {
117
+ !this.props.disabled && this.setState({
118
+ hovered: true
119
+ });
120
+ };
121
+ this.handleMouseOut = () => {
122
+ this.setState({
123
+ hovered: false
124
+ });
125
+ };
126
+ this.state = {
127
+ focused: false,
128
+ hovered: false,
129
+ checked: typeof props.checked === 'undefined' ? !!props.defaultChecked : void 0
130
+ };
131
+ if (typeof props.checked === 'undefined') {
132
+ // @ts-expect-error ts-migrate(2339) FIXME: Property 'checked' does not exist on type 'Readonl... Remove this comment to see the full error message
133
+ this.state.checked = !!props.defaultChecked;
134
+ }
135
+ this._defaultId = props.deterministicId();
136
+ }
137
+ componentDidMount() {
138
+ var _this$props$makeStyle, _this$props2;
139
+ if (this._input) {
140
+ this._input.indeterminate = this.props.indeterminate;
141
+ }
142
+ (_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2);
143
+ }
144
+ componentDidUpdate(prevProps) {
145
+ var _this$props$makeStyle2, _this$props3;
146
+ if (prevProps.indeterminate !== this.props.indeterminate && this._input) {
147
+ this._input.indeterminate = this.props.indeterminate || false;
148
+ }
149
+ (_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3);
150
+ }
151
+ get id() {
152
+ return this.props.id || this._defaultId;
153
+ }
154
+ get checked() {
155
+ return typeof this.props.checked === 'undefined' ? this.state.checked : this.props.checked;
156
+ }
157
+ get focused() {
158
+ return (0, _isActiveElement.isActiveElement)(this._input);
159
+ }
160
+ get isError() {
161
+ var _this$props$messages;
162
+ return !!((_this$props$messages = this.props.messages) !== null && _this$props$messages !== void 0 && _this$props$messages.find(m => m.type === 'error' || m.type === 'newError'));
163
+ }
164
+ get invalid() {
165
+ var _this$props$messages2;
166
+ return !!((_this$props$messages2 = this.props.messages) !== null && _this$props$messages2 !== void 0 && _this$props$messages2.find(m => m.type === 'newError' || m.type === 'error'));
167
+ }
168
+ focus() {
169
+ this._input && this._input.focus();
170
+ }
171
+ renderFacade() {
172
+ const _this$props4 = this.props,
173
+ size = _this$props4.size,
174
+ disabled = _this$props4.disabled,
175
+ variant = _this$props4.variant,
176
+ label = _this$props4.label,
177
+ readOnly = _this$props4.readOnly,
178
+ indeterminate = _this$props4.indeterminate,
179
+ labelPlacement = _this$props4.labelPlacement,
180
+ themeOverride = _this$props4.themeOverride,
181
+ isRequired = _this$props4.isRequired,
182
+ styles = _this$props4.styles;
183
+ const _this$state = this.state,
184
+ hovered = _this$state.hovered,
185
+ focused = _this$state.focused;
186
+ (0, _console.logError)(!(variant === 'simple' && labelPlacement !== 'end'), `[Checkbox] The \`simple\` variant does not support the \`labelPlacement\` property. Use the \`toggle\` variant instead.`);
187
+ if (variant === 'toggle') {
188
+ return (0, _jsxRuntime.jsxs)(_ToggleFacade.ToggleFacade, {
189
+ disabled: disabled,
190
+ size: size,
191
+ hovered: hovered,
192
+ focused: focused,
193
+ checked: this.checked,
194
+ readOnly: readOnly,
195
+ labelPlacement: labelPlacement,
196
+ themeOverride: themeOverride,
197
+ invalid: this.invalid,
198
+ children: [label, isRequired && label && (0, _jsxRuntime.jsxs)("span", {
199
+ css: this.invalid ? styles === null || styles === void 0 ? void 0 : styles.requiredInvalid : {},
200
+ "aria-hidden": true,
201
+ children: [' ', "*"]
202
+ })]
203
+ });
204
+ } else {
205
+ return (0, _jsxRuntime.jsxs)(_CheckboxFacade.CheckboxFacade, {
206
+ disabled: disabled,
207
+ size: size,
208
+ hovered: hovered,
209
+ focused: focused,
210
+ checked: this.checked,
211
+ readOnly: readOnly,
212
+ indeterminate: indeterminate,
213
+ themeOverride: themeOverride,
214
+ invalid: this.invalid,
215
+ children: [label, isRequired && label && (0, _jsxRuntime.jsxs)("span", {
216
+ css: this.invalid ? styles === null || styles === void 0 ? void 0 : styles.requiredInvalid : {},
217
+ "aria-hidden": true,
218
+ children: [' ', "*"]
219
+ })]
220
+ });
221
+ }
222
+ }
223
+ renderMessages() {
224
+ const _this$props5 = this.props,
225
+ messages = _this$props5.messages,
226
+ styles = _this$props5.styles,
227
+ variant = _this$props5.variant;
228
+ return messages && messages.length > 0 ? (0, _jsxRuntime.jsx)(_latest2.View, {
229
+ display: "block",
230
+ margin: "small 0 0",
231
+ css: this.isError && (variant === 'toggle' ? styles === null || styles === void 0 ? void 0 : styles.indentedToggleError : styles === null || styles === void 0 ? void 0 : styles.indentedError),
232
+ children: (0, _jsxRuntime.jsx)(_latest.FormFieldMessages, {
233
+ messages: messages
234
+ })
235
+ }) : null;
236
+ }
237
+ render() {
238
+ const _this$props6 = this.props,
239
+ disabled = _this$props6.disabled,
240
+ readOnly = _this$props6.readOnly,
241
+ value = _this$props6.value,
242
+ onKeyDown = _this$props6.onKeyDown,
243
+ onFocus = _this$props6.onFocus,
244
+ onBlur = _this$props6.onBlur,
245
+ onMouseOver = _this$props6.onMouseOver,
246
+ onMouseOut = _this$props6.onMouseOut,
247
+ indeterminate = _this$props6.indeterminate,
248
+ variant = _this$props6.variant,
249
+ styles = _this$props6.styles,
250
+ isRequired = _this$props6.isRequired;
251
+ const props = (0, _omitProps.omitProps)(this.props, Checkbox.allowedProps);
252
+ (0, _console.logError)(!(variant === 'toggle' && indeterminate), `[Checkbox] The \`toggle\` variant does not support the \`indeterminate\` property. Use the \`simple\` variant instead.`);
253
+ return (0, _jsxRuntime.jsx)("div", {
254
+ css: styles === null || styles === void 0 ? void 0 : styles.checkbox
255
+ /* eslint-disable-next-line jsx-a11y/mouse-events-have-key-events */,
256
+ onMouseOver: (0, _createChainedFunction.createChainedFunction)(onMouseOver, this.handleMouseOver)
257
+ /* eslint-disable-next-line jsx-a11y/mouse-events-have-key-events */,
258
+ onMouseOut: (0, _createChainedFunction.createChainedFunction)(onMouseOut, this.handleMouseOut),
259
+ ref: this.handleRef,
260
+ "data-cid": "Checkbox",
261
+ children: (0, _jsxRuntime.jsxs)("div", {
262
+ css: styles === null || styles === void 0 ? void 0 : styles.container,
263
+ children: [(0, _jsxRuntime.jsx)("input", {
264
+ ...props,
265
+ id: this.id,
266
+ value: value,
267
+ type: "checkbox",
268
+ ref: this.handleInputRef,
269
+ required: isRequired,
270
+ disabled: disabled,
271
+ readOnly: readOnly,
272
+ "aria-readonly": readOnly ? true : void 0,
273
+ "aria-checked": indeterminate ? 'mixed' : void 0,
274
+ css: styles === null || styles === void 0 ? void 0 : styles.input,
275
+ onClickCapture: e => {
276
+ if (readOnly) {
277
+ e.stopPropagation();
278
+ e.preventDefault();
279
+ }
280
+ },
281
+ onChange: this.handleChange,
282
+ onKeyDown: (0, _createChainedFunction.createChainedFunction)(onKeyDown, this.handleKeyDown),
283
+ onFocus: (0, _createChainedFunction.createChainedFunction)(onFocus, this.handleFocus),
284
+ onBlur: (0, _createChainedFunction.createChainedFunction)(onBlur, this.handleBlur),
285
+ checked: this.checked
286
+ }), (0, _jsxRuntime.jsxs)("label", {
287
+ htmlFor: this.id,
288
+ css: styles === null || styles === void 0 ? void 0 : styles.control,
289
+ onMouseDown: e => {
290
+ var _this$_input;
291
+ e.preventDefault();
292
+ (_this$_input = this._input) === null || _this$_input === void 0 ? void 0 : _this$_input.focus();
293
+ },
294
+ children: [this.renderFacade(), this.renderMessages()]
295
+ })]
296
+ })
297
+ });
298
+ }
299
+ }, _Checkbox.displayName = "Checkbox", _Checkbox.componentId = 'Checkbox', _Checkbox.allowedProps = _props.allowedProps, _Checkbox.defaultProps = {
300
+ size: 'medium',
301
+ variant: 'simple',
302
+ disabled: false,
303
+ inline: false,
304
+ indeterminate: false,
305
+ readOnly: false,
306
+ labelPlacement: 'end'
307
+ }, _Checkbox)) || _class) || _class);
308
+ var _default = exports.default = Checkbox;
@@ -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 = ['label', 'id', 'value', 'messages', 'defaultChecked', 'checked', 'onChange', 'onKeyDown', 'onFocus', 'onBlur', 'onMouseOver', 'onMouseOut', 'disabled', 'readOnly', 'indeterminate', 'size', 'variant', 'inline', 'labelPlacement', 'isRequired', 'inputRef'];
@@ -0,0 +1,108 @@
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
+ * @param {Object} props the props of the component, the style is applied to
38
+ * @param {Object} sharedTokens Shared theme token object
39
+ * @param {Object} state the state of the component, the style is applied to
40
+ * @return {Object} The final style object, which will be used in the component
41
+ */
42
+ const generateStyle = (componentTheme, props) => {
43
+ var _sizeVariants;
44
+ const inline = props.inline,
45
+ size = props.size,
46
+ variant = props.variant;
47
+
48
+ // toggleFullWidth calculation based on Toggle facade width (1.625rem * 1.5) and the marginInlineEnd (0.75rem)
49
+ const toggleFullWidth = `calc(1.625rem * 1.5 + 0.75rem)`;
50
+ const sizeVariants = {
51
+ small: {
52
+ paddingLeft: variant === 'toggle' ? toggleFullWidth : `calc(${componentTheme.gap} + ${componentTheme.controlSizeSm})`
53
+ },
54
+ medium: {
55
+ paddingLeft: variant === 'toggle' ? toggleFullWidth : `calc(${componentTheme.gap} + ${componentTheme.controlSizeMd})`
56
+ },
57
+ large: {
58
+ paddingLeft: variant === 'toggle' ? toggleFullWidth : `calc(${componentTheme.gap} + ${componentTheme.controlSizeLg})`
59
+ }
60
+ };
61
+ const sizeVariant = (_sizeVariants = sizeVariants[size]) !== null && _sizeVariants !== void 0 ? _sizeVariants : sizeVariants.medium;
62
+ return {
63
+ requiredInvalid: {
64
+ color: componentTheme.asteriskColor
65
+ },
66
+ indentedError: {
67
+ paddingLeft: sizeVariant.paddingLeft
68
+ },
69
+ indentedToggleError: {
70
+ paddingLeft: sizeVariant.paddingLeft
71
+ },
72
+ checkbox: {
73
+ label: 'checkbox',
74
+ position: 'relative',
75
+ width: '100%',
76
+ ...(inline && {
77
+ display: 'inline-block',
78
+ verticalAlign: 'middle',
79
+ width: 'auto'
80
+ })
81
+ },
82
+ // this container is added to reduce the clickable area of the checkbox to the actual checkbox and label
83
+ container: {
84
+ width: 'fit-content'
85
+ },
86
+ input: {
87
+ label: 'checkbox__input',
88
+ padding: 0,
89
+ margin: 0,
90
+ fontSize: 'inherit',
91
+ lineHeight: 'inherit',
92
+ width: 'auto',
93
+ position: 'absolute',
94
+ top: 0,
95
+ insetInlineStart: 0,
96
+ insetInlineEnd: 'auto',
97
+ opacity: 0.0001 /* selenium cannot find fully transparent elements */
98
+ },
99
+ control: {
100
+ label: 'checkbox__control',
101
+ all: 'initial',
102
+ display: 'block',
103
+ direction: 'inherit',
104
+ textAlign: 'start'
105
+ }
106
+ };
107
+ };
108
+ var _default = exports.default = generateStyle;