@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,132 @@
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 { FormMessage } from '@instructure/ui-form-field/latest'
26
+ import type {
27
+ CheckboxFacadeTheme,
28
+ OtherHTMLAttributes,
29
+ ToggleFacadeTheme
30
+ } from '@instructure/shared-types'
31
+ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
32
+ import type { WithDeterministicIdProps } from '@instructure/ui-react-utils'
33
+
34
+ type CheckboxOwnProps = {
35
+ label: React.ReactNode
36
+ id?: string
37
+ value?: string | number
38
+ /**
39
+ * Array of objects with shape: `{
40
+ * text: ReactNode,
41
+ * type: One of: ['newError', 'error', 'hint', 'success', 'screenreader-only']
42
+ * }`
43
+ */
44
+ messages?: FormMessage[]
45
+ /* whether to set the input to checked or not on initial render */
46
+ defaultChecked?: boolean
47
+ /**
48
+ * whether the input is checked or not (must be accompanied by an `onChange` prop)
49
+ */
50
+ checked?: boolean // TODO: controllable(PropTypes.bool, 'onChange', 'defaultChecked')
51
+ /**
52
+ * when used with the `checked` prop, the component will not control its own state
53
+ */
54
+ onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void
55
+ onKeyDown?: (e: React.KeyboardEvent<HTMLInputElement>) => void
56
+ onFocus?: (e: React.FocusEvent<HTMLInputElement>) => void
57
+ onBlur?: (e: React.FocusEvent<HTMLInputElement>) => void
58
+ onMouseOver?: (e: React.MouseEvent<HTMLInputElement>) => void
59
+ onMouseOut?: (e: React.MouseEvent<HTMLInputElement>) => void
60
+ /**
61
+ * Whether or not to disable the checkbox
62
+ */
63
+ disabled?: boolean
64
+ /**
65
+ * Works just like disabled but keeps the same styles as if it were active
66
+ */
67
+ readOnly?: boolean
68
+ /**
69
+ * Visual state showing that child checkboxes are a combination of checked and unchecked
70
+ */
71
+ indeterminate?: boolean
72
+ size?: 'small' | 'medium' | 'large'
73
+ variant?: 'simple' | 'toggle'
74
+ inline?: boolean
75
+ labelPlacement?: 'top' | 'start' | 'end'
76
+ isRequired?: boolean
77
+ /**
78
+ * A function that provides a reference to the actual underlying input element
79
+ */
80
+ inputRef?: (inputElement: HTMLInputElement | null) => void
81
+ }
82
+
83
+ type PropKeys = keyof CheckboxOwnProps
84
+
85
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
86
+
87
+ type CheckboxProps = CheckboxOwnProps &
88
+ WithStyleProps<CheckboxFacadeTheme | ToggleFacadeTheme, CheckboxStyle> &
89
+ OtherHTMLAttributes<CheckboxOwnProps> &
90
+ WithDeterministicIdProps
91
+
92
+ type CheckboxStyle = ComponentStyle<
93
+ | 'checkbox'
94
+ | 'input'
95
+ | 'control'
96
+ | 'container'
97
+ | 'requiredInvalid'
98
+ | 'indentedError'
99
+ | 'indentedToggleError'
100
+ >
101
+ const allowedProps: AllowedPropKeys = [
102
+ 'label',
103
+ 'id',
104
+ 'value',
105
+ 'messages',
106
+ 'defaultChecked',
107
+ 'checked',
108
+ 'onChange',
109
+ 'onKeyDown',
110
+ 'onFocus',
111
+ 'onBlur',
112
+ 'onMouseOver',
113
+ 'onMouseOut',
114
+ 'disabled',
115
+ 'readOnly',
116
+ 'indeterminate',
117
+ 'size',
118
+ 'variant',
119
+ 'inline',
120
+ 'labelPlacement',
121
+ 'isRequired',
122
+ 'inputRef'
123
+ ]
124
+
125
+ type CheckboxState = {
126
+ focused: boolean
127
+ hovered: boolean
128
+ checked?: boolean
129
+ }
130
+
131
+ export type { CheckboxProps, CheckboxStyle, CheckboxState }
132
+ export { allowedProps }
@@ -0,0 +1,118 @@
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 { CheckboxProps, CheckboxStyle } from './props'
26
+ import type { NewComponentTypes } from '@instructure/ui-themes'
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
+ * @param {Object} props the props of the component, the style is applied to
35
+ * @param {Object} sharedTokens Shared theme token object
36
+ * @param {Object} state the state of the component, the style is applied to
37
+ * @return {Object} The final style object, which will be used in the component
38
+ */
39
+ const generateStyle = (
40
+ componentTheme: NewComponentTypes['Checkbox'],
41
+ props: CheckboxProps
42
+ ): CheckboxStyle => {
43
+ const { inline, size, variant } = props
44
+
45
+ // toggleFullWidth calculation based on Toggle facade width (1.625rem * 1.5) and the marginInlineEnd (0.75rem)
46
+ const toggleFullWidth = `calc(1.625rem * 1.5 + 0.75rem)`
47
+
48
+ const sizeVariants = {
49
+ small: {
50
+ paddingLeft:
51
+ variant === 'toggle'
52
+ ? toggleFullWidth
53
+ : `calc(${componentTheme.gap} + ${componentTheme.controlSizeSm})`
54
+ },
55
+ medium: {
56
+ paddingLeft:
57
+ variant === 'toggle'
58
+ ? toggleFullWidth
59
+ : `calc(${componentTheme.gap} + ${componentTheme.controlSizeMd})`
60
+ },
61
+ large: {
62
+ paddingLeft:
63
+ variant === 'toggle'
64
+ ? toggleFullWidth
65
+ : `calc(${componentTheme.gap} + ${componentTheme.controlSizeLg})`
66
+ }
67
+ }
68
+ const sizeVariant =
69
+ sizeVariants[size as keyof typeof sizeVariants] ?? sizeVariants.medium
70
+
71
+ return {
72
+ requiredInvalid: {
73
+ color: componentTheme.asteriskColor
74
+ },
75
+ indentedError: {
76
+ paddingLeft: sizeVariant.paddingLeft
77
+ },
78
+ indentedToggleError: {
79
+ paddingLeft: sizeVariant.paddingLeft
80
+ },
81
+ checkbox: {
82
+ label: 'checkbox',
83
+ position: 'relative',
84
+ width: '100%',
85
+ ...(inline && {
86
+ display: 'inline-block',
87
+ verticalAlign: 'middle',
88
+ width: 'auto'
89
+ })
90
+ },
91
+ // this container is added to reduce the clickable area of the checkbox to the actual checkbox and label
92
+ container: {
93
+ width: 'fit-content'
94
+ },
95
+ input: {
96
+ label: 'checkbox__input',
97
+ padding: 0,
98
+ margin: 0,
99
+ fontSize: 'inherit',
100
+ lineHeight: 'inherit',
101
+ width: 'auto',
102
+ position: 'absolute',
103
+ top: 0,
104
+ insetInlineStart: 0,
105
+ insetInlineEnd: 'auto',
106
+ opacity: 0.0001 /* selenium cannot find fully transparent elements */
107
+ },
108
+ control: {
109
+ label: 'checkbox__control',
110
+ all: 'initial',
111
+ display: 'block',
112
+ direction: 'inherit',
113
+ textAlign: 'start'
114
+ }
115
+ }
116
+ }
117
+
118
+ export default generateStyle
@@ -24,7 +24,7 @@
24
24
 
25
25
  import { Children, Component } from 'react'
26
26
 
27
- import { FormFieldGroup } from '@instructure/ui-form-field'
27
+ import { FormFieldGroup } from '@instructure/ui-form-field/v11_6'
28
28
  import {
29
29
  matchComponentTypes,
30
30
  safeCloneElement,
@@ -33,7 +33,7 @@ import {
33
33
  withDeterministicId
34
34
  } from '@instructure/ui-react-utils'
35
35
 
36
- import { Checkbox } from '../Checkbox'
36
+ import { Checkbox } from '../../Checkbox/v1'
37
37
 
38
38
  import { allowedProps } from './props'
39
39
  import type {
@@ -23,12 +23,12 @@
23
23
  */
24
24
 
25
25
  import { type InputHTMLAttributes } from 'react'
26
- import type { FormMessage } from '@instructure/ui-form-field'
26
+ import type { FormMessage } from '@instructure/ui-form-field/v11_6'
27
27
  import type { OtherHTMLAttributes } from '@instructure/shared-types'
28
28
  import type { WithDeterministicIdProps } from '@instructure/ui-react-utils'
29
29
 
30
- import { Checkbox } from '../Checkbox'
31
- import type { CheckboxProps } from '../Checkbox/props'
30
+ import { Checkbox } from '../../Checkbox/v1'
31
+ import type { CheckboxProps } from '../../Checkbox/v1/props'
32
32
 
33
33
  type CheckboxChild = React.ComponentElement<CheckboxProps, Checkbox>
34
34
 
@@ -0,0 +1,111 @@
1
+ ---
2
+ describes: CheckboxGroup
3
+ ---
4
+
5
+ A `<CheckboxGroup/>` is a group of [Checkbox](Checkbox) components that share the same name. You can
6
+ set an array `value` for the entire group and it will handle setting the `checked` and `name` props for you.
7
+ The Checkbox components can be rendered vertically or horizontally using the `layout` property.
8
+
9
+ ```js
10
+ ---
11
+ type: example
12
+ ---
13
+ <FormFieldGroup description={<ScreenReaderContent>CheckboxGroup examples</ScreenReaderContent>}>
14
+ <CheckboxGroup name="sports"
15
+ onChange={function (value) { console.log(value) }}
16
+ defaultValue={['football', 'volleyball']}
17
+ description="Select your favorite sports"
18
+ >
19
+ <Checkbox label="Football" value="football" />
20
+ <Checkbox label="Basketball" value="basketball" />
21
+ <Checkbox label="Volleyball" value="volleyball" />
22
+ <Checkbox label="Other" value="other" />
23
+ </CheckboxGroup>
24
+ <CheckboxGroup name="sports" size="small"
25
+ layout="columns"
26
+ onChange={function (value) { console.log(value) }}
27
+ defaultValue={['football', 'volleyball']}
28
+ description="Select your favorite sports"
29
+ >
30
+ <Checkbox label="Football" value="football" />
31
+ <Checkbox label="Basketball" value="basketball" />
32
+ <Checkbox label="Volleyball" value="volleyball" />
33
+ <Checkbox label="Other" value="other" />
34
+ </CheckboxGroup>
35
+ </FormFieldGroup>
36
+ ```
37
+
38
+ The `toggle` variant with `layout` prop set to `inline` and an error message:
39
+
40
+ ```js
41
+ ---
42
+ type: example
43
+ ---
44
+ <CheckboxGroup
45
+ name="sports2"
46
+ layout="inline"
47
+ messages={[
48
+ { text: 'Invalid name', type: 'error' }
49
+ ]}
50
+ onChange={function (value) { console.log(value) }}
51
+ defaultValue={['soccer', 'volleyball']}
52
+ description="I wish to receive score alerts for"
53
+ >
54
+ <Checkbox label="Football" value="football" variant="toggle" />
55
+ <Checkbox label="Basketball" value="basketball" variant="toggle" />
56
+ <Checkbox label="Volleyball" value="volleyball" variant="toggle" />
57
+ <Checkbox label="Soccer" value="soccer" variant="toggle" />
58
+ </CheckboxGroup>
59
+ ```
60
+
61
+ You can set disable/readonly on a group and it works much the same way as a RadioInputGroup.
62
+
63
+ A `disabled` CheckboxGroup:
64
+
65
+ ```js
66
+ ---
67
+ type: example
68
+ ---
69
+ <CheckboxGroup
70
+ name="sports4"
71
+ onChange={function (value) { console.log(value) }}
72
+ defaultValue={['soccer', 'volleyball']}
73
+ description="I wish to receive score alerts for"
74
+ disabled
75
+ >
76
+ <Checkbox label="Football" value="football" variant="toggle" />
77
+ <Checkbox label="Basketball" value="basketball" variant="toggle" />
78
+ <Checkbox label="Volleyball" value="volleyball" variant="toggle" />
79
+ <Checkbox label="Soccer" value="soccer" variant="toggle" />
80
+ </CheckboxGroup>
81
+ ```
82
+
83
+ ### Guidelines
84
+
85
+ ```js
86
+ ---
87
+ type: embed
88
+ ---
89
+ <Guidelines>
90
+ <Figure recommendation="yes" title="Do">
91
+ <Figure.Item>Align to the left side of the label</Figure.Item>
92
+ <Figure.Item>Use when multiple selections are allowed</Figure.Item>
93
+ <Figure.Item>Use to save space from toggles</Figure.Item>
94
+ <Figure.Item>Stack vertically if there is more than two options to select</Figure.Item>
95
+ </Figure>
96
+ <Figure recommendation="no" title="Don't">
97
+ <Figure.Item>Run more than two checkboxes horizontally</Figure.Item>
98
+ </Figure>
99
+ </Guidelines>
100
+ ```
101
+
102
+ ```js
103
+ ---
104
+ type: embed
105
+ ---
106
+ <Guidelines>
107
+ <Figure recommendation="a11y" title="Accessibility">
108
+ <Figure.Item>Ensure CheckboxGroups are labeled correctly so screen readers announce what the group of checkboxes are used for</Figure.Item>
109
+ </Figure>
110
+ </Guidelines>
111
+ ```
@@ -0,0 +1,157 @@
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 { Children, Component } from 'react'
26
+
27
+ import { FormFieldGroup } from '@instructure/ui-form-field/latest'
28
+ import {
29
+ matchComponentTypes,
30
+ safeCloneElement,
31
+ pickProps,
32
+ omitProps,
33
+ withDeterministicId
34
+ } from '@instructure/ui-react-utils'
35
+
36
+ import { Checkbox } from '../../Checkbox/v2'
37
+
38
+ import { allowedProps } from './props'
39
+ import type {
40
+ CheckboxGroupProps,
41
+ CheckboxGroupState,
42
+ CheckboxChild
43
+ } from './props'
44
+
45
+ /**
46
+ ---
47
+ category: components
48
+ ---
49
+ **/
50
+
51
+ @withDeterministicId()
52
+ class CheckboxGroup extends Component<CheckboxGroupProps, CheckboxGroupState> {
53
+ static readonly componentId = 'CheckboxGroup'
54
+
55
+ static allowedProps = allowedProps
56
+ static defaultProps = {
57
+ disabled: false,
58
+ readOnly: false,
59
+ size: 'medium',
60
+ layout: 'stacked',
61
+ children: null
62
+ }
63
+
64
+ constructor(props: CheckboxGroupProps) {
65
+ super(props)
66
+
67
+ if (typeof props.value === 'undefined') {
68
+ this.state = {
69
+ value: props.defaultValue || []
70
+ }
71
+ }
72
+
73
+ this._messagesId = props.deterministicId!()
74
+ }
75
+ private readonly _messagesId: string
76
+ ref: Element | null = null
77
+
78
+ handleRef = (el: Element | null) => {
79
+ this.ref = el
80
+ }
81
+
82
+ get hasMessages() {
83
+ return this.props.messages && this.props.messages.length > 0
84
+ }
85
+
86
+ handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
87
+ const newValue = this.value
88
+
89
+ if (this.props.disabled || this.props.readOnly) {
90
+ e.preventDefault()
91
+ return
92
+ }
93
+
94
+ if (e.target.checked) {
95
+ newValue.push(e.target.value)
96
+ } else {
97
+ newValue.splice(newValue.indexOf(e.target.value), 1)
98
+ }
99
+
100
+ if (typeof this.props.value === 'undefined') {
101
+ this.setState({ value: newValue })
102
+ }
103
+
104
+ if (typeof this.props.onChange === 'function') {
105
+ this.props.onChange(newValue)
106
+ }
107
+ }
108
+
109
+ get value() {
110
+ return typeof this.props.value === 'undefined'
111
+ ? [...this.state.value]
112
+ : [...this.props.value]
113
+ }
114
+
115
+ renderChildren() {
116
+ const { children, name, size, disabled, readOnly } = this.props
117
+
118
+ return Children.map(children, (child) => {
119
+ if (matchComponentTypes<CheckboxChild>(child, [Checkbox])) {
120
+ return safeCloneElement(child, {
121
+ key: `${child.props.name}`,
122
+ name,
123
+ label: child.props.label,
124
+ disabled: disabled || child.props.disabled,
125
+ readOnly: readOnly || child.props.readOnly,
126
+ size,
127
+ checked: this.value.indexOf(child.props.value!) > -1,
128
+ onChange: this.handleChange,
129
+ width: child.props.width || 'auto',
130
+ 'aria-describedby': this.hasMessages ? this._messagesId : undefined
131
+ })
132
+ } else {
133
+ return child
134
+ }
135
+ })
136
+ }
137
+
138
+ render() {
139
+ return (
140
+ <FormFieldGroup
141
+ {...omitProps(this.props, CheckboxGroup.allowedProps)}
142
+ {...pickProps(this.props, FormFieldGroup.allowedProps)}
143
+ description={this.props.description}
144
+ rowSpacing="small"
145
+ vAlign="top"
146
+ messagesId={this._messagesId}
147
+ elementRef={this.handleRef}
148
+ data-cid="CheckboxGroup"
149
+ >
150
+ {this.renderChildren()}
151
+ </FormFieldGroup>
152
+ )
153
+ }
154
+ }
155
+
156
+ export default CheckboxGroup
157
+ export { CheckboxGroup }
@@ -0,0 +1,77 @@
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 InputHTMLAttributes } from 'react'
26
+ import type { FormMessage } from '@instructure/ui-form-field/latest'
27
+ import type { OtherHTMLAttributes } from '@instructure/shared-types'
28
+ import type { WithDeterministicIdProps } from '@instructure/ui-react-utils'
29
+
30
+ import { Checkbox } from '../../Checkbox/v2'
31
+ import type { CheckboxProps } from '../../Checkbox/v2/props'
32
+
33
+ type CheckboxChild = React.ComponentElement<CheckboxProps, Checkbox>
34
+
35
+ type CheckboxGroupOwnProps = {
36
+ children?: CheckboxChild[] // TODO: oneOf([Checkbox])
37
+ name: string
38
+ description: React.ReactNode
39
+ defaultValue?: (string | number)[]
40
+ value?: (string | number)[] // TODO: controllable(PropTypes.array)
41
+ onChange?: (value: (string | number)[]) => void
42
+ disabled?: boolean
43
+ readOnly?: boolean
44
+ messages?: FormMessage[]
45
+ size?: 'small' | 'medium' | 'large'
46
+ layout?: 'stacked' | 'columns' | 'inline'
47
+ }
48
+
49
+ type PropKeys = keyof CheckboxGroupOwnProps
50
+
51
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
52
+
53
+ type CheckboxGroupProps = CheckboxGroupOwnProps &
54
+ OtherHTMLAttributes<
55
+ CheckboxGroupOwnProps,
56
+ InputHTMLAttributes<CheckboxGroupOwnProps & Element>
57
+ > &
58
+ WithDeterministicIdProps
59
+ const allowedProps: AllowedPropKeys = [
60
+ 'name',
61
+ 'description',
62
+ 'defaultValue',
63
+ 'value',
64
+ 'onChange',
65
+ 'disabled',
66
+ 'readOnly',
67
+ 'messages',
68
+ 'children',
69
+ 'size',
70
+ 'layout'
71
+ ]
72
+
73
+ type CheckboxGroupState = {
74
+ value: (string | number)[]
75
+ }
76
+ export type { CheckboxGroupProps, CheckboxGroupState, CheckboxChild }
77
+ export { allowedProps }
@@ -21,10 +21,10 @@
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'
25
- export { CheckboxGroup } from './CheckboxGroup'
24
+ export { Checkbox, CheckboxFacade, ToggleFacade } from '../Checkbox/v1'
25
+ export { CheckboxGroup } from '../CheckboxGroup/v1'
26
26
 
27
- export type { CheckboxProps } from './Checkbox/props'
28
- export type { CheckboxFacadeProps } from './Checkbox/CheckboxFacade/props'
29
- export type { ToggleFacadeProps } from './Checkbox/ToggleFacade/props'
30
- export type { CheckboxGroupProps } from './CheckboxGroup/props'
27
+ export type { CheckboxProps } from '../Checkbox/v1/props'
28
+ export type { CheckboxFacadeProps } from '../Checkbox/v1/CheckboxFacade/props'
29
+ export type { ToggleFacadeProps } from '../Checkbox/v1/ToggleFacade/props'
30
+ export type { CheckboxGroupProps } from '../CheckboxGroup/v1/props'
@@ -0,0 +1,30 @@
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'
25
+ export { CheckboxGroup } from '../CheckboxGroup/v2'
26
+
27
+ export type { CheckboxProps } from '../Checkbox/v2/props'
28
+ export type { CheckboxFacadeProps } from '../Checkbox/v2/CheckboxFacade/props'
29
+ export type { ToggleFacadeProps } from '../Checkbox/v2/ToggleFacade/props'
30
+ export type { CheckboxGroupProps } from '../CheckboxGroup/v2/props'