Skip to content

Commit

Permalink
test(Button): add v2 stories for disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
booc0mtaco committed Mar 13, 2024
1 parent b33ddb1 commit 3501592
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
28 changes: 25 additions & 3 deletions src/components/Button/Button-v2.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import React from 'react';
import { Button } from './Button-v2';
import { SIZES } from '../ClickableStyle';

// TODO-AH: add documentation to each story

export default {
title: 'Components/Button (v2)',
component: Button,
Expand Down Expand Up @@ -60,6 +62,14 @@ export const DefaultRanks: StoryObj<Args> = {
},
};

export const Disabled: StoryObj<Args> = {
args: {
...DefaultRanks.args,
isDisabled: true,
},
render: DefaultRanks.render,
};

export const TertiaryStandalone: StoryObj<Args> = {
args: {
rank: 'tertiary',
Expand All @@ -82,7 +92,11 @@ export const InverseRanks: StoryObj<Args> = {
},
render: DefaultRanks.render,
// TODO-AH: find a cleaner way to decorate with unavailable tokens using parameters:backgounds:
decorators: [(Story) => <div className="bg-[#0F2163] p-1">{Story()}</div>],
decorators: [
(Story) => (
<div className="bg-[var(--eds-color-blue-850)] p-1">{Story()}</div>
),
],
};

export const Sizes: StoryObj<Args> = {
Expand Down Expand Up @@ -122,6 +136,10 @@ export const LoadingStates: StoryObj<Args> = {
render: Sizes.render,
};

/**
* `iconLayout` lets you place the icons adjacent to button text, or as the only visible element.
* When using `"icon-only"`, you **must** include a label (e.g., via `aria-label`).
*/
export const IconLayouts: StoryObj<Args> = {
args: {
...Default.args,
Expand All @@ -135,8 +153,12 @@ export const IconLayouts: StoryObj<Args> = {
<Button {...args} iconLayout="right">
Right
</Button>
<Button {...args} iconLayout="icon-only">
Icon Only
<Button
{...args}
aria-label="Label must be applied with icon-only layout"
iconLayout="icon-only"
>
Icon Only (text not visible)
</Button>
</div>
);
Expand Down
7 changes: 0 additions & 7 deletions src/components/Button/Button-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,11 @@ export const Button = forwardRef<HTMLButtonElement, ButtonV2Props>(
isLoading && styles['button--is-loading'],
);

const ariaLabel =
iconLayout === 'icon-only' && !other['aria-label']
? children
: other['aria-label'];

return (
<button
aria-label={ariaLabel}
className={componentClassName}
disabled={isDisabled}
ref={ref}
tabIndex={isDisabled ? -1 : undefined}
type={type}
{...other}
>
Expand Down

0 comments on commit 3501592

Please sign in to comment.