@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.
Files changed (139) hide show
  1. package/CHANGELOG.md +36 -295
  2. package/es/DrawerLayout/{DrawerContent → v1/DrawerContent}/index.js +1 -1
  3. package/es/DrawerLayout/{DrawerTray → v1/DrawerTray}/index.js +1 -1
  4. package/es/DrawerLayout/{index.js → v1/index.js} +1 -1
  5. package/es/DrawerLayout/v2/DrawerContent/index.js +124 -0
  6. package/es/DrawerLayout/v2/DrawerContent/props.js +26 -0
  7. package/es/DrawerLayout/v2/DrawerContent/styles.js +51 -0
  8. package/es/DrawerLayout/v2/DrawerTray/index.js +227 -0
  9. package/es/DrawerLayout/v2/DrawerTray/props.js +26 -0
  10. package/es/DrawerLayout/v2/DrawerTray/styles.js +94 -0
  11. package/es/DrawerLayout/v2/__fixtures__/DrawerLayout.fixture.js +73 -0
  12. package/es/DrawerLayout/v2/index.js +224 -0
  13. package/es/DrawerLayout/v2/props.js +26 -0
  14. package/es/DrawerLayout/v2/styles.js +44 -0
  15. package/es/{index.js → exports/a.js} +1 -1
  16. package/es/exports/b.js +24 -0
  17. package/lib/DrawerLayout/{DrawerContent → v1/DrawerContent}/index.js +1 -1
  18. package/lib/DrawerLayout/{DrawerTray → v1/DrawerTray}/index.js +1 -1
  19. package/lib/DrawerLayout/v1/index.js +245 -0
  20. package/lib/DrawerLayout/v2/DrawerContent/index.js +129 -0
  21. package/lib/DrawerLayout/v2/DrawerContent/props.js +31 -0
  22. package/lib/DrawerLayout/v2/DrawerContent/styles.js +57 -0
  23. package/lib/DrawerLayout/v2/DrawerTray/index.js +232 -0
  24. package/lib/DrawerLayout/v2/DrawerTray/props.js +31 -0
  25. package/lib/DrawerLayout/v2/DrawerTray/styles.js +100 -0
  26. package/lib/DrawerLayout/v2/__fixtures__/DrawerLayout.fixture.js +79 -0
  27. package/lib/DrawerLayout/{index.js → v2/index.js} +1 -1
  28. package/lib/DrawerLayout/v2/props.js +31 -0
  29. package/lib/DrawerLayout/v2/styles.js +50 -0
  30. package/lib/{index.js → exports/a.js} +4 -4
  31. package/lib/exports/b.js +24 -0
  32. package/package.json +47 -25
  33. package/src/DrawerLayout/{DrawerContent → v1/DrawerContent}/index.tsx +1 -1
  34. package/src/DrawerLayout/{DrawerTray → v1/DrawerTray}/index.tsx +1 -1
  35. package/src/DrawerLayout/v1/index.tsx +334 -0
  36. package/src/DrawerLayout/v2/DrawerContent/index.tsx +147 -0
  37. package/src/DrawerLayout/v2/DrawerContent/props.ts +73 -0
  38. package/src/DrawerLayout/v2/DrawerContent/styles.ts +68 -0
  39. package/src/DrawerLayout/v2/DrawerTray/index.tsx +288 -0
  40. package/src/DrawerLayout/v2/DrawerTray/props.ts +228 -0
  41. package/src/DrawerLayout/v2/DrawerTray/styles.ts +106 -0
  42. package/src/DrawerLayout/v2/README.md +231 -0
  43. package/src/DrawerLayout/v2/__fixtures__/DrawerLayout.fixture.tsx +75 -0
  44. package/src/DrawerLayout/{index.tsx → v2/index.tsx} +1 -1
  45. package/src/DrawerLayout/v2/props.ts +72 -0
  46. package/src/DrawerLayout/v2/styles.ts +47 -0
  47. package/src/{index.ts → exports/a.ts} +4 -4
  48. package/src/exports/b.ts +29 -0
  49. package/tsconfig.build.tsbuildinfo +1 -1
  50. package/types/DrawerLayout/v1/DrawerContent/index.d.ts.map +1 -0
  51. package/types/DrawerLayout/v1/DrawerContent/props.d.ts.map +1 -0
  52. package/types/DrawerLayout/v1/DrawerContent/styles.d.ts.map +1 -0
  53. package/types/DrawerLayout/v1/DrawerContent/theme.d.ts.map +1 -0
  54. package/types/DrawerLayout/v1/DrawerTray/index.d.ts.map +1 -0
  55. package/types/DrawerLayout/v1/DrawerTray/props.d.ts.map +1 -0
  56. package/types/DrawerLayout/v1/DrawerTray/styles.d.ts.map +1 -0
  57. package/types/DrawerLayout/v1/DrawerTray/theme.d.ts.map +1 -0
  58. package/types/DrawerLayout/v1/__fixtures__/DrawerLayout.fixture.d.ts.map +1 -0
  59. package/types/DrawerLayout/v1/index.d.ts.map +1 -0
  60. package/types/DrawerLayout/v1/props.d.ts.map +1 -0
  61. package/types/DrawerLayout/v1/styles.d.ts.map +1 -0
  62. package/types/DrawerLayout/v2/DrawerContent/index.d.ts +35 -0
  63. package/types/DrawerLayout/v2/DrawerContent/index.d.ts.map +1 -0
  64. package/types/DrawerLayout/v2/DrawerContent/props.d.ts +28 -0
  65. package/types/DrawerLayout/v2/DrawerContent/props.d.ts.map +1 -0
  66. package/types/DrawerLayout/v2/DrawerContent/styles.d.ts +16 -0
  67. package/types/DrawerLayout/v2/DrawerContent/styles.d.ts.map +1 -0
  68. package/types/DrawerLayout/v2/DrawerTray/index.d.ts +61 -0
  69. package/types/DrawerLayout/v2/DrawerTray/index.d.ts.map +1 -0
  70. package/types/DrawerLayout/v2/DrawerTray/props.d.ts +120 -0
  71. package/types/DrawerLayout/v2/DrawerTray/props.d.ts.map +1 -0
  72. package/types/DrawerLayout/v2/DrawerTray/styles.d.ts +16 -0
  73. package/types/DrawerLayout/v2/DrawerTray/styles.d.ts.map +1 -0
  74. package/types/DrawerLayout/v2/__fixtures__/DrawerLayout.fixture.d.ts +22 -0
  75. package/types/DrawerLayout/v2/__fixtures__/DrawerLayout.fixture.d.ts.map +1 -0
  76. package/types/DrawerLayout/v2/index.d.ts +146 -0
  77. package/types/DrawerLayout/v2/index.d.ts.map +1 -0
  78. package/types/DrawerLayout/v2/props.d.ts +33 -0
  79. package/types/DrawerLayout/v2/props.d.ts.map +1 -0
  80. package/types/DrawerLayout/v2/styles.d.ts +14 -0
  81. package/types/DrawerLayout/v2/styles.d.ts.map +1 -0
  82. package/types/exports/a.d.ts +5 -0
  83. package/types/exports/a.d.ts.map +1 -0
  84. package/types/exports/b.d.ts +5 -0
  85. package/types/exports/b.d.ts.map +1 -0
  86. package/types/DrawerLayout/DrawerContent/index.d.ts.map +0 -1
  87. package/types/DrawerLayout/DrawerContent/props.d.ts.map +0 -1
  88. package/types/DrawerLayout/DrawerContent/styles.d.ts.map +0 -1
  89. package/types/DrawerLayout/DrawerContent/theme.d.ts.map +0 -1
  90. package/types/DrawerLayout/DrawerTray/index.d.ts.map +0 -1
  91. package/types/DrawerLayout/DrawerTray/props.d.ts.map +0 -1
  92. package/types/DrawerLayout/DrawerTray/styles.d.ts.map +0 -1
  93. package/types/DrawerLayout/DrawerTray/theme.d.ts.map +0 -1
  94. package/types/DrawerLayout/__fixtures__/DrawerLayout.fixture.d.ts.map +0 -1
  95. package/types/DrawerLayout/index.d.ts.map +0 -1
  96. package/types/DrawerLayout/props.d.ts.map +0 -1
  97. package/types/DrawerLayout/styles.d.ts.map +0 -1
  98. package/types/index.d.ts +0 -5
  99. package/types/index.d.ts.map +0 -1
  100. /package/es/DrawerLayout/{DrawerContent → v1/DrawerContent}/props.js +0 -0
  101. /package/es/DrawerLayout/{DrawerContent → v1/DrawerContent}/styles.js +0 -0
  102. /package/es/DrawerLayout/{DrawerContent → v1/DrawerContent}/theme.js +0 -0
  103. /package/es/DrawerLayout/{DrawerTray → v1/DrawerTray}/props.js +0 -0
  104. /package/es/DrawerLayout/{DrawerTray → v1/DrawerTray}/styles.js +0 -0
  105. /package/es/DrawerLayout/{DrawerTray → v1/DrawerTray}/theme.js +0 -0
  106. /package/es/DrawerLayout/{__fixtures__ → v1/__fixtures__}/DrawerLayout.fixture.js +0 -0
  107. /package/es/DrawerLayout/{props.js → v1/props.js} +0 -0
  108. /package/es/DrawerLayout/{styles.js → v1/styles.js} +0 -0
  109. /package/lib/DrawerLayout/{DrawerContent → v1/DrawerContent}/props.js +0 -0
  110. /package/lib/DrawerLayout/{DrawerContent → v1/DrawerContent}/styles.js +0 -0
  111. /package/lib/DrawerLayout/{DrawerContent → v1/DrawerContent}/theme.js +0 -0
  112. /package/lib/DrawerLayout/{DrawerTray → v1/DrawerTray}/props.js +0 -0
  113. /package/lib/DrawerLayout/{DrawerTray → v1/DrawerTray}/styles.js +0 -0
  114. /package/lib/DrawerLayout/{DrawerTray → v1/DrawerTray}/theme.js +0 -0
  115. /package/lib/DrawerLayout/{__fixtures__ → v1/__fixtures__}/DrawerLayout.fixture.js +0 -0
  116. /package/lib/DrawerLayout/{props.js → v1/props.js} +0 -0
  117. /package/lib/DrawerLayout/{styles.js → v1/styles.js} +0 -0
  118. /package/src/DrawerLayout/{DrawerContent → v1/DrawerContent}/props.ts +0 -0
  119. /package/src/DrawerLayout/{DrawerContent → v1/DrawerContent}/styles.ts +0 -0
  120. /package/src/DrawerLayout/{DrawerContent → v1/DrawerContent}/theme.ts +0 -0
  121. /package/src/DrawerLayout/{DrawerTray → v1/DrawerTray}/props.ts +0 -0
  122. /package/src/DrawerLayout/{DrawerTray → v1/DrawerTray}/styles.ts +0 -0
  123. /package/src/DrawerLayout/{DrawerTray → v1/DrawerTray}/theme.ts +0 -0
  124. /package/src/DrawerLayout/{README.md → v1/README.md} +0 -0
  125. /package/src/DrawerLayout/{__fixtures__ → v1/__fixtures__}/DrawerLayout.fixture.tsx +0 -0
  126. /package/src/DrawerLayout/{props.ts → v1/props.ts} +0 -0
  127. /package/src/DrawerLayout/{styles.ts → v1/styles.ts} +0 -0
  128. /package/types/DrawerLayout/{DrawerContent → v1/DrawerContent}/index.d.ts +0 -0
  129. /package/types/DrawerLayout/{DrawerContent → v1/DrawerContent}/props.d.ts +0 -0
  130. /package/types/DrawerLayout/{DrawerContent → v1/DrawerContent}/styles.d.ts +0 -0
  131. /package/types/DrawerLayout/{DrawerContent → v1/DrawerContent}/theme.d.ts +0 -0
  132. /package/types/DrawerLayout/{DrawerTray → v1/DrawerTray}/index.d.ts +0 -0
  133. /package/types/DrawerLayout/{DrawerTray → v1/DrawerTray}/props.d.ts +0 -0
  134. /package/types/DrawerLayout/{DrawerTray → v1/DrawerTray}/styles.d.ts +0 -0
  135. /package/types/DrawerLayout/{DrawerTray → v1/DrawerTray}/theme.d.ts +0 -0
  136. /package/types/DrawerLayout/{__fixtures__ → v1/__fixtures__}/DrawerLayout.fixture.d.ts +0 -0
  137. /package/types/DrawerLayout/{index.d.ts → v1/index.d.ts} +0 -0
  138. /package/types/DrawerLayout/{props.d.ts → v1/props.d.ts} +0 -0
  139. /package/types/DrawerLayout/{styles.d.ts → v1/styles.d.ts} +0 -0
@@ -0,0 +1,228 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import React from 'react'
26
+ import type { PositionMountNode } from '@instructure/ui-position'
27
+ import type { TextDirectionContextConsumerProps } from '@instructure/ui-i18n'
28
+ import type { ComponentStyle, WithStyleProps } from '@instructure/emotion'
29
+ import type {
30
+ DrawerLayoutTrayTheme,
31
+ LiveRegion,
32
+ OtherHTMLAttributes,
33
+ UIElement
34
+ } from '@instructure/shared-types'
35
+ import type {
36
+ BaseTransitionStatesType,
37
+ TransitionType
38
+ } from '@instructure/ui-motion'
39
+
40
+ type DrawerTrayPlacement = 'start' | 'end'
41
+
42
+ type DrawerLayoutTrayOwnProps = {
43
+ label: string
44
+
45
+ children?: React.ReactNode | (() => React.ReactNode)
46
+
47
+ render?: () => React.ReactNode
48
+
49
+ /**
50
+ * Placement of the `<DrawerLayout.Tray />`
51
+ */
52
+ placement?: DrawerTrayPlacement
53
+
54
+ /**
55
+ * If the tray is open or closed.
56
+ */
57
+ open?: boolean
58
+
59
+ /**
60
+ * Called when the `<DrawerLayout.Tray />` is opened
61
+ */
62
+ onOpen?: (transitionType?: TransitionType) => void
63
+
64
+ /**
65
+ * Called when the `<DrawerLayout.Tray />` is closed
66
+ */
67
+ onClose?: (transitionType?: TransitionType) => void
68
+
69
+ /**
70
+ * Should the `<DrawerLayout.Tray />` have a border
71
+ */
72
+ border?: boolean
73
+
74
+ /**
75
+ * Should the `<DrawerLayout.Tray />` have a shadow
76
+ */
77
+ shadow?: boolean
78
+
79
+ /**
80
+ * Ref function for the `<DrawerLayout.Tray />` content
81
+ */
82
+ contentRef?: (element: HTMLDivElement | null) => void
83
+
84
+ /**
85
+ * An element or a function returning an element to use as the mount node
86
+ * for the `<DrawerLayout.Tray />` when tray is overlaying content
87
+ */
88
+ mountNode?: PositionMountNode
89
+ } & PropsPassedToDialog &
90
+ PropsPassedToTransition &
91
+ TextDirectionContextConsumerProps
92
+
93
+ type PropsPassedToDialog = {
94
+ /**
95
+ * An element or a function returning an element to focus by default
96
+ */
97
+ defaultFocusElement?: UIElement
98
+
99
+ /**
100
+ * An element, function returning an element, or array of elements that will not be hidden from
101
+ * the screen reader when the `<DrawerLayout.Tray />` is open
102
+ */
103
+ liveRegion?: LiveRegion
104
+
105
+ /**
106
+ * Event fired when the underlying FocusRegion is dismissed in overlay mode.
107
+ * This can happen if:
108
+ * - `shouldCloseOnDocumentClick` is `true` and the user
109
+ * clicks outside the `<DrawerLayout.Tray />`
110
+ * - If `shouldCloseOnEscape` is `true` and the user presses the ESC key.
111
+ *
112
+ * This should be used to close the `<DrawerLayout.Tray />` in these cases
113
+ */
114
+ onDismiss?: (
115
+ event: React.UIEvent | React.FocusEvent,
116
+ documentClick?: boolean
117
+ ) => void
118
+
119
+ shouldContainFocus?: boolean
120
+
121
+ shouldReturnFocus?: boolean
122
+
123
+ shouldCloseOnDocumentClick?: boolean
124
+ /**
125
+ * Should the `<DrawerLayout.Tray />` close when ESC is pressed.
126
+ * Note that it will only close if it's in the overlay mode (if there is
127
+ * less space for the content than `DrawerLayout.props.minWidth`)
128
+ */
129
+ shouldCloseOnEscape?: boolean
130
+ }
131
+
132
+ type PropsPassedToTransition = {
133
+ /**
134
+ * Callback fired when the `<DrawerLayout.Tray />` transitions in/out
135
+ */
136
+ onTransition?: (
137
+ toState: BaseTransitionStatesType,
138
+ fromState: BaseTransitionStatesType
139
+ ) => void
140
+
141
+ /**
142
+ * Callback fired before the `<DrawerLayout.Tray />` transitions in
143
+ */
144
+ onEnter?: () => void
145
+
146
+ /**
147
+ * Callback fired as the `<DrawerLayout.Tray />` begins to transition in
148
+ */
149
+ onEntering?: () => void
150
+
151
+ /**
152
+ * Callback fired after the `<DrawerLayout.Tray />` finishes transitioning in
153
+ */
154
+ onEntered?: (type?: TransitionType) => void
155
+
156
+ /**
157
+ * Callback fired right before the `<DrawerLayout.Tray />` transitions out
158
+ */
159
+ onExit?: () => void
160
+
161
+ /**
162
+ * Callback fired as the `<DrawerLayout.Tray />` begins to transition out
163
+ */
164
+ onExiting?: () => void
165
+
166
+ /**
167
+ * Callback fired after the `<DrawerLayout.Tray />` finishes transitioning out
168
+ */
169
+ onExited?: (type?: TransitionType) => void
170
+ }
171
+
172
+ type DrawerLayoutTrayState = {
173
+ transitioning: boolean
174
+ portalOpen: boolean
175
+ }
176
+
177
+ type DrawerLayoutTrayStyleProps = {
178
+ placement: DrawerTrayPlacement
179
+ }
180
+
181
+ type PropKeys = keyof DrawerLayoutTrayOwnProps
182
+
183
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
184
+
185
+ type DrawerLayoutTrayProps = DrawerLayoutTrayOwnProps &
186
+ WithStyleProps<DrawerLayoutTrayTheme, DrawerLayoutTrayStyle> &
187
+ OtherHTMLAttributes<DrawerLayoutTrayOwnProps>
188
+
189
+ type DrawerLayoutTrayStyle = ComponentStyle<
190
+ 'drawerTray' | 'drawerTrayWithShadow' | 'drawerTrayContent'
191
+ >
192
+ const allowedProps: AllowedPropKeys = [
193
+ 'label',
194
+ 'children',
195
+ 'render',
196
+ 'placement',
197
+ 'open',
198
+ 'onOpen',
199
+ 'onClose',
200
+ 'border',
201
+ 'shadow',
202
+ 'onTransition',
203
+ 'onEnter',
204
+ 'onEntering',
205
+ 'onEntered',
206
+ 'onExit',
207
+ 'onExiting',
208
+ 'onExited',
209
+ 'contentRef',
210
+ 'mountNode',
211
+ 'defaultFocusElement',
212
+ 'liveRegion',
213
+ 'onDismiss',
214
+ 'shouldContainFocus',
215
+ 'shouldReturnFocus',
216
+ 'shouldCloseOnDocumentClick',
217
+ 'shouldCloseOnEscape',
218
+ 'dir'
219
+ ]
220
+
221
+ export type {
222
+ DrawerLayoutTrayProps,
223
+ DrawerLayoutTrayState,
224
+ DrawerLayoutTrayStyle,
225
+ DrawerLayoutTrayStyleProps,
226
+ DrawerTrayPlacement
227
+ }
228
+ export { allowedProps }
@@ -0,0 +1,106 @@
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
+ DrawerLayoutTrayProps,
28
+ DrawerLayoutTrayStyleProps,
29
+ DrawerLayoutTrayStyle
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['DrawerLayoutTray'],
45
+ props: DrawerLayoutTrayProps,
46
+ _sharedTokens: SharedTokens,
47
+ state: DrawerLayoutTrayStyleProps
48
+ ): DrawerLayoutTrayStyle => {
49
+ const { border } = props
50
+ const { placement } = state
51
+
52
+ const borderPlacementStyle = {
53
+ start: { borderRightWidth: componentTheme.borderWidth },
54
+ end: { borderLeftWidth: componentTheme.borderWidth }
55
+ }
56
+
57
+ const borderStyles = border
58
+ ? {
59
+ borderWidth: 0,
60
+ borderColor: componentTheme.borderColor,
61
+ borderStyle: componentTheme.borderStyle,
62
+ boxSizing: 'border-box',
63
+ ...borderPlacementStyle[placement]
64
+ }
65
+ : {
66
+ boxSizing: 'content-box'
67
+ }
68
+
69
+ const placementStyleMap = {
70
+ start: { left: 0 },
71
+ end: { right: 0 }
72
+ }
73
+
74
+ const trayStyle = {
75
+ position: 'absolute',
76
+ backgroundColor: componentTheme.background,
77
+ zIndex: componentTheme.zIndex,
78
+ overflowY: componentTheme.overflowY,
79
+ overflowX: componentTheme.overflowX,
80
+ ...borderStyles,
81
+ top: 0,
82
+ bottom: 0,
83
+ ...placementStyleMap[placement]
84
+ }
85
+
86
+ return {
87
+ drawerTray: {
88
+ label: 'drawerTray',
89
+ ...trayStyle
90
+ },
91
+ drawerTrayWithShadow: {
92
+ label: 'drawerTray--with-shadow',
93
+ ...trayStyle,
94
+ boxShadow: componentTheme.boxShadow,
95
+ border: 0
96
+ },
97
+ drawerTrayContent: {
98
+ label: 'drawerTray__content',
99
+ overflowY: componentTheme.contentOverflowY,
100
+ height: '100%',
101
+ boxSizing: 'content-box'
102
+ }
103
+ }
104
+ }
105
+
106
+ export default generateStyle
@@ -0,0 +1,231 @@
1
+ ---
2
+ describes: DrawerLayout
3
+ ---
4
+
5
+ The `<DrawerLayout />` component creates a layout consisting of both `<DrawerLayout.Tray />` and `<DrawerLayout.Content />`.
6
+ The tray can be placed at the `start` or `end` position. When there is sufficient space available,
7
+ the tray is positioned alongside the content. As the screen gets smaller, the `<DrawerTray />` can
8
+ be configured to overlay the `<DrawerLayout.Content />`
9
+
10
+ The `minWidth` prop specifies a breakpoint. When the `<DrawerLayout.Content />` resizes such that the width is
11
+ less than the designated `minWidth`, the tray overlays the content
12
+
13
+ ```js
14
+ ---
15
+ type: example
16
+ ---
17
+ const Example = () => {
18
+ const [open, setOpen] = useState(false)
19
+ const [trayIsOverlayed, setTrayIsOverlayed] = useState(false)
20
+
21
+ const handleOverlayTrayChange = (trayIsOverlayed) => {
22
+ setTrayIsOverlayed(trayIsOverlayed)
23
+ }
24
+
25
+ const handleTrayDismiss = () => {
26
+ setOpen(false)
27
+ }
28
+
29
+ return (
30
+ <View height="25rem" as="div" background="primary" position="relative">
31
+ {trayIsOverlayed && open && <Mask onClick={handleTrayDismiss} />}
32
+ <DrawerLayout onOverlayTrayChange={handleOverlayTrayChange}>
33
+ <DrawerLayout.Tray
34
+ id="DrawerLayoutTrayExample1"
35
+ open={open}
36
+ placement="start"
37
+ label="Drawer Tray Start Example"
38
+ onDismiss={handleTrayDismiss}
39
+ >
40
+ <View
41
+ as="div"
42
+ maxWidth="16rem"
43
+ textAlign="center"
44
+ margin="large auto"
45
+ padding="small"
46
+ >
47
+ <CloseButton
48
+ placement="end"
49
+ offset="small"
50
+ onClick={handleTrayDismiss}
51
+ screenReaderLabel="Close"
52
+ />
53
+ <Avatar name="foo bar" margin="0 0 small 0" />
54
+ <Text as="div" size="x-small">
55
+ Hello from start tray with a small amount of placeholder content
56
+ </Text>
57
+ </View>
58
+ </DrawerLayout.Tray>
59
+ <DrawerLayout.Content label="Drawer content example">
60
+ <View as="div" height="100%" background="primary">
61
+ <View as="div" padding="x-large" background="primary">
62
+ <Heading border="bottom">A simple drawer layout</Heading>
63
+ <Grid startAt="medium" vAlign="middle" colSpacing="none">
64
+ <Grid.Row>
65
+ <Grid.Col>
66
+ <Button
67
+ margin="small 0"
68
+ size="small"
69
+ onClick={() => {
70
+ setOpen(true)
71
+ }}
72
+ aria-haspopup={trayIsOverlayed ? 'dialog' : 'region'}
73
+ aria-controls="DrawerLayoutTrayExample1"
74
+ >
75
+ Expand tray
76
+ </Button>
77
+ </Grid.Col>
78
+ </Grid.Row>
79
+ </Grid>
80
+ <Text size="x-small">
81
+ <p>{lorem.paragraph()}</p>
82
+ </Text>
83
+ <Text size="x-small">
84
+ <p>{lorem.paragraph()}</p>
85
+ </Text>
86
+ </View>
87
+ </View>
88
+ </DrawerLayout.Content>
89
+ </DrawerLayout>
90
+ </View>
91
+ )
92
+ }
93
+
94
+ render(<Example />)
95
+ ```
96
+
97
+ Multiple `<DrawerLayout />` components can be nested in order to place trays on both sides
98
+
99
+ ```js
100
+ ---
101
+ type: example
102
+ ---
103
+ const Example = () => {
104
+ const [endOpen, setEndOpen] = useState(false)
105
+ const [startOpen, setStartOpen] = useState(false)
106
+
107
+ return (
108
+ <View height="40rem" display="block" background="primary">
109
+ <DrawerLayout>
110
+ <DrawerLayout.Tray
111
+ open={endOpen}
112
+ placement="end"
113
+ label="Drawer Tray End Example"
114
+ onDismiss={() => {
115
+ setEndOpen(false)
116
+ }}
117
+ >
118
+ <View
119
+ as="div"
120
+ maxWidth="48rem"
121
+ textAlign="center"
122
+ margin="large auto"
123
+ padding="large"
124
+ background="primary"
125
+ >
126
+ <CloseButton
127
+ placement="end"
128
+ offset="small"
129
+ onClick={() => {
130
+ setEndOpen(false)
131
+ }}
132
+ screenReaderLabel="Close"
133
+ />
134
+ <Text as="div" size="x-small">
135
+ Hello from end tray with a good amount of content as well
136
+ </Text>
137
+ </View>
138
+ </DrawerLayout.Tray>
139
+ <DrawerLayout.Content label="Drawer content example containing another layout">
140
+ <DrawerLayout>
141
+ <DrawerLayout.Tray
142
+ label="Layout Tray Start Example"
143
+ open={startOpen}
144
+ placement="start"
145
+ onDismiss={() => {
146
+ setStartOpen(false)
147
+ }}
148
+ >
149
+ <View
150
+ as="div"
151
+ maxWidth="16rem"
152
+ textAlign="center"
153
+ margin="large auto"
154
+ padding="small"
155
+ >
156
+ <CloseButton
157
+ placement="end"
158
+ offset="small"
159
+ onClick={() => {
160
+ setStartOpen(false)
161
+ }}
162
+ screenReaderLabel="Close"
163
+ />
164
+ <Avatar name="foo bar" margin="0 0 small 0" />
165
+ <Text as="div" size="x-small">
166
+ Hello from start tray with a small amount of placeholder
167
+ content
168
+ </Text>
169
+ </View>
170
+ </DrawerLayout.Tray>
171
+ <DrawerLayout.Content label="Drawer content example containing a responsive ">
172
+ <View as="div" background="primary" height='100%'>
173
+ <View as="div" padding="x-large" background="primary">
174
+ <Heading border="bottom">A nested drawer layout</Heading>
175
+ <Grid startAt="medium" vAlign="middle" colSpacing="none">
176
+ <Grid.Row>
177
+ <Grid.Col>
178
+ <Button
179
+ margin="small 0"
180
+ size="small"
181
+ onClick={() => {
182
+ setStartOpen(true)
183
+ }}
184
+ aria-haspopup="dialog"
185
+ >
186
+ Expand start tray
187
+ </Button>
188
+ </Grid.Col>
189
+ <Grid.Col width="auto">
190
+ <Button
191
+ margin="small 0"
192
+ size="small"
193
+ onClick={() => {
194
+ setEndOpen(true)
195
+ }}
196
+ aria-haspopup="dialog"
197
+ >
198
+ Expand end tray
199
+ </Button>
200
+ </Grid.Col>
201
+ </Grid.Row>
202
+ <Grid.Row colSpacing="medium">
203
+ <Grid.Col>
204
+ <Img role="img" src={placeholderImage(250, 250)} />
205
+ </Grid.Col>
206
+ <Grid.Col>
207
+ <Img role="img" src={placeholderImage(250, 250)} />
208
+ </Grid.Col>
209
+ <Grid.Col>
210
+ <Img role="img" src={placeholderImage(250, 250)} />
211
+ </Grid.Col>
212
+ </Grid.Row>
213
+ </Grid>
214
+ <Text size="x-small">
215
+ <p>{lorem.paragraph()}</p>
216
+ </Text>
217
+ <Text size="x-small">
218
+ <p>{lorem.paragraph()}</p>
219
+ </Text>
220
+ </View>
221
+ </View>
222
+ </DrawerLayout.Content>
223
+ </DrawerLayout>
224
+ </DrawerLayout.Content>
225
+ </DrawerLayout>
226
+ </View>
227
+ )
228
+ }
229
+
230
+ render(<Example />)
231
+ ```
@@ -0,0 +1,75 @@
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 { DrawerLayout } from '../index'
28
+ import type { DrawerLayoutProps } from '../props'
29
+ import type { DrawerLayoutTrayProps } from '../DrawerTray/props'
30
+
31
+ type DrawerLayoutFixtureProps = {
32
+ layoutWidth?: string | number
33
+ trayWidth?: string | number
34
+ placement?: DrawerLayoutTrayProps['placement']
35
+ open?: DrawerLayoutTrayProps['open']
36
+ onOverlayTrayChange?: DrawerLayoutProps['onOverlayTrayChange']
37
+ }
38
+
39
+ export default class DrawerLayoutFixture extends Component<DrawerLayoutFixtureProps> {
40
+ static defaultProps = {
41
+ layoutWidth: '600px',
42
+ trayWidth: '200px',
43
+ open: false,
44
+ placement: 'start',
45
+ onOverlayTrayChange: () => {}
46
+ }
47
+
48
+ render() {
49
+ const { layoutWidth, trayWidth, open, placement, onOverlayTrayChange } =
50
+ this.props
51
+
52
+ return (
53
+ <div style={{ width: layoutWidth }}>
54
+ <DrawerLayout
55
+ minWidth="500px"
56
+ onOverlayTrayChange={onOverlayTrayChange}
57
+ >
58
+ <DrawerLayout.Tray
59
+ open={open}
60
+ placement={placement}
61
+ label="Test DrawerTray"
62
+ >
63
+ <div style={{ width: trayWidth }}>Hello from tray</div>
64
+ </DrawerLayout.Tray>
65
+ <DrawerLayout.Content label="Test DrawerContent">
66
+ <div>
67
+ Hello from content
68
+ <button>Expand</button>
69
+ </div>
70
+ </DrawerLayout.Content>
71
+ </DrawerLayout>
72
+ </div>
73
+ )
74
+ }
75
+ }
@@ -67,7 +67,7 @@ category: components
67
67
  ---
68
68
  **/
69
69
  @withDeterministicId()
70
- @withStyle(generateStyle, null)
70
+ @withStyle(generateStyle)
71
71
  @textDirectionContextConsumer()
72
72
  class DrawerLayout extends Component<DrawerLayoutProps, DrawerLayoutState> {
73
73
  static readonly componentId = 'DrawerLayout'