@instructure/ui-drawer-layout 8.14.1-snapshot.7 → 8.15.1-snapshot.2
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 +4 -0
- package/es/DrawerLayout/DrawerContent/DrawerContentLocator.js +2 -1
- package/es/DrawerLayout/DrawerContent/index.js +42 -43
- package/es/DrawerLayout/DrawerContent/props.js +0 -4
- package/es/DrawerLayout/DrawerContent/styles.js +1 -1
- package/es/DrawerLayout/DrawerLayoutLocator.js +2 -1
- package/es/DrawerLayout/DrawerTray/DrawerTrayLocator.js +2 -1
- package/es/DrawerLayout/DrawerTray/index.js +61 -66
- package/es/DrawerLayout/DrawerTray/props.js +0 -70
- package/es/DrawerLayout/index.js +19 -13
- package/es/DrawerLayout/props.js +0 -13
- package/lib/DrawerLayout/DrawerContent/DrawerContentLocator.js +1 -0
- package/lib/DrawerLayout/DrawerContent/index.js +42 -43
- package/lib/DrawerLayout/DrawerContent/props.js +0 -4
- package/lib/DrawerLayout/DrawerContent/styles.js +1 -1
- package/lib/DrawerLayout/DrawerLayoutLocator.js +1 -0
- package/lib/DrawerLayout/DrawerTray/DrawerTrayLocator.js +1 -0
- package/lib/DrawerLayout/DrawerTray/index.js +61 -66
- package/lib/DrawerLayout/DrawerTray/props.js +0 -70
- package/lib/DrawerLayout/index.js +21 -13
- package/lib/DrawerLayout/props.js +0 -13
- package/package.json +22 -22
- package/src/DrawerLayout/DrawerContent/index.tsx +38 -57
- package/src/DrawerLayout/DrawerContent/props.ts +13 -10
- package/src/DrawerLayout/DrawerContent/styles.ts +3 -4
- package/src/DrawerLayout/DrawerTray/index.tsx +31 -33
- package/src/DrawerLayout/DrawerTray/props.ts +110 -69
- package/src/DrawerLayout/__fixtures__/DrawerLayout.fixture.tsx +14 -13
- package/src/DrawerLayout/index.tsx +74 -86
- package/src/DrawerLayout/props.ts +22 -13
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/DrawerLayout/DrawerContent/DrawerContentLocator.d.ts +4 -4
- package/types/DrawerLayout/DrawerContent/index.d.ts +28 -19
- package/types/DrawerLayout/DrawerContent/index.d.ts.map +1 -1
- package/types/DrawerLayout/DrawerContent/props.d.ts +13 -6
- package/types/DrawerLayout/DrawerContent/props.d.ts.map +1 -1
- package/types/DrawerLayout/DrawerContent/styles.d.ts +2 -2
- package/types/DrawerLayout/DrawerContent/styles.d.ts.map +1 -1
- package/types/DrawerLayout/DrawerLayoutLocator.d.ts +14 -14
- package/types/DrawerLayout/DrawerTray/DrawerTrayLocator.d.ts +4 -4
- package/types/DrawerLayout/DrawerTray/index.d.ts +46 -22
- package/types/DrawerLayout/DrawerTray/index.d.ts.map +1 -1
- package/types/DrawerLayout/DrawerTray/props.d.ts +74 -16
- package/types/DrawerLayout/DrawerTray/props.d.ts.map +1 -1
- package/types/DrawerLayout/__fixtures__/DrawerLayout.fixture.d.ts +11 -1
- package/types/DrawerLayout/__fixtures__/DrawerLayout.fixture.d.ts.map +1 -1
- package/types/DrawerLayout/index.d.ts +116 -23
- package/types/DrawerLayout/index.d.ts.map +1 -1
- package/types/DrawerLayout/props.d.ts +19 -3
- package/types/DrawerLayout/props.d.ts.map +1 -1
|
@@ -21,12 +21,23 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import React, { Component } from 'react'
|
|
25
26
|
import PropTypes from 'prop-types'
|
|
26
27
|
|
|
27
28
|
import { DrawerLayout } from '../index'
|
|
29
|
+
import type { DrawerLayoutProps } from '../props'
|
|
30
|
+
import type { DrawerLayoutTrayProps } from '../DrawerTray/props'
|
|
31
|
+
|
|
32
|
+
type DrawerLayoutFixtureProps = {
|
|
33
|
+
layoutWidth?: string | number
|
|
34
|
+
trayWidth?: string | number
|
|
35
|
+
placement?: DrawerLayoutTrayProps['placement']
|
|
36
|
+
open?: DrawerLayoutTrayProps['open']
|
|
37
|
+
onOverlayTrayChange?: DrawerLayoutProps['onOverlayTrayChange']
|
|
38
|
+
}
|
|
28
39
|
|
|
29
|
-
export default class DrawerLayoutFixture extends Component {
|
|
40
|
+
export default class DrawerLayoutFixture extends Component<DrawerLayoutFixtureProps> {
|
|
30
41
|
static propTypes = {
|
|
31
42
|
layoutWidth: PropTypes.string,
|
|
32
43
|
trayWidth: PropTypes.string,
|
|
@@ -44,18 +55,8 @@ export default class DrawerLayoutFixture extends Component {
|
|
|
44
55
|
}
|
|
45
56
|
|
|
46
57
|
render() {
|
|
47
|
-
const {
|
|
48
|
-
|
|
49
|
-
layoutWidth,
|
|
50
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'trayWidth' does not exist on type 'Reado... Remove this comment to see the full error message
|
|
51
|
-
trayWidth,
|
|
52
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'open' does not exist on type 'Readonly<{... Remove this comment to see the full error message
|
|
53
|
-
open,
|
|
54
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'placement' does not exist on type 'Reado... Remove this comment to see the full error message
|
|
55
|
-
placement,
|
|
56
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'onOverlayTrayChange' does not exist on t... Remove this comment to see the full error message
|
|
57
|
-
onOverlayTrayChange
|
|
58
|
-
} = this.props
|
|
58
|
+
const { layoutWidth, trayWidth, open, placement, onOverlayTrayChange } =
|
|
59
|
+
this.props
|
|
59
60
|
|
|
60
61
|
return (
|
|
61
62
|
<div style={{ width: layoutWidth }}>
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
/** @jsx jsx */
|
|
26
|
-
import { Children, Component, createContext } from 'react'
|
|
26
|
+
import React, { Children, Component, createContext } from 'react'
|
|
27
27
|
|
|
28
28
|
import { textDirectionContextConsumer } from '@instructure/ui-i18n'
|
|
29
29
|
import {
|
|
@@ -37,41 +37,55 @@ import { uid } from '@instructure/uid'
|
|
|
37
37
|
import { testable } from '@instructure/ui-testable'
|
|
38
38
|
|
|
39
39
|
import { mirrorHorizontalPlacement } from '@instructure/ui-position'
|
|
40
|
+
import type { PlacementPropValues } from '@instructure/ui-position'
|
|
41
|
+
|
|
40
42
|
import { DrawerContent } from './DrawerContent'
|
|
43
|
+
import type {
|
|
44
|
+
DrawerLayoutContentProps,
|
|
45
|
+
DrawerContentSize
|
|
46
|
+
} from './DrawerContent/props'
|
|
41
47
|
import { DrawerTray } from './DrawerTray'
|
|
48
|
+
import type { DrawerLayoutTrayProps } from './DrawerTray/props'
|
|
42
49
|
|
|
43
50
|
import { withStyle, jsx } from '@instructure/emotion'
|
|
44
51
|
import generateStyle from './styles'
|
|
45
52
|
|
|
46
53
|
import { propTypes, allowedProps } from './props'
|
|
47
|
-
import type { DrawerLayoutProps } from './props'
|
|
54
|
+
import type { DrawerLayoutProps, DrawerLayoutState } from './props'
|
|
55
|
+
|
|
56
|
+
type TrayChild = React.ComponentElement<
|
|
57
|
+
DrawerLayoutTrayProps & React.Attributes,
|
|
58
|
+
DrawerTray
|
|
59
|
+
>
|
|
60
|
+
type ContentChild = React.ComponentElement<
|
|
61
|
+
DrawerLayoutContentProps & React.Attributes,
|
|
62
|
+
DrawerContent
|
|
63
|
+
>
|
|
64
|
+
type DrawerChildren = (TrayChild | ContentChild)[]
|
|
48
65
|
|
|
49
66
|
/**
|
|
50
67
|
---
|
|
51
68
|
category: components
|
|
52
69
|
---
|
|
70
|
+
@tsProps
|
|
53
71
|
**/
|
|
54
72
|
@withStyle(generateStyle, null)
|
|
55
73
|
@textDirectionContextConsumer()
|
|
56
74
|
@testable()
|
|
57
|
-
class DrawerLayout extends Component<DrawerLayoutProps> {
|
|
75
|
+
class DrawerLayout extends Component<DrawerLayoutProps, DrawerLayoutState> {
|
|
58
76
|
static readonly componentId = 'DrawerLayout'
|
|
59
77
|
|
|
60
78
|
static locatorAttribute = 'data-drawer-layout'
|
|
61
79
|
static propTypes = propTypes
|
|
62
80
|
static allowedProps = allowedProps
|
|
63
81
|
static defaultProps = {
|
|
64
|
-
|
|
65
|
-
minWidth: '30rem',
|
|
66
|
-
// @ts-expect-error ts-migrate(6133) FIXME: 'shouldOverlayTray' is declared but its value is n... Remove this comment to see the full error message
|
|
67
|
-
onOverlayTrayChange: (shouldOverlayTray) => {}
|
|
82
|
+
minWidth: '30rem'
|
|
68
83
|
}
|
|
69
84
|
|
|
70
85
|
static Content = DrawerContent
|
|
71
86
|
static Tray = DrawerTray
|
|
72
87
|
|
|
73
|
-
|
|
74
|
-
constructor(props) {
|
|
88
|
+
constructor(props: DrawerLayoutProps) {
|
|
75
89
|
super(props)
|
|
76
90
|
|
|
77
91
|
this.state = {
|
|
@@ -80,11 +94,12 @@ class DrawerLayout extends Component<DrawerLayoutProps> {
|
|
|
80
94
|
contentWidth: 0
|
|
81
95
|
}
|
|
82
96
|
|
|
83
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property '_id' does not exist on type 'DrawerLayou... Remove this comment to see the full error message
|
|
84
97
|
this._id = uid('DrawerLayout')
|
|
85
98
|
}
|
|
86
99
|
|
|
87
|
-
|
|
100
|
+
private readonly _id: string
|
|
101
|
+
private _content: HTMLDivElement | null = null
|
|
102
|
+
private _tray: HTMLDivElement | null = null
|
|
88
103
|
|
|
89
104
|
ref: Element | null = null
|
|
90
105
|
|
|
@@ -93,45 +108,38 @@ class DrawerLayout extends Component<DrawerLayoutProps> {
|
|
|
93
108
|
}
|
|
94
109
|
|
|
95
110
|
componentDidMount() {
|
|
96
|
-
|
|
97
|
-
this.props.makeStyles()
|
|
111
|
+
this.props.makeStyles?.()
|
|
98
112
|
}
|
|
99
113
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
// @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
|
|
103
|
-
this.props.makeStyles()
|
|
114
|
+
componentDidUpdate() {
|
|
115
|
+
this.props.makeStyles?.()
|
|
104
116
|
}
|
|
105
117
|
|
|
106
118
|
get trayProps() {
|
|
107
|
-
const tray =
|
|
108
|
-
|
|
109
|
-
)
|
|
110
|
-
|
|
119
|
+
const tray = (
|
|
120
|
+
Children.toArray(this.props.children) as DrawerChildren
|
|
121
|
+
).filter((child) =>
|
|
122
|
+
matchComponentTypes<TrayChild>(child, [DrawerTray])
|
|
123
|
+
)[0] as TrayChild
|
|
111
124
|
return tray.props
|
|
112
125
|
}
|
|
113
126
|
|
|
114
|
-
get trayPlacement() {
|
|
127
|
+
get trayPlacement(): PlacementPropValues {
|
|
115
128
|
const { placement, dir = this.props.dir } = this.trayProps
|
|
116
129
|
const isRtl = dir === textDirectionContextConsumer.DIRECTION.rtl
|
|
117
|
-
return isRtl ? mirrorHorizontalPlacement(placement
|
|
130
|
+
return isRtl ? mirrorHorizontalPlacement(placement!, ' ') : placement!
|
|
118
131
|
}
|
|
119
132
|
|
|
120
133
|
get contentMargin() {
|
|
121
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'trayWidth' does not exist on type 'Reado... Remove this comment to see the full error message
|
|
122
134
|
const trayWidth = this.state.trayWidth || 0
|
|
123
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'shouldOverlayTray' does not exist on typ... Remove this comment to see the full error message
|
|
124
135
|
return this.state.shouldOverlayTray ? 0 : trayWidth
|
|
125
136
|
}
|
|
126
137
|
|
|
127
138
|
get contentStyle() {
|
|
128
139
|
const shouldOverlayTray = this.shouldOverlayTray(
|
|
129
|
-
this.props.minWidth
|
|
130
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'trayWidth' does not exist on type 'Reado... Remove this comment to see the full error message
|
|
140
|
+
this.props.minWidth!,
|
|
131
141
|
this.state.trayWidth,
|
|
132
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'contentWidth' does not exist on type 'Re... Remove this comment to see the full error message
|
|
133
142
|
this.state.contentWidth,
|
|
134
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'shouldOverlayTray' does not exist on typ... Remove this comment to see the full error message
|
|
135
143
|
this.state.shouldOverlayTray
|
|
136
144
|
)
|
|
137
145
|
let marginLeft = 0
|
|
@@ -153,14 +161,16 @@ class DrawerLayout extends Component<DrawerLayoutProps> {
|
|
|
153
161
|
}
|
|
154
162
|
}
|
|
155
163
|
|
|
156
|
-
|
|
157
|
-
handleTrayContentRef = (el) => {
|
|
158
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property '_tray' does not exist on type 'DrawerLay... Remove this comment to see the full error message
|
|
164
|
+
handleTrayContentRef = (el: HTMLDivElement | null) => {
|
|
159
165
|
this._tray = el
|
|
160
166
|
}
|
|
161
167
|
|
|
162
|
-
|
|
163
|
-
|
|
168
|
+
shouldOverlayTray(
|
|
169
|
+
minWidth: string,
|
|
170
|
+
trayWidth: number,
|
|
171
|
+
contentWidth: number,
|
|
172
|
+
trayIsOverlayed: boolean
|
|
173
|
+
) {
|
|
164
174
|
if (!this._content) return false
|
|
165
175
|
|
|
166
176
|
const minWidthPx = px(minWidth, this._content)
|
|
@@ -172,8 +182,12 @@ class DrawerLayout extends Component<DrawerLayoutProps> {
|
|
|
172
182
|
}
|
|
173
183
|
}
|
|
174
184
|
|
|
175
|
-
|
|
176
|
-
|
|
185
|
+
getNextState(
|
|
186
|
+
minWidth: string,
|
|
187
|
+
trayWidth: number,
|
|
188
|
+
contentWidth: number,
|
|
189
|
+
trayIsOverlayed: boolean
|
|
190
|
+
) {
|
|
177
191
|
const shouldOverlayTray = this.shouldOverlayTray(
|
|
178
192
|
minWidth,
|
|
179
193
|
trayWidth,
|
|
@@ -188,26 +202,22 @@ class DrawerLayout extends Component<DrawerLayoutProps> {
|
|
|
188
202
|
}
|
|
189
203
|
}
|
|
190
204
|
|
|
191
|
-
|
|
192
|
-
notifyOverlayTrayChange(shouldOverlayTray) {
|
|
205
|
+
notifyOverlayTrayChange(shouldOverlayTray: boolean) {
|
|
193
206
|
const { onOverlayTrayChange } = this.props
|
|
207
|
+
|
|
194
208
|
if (typeof onOverlayTrayChange === 'function') {
|
|
195
209
|
onOverlayTrayChange(shouldOverlayTray)
|
|
196
210
|
}
|
|
197
211
|
}
|
|
198
212
|
|
|
199
|
-
|
|
200
|
-
handleContentSizeChange = ({ width }) => {
|
|
213
|
+
handleContentSizeChange = ({ width }: DrawerContentSize) => {
|
|
201
214
|
this.setState((state, props) => {
|
|
202
215
|
const nextState = this.getNextState(
|
|
203
|
-
props.minWidth
|
|
204
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'trayWidth' does not exist on type 'Reado... Remove this comment to see the full error message
|
|
216
|
+
props.minWidth!,
|
|
205
217
|
state.trayWidth,
|
|
206
218
|
width,
|
|
207
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'shouldOverlayTray' does not exist on typ... Remove this comment to see the full error message
|
|
208
219
|
state.shouldOverlayTray
|
|
209
220
|
)
|
|
210
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'shouldOverlayTray' does not exist on typ... Remove this comment to see the full error message
|
|
211
221
|
if (state.shouldOverlayTray !== nextState.shouldOverlayTray) {
|
|
212
222
|
this.notifyOverlayTrayChange(nextState.shouldOverlayTray)
|
|
213
223
|
}
|
|
@@ -216,18 +226,15 @@ class DrawerLayout extends Component<DrawerLayoutProps> {
|
|
|
216
226
|
})
|
|
217
227
|
}
|
|
218
228
|
|
|
219
|
-
|
|
220
|
-
handleTraySizeChange = ({ width }) => {
|
|
229
|
+
handleTraySizeChange = ({ width }: { width: number }) => {
|
|
221
230
|
this.setState((state, props) => {
|
|
222
231
|
const nextState = this.getNextState(
|
|
223
|
-
props.minWidth
|
|
232
|
+
props.minWidth!,
|
|
224
233
|
width,
|
|
225
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'contentWidth' does not exist on type 'Re... Remove this comment to see the full error message
|
|
226
234
|
state.contentWidth,
|
|
227
235
|
true
|
|
228
236
|
)
|
|
229
237
|
|
|
230
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'shouldOverlayTray' does not exist on typ... Remove this comment to see the full error message
|
|
231
238
|
if (state.shouldOverlayTray !== nextState.shouldOverlayTray) {
|
|
232
239
|
this.notifyOverlayTrayChange(nextState.shouldOverlayTray)
|
|
233
240
|
}
|
|
@@ -239,9 +246,7 @@ class DrawerLayout extends Component<DrawerLayoutProps> {
|
|
|
239
246
|
handleTrayTransitionEnter = () => {
|
|
240
247
|
let width = 0
|
|
241
248
|
|
|
242
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property '_tray' does not exist on type 'DrawerLay... Remove this comment to see the full error message
|
|
243
249
|
if (this._tray) {
|
|
244
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property '_tray' does not exist on type 'DrawerLay... Remove this comment to see the full error message
|
|
245
250
|
width = getBoundingClientRect(this._tray).width
|
|
246
251
|
}
|
|
247
252
|
|
|
@@ -256,60 +261,47 @@ class DrawerLayout extends Component<DrawerLayoutProps> {
|
|
|
256
261
|
let trayCount = 0
|
|
257
262
|
let contentCount = 0
|
|
258
263
|
|
|
259
|
-
const
|
|
260
|
-
this.props.
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'contentWidth' does not exist on type 'Re... Remove this comment to see the full error message
|
|
264
|
-
this.state.contentWidth,
|
|
265
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'shouldOverlayTray' does not exist on typ... Remove this comment to see the full error message
|
|
266
|
-
this.state.shouldOverlayTray
|
|
267
|
-
)
|
|
268
|
-
|
|
269
|
-
// @ts-expect-error ts-migrate(6133) FIXME: 'index' is declared but its value is never read.
|
|
270
|
-
const children = Children.map<ReactNode, ReactNode>(
|
|
271
|
-
this.props.children,
|
|
272
|
-
// @ts-expect-error index is unused
|
|
273
|
-
(child, index) => {
|
|
274
|
-
if (matchComponentTypes(child, [DrawerTray])) {
|
|
264
|
+
const children = Children.map(
|
|
265
|
+
this.props.children as DrawerChildren,
|
|
266
|
+
(child, _index) => {
|
|
267
|
+
if (matchComponentTypes<TrayChild>(child, [DrawerTray])) {
|
|
275
268
|
trayCount++
|
|
276
269
|
return safeCloneElement(child, {
|
|
270
|
+
label: child.props.label,
|
|
277
271
|
key: child.props.label,
|
|
278
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property '_id' does not exist on type 'DrawerLayou... Remove this comment to see the full error message
|
|
279
272
|
[DrawerTray.locatorAttribute]: this._id,
|
|
280
273
|
contentRef: this.handleTrayContentRef,
|
|
281
274
|
onEnter: this.handleTrayTransitionEnter,
|
|
282
275
|
onExit: this.handleTrayTransitionExit
|
|
283
|
-
})
|
|
284
|
-
} else if (matchComponentTypes(child, [DrawerContent])) {
|
|
276
|
+
}) as TrayChild
|
|
277
|
+
} else if (matchComponentTypes<ContentChild>(child, [DrawerContent])) {
|
|
285
278
|
contentCount++
|
|
286
279
|
|
|
287
|
-
|
|
288
|
-
|
|
280
|
+
const handleContentRef = (el: HTMLDivElement | null) => {
|
|
281
|
+
const { contentRef } = child.props
|
|
282
|
+
|
|
289
283
|
this._content = el
|
|
290
284
|
|
|
291
|
-
if (typeof
|
|
292
|
-
|
|
285
|
+
if (typeof contentRef === 'function') {
|
|
286
|
+
contentRef(el)
|
|
293
287
|
}
|
|
294
288
|
}
|
|
295
289
|
|
|
296
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'trayWidth' does not exist on type 'Reado... Remove this comment to see the full error message
|
|
297
290
|
return this.state.trayWidth !== null
|
|
298
|
-
? safeCloneElement(child, {
|
|
291
|
+
? (safeCloneElement(child, {
|
|
292
|
+
label: child.props.label,
|
|
299
293
|
key: child.props.label,
|
|
300
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property '_id' does not exist on type 'DrawerLayou... Remove this comment to see the full error message
|
|
301
294
|
[DrawerContent.locatorAttribute]: this._id,
|
|
302
295
|
style: this.contentStyle,
|
|
303
296
|
onSizeChange: createChainedFunction(
|
|
304
297
|
this.handleContentSizeChange,
|
|
305
298
|
child.props.onSizeChange
|
|
306
299
|
),
|
|
307
|
-
contentRef: handleContentRef
|
|
308
|
-
|
|
309
|
-
})
|
|
300
|
+
contentRef: handleContentRef
|
|
301
|
+
}) as ContentChild)
|
|
310
302
|
: null
|
|
311
303
|
} else {
|
|
312
|
-
return child
|
|
304
|
+
return child as ContentChild | TrayChild
|
|
313
305
|
}
|
|
314
306
|
}
|
|
315
307
|
)
|
|
@@ -326,13 +318,9 @@ class DrawerLayout extends Component<DrawerLayoutProps> {
|
|
|
326
318
|
}
|
|
327
319
|
|
|
328
320
|
render() {
|
|
329
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property '_id' does not exist on type 'DrawerLayou... Remove this comment to see the full error message
|
|
330
321
|
const props = { [DrawerLayout.locatorAttribute]: this._id }
|
|
331
322
|
return (
|
|
332
|
-
<DrawerLayoutContext.Provider
|
|
333
|
-
// @ts-expect-error ts-migrate(2339) FIXME: Property 'shouldOverlayTray' does not exist on typ... Remove this comment to see the full error message
|
|
334
|
-
value={this.state.shouldOverlayTray}
|
|
335
|
-
>
|
|
323
|
+
<DrawerLayoutContext.Provider value={this.state.shouldOverlayTray}>
|
|
336
324
|
<div
|
|
337
325
|
{...props}
|
|
338
326
|
css={this.props.styles?.drawerLayout}
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
+
import React from 'react'
|
|
25
26
|
import PropTypes from 'prop-types'
|
|
26
27
|
|
|
27
28
|
import { Children as ChildrenPropTypes } from '@instructure/ui-prop-types'
|
|
@@ -35,9 +36,22 @@ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
|
35
36
|
import type { PropValidators } from '@instructure/shared-types'
|
|
36
37
|
|
|
37
38
|
type DrawerLayoutOwnProps = {
|
|
39
|
+
/**
|
|
40
|
+
* Exactly one of each of the following child types: `DrawerLayout.Content`, `DrawerLayout.Tray`
|
|
41
|
+
*/
|
|
38
42
|
children?: React.ReactNode // TODO: oneOfEach([DrawerContent, DrawerTray])
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Min width for the `<DrawerLayout.Content />`
|
|
46
|
+
*/
|
|
39
47
|
minWidth?: string
|
|
40
|
-
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Function called when the `<DrawerLayout.Content />` is resized and hits the `minWidth` breakpoint
|
|
51
|
+
* Called with a boolean value, `true` if the tray is now overlaying the content or `false` if
|
|
52
|
+
* it is side by side
|
|
53
|
+
*/
|
|
54
|
+
onOverlayTrayChange?: (shouldOverlayTray: boolean) => void
|
|
41
55
|
} & BidirectionalProps
|
|
42
56
|
|
|
43
57
|
type PropKeys = keyof DrawerLayoutOwnProps
|
|
@@ -49,20 +63,15 @@ type DrawerLayoutProps = DrawerLayoutOwnProps &
|
|
|
49
63
|
|
|
50
64
|
type DrawerLayoutStyle = ComponentStyle<'drawerLayout'>
|
|
51
65
|
|
|
66
|
+
type DrawerLayoutState = {
|
|
67
|
+
shouldOverlayTray: boolean
|
|
68
|
+
trayWidth: number
|
|
69
|
+
contentWidth: number
|
|
70
|
+
}
|
|
71
|
+
|
|
52
72
|
const propTypes: PropValidators<PropKeys> = {
|
|
53
|
-
/**
|
|
54
|
-
* Exactly one of each of the following child types: `DrawerLayout.Content`, `DrawerLayout.Tray`
|
|
55
|
-
*/
|
|
56
73
|
children: ChildrenPropTypes.oneOfEach([DrawerContent, DrawerTray]),
|
|
57
|
-
/**
|
|
58
|
-
* Min width for the `<DrawerLayout.Content />`
|
|
59
|
-
*/
|
|
60
74
|
minWidth: PropTypes.string,
|
|
61
|
-
/**
|
|
62
|
-
* Function called when the `<DrawerLayout.Content />` is resized and hits the `minWidth` breakpoint
|
|
63
|
-
* Called with a boolean value, `true` if the tray is now overlaying the content or `false` if
|
|
64
|
-
* it is side by side
|
|
65
|
-
*/
|
|
66
75
|
onOverlayTrayChange: PropTypes.func,
|
|
67
76
|
dir: PropTypes.oneOf(Object.values(textDirectionContextConsumer.DIRECTION))
|
|
68
77
|
}
|
|
@@ -74,5 +83,5 @@ const allowedProps: AllowedPropKeys = [
|
|
|
74
83
|
'dir'
|
|
75
84
|
]
|
|
76
85
|
|
|
77
|
-
export type { DrawerLayoutProps, DrawerLayoutStyle }
|
|
86
|
+
export type { DrawerLayoutProps, DrawerLayoutState, DrawerLayoutStyle }
|
|
78
87
|
export { propTypes, allowedProps }
|