From 65e2fde12cbea3858edb76dadab53951ae22228d Mon Sep 17 00:00:00 2001 From: Boaz Shuster Date: Mon, 17 Jun 2019 11:58:55 +0300 Subject: [PATCH] feat(chipGroup): add heading level prop to toolbar chip group label Signed-off-by: Boaz Shuster --- .../src/components/ChipGroup/ChipGroup.tsx | 11 ++++- .../ChipGroup/ChipGroupToolbarItem.tsx | 27 +++++++---- .../__snapshots__/ChipGroup.test.tsx.snap | 46 ++++++++++--------- 3 files changed, 52 insertions(+), 32 deletions(-) diff --git a/packages/patternfly-4/react-core/src/components/ChipGroup/ChipGroup.tsx b/packages/patternfly-4/react-core/src/components/ChipGroup/ChipGroup.tsx index 02a00f92010..03b6c6aca71 100644 --- a/packages/patternfly-4/react-core/src/components/ChipGroup/ChipGroup.tsx +++ b/packages/patternfly-4/react-core/src/components/ChipGroup/ChipGroup.tsx @@ -4,6 +4,8 @@ import { css } from '@patternfly/react-styles'; import { Chip } from './Chip'; import { fillTemplate } from '../../helpers'; +export const ChipGroupContext = React.createContext(''); + export interface ChipGroupProps extends React.HTMLProps { /** Content rendered inside the chip text */ children?: React.ReactNode; @@ -15,6 +17,8 @@ export interface ChipGroupProps extends React.HTMLProps { collapsedText?: string; /** Flag for grouping with a toolbar & category name */ withToolbar?: boolean; + /** Set heading level to the chip item label */ + headingLevel?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'; } interface ChipGroupState { @@ -44,7 +48,12 @@ export class ChipGroup extends React.Component{ renderToolbarGroup() { const { isOpen } = this.state; - return ; + const { headingLevel = 'h4' } = this.props; + return ( + + + + ); } renderChipGroup() { diff --git a/packages/patternfly-4/react-core/src/components/ChipGroup/ChipGroupToolbarItem.tsx b/packages/patternfly-4/react-core/src/components/ChipGroup/ChipGroupToolbarItem.tsx index c8e9a32d1ed..607da717089 100644 --- a/packages/patternfly-4/react-core/src/components/ChipGroup/ChipGroupToolbarItem.tsx +++ b/packages/patternfly-4/react-core/src/components/ChipGroup/ChipGroupToolbarItem.tsx @@ -1,14 +1,15 @@ import * as React from 'react'; import { css } from '@patternfly/react-styles'; import styles from '@patternfly/react-styles/css/components/ChipGroup/chip-group'; +import {ChipGroupContext} from './ChipGroup'; export interface ChipGroupToolbarItemProps extends React.HTMLProps { /** Category name text */ categoryName?: string; /** Content rendered inside the chip text */ - children: React.ReactNode; + children: React.ReactNode; /** Additional classes added to the chip item */ - className?: string; + className?: string; } export const ChipGroupToolbarItem: React.FunctionComponent = ({ @@ -18,14 +19,20 @@ export const ChipGroupToolbarItem: React.FunctionComponent { if (React.Children.count(children)) { - return( -
    -
  • -

    {categoryName}

    -
      {children}
    -
  • -
+ return ( + + {(HeadingLevel: any) => { + return ( +
    +
  • + {categoryName} +
      {children}
    +
  • +
+ ); + }} +
); } return null; - }; \ No newline at end of file + }; diff --git a/packages/patternfly-4/react-core/src/components/ChipGroup/__snapshots__/ChipGroup.test.tsx.snap b/packages/patternfly-4/react-core/src/components/ChipGroup/__snapshots__/ChipGroup.test.tsx.snap index cb2732b4459..192859313dc 100644 --- a/packages/patternfly-4/react-core/src/components/ChipGroup/__snapshots__/ChipGroup.test.tsx.snap +++ b/packages/patternfly-4/react-core/src/components/ChipGroup/__snapshots__/ChipGroup.test.tsx.snap @@ -28,26 +28,30 @@ exports[`ChipGroup chip group default 1`] = ` `; exports[`ChipGroup chip group with toolbar 1`] = ` - - - - 1.1 - - - + + + + 1.1 + + + + `;