forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DataList): Add simple data list (patternfly#927)
Signed-off-by: Boaz Shuster <boaz.shuster.github@gmail.com>
- Loading branch information
Showing
25 changed files
with
830 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
packages/patternfly-4/react-core/src/components/DataList/DataList.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { SFC, HTMLProps } from 'react'; | ||
import { Omit } from '../../typeUtils'; | ||
|
||
export interface DataListProps extends Omit<HTMLProps<HTMLUListElement>, 'aria-label'> { | ||
'aria-label': string; | ||
} | ||
|
||
declare const DataList: SFC<DataListProps>; | ||
|
||
export default DataList; |
44 changes: 44 additions & 0 deletions
44
packages/patternfly-4/react-core/src/components/DataList/DataList.docs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
DataList, | ||
DataListItem, | ||
DataListCell, | ||
DataListCheck, | ||
DataListAction, | ||
DataListContent, | ||
DataListToggle | ||
} from '@patternfly/react-core'; | ||
import Simple from './examples/SimpleDataList'; | ||
import CheckboxAction from './examples/CheckboxActionDataList'; | ||
import Expandable from './examples/ExpandableDataList'; | ||
import Modifiers from './examples/ModifiersDataList'; | ||
|
||
export default { | ||
title: 'DataList', | ||
components: { | ||
DataList, | ||
DataListItem, | ||
DataListCell, | ||
DataListCheck, | ||
DataListAction, | ||
DataListContent, | ||
DataListToggle | ||
}, | ||
examples: [ | ||
{ | ||
component: Simple, | ||
title: 'Data List Simple' | ||
}, | ||
{ | ||
component: CheckboxAction, | ||
title: 'Data List Checkboxes, Actions and Additional Cells' | ||
}, | ||
{ | ||
component: Expandable, | ||
title: 'Data List Expandable' | ||
}, | ||
{ | ||
component: Modifiers, | ||
title: 'Data List Width Modifiers' | ||
} | ||
] | ||
}; |
29 changes: 29 additions & 0 deletions
29
packages/patternfly-4/react-core/src/components/DataList/DataList.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
import { css } from '@patternfly/react-styles'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '@patternfly/patternfly-next/components/DataList/styles.css'; | ||
import boxShStyles from '@patternfly/patternfly-next//utilities/BoxShadow/box-shadow.css'; | ||
|
||
const DataList = ({ children, className, 'aria-label': ariaLabel, ...props }) => { | ||
return ( | ||
<ul className={css(styles.dataList, boxShStyles.boxShadowMd, className)} role="list" aria-label={ariaLabel} {...props}> | ||
{children} | ||
</ul> | ||
); | ||
}; | ||
|
||
DataList.propTypes = { | ||
/** Content rendered inside the DataList list */ | ||
children: PropTypes.node, | ||
/** Additional classes added to the DataList list */ | ||
className: PropTypes.string, | ||
/** Adds accessible text to the DataList list */ | ||
'aria-label': PropTypes.string.isRequired | ||
}; | ||
|
||
DataList.defaultProps = { | ||
children: null, | ||
className: '', | ||
}; | ||
|
||
export default DataList; |
91 changes: 91 additions & 0 deletions
91
packages/patternfly-4/react-core/src/components/DataList/DataList.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import DataList from './DataList'; | ||
import DataListItem from './DataListItem'; | ||
import DataListCell from './DataListCell'; | ||
import DataListToggle from './DataListToggle'; | ||
import { Button } from '../Button'; | ||
|
||
describe('DataList', () => { | ||
test('List default', () => { | ||
const view = shallow(<DataList aria-label="this is a simple list" />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('List', () => { | ||
const view = shallow(<DataList key="list-id-1" className="data-list-custom" aria-label="this is a simple list" />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('Item default', () => { | ||
const view = shallow(<DataListItem key="item-id-1" aria-labelledby="item-1" />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('Item expanded', () => { | ||
const view = shallow(<DataListItem aria-labelledby="item-1" isExpanded />); | ||
expect(view.props().className).toBe('pf-c-data-list__item pf-m-expanded'); | ||
}); | ||
|
||
test('Item', () => { | ||
const view = shallow(<DataListItem className="data-list-item-custom" aria-labelledby="item-1" />); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('Cell default', () => { | ||
const view = shallow(<DataListCell>Secondary</DataListCell>); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('Cell', () => { | ||
const view = shallow( | ||
<DataListCell key="list-id-1" id="primary-item" className="data-list-custom"> | ||
Primary Id | ||
</DataListCell> | ||
); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('Cell with width modifier', () => { | ||
[ | ||
{ width: 1, class: '' }, | ||
{ width: 2, class: 'pf-m-flex-2' }, | ||
{ width: 3, class: 'pf-m-flex-3' }, | ||
{ width: 4, class: 'pf-m-flex-4' }, | ||
{ width: 5, class: 'pf-m-flex-5' } | ||
].forEach(testCase => { | ||
const view = shallow( | ||
<DataListCell width={testCase.width} key="list-id-1" id="primary-item"> | ||
Primary Id | ||
</DataListCell> | ||
); | ||
testCase.class === '' | ||
? expect(view.props().className).toBe('pf-c-data-list__cell') | ||
: expect(view.props().className).toBe(`pf-c-data-list__cell ${testCase.class}`); | ||
}); | ||
}); | ||
|
||
test('Toggle default', () => { | ||
const view = shallow( | ||
<DataListToggle aria-label="Toggle details for" aria-labelledby="ex-toggle2 ex-item2" id="ex-toggle2" /> | ||
); | ||
|
||
expect(view.find(Button).props()['aria-label']).toBe('Toggle details for'); | ||
expect(view.find(Button).props()['aria-labelledby']).toBe('ex-toggle2 ex-item2'); | ||
expect(view.find(Button).props()['aria-expanded']).toBe('false'); | ||
expect(view.find(Button).props().id).toBe('ex-toggle2'); | ||
expect(view.find(Button).props().id).toBe('ex-toggle2'); | ||
}); | ||
|
||
test('Toggle expanded', () => { | ||
const view = shallow( | ||
<DataListToggle | ||
aria-label="Toggle details for" | ||
aria-labelledby="ex-toggle2 ex-item2" | ||
id="ex-toggle2" | ||
isExpanded | ||
/> | ||
); | ||
expect(view.find(Button).props()['aria-expanded']).toBe('true'); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
packages/patternfly-4/react-core/src/components/DataList/DataListAction.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { SFC, HTMLProps } from 'react'; | ||
|
||
export interface DataListActionProps extends HTMLProps<HTMLDivElement> { | ||
'aria-labelledby': string; | ||
'aria-label': string; | ||
id: string; | ||
} | ||
|
||
declare const DataListAction: SFC<DataListActionProps>; | ||
|
||
export default DataListAction; |
34 changes: 34 additions & 0 deletions
34
packages/patternfly-4/react-core/src/components/DataList/DataListAction.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import { css } from '@patternfly/react-styles'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '@patternfly/patternfly-next/components/DataList/styles.css'; | ||
import { EllipsisVIcon } from '@patternfly/react-icons'; | ||
import { Button } from '../Button'; | ||
|
||
const DataListAction = ({ className, id, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, ...props }) => ( | ||
<div className={css(styles.dataListAction, className)} {...props}> | ||
<Button variant="plain" id={id} aria-labelledby={ariaLabelledBy} aria-label={ariaLabel}> | ||
<EllipsisVIcon /> | ||
</Button> | ||
</div> | ||
); | ||
|
||
DataListAction.propTypes = { | ||
/** Content rendered inside the DataList list */ | ||
children: PropTypes.node, | ||
/** Additional classes added to the DataList list */ | ||
className: PropTypes.string, | ||
/** Identify the DataList toggle number */ | ||
id: PropTypes.string.isRequired, | ||
/** Adds accessible text to the DataList item */ | ||
'aria-labelledby': PropTypes.string.isRequired, | ||
/** Adds accessible text to the DataList item */ | ||
'aria-label': PropTypes.string.isRequired | ||
}; | ||
|
||
DataListAction.defaultProps = { | ||
children: null, | ||
className: '' | ||
}; | ||
|
||
export default DataListAction; |
9 changes: 9 additions & 0 deletions
9
packages/patternfly-4/react-core/src/components/DataList/DataListCell.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { SFC, HTMLProps } from 'react'; | ||
|
||
export interface DataListCellProps extends HTMLProps<HTMLDivElement> { | ||
width: 1 | 2 | 3 | 4 | 5; | ||
} | ||
|
||
declare const DataListCell: SFC<DataListCellProps>; | ||
|
||
export default DataListCell; |
30 changes: 30 additions & 0 deletions
30
packages/patternfly-4/react-core/src/components/DataList/DataListCell.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { css, getModifier } from '@patternfly/react-styles'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '@patternfly/patternfly-next/components/DataList/styles.css'; | ||
|
||
const DataListCell = ({ children, className, width, ...props }) => ( | ||
<div | ||
className={css(styles.dataListCell, width > 1 && getModifier(styles, `flex_${width}`, ''), className)} | ||
{...props} | ||
> | ||
{children} | ||
</div> | ||
); | ||
|
||
DataListCell.propTypes = { | ||
/** Content rendered inside the DataList cell */ | ||
children: PropTypes.node, | ||
/** Additional classes added to the DataList cell */ | ||
className: PropTypes.string, | ||
/** Width (from 1-5) to the DataList cell */ | ||
width: PropTypes.oneOf([1, 2, 3, 4, 5]) | ||
}; | ||
|
||
DataListCell.defaultProps = { | ||
children: null, | ||
className: '', | ||
width: 1 | ||
}; | ||
|
||
export default DataListCell; |
15 changes: 15 additions & 0 deletions
15
packages/patternfly-4/react-core/src/components/DataList/DataListCheck.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { HTMLProps, FormEvent, ReactNode } from 'react'; | ||
import { Omit } from '../../typeUtils'; | ||
|
||
export interface DataListCheckProps | ||
extends Omit<HTMLProps<HTMLInputElement>, 'type' | 'onChange' | 'disabled' | 'aria-labelledby'> { | ||
isDisabled?: boolean; | ||
isValid?: boolean; | ||
isChecked?: boolean; | ||
onChange?(checked: boolean, event: FormEvent<HTMLInputElement>): void; | ||
'aria-labelledby': string; | ||
} | ||
|
||
declare const DataListCheck: React.SFC<DataListCheckProps>; | ||
|
||
export default DataListCheck; |
44 changes: 44 additions & 0 deletions
44
packages/patternfly-4/react-core/src/components/DataList/DataListCheck.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react'; | ||
import { css } from '@patternfly/react-styles'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '@patternfly/patternfly-next/components/DataList/styles.css'; | ||
import checkboxStyles from '@patternfly/patternfly-next/components/Check/check.css'; | ||
|
||
const DataListCheck = ({ className, onChange, isValid, isDisabled, isChecked, checked, ...props }) => ( | ||
<div className={css(styles.dataListCheck, className)}> | ||
<input | ||
{...props} | ||
className={css(checkboxStyles.checkInput)} | ||
type="checkbox" | ||
onChange={event => onChange(event.currentTarget.checked, event)} | ||
aria-invalid={!isValid} | ||
disabled={isDisabled} | ||
checked={isChecked || checked} | ||
/> | ||
</div> | ||
); | ||
|
||
DataListCheck.propTypes = { | ||
/** Additional classes added to the DataList item checkbox */ | ||
className: PropTypes.string, | ||
/** Flag to show if the DataList checkbox selection is valid or invalid */ | ||
isValid: PropTypes.bool, | ||
/** Flag to show if the DataList checkbox is disabled */ | ||
isDisabled: PropTypes.bool, | ||
/** Flag to show if the DataList checkbox is checked */ | ||
isChecked: PropTypes.bool, | ||
/** A callback for when the DataList checkbox selection changes */ | ||
onChange: PropTypes.func, | ||
/** Aria-labelledby of the DataList checkbox */ | ||
'aria-labelledby': PropTypes.string.isRequired | ||
}; | ||
|
||
DataListCheck.defaultProps = { | ||
className: '', | ||
isValid: true, | ||
isDisabled: false, | ||
isChecked: null, | ||
onChange: () => undefined | ||
}; | ||
|
||
export default DataListCheck; |
11 changes: 11 additions & 0 deletions
11
packages/patternfly-4/react-core/src/components/DataList/DataListContent.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { SFC, HTMLProps } from 'react'; | ||
import { Omit } from '../../typeUtils'; | ||
|
||
export interface DataListContentProps extends Omit<HTMLProps<HTMLElement>, 'aria-label'> { | ||
isHidden: boolean; | ||
'aria-label': string; | ||
} | ||
|
||
declare const DataListContent: SFC<DataListContentProps>; | ||
|
||
export default DataListContent; |
33 changes: 33 additions & 0 deletions
33
packages/patternfly-4/react-core/src/components/DataList/DataListContent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { css } from '@patternfly/react-styles'; | ||
import styles from '@patternfly/patternfly-next/components/DataList/styles.css'; | ||
|
||
const DataListContent = ({ className, children, isHidden, 'aria-label': ariaLabel, ...props }) => ( | ||
<section | ||
className={css(styles.dataListExpandableContent, className)} | ||
hidden={isHidden} | ||
aria-label={ariaLabel} | ||
{...props} | ||
> | ||
{children} | ||
</section> | ||
); | ||
|
||
DataListContent.propTypes = { | ||
/** Content rendered inside the DataList item */ | ||
children: PropTypes.node, | ||
/** Additional classes added to the DataList cell */ | ||
className: PropTypes.string, | ||
/** Flag to show if the expanded content of the DataList item is visible */ | ||
isHidden: PropTypes.bool, | ||
/** Adds accessible text to the DataList toggle */ | ||
'aria-label': PropTypes.string.isRequired | ||
}; | ||
|
||
DataListContent.defaultProps = { | ||
className: '', | ||
isHidden: false | ||
}; | ||
|
||
export default DataListContent; |
11 changes: 11 additions & 0 deletions
11
packages/patternfly-4/react-core/src/components/DataList/DataListItem.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { SFC, HTMLProps } from 'react'; | ||
import { Omit } from '../../typeUtils'; | ||
|
||
export interface DataListItemProps extends Omit<HTMLProps<HTMLLIElement>, 'aria-label'> { | ||
isExpanded: boolean; | ||
'aria-labelledby': string; | ||
} | ||
|
||
declare const DataListItem: SFC<DataListItemProps>; | ||
|
||
export default DataListItem; |
Oops, something went wrong.