@instructure/ui-drawer-layout 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 +36 -295
- package/es/DrawerLayout/{DrawerContent → v1/DrawerContent}/index.js +1 -1
- package/es/DrawerLayout/{DrawerTray → v1/DrawerTray}/index.js +1 -1
- package/es/DrawerLayout/{index.js → v1/index.js} +1 -1
- package/es/DrawerLayout/v2/DrawerContent/index.js +124 -0
- package/es/DrawerLayout/v2/DrawerContent/props.js +26 -0
- package/es/DrawerLayout/v2/DrawerContent/styles.js +51 -0
- package/es/DrawerLayout/v2/DrawerTray/index.js +227 -0
- package/es/DrawerLayout/v2/DrawerTray/props.js +26 -0
- package/es/DrawerLayout/v2/DrawerTray/styles.js +94 -0
- package/es/DrawerLayout/v2/__fixtures__/DrawerLayout.fixture.js +73 -0
- package/es/DrawerLayout/v2/index.js +224 -0
- package/es/DrawerLayout/v2/props.js +26 -0
- package/es/DrawerLayout/v2/styles.js +44 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/es/exports/b.js +24 -0
- package/lib/DrawerLayout/{DrawerContent → v1/DrawerContent}/index.js +1 -1
- package/lib/DrawerLayout/{DrawerTray → v1/DrawerTray}/index.js +1 -1
- package/lib/DrawerLayout/v1/index.js +245 -0
- package/lib/DrawerLayout/v2/DrawerContent/index.js +129 -0
- package/lib/DrawerLayout/v2/DrawerContent/props.js +31 -0
- package/lib/DrawerLayout/v2/DrawerContent/styles.js +57 -0
- package/lib/DrawerLayout/v2/DrawerTray/index.js +232 -0
- package/lib/DrawerLayout/v2/DrawerTray/props.js +31 -0
- package/lib/DrawerLayout/v2/DrawerTray/styles.js +100 -0
- package/lib/DrawerLayout/v2/__fixtures__/DrawerLayout.fixture.js +79 -0
- package/lib/DrawerLayout/{index.js → v2/index.js} +1 -1
- package/lib/DrawerLayout/v2/props.js +31 -0
- package/lib/DrawerLayout/v2/styles.js +50 -0
- package/lib/{index.js → exports/a.js} +4 -4
- package/lib/exports/b.js +24 -0
- package/package.json +47 -25
- package/src/DrawerLayout/{DrawerContent → v1/DrawerContent}/index.tsx +1 -1
- package/src/DrawerLayout/{DrawerTray → v1/DrawerTray}/index.tsx +1 -1
- package/src/DrawerLayout/v1/index.tsx +334 -0
- package/src/DrawerLayout/v2/DrawerContent/index.tsx +147 -0
- package/src/DrawerLayout/v2/DrawerContent/props.ts +73 -0
- package/src/DrawerLayout/v2/DrawerContent/styles.ts +68 -0
- package/src/DrawerLayout/v2/DrawerTray/index.tsx +288 -0
- package/src/DrawerLayout/v2/DrawerTray/props.ts +228 -0
- package/src/DrawerLayout/v2/DrawerTray/styles.ts +106 -0
- package/src/DrawerLayout/v2/README.md +231 -0
- package/src/DrawerLayout/v2/__fixtures__/DrawerLayout.fixture.tsx +75 -0
- package/src/DrawerLayout/{index.tsx → v2/index.tsx} +1 -1
- package/src/DrawerLayout/v2/props.ts +72 -0
- package/src/DrawerLayout/v2/styles.ts +47 -0
- package/src/{index.ts → exports/a.ts} +4 -4
- package/src/exports/b.ts +29 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/DrawerLayout/v1/DrawerContent/index.d.ts.map +1 -0
- package/types/DrawerLayout/v1/DrawerContent/props.d.ts.map +1 -0
- package/types/DrawerLayout/v1/DrawerContent/styles.d.ts.map +1 -0
- package/types/DrawerLayout/v1/DrawerContent/theme.d.ts.map +1 -0
- package/types/DrawerLayout/v1/DrawerTray/index.d.ts.map +1 -0
- package/types/DrawerLayout/v1/DrawerTray/props.d.ts.map +1 -0
- package/types/DrawerLayout/v1/DrawerTray/styles.d.ts.map +1 -0
- package/types/DrawerLayout/v1/DrawerTray/theme.d.ts.map +1 -0
- package/types/DrawerLayout/v1/__fixtures__/DrawerLayout.fixture.d.ts.map +1 -0
- package/types/DrawerLayout/v1/index.d.ts.map +1 -0
- package/types/DrawerLayout/v1/props.d.ts.map +1 -0
- package/types/DrawerLayout/v1/styles.d.ts.map +1 -0
- package/types/DrawerLayout/v2/DrawerContent/index.d.ts +35 -0
- package/types/DrawerLayout/v2/DrawerContent/index.d.ts.map +1 -0
- package/types/DrawerLayout/v2/DrawerContent/props.d.ts +28 -0
- package/types/DrawerLayout/v2/DrawerContent/props.d.ts.map +1 -0
- package/types/DrawerLayout/v2/DrawerContent/styles.d.ts +16 -0
- package/types/DrawerLayout/v2/DrawerContent/styles.d.ts.map +1 -0
- package/types/DrawerLayout/v2/DrawerTray/index.d.ts +61 -0
- package/types/DrawerLayout/v2/DrawerTray/index.d.ts.map +1 -0
- package/types/DrawerLayout/v2/DrawerTray/props.d.ts +120 -0
- package/types/DrawerLayout/v2/DrawerTray/props.d.ts.map +1 -0
- package/types/DrawerLayout/v2/DrawerTray/styles.d.ts +16 -0
- package/types/DrawerLayout/v2/DrawerTray/styles.d.ts.map +1 -0
- package/types/DrawerLayout/v2/__fixtures__/DrawerLayout.fixture.d.ts +22 -0
- package/types/DrawerLayout/v2/__fixtures__/DrawerLayout.fixture.d.ts.map +1 -0
- package/types/DrawerLayout/v2/index.d.ts +146 -0
- package/types/DrawerLayout/v2/index.d.ts.map +1 -0
- package/types/DrawerLayout/v2/props.d.ts +33 -0
- package/types/DrawerLayout/v2/props.d.ts.map +1 -0
- package/types/DrawerLayout/v2/styles.d.ts +14 -0
- package/types/DrawerLayout/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/DrawerLayout/DrawerContent/index.d.ts.map +0 -1
- package/types/DrawerLayout/DrawerContent/props.d.ts.map +0 -1
- package/types/DrawerLayout/DrawerContent/styles.d.ts.map +0 -1
- package/types/DrawerLayout/DrawerContent/theme.d.ts.map +0 -1
- package/types/DrawerLayout/DrawerTray/index.d.ts.map +0 -1
- package/types/DrawerLayout/DrawerTray/props.d.ts.map +0 -1
- package/types/DrawerLayout/DrawerTray/styles.d.ts.map +0 -1
- package/types/DrawerLayout/DrawerTray/theme.d.ts.map +0 -1
- package/types/DrawerLayout/__fixtures__/DrawerLayout.fixture.d.ts.map +0 -1
- package/types/DrawerLayout/index.d.ts.map +0 -1
- package/types/DrawerLayout/props.d.ts.map +0 -1
- package/types/DrawerLayout/styles.d.ts.map +0 -1
- package/types/index.d.ts +0 -5
- package/types/index.d.ts.map +0 -1
- /package/es/DrawerLayout/{DrawerContent → v1/DrawerContent}/props.js +0 -0
- /package/es/DrawerLayout/{DrawerContent → v1/DrawerContent}/styles.js +0 -0
- /package/es/DrawerLayout/{DrawerContent → v1/DrawerContent}/theme.js +0 -0
- /package/es/DrawerLayout/{DrawerTray → v1/DrawerTray}/props.js +0 -0
- /package/es/DrawerLayout/{DrawerTray → v1/DrawerTray}/styles.js +0 -0
- /package/es/DrawerLayout/{DrawerTray → v1/DrawerTray}/theme.js +0 -0
- /package/es/DrawerLayout/{__fixtures__ → v1/__fixtures__}/DrawerLayout.fixture.js +0 -0
- /package/es/DrawerLayout/{props.js → v1/props.js} +0 -0
- /package/es/DrawerLayout/{styles.js → v1/styles.js} +0 -0
- /package/lib/DrawerLayout/{DrawerContent → v1/DrawerContent}/props.js +0 -0
- /package/lib/DrawerLayout/{DrawerContent → v1/DrawerContent}/styles.js +0 -0
- /package/lib/DrawerLayout/{DrawerContent → v1/DrawerContent}/theme.js +0 -0
- /package/lib/DrawerLayout/{DrawerTray → v1/DrawerTray}/props.js +0 -0
- /package/lib/DrawerLayout/{DrawerTray → v1/DrawerTray}/styles.js +0 -0
- /package/lib/DrawerLayout/{DrawerTray → v1/DrawerTray}/theme.js +0 -0
- /package/lib/DrawerLayout/{__fixtures__ → v1/__fixtures__}/DrawerLayout.fixture.js +0 -0
- /package/lib/DrawerLayout/{props.js → v1/props.js} +0 -0
- /package/lib/DrawerLayout/{styles.js → v1/styles.js} +0 -0
- /package/src/DrawerLayout/{DrawerContent → v1/DrawerContent}/props.ts +0 -0
- /package/src/DrawerLayout/{DrawerContent → v1/DrawerContent}/styles.ts +0 -0
- /package/src/DrawerLayout/{DrawerContent → v1/DrawerContent}/theme.ts +0 -0
- /package/src/DrawerLayout/{DrawerTray → v1/DrawerTray}/props.ts +0 -0
- /package/src/DrawerLayout/{DrawerTray → v1/DrawerTray}/styles.ts +0 -0
- /package/src/DrawerLayout/{DrawerTray → v1/DrawerTray}/theme.ts +0 -0
- /package/src/DrawerLayout/{README.md → v1/README.md} +0 -0
- /package/src/DrawerLayout/{__fixtures__ → v1/__fixtures__}/DrawerLayout.fixture.tsx +0 -0
- /package/src/DrawerLayout/{props.ts → v1/props.ts} +0 -0
- /package/src/DrawerLayout/{styles.ts → v1/styles.ts} +0 -0
- /package/types/DrawerLayout/{DrawerContent → v1/DrawerContent}/index.d.ts +0 -0
- /package/types/DrawerLayout/{DrawerContent → v1/DrawerContent}/props.d.ts +0 -0
- /package/types/DrawerLayout/{DrawerContent → v1/DrawerContent}/styles.d.ts +0 -0
- /package/types/DrawerLayout/{DrawerContent → v1/DrawerContent}/theme.d.ts +0 -0
- /package/types/DrawerLayout/{DrawerTray → v1/DrawerTray}/index.d.ts +0 -0
- /package/types/DrawerLayout/{DrawerTray → v1/DrawerTray}/props.d.ts +0 -0
- /package/types/DrawerLayout/{DrawerTray → v1/DrawerTray}/styles.d.ts +0 -0
- /package/types/DrawerLayout/{DrawerTray → v1/DrawerTray}/theme.d.ts +0 -0
- /package/types/DrawerLayout/{__fixtures__ → v1/__fixtures__}/DrawerLayout.fixture.d.ts +0 -0
- /package/types/DrawerLayout/{index.d.ts → v1/index.d.ts} +0 -0
- /package/types/DrawerLayout/{props.d.ts → v1/props.d.ts} +0 -0
- /package/types/DrawerLayout/{styles.d.ts → v1/styles.d.ts} +0 -0
|
@@ -0,0 +1,147 @@
|
|
|
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 } from 'react'
|
|
26
|
+
|
|
27
|
+
import { debounce } from '@instructure/debounce'
|
|
28
|
+
import type { Debounced } from '@instructure/debounce'
|
|
29
|
+
import { getBoundingClientRect } from '@instructure/ui-dom-utils'
|
|
30
|
+
import { omitProps } from '@instructure/ui-react-utils'
|
|
31
|
+
import { withStyle } from '@instructure/emotion'
|
|
32
|
+
|
|
33
|
+
import generateStyle from './styles'
|
|
34
|
+
|
|
35
|
+
import { allowedProps } from './props'
|
|
36
|
+
import type {
|
|
37
|
+
DrawerLayoutContentProps,
|
|
38
|
+
DrawerLayoutContentStyleProps
|
|
39
|
+
} from './props'
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
---
|
|
43
|
+
parent: DrawerLayout
|
|
44
|
+
id: DrawerLayout.Content
|
|
45
|
+
---
|
|
46
|
+
**/
|
|
47
|
+
@withStyle(generateStyle)
|
|
48
|
+
class DrawerContent extends Component<DrawerLayoutContentProps> {
|
|
49
|
+
static readonly componentId = 'DrawerLayout.Content'
|
|
50
|
+
|
|
51
|
+
static locatorAttribute = 'data-drawer-content'
|
|
52
|
+
static allowedProps = allowedProps
|
|
53
|
+
static defaultProps = {
|
|
54
|
+
role: 'region'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
ref: HTMLDivElement | null = null
|
|
58
|
+
|
|
59
|
+
get _content() {
|
|
60
|
+
console.warn(
|
|
61
|
+
'_content property is deprecated and will be removed in v9, please use ref instead'
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
return this.ref
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private _resizeListener?: ResizeObserver
|
|
68
|
+
|
|
69
|
+
private _debounced?: Debounced<NonNullable<typeof this.props.onSizeChange>>
|
|
70
|
+
|
|
71
|
+
componentDidMount() {
|
|
72
|
+
const rect = getBoundingClientRect(this.ref)
|
|
73
|
+
const origSize = {
|
|
74
|
+
width: rect.width
|
|
75
|
+
}
|
|
76
|
+
// set initial size
|
|
77
|
+
if (typeof this.props.onSizeChange === 'function') {
|
|
78
|
+
this.props.onSizeChange({ width: rect.width, height: rect.height })
|
|
79
|
+
|
|
80
|
+
// listen for changes to size
|
|
81
|
+
this._debounced = debounce(this.props.onSizeChange, 100, {
|
|
82
|
+
leading: false,
|
|
83
|
+
trailing: true
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
this._resizeListener = new ResizeObserver((entries) => {
|
|
88
|
+
for (const entry of entries) {
|
|
89
|
+
const size = {
|
|
90
|
+
width: entry.contentRect.width
|
|
91
|
+
}
|
|
92
|
+
if (size.width !== origSize.width) {
|
|
93
|
+
this._debounced?.(size)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
this._resizeListener.observe(this.ref!)
|
|
99
|
+
|
|
100
|
+
this.props.makeStyles?.(this.makeStyleProps(false))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
componentDidUpdate() {
|
|
104
|
+
this.props.makeStyles?.(this.makeStyleProps(true))
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
componentWillUnmount() {
|
|
108
|
+
this._resizeListener?.disconnect()
|
|
109
|
+
|
|
110
|
+
this._debounced?.cancel()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
makeStyleProps = (
|
|
114
|
+
shouldTransition: DrawerLayoutContentStyleProps['shouldTransition']
|
|
115
|
+
): DrawerLayoutContentStyleProps => {
|
|
116
|
+
return { shouldTransition }
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
handleContentRef = (node: HTMLDivElement | null) => {
|
|
120
|
+
this.ref = node
|
|
121
|
+
|
|
122
|
+
if (typeof this.props.contentRef === 'function') {
|
|
123
|
+
this.props.contentRef(node)
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
render() {
|
|
128
|
+
const { style, label, role } = this.props
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<div
|
|
132
|
+
{...omitProps(this.props, DrawerContent.allowedProps)}
|
|
133
|
+
role={role}
|
|
134
|
+
style={style}
|
|
135
|
+
ref={this.handleContentRef}
|
|
136
|
+
aria-label={label}
|
|
137
|
+
css={this.props.styles?.drawerContent}
|
|
138
|
+
data-cid="DrawerContent"
|
|
139
|
+
>
|
|
140
|
+
{this.props.children}
|
|
141
|
+
</div>
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export default DrawerContent
|
|
147
|
+
export { DrawerContent }
|
|
@@ -0,0 +1,73 @@
|
|
|
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 { AriaRole } from 'react'
|
|
26
|
+
|
|
27
|
+
import type {
|
|
28
|
+
DrawerLayoutContentTheme,
|
|
29
|
+
OtherHTMLAttributes
|
|
30
|
+
} from '@instructure/shared-types'
|
|
31
|
+
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
32
|
+
|
|
33
|
+
type DrawerContentSize = { width: number; height?: number }
|
|
34
|
+
|
|
35
|
+
type DrawerLayoutContentOwnProps = {
|
|
36
|
+
label: string
|
|
37
|
+
children?: React.ReactNode
|
|
38
|
+
contentRef?: (element: HTMLDivElement | null) => void
|
|
39
|
+
/**
|
|
40
|
+
* Callback fired whenever the `<DrawerLayout.Content />` changes size
|
|
41
|
+
*/
|
|
42
|
+
onSizeChange?: (contentSize: DrawerContentSize) => void
|
|
43
|
+
role?: AriaRole
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type DrawerLayoutContentStyleProps = {
|
|
47
|
+
shouldTransition: boolean
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type PropKeys = keyof DrawerLayoutContentOwnProps
|
|
51
|
+
|
|
52
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
53
|
+
|
|
54
|
+
type DrawerLayoutContentProps = DrawerLayoutContentOwnProps &
|
|
55
|
+
WithStyleProps<DrawerLayoutContentTheme, DrawerLayoutContentStyle> &
|
|
56
|
+
OtherHTMLAttributes<DrawerLayoutContentOwnProps>
|
|
57
|
+
|
|
58
|
+
type DrawerLayoutContentStyle = ComponentStyle<'drawerContent'>
|
|
59
|
+
const allowedProps: AllowedPropKeys = [
|
|
60
|
+
'label',
|
|
61
|
+
'children',
|
|
62
|
+
'contentRef',
|
|
63
|
+
'onSizeChange',
|
|
64
|
+
'role'
|
|
65
|
+
]
|
|
66
|
+
|
|
67
|
+
export type {
|
|
68
|
+
DrawerLayoutContentProps,
|
|
69
|
+
DrawerLayoutContentStyleProps,
|
|
70
|
+
DrawerLayoutContentStyle,
|
|
71
|
+
DrawerContentSize
|
|
72
|
+
}
|
|
73
|
+
export { allowedProps }
|
|
@@ -0,0 +1,68 @@
|
|
|
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 type { NewComponentTypes, SharedTokens } from '@instructure/ui-themes'
|
|
26
|
+
import type {
|
|
27
|
+
DrawerLayoutContentProps,
|
|
28
|
+
DrawerLayoutContentStyleProps,
|
|
29
|
+
DrawerLayoutContentStyle
|
|
30
|
+
} from './props'
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* ---
|
|
34
|
+
* private: true
|
|
35
|
+
* ---
|
|
36
|
+
* Generates the style object from the theme and provided additional information
|
|
37
|
+
* @param {Object} componentTheme The theme variable object.
|
|
38
|
+
* @param {Object} props the props of the component, the style is applied to
|
|
39
|
+
* @param {Object} sharedTokens Shared token object that stores common values for the theme.
|
|
40
|
+
* @param {Object} state the state of the component, the style is applied to
|
|
41
|
+
* @return {Object} The final style object, which will be used in the component
|
|
42
|
+
*/
|
|
43
|
+
const generateStyle = (
|
|
44
|
+
componentTheme: NewComponentTypes['DrawerLayoutContent'],
|
|
45
|
+
_props: DrawerLayoutContentProps,
|
|
46
|
+
_sharedTokens: SharedTokens,
|
|
47
|
+
state: DrawerLayoutContentStyleProps
|
|
48
|
+
): DrawerLayoutContentStyle => {
|
|
49
|
+
const { shouldTransition } = state
|
|
50
|
+
|
|
51
|
+
const transitionState = shouldTransition
|
|
52
|
+
? {
|
|
53
|
+
transition: `margin ${componentTheme.duration}`
|
|
54
|
+
}
|
|
55
|
+
: {}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
drawerContent: {
|
|
59
|
+
label: 'drawerLayout__content',
|
|
60
|
+
overflowY: componentTheme.overflowY,
|
|
61
|
+
height: '100%',
|
|
62
|
+
boxSizing: 'content-box',
|
|
63
|
+
...transitionState
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default generateStyle
|
|
@@ -0,0 +1,288 @@
|
|
|
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 } from 'react'
|
|
26
|
+
|
|
27
|
+
import { withStyle } from '@instructure/emotion'
|
|
28
|
+
import { textDirectionContextConsumer } from '@instructure/ui-i18n'
|
|
29
|
+
import { Transition } from '@instructure/ui-motion'
|
|
30
|
+
import type { TransitionType } from '@instructure/ui-motion'
|
|
31
|
+
import { omitProps } from '@instructure/ui-react-utils'
|
|
32
|
+
import { createChainedFunction } from '@instructure/ui-utils'
|
|
33
|
+
import { Dialog } from '@instructure/ui-dialog'
|
|
34
|
+
import { Portal } from '@instructure/ui-portal'
|
|
35
|
+
import type { PortalNode } from '@instructure/ui-portal'
|
|
36
|
+
import { mirrorHorizontalPlacement } from '@instructure/ui-position'
|
|
37
|
+
|
|
38
|
+
import generateStyle from './styles'
|
|
39
|
+
import { DrawerLayoutContext } from '../index'
|
|
40
|
+
|
|
41
|
+
import { allowedProps } from './props'
|
|
42
|
+
import type {
|
|
43
|
+
DrawerLayoutTrayProps,
|
|
44
|
+
DrawerLayoutTrayState,
|
|
45
|
+
DrawerLayoutTrayStyleProps,
|
|
46
|
+
DrawerTrayPlacement
|
|
47
|
+
} from './props'
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
---
|
|
51
|
+
parent: DrawerLayout
|
|
52
|
+
id: DrawerLayout.Tray
|
|
53
|
+
---
|
|
54
|
+
**/
|
|
55
|
+
@withStyle(generateStyle)
|
|
56
|
+
@textDirectionContextConsumer()
|
|
57
|
+
class DrawerTray extends Component<
|
|
58
|
+
DrawerLayoutTrayProps,
|
|
59
|
+
DrawerLayoutTrayState
|
|
60
|
+
> {
|
|
61
|
+
static readonly componentId = 'DrawerLayout.Tray' as const
|
|
62
|
+
|
|
63
|
+
static locatorAttribute = 'data-drawer-tray'
|
|
64
|
+
|
|
65
|
+
static allowedProps = allowedProps
|
|
66
|
+
static defaultProps = {
|
|
67
|
+
shouldContainFocus: true,
|
|
68
|
+
shouldCloseOnEscape: true,
|
|
69
|
+
shouldCloseOnDocumentClick: true,
|
|
70
|
+
shouldReturnFocus: true,
|
|
71
|
+
open: false,
|
|
72
|
+
shadow: true,
|
|
73
|
+
border: true,
|
|
74
|
+
placement: 'start'
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
ref: HTMLDivElement | null = null
|
|
78
|
+
|
|
79
|
+
private _DOMNode: PortalNode = null
|
|
80
|
+
|
|
81
|
+
get _content() {
|
|
82
|
+
console.warn(
|
|
83
|
+
'_content property is deprecated and will be removed in v9, please use ref instead'
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
return this.ref
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
constructor(props: DrawerLayoutTrayProps) {
|
|
90
|
+
super(props)
|
|
91
|
+
|
|
92
|
+
this.state = {
|
|
93
|
+
transitioning: false,
|
|
94
|
+
portalOpen: false
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
componentDidMount() {
|
|
99
|
+
this.props.makeStyles?.(this.makeStyleProps())
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
componentDidUpdate(prevProps: DrawerLayoutTrayProps) {
|
|
103
|
+
if (this.props.open !== prevProps.open) {
|
|
104
|
+
this.setState({
|
|
105
|
+
transitioning: true
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
this.props.makeStyles?.(this.makeStyleProps())
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
makeStyleProps = (): DrawerLayoutTrayStyleProps => {
|
|
112
|
+
return {
|
|
113
|
+
placement: this.placement
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
get placement() {
|
|
118
|
+
const { placement, dir } = this.props
|
|
119
|
+
const isRtl = dir === textDirectionContextConsumer.DIRECTION.rtl
|
|
120
|
+
return (
|
|
121
|
+
isRtl ? mirrorHorizontalPlacement(placement!, ' ') : placement!
|
|
122
|
+
) as DrawerTrayPlacement
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
get transition(): TransitionType {
|
|
126
|
+
return this.placement === 'end' ? 'fade' : 'slide-left'
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
handleContentRef = (node: HTMLDivElement | null) => {
|
|
130
|
+
this.ref = node
|
|
131
|
+
|
|
132
|
+
if (typeof this.props.contentRef === 'function') {
|
|
133
|
+
this.props.contentRef(node)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
handleTransitionEntered = (_transitionType?: TransitionType) => {
|
|
138
|
+
this.setState({ transitioning: false })
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
handleTransitionExited = (_transitionType?: TransitionType) => {
|
|
142
|
+
this.setState({
|
|
143
|
+
transitioning: false
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
handlePortalOpen = (DOMNode: PortalNode) => {
|
|
148
|
+
this.DOMNode = DOMNode
|
|
149
|
+
this.setState({
|
|
150
|
+
portalOpen: true
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
get DOMNode() {
|
|
155
|
+
return this._DOMNode
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
set DOMNode(el: PortalNode) {
|
|
159
|
+
this._DOMNode = el
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
renderContent() {
|
|
163
|
+
const { children, render } = this.props
|
|
164
|
+
if (typeof render === 'function') {
|
|
165
|
+
return render()
|
|
166
|
+
} else if (typeof children === 'function') {
|
|
167
|
+
return children()
|
|
168
|
+
} else {
|
|
169
|
+
return children
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
render() {
|
|
174
|
+
const {
|
|
175
|
+
label,
|
|
176
|
+
children,
|
|
177
|
+
render,
|
|
178
|
+
placement,
|
|
179
|
+
open,
|
|
180
|
+
onOpen,
|
|
181
|
+
onClose,
|
|
182
|
+
border,
|
|
183
|
+
shadow,
|
|
184
|
+
onEnter,
|
|
185
|
+
onEntering,
|
|
186
|
+
onEntered,
|
|
187
|
+
onExit,
|
|
188
|
+
onExiting,
|
|
189
|
+
onExited,
|
|
190
|
+
contentRef,
|
|
191
|
+
mountNode,
|
|
192
|
+
defaultFocusElement,
|
|
193
|
+
liveRegion,
|
|
194
|
+
onDismiss,
|
|
195
|
+
onTransition,
|
|
196
|
+
shouldReturnFocus,
|
|
197
|
+
shouldCloseOnEscape,
|
|
198
|
+
shouldCloseOnDocumentClick,
|
|
199
|
+
shouldContainFocus,
|
|
200
|
+
styles,
|
|
201
|
+
...props
|
|
202
|
+
} = this.props
|
|
203
|
+
|
|
204
|
+
return (
|
|
205
|
+
<DrawerLayoutContext.Consumer>
|
|
206
|
+
{(shouldOverlayTray: boolean) => {
|
|
207
|
+
const { portalOpen } = this.state
|
|
208
|
+
const needsPortal = shouldOverlayTray && !!mountNode
|
|
209
|
+
// we have to handle the shadow version here,
|
|
210
|
+
// because passing and handling it in styles.js makes it
|
|
211
|
+
// rerender the component during the transition, breaking it
|
|
212
|
+
const trayStyles =
|
|
213
|
+
shadow && shouldOverlayTray
|
|
214
|
+
? styles?.drawerTrayWithShadow
|
|
215
|
+
: styles?.drawerTray
|
|
216
|
+
let transitionIn = open
|
|
217
|
+
if (needsPortal && !portalOpen) {
|
|
218
|
+
transitionIn = false
|
|
219
|
+
}
|
|
220
|
+
const content = (
|
|
221
|
+
<Transition
|
|
222
|
+
in={transitionIn}
|
|
223
|
+
type={this.transition}
|
|
224
|
+
onTransition={onTransition}
|
|
225
|
+
onEnter={onEnter}
|
|
226
|
+
onEntering={onEntering}
|
|
227
|
+
onEntered={createChainedFunction(
|
|
228
|
+
this.handleTransitionEntered,
|
|
229
|
+
onEntered,
|
|
230
|
+
onOpen
|
|
231
|
+
)}
|
|
232
|
+
onExit={onExit}
|
|
233
|
+
onExiting={onExiting}
|
|
234
|
+
onExited={createChainedFunction(
|
|
235
|
+
this.handleTransitionExited,
|
|
236
|
+
onExited,
|
|
237
|
+
onClose
|
|
238
|
+
)}
|
|
239
|
+
unmountOnExit
|
|
240
|
+
>
|
|
241
|
+
<div
|
|
242
|
+
{...omitProps(props, DrawerTray.allowedProps)}
|
|
243
|
+
ref={this.handleContentRef}
|
|
244
|
+
css={trayStyles}
|
|
245
|
+
data-cid="DrawerTray"
|
|
246
|
+
>
|
|
247
|
+
<Dialog
|
|
248
|
+
open
|
|
249
|
+
role={shouldOverlayTray ? 'dialog' : 'region'}
|
|
250
|
+
label={label}
|
|
251
|
+
shouldReturnFocus={shouldReturnFocus}
|
|
252
|
+
shouldContainFocus={
|
|
253
|
+
!this.state.transitioning &&
|
|
254
|
+
shouldContainFocus &&
|
|
255
|
+
shouldOverlayTray
|
|
256
|
+
}
|
|
257
|
+
shouldCloseOnDocumentClick={
|
|
258
|
+
shouldCloseOnDocumentClick && shouldOverlayTray
|
|
259
|
+
}
|
|
260
|
+
shouldCloseOnEscape={shouldCloseOnEscape && shouldOverlayTray}
|
|
261
|
+
defaultFocusElement={defaultFocusElement}
|
|
262
|
+
liveRegion={liveRegion}
|
|
263
|
+
onDismiss={onDismiss}
|
|
264
|
+
as="div"
|
|
265
|
+
css={this.props.styles?.drawerTrayContent}
|
|
266
|
+
>
|
|
267
|
+
{this.renderContent()}
|
|
268
|
+
</Dialog>
|
|
269
|
+
</div>
|
|
270
|
+
</Transition>
|
|
271
|
+
)
|
|
272
|
+
if (needsPortal) {
|
|
273
|
+
return (
|
|
274
|
+
<Portal mountNode={mountNode} open onOpen={this.handlePortalOpen}>
|
|
275
|
+
{content}
|
|
276
|
+
</Portal>
|
|
277
|
+
)
|
|
278
|
+
} else {
|
|
279
|
+
return content
|
|
280
|
+
}
|
|
281
|
+
}}
|
|
282
|
+
</DrawerLayoutContext.Consumer>
|
|
283
|
+
)
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export default DrawerTray
|
|
288
|
+
export { DrawerTray }
|