Skip to content

Commit

Permalink
feat(buttonpill): add disabled outline property
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisadubois committed Dec 13, 2024
1 parent 830e8f7 commit bff5f17
Show file tree
Hide file tree
Showing 9 changed files with 263 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/components/ButtonGroup/ButtonGroup.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,15 @@ AudioVideoControls.parameters = {
},
{
children: [
<ButtonPill outline ghost key="0" size={40} style={{ minWidth: '6.8rem' }}>
<ButtonPill
disabled
outline
disabledOutline
ghost
key="0"
size={40}
style={{ minWidth: '6.8rem' }}
>
<Icon
key="0"
name="microphone-muted"
Expand Down Expand Up @@ -247,7 +255,15 @@ AudioVideoControls.parameters = {
},
{
children: [
<ButtonPill outline ghost key="0" size={40} style={{ minWidth: '8.3rem' }}>
<ButtonPill
outline
disabled
disabledOutline
ghost
key="0"
size={40}
style={{ minWidth: '8.3rem' }}
>
<Icon key="0" name="camera-muted" strokeColor="#FC8B98" autoScale={125} />
<div key="1">Start Video</div>
</ButtonPill>,
Expand All @@ -261,7 +277,7 @@ AudioVideoControls.parameters = {
{
children: [
<ButtonPill outline ghost key="0" size={40} style={{ minWidth: '8.3rem' }}>
<Icon key="0" name="camera-muted" strokeColor="#FC8B98" autoScale={125} />
<Icon key="0" name="camera-on" autoScale={125} />
<div key="1">Long Label Possibly German</div>
</ButtonPill>,
<ButtonCircle outline ghost key="1" size={40}>
Expand All @@ -275,7 +291,7 @@ AudioVideoControls.parameters = {
children: [
<div key="0" {...ButtonGroup.CHILD_PROPS} style={{ fontSize: '0.8rem' }} data-compressed>
<ButtonPill outline ghost size={40} style={{ minWidth: '8.3rem' }}>
<Icon key="0" name="camera-muted" strokeColor="#FC8B98" autoScale={125} />
<Icon key="0" name="camera-on" autoScale={125} />
<div key="1">Long Label Possibly German</div>
</ButtonPill>
</div>,
Expand Down
1 change: 1 addition & 0 deletions src/components/ButtonPill/ButtonPill.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const CLASS_PREFIX = 'md-button-pill';
const DEFAULTS = {
COLOR: 'primary',
DISABLED: false,
DISABLED_OUTLINE: false,
SHALLOW_DISABLED: false,
GHOST: false,
GROWN: false,
Expand Down
14 changes: 14 additions & 0 deletions src/components/ButtonPill/ButtonPill.stories.args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ export default {
},
},
},
disabledOutline: {
description:
'Whether to render the `<ButtonPill />` with an outline even when disabled/shallowDisabled. Respects existing outline prop and will not display outline if outline is false.',
options: [true, false],
control: { type: 'boolean' },
table: {
type: {
summary: 'boolean',
},
defaultValue: {
summary: CONSTANTS.DEFAULTS.SHALLOW_DISABLED,
},
},
},
ghost: {
description: 'Whether this component has a transparent background.',
options: [true, false],
Expand Down
12 changes: 12 additions & 0 deletions src/components/ButtonPill/ButtonPill.style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@
cursor: auto;
}

&[data-disabled-outline='true'] {
border-color: var(--mds-color-theme-outline-button-normal);
}

// C.1 color = join
&[data-color='join'] {
border-color: var(--mds-color-theme-outline-join-normal);
Expand Down Expand Up @@ -397,6 +401,10 @@
cursor: auto;
}

&[data-disabled-outline='true'] {
border-color: var(--mds-color-theme-outline-button-normal);
}

// E.2 color = join
&[data-color='join'] {
background-color: var(--mds-color-theme-button-secondary-normal);
Expand Down Expand Up @@ -518,6 +526,10 @@
cursor: auto;
}

&[data-disabled-outline='true'] {
border-color: var(--mds-color-theme-outline-button-normal);
}

// F.2 color = join
&[data-color='join'] {
background-color: var(--mds-color-theme-inverted-button-primary-normal);
Expand Down
2 changes: 2 additions & 0 deletions src/components/ButtonPill/ButtonPill.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const ButtonPill = forwardRef((props: Props, providedRef: RefObject<HTMLButtonEl
className,
color,
disabled,
disabledOutline,
shallowDisabled,
ghost,
grown,
Expand All @@ -37,6 +38,7 @@ const ButtonPill = forwardRef((props: Props, providedRef: RefObject<HTMLButtonEl
data-outline={outline || DEFAULTS.OUTLINE}
data-size={size || DEFAULTS.SIZE}
data-inverted={inverted || DEFAULTS.INVERTED}
data-disabled-outline={disabledOutline || DEFAULTS.DISABLED_OUTLINE}
isDisabled={disabled}
{...otherProps}
/>
Expand Down
5 changes: 5 additions & 0 deletions src/components/ButtonPill/ButtonPill.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export interface Props extends ButtonSimpleProps {
*/
disabled?: boolean;

/**
* Whether or not this ButtonPill has an outline even when disabled. Respects existing outline prop and will not display outline if outline is false.
*/
disabledOutline?: boolean;

/**
* Whether or not this ButtonPill should look disabled, but allowing actions like onPress to be passed.
*/
Expand Down
38 changes: 38 additions & 0 deletions src/components/ButtonPill/ButtonPill.unit.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,32 @@ describe('<ButtonPill />', () => {
expect(container).toMatchSnapshot();
});

it('should match snapshot when disabledOutline', () => {
expect.assertions(1);

const disabledOutline = !DEFAULTS.DISABLED_OUTLINE;

container = mount(<ButtonPill disabledOutline={disabledOutline}>Example Text</ButtonPill>);

expect(container).toMatchSnapshot();
});

it('should match snapshot when disabledOutline and disabled and outline', () => {
expect.assertions(1);

const disabledOutline = !DEFAULTS.DISABLED_OUTLINE;
const outline = !DEFAULTS.OUTLINE;
const disabled = !DEFAULTS.DISABLED;

container = mount(
<ButtonPill outline={outline} disabled={disabled} disabledOutline={disabledOutline}>
Example Text
</ButtonPill>
);

expect(container).toMatchSnapshot();
});

it('should match snapshot when a ghost', () => {
expect.assertions(1);

Expand Down Expand Up @@ -232,6 +258,18 @@ describe('<ButtonPill />', () => {
expect(element.getAttribute('aria-disabled')).toBe('true');
});

it('should pass disabled outline prop', () => {
expect.assertions(1);

const disabledOutline = !DEFAULTS.DISABLED_OUTLINE;

const element = mount(<ButtonPill disabledOutline={disabledOutline} />)
.find(ButtonPill)
.getDOMNode();

expect(element.getAttribute('data-disabled-outline')).toBe(`${disabledOutline}`);
});

it('should pass ghost prop', () => {
expect.assertions(1);

Expand Down
Loading

0 comments on commit bff5f17

Please sign in to comment.