@instructure/ui-grid 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 (140) hide show
  1. package/CHANGELOG.md +27 -276
  2. package/es/Grid/{index.js → v1/index.js} +3 -3
  3. package/es/Grid/v2/index.js +98 -0
  4. package/es/Grid/v2/props.js +26 -0
  5. package/es/Grid/v2/styles.js +61 -0
  6. package/es/GridCol/{index.js → v1/index.js} +1 -1
  7. package/es/GridCol/v2/index.js +100 -0
  8. package/es/GridCol/v2/props.js +26 -0
  9. package/es/GridCol/v2/styles.js +211 -0
  10. package/es/GridRow/{index.js → v1/index.js} +2 -2
  11. package/es/GridRow/v2/index.js +93 -0
  12. package/es/GridRow/v2/props.js +26 -0
  13. package/es/GridRow/v2/styles.js +137 -0
  14. package/es/{index.js → exports/a.js} +1 -1
  15. package/es/exports/b.js +24 -0
  16. package/lib/Grid/v1/index.js +120 -0
  17. package/lib/Grid/{index.js → v2/index.js} +7 -8
  18. package/lib/Grid/v2/props.js +31 -0
  19. package/lib/Grid/v2/styles.js +67 -0
  20. package/lib/GridCol/v1/index.js +106 -0
  21. package/lib/GridCol/{index.js → v2/index.js} +1 -2
  22. package/lib/GridCol/v2/props.js +31 -0
  23. package/lib/GridCol/v2/styles.js +217 -0
  24. package/lib/GridRow/v1/index.js +102 -0
  25. package/lib/GridRow/{index.js → v2/index.js} +3 -4
  26. package/{src/index.ts → lib/GridRow/v2/props.js} +7 -6
  27. package/lib/GridRow/v2/styles.js +143 -0
  28. package/lib/{index.js → exports/a.js} +4 -4
  29. package/lib/exports/b.js +24 -0
  30. package/package.json +39 -17
  31. package/src/Grid/{index.tsx → v1/index.tsx} +4 -4
  32. package/src/Grid/{props.ts → v1/props.ts} +1 -1
  33. package/src/Grid/{styles.ts → v1/styles.ts} +1 -1
  34. package/src/Grid/v2/README.md +239 -0
  35. package/src/Grid/v2/index.tsx +117 -0
  36. package/src/Grid/v2/props.ts +62 -0
  37. package/src/Grid/v2/styles.ts +70 -0
  38. package/src/GridCol/{index.tsx → v1/index.tsx} +1 -1
  39. package/src/GridCol/{props.ts → v1/props.ts} +1 -1
  40. package/src/GridCol/{styles.ts → v1/styles.ts} +1 -1
  41. package/src/GridCol/v2/index.tsx +113 -0
  42. package/src/GridCol/v2/props.ts +90 -0
  43. package/src/GridCol/v2/styles.ts +221 -0
  44. package/src/GridRow/{index.tsx → v1/index.tsx} +3 -3
  45. package/src/GridRow/{props.ts → v1/props.ts} +1 -1
  46. package/src/GridRow/{styles.ts → v1/styles.ts} +1 -1
  47. package/src/GridRow/v2/index.tsx +109 -0
  48. package/src/GridRow/v2/props.ts +66 -0
  49. package/src/GridRow/v2/styles.ts +120 -0
  50. package/src/exports/a.ts +30 -0
  51. package/src/exports/b.ts +30 -0
  52. package/tsconfig.build.tsbuildinfo +1 -1
  53. package/types/Grid/{index.d.ts → v1/index.d.ts} +4 -4
  54. package/types/Grid/v1/index.d.ts.map +1 -0
  55. package/types/Grid/{props.d.ts → v1/props.d.ts} +1 -1
  56. package/types/Grid/v1/props.d.ts.map +1 -0
  57. package/types/Grid/v1/styles.d.ts.map +1 -0
  58. package/types/Grid/v1/theme.d.ts.map +1 -0
  59. package/types/Grid/v2/index.d.ts +42 -0
  60. package/types/Grid/v2/index.d.ts.map +1 -0
  61. package/types/Grid/v2/props.d.ts +23 -0
  62. package/types/Grid/v2/props.d.ts.map +1 -0
  63. package/types/Grid/v2/styles.d.ts +15 -0
  64. package/types/Grid/v2/styles.d.ts.map +1 -0
  65. package/types/GridCol/{index.d.ts → v1/index.d.ts} +1 -1
  66. package/types/GridCol/v1/index.d.ts.map +1 -0
  67. package/types/GridCol/{props.d.ts → v1/props.d.ts} +1 -1
  68. package/types/GridCol/v1/props.d.ts.map +1 -0
  69. package/types/GridCol/v1/styles.d.ts.map +1 -0
  70. package/types/GridCol/v1/theme.d.ts.map +1 -0
  71. package/types/GridCol/v2/index.d.ts +51 -0
  72. package/types/GridCol/v2/index.d.ts.map +1 -0
  73. package/types/GridCol/v2/props.d.ts +40 -0
  74. package/types/GridCol/v2/props.d.ts.map +1 -0
  75. package/types/GridCol/v2/styles.d.ts +15 -0
  76. package/types/GridCol/v2/styles.d.ts.map +1 -0
  77. package/types/GridRow/{index.d.ts → v1/index.d.ts} +3 -3
  78. package/types/GridRow/v1/index.d.ts.map +1 -0
  79. package/types/GridRow/{props.d.ts → v1/props.d.ts} +1 -1
  80. package/types/GridRow/v1/props.d.ts.map +1 -0
  81. package/types/GridRow/v1/styles.d.ts.map +1 -0
  82. package/types/GridRow/v1/theme.d.ts.map +1 -0
  83. package/types/GridRow/v2/index.d.ts +36 -0
  84. package/types/GridRow/v2/index.d.ts.map +1 -0
  85. package/types/GridRow/v2/props.d.ts +25 -0
  86. package/types/GridRow/v2/props.d.ts.map +1 -0
  87. package/types/GridRow/v2/styles.d.ts +15 -0
  88. package/types/GridRow/v2/styles.d.ts.map +1 -0
  89. package/types/exports/a.d.ts +6 -0
  90. package/types/exports/a.d.ts.map +1 -0
  91. package/types/exports/b.d.ts +6 -0
  92. package/types/exports/b.d.ts.map +1 -0
  93. package/types/utils/v1/GridTypes.d.ts.map +1 -0
  94. package/types/Grid/index.d.ts.map +0 -1
  95. package/types/Grid/props.d.ts.map +0 -1
  96. package/types/Grid/styles.d.ts.map +0 -1
  97. package/types/Grid/theme.d.ts.map +0 -1
  98. package/types/GridCol/index.d.ts.map +0 -1
  99. package/types/GridCol/props.d.ts.map +0 -1
  100. package/types/GridCol/styles.d.ts.map +0 -1
  101. package/types/GridCol/theme.d.ts.map +0 -1
  102. package/types/GridRow/index.d.ts.map +0 -1
  103. package/types/GridRow/props.d.ts.map +0 -1
  104. package/types/GridRow/styles.d.ts.map +0 -1
  105. package/types/GridRow/theme.d.ts.map +0 -1
  106. package/types/GridTypes.d.ts.map +0 -1
  107. package/types/index.d.ts +0 -6
  108. package/types/index.d.ts.map +0 -1
  109. /package/es/Grid/{props.js → v1/props.js} +0 -0
  110. /package/es/Grid/{styles.js → v1/styles.js} +0 -0
  111. /package/es/Grid/{theme.js → v1/theme.js} +0 -0
  112. /package/es/GridCol/{props.js → v1/props.js} +0 -0
  113. /package/es/GridCol/{styles.js → v1/styles.js} +0 -0
  114. /package/es/GridCol/{theme.js → v1/theme.js} +0 -0
  115. /package/es/GridRow/{props.js → v1/props.js} +0 -0
  116. /package/es/GridRow/{styles.js → v1/styles.js} +0 -0
  117. /package/es/GridRow/{theme.js → v1/theme.js} +0 -0
  118. /package/es/{GridTypes.js → utils/v1/GridTypes.js} +0 -0
  119. /package/lib/Grid/{props.js → v1/props.js} +0 -0
  120. /package/lib/Grid/{styles.js → v1/styles.js} +0 -0
  121. /package/lib/Grid/{theme.js → v1/theme.js} +0 -0
  122. /package/lib/GridCol/{props.js → v1/props.js} +0 -0
  123. /package/lib/GridCol/{styles.js → v1/styles.js} +0 -0
  124. /package/lib/GridCol/{theme.js → v1/theme.js} +0 -0
  125. /package/lib/GridRow/{props.js → v1/props.js} +0 -0
  126. /package/lib/GridRow/{styles.js → v1/styles.js} +0 -0
  127. /package/lib/GridRow/{theme.js → v1/theme.js} +0 -0
  128. /package/lib/{GridTypes.js → utils/v1/GridTypes.js} +0 -0
  129. /package/src/Grid/{README.md → v1/README.md} +0 -0
  130. /package/src/Grid/{theme.ts → v1/theme.ts} +0 -0
  131. /package/src/GridCol/{theme.ts → v1/theme.ts} +0 -0
  132. /package/src/GridRow/{theme.ts → v1/theme.ts} +0 -0
  133. /package/src/{GridTypes.ts → utils/v1/GridTypes.ts} +0 -0
  134. /package/types/Grid/{styles.d.ts → v1/styles.d.ts} +0 -0
  135. /package/types/Grid/{theme.d.ts → v1/theme.d.ts} +0 -0
  136. /package/types/GridCol/{styles.d.ts → v1/styles.d.ts} +0 -0
  137. /package/types/GridCol/{theme.d.ts → v1/theme.d.ts} +0 -0
  138. /package/types/GridRow/{styles.d.ts → v1/styles.d.ts} +0 -0
  139. /package/types/GridRow/{theme.d.ts → v1/theme.d.ts} +0 -0
  140. /package/types/{GridTypes.d.ts → utils/v1/GridTypes.d.ts} +0 -0
@@ -0,0 +1,90 @@
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 { WithStyleProps, ComponentStyle } from '@instructure/emotion'
26
+ import type { GridTheme, OtherHTMLAttributes } from '@instructure/shared-types'
27
+ import type { GridBreakpoints } from '../../utils/v1/GridTypes'
28
+
29
+ type ColWidths = 'auto' | number
30
+
31
+ type GridColOwnProps = {
32
+ children?: React.ReactNode
33
+ colSpacing?: 'none' | 'small' | 'medium' | 'large'
34
+ rowSpacing?: 'none' | 'small' | 'medium' | 'large'
35
+ textAlign?: 'start' | 'end' | 'center' | 'inherit'
36
+ hAlign?: 'start' | 'center' | 'end' | 'space-around' | 'space-between'
37
+ vAlign?: 'top' | 'middle' | 'bottom' | 'stretch'
38
+ startAt?: GridBreakpoints
39
+ visualDebug?: boolean
40
+ width?:
41
+ | ColWidths
42
+ | {
43
+ small?: ColWidths
44
+ medium?: ColWidths
45
+ large?: ColWidths
46
+ xLarge?: ColWidths
47
+ }
48
+ offset?:
49
+ | ColWidths
50
+ | {
51
+ small?: ColWidths
52
+ medium?: ColWidths
53
+ large?: ColWidths
54
+ xLarge?: ColWidths
55
+ }
56
+ isLastRow?: boolean
57
+ isLastCol?: boolean
58
+ /**
59
+ * provides a reference to the underlying html root element
60
+ */
61
+ elementRef?: (element: HTMLSpanElement | null) => void
62
+ }
63
+
64
+ type PropKeys = keyof GridColOwnProps
65
+
66
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
67
+
68
+ type GridColProps = GridColOwnProps &
69
+ WithStyleProps<GridTheme, GridColStyle> &
70
+ OtherHTMLAttributes<GridColOwnProps>
71
+
72
+ type GridColStyle = ComponentStyle<'gridCol'>
73
+ const allowedProps: AllowedPropKeys = [
74
+ 'children',
75
+ 'colSpacing',
76
+ 'rowSpacing',
77
+ 'textAlign',
78
+ 'hAlign',
79
+ 'vAlign',
80
+ 'startAt',
81
+ 'visualDebug',
82
+ 'width',
83
+ 'offset',
84
+ 'isLastRow',
85
+ 'isLastCol',
86
+ 'elementRef'
87
+ ]
88
+
89
+ export type { GridColProps, GridColStyle }
90
+ export { allowedProps }
@@ -0,0 +1,221 @@
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 } from '@instructure/ui-themes'
26
+ import type { GridBreakpoints } from '../../utils/v1/GridTypes'
27
+ import type { GridColProps, GridColStyle } from './props'
28
+
29
+ type BreakPoints = NonNullable<GridBreakpoints>
30
+
31
+ /**
32
+ * ---
33
+ * private: true
34
+ * ---
35
+ * Generates the style object from the theme and provided additional information
36
+ * @param {Object} componentTheme The theme variable object.
37
+ * @param {Object} props the props of the component, the style is applied to
38
+ * @param {Object} state the state of the component, the style is applied to
39
+ * @return {Object} The final style object, which will be used in the component
40
+ */
41
+ const generateStyle = (
42
+ componentTheme: NewComponentTypes['GridCol'],
43
+ props: GridColProps
44
+ ): GridColStyle => {
45
+ const {
46
+ vAlign,
47
+ textAlign,
48
+ rowSpacing,
49
+ colSpacing,
50
+ isLastRow,
51
+ isLastCol,
52
+ startAt,
53
+ visualDebug
54
+ } = props
55
+
56
+ const rowSpacingVariants = {
57
+ small: { marginBottom: componentTheme.spacingSmall },
58
+ medium: { marginBottom: componentTheme.spacingMedium },
59
+ large: { marginBottom: componentTheme.spacingLarge },
60
+ none: { marginBottom: 0 }
61
+ }
62
+
63
+ const getStartGridColumnStyle = () => {
64
+ const colSpacingVariants = {
65
+ small: {
66
+ paddingLeft: `calc(${componentTheme.spacingSmall} / 2)`,
67
+ paddingRight: `calc(${componentTheme.spacingSmall} / 2)`
68
+ },
69
+ medium: {
70
+ paddingLeft: `calc(${componentTheme.spacingMedium} / 2)`,
71
+ paddingRight: `calc(${componentTheme.spacingMedium} / 2)`
72
+ },
73
+ large: {
74
+ paddingLeft: `calc(${componentTheme.spacingLarge} / 2)`,
75
+ paddingRight: `calc(${componentTheme.spacingLarge} / 2)`
76
+ },
77
+ none: {}
78
+ }
79
+
80
+ const vAlignVariants = {
81
+ top: { alignSelf: 'flex-start' },
82
+ middle: { alignSelf: 'center' },
83
+ bottom: { alignSelf: 'flex-end' },
84
+ stretch: { alignSelf: 'stretch' }
85
+ }
86
+
87
+ const textAlignVariants = {
88
+ start: { textAlign: 'start' },
89
+ end: { textAlign: 'end' },
90
+ center: { textAlign: 'center' },
91
+ inherit: { textAlign: 'inherit' }
92
+ }
93
+
94
+ return {
95
+ flexGrow: 1,
96
+ flexShrink: 1,
97
+ flexBasis: '0%',
98
+ marginBottom: 0,
99
+ boxSizing: 'border-box',
100
+ ...(colSpacing && colSpacingVariants[colSpacing]),
101
+ ...(vAlign && vAlignVariants[vAlign]),
102
+ ...(textAlign && textAlignVariants[textAlign])
103
+ }
104
+ }
105
+
106
+ const enabledBreakpoints = () => {
107
+ const breakpoints: GridBreakpoints[] = [
108
+ 'small',
109
+ 'medium',
110
+ 'large',
111
+ 'x-large',
112
+ null
113
+ ]
114
+ return breakpoints.slice(breakpoints.indexOf(startAt!))
115
+ }
116
+
117
+ const breakpointIsEnabled = (breakpoint: BreakPoints) => {
118
+ return enabledBreakpoints().includes(breakpoint)
119
+ }
120
+
121
+ const getColSize = (breakpoint: BreakPoints) => {
122
+ let { width } = props
123
+
124
+ if (!width) return
125
+
126
+ if (width && typeof width === 'object') {
127
+ width = width[breakpoint === 'x-large' ? 'xLarge' : breakpoint]
128
+ }
129
+
130
+ return width
131
+ }
132
+
133
+ const getColOffset = (breakpoint: BreakPoints) => {
134
+ let { offset } = props
135
+
136
+ if (!offset) return
137
+
138
+ if (offset && typeof offset === 'object') {
139
+ offset = offset[breakpoint === 'x-large' ? 'xLarge' : breakpoint]
140
+ }
141
+
142
+ return offset
143
+ }
144
+
145
+ const getFlexColumnBySize = (size: string | number = '1') => {
146
+ switch (size) {
147
+ case 'auto':
148
+ return { flexGrow: 0, flexShrink: 0, flexBasis: 'auto' }
149
+ case 12:
150
+ return { flex: '0 0 100%' }
151
+ default:
152
+ return {
153
+ flexGrow: 0,
154
+ flexShrink: 0,
155
+ flexBasis: `calc(${size} / 12 * 99.999%)`,
156
+ maxWidth: `calc(${size} / 12 * 99.999%)`
157
+ }
158
+ }
159
+ }
160
+
161
+ const getColumnOffsetBySize = (size: string | number = '1') => {
162
+ switch (size) {
163
+ case 'auto':
164
+ case 12:
165
+ return {}
166
+ default:
167
+ return {
168
+ marginInlineStart: `calc(${size} / 12 * 99.999%)`,
169
+ marginInlineEnd: 0
170
+ }
171
+ }
172
+ }
173
+
174
+ const getStartAtVariants = (breakpoint: BreakPoints) =>
175
+ !!startAt && startAt === breakpoint ? { ...getStartGridColumnStyle() } : {}
176
+
177
+ const getGridColumnsForBreakpoint = (breakpoint: BreakPoints) => {
178
+ const size = getColSize(breakpoint)
179
+ const offset = getColOffset(breakpoint)
180
+
181
+ return breakpointIsEnabled(breakpoint)
182
+ ? {
183
+ ...(size && getFlexColumnBySize(size)),
184
+ ...(offset && getColumnOffsetBySize(offset))
185
+ }
186
+ : {}
187
+ }
188
+
189
+ const getBreakpointStyles = (breakpoint: BreakPoints) => ({
190
+ ...getStartAtVariants(breakpoint),
191
+ ...getGridColumnsForBreakpoint(breakpoint)
192
+ })
193
+
194
+ return {
195
+ gridCol: {
196
+ label: 'gridCol',
197
+ display: 'block',
198
+ boxSizing: 'border-box',
199
+ textAlign: 'inherit',
200
+ minWidth: '0.0625rem',
201
+ ...(rowSpacing && rowSpacingVariants[rowSpacing]),
202
+ ...(isLastRow && isLastCol && { marginBottom: 0 }),
203
+
204
+ ...getBreakpointStyles('small'),
205
+
206
+ [`@media screen and (min-width: ${componentTheme.mediumMin})`]: {
207
+ ...getBreakpointStyles('medium')
208
+ },
209
+ [`@media screen and (min-width: ${componentTheme.largeMin})`]: {
210
+ ...getBreakpointStyles('large')
211
+ },
212
+ [`@media screen and (min-width: ${componentTheme.xLargeMin})`]: {
213
+ ...getBreakpointStyles('x-large')
214
+ },
215
+
216
+ ...(visualDebug && { outline: '0.0625rem dashed red' })
217
+ }
218
+ }
219
+ }
220
+
221
+ export default generateStyle
@@ -31,10 +31,10 @@ import {
31
31
  pickProps
32
32
  } from '@instructure/ui-react-utils'
33
33
 
34
- import { GridCol } from '../GridCol'
35
- import type { GridColProps } from '../GridCol/props'
34
+ import { GridCol } from '../../GridCol/v1/'
35
+ import type { GridColProps } from '../../GridCol/v1/props'
36
36
 
37
- import { withStyle } from '@instructure/emotion'
37
+ import { withStyleLegacy as withStyle } from '@instructure/emotion'
38
38
 
39
39
  import generateStyle from './styles'
40
40
  import generateComponentTheme from './theme'
@@ -26,7 +26,7 @@ import React from 'react'
26
26
 
27
27
  import type { GridTheme, OtherHTMLAttributes } from '@instructure/shared-types'
28
28
  import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
29
- import type { GridBreakpoints } from '../GridTypes'
29
+ import type { GridBreakpoints } from '../../utils/v1/GridTypes'
30
30
 
31
31
  type GridRowOwnProps = {
32
32
  /**
@@ -23,7 +23,7 @@
23
23
  */
24
24
 
25
25
  import type { GridTheme } from '@instructure/shared-types'
26
- import type { GridBreakpoints } from '../GridTypes'
26
+ import type { GridBreakpoints } from '../../utils/v1/GridTypes'
27
27
  import type { GridRowProps, GridRowStyle } from './props'
28
28
 
29
29
  /**
@@ -0,0 +1,109 @@
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, Component, Children } from 'react'
26
+
27
+ import {
28
+ safeCloneElement,
29
+ matchComponentTypes,
30
+ omitProps,
31
+ pickProps
32
+ } from '@instructure/ui-react-utils'
33
+
34
+ import { GridCol } from '../../GridCol/v2/'
35
+ import type { GridColProps } from '../../GridCol/v2/props'
36
+
37
+ import { withStyle } from '@instructure/emotion'
38
+
39
+ import generateStyle from './styles'
40
+
41
+ import { allowedProps } from './props'
42
+ import type { GridRowProps } from './props'
43
+
44
+ /**
45
+ ---
46
+ parent: Grid
47
+ id: Grid.Row
48
+ ---
49
+ **/
50
+ @withStyle(generateStyle)
51
+ class GridRow extends Component<GridRowProps> {
52
+ static readonly componentId = 'Grid.Row'
53
+
54
+ static allowedProps = allowedProps
55
+ static defaultProps = {
56
+ children: null,
57
+ isLastRow: false
58
+ }
59
+
60
+ ref: Element | null = null
61
+
62
+ handleRef = (el: Element | null) => {
63
+ this.ref = el
64
+ }
65
+
66
+ componentDidMount() {
67
+ this.props.makeStyles?.()
68
+ }
69
+
70
+ componentDidUpdate() {
71
+ this.props.makeStyles?.()
72
+ }
73
+
74
+ renderChildren() {
75
+ const { styles, makeStyles, ...props } = this.props
76
+
77
+ return Children.map(this.props.children, (child, index) => {
78
+ if (
79
+ matchComponentTypes<ComponentElement<GridColProps, GridCol>>(child, [
80
+ GridCol
81
+ ])
82
+ ) {
83
+ return safeCloneElement(child, {
84
+ ...pickProps(props, GridRow.allowedProps),
85
+ ...child.props /* child props should override parent */,
86
+ isLastRow: props.isLastRow,
87
+ isLastCol: index + 1 === Children.count(this.props.children)
88
+ })
89
+ } else {
90
+ return child // PropType validation should handle errors
91
+ }
92
+ })
93
+ }
94
+
95
+ render() {
96
+ const { styles, ...restProps } = this.props
97
+
98
+ const props = omitProps(restProps, GridRow.allowedProps)
99
+
100
+ return (
101
+ <span {...props} css={styles?.gridRow} ref={this.handleRef}>
102
+ {this.renderChildren()}
103
+ </span>
104
+ )
105
+ }
106
+ }
107
+
108
+ export default GridRow
109
+ export { GridRow }
@@ -0,0 +1,66 @@
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
+
27
+ import type { GridTheme, OtherHTMLAttributes } from '@instructure/shared-types'
28
+ import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
29
+ import type { GridBreakpoints } from '../../utils/v1/GridTypes'
30
+
31
+ type GridRowOwnProps = {
32
+ /**
33
+ * One of: `Grid.Col`, `ScreenReaderContent`
34
+ */
35
+ children?: React.ReactNode // TODO: oneOf([GridCol, ScreenReaderContent])
36
+ rowSpacing?: 'none' | 'small' | 'medium' | 'large'
37
+ colSpacing?: 'none' | 'small' | 'medium' | 'large'
38
+ hAlign?: 'start' | 'center' | 'end' | 'space-around' | 'space-between'
39
+ vAlign?: 'top' | 'middle' | 'bottom' | 'stretch'
40
+ startAt?: GridBreakpoints
41
+ visualDebug?: boolean
42
+ isLastRow?: boolean
43
+ }
44
+
45
+ type PropKeys = keyof GridRowOwnProps
46
+
47
+ type AllowedPropKeys = Readonly<Array<PropKeys>>
48
+
49
+ type GridRowProps = GridRowOwnProps &
50
+ WithStyleProps<GridTheme, GridRowStyle> &
51
+ OtherHTMLAttributes<GridRowOwnProps>
52
+
53
+ type GridRowStyle = ComponentStyle<'gridRow'>
54
+ const allowedProps: AllowedPropKeys = [
55
+ 'children',
56
+ 'rowSpacing',
57
+ 'colSpacing',
58
+ 'hAlign',
59
+ 'vAlign',
60
+ 'startAt',
61
+ 'visualDebug',
62
+ 'isLastRow'
63
+ ]
64
+
65
+ export type { GridRowProps, GridRowStyle }
66
+ export { allowedProps }
@@ -0,0 +1,120 @@
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 } from '@instructure/ui-themes'
26
+ import type { GridBreakpoints } from '../../utils/v1/GridTypes'
27
+ import type { GridRowProps, GridRowStyle } from './props'
28
+
29
+ /**
30
+ * ---
31
+ * private: true
32
+ * ---
33
+ * Generates the style object from the theme and provided additional information
34
+ * @param {Object} componentTheme The theme variable object.
35
+ * @param {Object} props the props of the component, the style is applied to
36
+ * @param {Object} state the state of the component, the style is applied to
37
+ * @return {Object} The final style object, which will be used in the component
38
+ */
39
+ const generateStyle = (
40
+ componentTheme: NewComponentTypes['GridRow'],
41
+ props: GridRowProps
42
+ ): GridRowStyle => {
43
+ const {
44
+ hAlign,
45
+ vAlign,
46
+ rowSpacing,
47
+ colSpacing,
48
+ isLastRow,
49
+ startAt,
50
+ visualDebug
51
+ } = props
52
+
53
+ const getGridRowStyle = () => {
54
+ const hAlignVariants = {
55
+ center: { justifyContent: 'center' },
56
+ start: { justifyContent: 'flex-start' },
57
+ end: { justifyContent: 'flex-end' },
58
+ 'space-around': { justifyContent: 'space-around' },
59
+ 'space-between': { justifyContent: 'space-between' }
60
+ }
61
+
62
+ const vAlignVariants = {
63
+ top: { alignItems: 'flex-start' },
64
+ middle: { alignItems: 'center' },
65
+ bottom: { alignItems: 'flex-end' },
66
+ stretch: { alignItems: 'stretch' }
67
+ }
68
+
69
+ const colSpacingVariants = {
70
+ small: { margin: `0 calc(-1 * ${componentTheme.spacingSmall} / 2)` },
71
+ medium: { margin: `0 calc(-1 * ${componentTheme.spacingMedium} / 2)` },
72
+ large: { margin: `0 calc(-1 * ${componentTheme.spacingLarge} / 2)` },
73
+ none: {}
74
+ }
75
+
76
+ const rowSpacingVariants = {
77
+ small: { marginBottom: componentTheme.spacingSmall },
78
+ medium: { marginBottom: componentTheme.spacingMedium },
79
+ large: { marginBottom: componentTheme.spacingLarge },
80
+ none: { marginBottom: 0 }
81
+ }
82
+
83
+ return {
84
+ display: 'flex',
85
+ flexFlow: 'row nowrap',
86
+ ...(hAlign && hAlignVariants[hAlign]),
87
+ ...(vAlign && vAlignVariants[vAlign]),
88
+ ...(colSpacing && colSpacingVariants[colSpacing]),
89
+ ...(rowSpacing && rowSpacingVariants[rowSpacing]),
90
+ ...(isLastRow && { marginBottom: 0 })
91
+ }
92
+ }
93
+
94
+ const getStartAtVariants = (breakpoint: GridBreakpoints) =>
95
+ !!startAt && startAt === breakpoint ? { ...getGridRowStyle() } : {}
96
+
97
+ return {
98
+ gridRow: {
99
+ label: 'gridRow',
100
+ display: 'block',
101
+ boxSizing: 'border-box',
102
+
103
+ ...getStartAtVariants('small'),
104
+
105
+ [`@media screen and (min-width: ${componentTheme.mediumMin})`]: {
106
+ ...getStartAtVariants('medium')
107
+ },
108
+ [`@media screen and (min-width: ${componentTheme.largeMin})`]: {
109
+ ...getStartAtVariants('large')
110
+ },
111
+ [`@media screen and (min-width: ${componentTheme.xLargeMin})`]: {
112
+ ...getStartAtVariants('x-large')
113
+ },
114
+
115
+ ...(visualDebug && { outline: '0.0625rem dashed blue' })
116
+ }
117
+ }
118
+ }
119
+
120
+ export default generateStyle
@@ -0,0 +1,30 @@
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 { Grid, GridRow, GridCol } from '../Grid/v1'
25
+
26
+ export type { GridBreakpoints } from '../utils/v1/GridTypes'
27
+
28
+ export type { GridProps } from '../Grid/v1/props'
29
+ export type { GridRowProps } from '../GridRow/v1/props'
30
+ export type { GridColProps } from '../GridCol/v1/props'