From 267e05e44ac7da385c90ee28e5c5aec32e2862c3 Mon Sep 17 00:00:00 2001 From: Jenny <32821331+jenny-s51@users.noreply.github.com> Date: Tue, 31 Oct 2023 17:04:14 -0400 Subject: [PATCH] chore(PrimaryDetail): convert demos to TS --- .../react-core/src/demos/PrimaryDetail.md | 978 +----------------- .../PrimaryDetail/PrimaryDetailCardView.tsx | 659 ++++++++++++ .../PrimaryDetailDataListInCard.tsx | 207 ++++ .../PrimaryDetailSimpleListInCard.tsx | 116 +++ 4 files changed, 985 insertions(+), 975 deletions(-) create mode 100644 packages/react-core/src/demos/examples/PrimaryDetail/PrimaryDetailCardView.tsx create mode 100644 packages/react-core/src/demos/examples/PrimaryDetail/PrimaryDetailDataListInCard.tsx create mode 100644 packages/react-core/src/demos/examples/PrimaryDetail/PrimaryDetailSimpleListInCard.tsx diff --git a/packages/react-core/src/demos/PrimaryDetail.md b/packages/react-core/src/demos/PrimaryDetail.md index 732b5c4e3f0..2746dd3bb86 100644 --- a/packages/react-core/src/demos/PrimaryDetail.md +++ b/packages/react-core/src/demos/PrimaryDetail.md @@ -40,989 +40,17 @@ import { data } from '@patternfly/react-core/src/demos/CardView/examples/CardVie ### Primary-detail card view -```js isFullscreen -import React from 'react'; -import { - Button, - Card, - CardHeader, - CardBody, - CardTitle, - Divider, - Drawer, - DrawerActions, - DrawerPanelBody, - DrawerCloseButton, - DrawerContent, - DrawerContentBody, - DrawerHead, - DrawerPanelContent, - Dropdown, - DropdownItem, - DropdownList, - Flex, - FlexItem, - Gallery, - MenuToggle, - MenuToggleCheckbox, - PageSection, - PageSectionVariants, - Pagination, - Progress, - TextContent, - Text, - Title, - Toolbar, - ToolbarItem, - ToolbarContent -} from '@patternfly/react-core'; -import TrashIcon from '@patternfly/react-icons/dist/esm/icons/trash-icon'; -import pfIcon from './assets/pf-logo-small.svg'; -import activeMQIcon from './assets/activemq-core_200x150.png'; -import avroIcon from './assets/camel-avro_200x150.png'; -import dropBoxIcon from './assets/camel-dropbox_200x150.png'; -import infinispanIcon from './assets/camel-infinispan_200x150.png'; -import saxonIcon from './assets/camel-saxon_200x150.png'; -import sparkIcon from './assets/camel-spark_200x150.png'; -import swaggerIcon from './assets/camel-swagger-java_200x150.png'; -import azureIcon from './assets/FuseConnector_Icons_AzureServices.png'; -import restIcon from './assets/FuseConnector_Icons_REST.png'; -import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon'; -import { DashboardWrapper } from '@patternfly/react-core/src/demos/DashboardWrapper'; -import { data } from '@patternfly/react-core/src/demos/CardView/examples/CardViewData.jsx'; - -class PrimaryDetailCardView extends React.Component { - constructor(props) { - super(props); - - this.state = { - page: 1, - perPage: 10, - totalItemCount: 10, - isDrawerExpanded: false, - isChecked: false, - selectedItems: [], - areAllSelected: false, - splitButtonDropdownIsOpen: false, - activeCard: null, - filters: { - products: [] - }, - cardData: data, - isUpperToolbarDropdownOpen: false, - isUpperToolbarKebabDropdownOpen: false, - isLowerToolbarDropdownOpen: false, - isLowerToolbarKebabDropdownOpen: false, - isCardKebabDropdownOpen: false, - activeItem: 0 - }; - - this.onToolbarDropdownToggle = (_event, isLowerToolbarDropdownOpen) => { - this.setState((prevState) => ({ - isLowerToolbarDropdownOpen - })); - }; - - this.onToolbarDropdownSelect = (_event) => { - this.setState({ - isLowerToolbarDropdownOpen: !this.state.isLowerToolbarDropdownOpen - }); - }; - - this.onToolbarKebabDropdownToggle = () => { - this.setState((prevState) => ({ - isLowerToolbarKebabDropdownOpen: !prevState.isLowerToolbarKebabDropdownOpen - })); - }; - - this.onToolbarKebabDropdownSelect = () => { - this.setState({ - isLowerToolbarKebabDropdownOpen: false - }); - }; - - this.checkAllSelected = (selected, total) => { - if (selected && selected < total) { - return null; - } - return selected === total; - }; - - this.onNameSelect = (event, selection) => { - const checked = event.target.checked; - this.setState((prevState) => { - const prevSelections = prevState.filters.products; - return { - filters: { - ...prevState.filters, - ['products']: checked - ? [...prevSelections, selection] - : prevSelections.filter((value) => value !== selection) - } - }; - }); - }; - - this.onDelete = (type = '', id = '') => { - if (type) { - this.setState((prevState) => { - prevState.filters[type.toLowerCase()] = prevState.filters[type.toLowerCase()].filter((s) => s !== id); - return { - filters: prevState.filters - }; - }); - } else { - this.setState({ - filters: { - products: [] - } - }); - } - }; - - this.onCloseDrawerClick = () => { - this.setState({ - activeCard: null, - isDrawerExpanded: false - }); - }; - - this.onCheckboxClick = (event, productId) => { - this.setState((prevState) => - prevState.selectedItems.includes(productId * 1) || this.state.selectedItems.includes(productId * 1) - ? { - selectedItems: [...this.state.selectedItems.filter((id) => productId * 1 !== id)], - areAllSelected: this.checkAllSelected(prevState.selectedItems.length - 1, prevState.totalItemCount) - } - : { - selectedItems: [...prevState.selectedItems, productId * 1], - areAllSelected: this.checkAllSelected(prevState.selectedItems.length + 1, prevState.totalItemCount) - } - ); - }; - - this.onClick = (productId) => { - this.setState((prevState) => - prevState.selectedItems.includes(productId * 1) - ? { - selectedItems: [...prevState.selectedItems.filter((id) => productId * 1 !== id)], - areAllSelected: this.checkAllSelected(prevState.selectedItems.length - 1, prevState.totalItemCount) - } - : { - selectedItems: [...prevState.selectedItems, productId * 1], - areAllSelected: this.checkAllSelected(prevState.selectedItems.length + 1, prevState.totalItemCount) - } - ); - }; - - this.onCardClick = (productId) => { - - if (productId === this.state.activeCard) { - this.setState({ - isDrawerExpanded: !this.state.isDrawerExpanded, - activeCard: null - }); - return; - } - - this.setState({ - activeCard: productId, - isDrawerExpanded: true - }); - }; - - this.onChange = (_event, labelledById) => { - if (labelledById === this.state.activeCard) { - return; - } - - this.setState({ - activeCard: labelledById, - isDrawerExpanded: true - }); - }; - - this.onPerPageSelect = (_evt, perPage) => { - this.setState({ page: 1, perPage }); - }; - - this.onSetPage = (_evt, page) => { - this.setState({ page }); - }; - - this.selectPage = () => { - const { totalItemCount, perPage } = this.state; - let collection = []; - - collection = this.getAllItems(); - - this.setState( - { - selectedItems: collection, - areAllSelected: totalItemCount === perPage ? true : false - }, - this.updateSelected - ); - }; - - this.selectAll = () => { - let collection = []; - for (let i = 0; i <= 9; i++) { - collection = [...collection, i]; - } - - this.setState( - { - selectedItems: collection, - isChecked: true, - areAllSelected: true - }, - this.updateSelected - ); - }; - - this.selectNone = () => { - this.setState( - { - selectedItems: [], - isChecked: false, - areAllSelected: false, - isDrawerExpanded: false, - activeCard: null - }, - this.updateSelected - ); - }; - - this.splitCheckboxSelectAll = (e) => { - const { checked } = e.target; - const { isChecked } = this.state; - let collection = []; - - if (checked) { - for (let i = 0; i <= 9; i++) { - collection = [...collection, i]; - } - } - - this.setState( - { - selectedItems: collection, - areAllSelected: checked, - isDrawerExpanded: false, - activeCard: null, - isChecked - }, - this.updateSelected - ); - }; - - this.onSplitButtonSelect = () => { - this.setState(() => ({ - splitButtonDropdownIsOpen: false, - isDrawerExpanded: false, - activeCard: null - })); - }; - - this.onSplitButtonToggle = () => { - this.setState((prevState) => ({ - splitButtonDropdownIsOpen: !prevState.splitButtonDropdownIsOpen - })); - }; - - this.onCardKebabDropdownToggle = (key) => { - this.setState((prevState) => ({ - [key]: !prevState[key] - })); - }; - - this.onCardKebabDropdownSelect = (key) => { - this.setState({ - [key]: false - }); - }; - - this.deleteItem = (event, item) => { - const filter = (getter) => (val) => getter(val) !== item.id; - const filteredCards = this.state.cardData.filter(filter(({ id }) => id)); - this.setState({ - cardData: filteredCards, - selectedItems: this.state.selectedItems.filter(filter((id) => id)), - totalItemCount: this.state.totalItemCount - 1, - isDrawerExpanded: false, - activeCard: null - }); - }; - } - - getAllItems() { - const { cardData } = this.state; - const collection = []; - for (const items of cardData) { - collection.push(items.id); - } - - return collection; - } - - buildSelectDropdown() { - const { splitButtonDropdownIsOpen, selectedItems, areAllSelected } = this.state; - const numSelected = selectedItems.length; - const allSelected = areAllSelected; - const anySelected = numSelected > 0; - const someChecked = anySelected ? null : false; - const isChecked = allSelected ? true : someChecked; - const splitButtonDropdownItems = ( - <> - - Select none (0 items) - - - Select page ({this.state.perPage} items) - - - Select all ({this.state.totalItemCount} items) - - - ); - - return ( - this.setState({ splitButtonDropdownIsOpen: isOpen })} - toggle={(toggleRef) => ( - - {numSelected !== 0 && `${numSelected} selected`} - - ] - }} - > - )} - > - {splitButtonDropdownItems} - - ); - } - - render() { - const { - isDrawerExpanded, - isChecked, - selectedItems, - activeCard, - isLowerToolbarKebabDropdownOpen, - filters, - cardData - } = this.state; - - const toolbarKebabDropdownItems = ( - <> - - Action - - ev.preventDefault()} - > - Link - - - Disabled Action - - - Disabled Link - - - - Separated Action - - ev.preventDefault()}> - Separated Link - - - ); - const toolbarItems = ( - - {this.buildSelectDropdown()} - - - - - - - - this.setState({ isLowerToolbarKebabDropdownOpen: isOpen })} - toggle={(toggleRef) => ( - - - )} - > - {toolbarKebabDropdownItems} - - - - ); - - const filtered = - filters.products.length > 0 - ? cardData.filter((card) => filters.products.length === 0 || filters.products.includes(card.name)) - : cardData; - - const icons = { - pfIcon, - activeMQIcon, - sparkIcon, - avroIcon, - azureIcon, - saxonIcon, - dropBoxIcon, - infinispanIcon, - restIcon, - swaggerIcon - }; - - const drawerContent = ( - - {filtered.map((product, key) => ( - - - this.onCardKebabDropdownSelect(key)} - isOpen={this.state[key] || false} - onOpenChange={(isOpen) => this.setState({ [key]: isOpen })} - popperProps={{ position: 'right' }} - toggle={(toggleRef) => ( - this.onCardKebabDropdownToggle(key)} - > - - )} - > - - this.deleteItem(e, product)}> - - Delete - - - - - ) - }} - selectableActions={{ isChecked: selectedItems.includes(product.id), selectableActionId: `selectable-actions-item-${product.id}`, selectableActionAriaLabelledby: `${'card-view-' + key}`, name: `check-${product.id}`, onChange: () => this.onClick(product.id) }} - > - {`${product.name} - - - - - {product.description} - - ))} - - ); - - const panelContent = ( - - - - node-{activeCard} - - - - - - - - -

- The content of the drawer really is up to you. It could have form fields, definition lists, text lists, - labels, charts, progress bars, etc. Spacing recommendation is 24px margins. You can put tabs in here, - and can also make the drawer scrollable. -

-
- - - - - - -
-
-
- ); - - return ( - - - - Projects - This is a demo that showcases Patternfly Cards. - - - - - {toolbarItems} - - - - - - - {drawerContent} - - - - - - - - ); - } -} +```js file="./examples/PrimaryDetail/PrimaryDetailCardView.tsx" isFullscreen ``` ### Primary-detail simple list in card -```js isFullscreen -import React from 'react'; -import { - Card, - CardBody, - Divider, - Drawer, - DrawerActions, - DrawerCloseButton, - DrawerContent, - DrawerContentBody, - DrawerHead, - DrawerPanelBody, - DrawerPanelContent, - Flex, - FlexItem, - PageSection, - PageSectionVariants, - Progress, - SimpleList, - SimpleListGroup, - SimpleListItem, - Text, - TextContent, - TextInput, - Title -} from '@patternfly/react-core'; -import { DashboardWrapper } from '@patternfly/react-core/src/demos/DashboardWrapper'; - -class PrimaryDetailSimpleListInCard extends React.Component { - constructor(props) { - super(props); - this.state = { - drawerPanelBodyContent: 1, - activeItem: 0, - isKebabDropdownOpen: false, - isDropdownOpen: false, - isExpanded: false - }; - - this.onSelectListItem = (listItem, listItemProps) => { - const id = listItemProps.id; - this.setState({ - drawerPanelBodyContent: id.charAt(id.length - 1), - isExpanded: true - }); - }; - - this.onClose = () => { - this.setState({ - isExpanded: false - }); - }; - } - - render() { - const { drawerPanelBodyContent, selectedListItemId, activeItem, isExpanded } = this.state; - - const panelContent = ( - - - - {`List item ${drawerPanelBodyContent} details`} - - - - - - - - -

- The content of the drawer really is up to you. It could have form fields, definition lists, text lists, - labels, charts, progress bars, etc. Spacing recommendation is 24px margins. You can put tabs in here, - and can also make the drawer scrollable. -

-
- - - - - - -
-
-
- ); - - const drawerContent = ( - - - - - List item 1 - - - List item 2 - - - List item 3 - - - List item 4 - - - - - List item 5 - - - List item 6 - - - List item 7 - - - List item 8 - - - List item 9 - - - - - ); - - return ( - - - - Main title - - Body text should be Overpass Regular at 16px. It should have leading of 24px because
- of it’s relative line height of 1.5. -
-
-
- - - - - - {drawerContent} - - - - -
- ); - } -} +```js file="./examples/PrimaryDetail/PrimaryDetailSimpleListInCard.tsx" isFullscreen ``` ### Primary-detail data list in card -```js isFullscreen -import React from 'react'; -import { - Card, - DataList, - DataListCell, - DataListItem, - DataListItemCells, - DataListItemRow, - Toolbar, - ToolbarContent, - ToolbarItem, - Divider, - Drawer, - DrawerActions, - DrawerCloseButton, - DrawerContent, - DrawerContentBody, - DrawerHead, - DrawerPanelBody, - DrawerPanelContent, - Dropdown, - DropdownItem, - DropdownList, - Flex, - FlexItem, - MenuToggle, - PageSection, - PageSectionVariants, - Progress, - Text, - TextContent, - Title -} from '@patternfly/react-core'; -import { DashboardWrapper } from '@patternfly/react-core/src/demos/DashboardWrapper'; - -class PrimaryDetailDataListInCard extends React.Component { - constructor(props) { - super(props); - this.state = { - drawerPanelBodyContent: 1, - activeItem: 0, - isKebabDropdownOpen: false, - isDropdownOpen: false, - selectedDataListItemId: 'dataListItem1', - isExpanded: false - }; - - this.onDropdownToggle = () => { - this.setState((prevState) => ({ - isDropdownOpen: !prevState.isDropdownOpen - })); - }; - this.onDropdownSelect = () => { - this.setState({ - isDropdownOpen: false - }); - this.onDropdownFocus(); - }; - this.onDropdownFocus = () => { - const element = document.getElementById('toggle-id'); - element.focus(); - }; - this.onSelectDataListItem = (_event, id) => { - this.setState({ - selectedDataListItemId: id, - drawerPanelBodyContent: id.charAt(id.length - 1), - isExpanded: true - }); - }; - this.onClose = () => { - this.setState({ - isExpanded: false - }); - }; - } - - render() { - const { - drawerPanelBodyContent, - selectedListItemId, - activeItem, - isDropdownOpen, - selectedDataListItemId, - isExpanded - } = this.state; - - const panelContent = ( - - - - Patternfly-elements - - - - - - - - -

- The content of the drawer really is up to you. It could have form fields, definition lists, text lists, - labels, charts, progress bars, etc. Spacing recommendation is 24px margins. You can put tabs in here, - and can also make the drawer scrollable. -

-
- - - - - - -
-
-
- ); - - const drawerContent = ( - - - - - this.setState({ isDropdownOpen: isOpen })} - toggle={(toggleRef) => ( - - Dropdown - - )} - > - - Option 1 - Option 2 - - - - - - - - - -
Node 1
- siemur/test-space - - ]} - /> -
-
- - - -
Node 2
- siemur/test-space - - ]} - /> -
-
- - - -
Node 3
- siemur/test-space - - ]} - /> -
-
- - - -
Node 4
- siemur/test-space - - ]} - /> -
-
- - - -
Node 5
- siemur/test-space - - ]} - /> -
-
-
-
- ); - - return ( - - - - Main title - - Body text should be Overpass Regular at 16px. It should have leading of 24px because
- of it’s relative line height of 1.5. -
-
-
- - - - - - {drawerContent} - - - - -
- ); - } -} +```js file="./examples/PrimaryDetail/PrimaryDetailDataListInCard.tsx" isFullscreen ``` ### Primary-detail inline modifier diff --git a/packages/react-core/src/demos/examples/PrimaryDetail/PrimaryDetailCardView.tsx b/packages/react-core/src/demos/examples/PrimaryDetail/PrimaryDetailCardView.tsx new file mode 100644 index 00000000000..1bf60cf0904 --- /dev/null +++ b/packages/react-core/src/demos/examples/PrimaryDetail/PrimaryDetailCardView.tsx @@ -0,0 +1,659 @@ +import React from 'react'; +import { + Badge, + Button, + Card, + CardHeader, + CardBody, + CardTitle, + Divider, + Drawer, + DrawerActions, + DrawerPanelBody, + DrawerCloseButton, + DrawerContent, + DrawerContentBody, + DrawerHead, + DrawerPanelContent, + Dropdown, + DropdownItem, + DropdownList, + Flex, + FlexItem, + Gallery, + MenuToggle, + MenuToggleCheckbox, + PageSection, + PageSectionVariants, + Pagination, + Progress, + Select, + SelectList, + SelectOption, + TextContent, + Text, + Title, + Toolbar, + ToolbarFilter, + ToolbarItem, + ToolbarContent, + MenuToggleElement +} from '@patternfly/react-core'; +import TrashIcon from '@patternfly/react-icons/dist/esm/icons/trash-icon'; +import pfIcon from './assets/pf-logo-small.svg'; +import activeMQIcon from './assets/activemq-core_200x150.png'; +import avroIcon from './assets/camel-avro_200x150.png'; +import dropBoxIcon from './assets/camel-dropbox_200x150.png'; +import infinispanIcon from './assets/camel-infinispan_200x150.png'; +import saxonIcon from './assets/camel-saxon_200x150.png'; +import sparkIcon from './assets/camel-spark_200x150.png'; +import swaggerIcon from './assets/camel-swagger-java_200x150.png'; +import azureIcon from './assets/FuseConnector_Icons_AzureServices.png'; +import restIcon from './assets/FuseConnector_Icons_REST.png'; +import EllipsisVIcon from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon'; +import { DashboardWrapper } from '@patternfly/react-core/src/demos/DashboardWrapper'; +import { data } from '@patternfly/react-core/src/demos/CardView/examples/CardViewData.jsx'; + +export const PrimaryDetailCardView: React.FunctionComponent = () => { + const [totalItemCount, setTotalItemCount] = React.useState(10); + const [cardData, setCardData] = React.useState(data); + const [isChecked, setIsChecked] = React.useState(false); + const [isDrawerExpanded, setIsDrawerExpanded] = React.useState(false); + const [selectedItems, setSelectedItems] = React.useState([]); + const [areAllSelected, setAreAllSelected] = React.useState(false); + const [splitButtonDropdownIsOpen, setSplitButtonDropdownIsOpen] = React.useState(false); + const [isLowerToolbarDropdownOpen, setIsLowerToolbarDropdownOpen] = React.useState(false); + const [isLowerToolbarKebabDropdownOpen, setIsLowerToolbarKebabDropdownOpen] = React.useState(false); + const [page, setPage] = React.useState(1); + const [perPage, setPerPage] = React.useState(10); + const [filters, setFilters] = React.useState>({ products: [] }); + const [state, setState] = React.useState({}); + const [activeCard, setActiveCard] = React.useState(-1); + + interface ProductType { + id: number; + name: string; + icon: string; + description: string; + } + + const onToolbarDropdownToggle = () => { + setIsLowerToolbarDropdownOpen(!isLowerToolbarDropdownOpen); + }; + + const onToolbarKebabDropdownToggle = () => { + setIsLowerToolbarKebabDropdownOpen(!isLowerToolbarKebabDropdownOpen); + }; + + const onToolbarKebabDropdownSelect = () => { + setIsLowerToolbarKebabDropdownOpen(!isLowerToolbarKebabDropdownOpen); + }; + + const onCardKebabDropdownToggle = ( + event: React.MouseEvent | React.MouseEvent, + key: string + ) => { + setState({ + [key]: !state[key as keyof Object] + }); + }; + + const checkAllSelected = (selected: number, total: number) => { + if (selected && selected < total) { + return null; + } + return selected === total; + }; + + const onNameSelect = (event: any, selection = '') => { + const checked = event.target.checked; + const prevSelections = filters.products; + + setFilters({ + ...filters, + products: checked ? [...prevSelections, selection] : prevSelections.filter((value) => value !== selection) + }); + }; + + const onDelete = (type = '', _id = '') => { + if (type) { + setFilters(filters); + } else { + setFilters({ products: [] }); + } + }; + + const deleteItem = (item: ProductType) => { + const filter = (getter) => (val) => getter(val) !== item.id; + + setCardData(cardData.filter(filter(({ id }) => id))); + + setSelectedItems(selectedItems.filter(filter((id) => id))); + + setTotalItemCount(totalItemCount - 1); + setIsDrawerExpanded(false); + setActiveCard(-1); + }; + + const onSetPage = (_event: any, pageNumber: number) => { + setPage(pageNumber); + }; + + const onPerPageSelect = (_event: any, perPage: number) => { + setPerPage(perPage); + setPage(1); + }; + + const onSplitButtonToggle = () => { + setSplitButtonDropdownIsOpen(!splitButtonDropdownIsOpen); + }; + + const onSplitButtonSelect = () => { + setSplitButtonDropdownIsOpen(false); + setIsDrawerExpanded(false); + setActiveCard(-1); + }; + + const onCloseDrawerClick = () => { + setActiveCard(-1); + setIsDrawerExpanded(false); + }; + + const onChange = (event: React.FormEvent) => { + const name = event.currentTarget.name; + const productId = Number(name.charAt(name.length - 1)); + + if (selectedItems.includes(productId * 1)) { + setSelectedItems(selectedItems.filter((id) => productId * 1 !== id)); + + const checkAll = checkAllSelected(selectedItems.length - 1, totalItemCount); + setAreAllSelected(!!checkAll); + } else { + setSelectedItems([...selectedItems, productId * 1]); + const checkAll = checkAllSelected(selectedItems.length + 1, totalItemCount); + setAreAllSelected(!!checkAll); + } + }; + + const onCardClick = (productId) => { + if (productId === activeCard) { + setIsDrawerExpanded(!isDrawerExpanded); + setActiveCard(-1); + } else { + setActiveCard(productId); + setIsDrawerExpanded(true); + } + }; + + const selectPage = (e: { target: { checked: any } }) => { + const { checked } = e.target; + let collection: number[] = []; + + collection = getAllItems(); + + setSelectedItems(collection); + setIsChecked(checked); + setAreAllSelected(totalItemCount === perPage ? true : false); + + updateSelected(); + }; + + const selectAll = () => { + let collection: number[] = []; + for (let i = 0; i <= 9; i++) { + collection = [...collection, i]; + } + + setSelectedItems(collection); + setIsChecked(true); + setAreAllSelected(true); + + updateSelected(); + }; + + const selectNone = () => { + setSelectedItems([]); + setIsChecked(false); + setAreAllSelected(false); + setIsDrawerExpanded(false); + setActiveCard(-1); + + updateSelected(); + }; + + const updateSelected = () => { + const rows = cardData.map((post) => { + post.selected = selectedItems.includes(post.id); + return post; + }); + + setCardData(rows); + }; + + const getAllItems = () => { + const collection: number[] = []; + for (const items of cardData) { + collection.push(items.id); + } + + return collection; + }; + + const splitCheckboxSelectAll = (e: any) => { + let collection: number[] = []; + + if (e.target.checked) { + for (let i = 0; i <= 9; i++) { + collection = [...collection, i]; + } + } + + setSelectedItems(collection); + setIsChecked(isChecked); + setAreAllSelected(e.target.checked); + setIsDrawerExpanded(false); + setActiveCard(-1); + + updateSelected(); + }; + + const renderPagination = () => { + const defaultPerPageOptions = [ + { + title: '1', + value: 1 + }, + { + title: '5', + value: 5 + }, + { + title: '10', + value: 10 + } + ]; + + return ( + + ); + }; + + const buildSelectDropdown = () => { + const numSelected = selectedItems.length; + const anySelected = numSelected > 0; + const splitButtonDropdownItems = ( + <> + + Select none (0 items) + + + Select page ({perPage} items) + + + Select all ({totalItemCount} items) + + + ); + + return ( + setSplitButtonDropdownIsOpen(isOpen)} + toggle={(toggleRef) => ( + + {numSelected !== 0 && `${numSelected} selected`} + + ] + }} + > + )} + > + {splitButtonDropdownItems} + + ); + }; + + const buildFilterDropdown = () => { + const filterDropdownItems = ( + + + PatternFly + + + ActiveMQ + + + Apache Spark + + + Avro + + + Azure Services + + + Crypto + + + DropBox + + + JBoss Data Grid + + + REST + + + SWAGGER + + + ); + + return ( + onDelete(type as string, id as string)} + > + + + ); + }; + + const toolbarKebabDropdownItems = ( + <> + + Action + + ev.preventDefault()} + > + Link + + + Disabled Action + + + Disabled Link + + + + Separated Action + + ev.preventDefault()}> + Separated Link + + + ); + const toolbarItems = ( + + {buildSelectDropdown()} + {buildFilterDropdown()} + + + + + + + + setIsLowerToolbarKebabDropdownOpen(isOpen)} + toggle={(toggleRef) => ( + + + )} + > + {toolbarKebabDropdownItems} + + + + {renderPagination()} + + + ); + + const filtered = + filters.products.length > 0 + ? data.filter((card: { name: string }) => filters.products.length === 0 || filters.products.includes(card.name)) + : cardData.slice((page - 1) * perPage, perPage === 1 ? page * perPage : page * perPage - 1); + + const icons = { + pfIcon, + activeMQIcon, + sparkIcon, + avroIcon, + azureIcon, + saxonIcon, + dropBoxIcon, + infinispanIcon, + restIcon, + swaggerIcon + }; + + const drawerContent = ( + + {filtered.map((product, key) => ( + + + setState({ [key]: isOpen })} + popperProps={{ position: 'right' }} + toggle={(toggleRef: React.Ref) => ( + { + onCardKebabDropdownToggle(e, key.toString()); + }} + isExpanded={!!state[key]} + > + + + )} + > + + { + deleteItem(product); + }} + > + + Delete + + + + + ) + }} + selectableActions={{ + isChecked: selectedItems.includes(product.id), + selectableActionId: `selectable-actions-item-${product.id}`, + selectableActionAriaLabelledby: `${'card-view-' + key}`, + name: `check-${product.id}`, + onChange + }} + > + {`${product.name} + + + + + + + + + + Provided by Red Hat + + + + + + + {product.description} + + ))} + + ); + + const panelContent = ( + + + + node-{activeCard} + + + + + + + + +

+ The content of the drawer really is up to you. It could have form fields, definition lists, text lists, + labels, charts, progress bars, etc. Spacing recommendation is 24px margins. You can put tabs in here, and + can also make the drawer scrollable. +

+
+ + + + + + +
+
+
+ ); + + return ( + + + + Projects + This is a demo that showcases Patternfly Cards. + + + + + {toolbarItems} + + + + + + + {drawerContent} + + + + + + + + ); +}; diff --git a/packages/react-core/src/demos/examples/PrimaryDetail/PrimaryDetailDataListInCard.tsx b/packages/react-core/src/demos/examples/PrimaryDetail/PrimaryDetailDataListInCard.tsx new file mode 100644 index 00000000000..52e5a51696f --- /dev/null +++ b/packages/react-core/src/demos/examples/PrimaryDetail/PrimaryDetailDataListInCard.tsx @@ -0,0 +1,207 @@ +import React from 'react'; +import { + Card, + DataList, + DataListCell, + DataListItem, + DataListItemCells, + DataListItemRow, + Toolbar, + ToolbarContent, + ToolbarItem, + Divider, + Drawer, + DrawerActions, + DrawerCloseButton, + DrawerContent, + DrawerContentBody, + DrawerHead, + DrawerPanelBody, + DrawerPanelContent, + Dropdown, + DropdownItem, + DropdownList, + Flex, + FlexItem, + MenuToggle, + PageSection, + PageSectionVariants, + Progress, + Text, + TextContent, + Title +} from '@patternfly/react-core'; +import { DashboardWrapper } from '@patternfly/react-core/src/demos/DashboardWrapper'; + +export const PrimaryDetailDataListInCard: React.FunctionComponent = () => { + const [drawerPanelBodyContent, setDrawerPanelBodyContent] = React.useState(1); + const [isDropdownOpen, setIsDropdownOpen] = React.useState(false); + const [selectedDataListItemId, setSelectedDataListItemId] = React.useState('dataListItem1'); + const [isExpanded, setIsExpanded] = React.useState(false); + + const onDropdownToggle = () => { + setIsDropdownOpen(!isDropdownOpen); + }; + const onDropdownSelect = () => { + setIsDropdownOpen(false); + onDropdownFocus(); + }; + const onDropdownFocus = () => { + const element = document.getElementById('toggle-id'); + element?.focus(); + }; + const onSelectDataListItem = (_event, id) => { + setSelectedDataListItemId(id); + setDrawerPanelBodyContent(id.charAt(id.length - 1)); + setIsExpanded(true); + }; + const onClose = () => { + setIsExpanded(false); + }; + + const panelContent = ( + + + + Patternfly-elements + + + + + + + + +

+ The content of the drawer really is up to you. It could have form fields, definition lists, text lists, + labels, charts, progress bars, etc. Spacing recommendation is 24px margins. You can put tabs in here, and + can also make the drawer scrollable. +

+
+ + + + + + +
+
+
+ ); + + const drawerContent = ( + + + + + setIsDropdownOpen(isOpen)} + toggle={(toggleRef) => ( + + Dropdown + + )} + > + + Option 1 + Option 2 + + + + + + + + + +
Node 1
+ siemur/test-space + + ]} + /> +
+
+ + + +
Node 2
+ siemur/test-space + + ]} + /> +
+
+ + + +
Node 3
+ siemur/test-space + + ]} + /> +
+
+ + + +
Node 4
+ siemur/test-space + + ]} + /> +
+
+ + + +
Node 5
+ siemur/test-space + + ]} + /> +
+
+
+
+ ); + + return ( + + + + Main title + + Body text should be Overpass Regular at 16px. It should have leading of 24px because
+ of it’s relative line height of 1.5. +
+
+
+ + + + + + {drawerContent} + + + + +
+ ); +}; diff --git a/packages/react-core/src/demos/examples/PrimaryDetail/PrimaryDetailSimpleListInCard.tsx b/packages/react-core/src/demos/examples/PrimaryDetail/PrimaryDetailSimpleListInCard.tsx new file mode 100644 index 00000000000..9f500d6ea1c --- /dev/null +++ b/packages/react-core/src/demos/examples/PrimaryDetail/PrimaryDetailSimpleListInCard.tsx @@ -0,0 +1,116 @@ +import React from 'react'; +import { + Card, + Divider, + Drawer, + DrawerActions, + DrawerCloseButton, + DrawerContent, + DrawerContentBody, + DrawerHead, + DrawerPanelBody, + DrawerPanelContent, + Flex, + FlexItem, + PageSection, + PageSectionVariants, + Progress, + SimpleList, + SimpleListGroup, + SimpleListItem, + Text, + TextContent, + Title +} from '@patternfly/react-core'; +import { DashboardWrapper } from '@patternfly/react-core/src/demos/DashboardWrapper'; + +export const PrimaryDetailSimpleListInCard: React.FunctionComponent = () => { + const [drawerPanelBodyContent, setDrawerPanelBodyContent] = React.useState(1); + const [isExpanded, setIsExpanded] = React.useState(false); + + const onSelectListItem = (_listItem, listItemProps) => { + const id = listItemProps.children; + setDrawerPanelBodyContent(id.charAt(id.length - 1)); + setIsExpanded(true); + }; + + const onClose = () => { + setIsExpanded(false); + }; + + const panelContent = ( + + + + {`List item ${drawerPanelBodyContent} details`} + + + + + + + + +

+ The content of the drawer really is up to you. It could have form fields, definition lists, text lists, + labels, charts, progress bars, etc. Spacing recommendation is 24px margins. You can put tabs in here, and + can also make the drawer scrollable. +

+
+ + + + + + +
+
+
+ ); + + const drawerContent = ( + + + + + List item 1 + + List item 2 + List item 3 + List item 4 + + + List item 5 + List item 6 + List item 7 + List item 8 + List item 9 + + + + ); + + return ( + + + + Main title + + Body text should be Overpass Regular at 16px. It should have leading of 24px because
+ of it’s relative line height of 1.5. +
+
+
+ + + + + + {drawerContent} + + + + +
+ ); +};