From ddc87a74d443cf8ac74617ca99a957ec3797d79f Mon Sep 17 00:00:00 2001 From: Jenny <32821331+jenny-s51@users.noreply.github.com> Date: Wed, 6 Dec 2023 09:35:44 -0500 Subject: [PATCH] chore(DataList): convert data list react demo to TS (#9818) * convert data list react demo to TS * update function component name to match file --- .../DataListExpandableControlInToolbar.tsx | 397 +++++++++++++++++ packages/react-core/src/demos/DataListDemo.md | 408 +----------------- 2 files changed, 398 insertions(+), 407 deletions(-) create mode 100644 packages/react-core/src/demos/DataList/examples/DataListExpandableControlInToolbar.tsx diff --git a/packages/react-core/src/demos/DataList/examples/DataListExpandableControlInToolbar.tsx b/packages/react-core/src/demos/DataList/examples/DataListExpandableControlInToolbar.tsx new file mode 100644 index 00000000000..07fd6063cb6 --- /dev/null +++ b/packages/react-core/src/demos/DataList/examples/DataListExpandableControlInToolbar.tsx @@ -0,0 +1,397 @@ +import React from 'react'; +import { + Button, + DataList, + DataListItem, + DataListItemRow, + DataListCell, + DataListAction, + DataListToggle, + DataListContent, + DataListItemCells, + Dropdown, + DropdownItem, + DropdownList, + MenuToggle, + MenuToggleElement, + Toolbar, + ToolbarGroup, + ToolbarItem, + ToolbarExpandIconWrapper, + ToolbarContent, + SearchInput, + Tooltip, + Icon, + PageSection, + PageSectionVariants, + Text, + TextContent +} from '@patternfly/react-core'; + +import { DashboardWrapper } from '@patternfly/react-core/src/demos/DashboardWrapper'; + +import CodeBranchIcon from '@patternfly/react-icons/dist/esm/icons/code-branch-icon'; +import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon'; +import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon'; + +export const DataListExpandableControlInToolbar: React.FunctionComponent = () => { + const [expanded, setExpanded] = React.useState(['ex-toggle1', 'ex-toggle3']); + 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 onToggleAll = () => { + setAllExpanded((prevAllExpanded) => !prevAllExpanded); + + if (!allExpanded) { + setExpanded(['ex-toggle1', 'ex-toggle2', 'ex-toggle3']); + } else { + setExpanded([]); + } + }; + + const onToggle1 = () => { + setIsOpen1(!isOpen1); + }; + + const onToggle2 = () => { + setIsOpen2(!isOpen2); + }; + + const onToggle3 = () => { + setIsOpen3(!isOpen3); + }; + + const onSelect1 = () => { + setIsOpen1(false); + }; + + const onSelect2 = () => { + setIsOpen2(false); + }; + + const onSelect3 = () => { + setIsOpen3(false); + }; + + const renderToolbar = () => ( + + + + + + + {allExpanded && 'Collapse all rows'} + {!allExpanded && 'Expand all rows'} + + } + > + + + + + + + + + + + + + + Action + + + + Action + + + + + + ); + + const toggle = (id: string) => { + const index = expanded.indexOf(id); + const newExpanded = + index >= 0 ? [...expanded.slice(0, index), ...expanded.slice(index + 1, expanded.length)] : [...expanded, id]; + setExpanded(newExpanded); + if (newExpanded.length === 3) { + setAllExpanded(true); + } else if (newExpanded.length === 0) { + setAllExpanded(false); + } + }; + + return ( + + + + + Projects + This is a demo that showcases PatternFly Data List + + + + {renderToolbar()} + + + + + 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. + + ]} + /> + + setIsOpen1(isOpen)} + toggle={(toggleRef: React.Ref) => ( + + + + )} + > + + + Action + + ev.preventDefault()} + > + Link + + + Disabled 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. + + ]} + /> + + setIsOpen2(isOpen)} + toggle={(toggleRef: React.Ref) => ( + + + + )} + > + + + Action + + ev.preventDefault()} + > + Link + + + Disabled 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. + + ]} + /> + + setIsOpen3(isOpen)} + toggle={(toggleRef: React.Ref) => ( + + + + )} + > + + + Action + + ev.preventDefault()} + > + Link + + + Disabled Action + + + Disabled Link + + + + + + + This expanded section has no padding. + + + + + + + ); +}; diff --git a/packages/react-core/src/demos/DataListDemo.md b/packages/react-core/src/demos/DataListDemo.md index 6f72a9c083e..162355d7187 100644 --- a/packages/react-core/src/demos/DataListDemo.md +++ b/packages/react-core/src/demos/DataListDemo.md @@ -25,411 +25,5 @@ import TimesCircleIcon from '@patternfly/react-icons/dist/esm/icons/times-circle ### Expandable control in toolbar -```js -import React from 'react'; -import { - Button, - DataList, - DataListItem, - DataListItemRow, - DataListCell, - DataListAction, - DataListToggle, - DataListContent, - DataListItemCells, - Dropdown, - DropdownItem, - DropdownList, - MenuToggle, - Toolbar, - ToolbarGroup, - ToolbarItem, - ToolbarExpandIconWrapper, - ToolbarContent, - SearchInput, - Tooltip, - Icon -} from '@patternfly/react-core'; -import CodeBranchIcon from '@patternfly/react-icons/dist/esm/icons/code-branch-icon'; -import AngleRightIcon from '@patternfly/react-icons/dist/esm/icons/angle-right-icon'; -import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-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 = () => { - this.setState((prevState) => ({ isOpen1: !prevState.isOpen1 })); - }; - - this.onToggle2 = () => { - this.setState((prevState) => ({ isOpen2: !prevState.isOpen2 })); - }; - - this.onToggle3 = () => { - this.setState((prevState) => ({ isOpen3: !prevState.isOpen3 })); - }; - - this.onSelect1 = () => { - this.setState({ - isOpen1: false - }); - }; - - this.onSelect2 = () => { - this.setState({ - isOpen2: false - }); - }; - - this.onSelect3 = () => { - this.setState({ - isOpen3: false - }); - }; - } - - renderToolbar() { - return ( - - - - - - - {this.state.allExpanded && 'Collapse all rows'} - {!this.state.allExpanded && 'Expand all rows'} - - } - > - - - - - - - - - - - - - - Action - - - - Action - - - - - - ); - } - - render() { - const { isOpen1, isOpen2, isOpen3 } = this.state; - 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 })); - if (newExpanded.length === 3) { - this.setState(() => ({ allExpanded: true })); - } else if (newExpanded.length === 0) { - this.setState(() => ({ allExpanded: false })); - } - }; - - return ( - - {this.renderToolbar()} - - - - - - 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. - - ]} - /> - - this.setState({ isOpen1: isOpen })} - toggle={(toggleRef) => ( - - - - )} - > - - - Action - - ev.preventDefault()} - > - Link - - - Disabled 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. - - ]} - /> - - this.setState({ isOpen2: isOpen })} - toggle={(toggleRef) => ( - - - - )} - > - - - Action - - ev.preventDefault()} - > - Link - - - Disabled 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. - - ]} - /> - - this.setState({ isOpen3: isOpen })} - toggle={(toggleRef) => ( - - - - )} - > - - - Action - - ev.preventDefault()} - > - Link - - - Disabled Action - - - Disabled Link - - - - - - - This expanded section has no padding. - - - - - ); - } -} +```js file="./DataList/examples/DataListExpandableControlInToolbar.tsx" isFullscreen ```
+ Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore + et dolore magna aliqua. +
- Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et - dolore magna aliqua. -