From aa1036f4de822afa789c567a75a2ce76f91ec9c3 Mon Sep 17 00:00:00 2001 From: gitdallas Date: Mon, 3 Oct 2022 16:55:58 -0500 Subject: [PATCH 1/7] button - combine isSmall and isLarge into customSize --- .../Accordion/examples/AccordionBordered.tsx | 2 +- .../src/components/Button/Button.tsx | 19 +++--- .../Button/__tests__/Button.test.tsx | 8 +-- .../__snapshots__/Button.test.tsx.snap | 60 +++++++++---------- .../src/components/Button/examples/Button.md | 4 +- .../Button/examples/ButtonCallToAction.tsx | 8 +-- .../Button/examples/ButtonSmall.tsx | 10 ++-- .../demos/ButtonDemo/ButtonDemo.tsx | 4 +- 8 files changed, 59 insertions(+), 56 deletions(-) diff --git a/packages/react-core/src/components/Accordion/examples/AccordionBordered.tsx b/packages/react-core/src/components/Accordion/examples/AccordionBordered.tsx index aba7a806b29..6e50be22ff4 100644 --- a/packages/react-core/src/components/Accordion/examples/AccordionBordered.tsx +++ b/packages/react-core/src/components/Accordion/examples/AccordionBordered.tsx @@ -98,7 +98,7 @@ export const AccordionBordered: React.FunctionComponent = () => { Proin dictum imperdiet nibh, quis dapibus nulla. Integer sed tincidunt lectus, sit amet auctor eros. - diff --git a/packages/react-core/src/components/Button/Button.tsx b/packages/react-core/src/components/Button/Button.tsx index e3013421b37..6c816ce2a07 100644 --- a/packages/react-core/src/components/Button/Button.tsx +++ b/packages/react-core/src/components/Button/Button.tsx @@ -22,6 +22,12 @@ export enum ButtonType { reset = 'reset' } +export enum ButtonSize { + default = 'default', + small = 'small', + large = 'large' +} + export interface BadgeCountObject { /** Adds styling to the badge to indicate it has been read */ isRead?: boolean; @@ -70,10 +76,8 @@ export interface ButtonProps extends Omit, 'r icon?: React.ReactNode | null; /** Sets the button tabindex. */ tabIndex?: number; - /** Adds small styling to the button */ - isSmall?: boolean; - /** Adds large styling to the button */ - isLarge?: boolean; + /** Adds small or large styling to the button */ + customSize?: 'default' | 'small' | 'large'; /** Adds danger styling to secondary or link button variants */ isDanger?: boolean; /** Forwarded ref */ @@ -99,8 +103,7 @@ const ButtonBase: React.FunctionComponent = ({ spinnerAriaValueText, spinnerAriaLabelledBy, spinnerAriaLabel, - isSmall = false, - isLarge = false, + customSize = ButtonSize.default, inoperableEvents = ['onClick', 'onKeyPress'], isInline = false, type = ButtonType.button, @@ -157,8 +160,8 @@ const ButtonBase: React.FunctionComponent = ({ isDanger && (variant === ButtonVariant.secondary || variant === ButtonVariant.link) && styles.modifiers.danger, isLoading !== null && children !== null && styles.modifiers.progress, isLoading && styles.modifiers.inProgress, - isSmall && styles.modifiers.small, - isLarge && styles.modifiers.displayLg, + customSize === 'small' && styles.modifiers.small, + customSize === 'large' && styles.modifiers.displayLg, className )} disabled={isButtonElement ? isDisabled : null} diff --git a/packages/react-core/src/components/Button/__tests__/Button.test.tsx b/packages/react-core/src/components/Button/__tests__/Button.test.tsx index b8d19a3472e..843d283af1c 100644 --- a/packages/react-core/src/components/Button/__tests__/Button.test.tsx +++ b/packages/react-core/src/components/Button/__tests__/Button.test.tsx @@ -84,13 +84,13 @@ describe('Button', () => { expect(asFragment()).toMatchSnapshot(); }); - test('isSmall', () => { - const { asFragment } = render(); + test('customSize small', () => { + const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); - test('isLarge', () => { - const { asFragment } = render(); + test('customSize large', () => { + const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); diff --git a/packages/react-core/src/components/Button/__tests__/__snapshots__/Button.test.tsx.snap b/packages/react-core/src/components/Button/__tests__/__snapshots__/Button.test.tsx.snap index 29332d1d569..34a410e715b 100644 --- a/packages/react-core/src/components/Button/__tests__/__snapshots__/Button.test.tsx.snap +++ b/packages/react-core/src/components/Button/__tests__/__snapshots__/Button.test.tsx.snap @@ -31,6 +31,36 @@ exports[`Button control button 1`] = ` `; +exports[`Button customSize large 1`] = ` + + + +`; + +exports[`Button customSize small 1`] = ` + + + +`; + exports[`Button danger button 1`] = ` - -`; - exports[`Button isLoading 1`] = ` - -`; - exports[`Button link button 1`] = ` {' '} - {' '} - {' '} -
diff --git a/packages/react-core/src/components/Button/examples/ButtonSmall.tsx b/packages/react-core/src/components/Button/examples/ButtonSmall.tsx index 9e32fe99e65..aa4b3ec6d08 100644 --- a/packages/react-core/src/components/Button/examples/ButtonSmall.tsx +++ b/packages/react-core/src/components/Button/examples/ButtonSmall.tsx @@ -3,19 +3,19 @@ import { Button } from '@patternfly/react-core'; export const ButtonSmall: React.FunctionComponent = () => ( - {' '} - {' '} - {' '} - {' '} -
diff --git a/packages/react-integration/demo-app-ts/src/components/demos/ButtonDemo/ButtonDemo.tsx b/packages/react-integration/demo-app-ts/src/components/demos/ButtonDemo/ButtonDemo.tsx index 43367da1580..2486dfa8da7 100644 --- a/packages/react-integration/demo-app-ts/src/components/demos/ButtonDemo/ButtonDemo.tsx +++ b/packages/react-integration/demo-app-ts/src/components/demos/ButtonDemo/ButtonDemo.tsx @@ -121,10 +121,10 @@ export class ButtonDemo extends React.Component { Aria-disabled with tooltip - - diff --git a/packages/react-core/src/components/Button/Button.tsx b/packages/react-core/src/components/Button/Button.tsx index 050bf81873e..0c035a736b6 100644 --- a/packages/react-core/src/components/Button/Button.tsx +++ b/packages/react-core/src/components/Button/Button.tsx @@ -23,9 +23,9 @@ export enum ButtonType { } export enum ButtonSize { - default = 'default', - small = 'small', - large = 'large' + sm = 'sm', + md = 'md', + lg = 'lg' } export interface BadgeCountObject { @@ -37,7 +37,7 @@ export interface BadgeCountObject { className?: string; } -export interface ButtonProps extends Omit, 'ref'>, OUIAProps { +export interface ButtonProps extends Omit, 'ref' | 'size'>, OUIAProps { /** Content rendered inside the button */ children?: React.ReactNode; /** Additional classes added to the button */ @@ -64,6 +64,8 @@ export interface ButtonProps extends Omit, 'r inoperableEvents?: string[]; /** Adds inline styling to a link button */ isInline?: boolean; + /** Adds small or large styling to the button */ + size?: 'sm' | 'md' | 'lg'; /** Sets button type */ type?: 'button' | 'submit' | 'reset'; /** Adds button variant styles */ @@ -76,8 +78,6 @@ export interface ButtonProps extends Omit, 'r icon?: React.ReactNode | null; /** Sets the button tabindex. */ tabIndex?: number; - /** Adds small or large styling to the button */ - customSize?: 'default' | 'small' | 'large'; /** Adds danger styling to secondary or link button variants */ isDanger?: boolean; /** Forwarded ref */ @@ -103,7 +103,7 @@ const ButtonBase: React.FunctionComponent = ({ spinnerAriaValueText, spinnerAriaLabelledBy, spinnerAriaLabel, - customSize = ButtonSize.default, + size = ButtonSize.md, inoperableEvents = ['onClick', 'onKeyPress'], isInline = false, type = ButtonType.button, @@ -160,8 +160,8 @@ const ButtonBase: React.FunctionComponent = ({ isDanger && (variant === ButtonVariant.secondary || variant === ButtonVariant.link) && styles.modifiers.danger, isLoading !== null && children !== null && styles.modifiers.progress, isLoading && styles.modifiers.inProgress, - customSize === ButtonSize.small && styles.modifiers.small, - customSize === ButtonSize.large && styles.modifiers.displayLg, + size === ButtonSize.sm && styles.modifiers.small, + size === ButtonSize.lg && styles.modifiers.displayLg, className )} disabled={isButtonElement ? isDisabled : null} diff --git a/packages/react-core/src/components/Button/__tests__/Button.test.tsx b/packages/react-core/src/components/Button/__tests__/Button.test.tsx index 843d283af1c..7625dd1890c 100644 --- a/packages/react-core/src/components/Button/__tests__/Button.test.tsx +++ b/packages/react-core/src/components/Button/__tests__/Button.test.tsx @@ -84,13 +84,13 @@ describe('Button', () => { expect(asFragment()).toMatchSnapshot(); }); - test('customSize small', () => { - const { asFragment } = render(); + test('size small', () => { + const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); - test('customSize large', () => { - const { asFragment } = render(); + test('size large', () => { + const { asFragment } = render(); expect(asFragment()).toMatchSnapshot(); }); diff --git a/packages/react-core/src/components/Button/__tests__/__snapshots__/Button.test.tsx.snap b/packages/react-core/src/components/Button/__tests__/__snapshots__/Button.test.tsx.snap index 34a410e715b..e21b606d3ca 100644 --- a/packages/react-core/src/components/Button/__tests__/__snapshots__/Button.test.tsx.snap +++ b/packages/react-core/src/components/Button/__tests__/__snapshots__/Button.test.tsx.snap @@ -31,36 +31,6 @@ exports[`Button control button 1`] = `
`; -exports[`Button customSize large 1`] = ` - - - -`; - -exports[`Button customSize small 1`] = ` - - - -`; - exports[`Button danger button 1`] = ` + +`; + +exports[`Button size small 1`] = ` + + + +`; + exports[`Button tertiary button 1`] = ` {' '} - {' '} - {' '} -
diff --git a/packages/react-core/src/components/Button/examples/ButtonSmall.tsx b/packages/react-core/src/components/Button/examples/ButtonSmall.tsx index aa4b3ec6d08..b4a1d30c048 100644 --- a/packages/react-core/src/components/Button/examples/ButtonSmall.tsx +++ b/packages/react-core/src/components/Button/examples/ButtonSmall.tsx @@ -3,19 +3,19 @@ import { Button } from '@patternfly/react-core'; export const ButtonSmall: React.FunctionComponent = () => ( - {' '} - {' '} - {' '} - {' '} -
diff --git a/packages/react-integration/demo-app-ts/src/components/demos/ButtonDemo/ButtonDemo.tsx b/packages/react-integration/demo-app-ts/src/components/demos/ButtonDemo/ButtonDemo.tsx index 2486dfa8da7..2b2d9b739fe 100644 --- a/packages/react-integration/demo-app-ts/src/components/demos/ButtonDemo/ButtonDemo.tsx +++ b/packages/react-integration/demo-app-ts/src/components/demos/ButtonDemo/ButtonDemo.tsx @@ -1,5 +1,6 @@ import React from 'react'; import { Button, ButtonProps, Tooltip } from '@patternfly/react-core'; +import { ButtonSize } from '@patternfly/react-core/src/components/Button'; import PlusCircleIcon from '@patternfly/react-icons/dist/esm/icons/plus-circle-icon'; import ExternalLinkAltIcon from '@patternfly/react-icons/dist/esm/icons/external-link-alt-icon'; import '@patternfly/react-styles/css/utilities/Spacing/spacing.css'; @@ -121,10 +122,10 @@ export class ButtonDemo extends React.Component { Aria-disabled with tooltip - -