diff --git a/packages/react-core/src/components/DataList/examples/DataList.md b/packages/react-core/src/components/DataList/examples/DataList.md index b3436b2b9a0..1850dc6544f 100644 --- a/packages/react-core/src/components/DataList/examples/DataList.md +++ b/packages/react-core/src/components/DataList/examples/DataList.md @@ -27,1101 +27,42 @@ import { css } from '@patternfly/react-styles'; ### Basic -```js -import React from 'react'; -import { - Button, - DataList, - DataListItem, - DataListItemRow, - DataListItemCells, - DataListCell, - DataListCheck, - DataListAction, - DataListToggle, - DataListContent, - Dropdown, - KebabToggle, - DropdownItem -} from '@patternfly/react-core'; - - - - - - Primary content - , - Secondary content - ]} - /> - - - - - - Secondary content (pf-m-no-fill) - , - - Secondary content (pf-m-align-right pf-m-no-fill) - - ]} - /> - - - +```ts file="./DataListBasic.tsx" ``` ### Compact -```js -import React from 'react'; -import { - Button, - DataList, - DataListItem, - DataListItemRow, - DataListItemCells, - DataListCell, - DataListCheck, - DataListAction, - DataListToggle, - DataListContent, - Dropdown, - KebabToggle, - DropdownItem -} from '@patternfly/react-core'; - - - - - - Primary content - , - Secondary content - ]} - /> - - - - - - Secondary content (pf-m-no-fill) - , - - Secondary content (pf-m-align-right pf-m-no-fill) - - ]} - /> - - - +```ts file="./DataListCompact.tsx" ``` ### Checkboxes, actions and additional cells -```js -import React from 'react'; -import { - Button, - DataList, - DataListActionModifiers, - DataListItem, - DataListItemCells, - DataListItemRow, - DataListCell, - DataListCheck, - DataListAction, - Dropdown, - DropdownItem, - DropdownPosition, - KebabToggle -} from '@patternfly/react-core'; - -class CheckboxActionDataList extends React.Component { - constructor(props) { - super(props); - this.state = { isOpen1: false, isOpen2: false, isOpen3: false }; - - this.onToggle1 = isOpen1 => { - this.setState({ isOpen1 }); - }; - - this.onSelect1 = event => { - this.setState(prevState => ({ - 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 - })); - }; - } - - render() { - return ( - - - - - - Primary content Dolor sit amet, consectetur adipisicing elit, sed - do eiusmod. - , - - Secondary content. Dolor sit amet, consectetur adipisicing elit, sed do eiusmod. - , - - Tertiary content Dolor sit amet, consectetur adipisicing elit, sed do eiusmod. - , - - More content Dolor sit amet, consectetur adipisicing elit, sed do eiusmod. - , - - More content Dolor sit amet, consectetur adipisicing elit, sed do eiusmod. - - ]} - /> - - } - dropdownItems={[ - Link, - - Action - , - - Disabled Link - - ]} - /> - - - - - - - - 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 - - ]} - /> - - - - - - - - - - - - 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 - - ]} - /> - - - - - - - - - - - ); - } -} +```ts file="./DataListCheckboxes.tsx" ``` ### Actions: single and multiple -```js -import React from 'react'; -import { - Button, - Dropdown, - DropdownItem, - DropdownPosition, - KebabToggle, - DataList, - DataListItem, - DataListCell, - DataListItemRow, - DataListCheck, - DataListItemCells, - DataListAction -} from '@patternfly/react-core'; - -class ActionsDataList extends React.Component { - constructor(props) { - super(props); - this.state = { isOpen: false, isDeleted: false }; - - this.onToggle = isOpen => { - this.setState({ isOpen }); - }; - - this.onSelect = event => { - this.setState(prevState => ({ - isOpen: !prevState.isOpen - })); - }; - } - - render() { - return ( - - - {!this.state.isDeleted && ( - - - - Single actionable Primary content - , - Single actionable Secondary content - ]} - /> - - - - - - )} - - - - Multi actions Primary content - , - Multi actions Secondary content - ]} - /> - - } - dropdownItems={[ - Link, - - Action - , - - Disabled Link - - ]} - /> - - - - - - ); - } -} +```ts file="./DataListActions.tsx" ``` ### Expandable -```js -import React from 'react'; -import { - Button, - DataList, - DataListItem, - DataListItemRow, - DataListCell, - DataListCheck, - DataListAction, - DataListToggle, - DataListContent, - DataListItemCells, - Dropdown, - DropdownItem, - DropdownPosition, - KebabToggle -} from '@patternfly/react-core'; -import CodeBranchIcon from '@patternfly/react-icons/dist/esm/icons/code-branch-icon'; -import AngleDownIcon from '@patternfly/react-icons/dist/esm/icons/angle-down-icon'; -import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon'; - -class ExpandableDataList extends React.Component { - constructor(props) { - super(props); - this.state = { - expanded: ['ex-toggle1', 'ex-toggle3'], - isOpen1: false, - isOpen2: false, - isOpen3: false, - allExpanded: false - }; - - this.onToggleAll = () => { - this.setState( - { - allExpanded: !this.state.allExpanded - }, - () => { - if (this.state.allExpanded) { - this.setState({ - expanded: ['ex-toggle1', 'ex-toggle2', 'ex-toggle3'] - }); - } else { - this.setState({ - expanded: [] - }); - } - } - ); - }; - - this.onToggle1 = isOpen1 => { - this.setState({ isOpen1 }); - }; - - this.onToggle2 = isOpen2 => { - this.setState({ isOpen2 }); - }; - - this.onToggle3 = isOpen3 => { - this.setState({ isOpen3 }); - }; - - this.onSelect1 = event => { - this.setState(prevState => ({ - isOpen1: !prevState.isOpen1 - })); - }; - - this.onSelect2 = event => { - this.setState(prevState => ({ - isOpen2: !prevState.isOpen2 - })); - }; - - this.onSelect3 = event => { - this.setState(prevState => ({ - isOpen3: !prevState.isOpen3 - })); - }; - } - - render() { - const toggle = id => { - const expanded = this.state.expanded; - const index = expanded.indexOf(id); - const newExpanded = - index >= 0 ? [...expanded.slice(0, index), ...expanded.slice(index + 1, expanded.length)] : [...expanded, id]; - this.setState(() => ({ expanded: newExpanded })); - }; - return ( - - -
-
- - - - toggle('ex-toggle1')} - isExpanded={this.state.expanded.includes('ex-toggle1')} - id="ex-toggle1" - aria-controls="ex-expand1" - /> - - - , - -
Primary content
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. - link -
, - - Lorem ipsum dolor sit amet, consectetur adipiscing elit. - , - - Lorem ipsum dolor sit amet, consectetur adipiscing elit. - - ]} - /> - - } - dropdownItems={[ - Link, - - Action - , - - Disabled Link - - ]} - /> - -
- -

- Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et - dolore magna aliqua. -

-
-
- - - toggle('ex-toggle2')} - isExpanded={this.state.expanded.includes('ex-toggle2')} - id="ex-toggle2" - aria-controls="ex-expand2" - /> - - - , - -
Secondary content
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. -
, - - Lorem ipsum dolor sit amet. - , - - Lorem ipsum dolor sit amet, consectetur adipiscing elit. - - ]} - /> - - } - dropdownItems={[ - Link, - - Action - , - - Disabled Link - - ]} - /> - -
- -

- Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et - dolore magna aliqua. -

-
-
- - - toggle('ex-toggle3')} - isExpanded={this.state.expanded.includes('ex-toggle3')} - id="ex-toggle3" - aria-controls="ex-expand3" - /> - - - , - -
Tertiary content
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. -
, - - Lorem ipsum dolor sit amet. - , - - Lorem ipsum dolor sit amet, consectetur adipiscing elit. - - ]} - /> - - } - dropdownItems={[ - Link, - - Action - , - - Disabled Link - - ]} - /> - -
- - This expanded section has no padding. - -
-
-
- ); - } -} +```ts file="./DataListExpandable.tsx" ``` ### Width modifiers -```js -import React from 'react'; -import { - Button, - DataList, - DataListItem, - DataListCell, - DataListCheck, - DataListAction, - DataListToggle, - DataListContent, - DataListItemCells, - DataListItemRow, - Dropdown, - DropdownItem, - KebabToggle -} from '@patternfly/react-core'; - -class ModifiersDataList extends React.Component { - constructor(props) { - super(props); - this.state = { show: true, isOpen1: false, isOpen2: false, isOpen3: false }; - - this.onToggle1 = isOpen1 => { - this.setState({ isOpen1 }); - }; - - this.onToggle2 = isOpen2 => { - this.setState({ isOpen2 }); - }; - - this.onSelect1 = event => { - this.setState(prevState => ({ - isOpen1: !prevState.isOpen1 - })); - }; - - this.onSelect2 = event => { - this.setState(prevState => ({ - isOpen2: !prevState.isOpen2 - })); - }; - } - - render() { - const previewPlaceholder = { - display: 'block', - width: '100%', - padding: '.25rem .5rem', - color: '#004e8a', - backgroundColor: '#def3ff', - border: '1px solid rgba(0,0,0,.1)', - borderRadius: '4px' - }; - - return [ -
-

Default fitting - example 1

- - - - - -
- default -

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

-
- , - -
- default -

- Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut - labore et dolore magna aliqua. -

-
-
- ]} - /> -
-
-
-
, -
-

Flex modifiers - example 2

- - - - - -
- width 2 -

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.

-
- , - -
- width 4 -

Lorem ipsum dolor sit amet.

-
-
- ]} - /> - - } - dropdownItems={[ - Link, - - Action - , - - Disabled Link - - ]} - /> - -
-
-
-
, -
-

Flex modifiers - example 3

- - - - this.setState({ show: !this.state.show })} - /> - - -
- width 5 -

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

-
- , - -
- width 2 -

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

-
-
, - -
default
-
- ]} - /> - - } - dropdownItems={[ - Link, - - Action - , - - Disabled Link - - ]} - /> - -
- -

- Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et - dolore magna aliqua. -

-
-
-
-
- ]; - } -} +```ts file="./DataListWidthModifiers.tsx" ``` ### Selectable rows -```js -import React from 'react'; -import { - Button, - Dropdown, - DropdownItem, - DropdownPosition, - KebabToggle, - DataList, - DataListItem, - DataListCell, - DataListItemRow, - DataListCheck, - DataListItemCells, - DataListAction -} from '@patternfly/react-core'; - -class SelectableDataList extends React.Component { - constructor(props) { - super(props); - this.state = { - isOpen1: false, - isOpen2: false, - selectedDataListItemId: '' - }; - - this.onToggle1 = isOpen1 => { - this.setState({ isOpen1 }); - }; - - this.onToggle2 = isOpen2 => { - this.setState({ isOpen2 }); - }; - - this.onSelect1 = event => { - this.setState(prevState => ({ - isOpen1: !prevState.isOpen1 - })); - }; - - this.onSelect2 = event => { - this.setState(prevState => ({ - isOpen2: !prevState.isOpen2 - })); - }; - - this.onSelectDataListItem = id => { - this.setState({ selectedDataListItemId: id }); - }; - } - - render() { - return ( - - - {!this.state.isDeleted && ( - - - - Single actionable Primary content - , - Single actionable Secondary content - ]} - /> - - } - dropdownItems={[ - Link, - - Action - , - - Disabled Link - - ]} - /> - - - - )} - - - - Selectable actions Primary content - , - Selectable actions Secondary content - ]} - /> - - } - dropdownItems={[ - Link, - - Action - , - - Disabled Link - - ]} - /> - - - - - - ); - } -} +```ts file="./DataListSelectableRows.tsx" ``` ### Controlling text -```js -import React from 'react'; -import { - Button, - DataList, - DataListItem, - DataListItemRow, - DataListItemCells, - DataListCell, - DataListCheck, - DataListAction, - DataListWrapModifier -} from '@patternfly/react-core'; - - - - - - Primary content - , - - Really really really really really really really really really really really really really really long - description that should be truncated before it ends - - ]} - /> - - - +```ts file="./DataListControllingText.tsx" ``` ### Draggable @@ -1129,135 +70,11 @@ import { Draggable data lists used to have their own HTML5-based API for drag and drop, which wasn't able to fulfill requirements such as custom styling on items being dragged. So we wrote generic `DragDrop`, `Draggable`, and `Droppable` components for this purpose. Use those new components instead of the deprecated (and buggy!) HTML5-based API. Note: Keyboard accessibility and screen reader accessibility for the `DragDrop` component are still in development. -```js isBeta -import React from 'react'; -import { - DataList, - DataListItem, - DataListCell, - DataListItemRow, - DataListCheck, - DataListControl, - DataListDragButton, - DataListItemCells, - DragDrop, - Draggable, - Droppable -} from '@patternfly/react-core'; - -const getItems = count => - Array.from({ length: count }, (v, k) => k).map(k => ({ - id: `item-${k}`, - content: `item ${k} `.repeat(k === 4 ? 20 : 1) - })); - -const reorder = (list, startIndex, endIndex) => { - const result = Array.from(list); - const [removed] = result.splice(startIndex, 1); - result.splice(endIndex, 0, removed); - return result; -}; -DraggableDataList = () => { - const [items, setItems] = React.useState(getItems(10)); - const [liveText, setLiveText] = React.useState(''); - - function onDrag(source) { - setLiveText(`Started dragging ${items[source.index].content}`); - // Return true to allow drag - return true; - } - - function onDragMove(source, dest) { - const newText = dest - ? `Move ${items[source.index].content} to ${items[dest.index].content}` - : 'Invalid drop zone'; - if (newText !== liveText) { - setLiveText(newText); - } - } - - function onDrop(source, dest) { - if (dest) { - const newItems = reorder( - items, - source.index, - dest.index - ); - setItems(newItems); - - setLiveText('Dragging finished.'); - return true; // Signal that this is a valid drop and not to animate the item returning home. - } else { - setLiveText('Dragging cancelled. List unchanged.'); - } - } - - return ( - - - - {items.map(({id, content}) => - - - - - - - - - {content} - - ]} - /> - - - - )} - - -
- {liveText} -
-
- ); -}; +```ts isBeta file="./DataListDraggable.tsx" ``` ### Small grid breakpoint -```js -import React from 'react'; -import { - DataList, - DataListItem, - DataListItemRow, - DataListItemCells, - DataListCell -} from '@patternfly/react-core'; - - - - - - Primary content - , - - Really really really really really really really really really really really really really really long - description that should be truncated before it ends - - ]} - /> - - - +```ts file="./DataListSmGridBreakpoint.tsx" ``` diff --git a/packages/react-core/src/components/DataList/examples/DataListActions.tsx b/packages/react-core/src/components/DataList/examples/DataListActions.tsx new file mode 100644 index 00000000000..25a538bf699 --- /dev/null +++ b/packages/react-core/src/components/DataList/examples/DataListActions.tsx @@ -0,0 +1,100 @@ +import React from 'react'; +import { + Button, + Dropdown, + DropdownItem, + DropdownPosition, + KebabToggle, + DataList, + DataListItem, + DataListCell, + DataListItemRow, + DataListItemCells, + DataListAction +} from '@patternfly/react-core'; + +export const DataListActions: React.FunctionComponent = () => { + const [isOpen, setIsOpen] = React.useState(false); + const [isDeleted, setIsDeleted] = React.useState(false); + + const onToggle = isOpen => { + setIsOpen(isOpen); + }; + + const onSelect = () => { + setIsOpen(!isOpen); + }; + + return ( + + + {!isDeleted && ( + + + + Single actionable Primary content + , + Single actionable Secondary content + ]} + /> + + + + + + )} + + + + Multi actions Primary content + , + Multi actions Secondary content + ]} + /> + + } + dropdownItems={[ + Link, + + Action + , + + Disabled Link + + ]} + /> + + + + + + ); +}; diff --git a/packages/react-core/src/components/DataList/examples/DataListBasic.tsx b/packages/react-core/src/components/DataList/examples/DataListBasic.tsx new file mode 100644 index 00000000000..984511aa480 --- /dev/null +++ b/packages/react-core/src/components/DataList/examples/DataListBasic.tsx @@ -0,0 +1,33 @@ +import React from 'react'; +import { DataList, DataListItem, DataListItemRow, DataListItemCells, DataListCell } from '@patternfly/react-core'; + +export const DataListBasic: React.FunctionComponent = () => ( + + + + + Primary content + , + Secondary content + ]} + /> + + + + + + Secondary content (pf-m-no-fill) + , + + Secondary content (pf-m-align-right pf-m-no-fill) + + ]} + /> + + + +); diff --git a/packages/react-core/src/components/DataList/examples/DataListCheckboxes.tsx b/packages/react-core/src/components/DataList/examples/DataListCheckboxes.tsx new file mode 100644 index 00000000000..49c00675ef2 --- /dev/null +++ b/packages/react-core/src/components/DataList/examples/DataListCheckboxes.tsx @@ -0,0 +1,200 @@ +import React from 'react'; +import { + Button, + DataList, + DataListItem, + DataListItemCells, + DataListItemRow, + DataListCell, + DataListCheck, + DataListAction, + Dropdown, + DropdownItem, + DropdownPosition, + KebabToggle +} from '@patternfly/react-core'; + +export const DataListCheckboxes: React.FunctionComponent = () => { + const [isOpen1, setIsOpen1] = React.useState(false); + const [isOpen2, setIsOpen2] = React.useState(false); + const [isOpen3, setIsOpen3] = React.useState(false); + + const onToggle1 = isOpen1 => { + setIsOpen1(isOpen1); + }; + + const onSelect1 = () => { + setIsOpen1(!isOpen1); + }; + + const onToggle2 = isOpen2 => { + setIsOpen2(isOpen2); + }; + + const onSelect2 = () => { + setIsOpen2(!isOpen2); + }; + const onToggle3 = isOpen3 => { + setIsOpen3(isOpen3); + }; + + const onSelect3 = () => { + setIsOpen3(!isOpen3); + }; + return ( + + + + + + Primary content Dolor sit amet, consectetur adipisicing elit, sed + do eiusmod. + , + + Secondary content. Dolor sit amet, consectetur adipisicing elit, sed do eiusmod. + , + + Tertiary content Dolor sit amet, consectetur adipisicing elit, sed do eiusmod. + , + + More content Dolor sit amet, consectetur adipisicing elit, sed do eiusmod. + , + + More content Dolor sit amet, consectetur adipisicing elit, sed do eiusmod. + + ]} + /> + + } + dropdownItems={[ + Link, + + Action + , + + Disabled Link + + ]} + /> + + + + + + + + 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 + + ]} + /> + + + + + + + + + + + + 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 + + ]} + /> + + + + + + + + + + + ); +}; diff --git a/packages/react-core/src/components/DataList/examples/DataListCompact.tsx b/packages/react-core/src/components/DataList/examples/DataListCompact.tsx new file mode 100644 index 00000000000..163bc971850 --- /dev/null +++ b/packages/react-core/src/components/DataList/examples/DataListCompact.tsx @@ -0,0 +1,33 @@ +import React from 'react'; +import { DataList, DataListItem, DataListItemRow, DataListItemCells, DataListCell } from '@patternfly/react-core'; + +export const DataListCompact: React.FunctionComponent = () => ( + + + + + Primary content + , + Secondary content + ]} + /> + + + + + + Secondary content (pf-m-no-fill) + , + + Secondary content (pf-m-align-right pf-m-no-fill) + + ]} + /> + + + +); diff --git a/packages/react-core/src/components/DataList/examples/DataListControllingText.tsx b/packages/react-core/src/components/DataList/examples/DataListControllingText.tsx new file mode 100644 index 00000000000..1ee814690f8 --- /dev/null +++ b/packages/react-core/src/components/DataList/examples/DataListControllingText.tsx @@ -0,0 +1,29 @@ +import React from 'react'; +import { + DataList, + DataListItem, + DataListItemRow, + DataListItemCells, + DataListCell, + DataListWrapModifier +} from '@patternfly/react-core'; + +export const DataListControllingText: React.FunctionComponent = () => ( + + + + + Primary content + , + + Really really really really really really really really really really really really really really long + description that should be truncated before it ends + + ]} + /> + + + +); diff --git a/packages/react-core/src/components/DataList/examples/DataListDraggable.tsx b/packages/react-core/src/components/DataList/examples/DataListDraggable.tsx new file mode 100644 index 00000000000..4cd949200b9 --- /dev/null +++ b/packages/react-core/src/components/DataList/examples/DataListDraggable.tsx @@ -0,0 +1,98 @@ +import React from 'react'; +import { + DataList, + DataListItem, + DataListCell, + DataListItemRow, + DataListCheck, + DataListControl, + DataListDragButton, + DataListItemCells, + DragDrop, + Draggable, + Droppable +} from '@patternfly/react-core'; + +interface ItemType { + id: string; + content: string; +} + +const getItems = (count: number) => + Array.from({ length: count }, (_, idx) => idx).map(idx => ({ + id: `item-${idx}`, + content: `item ${idx} `.repeat(idx === 4 ? 20 : 1) + })); + +const reorder = (list: ItemType[], startIndex: number, endIndex: number) => { + const result = list; + const [removed] = result.splice(startIndex, 1); + result.splice(endIndex, 0, removed); + return result; +}; + +export const DataListDraggable: React.FunctionComponent = () => { + const [items, setItems] = React.useState(getItems(10)); + const [liveText, setLiveText] = React.useState(''); + + function onDrag(source) { + setLiveText(`Started dragging ${items[source.index].content}`); + // Return true to allow drag + return true; + } + + function onDragMove(source, dest) { + const newText = dest ? `Move ${items[source.index].content} to ${items[dest.index].content}` : 'Invalid drop zone'; + if (newText !== liveText) { + setLiveText(newText); + } + } + + function onDrop(source, dest) { + if (dest) { + const newItems = reorder(items, source.index, dest.index); + setItems(newItems); + + setLiveText('Dragging finished.'); + return true; // Signal that this is a valid drop and not to animate the item returning home. + } else { + setLiveText('Dragging cancelled. List unchanged.'); + } + } + + return ( + + + + {items.map(({ id, content }) => ( + + + + + + + + + {content} + + ]} + /> + + + + ))} + + +
+ {liveText} +
+
+ ); +}; diff --git a/packages/react-core/src/components/DataList/examples/DataListExpandable.tsx b/packages/react-core/src/components/DataList/examples/DataListExpandable.tsx new file mode 100644 index 00000000000..2502db5730c --- /dev/null +++ b/packages/react-core/src/components/DataList/examples/DataListExpandable.tsx @@ -0,0 +1,261 @@ +import React from 'react'; +import { + Button, + DataList, + DataListItem, + DataListItemRow, + DataListCell, + DataListAction, + DataListToggle, + DataListContent, + DataListItemCells, + Dropdown, + DropdownItem, + DropdownPosition, + KebabToggle +} from '@patternfly/react-core'; +import CodeBranchIcon from '@patternfly/react-icons/dist/esm/icons/code-branch-icon'; +import AngleDownIcon from '@patternfly/react-icons/dist/esm/icons/angle-down-icon'; +import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon'; + +export const DataListExpandable: React.FunctionComponent = () => { + const [isOpen1, setIsOpen1] = React.useState(false); + const [isOpen2, setIsOpen2] = React.useState(false); + const [isOpen3, setIsOpen3] = React.useState(false); + const [allExpanded, setAllExpanded] = React.useState(false); + const [expanded, setExpanded] = React.useState(['ex-toggle1', 'ex-toggle3']); + + const onToggleAll = () => { + setAllExpanded(!allExpanded); + }; + + React.useEffect(() => { + if (allExpanded) { + setExpanded(['ex-toggle1', 'ex-toggle2', 'ex-toggle3']); + } else { + setExpanded([]); + } + }, [allExpanded]); + + const onToggle1 = isOpen1 => { + setIsOpen1(isOpen1); + }; + + const onSelect1 = () => { + setIsOpen1(!isOpen1); + }; + + const onToggle2 = isOpen2 => { + setIsOpen2(isOpen2); + }; + + const onSelect2 = () => { + setIsOpen2(!isOpen2); + }; + const onToggle3 = isOpen3 => { + setIsOpen3(isOpen3); + }; + + const onSelect3 = () => { + setIsOpen3(!isOpen3); + }; + + const toggle = id => { + const index = expanded.indexOf(id); + const newExpanded = + index >= 0 ? [...expanded.slice(0, index), ...expanded.slice(index + 1, expanded.length)] : [...expanded, id]; + setExpanded(newExpanded); + }; + return ( + + +
+
+ + + + toggle('ex-toggle1')} + isExpanded={expanded.includes('ex-toggle1')} + id="ex-toggle1" + aria-controls="ex-expand1" + /> + + + , + +
Primary content
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. + link +
, + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + , + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + + ]} + /> + + } + dropdownItems={[ + Link, + + Action + , + + Disabled Link + + ]} + /> + +
+ +

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et + dolore magna aliqua. +

+
+
+ + + toggle('ex-toggle2')} + isExpanded={expanded.includes('ex-toggle2')} + id="ex-toggle2" + aria-controls="ex-expand2" + /> + + + , + +
Secondary content
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. +
, + + Lorem ipsum dolor sit amet. + , + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + + ]} + /> + + } + dropdownItems={[ + Link, + + Action + , + + Disabled Link + + ]} + /> + +
+ +

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et + dolore magna aliqua. +

+
+
+ + + toggle('ex-toggle3')} + isExpanded={expanded.includes('ex-toggle3')} + id="ex-toggle3" + aria-controls="ex-expand3" + /> + + + , + +
Tertiary content
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. +
, + + Lorem ipsum dolor sit amet. + , + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. + + ]} + /> + + } + dropdownItems={[ + Link, + + Action + , + + Disabled Link + + ]} + /> + +
+ + This expanded section has no padding. + +
+
+
+ ); +}; diff --git a/packages/react-core/src/components/DataList/examples/DataListSelectableRows.tsx b/packages/react-core/src/components/DataList/examples/DataListSelectableRows.tsx new file mode 100644 index 00000000000..b0267ae4d40 --- /dev/null +++ b/packages/react-core/src/components/DataList/examples/DataListSelectableRows.tsx @@ -0,0 +1,120 @@ +import React from 'react'; +import { + Dropdown, + DropdownItem, + DropdownPosition, + KebabToggle, + DataList, + DataListItem, + DataListCell, + DataListItemRow, + DataListItemCells, + DataListAction +} from '@patternfly/react-core'; + +export const DataListSelectableRows: React.FunctionComponent = () => { + const [isOpen1, setIsOpen1] = React.useState(false); + const [isOpen2, setIsOpen2] = React.useState(false); + const [selectedDataListItemId, setSelectedDataListItemId] = React.useState(''); + + const onToggle1 = isOpen1 => { + setIsOpen1(isOpen1); + }; + + const onSelect1 = () => { + setIsOpen1(!isOpen1); + }; + + const onToggle2 = isOpen2 => { + setIsOpen2(isOpen2); + }; + + const onSelect2 = () => { + setIsOpen2(!isOpen2); + }; + + const onSelectDataListItem = id => { + setSelectedDataListItemId(id); + }; + + return ( + + + + + + Single actionable Primary content + , + Single actionable Secondary content + ]} + /> + + } + dropdownItems={[ + Link, + + Action + , + + Disabled Link + + ]} + /> + + + + + + + Selectable actions Primary content + , + Selectable actions Secondary content + ]} + /> + + } + dropdownItems={[ + Link, + + Action + , + + Disabled Link + + ]} + /> + + + + + + ); +}; diff --git a/packages/react-core/src/components/DataList/examples/DataListSmGridBreakpoint.tsx b/packages/react-core/src/components/DataList/examples/DataListSmGridBreakpoint.tsx new file mode 100644 index 00000000000..e7f3c9a1acd --- /dev/null +++ b/packages/react-core/src/components/DataList/examples/DataListSmGridBreakpoint.tsx @@ -0,0 +1,22 @@ +import React from 'react'; +import { DataList, DataListItem, DataListItemRow, DataListItemCells, DataListCell } from '@patternfly/react-core'; + +export const DataListSmGridBreakpoint: React.FunctionComponent = () => ( + + + + + Primary content + , + + Really really really really really really really really really really really really really really long + description that should be truncated before it ends + + ]} + /> + + + +); diff --git a/packages/react-core/src/components/DataList/examples/DataListWidthModifiers.tsx b/packages/react-core/src/components/DataList/examples/DataListWidthModifiers.tsx new file mode 100644 index 00000000000..0ed40e31448 --- /dev/null +++ b/packages/react-core/src/components/DataList/examples/DataListWidthModifiers.tsx @@ -0,0 +1,204 @@ +import React from 'react'; +import { + DataList, + DataListItem, + DataListCell, + DataListCheck, + DataListAction, + DataListToggle, + DataListContent, + DataListItemCells, + DataListItemRow, + Dropdown, + DropdownItem, + KebabToggle, + DropdownPosition, + Text, + TextVariants, + TextContent +} from '@patternfly/react-core'; + +export const DataListWidthModifiers: React.FunctionComponent = () => { + const [show, setShow] = React.useState(true); + const [isOpen1, setIsOpen1] = React.useState(false); + const [isOpen2, setIsOpen2] = React.useState(false); + + const onToggle1 = isOpen1 => { + setIsOpen1(isOpen1); + }; + + const onSelect1 = () => { + setIsOpen1(!isOpen1); + }; + + const onToggle2 = isOpen2 => { + setIsOpen2(isOpen2); + }; + + const onSelect2 = () => { + setIsOpen2(!isOpen2); + }; + + const previewPlaceholder = { + display: 'block', + width: '100%', + padding: '.25rem .5rem', + color: '#004e8a', + backgroundColor: '#def3ff', + border: '1px solid rgba(0,0,0,.1)', + borderRadius: '4px' + }; + + return ( + <> +
+ + Default fitting - example 1 + + + + + + +
+ default +

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

+
+ , + +
+ default +

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut + labore et dolore magna aliqua. +

+
+
+ ]} + /> +
+
+
+
+
+ + Flex modifiers - example 2 + + + + + + +
+ width 2 +

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.

+
+ , + +
+ width 4 +

Lorem ipsum dolor sit amet.

+
+
+ ]} + /> + + } + dropdownItems={[ + Link, + + Action + , + + Disabled Link + + ]} + /> + +
+
+
+
+
+ + Flex modifiers - example 3 + + + + + setShow(!show)} + /> + + +
+ width 5 +

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

+
+ , + +
+ width 2 +

Lorem ipsum dolor sit amet, consectetur adipisicing elit.

+
+
, + +
default
+
+ ]} + /> + + } + dropdownItems={[ + Link, + + Action + , + + Disabled Link + + ]} + /> + +
+ +

+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et + dolore magna aliqua. +

+
+
+
+
+ + ); +};