@instructure/ui-modal 10.19.0 → 10.19.1-snapshot-1
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 +11 -0
- package/es/Modal/ModalBody/styles.js +4 -1
- package/es/Modal/ModalHeader/props.js +1 -2
- package/es/Modal/ModalHeader/styles.js +6 -6
- package/es/Modal/index.js +41 -80
- package/es/Modal/styles.js +8 -1
- package/lib/Modal/ModalBody/styles.js +4 -1
- package/lib/Modal/ModalHeader/props.js +1 -2
- package/lib/Modal/ModalHeader/styles.js +6 -6
- package/lib/Modal/index.js +41 -80
- package/lib/Modal/styles.js +8 -1
- package/package.json +19 -19
- package/src/Modal/ModalBody/styles.ts +4 -1
- package/src/Modal/ModalHeader/props.ts +1 -3
- package/src/Modal/ModalHeader/styles.ts +7 -3
- package/src/Modal/index.tsx +13 -52
- package/src/Modal/styles.ts +9 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Modal/ModalBody/styles.d.ts.map +1 -1
- package/types/Modal/ModalHeader/index.d.ts +0 -2
- package/types/Modal/ModalHeader/index.d.ts.map +1 -1
- package/types/Modal/ModalHeader/props.d.ts +0 -1
- package/types/Modal/ModalHeader/props.d.ts.map +1 -1
- package/types/Modal/ModalHeader/styles.d.ts.map +1 -1
- package/types/Modal/index.d.ts +3 -5
- package/types/Modal/index.d.ts.map +1 -1
- package/types/Modal/styles.d.ts.map +1 -1
package/src/Modal/index.tsx
CHANGED
|
@@ -22,12 +22,11 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import { Children, Component, isValidElement
|
|
25
|
+
import { Children, Component, isValidElement } from 'react'
|
|
26
26
|
|
|
27
27
|
import { passthroughProps, safeCloneElement } from '@instructure/ui-react-utils'
|
|
28
28
|
import { createChainedFunction } from '@instructure/ui-utils'
|
|
29
29
|
import { testable } from '@instructure/ui-testable'
|
|
30
|
-
import { canUseDOM } from '@instructure/ui-dom-utils'
|
|
31
30
|
|
|
32
31
|
import { Transition } from '@instructure/ui-motion'
|
|
33
32
|
import { Portal } from '@instructure/ui-portal'
|
|
@@ -156,69 +155,31 @@ class Modal extends Component<ModalProps, ModalState> {
|
|
|
156
155
|
}
|
|
157
156
|
}
|
|
158
157
|
|
|
159
|
-
getWindowHeightInRem = (): number => {
|
|
160
|
-
if (!canUseDOM) {
|
|
161
|
-
return Infinity
|
|
162
|
-
}
|
|
163
|
-
const rootFontSize = parseFloat(
|
|
164
|
-
getComputedStyle(document.documentElement)?.fontSize || '16'
|
|
165
|
-
)
|
|
166
|
-
if (isNaN(rootFontSize) || rootFontSize <= 0) {
|
|
167
|
-
return Infinity
|
|
168
|
-
}
|
|
169
|
-
return window.innerHeight / rootFontSize
|
|
170
|
-
}
|
|
171
|
-
|
|
172
158
|
renderChildren() {
|
|
173
|
-
const { children, variant, overflow } = this.props
|
|
174
|
-
|
|
175
|
-
// header should be non-sticky for small viewport height (ca. 320px)
|
|
176
|
-
if (this.getWindowHeightInRem() <= 20) {
|
|
177
|
-
return this.renderForSmallViewportHeight()
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return Children.map(children as ReactElement, (child) => {
|
|
181
|
-
if (!child) return // ignore null, falsy children
|
|
182
|
-
return this.cloneChildWithProps(child, variant, overflow)
|
|
183
|
-
})
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
renderForSmallViewportHeight() {
|
|
187
159
|
const { children, variant, overflow, styles } = this.props
|
|
160
|
+
const childrenArray = Children.toArray(children)
|
|
188
161
|
|
|
189
162
|
const headerAndBody: React.ReactNode[] = []
|
|
163
|
+
const others: React.ReactNode[] = []
|
|
190
164
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
// Separate header and body elements
|
|
194
|
-
const filteredChildren = childrenArray.filter((child) => {
|
|
165
|
+
childrenArray.forEach((child) => {
|
|
195
166
|
if (isValidElement(child)) {
|
|
196
167
|
if (child.type === Modal.Header || child.type === Modal.Body) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
})
|
|
201
|
-
headerAndBody.push(headerWithProp)
|
|
202
|
-
} else {
|
|
203
|
-
headerAndBody.push(child)
|
|
204
|
-
}
|
|
205
|
-
return false
|
|
168
|
+
headerAndBody.push(this.cloneChildWithProps(child, variant, overflow))
|
|
169
|
+
} else {
|
|
170
|
+
others.push(this.cloneChildWithProps(child, variant, overflow))
|
|
206
171
|
}
|
|
207
172
|
}
|
|
208
|
-
return true
|
|
209
173
|
})
|
|
210
174
|
|
|
211
|
-
//
|
|
212
|
-
|
|
213
|
-
|
|
175
|
+
// Putting ModalHeader and ModalBody into the same container, so they can be styled together;
|
|
176
|
+
// this is needed to apply a media query breakpoint
|
|
177
|
+
const wrappedHeaderAndBody =
|
|
178
|
+
headerAndBody.length > 0 ? (
|
|
214
179
|
<div css={styles?.joinedHeaderAndBody}>{headerAndBody}</div>
|
|
215
|
-
)
|
|
216
|
-
}
|
|
180
|
+
) : null
|
|
217
181
|
|
|
218
|
-
return
|
|
219
|
-
if (!child) return // ignore null, falsy children
|
|
220
|
-
return this.cloneChildWithProps(child, variant, overflow)
|
|
221
|
-
})
|
|
182
|
+
return [...(wrappedHeaderAndBody ? [wrappedHeaderAndBody] : []), ...others]
|
|
222
183
|
}
|
|
223
184
|
|
|
224
185
|
cloneChildWithProps(
|
package/src/Modal/styles.ts
CHANGED
|
@@ -111,7 +111,15 @@ const generateStyle = (
|
|
|
111
111
|
},
|
|
112
112
|
joinedHeaderAndBody: {
|
|
113
113
|
borderRadius: componentTheme.borderRadius,
|
|
114
|
-
|
|
114
|
+
display: 'flex',
|
|
115
|
+
flexDirection: 'column',
|
|
116
|
+
overflow: 'hidden',
|
|
117
|
+
|
|
118
|
+
// ModalHeader and ModalBody is set to scrollable above 20rem height instead of just the ModalBody
|
|
119
|
+
'@media (max-height: 20rem)': {
|
|
120
|
+
overflowY: 'auto',
|
|
121
|
+
maxHeight: '20rem'
|
|
122
|
+
}
|
|
115
123
|
}
|
|
116
124
|
}
|
|
117
125
|
}
|