Skip to content

Commit

Permalink
Merge pull request #1424 from dhis2/button-secondary-destructive
Browse files Browse the repository at this point in the history
feat(button): add destructive, secondary button type
  • Loading branch information
cooper-joe authored Nov 27, 2023
2 parents 79d1233 + b72a04a commit 838610b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 33 deletions.
14 changes: 5 additions & 9 deletions components/button/src/button/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,9 @@ Button.propTypes = {
*/
dataTest: PropTypes.string,
/**
* Indicates that the button makes potentially dangerous
* deletions or data changes.
* Mutually exclusive with `primary` and `secondary` props
* Applies 'destructive' button appearance, implying a dangerous action.
*/
destructive: sharedPropTypes.buttonVariantPropType,
destructive: PropTypes.bool,
/** Applies a greyed-out appearance and makes the button non-interactive */
disabled: PropTypes.bool,
/** An icon element to display inside the button */
Expand All @@ -121,15 +119,13 @@ Button.propTypes = {
*/
name: PropTypes.string,
/**
* Applies 'primary' button appearance.
* Mutually exclusive with `destructive` and `secondary` props
* Applies 'primary' button appearance, implying the most important action.
*/
primary: sharedPropTypes.buttonVariantPropType,
primary: PropTypes.bool,
/**
* Applies 'secondary' button appearance.
* Mutually exclusive with `primary` and `destructive` props
*/
secondary: sharedPropTypes.buttonVariantPropType,
secondary: PropTypes.bool,
/** Makes the button small. Mutually exclusive with `large` prop */
small: sharedPropTypes.sizePropType,
/** Tab index for focusing the button with a keyboard */
Expand Down
6 changes: 6 additions & 0 deletions components/button/src/button/button.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ Destructive.parameters = {
},
},
}
export const DestructiveSecondary = Template.bind({})
DestructiveSecondary.args = {
destructive: true,
secondary: true,
name: 'Destructive secondary button',
}

export const Disabled = (args) => (
<>
Expand Down
29 changes: 29 additions & 0 deletions components/button/src/button/button.styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,35 @@ export default css`
fill: ${colors.white};
}
.destructive.secondary {
border-color: rgba(74, 87, 104, 0.25);
background: transparent;
color: ${colors.red700};
fill: ${colors.red700};
font-weight: 400;
}
.destructive.secondary:hover {
border-color: ${colors.red600};
background: ${colors.red050};
color: ${colors.red800};
fill: ${colors.red800};
}
.destructive.secondary:active,
.destructive.secondary:active:focus {
background: ${colors.red100};
border-color: ${colors.red700};
box-shadow: none;
}
.destructive.secondary:disabled {
background: transparent;
border-color: rgba(74, 87, 104, 0.25);
color: rgba(183, 28, 28, 0.6);
fill: rgba(183, 28, 28, 0.6);
}
.icon-only {
padding: 0 0 0 5px;
}
Expand Down
22 changes: 0 additions & 22 deletions constants/src/shared-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,6 @@ export const statusArgType = {
control: { type: 'boolean' },
}

/**
* Button variant propType
* @return {PropType} Mutually exclusive variants:
* primary/secondary/destructive
*/
export const buttonVariantPropType = mutuallyExclusive(
['primary', 'secondary', 'destructive'],
PropTypes.bool
)
export const buttonVariantArgType = {
// No description because it should be set for the component description
table: {
type: {
summary: 'bool',
detail: "'primary', 'secondary', and 'destructive' are mutually exclusive props",
},
},
control: {
type: 'boolean',
},
}

/**
* Size variant propType
* @return {PropType} Mutually exclusive variants:
Expand Down
8 changes: 6 additions & 2 deletions docs/docs/components/button.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Buttons are used to trigger actions. There are different button variants that ar
| ------------- | -------------------------------------------------------------------------------------------------------------------------- |
| `Basic` | Default. Will suit the majority of actions on a page. |
| `Primary` | Use for the most important action on a page, like a _Save data_ button in a form. Only use one `primary` button on a page. |
| `Secondary` | Use for less important actions, usually in combination with other buttons. |
| `Secondary` | Use for less important actions, usually in combination with other buttons. Can be applied to `Destructive`. |
| `Destructive` | Only for primary-type actions that will delete or destroy something. Don't use several on a single page. |

#### Basic
Expand Down Expand Up @@ -67,12 +67,16 @@ Buttons are used to trigger actions. There are different button variants that ar
#### Destructive

<Demo>
<Button destructive>Destructive button</Button>
<div class="stacked-examples-horizontal">
<Button destructive>Destructive button</Button>
<Button destructive secondary>Destructive secondary button</Button>
</div>
</Demo>

- Only use for primary-type actions that will destroy data.
- Don't use if the action will only remove an item from the current context.
- Only use a one `destructive` button per page.
- `Destructive secondary` can be used more than once per page for less important destructive actions.

### Format

Expand Down

0 comments on commit 838610b

Please sign in to comment.