From 7eb9dfacdae6bf2b0b5e4a346d4802d0e7bfda2d Mon Sep 17 00:00:00 2001 From: adamviktora <84135613+adamviktora@users.noreply.github.com> Date: Fri, 20 Sep 2024 21:17:15 +0200 Subject: [PATCH] feat(Table): favoritable sortable header cell and example (#10823) * feat(Table): favoritable sortable header cell and example * fix(TableFavoritable): better favorite / unfavorite state of the header favorite button * refactor(TableFavoritable): custom aria-labels, refactoring --- .../src/components/Table/SortColumn.tsx | 28 +++++++++++++++ .../src/components/Table/TableTypes.tsx | 1 + .../react-table/src/components/Table/Th.tsx | 9 +++-- .../src/components/Table/base/types.tsx | 13 +++++-- .../Table/examples/TableFavoritable.tsx | 35 ++++++++++++++++--- .../Table/utils/decorators/sortable.tsx | 10 +++--- 6 files changed, 82 insertions(+), 14 deletions(-) diff --git a/packages/react-table/src/components/Table/SortColumn.tsx b/packages/react-table/src/components/Table/SortColumn.tsx index 9e5945195ca..5dd45a1b3b8 100644 --- a/packages/react-table/src/components/Table/SortColumn.tsx +++ b/packages/react-table/src/components/Table/SortColumn.tsx @@ -2,10 +2,13 @@ import * as React from 'react'; import LongArrowAltUpIcon from '@patternfly/react-icons/dist/esm/icons/long-arrow-alt-up-icon'; import LongArrowAltDownIcon from '@patternfly/react-icons/dist/esm/icons/long-arrow-alt-down-icon'; import ArrowsAltVIcon from '@patternfly/react-icons/dist/esm/icons/arrows-alt-v-icon'; +import StarIcon from '@patternfly/react-icons/dist/esm/icons/star-icon'; import { css } from '@patternfly/react-styles'; import styles from '@patternfly/react-styles/css/components/Table/table'; import { TableText } from './TableText'; import { TooltipProps } from '@patternfly/react-core/dist/esm/components/Tooltip'; +import { ActionList, ActionListItem, Button } from '@patternfly/react-core'; +import { FavoriteButtonProps } from './base/types'; export enum SortByDirection { asc = 'asc', @@ -21,6 +24,7 @@ export interface SortColumnProps extends React.ButtonHTMLAttributes; tooltipHasDefaultBehavior?: boolean; + favoriteButtonProps?: FavoriteButtonProps; } export const SortColumn: React.FunctionComponent = ({ @@ -33,6 +37,7 @@ export const SortColumn: React.FunctionComponent = ({ tooltip, tooltipProps, tooltipHasDefaultBehavior, + favoriteButtonProps, ...props }: SortColumnProps) => { let SortedByIcon; @@ -42,6 +47,29 @@ export const SortColumn: React.FunctionComponent = ({ } else { SortedByIcon = ArrowsAltVIcon; } + + if (favoriteButtonProps) { + return ( + + +