From 71e2477afef80f0776ea6248f6dfdf2c289bfdee Mon Sep 17 00:00:00 2001 From: Boaz Shuster Date: Thu, 13 Jun 2019 00:17:51 +0300 Subject: [PATCH] feat(datalist): add hidden and visible breakpoints Signed-off-by: Boaz Shuster --- .../src/components/DataList/DataList.md | 106 ++++++++++++++-- .../src/components/DataList/DataList.test.js | 32 ++++- .../components/DataList/DataListAction.tsx | 30 +++-- .../__snapshots__/DataList.test.js.snap | 114 ++++++++---------- .../patternfly-4/react-styles/src/index.d.ts | 3 +- .../patternfly-4/react-styles/src/index.js | 9 +- .../patternfly-4/react-styles/src/utils.js | 4 + .../Table/utils/decorators/classNames.js | 5 +- 8 files changed, 219 insertions(+), 84 deletions(-) diff --git a/packages/patternfly-4/react-core/src/components/DataList/DataList.md b/packages/patternfly-4/react-core/src/components/DataList/DataList.md index 22f0f10ed3b..ea590e50249 100644 --- a/packages/patternfly-4/react-core/src/components/DataList/DataList.md +++ b/packages/patternfly-4/react-core/src/components/DataList/DataList.md @@ -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 { } + isOpen={this.state.isOpen1} + onSelect={this.onSelect1} + toggle={} dropdownItems={[ Link, @@ -175,6 +197,25 @@ class CheckboxActionDataList extends React.Component { ]} /> + } + dropdownItems={[ + Primary, + Secondary, + ]} + /> + + + + + + + Primary content - Lorem ipsum dolor sit amet, consectetur + adipisicing elit, sed do eiusmod. + , + + Secondary content. Dolor sit amet, consectetur adipisicing elit, sed do eiusmod. + + ]} + /> + + } + dropdownItems={[ + Primary, + Secondary, + Secondary, + Secondary, + ]} + /> + + + + + + + + + ); } @@ -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 }); diff --git a/packages/patternfly-4/react-core/src/components/DataList/DataList.test.js b/packages/patternfly-4/react-core/src/components/DataList/DataList.test.js index 8f597d089a1..f47fb5e074b 100644 --- a/packages/patternfly-4/react-core/src/components/DataList/DataList.test.js +++ b/packages/patternfly-4/react-core/src/components/DataList/DataList.test.js @@ -2,13 +2,14 @@ import React from 'react'; import { shallow } from 'enzyme'; import { DataList } from './DataList'; import { DataListItem } from './DataListItem'; -import { DataListAction } from './DataListAction'; +import { DataListAction, DataListActionVisibility } from './DataListAction'; import { DataListCell } from './DataListCell'; import { DataListToggle } from './DataListToggle'; import { DataListItemCells } from './DataListItemCells'; import { DataListItemRow } from './DataListItemRow'; import { DataListContent } from './DataListContent'; import { Button } from '../Button'; +import { css } from '@patternfly/react-styles'; import { DropdownItem, Dropdown, KebabToggle, DropdownPosition } from '../Dropdown'; describe('DataList', () => { @@ -141,6 +142,35 @@ describe('DataList', () => { expect(view).toMatchSnapshot(); }); + test('DataListAction visibility - show button when lg', () => { + const view = shallow( + + + + ); + expect(view.find('div').props().className).toContain('pf-m-hidden'); + expect(view.find('div').props().className).toContain('pf-m-visible-on-lg'); + }); + + test('DataListAction visibility - hide button on 2xl', () => { + const view = shallow( + + + + ); + expect(view.find('div').props().className).toContain('pf-m-hidden-on-2xl'); + }); + test('DataListContent', () => { const view = shallow( test); expect(view).toMatchSnapshot(); diff --git a/packages/patternfly-4/react-core/src/components/DataList/DataListAction.tsx b/packages/patternfly-4/react-core/src/components/DataList/DataListAction.tsx index 59796c2e511..3e744ef04f0 100644 --- a/packages/patternfly-4/react-core/src/components/DataList/DataListAction.tsx +++ b/packages/patternfly-4/react-core/src/components/DataList/DataListAction.tsx @@ -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', + '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, 'children'> { /** Content rendered as DataList Action (e.g