@instructure/ui-modal 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 (184) hide show
  1. package/CHANGELOG.md +49 -311
  2. package/es/Modal/{ModalBody → v1/ModalBody}/index.js +2 -2
  3. package/es/Modal/{ModalFooter → v1/ModalFooter}/index.js +1 -1
  4. package/es/Modal/{ModalHeader → v1/ModalHeader}/index.js +2 -2
  5. package/es/Modal/{index.js → v1/index.js} +2 -2
  6. package/es/Modal/v2/ModalBody/index.js +132 -0
  7. package/es/Modal/v2/ModalBody/props.js +26 -0
  8. package/es/Modal/v2/ModalBody/styles.js +68 -0
  9. package/es/Modal/v2/ModalContext.js +34 -0
  10. package/es/Modal/v2/ModalFooter/index.js +73 -0
  11. package/es/{index.js → Modal/v2/ModalFooter/props.js} +3 -1
  12. package/es/Modal/v2/ModalFooter/styles.js +60 -0
  13. package/es/Modal/v2/ModalHeader/index.js +112 -0
  14. package/es/Modal/v2/ModalHeader/props.js +26 -0
  15. package/es/Modal/v2/ModalHeader/styles.js +76 -0
  16. package/es/Modal/v2/index.js +259 -0
  17. package/es/Modal/v2/props.js +26 -0
  18. package/es/Modal/v2/styles.js +119 -0
  19. package/es/exports/a.js +24 -0
  20. package/es/exports/b.js +24 -0
  21. package/lib/Modal/{ModalBody → v1/ModalBody}/index.js +4 -4
  22. package/lib/Modal/{ModalFooter → v1/ModalFooter}/index.js +1 -1
  23. package/lib/Modal/{ModalHeader → v1/ModalHeader}/index.js +3 -3
  24. package/lib/Modal/v1/index.js +285 -0
  25. package/lib/Modal/v2/ModalBody/index.js +137 -0
  26. package/lib/Modal/v2/ModalBody/props.js +31 -0
  27. package/lib/Modal/v2/ModalBody/styles.js +74 -0
  28. package/lib/Modal/v2/ModalContext.js +39 -0
  29. package/lib/Modal/v2/ModalFooter/index.js +78 -0
  30. package/lib/Modal/v2/ModalFooter/props.js +31 -0
  31. package/lib/Modal/v2/ModalFooter/styles.js +66 -0
  32. package/lib/Modal/v2/ModalHeader/index.js +118 -0
  33. package/lib/Modal/v2/ModalHeader/props.js +31 -0
  34. package/lib/Modal/v2/ModalHeader/styles.js +82 -0
  35. package/lib/Modal/{index.js → v2/index.js} +3 -4
  36. package/lib/Modal/v2/props.js +31 -0
  37. package/lib/Modal/v2/styles.js +125 -0
  38. package/lib/{index.js → exports/a.js} +5 -5
  39. package/lib/exports/b.js +30 -0
  40. package/package.json +46 -24
  41. package/src/Modal/{ModalBody → v1/ModalBody}/index.tsx +2 -2
  42. package/src/Modal/{ModalFooter → v1/ModalFooter}/index.tsx +1 -1
  43. package/src/Modal/{ModalHeader → v1/ModalHeader}/index.tsx +3 -3
  44. package/src/Modal/{index.tsx → v1/index.tsx} +2 -2
  45. package/src/Modal/v2/ModalBody/index.tsx +164 -0
  46. package/src/Modal/v2/ModalBody/props.ts +72 -0
  47. package/src/Modal/v2/ModalBody/styles.ts +76 -0
  48. package/src/Modal/v2/ModalContext.ts +46 -0
  49. package/src/Modal/v2/ModalFooter/index.tsx +80 -0
  50. package/src/Modal/v2/ModalFooter/props.ts +50 -0
  51. package/src/Modal/v2/ModalFooter/styles.ts +74 -0
  52. package/src/Modal/v2/ModalHeader/index.tsx +138 -0
  53. package/src/Modal/v2/ModalHeader/props.ts +54 -0
  54. package/src/Modal/v2/ModalHeader/styles.ts +99 -0
  55. package/src/Modal/v2/README.md +673 -0
  56. package/src/Modal/v2/index.tsx +326 -0
  57. package/src/Modal/v2/props.ts +235 -0
  58. package/src/Modal/v2/styles.ts +130 -0
  59. package/src/{index.ts → exports/a.ts} +5 -5
  60. package/src/exports/b.ts +29 -0
  61. package/tsconfig.build.tsbuildinfo +1 -1
  62. package/types/Modal/v1/ModalBody/index.d.ts.map +1 -0
  63. package/types/Modal/v1/ModalBody/props.d.ts.map +1 -0
  64. package/types/Modal/v1/ModalBody/styles.d.ts.map +1 -0
  65. package/types/Modal/v1/ModalBody/theme.d.ts.map +1 -0
  66. package/types/Modal/v1/ModalContext.d.ts.map +1 -0
  67. package/types/Modal/v1/ModalFooter/index.d.ts.map +1 -0
  68. package/types/Modal/v1/ModalFooter/props.d.ts.map +1 -0
  69. package/types/Modal/v1/ModalFooter/styles.d.ts.map +1 -0
  70. package/types/Modal/v1/ModalFooter/theme.d.ts.map +1 -0
  71. package/types/Modal/v1/ModalHeader/index.d.ts.map +1 -0
  72. package/types/Modal/v1/ModalHeader/props.d.ts.map +1 -0
  73. package/types/Modal/v1/ModalHeader/styles.d.ts.map +1 -0
  74. package/types/Modal/v1/ModalHeader/theme.d.ts.map +1 -0
  75. package/types/Modal/v1/index.d.ts.map +1 -0
  76. package/types/Modal/v1/props.d.ts.map +1 -0
  77. package/types/Modal/v1/styles.d.ts.map +1 -0
  78. package/types/Modal/v1/theme.d.ts.map +1 -0
  79. package/types/Modal/v2/ModalBody/index.d.ts +36 -0
  80. package/types/Modal/v2/ModalBody/index.d.ts.map +1 -0
  81. package/types/Modal/v2/ModalBody/props.d.ts +23 -0
  82. package/types/Modal/v2/ModalBody/props.d.ts.map +1 -0
  83. package/types/Modal/v2/ModalBody/styles.d.ts +16 -0
  84. package/types/Modal/v2/ModalBody/styles.d.ts.map +1 -0
  85. package/types/Modal/v2/ModalContext.d.ts +17 -0
  86. package/types/Modal/v2/ModalContext.d.ts.map +1 -0
  87. package/types/Modal/v2/ModalFooter/index.d.ts +27 -0
  88. package/types/Modal/v2/ModalFooter/index.d.ts.map +1 -0
  89. package/types/Modal/v2/ModalFooter/props.d.ts +16 -0
  90. package/types/Modal/v2/ModalFooter/props.d.ts.map +1 -0
  91. package/types/Modal/v2/ModalFooter/styles.d.ts +16 -0
  92. package/types/Modal/v2/ModalFooter/styles.d.ts.map +1 -0
  93. package/types/Modal/v2/ModalHeader/index.d.ts +37 -0
  94. package/types/Modal/v2/ModalHeader/index.d.ts.map +1 -0
  95. package/types/Modal/v2/ModalHeader/props.d.ts +19 -0
  96. package/types/Modal/v2/ModalHeader/props.d.ts.map +1 -0
  97. package/types/Modal/v2/ModalHeader/styles.d.ts +16 -0
  98. package/types/Modal/v2/ModalHeader/styles.d.ts.map +1 -0
  99. package/types/Modal/v2/index.d.ts +54 -0
  100. package/types/Modal/v2/index.d.ts.map +1 -0
  101. package/types/Modal/v2/props.d.ts +132 -0
  102. package/types/Modal/v2/props.d.ts.map +1 -0
  103. package/types/Modal/v2/styles.d.ts +16 -0
  104. package/types/Modal/v2/styles.d.ts.map +1 -0
  105. package/types/exports/a.d.ts +6 -0
  106. package/types/exports/a.d.ts.map +1 -0
  107. package/types/exports/b.d.ts +6 -0
  108. package/types/exports/b.d.ts.map +1 -0
  109. package/types/Modal/ModalBody/index.d.ts.map +0 -1
  110. package/types/Modal/ModalBody/props.d.ts.map +0 -1
  111. package/types/Modal/ModalBody/styles.d.ts.map +0 -1
  112. package/types/Modal/ModalBody/theme.d.ts.map +0 -1
  113. package/types/Modal/ModalContext.d.ts.map +0 -1
  114. package/types/Modal/ModalFooter/index.d.ts.map +0 -1
  115. package/types/Modal/ModalFooter/props.d.ts.map +0 -1
  116. package/types/Modal/ModalFooter/styles.d.ts.map +0 -1
  117. package/types/Modal/ModalFooter/theme.d.ts.map +0 -1
  118. package/types/Modal/ModalHeader/index.d.ts.map +0 -1
  119. package/types/Modal/ModalHeader/props.d.ts.map +0 -1
  120. package/types/Modal/ModalHeader/styles.d.ts.map +0 -1
  121. package/types/Modal/ModalHeader/theme.d.ts.map +0 -1
  122. package/types/Modal/index.d.ts.map +0 -1
  123. package/types/Modal/props.d.ts.map +0 -1
  124. package/types/Modal/styles.d.ts.map +0 -1
  125. package/types/Modal/theme.d.ts.map +0 -1
  126. package/types/index.d.ts +0 -6
  127. package/types/index.d.ts.map +0 -1
  128. /package/es/Modal/{ModalBody → v1/ModalBody}/props.js +0 -0
  129. /package/es/Modal/{ModalBody → v1/ModalBody}/styles.js +0 -0
  130. /package/es/Modal/{ModalBody → v1/ModalBody}/theme.js +0 -0
  131. /package/es/Modal/{ModalContext.js → v1/ModalContext.js} +0 -0
  132. /package/es/Modal/{ModalFooter → v1/ModalFooter}/props.js +0 -0
  133. /package/es/Modal/{ModalFooter → v1/ModalFooter}/styles.js +0 -0
  134. /package/es/Modal/{ModalFooter → v1/ModalFooter}/theme.js +0 -0
  135. /package/es/Modal/{ModalHeader → v1/ModalHeader}/props.js +0 -0
  136. /package/es/Modal/{ModalHeader → v1/ModalHeader}/styles.js +0 -0
  137. /package/es/Modal/{ModalHeader → v1/ModalHeader}/theme.js +0 -0
  138. /package/es/Modal/{props.js → v1/props.js} +0 -0
  139. /package/es/Modal/{styles.js → v1/styles.js} +0 -0
  140. /package/es/Modal/{theme.js → v1/theme.js} +0 -0
  141. /package/lib/Modal/{ModalBody → v1/ModalBody}/props.js +0 -0
  142. /package/lib/Modal/{ModalBody → v1/ModalBody}/styles.js +0 -0
  143. /package/lib/Modal/{ModalBody → v1/ModalBody}/theme.js +0 -0
  144. /package/lib/Modal/{ModalContext.js → v1/ModalContext.js} +0 -0
  145. /package/lib/Modal/{ModalFooter → v1/ModalFooter}/props.js +0 -0
  146. /package/lib/Modal/{ModalFooter → v1/ModalFooter}/styles.js +0 -0
  147. /package/lib/Modal/{ModalFooter → v1/ModalFooter}/theme.js +0 -0
  148. /package/lib/Modal/{ModalHeader → v1/ModalHeader}/props.js +0 -0
  149. /package/lib/Modal/{ModalHeader → v1/ModalHeader}/styles.js +0 -0
  150. /package/lib/Modal/{ModalHeader → v1/ModalHeader}/theme.js +0 -0
  151. /package/lib/Modal/{props.js → v1/props.js} +0 -0
  152. /package/lib/Modal/{styles.js → v1/styles.js} +0 -0
  153. /package/lib/Modal/{theme.js → v1/theme.js} +0 -0
  154. /package/src/Modal/{ModalBody → v1/ModalBody}/props.ts +0 -0
  155. /package/src/Modal/{ModalBody → v1/ModalBody}/styles.ts +0 -0
  156. /package/src/Modal/{ModalBody → v1/ModalBody}/theme.ts +0 -0
  157. /package/src/Modal/{ModalContext.ts → v1/ModalContext.ts} +0 -0
  158. /package/src/Modal/{ModalFooter → v1/ModalFooter}/props.ts +0 -0
  159. /package/src/Modal/{ModalFooter → v1/ModalFooter}/styles.ts +0 -0
  160. /package/src/Modal/{ModalFooter → v1/ModalFooter}/theme.ts +0 -0
  161. /package/src/Modal/{ModalHeader → v1/ModalHeader}/props.ts +0 -0
  162. /package/src/Modal/{ModalHeader → v1/ModalHeader}/styles.ts +0 -0
  163. /package/src/Modal/{ModalHeader → v1/ModalHeader}/theme.ts +0 -0
  164. /package/src/Modal/{README.md → v1/README.md} +0 -0
  165. /package/src/Modal/{props.ts → v1/props.ts} +0 -0
  166. /package/src/Modal/{styles.ts → v1/styles.ts} +0 -0
  167. /package/src/Modal/{theme.ts → v1/theme.ts} +0 -0
  168. /package/types/Modal/{ModalBody → v1/ModalBody}/index.d.ts +0 -0
  169. /package/types/Modal/{ModalBody → v1/ModalBody}/props.d.ts +0 -0
  170. /package/types/Modal/{ModalBody → v1/ModalBody}/styles.d.ts +0 -0
  171. /package/types/Modal/{ModalBody → v1/ModalBody}/theme.d.ts +0 -0
  172. /package/types/Modal/{ModalContext.d.ts → v1/ModalContext.d.ts} +0 -0
  173. /package/types/Modal/{ModalFooter → v1/ModalFooter}/index.d.ts +0 -0
  174. /package/types/Modal/{ModalFooter → v1/ModalFooter}/props.d.ts +0 -0
  175. /package/types/Modal/{ModalFooter → v1/ModalFooter}/styles.d.ts +0 -0
  176. /package/types/Modal/{ModalFooter → v1/ModalFooter}/theme.d.ts +0 -0
  177. /package/types/Modal/{ModalHeader → v1/ModalHeader}/index.d.ts +0 -0
  178. /package/types/Modal/{ModalHeader → v1/ModalHeader}/props.d.ts +0 -0
  179. /package/types/Modal/{ModalHeader → v1/ModalHeader}/styles.d.ts +0 -0
  180. /package/types/Modal/{ModalHeader → v1/ModalHeader}/theme.d.ts +0 -0
  181. /package/types/Modal/{index.d.ts → v1/index.d.ts} +0 -0
  182. /package/types/Modal/{props.d.ts → v1/props.d.ts} +0 -0
  183. /package/types/Modal/{styles.d.ts → v1/styles.d.ts} +0 -0
  184. /package/types/Modal/{theme.d.ts → v1/theme.d.ts} +0 -0
@@ -0,0 +1,138 @@
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 { ComponentElement, Children, Component } from 'react'
26
+
27
+ import {
28
+ matchComponentTypes,
29
+ passthroughProps
30
+ } from '@instructure/ui-react-utils'
31
+
32
+ import { withStyle } from '@instructure/emotion'
33
+
34
+ import { CloseButton } from '@instructure/ui-buttons/latest'
35
+ import type { CloseButtonProps } from '@instructure/ui-buttons/latest'
36
+
37
+ import generateStyle from './styles'
38
+
39
+ import { allowedProps } from './props'
40
+ import type { ModalHeaderProps, ModalHeaderStyleProps } from './props'
41
+ import ModalContext from '../ModalContext'
42
+
43
+ type CloseButtonChild = ComponentElement<CloseButtonProps, CloseButton>
44
+
45
+ /**
46
+ ---
47
+ parent: Modal
48
+ id: Modal.Header
49
+ ---
50
+ **/
51
+ @withStyle(generateStyle, 'ModalHeader')
52
+ class ModalHeader extends Component<ModalHeaderProps> {
53
+ static readonly componentId = 'Modal.Header'
54
+
55
+ static allowedProps = allowedProps
56
+ static defaultProps = {
57
+ variant: 'default',
58
+ spacing: 'default'
59
+ }
60
+
61
+ ref: HTMLDivElement | null = null
62
+ declare context: React.ContextType<typeof ModalContext>
63
+ static contextType = ModalContext
64
+
65
+ /**
66
+ * Gets all text in a DOM subtree, text under <button> nodes is excluded
67
+ */
68
+ getTextExcludingButtons = (root: Node) => {
69
+ const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, {
70
+ acceptNode(node) {
71
+ return node.parentElement?.closest('button')
72
+ ? NodeFilter.FILTER_REJECT
73
+ : NodeFilter.FILTER_ACCEPT
74
+ }
75
+ })
76
+ let text = ''
77
+ let current
78
+ while ((current = walker.nextNode())) {
79
+ text += current.nodeValue
80
+ }
81
+ return text
82
+ }
83
+
84
+ handleRef = (el: HTMLDivElement | null) => {
85
+ this.ref = el
86
+ if (el) {
87
+ const txt = this.getTextExcludingButtons(el)
88
+ this.context.setBodyScrollAriaLabel?.(txt)
89
+ }
90
+ }
91
+
92
+ componentDidMount() {
93
+ this.props.makeStyles?.(this.makeStyleProps())
94
+ }
95
+
96
+ componentDidUpdate() {
97
+ this.props.makeStyles?.(this.makeStyleProps())
98
+ }
99
+
100
+ makeStyleProps = (): ModalHeaderStyleProps => {
101
+ return {
102
+ withCloseButton: this.usesCloseButton
103
+ }
104
+ }
105
+
106
+ get usesCloseButton() {
107
+ let hasCloseButton = false
108
+
109
+ Children.forEach(this.props.children, (child) => {
110
+ if (
111
+ child &&
112
+ matchComponentTypes<CloseButtonChild>(child, [CloseButton])
113
+ ) {
114
+ hasCloseButton = true
115
+ }
116
+ })
117
+
118
+ return hasCloseButton
119
+ }
120
+
121
+ render() {
122
+ const { children, ...rest } = this.props
123
+
124
+ return (
125
+ <div
126
+ css={this.props.styles?.modalHeader}
127
+ {...passthroughProps(rest)}
128
+ ref={this.handleRef}
129
+ data-cid="ModalHeader"
130
+ >
131
+ {children}
132
+ </div>
133
+ )
134
+ }
135
+ }
136
+
137
+ export default ModalHeader
138
+ export { ModalHeader }
@@ -0,0 +1,54 @@
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 {
27
+ ModalHeaderTheme,
28
+ OtherHTMLAttributes
29
+ } from '@instructure/shared-types'
30
+ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
31
+
32
+ type ModalHeaderOwnProps = {
33
+ children?: React.ReactNode
34
+ variant?: 'default' | 'inverse'
35
+ spacing?: 'default' | 'compact'
36
+ }
37
+
38
+ type ModalHeaderStyleProps = {
39
+ withCloseButton: boolean
40
+ }
41
+
42
+ type PropKeys = keyof ModalHeaderOwnProps
43
+
44
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
45
+
46
+ type ModalHeaderProps = ModalHeaderOwnProps &
47
+ WithStyleProps<ModalHeaderTheme, ModalHeaderStyle> &
48
+ OtherHTMLAttributes<ModalHeaderOwnProps>
49
+
50
+ type ModalHeaderStyle = ComponentStyle<'modalHeader'>
51
+ const allowedProps: AllowedPropKeys = ['children', 'variant', 'spacing']
52
+
53
+ export type { ModalHeaderProps, ModalHeaderStyleProps, ModalHeaderStyle }
54
+ export { allowedProps }
@@ -0,0 +1,99 @@
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
+ ModalHeaderProps,
28
+ ModalHeaderStyleProps,
29
+ ModalHeaderStyle
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 theme token object (unused)
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['ModalHeader'],
45
+ props: ModalHeaderProps,
46
+ _sharedTokens: SharedTokens,
47
+ state: ModalHeaderStyleProps
48
+ ): ModalHeaderStyle => {
49
+ const { variant, spacing } = props
50
+ const { withCloseButton } = state
51
+
52
+ const sizeVariants = {
53
+ default: {
54
+ padding: componentTheme.padding,
55
+ paddingInlineStart: componentTheme.padding,
56
+ paddingInlineEnd: withCloseButton
57
+ ? `calc(${componentTheme.padding} * 2 + 1em)`
58
+ : componentTheme.padding
59
+ },
60
+ compact: {
61
+ padding: componentTheme.paddingCompact,
62
+ paddingInlineStart: componentTheme.paddingCompact,
63
+ paddingInlineEnd: withCloseButton
64
+ ? `calc(${componentTheme.paddingCompact} * 2 + 1em)`
65
+ : componentTheme.paddingCompact
66
+ }
67
+ }
68
+
69
+ const inverseStyle =
70
+ variant === 'inverse'
71
+ ? {
72
+ background: componentTheme.inverseBackgroundColor,
73
+ borderBottomColor: componentTheme.inverseBorderColor
74
+ }
75
+ : {}
76
+
77
+ return {
78
+ modalHeader: {
79
+ borderTopLeftRadius: 'inherit',
80
+ borderTopRightRadius: 'inherit',
81
+ label: 'modalHeader',
82
+ boxSizing: 'border-box',
83
+ flex: '0 0 auto',
84
+ background: componentTheme.backgroundColor,
85
+ borderBottomWidth: componentTheme.borderWidth,
86
+ borderBottomStyle: 'solid',
87
+ borderBottomColor: componentTheme.borderColor,
88
+ ...sizeVariants[spacing!],
89
+ ...inverseStyle,
90
+
91
+ // Position is set to relative for small viewports to ensure proper close button positioning during scrolling
92
+ '@media (max-height: 20rem)': {
93
+ position: 'relative'
94
+ }
95
+ }
96
+ }
97
+ }
98
+
99
+ export default generateStyle