@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
package/package.json ADDED
@@ -0,0 +1,94 @@
1
+ {
2
+ "name": "@ohos-ports/instructure-ui-toggle-details",
3
+ "version": "11.7.5-beta.1",
4
+ "description": "A styled toggleable, accordion-like component.",
5
+ "author": "Instructure, Inc. Engineering and Product Design",
6
+ "module": "./es/index.js",
7
+ "main": "./lib/index.js",
8
+ "types": "./types/index.d.ts",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/ohos-ports/ohos-ports.git",
12
+ "directory": "ports/instructure-ui-toggle-details/11.7.5"
13
+ },
14
+ "homepage": "https://instructure.github.io/instructure-ui/",
15
+ "bugs": {
16
+ "url": "https://github.com/ohos-ports/ohos-ports/issues"
17
+ },
18
+ "license": "MIT",
19
+ "dependencies": {
20
+ "@babel/runtime": "^7.29.7",
21
+ "@instructure/emotion": "11.7.5",
22
+ "@instructure/ui-buttons": "11.7.5",
23
+ "@instructure/shared-types": "11.7.5",
24
+ "@instructure/ui-dom-utils": "11.7.5",
25
+ "@instructure/ui-expandable": "11.7.5",
26
+ "@instructure/ui-flex": "11.7.5",
27
+ "@instructure/ui-icons": "11.7.5",
28
+ "@instructure/ui-motion": "11.7.5",
29
+ "@instructure/ui-react-utils": "11.7.5",
30
+ "@instructure/ui-utils": "11.7.5",
31
+ "@instructure/ui-view": "11.7.5",
32
+ "@instructure/uid": "11.7.5",
33
+ "@instructure/ui-themes": "11.7.5"
34
+ },
35
+ "devDependencies": {
36
+ "@testing-library/jest-dom": "^6.9.1",
37
+ "@testing-library/react": "16.3.2",
38
+ "@testing-library/user-event": "^14.6.1",
39
+ "vitest": "^4.1.9",
40
+ "@instructure/ui-axe-check": "11.7.5",
41
+ "@instructure/ui-babel-preset": "11.7.5"
42
+ },
43
+ "peerDependencies": {
44
+ "react": ">=18 <=19"
45
+ },
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "sideEffects": false,
50
+ "exports": {
51
+ "./lib/*": "./lib/*",
52
+ "./es/*": "./es/*",
53
+ "./types/*": "./types/*",
54
+ "./package.json": "./package.json",
55
+ "./src/*": "./src/*",
56
+ ".": {
57
+ "src": "./src/exports/a.ts",
58
+ "types": "./types/exports/a.d.ts",
59
+ "import": "./es/exports/a.js",
60
+ "require": "./lib/exports/a.js",
61
+ "default": "./es/exports/a.js"
62
+ },
63
+ "./v11_6": {
64
+ "src": "./src/exports/a.ts",
65
+ "types": "./types/exports/a.d.ts",
66
+ "import": "./es/exports/a.js",
67
+ "require": "./lib/exports/a.js",
68
+ "default": "./es/exports/a.js"
69
+ },
70
+ "./v11_7": {
71
+ "src": "./src/exports/b.ts",
72
+ "types": "./types/exports/b.d.ts",
73
+ "import": "./es/exports/b.js",
74
+ "require": "./lib/exports/b.js",
75
+ "default": "./es/exports/b.js"
76
+ },
77
+ "./latest": {
78
+ "src": "./src/exports/b.ts",
79
+ "types": "./types/exports/b.d.ts",
80
+ "import": "./es/exports/b.js",
81
+ "require": "./lib/exports/b.js",
82
+ "default": "./es/exports/b.js"
83
+ }
84
+ },
85
+ "scripts": {
86
+ "lint": "ui-scripts lint",
87
+ "lint:fix": "ui-scripts lint --fix",
88
+ "clean": "ui-scripts clean",
89
+ "build": "ui-scripts build --modules es,cjs",
90
+ "build:watch": "pnpm run ts:check -- --watch & ui-scripts build --watch",
91
+ "build:types": "tsc -p tsconfig.build.json",
92
+ "ts:check": "tsc -p tsconfig.build.json --noEmit --emitDeclarationOnly false"
93
+ }
94
+ }
@@ -0,0 +1,233 @@
1
+ ---
2
+ describes: ToggleDetails
3
+ ---
4
+
5
+ The ToggleDetails component can be used to show/hide content in response to user action.
6
+
7
+ By default, ToggleDetails content is hidden. To override, pass in the `defaultExpanded` prop.
8
+
9
+ ```js
10
+ ---
11
+ type: example
12
+ ---
13
+ <ToggleDetails
14
+ summary="Click to hide me!"
15
+ defaultExpanded
16
+ >
17
+ <Text weight="bold">I am expanded!</Text> {lorem.paragraph()}
18
+ </ToggleDetails>
19
+ ```
20
+
21
+ ToggleDetails can be controlled:
22
+
23
+ ```js
24
+ ---
25
+ type: example
26
+ ---
27
+ const Example = () => {
28
+ const [expanded, setExpanded] = useState(true)
29
+
30
+ const handleChange = (event, expanded) => {
31
+ setExpanded(expanded)
32
+ }
33
+
34
+ const handleToggle = () => {
35
+ setExpanded((prevExpanded) => !prevExpanded)
36
+ }
37
+
38
+ return (
39
+ <div>
40
+ <Button onClick={handleToggle}>
41
+ <div aria-live="polite">
42
+ This Button {expanded ? 'Collapses' : 'Expands'}
43
+ </div>
44
+ </Button>
45
+ <br />
46
+ <br />
47
+ <ToggleDetails
48
+ summary="Click to hide me!"
49
+ expanded={expanded}
50
+ onToggle={handleChange}
51
+ >
52
+ <Text weight="bold">I am controlled and expanded!</Text>
53
+ {lorem.paragraph()}
54
+ </ToggleDetails>
55
+ </div>
56
+ )
57
+ }
58
+
59
+ render(<Example />)
60
+ ```
61
+
62
+ Setting ToggleDetails to `filled` will make the toggle use a full-width [Button](Button) component.
63
+
64
+ ```js
65
+ ---
66
+ type: example
67
+ ---
68
+ <ToggleDetails
69
+ variant="filled"
70
+ summary="Click to expand me!"
71
+ >
72
+ {lorem.paragraph()}
73
+ </ToggleDetails>
74
+ ```
75
+
76
+ ### Icon size / summary text formatting
77
+
78
+ Icon size can be adjusted using the `size` prop with small, medium, and large options.
79
+
80
+ The `summary` prop accepts any node, allowing you to format the summary text as
81
+ you see fit. In these examples, we are formatting it with the
82
+ [Text](Text) component.
83
+
84
+ ```js
85
+ ---
86
+ type: example
87
+ ---
88
+ <div>
89
+ <ToggleDetails
90
+ size="small"
91
+ summary="Small icon"
92
+ >
93
+ {lorem.paragraph()}
94
+ </ToggleDetails>
95
+
96
+ <br />
97
+
98
+ <ToggleDetails summary="Medium icon">
99
+ {lorem.paragraph()}
100
+ </ToggleDetails>
101
+
102
+ <br />
103
+
104
+ <ToggleDetails
105
+ size="large"
106
+ summary="Large icon"
107
+ >
108
+ {lorem.paragraph()}
109
+ </ToggleDetails>
110
+ </div>
111
+ ```
112
+
113
+ ### Icon positioning and block display
114
+
115
+ The `iconPosition` prop determines if the icon comes before or after the summary.
116
+
117
+ When the `fluidWidth` prop is set, the toggle fills the width of its
118
+ container.
119
+
120
+ ```js
121
+ ---
122
+ type: example
123
+ ---
124
+ <ToggleDetails
125
+ summary="Block display"
126
+ iconPosition="end"
127
+ defaultExpanded
128
+ fluidWidth
129
+ >
130
+ <Text>
131
+ {lorem.paragraph()}
132
+ </Text>
133
+ </ToggleDetails>
134
+ ```
135
+
136
+ ### Example to demonstrate more properties
137
+
138
+ ```js
139
+ ---
140
+ type: example
141
+ ---
142
+ const Example = () => {
143
+ const [state, setState] = useState({
144
+ expanded: true,
145
+ fluidWidth: true,
146
+ iconPosition: 'start',
147
+ size: 'small',
148
+ variant: 'default'
149
+ });
150
+
151
+ const handleChange = (field, value) => setState(prevState => ({ ...prevState, [field]: value }));
152
+ const handleToggle = () => setState(prevState => ({ ...prevState, expanded: !prevState.expanded }));
153
+
154
+ const renderOptions = () => {
155
+ const { fluidWidth, iconPosition, size, variant } = state;
156
+ const options = [
157
+ { name: 'iconPosition', values: ['start', 'end'] },
158
+ { name: 'size', values: ['small', 'medium', 'large'] },
159
+ { name: 'variant', values: ['default', 'filled'] },
160
+ ];
161
+
162
+ return (
163
+ <Flex alignItems="start">
164
+ {options.map(({ name, values }) => (
165
+ <Flex.Item margin="small" key={name}>
166
+ <RadioInputGroup
167
+ name={name}
168
+ description={name}
169
+ value={state[name]}
170
+ onChange={(e, value) => handleChange(name, value)}
171
+ >
172
+ {values.map(val => (
173
+ <RadioInput label={val} value={val} key={val} />
174
+ ))}
175
+ </RadioInputGroup>
176
+ </Flex.Item>
177
+ ))}
178
+ <Flex.Item margin="small">
179
+ <Checkbox
180
+ label="fluidWidth"
181
+ checked={fluidWidth}
182
+ onChange={() => handleChange('fluidWidth', !fluidWidth)}
183
+ />
184
+ </Flex.Item>
185
+ </Flex>
186
+ );
187
+ };
188
+
189
+ const { expanded, iconPosition, size, variant, fluidWidth } = state;
190
+
191
+ return (
192
+ <div>
193
+ {renderOptions()}
194
+ <Button onClick={handleToggle}>
195
+ This Button {expanded ? 'Collapses' : 'Expands'}
196
+ </Button>
197
+ <br />
198
+ <br />
199
+ <ToggleDetails
200
+ summary="Click to hide me!"
201
+ expanded={expanded}
202
+ onToggle={(_, expanded) => handleChange('expanded', expanded)}
203
+ fluidWidth={fluidWidth}
204
+ iconPosition={iconPosition}
205
+ size={size}
206
+ variant={variant}
207
+ >
208
+ <Text weight="bold">
209
+ I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!I am controlled and expanded!
210
+ </Text>
211
+ </ToggleDetails>
212
+ </div>
213
+ );
214
+ };
215
+
216
+ render(<Example />)
217
+ ```
218
+
219
+ ### Guidelines
220
+
221
+ ```js
222
+ ---
223
+ type: embed
224
+ ---
225
+ <Guidelines>
226
+ <Figure recommendation="yes" title="Do">
227
+ <Figure.Item>Use ToggleDetails when descriptive text is longer than a short phrase</Figure.Item>
228
+ </Figure>
229
+ <Figure recommendation="no" title="Don't">
230
+ <Figure.Item>Nest ToggleDetails within another ToggleDetails</Figure.Item>
231
+ </Figure>
232
+ </Guidelines>
233
+ ```
@@ -0,0 +1,204 @@
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, createRef } from 'react'
26
+ import { Button } from '@instructure/ui-buttons/v11_6'
27
+ import {
28
+ IconArrowOpenEndSolid,
29
+ IconArrowOpenDownSolid
30
+ } from '@instructure/ui-icons'
31
+ import { Expandable } from '@instructure/ui-expandable'
32
+ import { omitProps, pickProps } from '@instructure/ui-react-utils'
33
+ import { isActiveElement } from '@instructure/ui-dom-utils'
34
+
35
+ import { withStyle } from '@instructure/emotion'
36
+ import generateStyle from './styles.js'
37
+ import generateComponentTheme from './theme.js'
38
+ import type { ToggleDetailsProps } from './props'
39
+ import { allowedProps } from './props.js'
40
+ import type { ExpandableToggleProps } from '@instructure/ui-expandable'
41
+ import type { ViewProps } from '@instructure/ui-view/v11_6'
42
+
43
+ /**
44
+ ---
45
+ category: components
46
+ ---
47
+ **/
48
+ @withStyle(generateStyle, generateComponentTheme)
49
+ class ToggleDetails extends Component<ToggleDetailsProps> {
50
+ static displayName = 'ToggleDetails'
51
+ static readonly componentId = 'ToggleDetails'
52
+ static allowedProps = allowedProps
53
+
54
+ static defaultProps = {
55
+ variant: 'default',
56
+ size: 'medium',
57
+ fluidWidth: false,
58
+ icon: IconArrowOpenEndSolid,
59
+ iconExpanded: IconArrowOpenDownSolid,
60
+ iconPosition: 'start',
61
+ defaultExpanded: false,
62
+ children: null
63
+ }
64
+
65
+ _buttonNode: HTMLElement | null = null
66
+ ref = createRef<HTMLDivElement>()
67
+
68
+ // TODO this solution was generated with Gemini, should be tested if it works as fine as before
69
+ setButtonRef = (node: Element | null) => {
70
+ this._buttonNode = node as HTMLElement | null
71
+ }
72
+
73
+ get focused() {
74
+ return isActiveElement(this._buttonNode)
75
+ }
76
+
77
+ focus() {
78
+ this._buttonNode?.focus()
79
+ }
80
+
81
+ componentDidMount() {
82
+ this.props.makeStyles?.()
83
+ }
84
+
85
+ componentDidUpdate() {
86
+ this.props.makeStyles?.()
87
+ }
88
+
89
+ renderSummary(expanded: boolean) {
90
+ const { summary, iconPosition } = this.props
91
+
92
+ return (
93
+ <span css={this.props.styles?.summary}>
94
+ {iconPosition === 'start' && this.renderIcon(expanded)}
95
+ <span css={this.props.styles?.summaryText}>{summary}</span>
96
+ {iconPosition === 'end' && this.renderIcon(expanded)}
97
+ </span>
98
+ )
99
+ }
100
+
101
+ renderToggle(
102
+ toggleProps: ReturnType<ExpandableToggleProps>,
103
+ expanded: boolean
104
+ ) {
105
+ const { variant } = this.props
106
+ const tProps = this.props.children
107
+ ? toggleProps
108
+ : { onClick: toggleProps.onClick }
109
+ const props = {
110
+ ...omitProps(this.props, ToggleDetails.allowedProps),
111
+ ...tProps,
112
+ children: this.renderSummary(expanded)
113
+ } as Record<string, unknown>
114
+ const summary = this.renderSummary(expanded)
115
+
116
+ if (variant === 'filled') {
117
+ return (
118
+ <Button
119
+ {...props}
120
+ display="block"
121
+ textAlign="start"
122
+ elementRef={this.setButtonRef}
123
+ >
124
+ {summary}
125
+ </Button>
126
+ )
127
+ } else if (props.href) {
128
+ return (
129
+ <a {...props} css={this.props.styles?.toggle} ref={this.setButtonRef}>
130
+ {summary}
131
+ </a>
132
+ )
133
+ } else {
134
+ return (
135
+ <button
136
+ {...props}
137
+ type="button"
138
+ css={this.props.styles?.toggle}
139
+ ref={this.setButtonRef}
140
+ >
141
+ {summary}
142
+ </button>
143
+ )
144
+ }
145
+ }
146
+
147
+ renderIcon(expanded: boolean) {
148
+ const Icon = expanded ? this.props.iconExpanded : this.props.icon
149
+
150
+ return this.props.children && Icon ? (
151
+ <span css={this.props.styles?.icon}>
152
+ <Icon />
153
+ </span>
154
+ ) : null
155
+ }
156
+
157
+ renderDetails(expanded: boolean, detailsProps: { id: string }) {
158
+ if (!this.props.children) return null
159
+ const expandedStyles = expanded ? { display: 'block' } : { display: 'none' }
160
+ return (
161
+ <div {...detailsProps} css={[this.props.styles?.details, expandedStyles]}>
162
+ {expanded && this.renderContent()}
163
+ </div>
164
+ )
165
+ }
166
+
167
+ renderContent() {
168
+ return <div css={this.props.styles?.content}>{this.props.children}</div>
169
+ }
170
+
171
+ handleToggle = (
172
+ event: React.KeyboardEvent<ViewProps> | React.MouseEvent<ViewProps>,
173
+ expanded: boolean
174
+ ) => {
175
+ if (typeof this.props.onToggle === 'function') {
176
+ this.props.onToggle(event, expanded)
177
+ }
178
+ }
179
+
180
+ render() {
181
+ return (
182
+ <Expandable
183
+ {...pickProps(this.props, Expandable.allowedProps)}
184
+ onToggle={this.handleToggle}
185
+ >
186
+ {({ expanded, getToggleProps, getDetailsProps }) => {
187
+ return (
188
+ <div
189
+ css={this.props.styles?.toggleDetails}
190
+ ref={this.ref}
191
+ data-cid="ToggleDetails"
192
+ >
193
+ {this.renderToggle(getToggleProps(), expanded)}
194
+ {this.renderDetails(expanded, getDetailsProps())}
195
+ </div>
196
+ )
197
+ }}
198
+ </Expandable>
199
+ )
200
+ }
201
+ }
202
+
203
+ export default ToggleDetails
204
+ export { ToggleDetails }
@@ -0,0 +1,114 @@
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 type {
28
+ OtherHTMLAttributes,
29
+ ToggleDetailsTheme
30
+ } from '@instructure/shared-types'
31
+ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
32
+ import type { ViewProps } from '@instructure/ui-view/v11_6'
33
+
34
+ type ToggleDetailsOwnProps = {
35
+ variant?: 'default' | 'filled'
36
+ /**
37
+ * The summary that displays and can be interacted with
38
+ */
39
+ summary: React.ReactNode
40
+ /**
41
+ * Whether the content is expanded or hidden
42
+ */
43
+ expanded?: boolean // TODO: controllable(PropTypes.bool, 'onToggle', 'defaultExpanded')
44
+ /**
45
+ * Whether the content is initially expanded or hidden (uncontrolled)
46
+ */
47
+ defaultExpanded?: boolean
48
+ onToggle?: (
49
+ event: React.KeyboardEvent<ViewProps> | React.MouseEvent<ViewProps>,
50
+ expanded: boolean
51
+ ) => void
52
+ /**
53
+ * The icon to display next to the summary text when content is hidden
54
+ */
55
+ icon?: (...args: any[]) => React.ReactElement
56
+ /**
57
+ * The icon to display when content is expanded
58
+ */
59
+ iconExpanded?: (...args: any[]) => React.ReactElement
60
+ /**
61
+ * Icon position at the start or end of the summary text
62
+ */
63
+ iconPosition?: 'start' | 'end'
64
+ /**
65
+ * should the summary fill the width of its container
66
+ */
67
+ fluidWidth?: boolean
68
+ /**
69
+ * Choose a size for the expand/collapse icon
70
+ */
71
+ size?: 'small' | 'medium' | 'large'
72
+ /**
73
+ * The toggleable content passed inside the ToggleDetails component
74
+ */
75
+ children?: React.ReactNode
76
+ }
77
+
78
+ type PropKeys = keyof ToggleDetailsOwnProps
79
+
80
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
81
+
82
+ type ToggleDetailsProps = ToggleDetailsOwnProps &
83
+ WithStyleProps<ToggleDetailsTheme, ToggleDetailsStyle> &
84
+ OtherHTMLAttributes<ToggleDetailsOwnProps>
85
+
86
+ type ToggleDetailsStyle = ComponentStyle<
87
+ | 'toggleDetails'
88
+ | 'summary'
89
+ | 'summaryText'
90
+ | 'toggle'
91
+ | 'icon'
92
+ | 'details'
93
+ | 'content'
94
+ >
95
+
96
+ type ToggleDetailsStyleProps = {
97
+ animate: boolean
98
+ }
99
+ const allowedProps: AllowedPropKeys = [
100
+ 'variant',
101
+ 'summary',
102
+ 'expanded',
103
+ 'defaultExpanded',
104
+ 'onToggle',
105
+ 'icon',
106
+ 'iconExpanded',
107
+ 'iconPosition',
108
+ 'fluidWidth',
109
+ 'children',
110
+ 'size'
111
+ ]
112
+
113
+ export type { ToggleDetailsProps, ToggleDetailsStyleProps, ToggleDetailsStyle }
114
+ export { allowedProps }