@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.
@@ -22,12 +22,11 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- import { Children, Component, isValidElement, ReactElement } from 'react'
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
- const childrenArray = Children.toArray(children)
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
- if (child.type === Modal.Header) {
198
- const headerWithProp = safeCloneElement(child, {
199
- smallViewPort: true
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
- // Adds the <div> to the beginning of the filteredChildren array
212
- if (headerAndBody.length > 0) {
213
- filteredChildren.unshift(
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 Children.map(filteredChildren as ReactElement[], (child) => {
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(
@@ -111,7 +111,15 @@ const generateStyle = (
111
111
  },
112
112
  joinedHeaderAndBody: {
113
113
  borderRadius: componentTheme.borderRadius,
114
- overflowY: 'scroll'
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
  }