Skip to content

Commit

Permalink
feat(ButtonToggle): implement new icon variant of toggle (#860)
Browse files Browse the repository at this point in the history
* feat(buttontoggle): first implementation of the ButtonToggle component

* test(buttontoggle): added tests

* fix(buttontoggle): fix A11y errors

* refactor(buttontoggle): fix styling bugs in CellBasic
  • Loading branch information
masoudmanson authored Oct 16, 2024
1 parent 8820260 commit 3f532ad
Show file tree
Hide file tree
Showing 26 changed files with 390 additions and 37 deletions.
7 changes: 6 additions & 1 deletion packages/components/src/common/warnings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ export enum SDSWarningTypes {
ButtonMinimalIsAllCaps = "buttonMinimalIsAllCaps",
ButtonMissingSDSProps = "buttonMissingProps",
ButtonIconMissingIconProp = "buttonIconMissingIconProp",
ButtonToggleMissingIconProp = "buttonToggleMissingIconProp",
ChipDeprecated = "chipDeprecated",
MenuSelectDeprecated = "menuSelectDeprecated",
TooltipSubtitle = "tooltipSubtitle",
TooltipWidth = "tooltipWidth",
TooltipInverted = "tooltipInverted",
}

const SDS_WARNINGS = {
export const SDS_WARNINGS = {
[SDSWarningTypes.ButtonMinimalIsAllCaps]: {
hasWarned: false,
message:
Expand All @@ -25,6 +26,10 @@ const SDS_WARNINGS = {
message:
"Warning: Buttons with an SDS type of icon require an icon prop to be provided.",
},
[SDSWarningTypes.ButtonToggleMissingIconProp]: {
hasWarned: false,
message: "Warning: Button Toggles require an icon prop to be provided.",
},
[SDSWarningTypes.ChipDeprecated]: {
hasWarned: false,
message: "Warning: <Chip /> will be deprecated and replaced with <Tag />",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exports[`<Autocomplete /> ControlledOpen story renders snapshot 1`] = `
</span>
<button
aria-label="search-button"
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeMedium css-1b01nn3-MuiButtonBase-root-MuiIconButton-root"
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeMedium css-3px3eh-MuiButtonBase-root-MuiIconButton-root"
icon="Search"
tabindex="0"
type="button"
Expand Down Expand Up @@ -160,7 +160,7 @@ exports[`<Autocomplete /> ControlledOpen story renders snapshot 1`] = `
<button
aria-hidden="true"
aria-label="Search Button"
class="MuiButtonBase-root Mui-disabled MuiIconButton-root Mui-disabled MuiIconButton-sizeMedium css-9z0etm-MuiButtonBase-root-MuiIconButton-root"
class="MuiButtonBase-root Mui-disabled MuiIconButton-root Mui-disabled MuiIconButton-sizeMedium css-l19ret-MuiButtonBase-root-MuiIconButton-root"
disabled=""
icon="Search"
tabindex="-1"
Expand Down Expand Up @@ -575,7 +575,7 @@ exports[`<Autocomplete /> ControlledOpen story renders snapshot 1`] = `
<button
aria-hidden="true"
aria-label="Search Button"
class="MuiButtonBase-root Mui-disabled MuiIconButton-root Mui-disabled MuiIconButton-sizeMedium css-9z0etm-MuiButtonBase-root-MuiIconButton-root"
class="MuiButtonBase-root Mui-disabled MuiIconButton-root Mui-disabled MuiIconButton-sizeMedium css-l19ret-MuiButtonBase-root-MuiIconButton-root"
disabled=""
icon="Search"
tabindex="-1"
Expand Down Expand Up @@ -1001,7 +1001,7 @@ exports[`<Autocomplete /> Default story renders snapshot 1`] = `
<button
aria-hidden="false"
aria-label="Search Button"
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeMedium css-1b01nn3-MuiButtonBase-root-MuiIconButton-root"
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeMedium css-3px3eh-MuiButtonBase-root-MuiIconButton-root"
icon="Search"
tabindex="0"
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ exports[`<Banner /> Default story renders snapshot 1`] = `
</div>
<button
aria-label="Close"
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeMedium css-72jt6e-MuiButtonBase-root-MuiIconButton-root"
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeMedium css-14btmof-MuiButtonBase-root-MuiIconButton-root"
icon="XMark"
tabindex="0"
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default {
parameters: {
badges: [BADGE.STABLE],
},
title: "Components/Button",
title: "Components/Buttons/Button",
} as Meta;

// Default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default {
parameters: {
badges: [BADGE.STABLE],
},
title: "Components/ButtonDropdown",
title: "Components/Buttons/ButtonDropdown",
} as Meta;

// Default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`<ButtonIcon /> Default story renders snapshot 1`] = `
<button
aria-label="info"
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeMedium css-zkd9l9-MuiButtonBase-root-MuiIconButton-root"
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeMedium css-1sh3t66-MuiButtonBase-root-MuiIconButton-root"
icon="InfoCircle"
tabindex="0"
type="button"
Expand Down
12 changes: 12 additions & 0 deletions packages/components/src/core/ButtonIcon/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ const small = (props: ButtonIconExtraProps): SerializedStyles => {
const spaces = getSpaces(props);

return css`
${sdsType !== "tertiary"
? `margin: 0 ${spaces?.xxs}px ${spaces?.xxs}px 0;`
: ""}
.MuiSvgIcon-root {
height: ${iconSizes?.s.height}px;
width: ${iconSizes?.s.width}px;
Expand All @@ -137,6 +141,10 @@ const medium = (props: ButtonIconExtraProps): SerializedStyles => {
const spaces = getSpaces(props);

return css`
${sdsType !== "tertiary"
? `margin: 0 ${spaces?.xxs}px ${spaces?.xxs}px 0;`
: ""}
.MuiSvgIcon-root {
height: ${iconSizes?.l.height}px;
width: ${iconSizes?.l.width}px;
Expand All @@ -151,6 +159,10 @@ const large = (props: ButtonIconExtraProps): SerializedStyles => {
const spaces = getSpaces(props);

return css`
${sdsType !== "tertiary"
? `margin: 0 ${spaces?.s}px ${spaces?.s}px 0;`
: ""}
.MuiSvgIcon-root {
height: ${iconSizes?.xl.height}px;
width: ${iconSizes?.xl.height}px;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import CustomSdsIcon from "src/common/storybook/customSdsIcon";
import CustomSvgIcon from "src/common/storybook/customSvgIcon";

export const BUTTON_TOGGLE_EXCLUDED_CONTROLS = [
"sdsSize",
"icon",
"sdsStage",
"sdsType",
];

export const BUTTON_TOGGLE_ICON_OPTIONS = [
"InfoCircle",
"SlidersHorizontal",
"Filter",
"DotsHorizontal",
"LinesHorizontal3",
<CustomSdsIcon key="customSdsIcon" />,
<CustomSvgIcon key="customIcon" />,
];

export const BUTTON_TOGGLE_ICON_LABELS = [
"SDS Icon: InfoCircle (s/m/l)",
"SDS Icon: SlidersHorizontal (m/l)",
"SDS Icon: Filter (s)",
"SDS Icon: DotsHorizontal (s/m/l)",
"SDS Icon: LinesHorizontal3 (s/m/l)",
"Custom SDS Icon (s/m/l)",
"Custom SVG Icon (s/m/l)",
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { Args, Meta } from "@storybook/react";
import { BADGE } from "@geometricpanda/storybook-addon-badges";
import { ButtonToggle } from "./stories/default";
import {
BUTTON_TOGGLE_EXCLUDED_CONTROLS,
BUTTON_TOGGLE_ICON_LABELS,
BUTTON_TOGGLE_ICON_OPTIONS,
} from "./constants";
import { TestDemo } from "./stories/test";

export default {
argTypes: {
disabled: {
control: {
type: "boolean",
},
},
icon: {
control: {
labels: BUTTON_TOGGLE_ICON_LABELS,
type: "select",
},
mapping: BUTTON_TOGGLE_ICON_OPTIONS,
options: Object.keys(BUTTON_TOGGLE_ICON_OPTIONS),
},
sdsSize: {
control: {
type: "select",
},
options: ["small", "medium", "large"],
},
sdsStage: {
control: {
type: "radio",
},
options: ["on", "off"],
},
sdsType: {
control: {
type: "radio",
},
options: ["primary", "secondary"],
},
},
component: ButtonToggle,
parameters: {
badges: [BADGE.BETA],
},
title: "Components/Buttons/ButtonToggle",
} as Meta;

// Default

export const Default = {
args: {
disabled: false,
icon: "InfoCircle",
sdsSize: "medium",
sdsStage: "off",
sdsType: "primary",
},
};

// Test

export const Test = {
parameters: {
controls: {
exclude: BUTTON_TOGGLE_EXCLUDED_CONTROLS,
},
snapshot: {
skip: true,
},
},
render: (args: Args) => <TestDemo icon="InfoCircle" {...args} />,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Args } from "@storybook/react";
import RawButtonToggle from "src/core/ButtonToggle";

export const ButtonToggle = (props: Args): JSX.Element => {
const { icon } = props;

return <RawButtonToggle aria-label="button-toggle" icon={icon} {...props} />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Args } from "@storybook/react";
import ButtonToggle from "src/core/ButtonToggle";

export const TestDemo = (props: Args): JSX.Element => {
const { icon } = props;

return (
<ButtonToggle
data-testid="button-toggle"
aria-label="button-toggle"
icon={icon}
{...props}
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ButtonToggle, ButtonToggleProps } from "@czi-sds/components";

const ButtonToggleNameSpaceTest = (props: ButtonToggleProps) => {
return (
<ButtonToggle
sdsSize="medium"
sdsType="primary"
sdsStage="off"
icon="InfoCircle"
disabled={false}
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<ButtonToggle /> Default story renders snapshot 1`] = `
<button
aria-label="button-toggle"
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeMedium css-ul4hcs-MuiButtonBase-root-MuiIconButton-root"
icon="InfoCircle"
tabindex="0"
type="button"
>
<div
class="css-1ft6wgl"
>
<svg
aria-hidden="true"
class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1q6hio5-MuiSvgIcon-root"
data-file-name="IconInfoCircleLarge"
data-testid="IconInfoCircleLarge"
fillcontrast="white"
focusable="false"
height="24"
viewBox="0 0 24 24"
width="24"
/>
</div>
<span
class="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root"
/>
</button>
`;
Loading

0 comments on commit 3f532ad

Please sign in to comment.