diff --git a/examples/component-examples/FilterList.js b/examples/component-examples/FilterList.js new file mode 100644 index 00000000000..d5304fcc2e8 --- /dev/null +++ b/examples/component-examples/FilterList.js @@ -0,0 +1,33 @@ +import React from 'react' +import {LiveEditor} from '@compositor/kit' +import {Block, FilterList, FilterListItem} from '../../src' + +const filterListCode = ` + First Filter + Second Filter + Third Filter + +` + +const filterListSmallCode = ` + First Filter + Second Filter + Third Filter + +` + +const FilterListExample = { + name: 'Filter List', + element: ( +
+ + + + + + +
+ ) +} + +export default FilterListExample diff --git a/examples/component-examples/index.js b/examples/component-examples/index.js index eba1e7ff901..bb0036003e9 100644 --- a/examples/component-examples/index.js +++ b/examples/component-examples/index.js @@ -12,6 +12,7 @@ export {default as CounterLabel} from './CounterLabel' export {default as Details} from './Details' export {default as DonutChart} from './DonutChart' export {default as Dropdown} from './Dropdown' +export {default as FilterList} from './FilterList' export {default as Flash} from './Flash' export {default as Flex} from './Flex' export {default as FontSizes} from './FontSizes' diff --git a/src/FilterList.js b/src/FilterList.js new file mode 100644 index 00000000000..011d80bc765 --- /dev/null +++ b/src/FilterList.js @@ -0,0 +1,31 @@ +import React from 'react' +import PropTypes from 'prop-types' +import classnames from 'classnames' +import {withSystemProps, COMMON} from './system-props' + +export const ITEM_CLASS = 'filter-item' +export const SELECTED_CLASS = 'selected' + +function FilterList({children, className, small}) { + const classes = classnames(className, 'filter-list', small && 'small') + + const items = React.Children.map(children, child => { + return
  • {child}
  • + }) + + return +} + +Object.assign(FilterList, {ITEM_CLASS, SELECTED_CLASS}) + +FilterList.defaultProps = { + m: 0, + p: 0 +} + +FilterList.propTypes = { + children: PropTypes.node, + small: PropTypes.bool +} + +export default withSystemProps(FilterList, COMMON) diff --git a/src/FilterListItem.js b/src/FilterListItem.js new file mode 100644 index 00000000000..3be141c2e9e --- /dev/null +++ b/src/FilterListItem.js @@ -0,0 +1,42 @@ +import React from 'react' +import PropTypes from 'prop-types' +import classnames from 'classnames' +import {ITEM_CLASS, SELECTED_CLASS} from './FilterList' +import {withSystemProps, COMMON} from './system-props' + +function getCountComponent(count) { + return ( + + {count} + + ) +} + +function FilterListItem({children, className, count, selected, is: Tag, ...rest}) { + const classes = classnames(ITEM_CLASS, selected && SELECTED_CLASS, className) + + if (typeof rest.to === 'string') { + rest.activeClassName = SELECTED_CLASS + } + + return ( + + {count && getCountComponent(count)} + {children} + + ) +} + +FilterListItem.defaultProps = { + is: 'a' +} + +FilterListItem.propTypes = { + children: PropTypes.node, + className: PropTypes.string, + count: PropTypes.string, + is: PropTypes.oneOfType([PropTypes.string, PropTypes.func]), + selected: PropTypes.bool +} + +export default withSystemProps(FilterListItem, COMMON) diff --git a/src/__tests__/FilterList.js b/src/__tests__/FilterList.js new file mode 100644 index 00000000000..c4f8261bc18 --- /dev/null +++ b/src/__tests__/FilterList.js @@ -0,0 +1,26 @@ +import React from 'react' +import FilterList from '../FilterList' +import {render, rendersClass} from '../utils/testing' +import {COMMON} from '../system-props' + +describe('FilterList', () => { + it('implements common system props', () => { + expect(FilterList).toImplementSystemProps(COMMON) + }) + + it('renders a