Skip to content

Commit 0b31d25

Browse files
committed
docs(list): add docs for list
1 parent ed19269 commit 0b31d25

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed

src/components/list/README.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# md-list
2+
3+
`md-list` is a container component that wraps and formats a series of line items. As the base list component,
4+
it provides Material Design styling, but no behavior of its own.
5+
6+
## Usage
7+
8+
### Simple list
9+
10+
To use `md-list`, first import the list directives and add them to your component's directives array:
11+
12+
```javascript
13+
@Component({
14+
...
15+
directives: [MD_LIST_DIRECTIVES]
16+
})
17+
```
18+
19+
In your template, create an `md-list` element and wrap each of your items in an `md-list-item` tag.
20+
21+
```html
22+
<md-list>
23+
<md-list-item> Pepper </md-list-item>
24+
<md-list-item> Salt </md-list-item>
25+
<md-list-item> Paprika </md-list-item>
26+
</md-list>
27+
```
28+
29+
Output:
30+
31+
<img src="https://material.angularjs.org/material2_assets/list/basic-list.png">
32+
33+
### Multi-line lists
34+
35+
If your list requires multiple lines per list item, annotate each line with an `md-line` attribute.
36+
You can use whichever heading tag is appropriate for your DOM hierarchy (doesn't have to be `h3`),
37+
as long as the `md-line` attribute is included.
38+
39+
```html
40+
<!-- two line list -->
41+
<md-list>
42+
<md-list-item *ngFor="#message of messages">
43+
<h3 md-line> {{message.from}} </h3>
44+
<p md-line>
45+
<span> {{message.subject}} </span>
46+
<span class="demo-2"> -- {{message.message}} </span>
47+
</p>
48+
</md-list-item>
49+
</md-list>
50+
51+
<!-- three line list -->
52+
<md-list>
53+
<md-list-item *ngFor="#message of messages">
54+
<h3 md-line> {{message.from}} </h3>
55+
<p md-line> {{message.subject}} </p>
56+
<p md-line class="demo-2"> {{message.message}} </p>
57+
</md-list-item>
58+
</md-list>
59+
```
60+
61+
Two line list output:
62+
63+
<img src="https://material.angularjs.org/material2_assets/list/two-line-list.png">
64+
65+
Three line list output:
66+
67+
<img src="https://material.angularjs.org/material2_assets/list/three-line-list.png">
68+
69+
### Lists with avatars
70+
71+
To include an avatar, add an image tag with an `md-list-avatar` attribute.
72+
73+
```html
74+
<md-list>
75+
<md-list-item *ngFor="#message of messages">
76+
<img md-list-avatar src="..." alt="...">
77+
<h3 md-line> {{message.from}} </h3>
78+
<p md-line>
79+
<span> {{message.subject}} </span>
80+
<span class="demo-2"> -- {{message.message}} </span>
81+
</p>
82+
</md-list-item>
83+
</md-list>
84+
```
85+
86+
Output:
87+
88+
<img src="https://material.angularjs.org/material2_assets/list/list-with-avatar-2.png">
89+
90+
### Dense lists
91+
Lists are also available in "dense layout" mode, which shrinks the font size and height of the list
92+
to suit UIs that may need to display more information. To enable this mode, add a `dense` attribute
93+
to the main `md-list` tag.
94+
95+
96+
```html
97+
<md-list dense>
98+
<md-list-item> Pepper </md-list-item>
99+
<md-list-item> Salt </md-list-item>
100+
<md-list-item> Paprika </md-list-item>
101+
</md-list>
102+
```
103+
104+
Output:
105+
106+
<img src="https://material.angularjs.org/material2_assets/list/dense-list.png">
107+
108+
### Lists with secondary text
109+
Secondary text styling will be part of a broader typography module to
110+
[come later](https://github.com/angular/material2/issues/205), and won’t be implemented as part of this component
111+
specifically. Gray text in the examples above comes from a "demo-2" class added manually by the demo.
112+
113+
### Lists with `*ngIf`
114+
115+
If you'd like to use `*ngIf` on one of your list item lines, make sure to use `<template [ngIf]>` syntax rather than
116+
the `*ngIf` shortcut (see example below). There is currently an [issue in the main Angular repo](https://github.com/angular/angular/issues/6303)
117+
that will project the line into the wrong content container if the shortcut is used.
118+
119+
```html
120+
<md-list-item>
121+
<h3 md-line> Some heading </h3>
122+
<template [ngIf]="showLine">
123+
<p md-line> Some text </p>
124+
</template>
125+
</md-list-item>
126+
```

0 commit comments

Comments
 (0)