Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

feat(list): Add component #339

Merged
merged 37 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
db8db91
feat(list): Add component
bonniezhou Oct 5, 2018
19db863
implement adapter methods
bonniezhou Oct 5, 2018
2f2073e
finish implementing list
bonniezhou Oct 5, 2018
35d9c3c
list item
bonniezhou Oct 8, 2018
a035700
add screenshot test
bonniezhou Oct 8, 2018
66523f4
get selection and tabindex working
bonniezhou Oct 8, 2018
8fe7934
get selection working
bonniezhou Oct 9, 2018
12ef3da
ListItem test
bonniezhou Oct 15, 2018
682f8b9
list tests
bonniezhou Oct 16, 2018
f26b9ac
fix tests and lint
bonniezhou Oct 16, 2018
112f19d
README
bonniezhou Oct 16, 2018
1013268
Merge branch 'master' into feat/list
bonniezhou Oct 16, 2018
72e6cb2
name change
bonniezhou Oct 17, 2018
aa96143
break graphic text and meta to subcomponents
bonniezhou Oct 18, 2018
9d2a2a3
fix nits for list
bonniezhou Oct 18, 2018
7c55b77
accept elements for text
bonniezhou Oct 18, 2018
21c527d
merge classes instead of init
bonniezhou Oct 18, 2018
4eb1f3e
condense screenshot tests
bonniezhou Oct 18, 2018
706b8cb
use keys instead of indices
bonniezhou Oct 18, 2018
5b526d4
fix tests
bonniezhou Oct 18, 2018
ccfb8a8
fixes
bonniezhou Oct 19, 2018
0017019
more fixes
bonniezhou Oct 19, 2018
a41652a
bug
bonniezhou Oct 19, 2018
167bd34
selection fix
bonniezhou Oct 19, 2018
d2726d2
use id instead of key
bonniezhou Oct 19, 2018
38ff1c6
list tests
bonniezhou Oct 20, 2018
ca0a263
WIP tests
bonniezhou Oct 21, 2018
a9f5b84
fix all tests
bonniezhou Oct 21, 2018
f057f83
readme
bonniezhou Oct 21, 2018
545a933
Merge branch 'master' into feat/list
bonniezhou Oct 21, 2018
39ac757
lint
bonniezhou Oct 21, 2018
c36e005
merge with master
bonniezhou Oct 21, 2018
d40ae5b
update screenshot golden
bonniezhou Oct 22, 2018
2ffe55c
only change list in screenshot goldens
bonniezhou Oct 22, 2018
d8fc6c6
fix readme
bonniezhou Oct 23, 2018
fdc52fd
Merge branch 'master' into feat/list
bonniezhou Oct 23, 2018
585f340
fix layout grid screenshot test
bonniezhou Oct 23, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/list/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
index.js
ListDivider.js
ListItem.js
107 changes: 107 additions & 0 deletions packages/list/ListItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// 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, {Component} from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';

export default class ListItem extends Component {
listItemElement_ = React.createRef();

componentDidMount() {
const {init} = this.props;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just add a defaultProp for init as an empty method. You don't need to guard against it on line 32.

init();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we set a default prop here the actual prop doesn't override it....

init && init();
}

get listItemElement() {
return this.listItemElement_.current;
}

get classes() {
const {className} = this.props;
return classnames('mdc-list-item', className);
}

focus() {
const element = this.listItemElement_.current;
if (element) {
element.focus();
}
}

followHref() {
const element = this.listItemElement_.current;
if (element && element.href) {
element.click();
}
}

toggleCheckbox() {
// TODO(bonniez): implement
// https://github.com/material-components/material-components-web-react/issues/352
}

render() {
const {
/* eslint-disable */
className,
childrenTabIndex,
init,
id,
/* eslint-enable */
children,
...otherProps
} = this.props;

return (
<li
className={this.classes}
ref={this.listItemElement_}
{...otherProps}
>
{React.Children.map(children, this.renderChild)}
</li>
);
}

renderChild = (child) => {
const props = Object.assign({},
child.props,
{tabIndex: this.props.childrenTabIndex}
);
return React.cloneElement(child, props);
}
}

ListItem.propTypes = {
id: PropTypes.string,
childrenTabIndex: PropTypes.number,
children: PropTypes.node,
className: PropTypes.string,
init: PropTypes.func,
};

ListItem.defaultProps = {
id: '',
childrenTabIndex: -1,
className: '',
};
59 changes: 59 additions & 0 deletions packages/list/ListItemGraphic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// 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 ListItemGraphic = (props) => {
const {
tabIndex, // eslint-disable-line no-unused-vars
graphic,
tabbableOnListItemFocus,
className,
...otherProps
} = props;

const graphicProps = {
className: classnames('mdc-list-item__graphic', className),
tabIndex: tabbableOnListItemFocus ? props.tabIndex : -1,
...otherProps,
};

return React.cloneElement(graphic, graphicProps);
};

ListItemGraphic.propTypes = {
tabbableOnListItemFocus: PropTypes.bool,
className: PropTypes.string,
tabIndex: PropTypes.number,
graphic: PropTypes.element,
};

ListItemGraphic.defaultProps = {
tabbableOnListItemFocus: false,
className: '',
tabIndex: -1,
graphic: {},
};

export default ListItemGraphic;
69 changes: 69 additions & 0 deletions packages/list/ListItemMeta.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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 ListItemMeta = (props) => {
const {
tabIndex, // eslint-disable-line no-unused-vars
meta,
className,
tabbableOnListItemFocus,
...otherProps
} = props;

let metaElement = null;
if (typeof meta === 'string') {
metaElement = <span>{meta}</span>;
} else {
metaElement = meta;
}

const metaProps = {
className: classnames('mdc-list-item__meta', className, meta.className),
tabIndex: tabbableOnListItemFocus ? props.tabIndex : -1,
...otherProps,
};

return React.cloneElement(metaElement, metaProps);
};

ListItemMeta.propTypes = {
tabbableOnListItemFocus: PropTypes.bool,
className: PropTypes.string,
tabIndex: PropTypes.number,
meta: PropTypes.oneOfType([
PropTypes.string,
PropTypes.element,
]),
};

ListItemMeta.defaultProps = {
tabbableOnListItemFocus: false,
className: '',
tabIndex: -1,
meta: null,
};

export default ListItemMeta;
93 changes: 93 additions & 0 deletions packages/list/ListItemText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// 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 ListItemText = (props) => {
const {
primaryText,
secondaryText,
tabbableOnListItemFocus,
tabIndex,
className,
...otherProps
} = props;

const renderText = (text, className) => {
if (typeof text === 'string') {
return (
<span
className={className}
tabIndex={tabbableOnListItemFocus ? tabIndex : -1}
>
{text}
</span>
);
}
const {className: textClassName, ...otherProps} = text.props;
const props = Object.assign({
className: classnames(className, textClassName),
}, ...otherProps);
return React.cloneElement(text, props);
};

if (!secondaryText) {
return renderText(primaryText, classnames('mdc-list-item__text', className));
}

return (
<span
className={classnames('mdc-list-item__text', className)}
tabIndex={tabbableOnListItemFocus ? tabIndex : -1}
{...otherProps}
>
{renderText(primaryText, 'mdc-list-item__primary-text')}
{renderText(secondaryText, 'mdc-list-item__secondary-text')}
</span>
);
};

ListItemText.propTypes = {
tabbableOnListItemFocus: PropTypes.bool,
tabIndex: PropTypes.number,
className: PropTypes.string,
primaryText: PropTypes.oneOfType([
PropTypes.string,
PropTypes.element,
]),
secondaryText: PropTypes.oneOfType([
PropTypes.string,
PropTypes.element,
]),
};

ListItemText.defaultProps = {
tabbableOnListItemFocus: false,
tabIndex: -1,
className: '',
primaryText: '',
secondaryText: '',
};

export default ListItemText;
Loading