Skip to content

Commit

Permalink
feat: busy state for button
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbert committed Sep 19, 2021
1 parent b69b853 commit 48c5a17
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 6 deletions.
11 changes: 10 additions & 1 deletion components/button/bem.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@
import clsx from 'clsx';

export const defaultArgs = {
busy: false,
disabled: false,
focus: false,
hover: false,
textContent: '',
type: 'button',
};

export const Button = ({ textContent = '', focus = false, hover = false, disabled = false, type = 'button' }) =>
export const Button = ({
textContent = '',
busy = false,
focus = false,
hover = false,
disabled = false,
type = 'button',
}) =>
`<button class="${clsx('utrecht-button', {
'utrecht-button--busy': busy,
'utrecht-button--hover': hover,
'utrecht-button--focus': focus,
'utrecht-button--disabled': disabled,
Expand Down
4 changes: 4 additions & 0 deletions components/button/bem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
cursor: var(--utrecht-action-submit-cursor);
}

.utrecht-button--busy {
cursor: var(--utrecht-action-busy-cursor);
}

.utrecht-button:disabled,
.utrecht-button--disabled {
background-color: var(--utrecht-button-disabled-background-color);
Expand Down
23 changes: 23 additions & 0 deletions components/button/bem.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import "./bem.scss";
description: "Button text",
control: "text",
},
busy: {
description: "Busy",
control: "boolean",
},
focus: {
description: "Focus",
control: "boolean",
Expand Down Expand Up @@ -106,3 +110,22 @@ Styling via the `.utrecht-button--disabled` class name:
{Button.bind({})}
</Story>
</Canvas>

### Busy

Styling via the `.utrecht-button--busy` class name:

<Canvas>
<Story
name="Button busy"
args={{
busy: true,
textContent: "Read more...",
}}
parameters={{
percy: { skip: true },
}}
>
{Button.bind({})}
</Story>
</Canvas>
7 changes: 5 additions & 2 deletions components/button/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
*/

export const defaultArgs = {
busy: false,
disabled: false,
textContent: '',
type: 'button',
};

export const Button = ({ disabled = false, textContent = '', type = 'button' }) =>
`<button type="${type || 'button'}"${disabled ? ' disabled' : ''}>${textContent}</button>`;
export const Button = ({ busy = false, disabled = false, textContent = '', type = 'button' }) =>
`<button type="${type || 'button'}"${busy ? ' aria-busy="true"' : ''}${
disabled ? ' disabled' : ''
}>${textContent}</button>`;
4 changes: 4 additions & 0 deletions components/button/html.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
@extend .utrecht-button--submit;
}

.utrecht-html button[aria-busy="true"] {
@extend .utrecht-button--busy;
}

.utrecht-html button:hover {
@extend .utrecht-button--hover;
}
Expand Down
48 changes: 48 additions & 0 deletions components/button/html.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { defaultArgs, Button } from "./html";
description: "Content of the button",
control: "text",
},
disabled: {
description: "Busy",
control: "boolean",
},
disabled: {
description: "Disabled",
control: "boolean",
Expand Down Expand Up @@ -53,6 +57,10 @@ Styling via the `<button>` element:

<ArgsTable story="Button" />

## States

### Disabled

Button with `disabled` state:

<Canvas>
Expand All @@ -66,3 +74,43 @@ Button with `disabled` state:
{Button.bind({})}
</Story>
</Canvas>

### Busy

Button with `aria-busy` state:

<Canvas>
<Story
name="Busy button"
args={{
busy: true,
textContent: "The Quick Brown Fox Jumps Over The Lazy Dog",
}}
parameters={{
percy: { skip: true },
}}
>
{Button.bind({})}
</Story>
</Canvas>

## Types

### Submit

Button with `submit` type:

<Canvas>
<Story
name="Submit button"
args={{
textContent: "The Quick Brown Fox Jumps Over The Lazy Dog",
type: "submit",
}}
parameters={{
percy: { skip: true },
}}
>
{Button.bind({})}
</Story>
</Canvas>
41 changes: 38 additions & 3 deletions components/button/stencil.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@ import { Meta, Story, Canvas, ArgsTable } from "@storybook/addon-docs";

import "./bem.scss";

export const Template = ({ disabled = false, textContent = "", type = "" }) =>
`<utrecht-button${disabled ? " disabled" : ""}${type ? ` type="${type}"` : ""}>${textContent}</utrecht-button>`;
export const defaultArgs = {
busy: false,
disabled: false,
textContent: "",
type: "",
};

export const Template = ({ busy = false, disabled = false, textContent = "", type = "" }) =>
`<utrecht-button${busy ? ' busy="true"' : ""}${disabled ? " disabled" : ""}${
type ? ` type="${type}"` : ""
}>${textContent}</utrecht-button>`;

<Meta
title="Web Component/Button"
Expand All @@ -18,6 +27,10 @@ export const Template = ({ disabled = false, textContent = "", type = "" }) =>
description: "Button text",
control: "text",
},
busy: {
description: "Busy",
control: "boolean",
},
disabled: {
description: "Disabled",
control: "boolean",
Expand Down Expand Up @@ -46,7 +59,7 @@ export const Template = ({ disabled = false, textContent = "", type = "" }) =>
<Story
name="Button"
args={{
disabled: false,
...defaultArgs,
textContent: "Read more...",
type: "",
}}
Expand All @@ -61,10 +74,32 @@ export const Template = ({ disabled = false, textContent = "", type = "" }) =>
<Story
name="Submit button"
args={{
...defaultArgs,
textContent: "Send",
type: "submit",
}}
>
{Template.bind({})}
</Story>
</Canvas>

## State

### Busy

<Canvas>
<Story
name="Busy button"
args={{
...defaultArgs,
busy: true,
textContent: "Send",
type: "submit",
}}
parameters={{
percy: { skip: true },
}}
>
{Template.bind({})}
</Story>
</Canvas>
3 changes: 3 additions & 0 deletions components/button/stencil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import clsx from "clsx";
shadow: true,
})
export class Button {
@Prop() busy: boolean;
@Prop() disabled: boolean;
@Event({ cancelable: true }) utrechtRequestReset: EventEmitter;
@Event({ cancelable: true }) utrechtRequestSubmit: EventEmitter;
Expand Down Expand Up @@ -40,9 +41,11 @@ export class Button {
<button
class={clsx(
"utrecht-button",
this.busy && "utrecht-button--busy",
this.disabled && "utrecht-button--disabled",
this.type === "submit" && "utrecht-button--submit"
)}
aria-busy={this.busy ? "true" : null}
disabled={this.disabled}
type={this.type || "button"}
onClick={handleClick}
Expand Down
8 changes: 8 additions & 0 deletions components/common/action.tokens.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"utrecht": {
"action": {
"busy": {
"cursor": {
"css": {
"syntax": "*",
"inherits": true
}
}
},
"disabled": {
"cursor": {
"css": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"utrecht": {
"action": {
"busy": { "cursor": { "value": "wait" } },
"disabled": { "cursor": { "value": "not-allowed" } },
"submit": { "cursor": { "value": "pointer" } }
}
Expand Down

0 comments on commit 48c5a17

Please sign in to comment.