-
Notifications
You must be signed in to change notification settings - Fork 392
feat(datalist): add hidden and visible breakpoints #2251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ import { | |
| DataListCell, | ||
| DataListCheck, | ||
| DataListAction, | ||
| DataListActionVisibility, | ||
| DataListToggle, | ||
| DataListContent, | ||
| Dropdown, | ||
|
|
@@ -24,6 +25,7 @@ import { | |
| DropdownItem | ||
| } from '@patternfly/react-core'; | ||
| import { CodeBranchIcon } from '@patternfly/react-icons'; | ||
| import { css } from '@patternfly/react-styles'; | ||
|
|
||
| ```js | ||
| import React from 'react'; | ||
|
|
@@ -97,15 +99,35 @@ import { | |
| class CheckboxActionDataList extends React.Component { | ||
| constructor(props) { | ||
| super(props); | ||
| this.state = { isOpen: false }; | ||
| this.state = { isOpen1: false, isOpen2: false, isOpen3: false }; | ||
|
|
||
| this.onToggle = isOpen => { | ||
| this.setState({ isOpen }); | ||
| this.onToggle1 = isOpen1 => { | ||
| this.setState({ isOpen1 }); | ||
| }; | ||
|
|
||
| this.onSelect = event => { | ||
| this.onSelect1 = event => { | ||
| this.setState(prevState => ({ | ||
| isOpen: !prevState.isOpen | ||
| isOpen1: !prevState.isOpen1 | ||
| })); | ||
| }; | ||
|
|
||
| this.onToggle2 = isOpen2 => { | ||
| this.setState({ isOpen2 }); | ||
| }; | ||
|
|
||
| this.onSelect2 = event => { | ||
| this.setState(prevState => ({ | ||
| isOpen2: !prevState.isOpen2 | ||
| })); | ||
| }; | ||
|
|
||
| this.onToggle3 = isOpen3 => { | ||
| this.setState({ isOpen3 }); | ||
| }; | ||
|
|
||
| this.onSelect3 = event => { | ||
| this.setState(prevState => ({ | ||
| isOpen3: !prevState.isOpen3 | ||
| })); | ||
| }; | ||
| } | ||
|
|
@@ -144,9 +166,9 @@ class CheckboxActionDataList extends React.Component { | |
| <Dropdown | ||
| isPlain | ||
| position={DropdownPosition.right} | ||
| isOpen={this.state.isOpen} | ||
| onSelect={this.onSelect} | ||
| toggle={<KebabToggle onToggle={this.onToggle} />} | ||
| isOpen={this.state.isOpen1} | ||
| onSelect={this.onSelect1} | ||
| toggle={<KebabToggle onToggle={this.onToggle1} />} | ||
| dropdownItems={[ | ||
| <DropdownItem key="link">Link</DropdownItem>, | ||
| <DropdownItem key="action" component="button"> | ||
|
|
@@ -175,6 +197,25 @@ class CheckboxActionDataList extends React.Component { | |
| ]} | ||
| /> | ||
| <DataListAction | ||
| className={css(DataListActionVisibility.hiddenOnLg)} | ||
| aria-labelledby="check-action-item2 check-action-action2" | ||
| id="check-action-action2" | ||
| aria-label="Actions" | ||
| > | ||
| <Dropdown | ||
| isPlain | ||
| position={DropdownPosition.right} | ||
| isOpen={this.state.isOpen2} | ||
| onSelect={this.onSelect2} | ||
| toggle={<KebabToggle onToggle={this.onToggle2} />} | ||
| dropdownItems={[ | ||
| <DropdownItem key="pri-action2" component="button">Primary</DropdownItem>, | ||
| <DropdownItem key="sec-action2" component="button">Secondary</DropdownItem>, | ||
| ]} | ||
| /> | ||
| </DataListAction> | ||
| <DataListAction | ||
| className={css(DataListActionVisibility.visibleOnLg, DataListActionVisibility.hidden)} | ||
| aria-labelledby="check-action-item2 check-action-action2" | ||
| id="check-action-action2" | ||
| aria-label="Actions" | ||
|
|
@@ -184,6 +225,53 @@ class CheckboxActionDataList extends React.Component { | |
| </DataListAction> | ||
| </DataListItemRow> | ||
| </DataListItem> | ||
| <DataListItem aria-labelledby="check-action-item3"> | ||
| <DataListItemRow> | ||
| <DataListCheck aria-labelledby="check-action-item3" name="check-action-check3" /> | ||
| <DataListItemCells | ||
| dataListCells={[ | ||
| <DataListCell key="primary content"> | ||
| <span id="check-action-item3">Primary content - Lorem ipsum</span> dolor sit amet, consectetur | ||
| adipisicing elit, sed do eiusmod. | ||
| </DataListCell>, | ||
| <DataListCell key="secondary content"> | ||
| Secondary content. Dolor sit amet, consectetur adipisicing elit, sed do eiusmod. | ||
| </DataListCell> | ||
| ]} | ||
| /> | ||
| <DataListAction | ||
| className={css(DataListActionVisibility.hiddenOnXl)} | ||
| aria-labelledby="check-action-item3 check-action-action3" | ||
| id="check-action-action3" | ||
| aria-label="Actions" | ||
| > | ||
| <Dropdown | ||
| isPlain | ||
| position={DropdownPosition.right} | ||
| isOpen={this.state.isOpen3} | ||
| onSelect={this.onSelect3} | ||
| toggle={<KebabToggle onToggle={this.onToggle3} />} | ||
| dropdownItems={[ | ||
| <DropdownItem key="pri-action3" component="button">Primary</DropdownItem>, | ||
| <DropdownItem key="sec1-action3" component="button">Secondary</DropdownItem>, | ||
| <DropdownItem key="sec2-action3" component="button">Secondary</DropdownItem>, | ||
| <DropdownItem key="sec3-action3" component="button">Secondary</DropdownItem>, | ||
| ]} | ||
| /> | ||
| </DataListAction> | ||
| <DataListAction | ||
| className={css(DataListActionVisibility.visibleOnXl, DataListActionVisibility.hidden)} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The buttons are still visible when i reduce the screen width
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. I will be looking into it. 😄
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep, I found the problem!
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am just adding unit tests. |
||
| aria-labelledby="check-action-item3 check-action-action3" | ||
| id="check-action-action3" | ||
| aria-label="Actions" | ||
| > | ||
| <Button variant="primary">Primary</Button> | ||
| <Button variant="secondary">Secondary</Button> | ||
| <Button variant="secondary">Secondary</Button> | ||
| <Button variant="secondary">Secondary</Button> | ||
| </DataListAction> | ||
| </DataListItemRow> | ||
| </DataListItem> | ||
| </DataList> | ||
| ); | ||
| } | ||
|
|
@@ -566,7 +654,7 @@ import { | |
| class ModifiersDataList extends React.Component { | ||
| constructor(props) { | ||
| super(props); | ||
| this.state = { show: true, isOpen1: false, isOpen2: false }; | ||
| this.state = { show: true, isOpen1: false, isOpen2: false, isOpen3: false }; | ||
|
|
||
| this.onToggle1 = isOpen1 => { | ||
| this.setState({ isOpen1 }); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,26 @@ | ||
| import * as React from 'react'; | ||
| import { css } from '@patternfly/react-styles'; | ||
| import { css, pickProperties } from '@patternfly/react-styles'; | ||
| import styles from '@patternfly/react-styles/css/components/DataList/data-list'; | ||
| import { Omit } from '../../helpers/typeUtils'; | ||
|
|
||
| const visibilityModifiers = pickProperties(styles.modifiers, [ | ||
| 'hidden', | ||
| 'hiddenOnSm', | ||
| 'hiddenOnMd', | ||
| 'hiddenOnLg', | ||
| 'hiddenOnXl', | ||
| 'hiddenOn_2xl', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Workaround looks good. Thanks as always @boaz0 ! 👍 |
||
| 'visibleOnSm', | ||
| 'visibleOnMd', | ||
| 'visibleOnLg', | ||
| 'visibleOnXl', | ||
| 'visibleOn_2xl' | ||
| ]); | ||
|
|
||
| export const DataListActionVisibility = Object.keys(visibilityModifiers) | ||
| .map(key => [key.replace('_2xl', '2Xl'), visibilityModifiers[key]]) | ||
| .reduce((acc, curr) => ({ ...acc, [curr[0]]: curr[1] }), {}); | ||
|
|
||
| export interface DataListActionProps extends Omit<React.HTMLProps<HTMLDivElement>, 'children'> { | ||
| /** Content rendered as DataList Action (e.g <Button> or <Dropdown>) */ | ||
| children: React.ReactNode; | ||
|
|
@@ -22,8 +40,8 @@ interface DataListActionState { | |
|
|
||
| export class DataListAction extends React.Component<DataListActionProps, DataListActionState> { | ||
| static defaultProps = { | ||
| className: '', | ||
| } | ||
| className: '' | ||
| }; | ||
|
|
||
| constructor(props: DataListActionProps) { | ||
| super(props); | ||
|
|
@@ -53,10 +71,8 @@ export class DataListAction extends React.Component<DataListActionProps, DataLis | |
| } = this.props; | ||
|
|
||
| return ( | ||
| <div className={css(styles.dataListItemAction, className)}> | ||
| <div className={css(styles.dataListAction, className)} {...props}> | ||
| {children} | ||
| </div> | ||
| <div className={css(styles.dataListItemAction, className)} {...props}> | ||
| {children} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.