@instructure/ui-toggle-details 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.
- package/CHANGELOG.md +35 -289
- package/es/ToggleDetails/{index.js → v1/index.js} +2 -2
- package/es/ToggleDetails/v2/index.js +186 -0
- package/{src/index.ts → es/ToggleDetails/v2/props.js} +2 -5
- package/es/ToggleDetails/v2/styles.js +186 -0
- package/es/ToggleGroup/{index.js → v1/index.js} +4 -4
- package/es/ToggleGroup/v2/index.js +172 -0
- package/es/ToggleGroup/v2/props.js +26 -0
- package/es/ToggleGroup/v2/styles.js +40 -0
- package/es/{index.js → exports/a.js} +2 -2
- package/es/exports/b.js +25 -0
- package/lib/ToggleDetails/{index.js → v1/index.js} +5 -5
- package/lib/ToggleDetails/v2/index.js +192 -0
- package/lib/ToggleDetails/v2/props.js +31 -0
- package/lib/ToggleDetails/v2/styles.js +192 -0
- package/lib/ToggleGroup/{index.js → v1/index.js} +12 -12
- package/lib/ToggleGroup/v2/index.js +179 -0
- package/lib/ToggleGroup/v2/props.js +31 -0
- package/lib/ToggleGroup/v2/styles.js +46 -0
- package/lib/{index.js → exports/a.js} +4 -4
- package/lib/exports/b.js +19 -0
- package/package.json +45 -23
- package/src/ToggleDetails/{index.tsx → v1/index.tsx} +3 -3
- package/src/ToggleDetails/{props.ts → v1/props.ts} +1 -1
- package/src/ToggleDetails/v2/README.md +233 -0
- package/src/ToggleDetails/v2/index.tsx +205 -0
- package/src/ToggleDetails/v2/props.ts +114 -0
- package/src/ToggleDetails/v2/styles.ts +188 -0
- package/src/ToggleGroup/{index.tsx → v1/index.tsx} +4 -4
- package/src/ToggleGroup/v2/README.md +93 -0
- package/src/ToggleGroup/v2/index.tsx +213 -0
- package/src/ToggleGroup/v2/props.ts +115 -0
- package/src/ToggleGroup/v2/styles.ts +47 -0
- package/src/exports/a.ts +29 -0
- package/src/exports/b.ts +29 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/ToggleDetails/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/ToggleDetails/v1/index.d.ts.map +1 -0
- package/types/ToggleDetails/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/ToggleDetails/v1/props.d.ts.map +1 -0
- package/types/ToggleDetails/v1/styles.d.ts.map +1 -0
- package/types/ToggleDetails/v1/theme.d.ts.map +1 -0
- package/types/ToggleDetails/v2/index.d.ts +54 -0
- package/types/ToggleDetails/v2/index.d.ts.map +1 -0
- package/types/ToggleDetails/v2/props.d.ts +55 -0
- package/types/ToggleDetails/v2/props.d.ts.map +1 -0
- package/types/ToggleDetails/v2/styles.d.ts +16 -0
- package/types/ToggleDetails/v2/styles.d.ts.map +1 -0
- package/types/ToggleGroup/v1/index.d.ts.map +1 -0
- package/types/ToggleGroup/v1/props.d.ts.map +1 -0
- package/types/ToggleGroup/v1/styles.d.ts.map +1 -0
- package/types/ToggleGroup/v1/theme.d.ts.map +1 -0
- package/types/ToggleGroup/v2/index.d.ts +53 -0
- package/types/ToggleGroup/v2/index.d.ts.map +1 -0
- package/types/ToggleGroup/v2/props.d.ts +65 -0
- package/types/ToggleGroup/v2/props.d.ts.map +1 -0
- package/types/ToggleGroup/v2/styles.d.ts +15 -0
- package/types/ToggleGroup/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +5 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +5 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/ToggleDetails/index.d.ts.map +0 -1
- package/types/ToggleDetails/props.d.ts.map +0 -1
- package/types/ToggleDetails/styles.d.ts.map +0 -1
- package/types/ToggleDetails/theme.d.ts.map +0 -1
- package/types/ToggleGroup/index.d.ts.map +0 -1
- package/types/ToggleGroup/props.d.ts.map +0 -1
- package/types/ToggleGroup/styles.d.ts.map +0 -1
- package/types/ToggleGroup/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -5
- package/types/index.d.ts.map +0 -1
- /package/es/ToggleDetails/{props.js → v1/props.js} +0 -0
- /package/es/ToggleDetails/{styles.js → v1/styles.js} +0 -0
- /package/es/ToggleDetails/{theme.js → v1/theme.js} +0 -0
- /package/es/ToggleGroup/{props.js → v1/props.js} +0 -0
- /package/es/ToggleGroup/{styles.js → v1/styles.js} +0 -0
- /package/es/ToggleGroup/{theme.js → v1/theme.js} +0 -0
- /package/lib/ToggleDetails/{props.js → v1/props.js} +0 -0
- /package/lib/ToggleDetails/{styles.js → v1/styles.js} +0 -0
- /package/lib/ToggleDetails/{theme.js → v1/theme.js} +0 -0
- /package/lib/ToggleGroup/{props.js → v1/props.js} +0 -0
- /package/lib/ToggleGroup/{styles.js → v1/styles.js} +0 -0
- /package/lib/ToggleGroup/{theme.js → v1/theme.js} +0 -0
- /package/src/ToggleDetails/{README.md → v1/README.md} +0 -0
- /package/src/ToggleDetails/{styles.ts → v1/styles.ts} +0 -0
- /package/src/ToggleDetails/{theme.ts → v1/theme.ts} +0 -0
- /package/src/ToggleGroup/{README.md → v1/README.md} +0 -0
- /package/src/ToggleGroup/{props.ts → v1/props.ts} +0 -0
- /package/src/ToggleGroup/{styles.ts → v1/styles.ts} +0 -0
- /package/src/ToggleGroup/{theme.ts → v1/theme.ts} +0 -0
- /package/types/ToggleDetails/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/ToggleDetails/{theme.d.ts → v1/theme.d.ts} +0 -0
- /package/types/ToggleGroup/{index.d.ts → v1/index.d.ts} +0 -0
- /package/types/ToggleGroup/{props.d.ts → v1/props.d.ts} +0 -0
- /package/types/ToggleGroup/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/ToggleGroup/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,205 @@
|
|
|
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/latest'
|
|
27
|
+
import {
|
|
28
|
+
ChevronRightInstUIIcon,
|
|
29
|
+
ChevronDownInstUIIcon
|
|
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'
|
|
37
|
+
import type { ToggleDetailsProps } from './props'
|
|
38
|
+
import { allowedProps } from './props'
|
|
39
|
+
import type { ExpandableToggleProps } from '@instructure/ui-expandable'
|
|
40
|
+
import type { ViewProps } from '@instructure/ui-view/latest'
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
---
|
|
44
|
+
category: components
|
|
45
|
+
---
|
|
46
|
+
**/
|
|
47
|
+
@withStyle(generateStyle)
|
|
48
|
+
class ToggleDetails extends Component<ToggleDetailsProps> {
|
|
49
|
+
static readonly componentId = 'ToggleDetails'
|
|
50
|
+
static allowedProps = allowedProps
|
|
51
|
+
|
|
52
|
+
static defaultProps = {
|
|
53
|
+
variant: 'default',
|
|
54
|
+
size: 'medium',
|
|
55
|
+
fluidWidth: false,
|
|
56
|
+
icon: ChevronRightInstUIIcon,
|
|
57
|
+
iconExpanded: ChevronDownInstUIIcon,
|
|
58
|
+
iconPosition: 'start',
|
|
59
|
+
defaultExpanded: false,
|
|
60
|
+
children: null
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
_buttonNode: HTMLElement | null = null
|
|
64
|
+
ref = createRef<HTMLDivElement>()
|
|
65
|
+
|
|
66
|
+
// TODO this solution was generated with Gemini, should be tested if it works as fine as before
|
|
67
|
+
setButtonRef = (node: Element | null) => {
|
|
68
|
+
this._buttonNode = node as HTMLElement | null
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
get focused() {
|
|
72
|
+
return isActiveElement(this._buttonNode)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
focus() {
|
|
76
|
+
this._buttonNode?.focus()
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
componentDidMount() {
|
|
80
|
+
this.props.makeStyles?.()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
componentDidUpdate() {
|
|
84
|
+
this.props.makeStyles?.()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
renderSummary(expanded: boolean) {
|
|
88
|
+
const { summary, iconPosition } = this.props
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<span css={this.props.styles?.summary}>
|
|
92
|
+
{iconPosition === 'start' && this.renderIcon(expanded)}
|
|
93
|
+
<span css={this.props.styles?.summaryText}>{summary}</span>
|
|
94
|
+
{iconPosition === 'end' && this.renderIcon(expanded)}
|
|
95
|
+
</span>
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
renderToggle(
|
|
100
|
+
toggleProps: ReturnType<ExpandableToggleProps>,
|
|
101
|
+
expanded: boolean
|
|
102
|
+
) {
|
|
103
|
+
const { variant } = this.props
|
|
104
|
+
const tProps = this.props.children
|
|
105
|
+
? toggleProps
|
|
106
|
+
: { onClick: toggleProps.onClick }
|
|
107
|
+
const props = {
|
|
108
|
+
...omitProps(this.props, ToggleDetails.allowedProps),
|
|
109
|
+
...tProps,
|
|
110
|
+
children: this.renderSummary(expanded)
|
|
111
|
+
} as Record<string, unknown>
|
|
112
|
+
const summary = this.renderSummary(expanded)
|
|
113
|
+
|
|
114
|
+
if (variant === 'filled') {
|
|
115
|
+
return (
|
|
116
|
+
<Button
|
|
117
|
+
{...props}
|
|
118
|
+
display="block"
|
|
119
|
+
textAlign="start"
|
|
120
|
+
elementRef={this.setButtonRef}
|
|
121
|
+
>
|
|
122
|
+
{summary}
|
|
123
|
+
</Button>
|
|
124
|
+
)
|
|
125
|
+
} else if (props.href) {
|
|
126
|
+
return (
|
|
127
|
+
<a {...props} css={this.props.styles?.toggle} ref={this.setButtonRef}>
|
|
128
|
+
{summary}
|
|
129
|
+
</a>
|
|
130
|
+
)
|
|
131
|
+
} else {
|
|
132
|
+
return (
|
|
133
|
+
<button
|
|
134
|
+
{...props}
|
|
135
|
+
type="button"
|
|
136
|
+
css={this.props.styles?.toggle}
|
|
137
|
+
ref={this.setButtonRef}
|
|
138
|
+
>
|
|
139
|
+
{summary}
|
|
140
|
+
</button>
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
renderIcon(expanded: boolean) {
|
|
146
|
+
const Icon = expanded ? this.props.iconExpanded : this.props.icon
|
|
147
|
+
const iconSize = this.props.size === 'large' ? 'lg' : 'md'
|
|
148
|
+
const iconColor =
|
|
149
|
+
this.props.variant === 'filled' ? 'actionSecondaryBaseColor' : 'baseColor'
|
|
150
|
+
|
|
151
|
+
return this.props.children && Icon ? (
|
|
152
|
+
<span css={this.props.styles?.icon}>
|
|
153
|
+
<Icon size={iconSize} color={iconColor} />
|
|
154
|
+
</span>
|
|
155
|
+
) : null
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
renderDetails(expanded: boolean, detailsProps: { id: string }) {
|
|
159
|
+
if (!this.props.children) return null
|
|
160
|
+
const expandedStyles = expanded ? { display: 'block' } : { display: 'none' }
|
|
161
|
+
return (
|
|
162
|
+
<div {...detailsProps} css={[this.props.styles?.details, expandedStyles]}>
|
|
163
|
+
{expanded && this.renderContent()}
|
|
164
|
+
</div>
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
renderContent() {
|
|
169
|
+
return <div css={this.props.styles?.content}>{this.props.children}</div>
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
handleToggle = (
|
|
173
|
+
event: React.KeyboardEvent<ViewProps> | React.MouseEvent<ViewProps>,
|
|
174
|
+
expanded: boolean
|
|
175
|
+
) => {
|
|
176
|
+
if (typeof this.props.onToggle === 'function') {
|
|
177
|
+
this.props.onToggle(event, expanded)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
render() {
|
|
182
|
+
return (
|
|
183
|
+
<Expandable
|
|
184
|
+
{...pickProps(this.props, Expandable.allowedProps)}
|
|
185
|
+
onToggle={this.handleToggle}
|
|
186
|
+
>
|
|
187
|
+
{({ expanded, getToggleProps, getDetailsProps }) => {
|
|
188
|
+
return (
|
|
189
|
+
<div
|
|
190
|
+
css={this.props.styles?.toggleDetails}
|
|
191
|
+
ref={this.ref}
|
|
192
|
+
data-cid="ToggleDetails"
|
|
193
|
+
>
|
|
194
|
+
{this.renderToggle(getToggleProps(), expanded)}
|
|
195
|
+
{this.renderDetails(expanded, getDetailsProps())}
|
|
196
|
+
</div>
|
|
197
|
+
)
|
|
198
|
+
}}
|
|
199
|
+
</Expandable>
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export default ToggleDetails
|
|
205
|
+
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/latest'
|
|
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 }
|
|
@@ -0,0 +1,188 @@
|
|
|
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 { keyframes } from '@instructure/emotion'
|
|
26
|
+
|
|
27
|
+
import type { NewComponentTypes, SharedTokens } from '@instructure/ui-themes'
|
|
28
|
+
import type {
|
|
29
|
+
ToggleDetailsProps,
|
|
30
|
+
ToggleDetailsStyleProps,
|
|
31
|
+
ToggleDetailsStyle
|
|
32
|
+
} from './props'
|
|
33
|
+
|
|
34
|
+
const contentAnimation = keyframes`
|
|
35
|
+
to {
|
|
36
|
+
opacity: 1;
|
|
37
|
+
}`
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* ---
|
|
41
|
+
* private: true
|
|
42
|
+
* ---
|
|
43
|
+
* Generates the style object from the theme and provided additional information
|
|
44
|
+
* @param {Object} componentTheme The theme variable object.
|
|
45
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
46
|
+
* @param {Object} sharedTokens the shared tokens of the component
|
|
47
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
48
|
+
* @return {Object} The final style object, which will be used in the component
|
|
49
|
+
*/
|
|
50
|
+
const generateStyle = (
|
|
51
|
+
componentTheme: NewComponentTypes['ToggleDetails'],
|
|
52
|
+
props: ToggleDetailsProps,
|
|
53
|
+
sharedTokens: SharedTokens,
|
|
54
|
+
_state: ToggleDetailsStyleProps
|
|
55
|
+
): ToggleDetailsStyle => {
|
|
56
|
+
const { fluidWidth, iconPosition, size, variant } = props
|
|
57
|
+
|
|
58
|
+
const positionIconAtEnd =
|
|
59
|
+
iconPosition === 'end' && (variant === 'filled' || fluidWidth)
|
|
60
|
+
const fluidWidthStyles = fluidWidth ? { display: 'block', width: '100%' } : {}
|
|
61
|
+
|
|
62
|
+
const iconPositionStyles = {
|
|
63
|
+
start: {
|
|
64
|
+
marginInlineEnd: componentTheme.iconMargin,
|
|
65
|
+
marginInlineStart: 0
|
|
66
|
+
},
|
|
67
|
+
end: {
|
|
68
|
+
marginInlineStart: componentTheme.iconMargin,
|
|
69
|
+
marginInlineEnd: 0
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const fontSizeStyles = {
|
|
74
|
+
small: { fontSize: componentTheme.fontSizeSmall },
|
|
75
|
+
medium: { fontSize: componentTheme.fontSizeMedium },
|
|
76
|
+
large: { fontSize: componentTheme.fontSizeLarge }
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const indentDetailsStyles =
|
|
80
|
+
iconPosition === 'start' && !fluidWidth
|
|
81
|
+
? {
|
|
82
|
+
small: {
|
|
83
|
+
paddingInlineStart: `calc(${componentTheme.contentPaddingSmall} + ${componentTheme.togglePadding})`,
|
|
84
|
+
paddingInlineEnd: '0'
|
|
85
|
+
},
|
|
86
|
+
medium: {
|
|
87
|
+
paddingInlineStart: `calc(${componentTheme.contentPaddingMedium} + ${componentTheme.togglePadding})`,
|
|
88
|
+
paddingInlineEnd: '0'
|
|
89
|
+
},
|
|
90
|
+
large: {
|
|
91
|
+
paddingInlineStart: `calc(${componentTheme.contentPaddingLarge} + ${componentTheme.togglePadding})`,
|
|
92
|
+
paddingInlineEnd: '0'
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
: {
|
|
96
|
+
small: {},
|
|
97
|
+
medium: {},
|
|
98
|
+
large: {}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
toggleDetails: {
|
|
103
|
+
label: 'toggleDetails',
|
|
104
|
+
fontFamily: componentTheme.fontFamily,
|
|
105
|
+
fontWeight: componentTheme.fontWeight
|
|
106
|
+
},
|
|
107
|
+
summary: {
|
|
108
|
+
label: 'toggleDetails__summary',
|
|
109
|
+
position: 'relative',
|
|
110
|
+
display: 'flex',
|
|
111
|
+
alignItems: 'center',
|
|
112
|
+
boxSizing: 'border-box',
|
|
113
|
+
textAlign: 'start'
|
|
114
|
+
},
|
|
115
|
+
summaryText: {
|
|
116
|
+
label: 'toggleDetails__summaryText',
|
|
117
|
+
minWidth: '0.0625rem',
|
|
118
|
+
flexGrow: 1,
|
|
119
|
+
...(positionIconAtEnd ? { flex: 1 } : {})
|
|
120
|
+
},
|
|
121
|
+
toggle: {
|
|
122
|
+
label: 'toggleDetails__toggle',
|
|
123
|
+
fontFamily: componentTheme.fontFamily,
|
|
124
|
+
lineHeight: componentTheme.lineHeight,
|
|
125
|
+
appearance: 'none',
|
|
126
|
+
cursor: 'pointer',
|
|
127
|
+
userSelect: 'none',
|
|
128
|
+
touchAction: 'manipulation',
|
|
129
|
+
position: 'relative',
|
|
130
|
+
overflow: 'visible',
|
|
131
|
+
boxSizing: 'border-box',
|
|
132
|
+
padding: '0',
|
|
133
|
+
margin: '0',
|
|
134
|
+
outline: 'none',
|
|
135
|
+
border: 'none',
|
|
136
|
+
background: 'transparent',
|
|
137
|
+
color: componentTheme.textColor,
|
|
138
|
+
'&::-moz-focus-inner': { padding: '0', margin: '0' },
|
|
139
|
+
'&::before': {
|
|
140
|
+
content: '""',
|
|
141
|
+
position: 'absolute',
|
|
142
|
+
top: '-0.375rem',
|
|
143
|
+
left: '-0.375rem',
|
|
144
|
+
right: '-0.375rem',
|
|
145
|
+
bottom: '-0.375rem',
|
|
146
|
+
border: `${componentTheme.toggleBorderWidth} ${componentTheme.toggleBorderStyle} ${sharedTokens.focusOutline.infoColor}`,
|
|
147
|
+
borderRadius: `calc(${componentTheme.toggleBorderRadius} * 1.5)`,
|
|
148
|
+
opacity: 0,
|
|
149
|
+
pointerEvents: 'none'
|
|
150
|
+
},
|
|
151
|
+
'&:focus': { '&::before': { opacity: 1 } },
|
|
152
|
+
'&:focus, &:hover, &:active': {
|
|
153
|
+
textDecoration: 'none',
|
|
154
|
+
color: componentTheme.textColor
|
|
155
|
+
},
|
|
156
|
+
textDecoration: 'none',
|
|
157
|
+
...fluidWidthStyles,
|
|
158
|
+
...fontSizeStyles[size!]
|
|
159
|
+
},
|
|
160
|
+
icon: {
|
|
161
|
+
label: 'toggleDetails__icon',
|
|
162
|
+
display: 'flex',
|
|
163
|
+
alignItems: 'center',
|
|
164
|
+
'& > svg': {
|
|
165
|
+
display: 'block' /* fix vertical alignment of icon */
|
|
166
|
+
},
|
|
167
|
+
...iconPositionStyles[iconPosition!]
|
|
168
|
+
},
|
|
169
|
+
details: {
|
|
170
|
+
label: 'toggleDetails__details',
|
|
171
|
+
boxSizing: 'border-box',
|
|
172
|
+
paddingTop: componentTheme.togglePadding,
|
|
173
|
+
color: componentTheme.textColor,
|
|
174
|
+
lineHeight: componentTheme.lineHeight,
|
|
175
|
+
...fontSizeStyles[size!],
|
|
176
|
+
...indentDetailsStyles[size!]
|
|
177
|
+
},
|
|
178
|
+
content: {
|
|
179
|
+
label: 'toggleDetails__content',
|
|
180
|
+
opacity: 0.01,
|
|
181
|
+
animationName: contentAnimation,
|
|
182
|
+
animationFillMode: 'forwards',
|
|
183
|
+
animationDuration: '.3s'
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export default generateStyle
|
|
@@ -30,13 +30,13 @@ import {
|
|
|
30
30
|
getElementType,
|
|
31
31
|
callRenderProp
|
|
32
32
|
} from '@instructure/ui-react-utils'
|
|
33
|
-
import { IconButton } from '@instructure/ui-buttons'
|
|
33
|
+
import { IconButton } from '@instructure/ui-buttons/v11_6'
|
|
34
34
|
import { Transition } from '@instructure/ui-motion'
|
|
35
35
|
import { Expandable } from '@instructure/ui-expandable'
|
|
36
36
|
import type { ExpandableToggleProps } from '@instructure/ui-expandable'
|
|
37
37
|
import { isActiveElement } from '@instructure/ui-dom-utils'
|
|
38
|
-
import { Flex } from '@instructure/ui-flex'
|
|
39
|
-
import { View } from '@instructure/ui-view'
|
|
38
|
+
import { Flex } from '@instructure/ui-flex/v11_6'
|
|
39
|
+
import { View } from '@instructure/ui-view/v11_6'
|
|
40
40
|
import {
|
|
41
41
|
IconArrowOpenEndSolid,
|
|
42
42
|
IconArrowOpenDownSolid
|
|
@@ -44,7 +44,7 @@ import {
|
|
|
44
44
|
import type { ToggleGroupProps } from './props'
|
|
45
45
|
import { allowedProps } from './props'
|
|
46
46
|
|
|
47
|
-
import { withStyle } from '@instructure/emotion'
|
|
47
|
+
import { withStyleLegacy as withStyle } from '@instructure/emotion'
|
|
48
48
|
|
|
49
49
|
import generateStyle from './styles'
|
|
50
50
|
import generateComponentTheme from './theme'
|
|
@@ -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="small">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="small">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="small">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="small">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="small">
|
|
89
|
+
This is the details section of the nested ToggleGroup
|
|
90
|
+
</View>
|
|
91
|
+
</ToggleGroup>
|
|
92
|
+
</ToggleGroup>
|
|
93
|
+
```
|