@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,239 @@
|
|
|
1
|
+
---
|
|
2
|
+
describes: Grid
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
### Create a basic column layout
|
|
6
|
+
|
|
7
|
+
Simply create a `<Grid>` with some `<Grid.Row>` and `Grid.Col` children, and
|
|
8
|
+
the component will evenly distribute its columns.
|
|
9
|
+
|
|
10
|
+
Note the `visualDebug` prop you can set if you're wondering
|
|
11
|
+
exactly where your Grid columns are.
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
---
|
|
15
|
+
type: example
|
|
16
|
+
---
|
|
17
|
+
<div>
|
|
18
|
+
<Grid visualDebug>
|
|
19
|
+
<Grid.Row>
|
|
20
|
+
<Grid.Col>
|
|
21
|
+
{lorem.paragraph()}
|
|
22
|
+
</Grid.Col>
|
|
23
|
+
<Grid.Col>
|
|
24
|
+
{lorem.paragraph()}
|
|
25
|
+
</Grid.Col>
|
|
26
|
+
<Grid.Col>
|
|
27
|
+
{lorem.paragraph()}
|
|
28
|
+
</Grid.Col>
|
|
29
|
+
</Grid.Row>
|
|
30
|
+
</Grid>
|
|
31
|
+
<p>
|
|
32
|
+
{lorem.paragraph()}
|
|
33
|
+
</p>
|
|
34
|
+
</div>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Make the Grid stack until a certain breakpoint/screen width
|
|
38
|
+
|
|
39
|
+
Often you will want to stack your `<Grid.Col>`s until you reach a certain
|
|
40
|
+
screen width. To do this, use the `startAt` prop.
|
|
41
|
+
|
|
42
|
+
Reduce the screen width and see how the Grid below only displays its
|
|
43
|
+
columns inline after it hits the `large` breakpoint. Note that by
|
|
44
|
+
default, stacked columns have bottom margin for visual separation.
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
---
|
|
48
|
+
type: example
|
|
49
|
+
---
|
|
50
|
+
<Grid startAt="large" visualDebug>
|
|
51
|
+
<Grid.Row>
|
|
52
|
+
<Grid.Col>
|
|
53
|
+
{lorem.paragraph()}
|
|
54
|
+
</Grid.Col>
|
|
55
|
+
<Grid.Col>
|
|
56
|
+
{lorem.paragraph()}
|
|
57
|
+
</Grid.Col>
|
|
58
|
+
</Grid.Row>
|
|
59
|
+
</Grid>
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Control the width of each column
|
|
63
|
+
|
|
64
|
+
You can control the width of the `<Grid.Col>` columns for each
|
|
65
|
+
breakpoint with the `width` prop. Please note the following:
|
|
66
|
+
|
|
67
|
+
- If you don't need complex responsive behavior, you can just set
|
|
68
|
+
the width property to a single value for all breakpoints after
|
|
69
|
+
and including the breakpoint set via the `startAt` prop. e.g.
|
|
70
|
+
`<Grid.Col width={2}>`
|
|
71
|
+
|
|
72
|
+
- The Grid is made up of **12 columns**. If the columns' total
|
|
73
|
+
width exceeds 12, the layout will break.
|
|
74
|
+
|
|
75
|
+
- In addition to accepting any positive, `<=12` numerical values,
|
|
76
|
+
columns can also accept an `auto` value. This tells the column
|
|
77
|
+
to expand to the width of its content. (See the final example Grid
|
|
78
|
+
to see how this can be useful for right-aligning column content.)
|
|
79
|
+
|
|
80
|
+
- The `startAt` prop setting supersedes any `<Grid.Col>` width props. For
|
|
81
|
+
example, if you set `width={{small: 2}}` on a column, but the `startAt` prop
|
|
82
|
+
on your `<Grid>` is set to `medium`, the `width={{small: 2}}` will be ignored.
|
|
83
|
+
|
|
84
|
+
```js
|
|
85
|
+
---
|
|
86
|
+
type: example
|
|
87
|
+
---
|
|
88
|
+
<Grid visualDebug>
|
|
89
|
+
<Grid.Row>
|
|
90
|
+
<Grid.Col width={{small: 4, medium: 6, large: 3, xLarge: 6}}>
|
|
91
|
+
{lorem.paragraph()}
|
|
92
|
+
</Grid.Col>
|
|
93
|
+
<Grid.Col width={{small: 4, medium: 4, large: 3, xLarge: 5}}>
|
|
94
|
+
{lorem.paragraph()}
|
|
95
|
+
</Grid.Col>
|
|
96
|
+
<Grid.Col width={{small: 4, medium: 2, large: 6, xLarge: 1}}>
|
|
97
|
+
{lorem.paragraph()}
|
|
98
|
+
</Grid.Col>
|
|
99
|
+
</Grid.Row>
|
|
100
|
+
</Grid>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Add space/gutter between columns and rows
|
|
104
|
+
|
|
105
|
+
By default there is uniform spacing between Grid columns and rows, use the `colSpacing` and
|
|
106
|
+
`rowSpacing` props, which accept `small`, `medium`, and `large` as values, you can change amount of spacing,
|
|
107
|
+
or remove it with `none`.
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
---
|
|
111
|
+
type: example
|
|
112
|
+
---
|
|
113
|
+
<Grid colSpacing="large" rowSpacing="small" visualDebug>
|
|
114
|
+
<Grid.Row>
|
|
115
|
+
<Grid.Col>
|
|
116
|
+
{lorem.paragraph()}
|
|
117
|
+
</Grid.Col>
|
|
118
|
+
<Grid.Col>
|
|
119
|
+
{lorem.paragraph()}
|
|
120
|
+
</Grid.Col>
|
|
121
|
+
<Grid.Col>
|
|
122
|
+
{lorem.paragraph()}
|
|
123
|
+
</Grid.Col>
|
|
124
|
+
</Grid.Row>
|
|
125
|
+
<Grid.Row>
|
|
126
|
+
<Grid.Col>
|
|
127
|
+
{lorem.paragraph()}
|
|
128
|
+
</Grid.Col>
|
|
129
|
+
<Grid.Col>
|
|
130
|
+
{lorem.paragraph()}
|
|
131
|
+
</Grid.Col>
|
|
132
|
+
<Grid.Col>
|
|
133
|
+
{lorem.paragraph()}
|
|
134
|
+
</Grid.Col>
|
|
135
|
+
</Grid.Row>
|
|
136
|
+
</Grid>
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Another useful method for spacing out `<Grid.Col>` elements is to use the `hAlign`
|
|
140
|
+
prop together with set widths on the columns. `hAlign` accepts the following
|
|
141
|
+
values: `start`, `center`, `end`, `space-around`, and `space-between`.
|
|
142
|
+
|
|
143
|
+
#### `hAlign="space-between"`
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
---
|
|
147
|
+
type: example
|
|
148
|
+
---
|
|
149
|
+
<Grid hAlign="space-between" visualDebug>
|
|
150
|
+
<Grid.Row>
|
|
151
|
+
<Grid.Col width={2}>
|
|
152
|
+
{lorem.paragraph()}
|
|
153
|
+
</Grid.Col>
|
|
154
|
+
<Grid.Col width={4}>
|
|
155
|
+
{lorem.paragraph()}
|
|
156
|
+
</Grid.Col>
|
|
157
|
+
<Grid.Col width={2}>
|
|
158
|
+
{lorem.paragraph()}
|
|
159
|
+
</Grid.Col>
|
|
160
|
+
</Grid.Row>
|
|
161
|
+
</Grid>
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
#### `hAlign="space-around"`
|
|
165
|
+
|
|
166
|
+
```js
|
|
167
|
+
---
|
|
168
|
+
type: example
|
|
169
|
+
---
|
|
170
|
+
<Grid hAlign="space-around" visualDebug>
|
|
171
|
+
<Grid.Row>
|
|
172
|
+
<Grid.Col width={2}>
|
|
173
|
+
{lorem.paragraph()}
|
|
174
|
+
</Grid.Col>
|
|
175
|
+
<Grid.Col width={4}>
|
|
176
|
+
{lorem.paragraph()}
|
|
177
|
+
</Grid.Col>
|
|
178
|
+
<Grid.Col width={2}>
|
|
179
|
+
{lorem.paragraph()}
|
|
180
|
+
</Grid.Col>
|
|
181
|
+
</Grid.Row>
|
|
182
|
+
</Grid>
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Vertically align your columns
|
|
186
|
+
|
|
187
|
+
Align your columns along the vertical axis with the `vAlign` prop. In the example
|
|
188
|
+
below the Grid is set to vertically center its columns.
|
|
189
|
+
|
|
190
|
+
```js
|
|
191
|
+
---
|
|
192
|
+
type: example
|
|
193
|
+
---
|
|
194
|
+
<Grid vAlign="middle" visualDebug>
|
|
195
|
+
<Grid.Row>
|
|
196
|
+
<Grid.Col>
|
|
197
|
+
{lorem.paragraph()}
|
|
198
|
+
</Grid.Col>
|
|
199
|
+
<Grid.Col>
|
|
200
|
+
{lorem.paragraph()}
|
|
201
|
+
</Grid.Col>
|
|
202
|
+
<Grid.Col>
|
|
203
|
+
{lorem.paragraph()}
|
|
204
|
+
</Grid.Col>
|
|
205
|
+
</Grid.Row>
|
|
206
|
+
</Grid>
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Putting it all together
|
|
210
|
+
|
|
211
|
+
Let's use `<Grid>` to create a page header with a heading on the left side
|
|
212
|
+
and some action buttons on the right. In addition, let's say that on small
|
|
213
|
+
screens — like smalls — we want the header to stack the heading and
|
|
214
|
+
the buttons.
|
|
215
|
+
|
|
216
|
+
Use `startAt="medium"` to make the Grid only affect most tablets and above. To align
|
|
217
|
+
the buttons to the right, add `width="auto"` to their `<Grid.Col>`. This will
|
|
218
|
+
make the column only expand to fit the width of the buttons. Because the
|
|
219
|
+
`<Grid.Col>` containing the heading has no set width, it will expand by default
|
|
220
|
+
to take up all the width it can, pinning the columns containing the buttons
|
|
221
|
+
to the right.
|
|
222
|
+
|
|
223
|
+
```js
|
|
224
|
+
---
|
|
225
|
+
type: example
|
|
226
|
+
---
|
|
227
|
+
<Grid startAt="medium" vAlign="middle" colSpacing="none">
|
|
228
|
+
<Grid.Row>
|
|
229
|
+
<Grid.Col>
|
|
230
|
+
<Heading>I am a fairly lengthy heading for the page</Heading>
|
|
231
|
+
</Grid.Col>
|
|
232
|
+
<Grid.Col width="auto">
|
|
233
|
+
<Button>Cancel</Button>
|
|
234
|
+
|
|
235
|
+
<Button color="primary" renderIcon={IconAddSolid}>Widget</Button>
|
|
236
|
+
</Grid.Col>
|
|
237
|
+
</Grid.Row>
|
|
238
|
+
</Grid>
|
|
239
|
+
```
|
|
@@ -0,0 +1,117 @@
|
|
|
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 { GridRow } from '../../GridRow/v2'
|
|
35
|
+
import type { GridRowProps } from '../../GridRow/v2/props'
|
|
36
|
+
import { GridCol } from '../../GridCol/v2'
|
|
37
|
+
|
|
38
|
+
import { withStyle } from '@instructure/emotion'
|
|
39
|
+
|
|
40
|
+
import generateStyle from './styles'
|
|
41
|
+
|
|
42
|
+
import { allowedProps } from './props'
|
|
43
|
+
import type { GridProps } from './props'
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
---
|
|
47
|
+
category: components
|
|
48
|
+
---
|
|
49
|
+
**/
|
|
50
|
+
@withStyle(generateStyle)
|
|
51
|
+
class Grid extends Component<GridProps> {
|
|
52
|
+
static readonly componentId = 'Grid'
|
|
53
|
+
|
|
54
|
+
static allowedProps = allowedProps
|
|
55
|
+
static defaultProps = {
|
|
56
|
+
colSpacing: 'medium',
|
|
57
|
+
rowSpacing: 'medium',
|
|
58
|
+
hAlign: 'start',
|
|
59
|
+
startAt: 'small',
|
|
60
|
+
vAlign: 'top',
|
|
61
|
+
visualDebug: false,
|
|
62
|
+
children: null
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static Row = GridRow
|
|
66
|
+
static Col = GridCol
|
|
67
|
+
|
|
68
|
+
ref: Element | null = null
|
|
69
|
+
|
|
70
|
+
handleRef = (el: Element | null) => {
|
|
71
|
+
this.ref = el
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
componentDidMount() {
|
|
75
|
+
this.props.makeStyles?.()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
componentDidUpdate() {
|
|
79
|
+
this.props.makeStyles?.()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
renderChildren() {
|
|
83
|
+
const { styles, makeStyles, ...props } = this.props
|
|
84
|
+
const children = Children.toArray(this.props.children)
|
|
85
|
+
|
|
86
|
+
return children.map((child, index) => {
|
|
87
|
+
if (
|
|
88
|
+
matchComponentTypes<ComponentElement<GridRowProps, GridRow>>(child, [
|
|
89
|
+
GridRow
|
|
90
|
+
])
|
|
91
|
+
) {
|
|
92
|
+
return safeCloneElement(child, {
|
|
93
|
+
...pickProps(props, Grid.allowedProps),
|
|
94
|
+
...child.props /* child props should override parent */,
|
|
95
|
+
isLastRow: index + 1 === children.length
|
|
96
|
+
})
|
|
97
|
+
} else {
|
|
98
|
+
return child // PropType validation should handle errors
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
render() {
|
|
104
|
+
const { styles, ...restProps } = this.props
|
|
105
|
+
|
|
106
|
+
const props = omitProps(restProps, Grid.allowedProps)
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<span {...props} css={styles?.grid} ref={this.handleRef}>
|
|
110
|
+
{this.renderChildren()}
|
|
111
|
+
</span>
|
|
112
|
+
)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export default Grid
|
|
117
|
+
export { Grid, GridRow, GridCol }
|
|
@@ -0,0 +1,62 @@
|
|
|
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 { GridTheme, OtherHTMLAttributes } from '@instructure/shared-types'
|
|
26
|
+
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
27
|
+
import type { GridBreakpoints } from '../../utils/v1/GridTypes'
|
|
28
|
+
|
|
29
|
+
type GridOwnProps = {
|
|
30
|
+
/**
|
|
31
|
+
* One of: `Grid.Row`, `ScreenReaderContent`
|
|
32
|
+
*/
|
|
33
|
+
children?: React.ReactNode // TODO: oneOf([GridRow, ScreenReaderContent])
|
|
34
|
+
colSpacing?: 'none' | 'small' | 'medium' | 'large'
|
|
35
|
+
rowSpacing?: 'none' | 'small' | 'medium' | 'large'
|
|
36
|
+
hAlign?: 'start' | 'center' | 'end' | 'space-around' | 'space-between'
|
|
37
|
+
vAlign?: 'top' | 'middle' | 'bottom' | 'stretch'
|
|
38
|
+
startAt?: GridBreakpoints
|
|
39
|
+
visualDebug?: boolean
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
type PropKeys = keyof GridOwnProps
|
|
43
|
+
|
|
44
|
+
type AllowedPropKeys = Readonly<Array<PropKeys>>
|
|
45
|
+
|
|
46
|
+
type GridProps = GridOwnProps &
|
|
47
|
+
WithStyleProps<GridTheme, GridStyle> &
|
|
48
|
+
OtherHTMLAttributes<GridOwnProps>
|
|
49
|
+
|
|
50
|
+
type GridStyle = ComponentStyle<'grid'>
|
|
51
|
+
const allowedProps: AllowedPropKeys = [
|
|
52
|
+
'children',
|
|
53
|
+
'colSpacing',
|
|
54
|
+
'rowSpacing',
|
|
55
|
+
'hAlign',
|
|
56
|
+
'vAlign',
|
|
57
|
+
'startAt',
|
|
58
|
+
'visualDebug'
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
export type { GridProps, GridStyle }
|
|
62
|
+
export { allowedProps }
|
|
@@ -0,0 +1,70 @@
|
|
|
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 { GridProps, GridStyle } 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['Grid'],
|
|
41
|
+
props: GridProps
|
|
42
|
+
): GridStyle => {
|
|
43
|
+
const { startAt, visualDebug } = props
|
|
44
|
+
|
|
45
|
+
const getStartAtVariants = (breakpoint: GridBreakpoints) =>
|
|
46
|
+
!!startAt && startAt === breakpoint ? { boxSizing: 'border-box' } : {}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
grid: {
|
|
50
|
+
label: 'grid',
|
|
51
|
+
display: 'block',
|
|
52
|
+
|
|
53
|
+
...getStartAtVariants('small'),
|
|
54
|
+
|
|
55
|
+
[`@media screen and (min-width: ${componentTheme.mediumMin})`]: {
|
|
56
|
+
...getStartAtVariants('medium')
|
|
57
|
+
},
|
|
58
|
+
[`@media screen and (min-width: ${componentTheme.largeMin})`]: {
|
|
59
|
+
...getStartAtVariants('large')
|
|
60
|
+
},
|
|
61
|
+
[`@media screen and (min-width: ${componentTheme.xLargeMin})`]: {
|
|
62
|
+
...getStartAtVariants('x-large')
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
...(visualDebug && { outline: '0.0625rem dashed red' })
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default generateStyle
|
|
@@ -26,7 +26,7 @@ import { Component } from 'react'
|
|
|
26
26
|
|
|
27
27
|
import { omitProps } from '@instructure/ui-react-utils'
|
|
28
28
|
|
|
29
|
-
import { withStyle } from '@instructure/emotion'
|
|
29
|
+
import { withStyleLegacy as withStyle } from '@instructure/emotion'
|
|
30
30
|
import { logWarn as warn } from '@instructure/console'
|
|
31
31
|
|
|
32
32
|
import generateStyle from './styles'
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
import type { WithStyleProps, ComponentStyle } from '@instructure/emotion'
|
|
26
26
|
import type { GridTheme, OtherHTMLAttributes } from '@instructure/shared-types'
|
|
27
|
-
import type { GridBreakpoints } from '
|
|
27
|
+
import type { GridBreakpoints } from '../../utils/v1/GridTypes'
|
|
28
28
|
|
|
29
29
|
type ColWidths = 'auto' | number
|
|
30
30
|
|
|
@@ -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 { GridColProps, GridColStyle } from './props'
|
|
28
28
|
|
|
29
29
|
type BreakPoints = NonNullable<GridBreakpoints>
|
|
@@ -0,0 +1,113 @@
|
|
|
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 { Component } from 'react'
|
|
26
|
+
|
|
27
|
+
import { omitProps } from '@instructure/ui-react-utils'
|
|
28
|
+
|
|
29
|
+
import { withStyle } from '@instructure/emotion'
|
|
30
|
+
import { logWarn as warn } from '@instructure/console'
|
|
31
|
+
|
|
32
|
+
import generateStyle from './styles'
|
|
33
|
+
|
|
34
|
+
import { allowedProps } from './props'
|
|
35
|
+
import type { GridColProps } from './props'
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
---
|
|
39
|
+
parent: Grid
|
|
40
|
+
id: Grid.Col
|
|
41
|
+
---
|
|
42
|
+
**/
|
|
43
|
+
@withStyle(generateStyle)
|
|
44
|
+
class GridCol extends Component<GridColProps> {
|
|
45
|
+
static readonly componentId = 'Grid.Col'
|
|
46
|
+
|
|
47
|
+
static allowedProps = allowedProps
|
|
48
|
+
static defaultProps = {
|
|
49
|
+
textAlign: 'inherit',
|
|
50
|
+
children: null,
|
|
51
|
+
isLastCol: false,
|
|
52
|
+
isLastRow: false
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
ref: HTMLSpanElement | null = null
|
|
56
|
+
|
|
57
|
+
handleRef = (el: HTMLSpanElement | null) => {
|
|
58
|
+
const { elementRef } = this.props
|
|
59
|
+
|
|
60
|
+
this.ref = el
|
|
61
|
+
|
|
62
|
+
if (typeof elementRef === 'function') {
|
|
63
|
+
elementRef(el)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
widthCheck() {
|
|
68
|
+
const { width } = this.props
|
|
69
|
+
let shouldWarn = false
|
|
70
|
+
if (width) {
|
|
71
|
+
if (typeof width === 'number' && width <= 0) {
|
|
72
|
+
shouldWarn = true
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (typeof width === 'object') {
|
|
76
|
+
Object.keys(width).forEach((breakpoint) => {
|
|
77
|
+
//@ts-expect-error Ts doesn't understand Object.keys properly
|
|
78
|
+
if (typeof width[breakpoint] === 'number' && width[breakpoint] <= 0) {
|
|
79
|
+
shouldWarn = true
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (shouldWarn) {
|
|
85
|
+
warn(false, 'Col width must be positive!')
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
componentDidMount() {
|
|
90
|
+
this.props.makeStyles?.()
|
|
91
|
+
this.widthCheck()
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
componentDidUpdate() {
|
|
95
|
+
this.props.makeStyles?.()
|
|
96
|
+
this.widthCheck()
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
render() {
|
|
100
|
+
const { children, styles } = this.props
|
|
101
|
+
|
|
102
|
+
const props = omitProps(this.props, GridCol.allowedProps)
|
|
103
|
+
|
|
104
|
+
return (
|
|
105
|
+
<span {...props} ref={this.handleRef} css={styles?.gridCol}>
|
|
106
|
+
{children}
|
|
107
|
+
</span>
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export default GridCol
|
|
113
|
+
export { GridCol }
|