@ohos-ports/instructure-ui-toggle-details 11.7.5-beta.1

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 (91) hide show
  1. package/CHANGELOG.md +1323 -0
  2. package/LICENSE.md +28 -0
  3. package/README.md +42 -0
  4. package/es/ToggleDetails/v1/index.js +177 -0
  5. package/es/ToggleDetails/v1/props.js +26 -0
  6. package/es/ToggleDetails/v1/styles.js +196 -0
  7. package/es/ToggleDetails/v1/theme.js +75 -0
  8. package/es/ToggleDetails/v2/index.js +181 -0
  9. package/es/ToggleDetails/v2/props.js +26 -0
  10. package/es/ToggleDetails/v2/styles.js +188 -0
  11. package/es/ToggleGroup/v1/index.js +172 -0
  12. package/es/ToggleGroup/v1/props.js +26 -0
  13. package/es/ToggleGroup/v1/styles.js +40 -0
  14. package/es/ToggleGroup/v1/theme.js +41 -0
  15. package/es/ToggleGroup/v2/index.js +178 -0
  16. package/es/ToggleGroup/v2/props.js +26 -0
  17. package/es/ToggleGroup/v2/styles.js +40 -0
  18. package/es/exports/a.js +26 -0
  19. package/es/exports/b.js +26 -0
  20. package/lib/ToggleDetails/v1/index.js +184 -0
  21. package/lib/ToggleDetails/v1/props.js +31 -0
  22. package/lib/ToggleDetails/v1/styles.js +202 -0
  23. package/lib/ToggleDetails/v1/theme.js +81 -0
  24. package/lib/ToggleDetails/v2/index.js +187 -0
  25. package/lib/ToggleDetails/v2/props.js +31 -0
  26. package/lib/ToggleDetails/v2/styles.js +194 -0
  27. package/lib/ToggleGroup/v1/index.js +180 -0
  28. package/lib/ToggleGroup/v1/props.js +31 -0
  29. package/lib/ToggleGroup/v1/styles.js +46 -0
  30. package/lib/ToggleGroup/v1/theme.js +47 -0
  31. package/lib/ToggleGroup/v2/index.js +185 -0
  32. package/lib/ToggleGroup/v2/props.js +31 -0
  33. package/lib/ToggleGroup/v2/styles.js +46 -0
  34. package/lib/exports/a.js +19 -0
  35. package/lib/exports/b.js +19 -0
  36. package/lib/package.json +1 -0
  37. package/package.json +94 -0
  38. package/src/ToggleDetails/v1/README.md +233 -0
  39. package/src/ToggleDetails/v1/index.tsx +204 -0
  40. package/src/ToggleDetails/v1/props.ts +114 -0
  41. package/src/ToggleDetails/v1/styles.ts +190 -0
  42. package/src/ToggleDetails/v1/theme.ts +80 -0
  43. package/src/ToggleDetails/v2/README.md +233 -0
  44. package/src/ToggleDetails/v2/index.tsx +206 -0
  45. package/src/ToggleDetails/v2/props.ts +115 -0
  46. package/src/ToggleDetails/v2/styles.ts +188 -0
  47. package/src/ToggleGroup/v1/README.md +93 -0
  48. package/src/ToggleGroup/v1/index.tsx +206 -0
  49. package/src/ToggleGroup/v1/props.ts +115 -0
  50. package/src/ToggleGroup/v1/styles.ts +47 -0
  51. package/src/ToggleGroup/v1/theme.ts +43 -0
  52. package/src/ToggleGroup/v2/README.md +93 -0
  53. package/src/ToggleGroup/v2/index.tsx +214 -0
  54. package/src/ToggleGroup/v2/props.ts +115 -0
  55. package/src/ToggleGroup/v2/styles.ts +47 -0
  56. package/src/exports/a.ts +29 -0
  57. package/src/exports/b.ts +29 -0
  58. package/tsconfig.build.json +26 -0
  59. package/tsconfig.json +4 -0
  60. package/types/ToggleDetails/v1/index.d.ts +56 -0
  61. package/types/ToggleDetails/v1/index.d.ts.map +1 -0
  62. package/types/ToggleDetails/v1/props.d.ts +55 -0
  63. package/types/ToggleDetails/v1/props.d.ts.map +1 -0
  64. package/types/ToggleDetails/v1/styles.d.ts +15 -0
  65. package/types/ToggleDetails/v1/styles.d.ts.map +1 -0
  66. package/types/ToggleDetails/v1/theme.d.ts +10 -0
  67. package/types/ToggleDetails/v1/theme.d.ts.map +1 -0
  68. package/types/ToggleDetails/v2/index.d.ts +55 -0
  69. package/types/ToggleDetails/v2/index.d.ts.map +1 -0
  70. package/types/ToggleDetails/v2/props.d.ts +56 -0
  71. package/types/ToggleDetails/v2/props.d.ts.map +1 -0
  72. package/types/ToggleDetails/v2/styles.d.ts +16 -0
  73. package/types/ToggleDetails/v2/styles.d.ts.map +1 -0
  74. package/types/ToggleGroup/v1/index.d.ts +55 -0
  75. package/types/ToggleGroup/v1/index.d.ts.map +1 -0
  76. package/types/ToggleGroup/v1/props.d.ts +65 -0
  77. package/types/ToggleGroup/v1/props.d.ts.map +1 -0
  78. package/types/ToggleGroup/v1/styles.d.ts +15 -0
  79. package/types/ToggleGroup/v1/styles.d.ts.map +1 -0
  80. package/types/ToggleGroup/v1/theme.d.ts +10 -0
  81. package/types/ToggleGroup/v1/theme.d.ts.map +1 -0
  82. package/types/ToggleGroup/v2/index.d.ts +54 -0
  83. package/types/ToggleGroup/v2/index.d.ts.map +1 -0
  84. package/types/ToggleGroup/v2/props.d.ts +66 -0
  85. package/types/ToggleGroup/v2/props.d.ts.map +1 -0
  86. package/types/ToggleGroup/v2/styles.d.ts +15 -0
  87. package/types/ToggleGroup/v2/styles.d.ts.map +1 -0
  88. package/types/exports/a.d.ts +5 -0
  89. package/types/exports/a.d.ts.map +1 -0
  90. package/types/exports/b.d.ts +5 -0
  91. package/types/exports/b.d.ts.map +1 -0
@@ -0,0 +1,115 @@
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
+
27
+ import {
28
+ AsElementType,
29
+ OtherHTMLAttributes,
30
+ Renderable,
31
+ ToggleGroupTheme
32
+ } from '@instructure/shared-types'
33
+
34
+ import type { WithStyleProps } from '@instructure/emotion'
35
+
36
+ type ToggleGroupOwnProps = {
37
+ /**
38
+ * the content to show and hide
39
+ */
40
+ children: React.ReactNode
41
+ /**
42
+ * the content area next to the toggle button
43
+ */
44
+ summary: React.ReactNode
45
+ /**
46
+ * provides a screenreader label for the toggle button
47
+ * (takes `expanded` as an argument if a function)
48
+ */
49
+ toggleLabel: React.ReactNode | ((expanded: boolean) => React.ReactNode)
50
+ /**
51
+ * the element type to render as
52
+ */
53
+ as?: AsElementType
54
+ /**
55
+ * provides a reference to the underlying html root element
56
+ */
57
+ elementRef?: (element: Element | null) => void
58
+ size?: 'small' | 'medium' | 'large'
59
+ /**
60
+ * Whether the content is expanded or hidden
61
+ */
62
+ expanded?: boolean // TODO: controllable(PropTypes.bool, 'onToggle', 'defaultExpanded')
63
+ /**
64
+ * Whether the content is initially expanded or hidden (uncontrolled)
65
+ */
66
+ defaultExpanded?: boolean
67
+ /**
68
+ * Fired when the content display is toggled
69
+ */
70
+ onToggle?: (event: React.MouseEvent, expanded: boolean) => void
71
+ /**
72
+ * The icon displayed in the toggle button when the content is hidden
73
+ */
74
+ icon?: Renderable
75
+ /**
76
+ * The icon displayed in the toggle button when the content is showing
77
+ */
78
+ iconExpanded?: Renderable
79
+ /**
80
+ * Transition content into view
81
+ */
82
+ transition?: boolean
83
+ /**
84
+ * Toggle the border around the component
85
+ */
86
+ border?: boolean
87
+ }
88
+
89
+ type PropKeys = keyof ToggleGroupOwnProps
90
+
91
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
92
+
93
+ type ToggleGroupStyle = { borderColor: string }
94
+
95
+ type ToggleGroupProps = ToggleGroupOwnProps &
96
+ OtherHTMLAttributes<ToggleGroupOwnProps> &
97
+ WithStyleProps<ToggleGroupTheme, ToggleGroupStyle>
98
+ const allowedProps: AllowedPropKeys = [
99
+ 'children',
100
+ 'summary',
101
+ 'toggleLabel',
102
+ 'as',
103
+ 'elementRef',
104
+ 'size',
105
+ 'expanded',
106
+ 'defaultExpanded',
107
+ 'onToggle',
108
+ 'icon',
109
+ 'iconExpanded',
110
+ 'transition',
111
+ 'border'
112
+ ]
113
+
114
+ export type { ToggleGroupProps, ToggleGroupStyle }
115
+ export { allowedProps }
@@ -0,0 +1,47 @@
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 { ToggleGroupTheme } from '@instructure/shared-types'
26
+ import type { ToggleGroupProps, ToggleGroupStyle } from './props'
27
+
28
+ /**
29
+ * ---
30
+ * private: true
31
+ * ---
32
+ * Generates the style object from the theme and provided additional information
33
+ * @param {Object} componentTheme The theme variable object.
34
+ * @param {Object} props the props of the component, the style is applied to
35
+ * @param {Object} state the state of the component, the style is applied to
36
+ * @return {Object} The final style object, which will be used in the component
37
+ */
38
+ const generateStyle = (
39
+ componentTheme: ToggleGroupTheme,
40
+ _props: ToggleGroupProps
41
+ ): ToggleGroupStyle => {
42
+ return {
43
+ borderColor: componentTheme.borderColor
44
+ }
45
+ }
46
+
47
+ export default generateStyle
@@ -0,0 +1,43 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import type { Theme } from '@instructure/ui-themes'
26
+ import { ToggleGroupTheme } from '@instructure/shared-types'
27
+
28
+ /**
29
+ * Generates the theme object for the component from the theme and provided additional information
30
+ * @param {Object} theme The actual theme object.
31
+ * @return {Object} The final theme object with the overrides and component variables
32
+ */
33
+ const generateComponentTheme = (theme: Theme): ToggleGroupTheme => {
34
+ const { colors } = theme
35
+
36
+ const componentVariables: ToggleGroupTheme = {
37
+ borderColor: colors?.contrasts?.grey3045
38
+ }
39
+ return {
40
+ ...componentVariables
41
+ }
42
+ }
43
+ export default generateComponentTheme
@@ -0,0 +1,93 @@
1
+ ---
2
+ describes: ToggleGroup
3
+ ---
4
+
5
+ Performs the same function as [`ToggleDetails`](ToggleDetails), but with the summary separated from the
6
+ toggle button, and built in padding and borders around the summary and main content area.
7
+
8
+ ### Basic example
9
+
10
+ ```javascript
11
+ ---
12
+ type: example
13
+ ---
14
+ <ToggleGroup
15
+ toggleLabel="This is the toggle button label for screenreaders"
16
+ summary="This is the summary"
17
+ background="default"
18
+ >
19
+ <View display="block" padding="general.spaceMd">Here is the expanded content</View>
20
+ </ToggleGroup>
21
+ ```
22
+
23
+ ### More detailed examples
24
+
25
+ #### `defaultExpanded` to make the component `expanded` when it renders
26
+
27
+ ```javascript
28
+ ---
29
+ type: example
30
+ ---
31
+ <ToggleGroup
32
+ toggleLabel="This is the toggle button label for screenreaders"
33
+ summary="This is the summary"
34
+ defaultExpanded
35
+ >
36
+ <View display="block" padding="general.spaceMd">This content is expanded when the component renders</View>
37
+ </ToggleGroup>
38
+ ```
39
+
40
+ #### Passing in your own `icon` and `iconExpanded`
41
+
42
+ ```javascript
43
+ ---
44
+ type: example
45
+ ---
46
+ <ToggleGroup
47
+ toggleLabel="This is the toggle button label for screenreaders"
48
+ summary="This is the summary"
49
+ iconExpanded={XInstUIIcon}
50
+ icon={PlusInstUIIcon}
51
+ >
52
+ <View display="block" padding="general.spaceMd">Here is the expanded content</View>
53
+ </ToggleGroup>
54
+ ```
55
+
56
+ #### Disable default transition of details
57
+
58
+ ```javascript
59
+ ---
60
+ type: example
61
+ ---
62
+ <ToggleGroup
63
+ transition={false}
64
+ toggleLabel="This is the toggle button label for screenreaders"
65
+ summary="This is the summary"
66
+ >
67
+ <View display="block" padding="general.spaceMd">This content will not fade in</View>
68
+ </ToggleGroup>
69
+ ```
70
+
71
+ #### Disable default border if you want to nest ToggleGroups
72
+
73
+ ```javascript
74
+ ---
75
+ type: example
76
+ ---
77
+ <ToggleGroup
78
+ defaultExpanded
79
+ toggleLabel="This is the toggle button label for screenreaders"
80
+ summary={<Heading level="h3">Parent ToggleGroup</Heading>}
81
+ >
82
+ <ToggleGroup
83
+ size="small"
84
+ toggleLabel="This is the toggle button label for screenreaders"
85
+ summary="I am nested inside a parent ToggleGroup"
86
+ border={false}
87
+ >
88
+ <View display="block" padding="general.spaceMd">
89
+ This is the details section of the nested ToggleGroup
90
+ </View>
91
+ </ToggleGroup>
92
+ </ToggleGroup>
93
+ ```
@@ -0,0 +1,214 @@
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 { Component } from 'react'
26
+
27
+ import {
28
+ omitProps,
29
+ pickProps,
30
+ getElementType
31
+ } from '@instructure/ui-react-utils'
32
+ import { IconButton } from '@instructure/ui-buttons/latest'
33
+ import { Transition } from '@instructure/ui-motion'
34
+ import { Expandable } from '@instructure/ui-expandable/latest'
35
+ import type { ExpandableToggleProps } from '@instructure/ui-expandable/latest'
36
+ import { isActiveElement } from '@instructure/ui-dom-utils'
37
+ import { Flex } from '@instructure/ui-flex/latest'
38
+ import { View } from '@instructure/ui-view/latest'
39
+ import {
40
+ ChevronRightInstUIIcon,
41
+ ChevronDownInstUIIcon,
42
+ renderIconWithProps
43
+ } from '@instructure/ui-icons'
44
+ import type { ToggleGroupProps } from './props'
45
+ import { allowedProps } from './props.js'
46
+
47
+ import { withStyleNew } from '@instructure/emotion'
48
+
49
+ import generateStyle from './styles.js'
50
+
51
+ const toggleGroupSizeToIconSize = {
52
+ small: 'md',
53
+ medium: 'md',
54
+ large: 'lg'
55
+ } as const
56
+
57
+ /**
58
+ ---
59
+ category: components
60
+ ---
61
+ **/
62
+ @withStyleNew(generateStyle)
63
+ class ToggleGroup extends Component<ToggleGroupProps> {
64
+ static displayName = 'ToggleGroup'
65
+ static readonly componentId = 'ToggleGroup'
66
+
67
+ static allowedProps = allowedProps
68
+
69
+ static defaultProps = {
70
+ size: 'medium',
71
+ icon: ChevronRightInstUIIcon,
72
+ iconExpanded: ChevronDownInstUIIcon,
73
+ defaultExpanded: false,
74
+ transition: true,
75
+ as: 'span',
76
+ border: true
77
+ } as const
78
+
79
+ ref: Element | null = null
80
+ _button: HTMLElement | null = null
81
+ _shouldTransition = false
82
+
83
+ handleRef = (el: Element | null) => {
84
+ const { elementRef } = this.props
85
+
86
+ this.ref = el
87
+
88
+ if (typeof elementRef === 'function') {
89
+ elementRef(el)
90
+ }
91
+ }
92
+
93
+ handleButtonRef = (el: Element | null) => {
94
+ this._button = el as HTMLElement
95
+ }
96
+
97
+ get focused() {
98
+ return isActiveElement(this._button)
99
+ }
100
+
101
+ focus() {
102
+ this._button?.focus()
103
+ }
104
+
105
+ componentDidMount() {
106
+ this._shouldTransition = true
107
+ }
108
+
109
+ componentDidUpdate() {
110
+ this.props.makeStyles?.(this.state)
111
+ }
112
+
113
+ renderIcon(expanded: boolean) {
114
+ const Icon = expanded ? this.props.iconExpanded : this.props.icon
115
+ if (!Icon) return null
116
+
117
+ const iconSize = toggleGroupSizeToIconSize[this.props.size!]
118
+ return renderIconWithProps(Icon, iconSize, 'baseColor')
119
+ }
120
+
121
+ renderToggle(
122
+ toggleProps: ReturnType<ExpandableToggleProps>,
123
+ expanded: boolean
124
+ ) {
125
+ const { toggleLabel, size } = this.props
126
+ let label
127
+ if (typeof toggleLabel === 'function') {
128
+ label = toggleLabel(expanded)
129
+ } else {
130
+ label = toggleLabel
131
+ }
132
+
133
+ const props = { ...toggleProps } as Record<string, any>
134
+ return (
135
+ <IconButton
136
+ {...props}
137
+ withBackground={false}
138
+ withBorder={false}
139
+ size={size === 'large' ? 'medium' : 'small'}
140
+ elementRef={this.handleButtonRef}
141
+ screenReaderLabel={label}
142
+ >
143
+ {this.renderIcon(expanded)}
144
+ </IconButton>
145
+ )
146
+ }
147
+
148
+ renderDetails(detailsProps: { id: string }) {
149
+ const { styles } = this.props
150
+ return (
151
+ <View
152
+ {...detailsProps}
153
+ display="block"
154
+ borderWidth="small none none none"
155
+ borderColor={styles?.borderColor}
156
+ >
157
+ {this.props.transition && this._shouldTransition ? (
158
+ <Transition transitionOnMount in type="fade">
159
+ {this.props.children}
160
+ </Transition>
161
+ ) : (
162
+ this.props.children
163
+ )}
164
+ </View>
165
+ )
166
+ }
167
+
168
+ render() {
169
+ const Element = getElementType(ToggleGroup, this.props)
170
+ const { styles } = this.props
171
+ return (
172
+ <Expandable {...pickProps(this.props, Expandable.allowedProps)}>
173
+ {({ expanded, getToggleProps, getDetailsProps }) => {
174
+ return (
175
+ <View
176
+ {...omitProps(this.props, ToggleGroup.allowedProps)}
177
+ borderWidth={this.props.border ? 'small' : 'none'}
178
+ as={Element}
179
+ elementRef={this.handleRef}
180
+ display="block"
181
+ borderRadius="medium"
182
+ background="primary"
183
+ borderColor={styles?.borderColor}
184
+ data-cid="ToggleGroup"
185
+ >
186
+ <Flex
187
+ padding={
188
+ this.props.size === 'small'
189
+ ? 'x-small'
190
+ : 'small small small x-small'
191
+ }
192
+ >
193
+ <Flex.Item>
194
+ {this.renderToggle(getToggleProps(), expanded)}
195
+ </Flex.Item>
196
+ <Flex.Item shouldGrow shouldShrink padding="0 0 0 x-small">
197
+ {this.props.summary}
198
+ </Flex.Item>
199
+ </Flex>
200
+ {expanded ? (
201
+ this.renderDetails(getDetailsProps())
202
+ ) : (
203
+ <span {...getDetailsProps()} />
204
+ )}
205
+ </View>
206
+ )
207
+ }}
208
+ </Expandable>
209
+ )
210
+ }
211
+ }
212
+
213
+ export default ToggleGroup
214
+ export { ToggleGroup }
@@ -0,0 +1,115 @@
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
+
27
+ import {
28
+ AsElementType,
29
+ OtherHTMLAttributes,
30
+ Renderable
31
+ } from '@instructure/shared-types'
32
+
33
+ import type { WithStyleProps } from '@instructure/emotion'
34
+ import type { NewComponentTypes } from '@instructure/ui-themes'
35
+
36
+ type ToggleGroupOwnProps = {
37
+ /**
38
+ * the content to show and hide
39
+ */
40
+ children: React.ReactNode
41
+ /**
42
+ * the content area next to the toggle button
43
+ */
44
+ summary: React.ReactNode
45
+ /**
46
+ * provides a screenreader label for the toggle button
47
+ * (takes `expanded` as an argument if a function)
48
+ */
49
+ toggleLabel: React.ReactNode | ((expanded: boolean) => React.ReactNode)
50
+ /**
51
+ * the element type to render as
52
+ */
53
+ as?: AsElementType
54
+ /**
55
+ * provides a reference to the underlying html root element
56
+ */
57
+ elementRef?: (element: Element | null) => void
58
+ size?: 'small' | 'medium' | 'large'
59
+ /**
60
+ * Whether the content is expanded or hidden
61
+ */
62
+ expanded?: boolean // TODO: controllable(PropTypes.bool, 'onToggle', 'defaultExpanded')
63
+ /**
64
+ * Whether the content is initially expanded or hidden (uncontrolled)
65
+ */
66
+ defaultExpanded?: boolean
67
+ /**
68
+ * Fired when the content display is toggled
69
+ */
70
+ onToggle?: (event: React.MouseEvent, expanded: boolean) => void
71
+ /**
72
+ * The icon displayed in the toggle button when the content is hidden
73
+ */
74
+ icon?: Renderable
75
+ /**
76
+ * The icon displayed in the toggle button when the content is showing
77
+ */
78
+ iconExpanded?: Renderable
79
+ /**
80
+ * Transition content into view
81
+ */
82
+ transition?: boolean
83
+ /**
84
+ * Toggle the border around the component
85
+ */
86
+ border?: boolean
87
+ }
88
+
89
+ type PropKeys = keyof ToggleGroupOwnProps
90
+
91
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
92
+
93
+ type ToggleGroupStyle = { borderColor: string }
94
+
95
+ type ToggleGroupProps = ToggleGroupOwnProps &
96
+ OtherHTMLAttributes<ToggleGroupOwnProps> &
97
+ WithStyleProps<ReturnType<NewComponentTypes['ToggleGroup']>, ToggleGroupStyle>
98
+ const allowedProps: AllowedPropKeys = [
99
+ 'children',
100
+ 'summary',
101
+ 'toggleLabel',
102
+ 'as',
103
+ 'elementRef',
104
+ 'size',
105
+ 'expanded',
106
+ 'defaultExpanded',
107
+ 'onToggle',
108
+ 'icon',
109
+ 'iconExpanded',
110
+ 'transition',
111
+ 'border'
112
+ ]
113
+
114
+ export type { ToggleGroupProps, ToggleGroupStyle }
115
+ export { allowedProps }
@@ -0,0 +1,47 @@
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 { NewComponentTypes } from '@instructure/ui-themes'
26
+ import type { ToggleGroupProps, ToggleGroupStyle } from './props'
27
+
28
+ /**
29
+ * ---
30
+ * private: true
31
+ * ---
32
+ * Generates the style object from the theme and provided additional information
33
+ * @param {Object} componentTheme The theme variable object.
34
+ * @param {Object} props the props of the component, the style is applied to
35
+ * @param {Object} state the state of the component, the style is applied to
36
+ * @return {Object} The final style object, which will be used in the component
37
+ */
38
+ const generateStyle = (
39
+ componentTheme: ReturnType<NewComponentTypes['ToggleGroup']>,
40
+ _props: ToggleGroupProps
41
+ ): ToggleGroupStyle => {
42
+ return {
43
+ borderColor: componentTheme.borderColor
44
+ }
45
+ }
46
+
47
+ export default generateStyle