@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.
- package/CHANGELOG.md +27 -276
- package/es/Grid/{index.js → v1/index.js} +3 -3
- package/es/Grid/v2/index.js +98 -0
- package/es/Grid/v2/props.js +26 -0
- package/es/Grid/v2/styles.js +61 -0
- package/es/GridCol/{index.js → v1/index.js} +1 -1
- package/es/GridCol/v2/index.js +100 -0
- package/es/GridCol/v2/props.js +26 -0
- package/es/GridCol/v2/styles.js +211 -0
- package/es/GridRow/{index.js → v1/index.js} +2 -2
- package/es/GridRow/v2/index.js +93 -0
- package/es/GridRow/v2/props.js +26 -0
- package/es/GridRow/v2/styles.js +137 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/es/exports/b.js +24 -0
- package/lib/Grid/v1/index.js +120 -0
- package/lib/Grid/{index.js → v2/index.js} +7 -8
- package/lib/Grid/v2/props.js +31 -0
- package/lib/Grid/v2/styles.js +67 -0
- package/lib/GridCol/v1/index.js +106 -0
- package/lib/GridCol/{index.js → v2/index.js} +1 -2
- package/lib/GridCol/v2/props.js +31 -0
- package/lib/GridCol/v2/styles.js +217 -0
- package/lib/GridRow/v1/index.js +102 -0
- package/lib/GridRow/{index.js → v2/index.js} +3 -4
- package/{src/index.ts → lib/GridRow/v2/props.js} +7 -6
- package/lib/GridRow/v2/styles.js +143 -0
- package/lib/{index.js → exports/a.js} +4 -4
- package/lib/exports/b.js +24 -0
- package/package.json +39 -17
- package/src/Grid/{index.tsx → v1/index.tsx} +4 -4
- package/src/Grid/{props.ts → v1/props.ts} +1 -1
- package/src/Grid/{styles.ts → v1/styles.ts} +1 -1
- package/src/Grid/v2/README.md +239 -0
- package/src/Grid/v2/index.tsx +117 -0
- package/src/Grid/v2/props.ts +62 -0
- package/src/Grid/v2/styles.ts +70 -0
- package/src/GridCol/{index.tsx → v1/index.tsx} +1 -1
- package/src/GridCol/{props.ts → v1/props.ts} +1 -1
- package/src/GridCol/{styles.ts → v1/styles.ts} +1 -1
- package/src/GridCol/v2/index.tsx +113 -0
- package/src/GridCol/v2/props.ts +90 -0
- package/src/GridCol/v2/styles.ts +221 -0
- package/src/GridRow/{index.tsx → v1/index.tsx} +3 -3
- package/src/GridRow/{props.ts → v1/props.ts} +1 -1
- package/src/GridRow/{styles.ts → v1/styles.ts} +1 -1
- package/src/GridRow/v2/index.tsx +109 -0
- package/src/GridRow/v2/props.ts +66 -0
- package/src/GridRow/v2/styles.ts +120 -0
- package/src/exports/a.ts +30 -0
- package/src/exports/b.ts +30 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Grid/{index.d.ts → v1/index.d.ts} +4 -4
- package/types/Grid/v1/index.d.ts.map +1 -0
- package/types/Grid/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/Grid/v1/props.d.ts.map +1 -0
- package/types/Grid/v1/styles.d.ts.map +1 -0
- package/types/Grid/v1/theme.d.ts.map +1 -0
- package/types/Grid/v2/index.d.ts +42 -0
- package/types/Grid/v2/index.d.ts.map +1 -0
- package/types/Grid/v2/props.d.ts +23 -0
- package/types/Grid/v2/props.d.ts.map +1 -0
- package/types/Grid/v2/styles.d.ts +15 -0
- package/types/Grid/v2/styles.d.ts.map +1 -0
- package/types/GridCol/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/GridCol/v1/index.d.ts.map +1 -0
- package/types/GridCol/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/GridCol/v1/props.d.ts.map +1 -0
- package/types/GridCol/v1/styles.d.ts.map +1 -0
- package/types/GridCol/v1/theme.d.ts.map +1 -0
- package/types/GridCol/v2/index.d.ts +51 -0
- package/types/GridCol/v2/index.d.ts.map +1 -0
- package/types/GridCol/v2/props.d.ts +40 -0
- package/types/GridCol/v2/props.d.ts.map +1 -0
- package/types/GridCol/v2/styles.d.ts +15 -0
- package/types/GridCol/v2/styles.d.ts.map +1 -0
- package/types/GridRow/{index.d.ts → v1/index.d.ts} +3 -3
- package/types/GridRow/v1/index.d.ts.map +1 -0
- package/types/GridRow/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/GridRow/v1/props.d.ts.map +1 -0
- package/types/GridRow/v1/styles.d.ts.map +1 -0
- package/types/GridRow/v1/theme.d.ts.map +1 -0
- package/types/GridRow/v2/index.d.ts +36 -0
- package/types/GridRow/v2/index.d.ts.map +1 -0
- package/types/GridRow/v2/props.d.ts +25 -0
- package/types/GridRow/v2/props.d.ts.map +1 -0
- package/types/GridRow/v2/styles.d.ts +15 -0
- package/types/GridRow/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +6 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +6 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/utils/v1/GridTypes.d.ts.map +1 -0
- package/types/Grid/index.d.ts.map +0 -1
- package/types/Grid/props.d.ts.map +0 -1
- package/types/Grid/styles.d.ts.map +0 -1
- package/types/Grid/theme.d.ts.map +0 -1
- package/types/GridCol/index.d.ts.map +0 -1
- package/types/GridCol/props.d.ts.map +0 -1
- package/types/GridCol/styles.d.ts.map +0 -1
- package/types/GridCol/theme.d.ts.map +0 -1
- package/types/GridRow/index.d.ts.map +0 -1
- package/types/GridRow/props.d.ts.map +0 -1
- package/types/GridRow/styles.d.ts.map +0 -1
- package/types/GridRow/theme.d.ts.map +0 -1
- package/types/GridTypes.d.ts.map +0 -1
- package/types/index.d.ts +0 -6
- package/types/index.d.ts.map +0 -1
- /package/es/Grid/{props.js → v1/props.js} +0 -0
- /package/es/Grid/{styles.js → v1/styles.js} +0 -0
- /package/es/Grid/{theme.js → v1/theme.js} +0 -0
- /package/es/GridCol/{props.js → v1/props.js} +0 -0
- /package/es/GridCol/{styles.js → v1/styles.js} +0 -0
- /package/es/GridCol/{theme.js → v1/theme.js} +0 -0
- /package/es/GridRow/{props.js → v1/props.js} +0 -0
- /package/es/GridRow/{styles.js → v1/styles.js} +0 -0
- /package/es/GridRow/{theme.js → v1/theme.js} +0 -0
- /package/es/{GridTypes.js → utils/v1/GridTypes.js} +0 -0
- /package/lib/Grid/{props.js → v1/props.js} +0 -0
- /package/lib/Grid/{styles.js → v1/styles.js} +0 -0
- /package/lib/Grid/{theme.js → v1/theme.js} +0 -0
- /package/lib/GridCol/{props.js → v1/props.js} +0 -0
- /package/lib/GridCol/{styles.js → v1/styles.js} +0 -0
- /package/lib/GridCol/{theme.js → v1/theme.js} +0 -0
- /package/lib/GridRow/{props.js → v1/props.js} +0 -0
- /package/lib/GridRow/{styles.js → v1/styles.js} +0 -0
- /package/lib/GridRow/{theme.js → v1/theme.js} +0 -0
- /package/lib/{GridTypes.js → utils/v1/GridTypes.js} +0 -0
- /package/src/Grid/{README.md → v1/README.md} +0 -0
- /package/src/Grid/{theme.ts → v1/theme.ts} +0 -0
- /package/src/GridCol/{theme.ts → v1/theme.ts} +0 -0
- /package/src/GridRow/{theme.ts → v1/theme.ts} +0 -0
- /package/src/{GridTypes.ts → utils/v1/GridTypes.ts} +0 -0
- /package/types/Grid/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/Grid/{theme.d.ts → v1/theme.d.ts} +0 -0
- /package/types/GridCol/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/GridCol/{theme.d.ts → v1/theme.d.ts} +0 -0
- /package/types/GridRow/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/GridRow/{theme.d.ts → v1/theme.d.ts} +0 -0
- /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 '
|
|
35
|
-
import type { GridColProps } from '
|
|
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 '
|
|
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 '
|
|
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
|
package/src/exports/a.ts
ADDED
|
@@ -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'
|