@instructure/ui-drawer-layout 8.14.1-snapshot.6 → 8.14.1-snapshot.63

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 (49) hide show
  1. package/es/DrawerLayout/DrawerContent/DrawerContentLocator.js +2 -1
  2. package/es/DrawerLayout/DrawerContent/index.js +42 -43
  3. package/es/DrawerLayout/DrawerContent/props.js +0 -4
  4. package/es/DrawerLayout/DrawerContent/styles.js +1 -1
  5. package/es/DrawerLayout/DrawerLayoutLocator.js +2 -1
  6. package/es/DrawerLayout/DrawerTray/DrawerTrayLocator.js +2 -1
  7. package/es/DrawerLayout/DrawerTray/index.js +61 -66
  8. package/es/DrawerLayout/DrawerTray/props.js +0 -70
  9. package/es/DrawerLayout/index.js +19 -13
  10. package/es/DrawerLayout/props.js +0 -13
  11. package/lib/DrawerLayout/DrawerContent/DrawerContentLocator.js +1 -0
  12. package/lib/DrawerLayout/DrawerContent/index.js +42 -43
  13. package/lib/DrawerLayout/DrawerContent/props.js +0 -4
  14. package/lib/DrawerLayout/DrawerContent/styles.js +1 -1
  15. package/lib/DrawerLayout/DrawerLayoutLocator.js +1 -0
  16. package/lib/DrawerLayout/DrawerTray/DrawerTrayLocator.js +1 -0
  17. package/lib/DrawerLayout/DrawerTray/index.js +61 -66
  18. package/lib/DrawerLayout/DrawerTray/props.js +0 -70
  19. package/lib/DrawerLayout/index.js +21 -13
  20. package/lib/DrawerLayout/props.js +0 -13
  21. package/package.json +22 -22
  22. package/src/DrawerLayout/DrawerContent/index.tsx +38 -57
  23. package/src/DrawerLayout/DrawerContent/props.ts +13 -10
  24. package/src/DrawerLayout/DrawerContent/styles.ts +3 -4
  25. package/src/DrawerLayout/DrawerTray/index.tsx +31 -33
  26. package/src/DrawerLayout/DrawerTray/props.ts +110 -69
  27. package/src/DrawerLayout/__fixtures__/DrawerLayout.fixture.tsx +14 -13
  28. package/src/DrawerLayout/index.tsx +75 -87
  29. package/src/DrawerLayout/props.ts +22 -13
  30. package/tsconfig.build.tsbuildinfo +1 -1
  31. package/types/DrawerLayout/DrawerContent/DrawerContentLocator.d.ts +4 -4
  32. package/types/DrawerLayout/DrawerContent/index.d.ts +28 -19
  33. package/types/DrawerLayout/DrawerContent/index.d.ts.map +1 -1
  34. package/types/DrawerLayout/DrawerContent/props.d.ts +13 -6
  35. package/types/DrawerLayout/DrawerContent/props.d.ts.map +1 -1
  36. package/types/DrawerLayout/DrawerContent/styles.d.ts +2 -2
  37. package/types/DrawerLayout/DrawerContent/styles.d.ts.map +1 -1
  38. package/types/DrawerLayout/DrawerLayoutLocator.d.ts +14 -14
  39. package/types/DrawerLayout/DrawerTray/DrawerTrayLocator.d.ts +4 -4
  40. package/types/DrawerLayout/DrawerTray/index.d.ts +45 -21
  41. package/types/DrawerLayout/DrawerTray/index.d.ts.map +1 -1
  42. package/types/DrawerLayout/DrawerTray/props.d.ts +74 -16
  43. package/types/DrawerLayout/DrawerTray/props.d.ts.map +1 -1
  44. package/types/DrawerLayout/__fixtures__/DrawerLayout.fixture.d.ts +11 -1
  45. package/types/DrawerLayout/__fixtures__/DrawerLayout.fixture.d.ts.map +1 -1
  46. package/types/DrawerLayout/index.d.ts +116 -23
  47. package/types/DrawerLayout/index.d.ts.map +1 -1
  48. package/types/DrawerLayout/props.d.ts +19 -3
  49. package/types/DrawerLayout/props.d.ts.map +1 -1
@@ -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
- children: null,
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
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'props' implicitly has an 'any' type.
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
- _content = null
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
- // @ts-expect-error ts-migrate(2722) FIXME: Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
97
- this.props.makeStyles()
111
+ this.props.makeStyles?.()
98
112
  }
99
113
 
100
- // @ts-expect-error ts-migrate(6133) FIXME: 'prevProps' is declared but its value is never rea... Remove this comment to see the full error message
101
- componentDidUpdate(prevProps, prevState, snapshot) {
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 = Children.toArray(this.props.children).filter((child) =>
119
+ const tray = (
120
+ Children.toArray(this.props.children) as DrawerChildren
121
+ ).filter((child) =>
108
122
  matchComponentTypes(child, [DrawerTray])
109
- )[0]
110
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'props' does not exist on type 'ReactChil... Remove this comment to see the full error message
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, ' ') : 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
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'el' implicitly has an 'any' type.
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
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'minWidth' implicitly has an 'any' type.
163
- shouldOverlayTray(minWidth, trayWidth, contentWidth, trayIsOverlayed) {
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
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'minWidth' implicitly has an 'any' type.
176
- getNextState(minWidth, trayWidth, contentWidth, trayIsOverlayed) {
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
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'shouldOverlayTray' implicitly has an 'a... Remove this comment to see the full error message
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
- // @ts-expect-error ts-migrate(7031) FIXME: Binding element 'width' implicitly has an 'any' ty... Remove this comment to see the full error message
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
- // @ts-expect-error ts-migrate(7031) FIXME: Binding element 'width' implicitly has an 'any' ty... Remove this comment to see the full error message
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 shouldOverlayTray = this.shouldOverlayTray(
260
- this.props.minWidth,
261
- // @ts-expect-error ts-migrate(2339) FIXME: Property 'trayWidth' does not exist on type 'Reado... Remove this comment to see the full error message
262
- this.state.trayWidth,
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) => {
264
+ const children = Children.map(
265
+ this.props.children as DrawerChildren,
266
+ (child, _index) => {
274
267
  if (matchComponentTypes(child, [DrawerTray])) {
275
268
  trayCount++
276
- return safeCloneElement(child, {
277
- 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
269
+ return safeCloneElement(child as TrayChild, {
270
+ label: (child as TrayChild).props.label,
271
+ key: (child as TrayChild).props.label,
279
272
  [DrawerTray.locatorAttribute]: this._id,
280
273
  contentRef: this.handleTrayContentRef,
281
274
  onEnter: this.handleTrayTransitionEnter,
282
275
  onExit: this.handleTrayTransitionExit
283
- })
276
+ }) as TrayChild
284
277
  } else if (matchComponentTypes(child, [DrawerContent])) {
285
278
  contentCount++
286
279
 
287
- // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'el' implicitly has an 'any' type.
288
- const handleContentRef = (el) => {
280
+ const handleContentRef = (el: HTMLDivElement | null) => {
281
+ const { contentRef } = (child as ContentChild).props
282
+
289
283
  this._content = el
290
284
 
291
- if (typeof child.props.contentRef === 'function') {
292
- child.props.contentRef(el)
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, {
299
- 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
291
+ ? (safeCloneElement(child as ContentChild, {
292
+ label: (child as ContentChild).props.label,
293
+ key: (child as ContentChild).props.label,
301
294
  [DrawerContent.locatorAttribute]: this._id,
302
295
  style: this.contentStyle,
303
296
  onSizeChange: createChainedFunction(
304
297
  this.handleContentSizeChange,
305
- child.props.onSizeChange
298
+ (child as ContentChild).props.onSizeChange
306
299
  ),
307
- contentRef: handleContentRef,
308
- shouldTransition: !shouldOverlayTray
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
- onOverlayTrayChange?: (...args: any[]) => any
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 }