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(pf4-list): introduce the pf4 simple list (patternfly#672)
affects: patternfly4-react-lerna-root, @patternfly/react-core
- Loading branch information
Showing
13 changed files
with
346 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
packages/patternfly-4/react-core/src/components/List/List.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,16 @@ | ||
import { SFC, HTMLProps, ReactNode } from 'react'; | ||
import { OneOf } from '../../typeUtils'; | ||
|
||
export const ListVariant: { | ||
grid: 'grid'; | ||
inline: 'inline'; | ||
}; | ||
|
||
export interface ListProps extends HTMLProps<HTMLUListElement> { | ||
children?: ReactNode; | ||
variant?: OneOf<typeof ListVariant, keyof typeof ListVariant>; | ||
} | ||
|
||
declare const List: SFC<ListProps>; | ||
|
||
export default List; |
13 changes: 13 additions & 0 deletions
13
packages/patternfly-4/react-core/src/components/List/List.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,13 @@ | ||
import { List, ListItem } from '@patternfly/react-core'; | ||
import Simple from './examples/SimpleList'; | ||
import Inline from './examples/InlineList'; | ||
import Grid from './examples/GridList'; | ||
|
||
export default { | ||
title: 'List', | ||
components: { | ||
List, | ||
ListItem | ||
}, | ||
examples: [Simple, Inline, Grid] | ||
}; |
35 changes: 35 additions & 0 deletions
35
packages/patternfly-4/react-core/src/components/List/List.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,35 @@ | ||
import React from 'react'; | ||
import styles from '@patternfly/patternfly-next/components/List/styles.css'; | ||
import { css, getModifier } from '@patternfly/react-styles'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export const ListVariant = { | ||
grid: 'grid', | ||
inline: 'inline' | ||
}; | ||
|
||
const propTypes = { | ||
/** Anything that can be rendered inside of the list */ | ||
children: PropTypes.node, | ||
/** Additional classes added to the list. */ | ||
className: PropTypes.string, | ||
/** Adds list variant styles */ | ||
variant: PropTypes.oneOf(Object.values(ListVariant)) | ||
}; | ||
|
||
const defaultProps = { | ||
children: null, | ||
className: '', | ||
variant: null | ||
}; | ||
|
||
const List = ({ className, children, variant, ...props }) => ( | ||
<ul {...props} className={css(styles.list, getModifier(styles.modifiers, variant), className)}> | ||
{children} | ||
</ul> | ||
); | ||
|
||
List.propTypes = propTypes; | ||
List.defaultProps = defaultProps; | ||
|
||
export default List; |
43 changes: 43 additions & 0 deletions
43
packages/patternfly-4/react-core/src/components/List/List.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,43 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import List from './List'; | ||
import ListItem from './ListItem'; | ||
|
||
const ListItems = () => ( | ||
<React.Fragment> | ||
<List> | ||
<ListItem>First</ListItem> | ||
<ListItem>Second</ListItem> | ||
<ListItem>Third</ListItem> | ||
</List> | ||
</React.Fragment> | ||
); | ||
|
||
describe('list', () => { | ||
test('simple list', () => { | ||
const view = mount( | ||
<List> | ||
<ListItems /> | ||
</List> | ||
); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('inline list', () => { | ||
const view = mount( | ||
<List variant="inline"> | ||
<ListItems /> | ||
</List> | ||
); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('grid list', () => { | ||
const view = mount( | ||
<List variant="grid"> | ||
<ListItems /> | ||
</List> | ||
); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/patternfly-4/react-core/src/components/List/ListItem.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, ReactNode } from 'react'; | ||
|
||
export interface ListItemProps extends HTMLProps<HTMLLIElement> { | ||
children?: ReactNode; | ||
} | ||
|
||
declare const ListItem: SFC<ListItemProps>; | ||
|
||
export default ListItem; |
18 changes: 18 additions & 0 deletions
18
packages/patternfly-4/react-core/src/components/List/ListItem.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,18 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const propTypes = { | ||
/** Anything that can be rendered inside of list item */ | ||
children: PropTypes.node | ||
}; | ||
|
||
const defaultProps = { | ||
children: null | ||
}; | ||
|
||
const ListItem = ({ children, ...props }) => <li {...props}>{children}</li>; | ||
|
||
ListItem.propTypes = propTypes; | ||
ListItem.defaultProps = defaultProps; | ||
|
||
export default ListItem; |
151 changes: 151 additions & 0 deletions
151
packages/patternfly-4/react-core/src/components/List/__snapshots__/List.test.js.snap
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,151 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`list grid list 1`] = ` | ||
.pf-c-list { | ||
display: block; | ||
padding-left: 1.5rem; | ||
margin: 1rem 0px 1rem 1.5rem; | ||
list-style: undefined; | ||
} | ||
.pf-c-list.pf-m-grid { | ||
display: grid; | ||
grid-template-columns: repeat(auto-fit,minmax(100px,1fr)); | ||
grid-gap: 1rem; | ||
} | ||
<List | ||
className="" | ||
variant="grid" | ||
> | ||
<ul | ||
className="pf-c-list pf-m-grid" | ||
> | ||
<ListItems> | ||
<List | ||
className="" | ||
variant={null} | ||
> | ||
<ul | ||
className="pf-c-list" | ||
> | ||
<ListItem> | ||
<li> | ||
First | ||
</li> | ||
</ListItem> | ||
<ListItem> | ||
<li> | ||
Second | ||
</li> | ||
</ListItem> | ||
<ListItem> | ||
<li> | ||
Third | ||
</li> | ||
</ListItem> | ||
</ul> | ||
</List> | ||
</ListItems> | ||
</ul> | ||
</List> | ||
`; | ||
|
||
exports[`list inline list 1`] = ` | ||
.pf-c-list { | ||
display: block; | ||
padding-left: 1.5rem; | ||
margin: 1rem 0px 1rem 1.5rem; | ||
list-style: undefined; | ||
} | ||
.pf-c-list.pf-m-inline { | ||
display: flex; | ||
flex-wrap: wrap; | ||
} | ||
<List | ||
className="" | ||
variant="inline" | ||
> | ||
<ul | ||
className="pf-c-list pf-m-inline" | ||
> | ||
<ListItems> | ||
<List | ||
className="" | ||
variant={null} | ||
> | ||
<ul | ||
className="pf-c-list" | ||
> | ||
<ListItem> | ||
<li> | ||
First | ||
</li> | ||
</ListItem> | ||
<ListItem> | ||
<li> | ||
Second | ||
</li> | ||
</ListItem> | ||
<ListItem> | ||
<li> | ||
Third | ||
</li> | ||
</ListItem> | ||
</ul> | ||
</List> | ||
</ListItems> | ||
</ul> | ||
</List> | ||
`; | ||
|
||
exports[`list simple list 1`] = ` | ||
.pf-c-list { | ||
display: block; | ||
padding-left: 1.5rem; | ||
margin: 1rem 0px 1rem 1.5rem; | ||
list-style: undefined; | ||
} | ||
.pf-c-list { | ||
display: block; | ||
padding-left: 1.5rem; | ||
margin: 1rem 0px 1rem 1.5rem; | ||
list-style: undefined; | ||
} | ||
<List | ||
className="" | ||
variant={null} | ||
> | ||
<ul | ||
className="pf-c-list" | ||
> | ||
<ListItems> | ||
<List | ||
className="" | ||
variant={null} | ||
> | ||
<ul | ||
className="pf-c-list" | ||
> | ||
<ListItem> | ||
<li> | ||
First | ||
</li> | ||
</ListItem> | ||
<ListItem> | ||
<li> | ||
Second | ||
</li> | ||
</ListItem> | ||
<ListItem> | ||
<li> | ||
Third | ||
</li> | ||
</ListItem> | ||
</ul> | ||
</List> | ||
</ListItems> | ||
</ul> | ||
</List> | ||
`; |
21 changes: 21 additions & 0 deletions
21
packages/patternfly-4/react-core/src/components/List/examples/GridList.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,21 @@ | ||
import React from 'react'; | ||
import { List, ListItem } from '@patternfly/react-core'; | ||
|
||
class GridList extends React.Component { | ||
static title = 'Grid List'; | ||
|
||
render() { | ||
return ( | ||
<List variant="grid"> | ||
<ListItem>First</ListItem> | ||
<ListItem>Second</ListItem> | ||
<ListItem>Third</ListItem> | ||
<ListItem>Fourth</ListItem> | ||
<ListItem>Fifth</ListItem> | ||
<ListItem>Sixth</ListItem> | ||
</List> | ||
); | ||
} | ||
} | ||
|
||
export default GridList; |
18 changes: 18 additions & 0 deletions
18
packages/patternfly-4/react-core/src/components/List/examples/InlineList.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,18 @@ | ||
import React from 'react'; | ||
import { List, ListItem } from '@patternfly/react-core'; | ||
|
||
class InlineList extends React.Component { | ||
static title = 'Inline List'; | ||
|
||
render() { | ||
return ( | ||
<List variant="inline"> | ||
<ListItem>First</ListItem> | ||
<ListItem>Second</ListItem> | ||
<ListItem>Third</ListItem> | ||
</List> | ||
); | ||
} | ||
} | ||
|
||
export default InlineList; |
18 changes: 18 additions & 0 deletions
18
packages/patternfly-4/react-core/src/components/List/examples/SimpleList.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,18 @@ | ||
import React from 'react'; | ||
import { List, ListItem } from '@patternfly/react-core'; | ||
|
||
class SimpleList extends React.Component { | ||
static title = 'Simple List'; | ||
|
||
render() { | ||
return ( | ||
<List> | ||
<ListItem>First</ListItem> | ||
<ListItem>Second</ListItem> | ||
<ListItem>Third</ListItem> | ||
</List> | ||
); | ||
} | ||
} | ||
|
||
export default SimpleList; |
2 changes: 2 additions & 0 deletions
2
packages/patternfly-4/react-core/src/components/List/index.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,2 @@ | ||
export { default as List } from './List'; | ||
export { default as ListItem } from './ListItem'; |
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
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