@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,224 @@
1
+ var _dec, _dec2, _dec3, _class, _DrawerLayout;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import { Children, Component, createContext } from 'react';
27
+ import { textDirectionContextConsumer } from '@instructure/ui-i18n';
28
+ import { matchComponentTypes, safeCloneElement, withDeterministicId } from '@instructure/ui-react-utils';
29
+ import { getBoundingClientRect } from '@instructure/ui-dom-utils';
30
+ import { createChainedFunction, px } from '@instructure/ui-utils';
31
+ import { logError as error } from '@instructure/console';
32
+ import { mirrorHorizontalPlacement } from '@instructure/ui-position';
33
+ import { DrawerContent } from "./DrawerContent/index.js";
34
+ import { DrawerTray } from "./DrawerTray/index.js";
35
+ import { withStyle } from '@instructure/emotion';
36
+ import generateStyle from "./styles.js";
37
+ import { allowedProps } from "./props.js";
38
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
39
+ /**
40
+ ---
41
+ category: components
42
+ ---
43
+ **/
44
+ let DrawerLayout = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec3 = textDirectionContextConsumer(), _dec(_class = _dec2(_class = _dec3(_class = (_DrawerLayout = class DrawerLayout extends Component {
45
+ constructor(_props) {
46
+ super(_props);
47
+ this._id = void 0;
48
+ this._content = null;
49
+ this._tray = null;
50
+ this.ref = null;
51
+ this.handleRef = el => {
52
+ this.ref = el;
53
+ };
54
+ this.handleTrayContentRef = el => {
55
+ this._tray = el;
56
+ };
57
+ this.handleContentSizeChange = ({
58
+ width
59
+ }) => {
60
+ this.setState((state, props) => {
61
+ const nextState = this.getNextState(props.minWidth, state.trayWidth, width, state.shouldOverlayTray);
62
+ if (state.shouldOverlayTray !== nextState.shouldOverlayTray) {
63
+ this.notifyOverlayTrayChange(nextState.shouldOverlayTray);
64
+ }
65
+ return nextState;
66
+ });
67
+ };
68
+ this.handleTraySizeChange = ({
69
+ width
70
+ }) => {
71
+ this.setState((state, props) => {
72
+ const nextState = this.getNextState(props.minWidth, width, state.contentWidth, true);
73
+ if (state.shouldOverlayTray !== nextState.shouldOverlayTray) {
74
+ this.notifyOverlayTrayChange(nextState.shouldOverlayTray);
75
+ }
76
+ return nextState;
77
+ });
78
+ };
79
+ this.handleTrayTransitionEnter = () => {
80
+ let width = 0;
81
+ if (this._tray) {
82
+ width = getBoundingClientRect(this._tray).width;
83
+ }
84
+ this.handleTraySizeChange({
85
+ width
86
+ });
87
+ };
88
+ this.handleTrayTransitionExit = () => {
89
+ this.handleTraySizeChange({
90
+ width: 0
91
+ });
92
+ };
93
+ this.state = {
94
+ shouldOverlayTray: false,
95
+ trayWidth: 0,
96
+ contentWidth: 0
97
+ };
98
+ this._id = _props.deterministicId();
99
+ }
100
+ componentDidMount() {
101
+ var _this$props$makeStyle, _this$props;
102
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
103
+ }
104
+ componentDidUpdate() {
105
+ var _this$props$makeStyle2, _this$props2;
106
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
107
+ }
108
+ get trayProps() {
109
+ const tray = Children.toArray(this.props.children).filter(child => matchComponentTypes(child, [DrawerTray]))[0];
110
+ return tray.props;
111
+ }
112
+ get trayPlacement() {
113
+ const _this$trayProps = this.trayProps,
114
+ placement = _this$trayProps.placement,
115
+ _this$trayProps$dir = _this$trayProps.dir,
116
+ dir = _this$trayProps$dir === void 0 ? this.props.dir : _this$trayProps$dir;
117
+ const isRtl = dir === textDirectionContextConsumer.DIRECTION.rtl;
118
+ return isRtl ? mirrorHorizontalPlacement(placement, ' ') : placement;
119
+ }
120
+ get contentMargin() {
121
+ const trayWidth = this.state.trayWidth || 0;
122
+ return this.state.shouldOverlayTray ? 0 : trayWidth;
123
+ }
124
+ get contentStyle() {
125
+ const shouldOverlayTray = this.shouldOverlayTray(this.props.minWidth, this.state.trayWidth, this.state.contentWidth, this.state.shouldOverlayTray);
126
+ let marginLeft = 0;
127
+ let marginRight = 0;
128
+ if (!shouldOverlayTray) {
129
+ if (this.trayPlacement === 'start') {
130
+ marginLeft = this.contentMargin;
131
+ }
132
+ if (this.trayPlacement === 'end') {
133
+ marginRight = this.contentMargin;
134
+ }
135
+ }
136
+ return {
137
+ marginLeft: `${marginLeft}px`,
138
+ marginRight: `${marginRight}px`
139
+ };
140
+ }
141
+ shouldOverlayTray(minWidth, trayWidth, contentWidth, trayIsOverlayed) {
142
+ if (!this._content) return false;
143
+ const minWidthPx = px(minWidth, this._content);
144
+ if (trayIsOverlayed) {
145
+ return contentWidth - trayWidth < minWidthPx;
146
+ } else {
147
+ return contentWidth < minWidthPx;
148
+ }
149
+ }
150
+ getNextState(minWidth, trayWidth, contentWidth, trayIsOverlayed) {
151
+ const shouldOverlayTray = this.shouldOverlayTray(minWidth, trayWidth, contentWidth, trayIsOverlayed);
152
+ return {
153
+ trayWidth,
154
+ contentWidth,
155
+ shouldOverlayTray
156
+ };
157
+ }
158
+ notifyOverlayTrayChange(shouldOverlayTray) {
159
+ const onOverlayTrayChange = this.props.onOverlayTrayChange;
160
+ if (typeof onOverlayTrayChange === 'function') {
161
+ onOverlayTrayChange(shouldOverlayTray);
162
+ }
163
+ }
164
+ renderChildren() {
165
+ let trayCount = 0;
166
+ let contentCount = 0;
167
+ const children = Children.map(this.props.children, (child, _index) => {
168
+ if (matchComponentTypes(child, [DrawerTray])) {
169
+ trayCount++;
170
+ return safeCloneElement(child, {
171
+ label: child.props.label,
172
+ key: child.props.label,
173
+ [DrawerTray.locatorAttribute]: this._id,
174
+ contentRef: this.handleTrayContentRef,
175
+ onEnter: this.handleTrayTransitionEnter,
176
+ onExit: this.handleTrayTransitionExit
177
+ });
178
+ } else if (matchComponentTypes(child, [DrawerContent])) {
179
+ contentCount++;
180
+ const handleContentRef = el => {
181
+ const contentRef = child.props.contentRef;
182
+ this._content = el;
183
+ if (typeof contentRef === 'function') {
184
+ contentRef(el);
185
+ }
186
+ };
187
+ return this.state.trayWidth !== null ? safeCloneElement(child, {
188
+ label: child.props.label,
189
+ key: child.props.label,
190
+ [DrawerContent.locatorAttribute]: this._id,
191
+ style: this.contentStyle,
192
+ onSizeChange: createChainedFunction(this.handleContentSizeChange, child.props.onSizeChange),
193
+ contentRef: handleContentRef
194
+ }) : null;
195
+ } else {
196
+ return child;
197
+ }
198
+ });
199
+ error(trayCount <= 1, `[DrawerLayout] Only one 'DrawerTray' per 'DrawerLayout' is supported.`);
200
+ error(contentCount <= 1, `[DrawerLayout] Only one 'DrawerContent' per 'DrawerLayout' is supported.`);
201
+ return children;
202
+ }
203
+ render() {
204
+ var _this$props$styles;
205
+ const props = {
206
+ [DrawerLayout.locatorAttribute]: this._id
207
+ };
208
+ return _jsx(DrawerLayoutContext.Provider, {
209
+ value: this.state.shouldOverlayTray,
210
+ children: _jsx("div", {
211
+ ...props,
212
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.drawerLayout,
213
+ ref: this.handleRef,
214
+ "data-cid": "DrawerLayout",
215
+ children: this.renderChildren()
216
+ })
217
+ });
218
+ }
219
+ }, _DrawerLayout.displayName = "DrawerLayout", _DrawerLayout.componentId = 'DrawerLayout', _DrawerLayout.locatorAttribute = 'data-drawer-layout', _DrawerLayout.allowedProps = allowedProps, _DrawerLayout.defaultProps = {
220
+ minWidth: '30rem'
221
+ }, _DrawerLayout.Content = DrawerContent, _DrawerLayout.Tray = DrawerTray, _DrawerLayout)) || _class) || _class) || _class);
222
+ export default DrawerLayout;
223
+ export { DrawerLayout, DrawerContent, DrawerTray };
224
+ export const DrawerLayoutContext = /*#__PURE__*/createContext(false);
@@ -0,0 +1,26 @@
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
+ const allowedProps = ['children', 'minWidth', 'onOverlayTrayChange', 'dir'];
26
+ export { allowedProps };
@@ -0,0 +1,44 @@
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
+ /**
26
+ * ---
27
+ * private: true
28
+ * ---
29
+ * Generates the style object from the theme and provided additional information
30
+ * @param {Object} componentTheme The theme variable object.
31
+ * @param {Object} props the props of the component, the style is applied to
32
+ * @param {Object} state the state of the component, the style is applied to
33
+ * @return {Object} The final style object, which will be used in the component
34
+ */
35
+ const generateStyle = () => {
36
+ return {
37
+ drawerLayout: {
38
+ label: 'drawerLayout',
39
+ position: 'relative',
40
+ height: '100%'
41
+ }
42
+ };
43
+ };
44
+ export default generateStyle;
@@ -21,4 +21,4 @@
21
21
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  * SOFTWARE.
23
23
  */
24
- export { DrawerLayout, DrawerContent, DrawerTray } from "./DrawerLayout/index.js";
24
+ export { DrawerLayout, DrawerContent, DrawerTray } from "../DrawerLayout/v1/index.js";
@@ -0,0 +1,24 @@
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
+ export { DrawerLayout, DrawerContent, DrawerTray } from "../DrawerLayout/v2/index.js";
@@ -44,7 +44,7 @@ parent: DrawerLayout
44
44
  id: DrawerLayout.Content
45
45
  ---
46
46
  **/
47
- let DrawerContent = exports.DrawerContent = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec(_class = (_DrawerContent = class DrawerContent extends _react.Component {
47
+ let DrawerContent = exports.DrawerContent = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = (_DrawerContent = class DrawerContent extends _react.Component {
48
48
  constructor(...args) {
49
49
  super(...args);
50
50
  this.ref = null;
@@ -51,7 +51,7 @@ parent: DrawerLayout
51
51
  id: DrawerLayout.Tray
52
52
  ---
53
53
  **/
54
- let DrawerTray = exports.DrawerTray = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _textDirectionContextConsumer.textDirectionContextConsumer)(), _dec(_class = _dec2(_class = (_DrawerTray = class DrawerTray extends _react.Component {
54
+ let DrawerTray = exports.DrawerTray = (_dec = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec2 = (0, _textDirectionContextConsumer.textDirectionContextConsumer)(), _dec(_class = _dec2(_class = (_DrawerTray = class DrawerTray extends _react.Component {
55
55
  get _content() {
56
56
  return this.ref;
57
57
  }
@@ -0,0 +1,245 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "DrawerContent", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _DrawerContent.DrawerContent;
11
+ }
12
+ });
13
+ exports.DrawerLayoutContext = exports.DrawerLayout = void 0;
14
+ Object.defineProperty(exports, "DrawerTray", {
15
+ enumerable: true,
16
+ get: function () {
17
+ return _DrawerTray.DrawerTray;
18
+ }
19
+ });
20
+ exports.default = void 0;
21
+ var _react = require("react");
22
+ var _textDirectionContextConsumer = require("@instructure/ui-i18n/lib/textDirectionContextConsumer.js");
23
+ var _matchComponentTypes = require("@instructure/ui-react-utils/lib/matchComponentTypes.js");
24
+ var _safeCloneElement = require("@instructure/ui-react-utils/lib/safeCloneElement.js");
25
+ var _withDeterministicId = require("@instructure/ui-react-utils/lib/DeterministicIdContext/withDeterministicId.js");
26
+ var _getBoundingClientRect = require("@instructure/ui-dom-utils/lib/getBoundingClientRect.js");
27
+ var _createChainedFunction = require("@instructure/ui-utils/lib/createChainedFunction.js");
28
+ var _px = require("@instructure/ui-utils/lib/px.js");
29
+ var _console = require("@instructure/console");
30
+ var _mirrorHorizontalPlacement = require("@instructure/ui-position/lib/mirrorHorizontalPlacement.js");
31
+ var _DrawerContent = require("./DrawerContent");
32
+ var _DrawerTray = require("./DrawerTray");
33
+ var _emotion = require("@instructure/emotion");
34
+ var _styles = _interopRequireDefault(require("./styles"));
35
+ var _props2 = require("./props");
36
+ var _jsxRuntime = require("@emotion/react/jsx-runtime");
37
+ var _dec, _dec2, _dec3, _class, _DrawerLayout;
38
+ /*
39
+ * The MIT License (MIT)
40
+ *
41
+ * Copyright (c) 2015 - present Instructure, Inc.
42
+ *
43
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
44
+ * of this software and associated documentation files (the "Software"), to deal
45
+ * in the Software without restriction, including without limitation the rights
46
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
47
+ * copies of the Software, and to permit persons to whom the Software is
48
+ * furnished to do so, subject to the following conditions:
49
+ *
50
+ * The above copyright notice and this permission notice shall be included in all
51
+ * copies or substantial portions of the Software.
52
+ *
53
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
54
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
55
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
56
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
57
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
58
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
59
+ * SOFTWARE.
60
+ */
61
+ /**
62
+ ---
63
+ category: components
64
+ ---
65
+ **/
66
+ let DrawerLayout = exports.DrawerLayout = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _emotion.withStyleLegacy)(_styles.default, null), _dec3 = (0, _textDirectionContextConsumer.textDirectionContextConsumer)(), _dec(_class = _dec2(_class = _dec3(_class = (_DrawerLayout = class DrawerLayout extends _react.Component {
67
+ constructor(_props) {
68
+ super(_props);
69
+ this._id = void 0;
70
+ this._content = null;
71
+ this._tray = null;
72
+ this.ref = null;
73
+ this.handleRef = el => {
74
+ this.ref = el;
75
+ };
76
+ this.handleTrayContentRef = el => {
77
+ this._tray = el;
78
+ };
79
+ this.handleContentSizeChange = ({
80
+ width
81
+ }) => {
82
+ this.setState((state, props) => {
83
+ const nextState = this.getNextState(props.minWidth, state.trayWidth, width, state.shouldOverlayTray);
84
+ if (state.shouldOverlayTray !== nextState.shouldOverlayTray) {
85
+ this.notifyOverlayTrayChange(nextState.shouldOverlayTray);
86
+ }
87
+ return nextState;
88
+ });
89
+ };
90
+ this.handleTraySizeChange = ({
91
+ width
92
+ }) => {
93
+ this.setState((state, props) => {
94
+ const nextState = this.getNextState(props.minWidth, width, state.contentWidth, true);
95
+ if (state.shouldOverlayTray !== nextState.shouldOverlayTray) {
96
+ this.notifyOverlayTrayChange(nextState.shouldOverlayTray);
97
+ }
98
+ return nextState;
99
+ });
100
+ };
101
+ this.handleTrayTransitionEnter = () => {
102
+ let width = 0;
103
+ if (this._tray) {
104
+ width = (0, _getBoundingClientRect.getBoundingClientRect)(this._tray).width;
105
+ }
106
+ this.handleTraySizeChange({
107
+ width
108
+ });
109
+ };
110
+ this.handleTrayTransitionExit = () => {
111
+ this.handleTraySizeChange({
112
+ width: 0
113
+ });
114
+ };
115
+ this.state = {
116
+ shouldOverlayTray: false,
117
+ trayWidth: 0,
118
+ contentWidth: 0
119
+ };
120
+ this._id = _props.deterministicId();
121
+ }
122
+ componentDidMount() {
123
+ var _this$props$makeStyle, _this$props;
124
+ (_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
125
+ }
126
+ componentDidUpdate() {
127
+ var _this$props$makeStyle2, _this$props2;
128
+ (_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
129
+ }
130
+ get trayProps() {
131
+ const tray = _react.Children.toArray(this.props.children).filter(child => (0, _matchComponentTypes.matchComponentTypes)(child, [_DrawerTray.DrawerTray]))[0];
132
+ return tray.props;
133
+ }
134
+ get trayPlacement() {
135
+ const _this$trayProps = this.trayProps,
136
+ placement = _this$trayProps.placement,
137
+ _this$trayProps$dir = _this$trayProps.dir,
138
+ dir = _this$trayProps$dir === void 0 ? this.props.dir : _this$trayProps$dir;
139
+ const isRtl = dir === _textDirectionContextConsumer.textDirectionContextConsumer.DIRECTION.rtl;
140
+ return isRtl ? (0, _mirrorHorizontalPlacement.mirrorHorizontalPlacement)(placement, ' ') : placement;
141
+ }
142
+ get contentMargin() {
143
+ const trayWidth = this.state.trayWidth || 0;
144
+ return this.state.shouldOverlayTray ? 0 : trayWidth;
145
+ }
146
+ get contentStyle() {
147
+ const shouldOverlayTray = this.shouldOverlayTray(this.props.minWidth, this.state.trayWidth, this.state.contentWidth, this.state.shouldOverlayTray);
148
+ let marginLeft = 0;
149
+ let marginRight = 0;
150
+ if (!shouldOverlayTray) {
151
+ if (this.trayPlacement === 'start') {
152
+ marginLeft = this.contentMargin;
153
+ }
154
+ if (this.trayPlacement === 'end') {
155
+ marginRight = this.contentMargin;
156
+ }
157
+ }
158
+ return {
159
+ marginLeft: `${marginLeft}px`,
160
+ marginRight: `${marginRight}px`
161
+ };
162
+ }
163
+ shouldOverlayTray(minWidth, trayWidth, contentWidth, trayIsOverlayed) {
164
+ if (!this._content) return false;
165
+ const minWidthPx = (0, _px.px)(minWidth, this._content);
166
+ if (trayIsOverlayed) {
167
+ return contentWidth - trayWidth < minWidthPx;
168
+ } else {
169
+ return contentWidth < minWidthPx;
170
+ }
171
+ }
172
+ getNextState(minWidth, trayWidth, contentWidth, trayIsOverlayed) {
173
+ const shouldOverlayTray = this.shouldOverlayTray(minWidth, trayWidth, contentWidth, trayIsOverlayed);
174
+ return {
175
+ trayWidth,
176
+ contentWidth,
177
+ shouldOverlayTray
178
+ };
179
+ }
180
+ notifyOverlayTrayChange(shouldOverlayTray) {
181
+ const onOverlayTrayChange = this.props.onOverlayTrayChange;
182
+ if (typeof onOverlayTrayChange === 'function') {
183
+ onOverlayTrayChange(shouldOverlayTray);
184
+ }
185
+ }
186
+ renderChildren() {
187
+ let trayCount = 0;
188
+ let contentCount = 0;
189
+ const children = _react.Children.map(this.props.children, (child, _index) => {
190
+ if ((0, _matchComponentTypes.matchComponentTypes)(child, [_DrawerTray.DrawerTray])) {
191
+ trayCount++;
192
+ return (0, _safeCloneElement.safeCloneElement)(child, {
193
+ label: child.props.label,
194
+ key: child.props.label,
195
+ [_DrawerTray.DrawerTray.locatorAttribute]: this._id,
196
+ contentRef: this.handleTrayContentRef,
197
+ onEnter: this.handleTrayTransitionEnter,
198
+ onExit: this.handleTrayTransitionExit
199
+ });
200
+ } else if ((0, _matchComponentTypes.matchComponentTypes)(child, [_DrawerContent.DrawerContent])) {
201
+ contentCount++;
202
+ const handleContentRef = el => {
203
+ const contentRef = child.props.contentRef;
204
+ this._content = el;
205
+ if (typeof contentRef === 'function') {
206
+ contentRef(el);
207
+ }
208
+ };
209
+ return this.state.trayWidth !== null ? (0, _safeCloneElement.safeCloneElement)(child, {
210
+ label: child.props.label,
211
+ key: child.props.label,
212
+ [_DrawerContent.DrawerContent.locatorAttribute]: this._id,
213
+ style: this.contentStyle,
214
+ onSizeChange: (0, _createChainedFunction.createChainedFunction)(this.handleContentSizeChange, child.props.onSizeChange),
215
+ contentRef: handleContentRef
216
+ }) : null;
217
+ } else {
218
+ return child;
219
+ }
220
+ });
221
+ (0, _console.logError)(trayCount <= 1, `[DrawerLayout] Only one 'DrawerTray' per 'DrawerLayout' is supported.`);
222
+ (0, _console.logError)(contentCount <= 1, `[DrawerLayout] Only one 'DrawerContent' per 'DrawerLayout' is supported.`);
223
+ return children;
224
+ }
225
+ render() {
226
+ var _this$props$styles;
227
+ const props = {
228
+ [DrawerLayout.locatorAttribute]: this._id
229
+ };
230
+ return (0, _jsxRuntime.jsx)(DrawerLayoutContext.Provider, {
231
+ value: this.state.shouldOverlayTray,
232
+ children: (0, _jsxRuntime.jsx)("div", {
233
+ ...props,
234
+ css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.drawerLayout,
235
+ ref: this.handleRef,
236
+ "data-cid": "DrawerLayout",
237
+ children: this.renderChildren()
238
+ })
239
+ });
240
+ }
241
+ }, _DrawerLayout.displayName = "DrawerLayout", _DrawerLayout.componentId = 'DrawerLayout', _DrawerLayout.locatorAttribute = 'data-drawer-layout', _DrawerLayout.allowedProps = _props2.allowedProps, _DrawerLayout.defaultProps = {
242
+ minWidth: '30rem'
243
+ }, _DrawerLayout.Content = _DrawerContent.DrawerContent, _DrawerLayout.Tray = _DrawerTray.DrawerTray, _DrawerLayout)) || _class) || _class) || _class);
244
+ var _default = exports.default = DrawerLayout;
245
+ const DrawerLayoutContext = exports.DrawerLayoutContext = /*#__PURE__*/(0, _react.createContext)(false);