@instructure/ui-checkbox 8.8.1-snapshot.3 → 8.9.0

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 (66) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/es/Checkbox/CheckboxFacade/index.js +5 -20
  3. package/{src/CheckboxGroup/types.ts → es/Checkbox/CheckboxFacade/props.js} +14 -15
  4. package/es/Checkbox/ToggleFacade/index.js +9 -21
  5. package/{src/Checkbox/CheckboxFacade/types.ts → es/Checkbox/ToggleFacade/props.js} +12 -10
  6. package/es/Checkbox/index.js +7 -72
  7. package/es/Checkbox/props.js +78 -0
  8. package/es/CheckboxGroup/index.js +3 -43
  9. package/es/CheckboxGroup/props.js +65 -0
  10. package/lib/Checkbox/CheckboxFacade/index.js +6 -21
  11. package/lib/Checkbox/CheckboxFacade/props.js +49 -0
  12. package/lib/Checkbox/ToggleFacade/index.js +10 -22
  13. package/{src/Checkbox/types.ts → lib/Checkbox/ToggleFacade/props.js} +23 -26
  14. package/lib/Checkbox/index.js +7 -75
  15. package/lib/Checkbox/props.js +91 -0
  16. package/lib/CheckboxGroup/index.js +3 -50
  17. package/lib/CheckboxGroup/props.js +81 -0
  18. package/package.json +20 -21
  19. package/src/Checkbox/CheckboxFacade/index.tsx +8 -21
  20. package/src/Checkbox/CheckboxFacade/props.ts +67 -0
  21. package/src/Checkbox/CheckboxFacade/styles.ts +1 -1
  22. package/src/Checkbox/ToggleFacade/index.tsx +12 -23
  23. package/src/Checkbox/ToggleFacade/{types.ts → props.ts} +36 -3
  24. package/src/Checkbox/ToggleFacade/styles.ts +1 -1
  25. package/src/Checkbox/index.tsx +10 -68
  26. package/src/Checkbox/props.ts +129 -0
  27. package/src/Checkbox/styles.ts +1 -1
  28. package/src/CheckboxGroup/index.tsx +6 -43
  29. package/src/CheckboxGroup/props.ts +106 -0
  30. package/src/index.ts +4 -4
  31. package/types/Checkbox/CheckboxFacade/index.d.ts +17 -15
  32. package/types/Checkbox/CheckboxFacade/index.d.ts.map +1 -1
  33. package/types/Checkbox/CheckboxFacade/props.d.ts +19 -0
  34. package/types/Checkbox/CheckboxFacade/props.d.ts.map +1 -0
  35. package/types/Checkbox/CheckboxFacade/styles.d.ts +1 -1
  36. package/types/Checkbox/ToggleFacade/index.d.ts +19 -13
  37. package/types/Checkbox/ToggleFacade/index.d.ts.map +1 -1
  38. package/types/Checkbox/ToggleFacade/props.d.ts +20 -0
  39. package/types/Checkbox/ToggleFacade/props.d.ts.map +1 -0
  40. package/types/Checkbox/ToggleFacade/styles.d.ts +1 -1
  41. package/types/Checkbox/index.d.ts +43 -60
  42. package/types/Checkbox/index.d.ts.map +1 -1
  43. package/types/Checkbox/{types.d.ts → props.d.ts} +11 -4
  44. package/types/Checkbox/props.d.ts.map +1 -0
  45. package/types/Checkbox/styles.d.ts +1 -1
  46. package/types/CheckboxGroup/index.d.ts +28 -44
  47. package/types/CheckboxGroup/index.d.ts.map +1 -1
  48. package/types/CheckboxGroup/props.d.ts +24 -0
  49. package/types/CheckboxGroup/props.d.ts.map +1 -0
  50. package/types/index.d.ts +4 -4
  51. package/LICENSE.md +0 -27
  52. package/es/Checkbox/CheckboxFacade/types.js +0 -1
  53. package/es/Checkbox/ToggleFacade/types.js +0 -1
  54. package/es/Checkbox/types.js +0 -1
  55. package/es/CheckboxGroup/types.js +0 -1
  56. package/lib/Checkbox/CheckboxFacade/types.js +0 -1
  57. package/lib/Checkbox/ToggleFacade/types.js +0 -1
  58. package/lib/Checkbox/types.js +0 -1
  59. package/lib/CheckboxGroup/types.js +0 -1
  60. package/types/Checkbox/CheckboxFacade/types.d.ts +0 -10
  61. package/types/Checkbox/CheckboxFacade/types.d.ts.map +0 -1
  62. package/types/Checkbox/ToggleFacade/types.d.ts +0 -11
  63. package/types/Checkbox/ToggleFacade/types.d.ts.map +0 -1
  64. package/types/Checkbox/types.d.ts.map +0 -1
  65. package/types/CheckboxGroup/types.d.ts +0 -15
  66. package/types/CheckboxGroup/types.d.ts.map +0 -1
@@ -23,7 +23,7 @@
23
23
  */
24
24
 
25
25
  import { ToggleFacadeTheme } from '@instructure/shared-types'
26
- import { ToggleFacadeProps } from './types'
26
+ import { ToggleFacadeProps } from './props'
27
27
 
28
28
  /**
29
29
  * ---
@@ -24,11 +24,9 @@
24
24
 
25
25
  /** @jsx jsx */
26
26
  import { Component } from 'react'
27
- import PropTypes from 'prop-types'
28
27
  import keycode from 'keycode'
29
28
 
30
- import { controllable } from '@instructure/ui-prop-types'
31
- import { FormPropTypes, FormFieldMessages } from '@instructure/ui-form-field'
29
+ import { FormFieldMessages } from '@instructure/ui-form-field'
32
30
  import { createChainedFunction } from '@instructure/ui-utils'
33
31
  import { logError as error } from '@instructure/console'
34
32
  import { uid } from '@instructure/uid'
@@ -43,7 +41,9 @@ import { CheckboxFacade } from './CheckboxFacade'
43
41
  import { ToggleFacade } from './ToggleFacade'
44
42
 
45
43
  import generateStyle from './styles'
46
- import { CheckboxProps } from './types'
44
+
45
+ import { propTypes, allowedProps } from './props'
46
+ import type { CheckboxProps } from './props'
47
47
 
48
48
  /**
49
49
  ---
@@ -57,54 +57,8 @@ tags: toggle, switch
57
57
  class Checkbox extends Component<CheckboxProps> {
58
58
  static readonly componentId = 'Checkbox'
59
59
 
60
- static propTypes = {
61
- // eslint-disable-next-line react/require-default-props
62
- makeStyles: PropTypes.func,
63
- // eslint-disable-next-line react/require-default-props
64
- styles: PropTypes.object,
65
- label: PropTypes.node.isRequired,
66
- id: PropTypes.string,
67
- value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
68
- /**
69
- * object with shape: `{
70
- * text: PropTypes.string,
71
- * type: PropTypes.oneOf(['error', 'hint', 'success', 'screenreader-only'])
72
- * }`
73
- */
74
- messages: PropTypes.arrayOf(FormPropTypes.message),
75
- /* whether to set the input to checked or not on initial render */
76
- defaultChecked: PropTypes.bool,
77
- /**
78
- * whether the input is checked or not (must be accompanied by an `onChange` prop)
79
- */
80
- checked: controllable(PropTypes.bool, 'onChange', 'defaultChecked'),
81
- /**
82
- * when used with the `checked` prop, the component will not control its own state
83
- */
84
- onChange: PropTypes.func,
85
- onKeyDown: PropTypes.func,
86
- onFocus: PropTypes.func,
87
- onBlur: PropTypes.func,
88
- onMouseOver: PropTypes.func,
89
- onMouseOut: PropTypes.func,
90
- /**
91
- * Whether or not to disable the checkbox
92
- */
93
- disabled: PropTypes.bool,
94
- /**
95
- * Works just like disabled but keeps the same styles as if it were active
96
- */
97
- readOnly: PropTypes.bool,
98
- /**
99
- * Visual state showing that child checkboxes are a combination of checked and unchecked
100
- */
101
- indeterminate: PropTypes.bool,
102
- size: PropTypes.oneOf(['small', 'medium', 'large']),
103
- variant: PropTypes.oneOf(['simple', 'toggle']),
104
- inline: PropTypes.bool,
105
- labelPlacement: PropTypes.oneOf(['top', 'start', 'end'])
106
- }
107
-
60
+ static propTypes = propTypes
61
+ static allowedProps = allowedProps
108
62
  static defaultProps = {
109
63
  size: 'medium',
110
64
  variant: 'simple',
@@ -112,17 +66,6 @@ class Checkbox extends Component<CheckboxProps> {
112
66
  inline: false,
113
67
  indeterminate: false,
114
68
  readOnly: false,
115
- onChange: undefined,
116
- onKeyDown: undefined,
117
- onFocus: undefined,
118
- onBlur: undefined,
119
- onMouseOut: undefined,
120
- onMouseOver: undefined,
121
- checked: undefined,
122
- defaultChecked: undefined,
123
- messages: undefined,
124
- id: undefined,
125
- value: undefined,
126
69
  labelPlacement: 'end'
127
70
  }
128
71
 
@@ -338,7 +281,7 @@ class Checkbox extends Component<CheckboxProps> {
338
281
 
339
282
  return (
340
283
  <div
341
- css={styles.checkbox}
284
+ css={styles?.checkbox}
342
285
  onMouseOver={createChainedFunction(onMouseOver, this.handleMouseOver)}
343
286
  onMouseOut={createChainedFunction(onMouseOut, this.handleMouseOut)}
344
287
  >
@@ -352,16 +295,15 @@ class Checkbox extends Component<CheckboxProps> {
352
295
  this._input = c
353
296
  }}
354
297
  disabled={disabled || readOnly}
355
- // @ts-expect-error ts-migrate(2322) FIXME: Type '"mixed" | null' is not assignable to type 'b... Remove this comment to see the full error message
356
- aria-checked={indeterminate ? 'mixed' : null}
357
- css={styles.input}
298
+ aria-checked={indeterminate ? 'mixed' : undefined}
299
+ css={styles?.input}
358
300
  onChange={this.handleChange}
359
301
  onKeyDown={createChainedFunction(onKeyDown, this.handleKeyDown)}
360
302
  onFocus={createChainedFunction(onFocus, this.handleFocus)}
361
303
  onBlur={createChainedFunction(onBlur, this.handleBlur)}
362
304
  checked={this.checked}
363
305
  />
364
- <label htmlFor={this.id} css={styles.control}>
306
+ <label htmlFor={this.id} css={styles?.control}>
365
307
  {this.renderFacade()}
366
308
  {this.renderMessages()}
367
309
  </label>
@@ -0,0 +1,129 @@
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 PropTypes from 'prop-types'
26
+
27
+ import { FormPropTypes } from '@instructure/ui-form-field'
28
+ import { controllable } from '@instructure/ui-prop-types'
29
+
30
+ import type { FormMessage } from '@instructure/ui-form-field'
31
+ import type { PropValidators } from '@instructure/shared-types'
32
+ import type { WithStyleProps } from '@instructure/emotion'
33
+
34
+ type CheckboxOwnProps = {
35
+ label: React.ReactNode
36
+ id?: string
37
+ value?: string | number
38
+ messages?: FormMessage[]
39
+ defaultChecked?: boolean
40
+ checked?: any // TODO: controllable(PropTypes.bool, 'onChange', 'defaultChecked')
41
+ onChange?: (...args: any[]) => any
42
+ onKeyDown?: (...args: any[]) => any
43
+ onFocus?: (...args: any[]) => any
44
+ onBlur?: (...args: any[]) => any
45
+ onMouseOver?: (...args: any[]) => any
46
+ onMouseOut?: (...args: any[]) => any
47
+ disabled?: boolean
48
+ readOnly?: boolean
49
+ indeterminate?: boolean
50
+ size?: 'small' | 'medium' | 'large'
51
+ variant?: 'simple' | 'toggle'
52
+ inline?: boolean
53
+ labelPlacement?: 'top' | 'start' | 'end'
54
+ }
55
+
56
+ type PropKeys = keyof CheckboxOwnProps
57
+
58
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
59
+
60
+ type CheckboxProps = CheckboxOwnProps & WithStyleProps
61
+
62
+ const propTypes: PropValidators<PropKeys> = {
63
+ label: PropTypes.node.isRequired,
64
+ id: PropTypes.string,
65
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
66
+ /**
67
+ * object with shape: `{
68
+ * text: PropTypes.string,
69
+ * type: PropTypes.oneOf(['error', 'hint', 'success', 'screenreader-only'])
70
+ * }`
71
+ */
72
+ messages: PropTypes.arrayOf(FormPropTypes.message),
73
+ /* whether to set the input to checked or not on initial render */
74
+ defaultChecked: PropTypes.bool,
75
+ /**
76
+ * whether the input is checked or not (must be accompanied by an `onChange` prop)
77
+ */
78
+ checked: controllable(PropTypes.bool, 'onChange', 'defaultChecked'),
79
+ /**
80
+ * when used with the `checked` prop, the component will not control its own state
81
+ */
82
+ onChange: PropTypes.func,
83
+ onKeyDown: PropTypes.func,
84
+ onFocus: PropTypes.func,
85
+ onBlur: PropTypes.func,
86
+ onMouseOver: PropTypes.func,
87
+ onMouseOut: PropTypes.func,
88
+ /**
89
+ * Whether or not to disable the checkbox
90
+ */
91
+ disabled: PropTypes.bool,
92
+ /**
93
+ * Works just like disabled but keeps the same styles as if it were active
94
+ */
95
+ readOnly: PropTypes.bool,
96
+ /**
97
+ * Visual state showing that child checkboxes are a combination of checked and unchecked
98
+ */
99
+ indeterminate: PropTypes.bool,
100
+ size: PropTypes.oneOf(['small', 'medium', 'large']),
101
+ variant: PropTypes.oneOf(['simple', 'toggle']),
102
+ inline: PropTypes.bool,
103
+ labelPlacement: PropTypes.oneOf(['top', 'start', 'end'])
104
+ }
105
+
106
+ const allowedProps: AllowedPropKeys = [
107
+ 'label',
108
+ 'id',
109
+ 'value',
110
+ 'messages',
111
+ 'defaultChecked',
112
+ 'checked',
113
+ 'onChange',
114
+ 'onKeyDown',
115
+ 'onFocus',
116
+ 'onBlur',
117
+ 'onMouseOver',
118
+ 'onMouseOut',
119
+ 'disabled',
120
+ 'readOnly',
121
+ 'indeterminate',
122
+ 'size',
123
+ 'variant',
124
+ 'inline',
125
+ 'labelPlacement'
126
+ ]
127
+
128
+ export type { CheckboxProps }
129
+ export { propTypes, allowedProps }
@@ -22,7 +22,7 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- import { CheckboxProps } from './types'
25
+ import { CheckboxProps } from './props'
26
26
 
27
27
  /**
28
28
  * ---
@@ -23,13 +23,8 @@
23
23
  */
24
24
 
25
25
  import React, { Children, Component, ReactElement } from 'react'
26
- import PropTypes from 'prop-types'
27
26
 
28
- import {
29
- controllable,
30
- Children as ChildrenPropTypes
31
- } from '@instructure/ui-prop-types'
32
- import { FormPropTypes, FormFieldGroup } from '@instructure/ui-form-field'
27
+ import { FormFieldGroup } from '@instructure/ui-form-field'
33
28
  import { uid } from '@instructure/uid'
34
29
  import {
35
30
  matchComponentTypes,
@@ -40,7 +35,9 @@ import {
40
35
  import { testable } from '@instructure/ui-testable'
41
36
 
42
37
  import { Checkbox } from '../Checkbox'
43
- import { CheckboxGroupProps } from './types'
38
+
39
+ import { propTypes, allowedProps } from './props'
40
+ import type { CheckboxGroupProps } from './props'
44
41
 
45
42
  /**
46
43
  ---
@@ -52,47 +49,13 @@ category: components
52
49
  class CheckboxGroup extends Component<CheckboxGroupProps> {
53
50
  static readonly componentId = 'CheckboxGroup'
54
51
 
55
- static propTypes = {
56
- name: PropTypes.string.isRequired,
57
- description: PropTypes.node.isRequired,
58
- /**
59
- * value to set on initial render
60
- */
61
- defaultValue: PropTypes.array,
62
- /**
63
- * the selected values (must be accompanied by an `onChange` prop)
64
- */
65
- value: controllable(PropTypes.array),
66
- /**
67
- * when used with the `value` prop, the component will not control its own state
68
- */
69
- onChange: PropTypes.func,
70
- disabled: PropTypes.bool,
71
- readOnly: PropTypes.bool,
72
- /**
73
- * object with shape: `{
74
- text: PropTypes.string,
75
- type: PropTypes.oneOf(['error', 'hint', 'success', 'screenreader-only'])
76
- }`
77
- */
78
- messages: PropTypes.arrayOf(FormPropTypes.message),
79
- /**
80
- * children of type `Checkbox`
81
- */
82
- children: ChildrenPropTypes.oneOf([Checkbox]),
83
- size: PropTypes.oneOf(['small', 'medium', 'large']),
84
- layout: PropTypes.oneOf(['stacked', 'columns', 'inline'])
85
- }
86
-
52
+ static propTypes = propTypes
53
+ static allowedProps = allowedProps
87
54
  static defaultProps = {
88
55
  disabled: false,
89
56
  readOnly: false,
90
57
  size: 'medium',
91
58
  layout: 'stacked',
92
- defaultValue: undefined,
93
- messages: undefined,
94
- value: undefined,
95
- onChange: undefined,
96
59
  children: null
97
60
  }
98
61
 
@@ -0,0 +1,106 @@
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 React from 'react'
26
+ import PropTypes from 'prop-types'
27
+
28
+ import { FormPropTypes } from '@instructure/ui-form-field'
29
+ import {
30
+ controllable,
31
+ Children as ChildrenPropTypes
32
+ } from '@instructure/ui-prop-types'
33
+
34
+ import type { FormMessage } from '@instructure/ui-form-field'
35
+ import type { PropValidators } from '@instructure/shared-types'
36
+
37
+ import { Checkbox } from '../Checkbox'
38
+
39
+ type CheckboxGroupOwnProps = {
40
+ children?: React.ReactNode // TODO: oneOf([Checkbox])
41
+ name: string
42
+ description: React.ReactNode
43
+ defaultValue?: any[]
44
+ value?: any // TODO: controllable(PropTypes.array)
45
+ onChange?: (...args: any[]) => any
46
+ disabled?: boolean
47
+ readOnly?: boolean
48
+ messages?: FormMessage[]
49
+ size?: 'small' | 'medium' | 'large'
50
+ layout?: 'stacked' | 'columns' | 'inline'
51
+ }
52
+
53
+ type PropKeys = keyof CheckboxGroupOwnProps
54
+
55
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
56
+
57
+ type CheckboxGroupProps = CheckboxGroupOwnProps
58
+
59
+ const propTypes: PropValidators<PropKeys> = {
60
+ name: PropTypes.string.isRequired,
61
+ description: PropTypes.node.isRequired,
62
+ /**
63
+ * value to set on initial render
64
+ */
65
+ defaultValue: PropTypes.array,
66
+ /**
67
+ * the selected values (must be accompanied by an `onChange` prop)
68
+ */
69
+ value: controllable(PropTypes.array),
70
+ /**
71
+ * when used with the `value` prop, the component will not control its own state
72
+ */
73
+ onChange: PropTypes.func,
74
+ disabled: PropTypes.bool,
75
+ readOnly: PropTypes.bool,
76
+ /**
77
+ * object with shape: `{
78
+ text: PropTypes.string,
79
+ type: PropTypes.oneOf(['error', 'hint', 'success', 'screenreader-only'])
80
+ }`
81
+ */
82
+ messages: PropTypes.arrayOf(FormPropTypes.message),
83
+ /**
84
+ * children of type `Checkbox`
85
+ */
86
+ children: ChildrenPropTypes.oneOf([Checkbox]),
87
+ size: PropTypes.oneOf(['small', 'medium', 'large']),
88
+ layout: PropTypes.oneOf(['stacked', 'columns', 'inline'])
89
+ }
90
+
91
+ const allowedProps: AllowedPropKeys = [
92
+ 'name',
93
+ 'description',
94
+ 'defaultValue',
95
+ 'value',
96
+ 'onChange',
97
+ 'disabled',
98
+ 'readOnly',
99
+ 'messages',
100
+ 'children',
101
+ 'size',
102
+ 'layout'
103
+ ]
104
+
105
+ export type { CheckboxGroupProps }
106
+ export { propTypes, allowedProps }