Skip to content

Commit d1a2a68

Browse files
committed
docs(grid-list): added docs for basic grid-list
1 parent b927afd commit d1a2a68

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

src/components/grid-list/README.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# md-grid-list
2+
3+
`md-grid-list` is an alternative list view that arranges cells into grid-based layout.
4+
See Material Design spec [here](https://www.google.com/design/spec/components/grid-lists.html).
5+
6+
## Usage
7+
8+
### Simple grid list
9+
10+
To use `md-grid-list`, first import the grid list directives and add them to your component's directives
11+
array:
12+
13+
```javascript
14+
@Component({
15+
...
16+
directives: [MD_GRID_LIST_DIRECTIVES]
17+
})
18+
```
19+
20+
In your template, create an `md-grid-list` element and specify the number of columns you want for
21+
your grid using the `cols` property (this is the only mandatory attribute).
22+
23+
You can define each tile using an `md-grid-tile` element, passing any tile content between its tags.
24+
25+
Tiles are greedily placed in the first position of the grid that fits them, so row count depends on
26+
how many tiles can fit in each row, given the col count and the colspan/rowspan of each tile.
27+
28+
```html
29+
<md-grid-list cols="4" [style.background]="'lightblue'">
30+
<md-grid-tile>One</md-grid-tile>
31+
<md-grid-tile>Two</md-grid-tile>
32+
<md-grid-tile>Three</md-grid-tile>
33+
<md-grid-tile>Four</md-grid-tile>
34+
</md-grid-list>
35+
```
36+
37+
Output:
38+
39+
<img src="https://material.angularjs.org/material2_assets/grid-list/basic-grid-list.png">
40+
41+
## Grid list config
42+
43+
####`cols`
44+
45+
The `cols` property controls the number of columns displayed in your grid. It must be set or the
46+
grid list will not be able to generate your layout.
47+
48+
####`rowHeight`
49+
50+
Row height for the list can be calculated in three ways:
51+
52+
1. **Fixed height**: The height can be in `px`, `em`, or `rem`. If no units are specified, `px`
53+
units are assumed.
54+
55+
Ex: `<md-grid-list cols="3" rowHeight="100px">...`
56+
57+
2. **Ratio**: This ratio is width:height, and must be passed in with a colon, not a decimal.
58+
59+
Ex: `<md-grid-list cols="3" rowHeight="4:3">...`.
60+
61+
3. **Fit**: This mode automatically divides the available height by the number of rows. Please note
62+
the height of the grid-list or its container must be set.
63+
64+
Ex: `<md-grid-list cols="3" rowHeight="fit">...`
65+
66+
Defaults to a 1:1 ratio of width:height.
67+
68+
####`gutterSize`
69+
70+
Gutter size can be set to any `px`, `em`, or `rem` value with the `gutterSize` property. If no
71+
units are specified, `px` units are assumed.
72+
73+
Ex: `<md-grid-list cols="3" gutterSize="4px">...`
74+
75+
Defaults to `1px`.
76+
77+
## Grid tile config
78+
79+
You can set the rowspan and colspan of each tile individually, using the `rowspan` and `colspan`
80+
properties. If not set, they both default to `1`.
81+
82+
```html
83+
<md-grid-list cols="4" rowHeight="100px">
84+
<md-grid-tile *ngFor="let tile of tiles" [colspan]="tile.cols" [rowspan]="tile.rows"
85+
[style.background]="tile.color">
86+
{{tile.text}}
87+
</md-grid-tile>
88+
</md-grid-list>
89+
```
90+
91+
```javascript
92+
...
93+
export class MyComp {
94+
tiles: any[] = [
95+
{text: 'One', cols: 3, rows: 1, color: 'lightblue'},
96+
{text: 'Two', cols: 1, rows: 2, color: 'lightgreen'},
97+
{text: 'Three', cols: 1, rows: 1, color: 'lightpink'},
98+
{text: 'Four', cols: 2, rows: 1, color: '#DDBDF1'},
99+
];
100+
}
101+
```
102+
103+
Output:
104+
105+
<img src="https://material.angularjs.org/material2_assets/grid-list/fancy-grid-list.png">
106+
107+
## TODO
108+
109+
- Grid tile headers and footers
110+
- Responsive sizing support

0 commit comments

Comments
 (0)