@instructure/ui-toggle-details 8.24.5 → 8.24.6-snapshot.9
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/LICENSE.md +27 -0
- package/es/ToggleDetails/ToggleDetailsLocator.js +2 -1
- package/es/ToggleDetails/index.js +14 -7
- package/es/ToggleDetails/props.js +0 -36
- package/es/ToggleGroup/ToggleGroupLocator.js +2 -1
- package/es/ToggleGroup/index.js +9 -6
- package/es/ToggleGroup/props.js +0 -48
- package/lib/ToggleDetails/ToggleDetailsLocator.js +2 -1
- package/lib/ToggleDetails/index.js +15 -6
- package/lib/ToggleDetails/props.js +0 -36
- package/lib/ToggleGroup/ToggleGroupLocator.js +2 -1
- package/lib/ToggleGroup/index.js +10 -5
- package/lib/ToggleGroup/props.js +0 -48
- package/package.json +23 -22
- package/src/ToggleDetails/index.tsx +21 -28
- package/src/ToggleDetails/props.ts +30 -30
- package/src/ToggleGroup/index.tsx +17 -18
- package/src/ToggleGroup/props.ts +35 -35
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/ToggleDetails/index.d.ts +22 -18
- package/types/ToggleDetails/index.d.ts.map +1 -1
- package/types/ToggleDetails/props.d.ts +30 -3
- package/types/ToggleDetails/props.d.ts.map +1 -1
- package/types/ToggleGroup/index.d.ts +18 -16
- package/types/ToggleGroup/index.d.ts.map +1 -1
- package/types/ToggleGroup/props.d.ts +42 -5
- package/types/ToggleGroup/props.d.ts.map +1 -1
|
@@ -22,8 +22,7 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
/** @jsx jsx */
|
|
25
|
-
import { Component } from 'react'
|
|
26
|
-
|
|
25
|
+
import React, { Component } from 'react'
|
|
27
26
|
import { Button } from '@instructure/ui-buttons'
|
|
28
27
|
import {
|
|
29
28
|
IconArrowOpenEndSolid,
|
|
@@ -35,16 +34,17 @@ import { isActiveElement } from '@instructure/ui-dom-utils'
|
|
|
35
34
|
import { testable } from '@instructure/ui-testable'
|
|
36
35
|
|
|
37
36
|
import { withStyle, jsx } from '@instructure/emotion'
|
|
38
|
-
|
|
39
37
|
import generateStyle from './styles'
|
|
40
38
|
import generateComponentTheme from './theme'
|
|
41
39
|
import type { ToggleDetailsProps, ToggleDetailsStyleProps } from './props'
|
|
42
40
|
import { allowedProps, propTypes } from './props'
|
|
41
|
+
import type { ExpandableToggleProps } from '@instructure/ui-expandable'
|
|
43
42
|
|
|
44
43
|
/**
|
|
45
44
|
---
|
|
46
45
|
category: components
|
|
47
46
|
---
|
|
47
|
+
@tsProps
|
|
48
48
|
**/
|
|
49
49
|
@withStyle(generateStyle, generateComponentTheme)
|
|
50
50
|
@testable()
|
|
@@ -61,21 +61,18 @@ class ToggleDetails extends Component<ToggleDetailsProps> {
|
|
|
61
61
|
iconExpanded: IconArrowOpenDownSolid,
|
|
62
62
|
iconPosition: 'start',
|
|
63
63
|
defaultExpanded: false,
|
|
64
|
-
// @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
|
|
65
|
-
onToggle: function (event, expanded) {},
|
|
66
64
|
children: null
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
ref: Element | null = null
|
|
68
|
+
_button: HTMLElement | null = null
|
|
70
69
|
|
|
71
70
|
get focused() {
|
|
72
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property '_button' does not exist on type 'ToggleD... Remove this comment to see the full error message
|
|
73
71
|
return isActiveElement(this._button)
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
focus() {
|
|
77
|
-
|
|
78
|
-
this._button.focus()
|
|
75
|
+
this._button?.focus()
|
|
79
76
|
}
|
|
80
77
|
|
|
81
78
|
componentDidMount() {
|
|
@@ -86,11 +83,9 @@ class ToggleDetails extends Component<ToggleDetailsProps> {
|
|
|
86
83
|
this.props.makeStyles?.({ animate: true } as ToggleDetailsStyleProps)
|
|
87
84
|
}
|
|
88
85
|
|
|
89
|
-
|
|
90
|
-
getButtonRef = (el) => (this._button = el)
|
|
86
|
+
getButtonRef = (el: Element | null) => (this._button = el as HTMLElement)
|
|
91
87
|
|
|
92
|
-
|
|
93
|
-
renderSummary(expanded) {
|
|
88
|
+
renderSummary(expanded: boolean) {
|
|
94
89
|
const { summary, iconPosition } = this.props
|
|
95
90
|
|
|
96
91
|
return (
|
|
@@ -102,17 +97,18 @@ class ToggleDetails extends Component<ToggleDetailsProps> {
|
|
|
102
97
|
)
|
|
103
98
|
}
|
|
104
99
|
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
renderToggle(
|
|
101
|
+
toggleProps: ReturnType<ExpandableToggleProps>,
|
|
102
|
+
expanded: boolean
|
|
103
|
+
) {
|
|
107
104
|
const { variant } = this.props
|
|
108
105
|
|
|
109
106
|
const props = {
|
|
110
107
|
...omitProps(this.props, ToggleDetails.allowedProps),
|
|
111
108
|
...toggleProps,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
109
|
+
children: this.renderSummary(expanded)
|
|
110
|
+
// spread operator makes toggleProps loose Record<string, any>>
|
|
111
|
+
} as Record<string, any>
|
|
116
112
|
const summary = this.renderSummary(expanded)
|
|
117
113
|
|
|
118
114
|
if (variant === 'filled') {
|
|
@@ -146,20 +142,17 @@ class ToggleDetails extends Component<ToggleDetailsProps> {
|
|
|
146
142
|
}
|
|
147
143
|
}
|
|
148
144
|
|
|
149
|
-
|
|
150
|
-
renderIcon(expanded) {
|
|
145
|
+
renderIcon(expanded: boolean) {
|
|
151
146
|
const Icon = expanded ? this.props.iconExpanded : this.props.icon
|
|
152
147
|
|
|
153
|
-
return this.props.children ? (
|
|
148
|
+
return this.props.children && Icon ? (
|
|
154
149
|
<span css={this.props.styles?.icon}>
|
|
155
|
-
{/* @ts-expect-error ts-migrate(2604) FIXME: JSX element type 'Icon' does not have any construc... Remove this comment to see the full error message */}
|
|
156
150
|
<Icon />
|
|
157
151
|
</span>
|
|
158
152
|
) : null
|
|
159
153
|
}
|
|
160
154
|
|
|
161
|
-
|
|
162
|
-
renderDetails(expanded, detailsProps) {
|
|
155
|
+
renderDetails(expanded: boolean, detailsProps: { id: string }) {
|
|
163
156
|
const { children } = this.props
|
|
164
157
|
const expandedStyles = expanded ? { display: 'block' } : { display: 'none' }
|
|
165
158
|
return (
|
|
@@ -173,10 +166,10 @@ class ToggleDetails extends Component<ToggleDetailsProps> {
|
|
|
173
166
|
return <div css={this.props.styles?.content}>{this.props.children}</div>
|
|
174
167
|
}
|
|
175
168
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
169
|
+
handleToggle = (event: React.MouseEvent, expanded: boolean) => {
|
|
170
|
+
if (typeof this.props.onToggle === 'function') {
|
|
171
|
+
this.props.onToggle(event, expanded)
|
|
172
|
+
}
|
|
180
173
|
this.props.makeStyles?.({ animate: true })
|
|
181
174
|
}
|
|
182
175
|
|
|
@@ -36,15 +36,42 @@ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
|
36
36
|
|
|
37
37
|
type ToggleDetailsOwnProps = {
|
|
38
38
|
variant?: 'default' | 'filled'
|
|
39
|
+
/**
|
|
40
|
+
* The summary that displays and can be interacted with
|
|
41
|
+
*/
|
|
39
42
|
summary: React.ReactNode
|
|
43
|
+
/**
|
|
44
|
+
* Whether the content is expanded or hidden
|
|
45
|
+
*/
|
|
40
46
|
expanded?: boolean // TODO: controllable(PropTypes.bool, 'onToggle', 'defaultExpanded')
|
|
47
|
+
/**
|
|
48
|
+
* Whether the content is initially expanded or hidden (uncontrolled)
|
|
49
|
+
*/
|
|
41
50
|
defaultExpanded?: boolean
|
|
42
|
-
onToggle?: (
|
|
43
|
-
|
|
44
|
-
|
|
51
|
+
onToggle?: (event: React.MouseEvent, expanded: boolean) => 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
|
+
*/
|
|
45
63
|
iconPosition?: 'start' | 'end'
|
|
64
|
+
/**
|
|
65
|
+
* should the summary fill the width of its container
|
|
66
|
+
*/
|
|
46
67
|
fluidWidth?: boolean
|
|
68
|
+
/**
|
|
69
|
+
* Choose a size for the expand/collapse icon
|
|
70
|
+
*/
|
|
47
71
|
size?: 'small' | 'medium' | 'large'
|
|
72
|
+
/**
|
|
73
|
+
* The toggleable content passed inside the ToggleDetails component
|
|
74
|
+
*/
|
|
48
75
|
children?: React.ReactNode
|
|
49
76
|
}
|
|
50
77
|
|
|
@@ -72,42 +99,15 @@ type ToggleDetailsStyleProps = {
|
|
|
72
99
|
|
|
73
100
|
const propTypes: PropValidators<PropKeys> = {
|
|
74
101
|
variant: PropTypes.oneOf(['default', 'filled']),
|
|
75
|
-
/**
|
|
76
|
-
* The summary that displays and can be interacted with
|
|
77
|
-
*/
|
|
78
102
|
summary: PropTypes.node.isRequired,
|
|
79
|
-
/**
|
|
80
|
-
* Whether the content is expanded or hidden
|
|
81
|
-
*/
|
|
82
103
|
expanded: controllable(PropTypes.bool, 'onToggle', 'defaultExpanded'),
|
|
83
|
-
/**
|
|
84
|
-
* Whether the content is initially expanded or hidden (uncontrolled)
|
|
85
|
-
*/
|
|
86
104
|
defaultExpanded: PropTypes.bool,
|
|
87
105
|
onToggle: PropTypes.func,
|
|
88
|
-
/**
|
|
89
|
-
* The icon to display next to the summary text when content is hidden
|
|
90
|
-
*/
|
|
91
106
|
icon: PropTypes.func,
|
|
92
|
-
/**
|
|
93
|
-
* The icon to display when content is expanded
|
|
94
|
-
*/
|
|
95
107
|
iconExpanded: PropTypes.func,
|
|
96
|
-
/**
|
|
97
|
-
* Icon position at the start or end of the summary text
|
|
98
|
-
*/
|
|
99
108
|
iconPosition: PropTypes.oneOf(['start', 'end']),
|
|
100
|
-
/**
|
|
101
|
-
* should the summary fill the width of its container
|
|
102
|
-
*/
|
|
103
109
|
fluidWidth: PropTypes.bool,
|
|
104
|
-
/**
|
|
105
|
-
* The toggleable content passed inside the ToggleDetails component
|
|
106
|
-
*/
|
|
107
110
|
children: PropTypes.node,
|
|
108
|
-
/**
|
|
109
|
-
* Choose a size for the expand/collapse icon
|
|
110
|
-
*/
|
|
111
111
|
size: PropTypes.oneOf(['small', 'medium', 'large'])
|
|
112
112
|
}
|
|
113
113
|
|
|
@@ -27,11 +27,13 @@ import React, { Component } from 'react'
|
|
|
27
27
|
import {
|
|
28
28
|
omitProps,
|
|
29
29
|
pickProps,
|
|
30
|
-
getElementType
|
|
30
|
+
getElementType,
|
|
31
|
+
callRenderProp
|
|
31
32
|
} from '@instructure/ui-react-utils'
|
|
32
33
|
import { IconButton } from '@instructure/ui-buttons'
|
|
33
34
|
import { Transition } from '@instructure/ui-motion'
|
|
34
35
|
import { Expandable } from '@instructure/ui-expandable'
|
|
36
|
+
import type { ExpandableToggleProps } from '@instructure/ui-expandable'
|
|
35
37
|
import { isActiveElement } from '@instructure/ui-dom-utils'
|
|
36
38
|
import { Flex } from '@instructure/ui-flex'
|
|
37
39
|
import { View } from '@instructure/ui-view'
|
|
@@ -47,6 +49,7 @@ import { allowedProps, propTypes } from './props'
|
|
|
47
49
|
---
|
|
48
50
|
category: components
|
|
49
51
|
---
|
|
52
|
+
@tsProps
|
|
50
53
|
**/
|
|
51
54
|
@testable()
|
|
52
55
|
class ToggleGroup extends Component<ToggleGroupProps> {
|
|
@@ -60,17 +63,13 @@ class ToggleGroup extends Component<ToggleGroupProps> {
|
|
|
60
63
|
icon: IconArrowOpenEndSolid,
|
|
61
64
|
iconExpanded: IconArrowOpenDownSolid,
|
|
62
65
|
defaultExpanded: false,
|
|
63
|
-
// @ts-expect-error ts-migrate(6133) FIXME: 'event' is declared but its value is never read.
|
|
64
|
-
onToggle: function (event, expanded) {},
|
|
65
66
|
transition: true,
|
|
66
67
|
as: 'span',
|
|
67
|
-
// @ts-expect-error ts-migrate(6133) FIXME: 'el' is declared but its value is never read.
|
|
68
|
-
elementRef: (el) => {},
|
|
69
68
|
border: true
|
|
70
69
|
} as const
|
|
71
70
|
|
|
72
71
|
ref: Element | null = null
|
|
73
|
-
_button:
|
|
72
|
+
_button: HTMLElement | null = null
|
|
74
73
|
_shouldTransition = false
|
|
75
74
|
|
|
76
75
|
handleRef = (el: Element | null) => {
|
|
@@ -84,7 +83,7 @@ class ToggleGroup extends Component<ToggleGroupProps> {
|
|
|
84
83
|
}
|
|
85
84
|
|
|
86
85
|
handleButtonRef = (el: Element | null) => {
|
|
87
|
-
this._button = el
|
|
86
|
+
this._button = el as HTMLElement
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
get focused() {
|
|
@@ -92,23 +91,22 @@ class ToggleGroup extends Component<ToggleGroupProps> {
|
|
|
92
91
|
}
|
|
93
92
|
|
|
94
93
|
focus() {
|
|
95
|
-
|
|
96
|
-
this._button.focus()
|
|
94
|
+
this._button?.focus()
|
|
97
95
|
}
|
|
98
96
|
|
|
99
97
|
componentDidMount() {
|
|
100
98
|
this._shouldTransition = true
|
|
101
99
|
}
|
|
102
100
|
|
|
103
|
-
|
|
104
|
-
renderIcon(expanded) {
|
|
101
|
+
renderIcon(expanded: boolean) {
|
|
105
102
|
const Icon = expanded ? this.props.iconExpanded : this.props.icon
|
|
106
|
-
|
|
107
|
-
return <Icon />
|
|
103
|
+
return Icon ? callRenderProp(Icon) : null
|
|
108
104
|
}
|
|
109
105
|
|
|
110
|
-
|
|
111
|
-
|
|
106
|
+
renderToggle(
|
|
107
|
+
toggleProps: ReturnType<ExpandableToggleProps>,
|
|
108
|
+
expanded: boolean
|
|
109
|
+
) {
|
|
112
110
|
const { toggleLabel, size } = this.props
|
|
113
111
|
let label
|
|
114
112
|
if (typeof toggleLabel === 'function') {
|
|
@@ -116,9 +114,11 @@ class ToggleGroup extends Component<ToggleGroupProps> {
|
|
|
116
114
|
} else {
|
|
117
115
|
label = toggleLabel
|
|
118
116
|
}
|
|
117
|
+
|
|
118
|
+
const props = { ...toggleProps } as Record<string, any>
|
|
119
119
|
return (
|
|
120
120
|
<IconButton
|
|
121
|
-
{...
|
|
121
|
+
{...props}
|
|
122
122
|
withBackground={false}
|
|
123
123
|
withBorder={false}
|
|
124
124
|
size={size === 'large' ? 'medium' : 'small'}
|
|
@@ -130,8 +130,7 @@ class ToggleGroup extends Component<ToggleGroupProps> {
|
|
|
130
130
|
)
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
renderDetails(detailsProps) {
|
|
133
|
+
renderDetails(detailsProps: { id: string }) {
|
|
135
134
|
return (
|
|
136
135
|
<View
|
|
137
136
|
{...detailsProps}
|
package/src/ToggleGroup/props.ts
CHANGED
|
@@ -34,78 +34,78 @@ import {
|
|
|
34
34
|
} from '@instructure/shared-types'
|
|
35
35
|
|
|
36
36
|
type ToggleGroupOwnProps = {
|
|
37
|
-
children: React.ReactNode
|
|
38
|
-
summary: React.ReactNode
|
|
39
|
-
toggleLabel: React.ReactNode | ((...args: any[]) => any)
|
|
40
|
-
as?: AsElementType
|
|
41
|
-
elementRef?: (element: Element | null) => void
|
|
42
|
-
size?: 'small' | 'medium' | 'large'
|
|
43
|
-
expanded?: any // TODO: controllable(PropTypes.bool, 'onToggle', 'defaultExpanded')
|
|
44
|
-
defaultExpanded?: boolean
|
|
45
|
-
onToggle?: (...args: any[]) => any
|
|
46
|
-
icon?: React.ReactNode | ((...args: any[]) => any)
|
|
47
|
-
iconExpanded?: React.ReactNode | ((...args: any[]) => any)
|
|
48
|
-
transition?: boolean
|
|
49
|
-
border?: boolean
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
type PropKeys = keyof ToggleGroupOwnProps
|
|
53
|
-
|
|
54
|
-
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
55
|
-
|
|
56
|
-
type ToggleGroupProps = ToggleGroupOwnProps &
|
|
57
|
-
OtherHTMLAttributes<ToggleGroupOwnProps>
|
|
58
|
-
|
|
59
|
-
const propTypes: PropValidators<PropKeys> = {
|
|
60
37
|
/**
|
|
61
38
|
* the content to show and hide
|
|
62
39
|
*/
|
|
63
|
-
children:
|
|
40
|
+
children: React.ReactNode
|
|
64
41
|
/**
|
|
65
42
|
* the content area next to the toggle button
|
|
66
43
|
*/
|
|
67
|
-
summary:
|
|
44
|
+
summary: React.ReactNode
|
|
68
45
|
/**
|
|
69
46
|
* provides a screenreader label for the toggle button
|
|
70
47
|
* (takes `expanded` as an argument if a function)
|
|
71
48
|
*/
|
|
72
|
-
toggleLabel:
|
|
49
|
+
toggleLabel: React.ReactNode | ((expanded: boolean) => React.ReactNode)
|
|
73
50
|
/**
|
|
74
51
|
* the element type to render as
|
|
75
52
|
*/
|
|
76
|
-
as
|
|
53
|
+
as?: AsElementType
|
|
77
54
|
/**
|
|
78
55
|
* provides a reference to the underlying html root element
|
|
79
56
|
*/
|
|
80
|
-
elementRef:
|
|
81
|
-
size
|
|
57
|
+
elementRef?: (element: Element | null) => void
|
|
58
|
+
size?: 'small' | 'medium' | 'large'
|
|
82
59
|
/**
|
|
83
60
|
* Whether the content is expanded or hidden
|
|
84
61
|
*/
|
|
85
|
-
expanded: controllable(PropTypes.bool, 'onToggle', 'defaultExpanded')
|
|
62
|
+
expanded?: boolean // TODO: controllable(PropTypes.bool, 'onToggle', 'defaultExpanded')
|
|
86
63
|
/**
|
|
87
64
|
* Whether the content is initially expanded or hidden (uncontrolled)
|
|
88
65
|
*/
|
|
89
|
-
defaultExpanded
|
|
66
|
+
defaultExpanded?: boolean
|
|
90
67
|
/**
|
|
91
68
|
* Fired when the content display is toggled
|
|
92
69
|
*/
|
|
93
|
-
onToggle:
|
|
70
|
+
onToggle?: (event: React.MouseEvent, expanded: boolean) => void
|
|
94
71
|
/**
|
|
95
72
|
* The icon displayed in the toggle button when the content is hidden
|
|
96
73
|
*/
|
|
97
|
-
icon
|
|
74
|
+
icon?: React.ReactNode | ((...args: any[]) => React.ReactElement)
|
|
98
75
|
/**
|
|
99
76
|
* The icon displayed in the toggle button when the content is showing
|
|
100
77
|
*/
|
|
101
|
-
iconExpanded
|
|
78
|
+
iconExpanded?: React.ReactNode | ((...args: any[]) => React.ReactElement)
|
|
102
79
|
/**
|
|
103
80
|
* Transition content into view
|
|
104
81
|
*/
|
|
105
|
-
transition
|
|
82
|
+
transition?: boolean
|
|
106
83
|
/**
|
|
107
84
|
* Toggle the border around the component
|
|
108
85
|
*/
|
|
86
|
+
border?: boolean
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
type PropKeys = keyof ToggleGroupOwnProps
|
|
90
|
+
|
|
91
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
92
|
+
|
|
93
|
+
type ToggleGroupProps = ToggleGroupOwnProps &
|
|
94
|
+
OtherHTMLAttributes<ToggleGroupOwnProps>
|
|
95
|
+
|
|
96
|
+
const propTypes: PropValidators<PropKeys> = {
|
|
97
|
+
children: PropTypes.node.isRequired,
|
|
98
|
+
summary: PropTypes.node.isRequired,
|
|
99
|
+
toggleLabel: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,
|
|
100
|
+
as: PropTypes.elementType,
|
|
101
|
+
elementRef: PropTypes.func,
|
|
102
|
+
size: PropTypes.oneOf(['small', 'medium', 'large']),
|
|
103
|
+
expanded: controllable(PropTypes.bool, 'onToggle', 'defaultExpanded'),
|
|
104
|
+
defaultExpanded: PropTypes.bool,
|
|
105
|
+
onToggle: PropTypes.func,
|
|
106
|
+
icon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
107
|
+
iconExpanded: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
|
|
108
|
+
transition: PropTypes.bool,
|
|
109
109
|
border: PropTypes.bool
|
|
110
110
|
}
|
|
111
111
|
|