Skip to content

Commit

Permalink
feat(list): Add list divider (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
bonniezhou authored and Matt Goo committed Nov 20, 2018
1 parent ecfe414 commit 1b8f38f
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 6 deletions.
54 changes: 54 additions & 0 deletions packages/list/ListDivider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// The MIT License
//
// Copyright (c) 2018 Google, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';

const ListDivider = (props) => {
const {
tag: Tag,
className,
...otherProps
} = props;

return (
<Tag
className={classnames('mdc-list-divider', className)}
{...otherProps}
/>
);
};

ListDivider.propTypes = {
className: PropTypes.string,
tag: PropTypes.string,
role: PropTypes.string,
};

ListDivider.defaultProps = {
className: '',
tag: 'li',
role: 'separator',
};

export default ListDivider;
30 changes: 26 additions & 4 deletions packages/list/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,9 @@ class MyApp extends Component {
}
```

### List groups
### List groups and list dividers

Multiple related lists can be grouped together using the `ListGroup` component. Optional subheaders can be added using `ListGroupSubheader`.

> _NOTE_: You can override the element that the `ListGroup` or `ListGroupSubheader` renders by passing in a `tag` prop. By default, `ListGroup` renders a `div` and `ListGroupSubheader` renders an `h3`.
Multiple related lists can be grouped together using the `ListGroup` component. Optional subheaders can be added using `ListGroupSubheader`. `ListDivider`s can be used to separate content either within a list or between lists.

```js
import React, {Component} from 'react';
Expand All @@ -129,6 +127,7 @@ class MyApp extends Component {
<ListItem><ListItemText primaryText='Photos' /></ListItem>
...
</List>
<ListDivider />
<ListGroupSubheader tag='h2'>Recent Files</ListGroupSubheader>
<List>
<ListItem><ListItemText primaryText='Vacation' /></ListItem>
Expand Down Expand Up @@ -237,6 +236,29 @@ tabIndex | Number | Tab index of the list item meta
tabbableOnListItemFocus | Boolean | Whether focusing list item will toggle tab index of the list item meta. If false, the tab index will always be -1
meta | Element or String | The meta element or string to be displayed behind list item text

### ListDivider

Prop Name | Type | Description
--- | --- | ---
className | String | Classes to be applied to the list divider
tag | String | Element tag of the list divider, defaults to `li`
role | String | ARIA role of the list divider, defaults to `separator`

### ListGroup

Prop Name | Type | Description
--- | --- | ---
className | String | Classes to be applied to the list group
tag | String | Element tag of the list group, defaults to `div`


### ListGroupSubheader

Prop Name | Type | Description
--- | --- | ---
className | String | Classes to be applied to the list group subheader
tag | String | Element tag of the list group subheader, defaults to `h3`

## Sass Mixins

Sass mixins may be available to customize various aspects of the Components. Please refer to the MDC Web repository for more information on what mixins are available, and how to use them.
Expand Down
3 changes: 2 additions & 1 deletion packages/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import ListItem from './ListItem';
import ListItemGraphic from './ListItemGraphic';
import ListItemText from './ListItemText';
import ListItemMeta from './ListItemMeta';
import ListDivider from './ListDivider';
import ListGroup from './ListGroup';
import ListGroupSubheader from './ListGroupSubheader';

Expand Down Expand Up @@ -308,4 +309,4 @@ List.defaultProps = {

/* eslint-enable quote-props */

export {ListItem, ListItemGraphic, ListItemText, ListItemMeta, ListGroup, ListGroupSubheader};
export {ListItem, ListItemGraphic, ListItemText, ListItemMeta, ListDivider, ListGroup, ListGroupSubheader};
3 changes: 2 additions & 1 deletion test/screenshot/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import List, {
ListItemGraphic,
ListItemText,
ListItemMeta,
ListDivider,
ListGroup,
ListGroupSubheader,
} from '../../../packages/list/index';
Expand Down Expand Up @@ -63,7 +64,7 @@ const ListScreenshotTest = () => {
{renderListItem('List item', 'Secondary text')}
{renderListItem('List item', 'Secondary text')}
{renderListItem('List item', 'Secondary text')}
<li className='mdc-list-divider' role='separator'></li>
<ListDivider />
{renderListItem('List item', 'Secondary text')}
{renderListItem('List item', 'Secondary text')}
</List>
Expand Down
26 changes: 26 additions & 0 deletions test/unit/list/ListDivider.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import {assert} from 'chai';
import {shallow} from 'enzyme';
import {ListDivider} from '../../../packages/list';

suite('ListDivider');

test('className adds classes', () => {
const wrapper = shallow(<ListDivider className='test-class-name' />);
assert.isTrue(wrapper.hasClass('test-class-name'));
});

test('has mdc-list-divider class', () => {
const wrapper = shallow(<ListDivider />);
assert.isTrue(wrapper.hasClass('mdc-list-divider'));
});

test('has separator role by default', () => {
const wrapper = shallow(<ListDivider />);
assert.equal(wrapper.props().role, 'separator');
});

test('renders with given tag', () => {
const wrapper = shallow(<ListDivider tag='span' />);
assert.exists(wrapper.find('span'));
});

0 comments on commit 1b8f38f

Please sign in to comment.