Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const AccordionBordered: React.FunctionComponent = () => {
Proin dictum imperdiet nibh, quis dapibus nulla. Integer sed tincidunt lectus, sit amet auctor eros.
</AccordionExpandedContentBody>
<AccordionExpandedContentBody>
<Button variant="link" isLarge isInline>
<Button variant="link" size="lg" isInline>
Call to action <ArrowRightIcon />
</Button>
</AccordionExpandedContentBody>
Expand Down
21 changes: 12 additions & 9 deletions packages/react-core/src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export enum ButtonType {
reset = 'reset'
}

export enum ButtonSize {
sm = 'sm',
md = 'md',
lg = 'lg'
}

export interface BadgeCountObject {
/** Adds styling to the badge to indicate it has been read */
isRead?: boolean;
Expand All @@ -31,7 +37,7 @@ export interface BadgeCountObject {
className?: string;
}

export interface ButtonProps extends Omit<React.HTMLProps<HTMLButtonElement>, 'ref'>, OUIAProps {
export interface ButtonProps extends Omit<React.HTMLProps<HTMLButtonElement>, 'ref' | 'size'>, OUIAProps {
/** Content rendered inside the button */
children?: React.ReactNode;
/** Additional classes added to the button */
Expand All @@ -58,6 +64,8 @@ export interface ButtonProps extends Omit<React.HTMLProps<HTMLButtonElement>, '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 */
Expand All @@ -70,10 +78,6 @@ export interface ButtonProps extends Omit<React.HTMLProps<HTMLButtonElement>, '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 danger styling to secondary or link button variants */
isDanger?: boolean;
/** Forwarded ref */
Expand All @@ -99,8 +103,7 @@ const ButtonBase: React.FunctionComponent<ButtonProps> = ({
spinnerAriaValueText,
spinnerAriaLabelledBy,
spinnerAriaLabel,
isSmall = false,
isLarge = false,
size = ButtonSize.md,
inoperableEvents = ['onClick', 'onKeyPress'],
isInline = false,
type = ButtonType.button,
Expand Down Expand Up @@ -157,8 +160,8 @@ const ButtonBase: React.FunctionComponent<ButtonProps> = ({
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,
size === ButtonSize.sm && styles.modifiers.small,
size === ButtonSize.lg && styles.modifiers.displayLg,
className
)}
disabled={isButtonElement ? isDisabled : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ describe('Button', () => {
expect(asFragment()).toMatchSnapshot();
});

test('isSmall', () => {
const { asFragment } = render(<Button isSmall>Small Button</Button>);
test('size small', () => {
const { asFragment } = render(<Button size="sm">Small Button</Button>);
expect(asFragment()).toMatchSnapshot();
});

test('isLarge', () => {
const { asFragment } = render(<Button isLarge>Large Button</Button>);
test('size large', () => {
const { asFragment } = render(<Button size="lg">Large Button</Button>);
expect(asFragment()).toMatchSnapshot();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,6 @@ exports[`Button isInline 1`] = `
</DocumentFragment>
`;

exports[`Button isLarge 1`] = `
<DocumentFragment>
<button
aria-disabled="false"
class="pf-c-button pf-m-primary pf-m-display-lg"
data-ouia-component-id="OUIA-Generated-Button-primary-8"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
type="button"
>
Large Button
</button>
</DocumentFragment>
`;

exports[`Button isLoading 1`] = `
<DocumentFragment>
<button
Expand Down Expand Up @@ -240,21 +225,6 @@ exports[`Button isLoading icon only 1`] = `
</DocumentFragment>
`;

exports[`Button isSmall 1`] = `
<DocumentFragment>
<button
aria-disabled="false"
class="pf-c-button pf-m-primary pf-m-small"
data-ouia-component-id="OUIA-Generated-Button-primary-7"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
type="button"
>
Small Button
</button>
</DocumentFragment>
`;

exports[`Button link button 1`] = `
<DocumentFragment>
<button
Expand Down Expand Up @@ -351,6 +321,36 @@ exports[`Button secondary button 1`] = `
</DocumentFragment>
`;

exports[`Button size large 1`] = `
<DocumentFragment>
<button
aria-disabled="false"
class="pf-c-button pf-m-primary pf-m-display-lg"
data-ouia-component-id="OUIA-Generated-Button-primary-8"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
type="button"
>
Large Button
</button>
</DocumentFragment>
`;

exports[`Button size small 1`] = `
<DocumentFragment>
<button
aria-disabled="false"
class="pf-c-button pf-m-primary pf-m-small"
data-ouia-component-id="OUIA-Generated-Button-primary-7"
data-ouia-component-type="PF4/Button"
data-ouia-safe="true"
type="button"
>
Small Button
</button>
</DocumentFragment>
`;

exports[`Button tertiary button 1`] = `
<DocumentFragment>
<button
Expand Down
4 changes: 2 additions & 2 deletions packages/react-core/src/components/Button/examples/Button.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ To indicate that an action is currently unavailable, all button variations can b

### Small buttons

To fit into tight spaces, primary, secondary, tertiary, danger, and warning button variations can be made smaller using the `isSmall` property.
To fit into tight spaces, primary, secondary, tertiary, danger, and warning button variations can be made smaller using the `"sm"` value for the `size` property.

```ts file="./ButtonSmall.tsx"
```

### Call to action (CTA) buttons

CTA buttons and links direct users to complete an action. Primary, secondary, tertiary, and link button variants can be styled as CTAs using the `isLarge` property.
CTA buttons and links direct users to complete an action. Primary, secondary, tertiary, and link button variants can be styled as CTAs using the `"lg"` value for the `size` property.

```ts file="./ButtonCallToAction.tsx"
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import ArrowRightIcon from '@patternfly/react-icons/dist/esm/icons/arrow-right-i

export const ButtonCallToAction: React.FunctionComponent = () => (
<React.Fragment>
<Button variant="primary" isLarge>
<Button variant="primary" size="lg">
Call to action
</Button>{' '}
<Button variant="secondary" isLarge>
<Button variant="secondary" size="lg">
Call to action
</Button>{' '}
<Button variant="tertiary" isLarge>
<Button variant="tertiary" size="lg">
Call to action
</Button>{' '}
<Button variant="link" isLarge>
<Button variant="link" size="lg">
Call to action <ArrowRightIcon />
</Button>
<br />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ import { Button } from '@patternfly/react-core';

export const ButtonSmall: React.FunctionComponent = () => (
<React.Fragment>
<Button variant="primary" isSmall>
<Button variant="primary" size="sm">
Primary
</Button>{' '}
<Button variant="secondary" isSmall>
<Button variant="secondary" size="sm">
Secondary
</Button>{' '}
<Button variant="tertiary" isSmall>
<Button variant="tertiary" size="sm">
Tertiary
</Button>{' '}
<Button variant="danger" isSmall>
<Button variant="danger" size="sm">
Danger
</Button>{' '}
<Button variant="warning" isSmall>
<Button variant="warning" size="sm">
Warning
</Button>
<br />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Button, ButtonProps, Tooltip } from '@patternfly/react-core';
import { Button, ButtonProps, ButtonSize, Tooltip } from '@patternfly/react-core';
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';
Expand Down Expand Up @@ -121,10 +121,10 @@ export class ButtonDemo extends React.Component<ButtonProps, ButtonDemoState> {
Aria-disabled with tooltip
</Button>
</Tooltip>
<Button {...this.normalButton} id="normal-btn-12" isSmall>
<Button {...this.normalButton} id="normal-btn-12" size={ButtonSize.sm}>
Small button
</Button>
<Button {...this.normalButton} id="normal-btn-13" isLarge>
<Button {...this.normalButton} id="normal-btn-13" size={ButtonSize.lg}>
Large button
</Button>
<Button {...this.normalButton} id="normal-btn-14" variant="warning">
Expand Down