Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
118 changes: 64 additions & 54 deletions packages/ui/src/button/stories/index.story.tsx

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a dedicated story? In particular, since we have some pretty specific guidance around how this variant should be used, I wonder how we'd want to go about communicating that guidance?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

197e678

More in general, I feel like we may actually remove some stories, since we can expect consumers to use Storybook controls to check all tones/variants. We can still keep the "matrix" story though, as it's a nice recap.

Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@ export const Neutral: Story = {
},
};

export const NeutralOutline: Story = {
/**
* Destructive buttons should be used for high-stakes, irreversible actions.
*/
export const Destructive: Story = {
...Default,
args: {
...Default.args,
tone: 'neutral',
variant: 'outline',
children: 'Permanently delete',
tone: 'destructive',
},
};

Expand All @@ -92,57 +95,64 @@ export const AllTonesAndVariants: Story = {
<div></div>
<div style={ { textAlign: 'center' } }>Resting</div>
<div style={ { textAlign: 'center' } }>Disabled</div>
{ ( [ 'brand', 'neutral' ] as const ).map( ( tone ) => (

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only actual change in the file, the rest is whitespace

<Fragment key={ tone }>
{ (
[ 'solid', 'outline', 'minimal', 'unstyled' ] as const
).map( ( variant ) => (
<Fragment key={ variant }>
<div
style={ {
paddingInlineEnd: '1rem',
display: 'flex',
alignItems: 'center',
} }
>
{ variant }, { tone }
</div>
<div
style={ {
padding: '0.5rem 1rem',
display: 'flex',
alignItems: 'center',
} }
>
<Button
{ ...args }
tone={ tone }
variant={ variant }
/>
</div>
<div
style={ {
padding: '0.5rem 1rem',
display: 'flex',
alignItems: 'center',
} }
>
<Button
{ ...args }
tone={ tone }
variant={ variant }
// Disabling because this lint rule was meant for the
// `@wordpress/components` Button, but is being applied here.
// TODO: rework the lint rule so that it checks the package
// where the Button comes from.
// eslint-disable-next-line no-restricted-syntax
disabled
/>
</div>
</Fragment>
) ) }
</Fragment>
) ) }
{ ( [ 'brand', 'neutral', 'destructive' ] as const ).map(
( tone ) => (
<Fragment key={ tone }>
{ (
[
'solid',
'outline',
'minimal',
'unstyled',
] as const
).map( ( variant ) => (
<Fragment key={ variant }>
<div
style={ {
paddingInlineEnd: '1rem',
display: 'flex',
alignItems: 'center',
} }
>
{ variant }, { tone }
</div>
<div
style={ {
padding: '0.5rem 1rem',
display: 'flex',
alignItems: 'center',
} }
>
<Button
{ ...args }
tone={ tone }
variant={ variant }
/>
</div>
<div
style={ {
padding: '0.5rem 1rem',
display: 'flex',
alignItems: 'center',
} }
>
<Button
{ ...args }
tone={ tone }
variant={ variant }
// Disabling because this lint rule was meant for the
// `@wordpress/components` Button, but is being applied here.
// TODO: rework the lint rule so that it checks the package
// where the Button comes from.
// eslint-disable-next-line no-restricted-syntax
disabled
/>
</div>
</Fragment>
) ) }
</Fragment>
)
) }
</div>
),
};
Expand Down
33 changes: 33 additions & 0 deletions packages/ui/src/button/style.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,39 @@
}
}

.is-destructive {
&.is-solid {
--wp-ui-button-background-color: var(--wpds-color-bg-interactive-error-strong);
--wp-ui-button-background-color-active: var(--wpds-color-bg-interactive-error-strong-active);
--wp-ui-button-background-color-disabled: var(--wpds-color-bg-interactive-error-strong-disabled);
--wp-ui-button-foreground-color: var(--wpds-color-fg-interactive-error-strong);
--wp-ui-button-foreground-color-active: var(--wpds-color-fg-interactive-error-strong-active);
--wp-ui-button-foreground-color-disabled: var(--wpds-color-fg-interactive-error-strong-disabled);
}

/* Outline and minimal buttons use the same foreground color */
&.is-outline,
&.is-minimal {
--wp-ui-button-foreground-color: var(--wpds-color-fg-interactive-error);
--wp-ui-button-foreground-color-active: var(--wpds-color-fg-interactive-error-active);
--wp-ui-button-foreground-color-disabled: var(--wpds-color-fg-interactive-error-disabled);
}

&.is-outline {
--wp-ui-button-background-color: var(--wpds-color-bg-interactive-error);
--wp-ui-button-background-color-active: var(--wpds-color-bg-interactive-error-active);
--wp-ui-button-background-color-disabled: var(--wpds-color-bg-interactive-error-disabled);
--wp-ui-button-border-color: var(--wpds-color-stroke-interactive-error);
--wp-ui-button-border-color-active: var(--wpds-color-stroke-interactive-error-active);
}

&.is-minimal {
--wp-ui-button-background-color: var(--wpds-color-bg-interactive-error-weak);
--wp-ui-button-background-color-active: var(--wpds-color-bg-interactive-error-weak-active);
--wp-ui-button-background-color-disabled: var(--wpds-color-bg-interactive-error-weak-disabled);
}
}

.is-unstyled {
border: none;
background: none;
Expand Down
7 changes: 5 additions & 2 deletions packages/ui/src/button/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ export interface ButtonProps
variant?: 'solid' | 'outline' | 'minimal' | 'unstyled';

/**
* The tone of the button. Tone describes a semantic color intent.
* The tone of the button:
*
* - `'brand': for the most prominent actions, using the brand colors.
* - `'neutral'` for less prominent actions.
* - `'destructive'`: for high-stakes, irreversible actions.
* @default "brand"
*/
tone?: 'brand' | 'neutral';
tone?: 'brand' | 'neutral' | 'destructive';

/**
* The size of the button.
Expand Down
Loading