Skip to content

Commit

Permalink
fix(button): fix Button types and remove destructive type for the min…
Browse files Browse the repository at this point in the history
…imal styled button
  • Loading branch information
masoudmanson committed Apr 30, 2024
1 parent 3687567 commit 36bce7f
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ export const BUTTON_ICON_PSEUDO_STATES = [
"default",
"hover",
"active",
"focus",
"focus-visible",
];
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const InvalidIconButtonPropsError = (
<Callout intent="negative">
<CalloutTitle>Invalid Props!</CalloutTitle>
<p>
The icon styled Button must include an icon. Please choose an icon from
from the controls section.
The <strong>icon</strong> styled Button must include an icon. Please
choose an icon from from the controls section.
</p>
</Callout>
);
Expand All @@ -25,8 +25,9 @@ const InvalidSdsTypeTertiaryError = (
<Callout intent="negative">
<CalloutTitle>Invalid Props!</CalloutTitle>
<p>
Only buttons with the icon style can have the tertiary type. Please select
another type, either primary or secondary.
Only buttons with the <strong>icon</strong> style can have the{" "}
<strong>tertiary</strong> type. Please select another type, either{" "}
<strong>primary</strong> or <strong>secondary</strong>.
</p>
</Callout>
);
Expand All @@ -35,9 +36,9 @@ const InvalidSdsTypeDestructiveError = (
<Callout intent="negative">
<CalloutTitle>Invalid Props!</CalloutTitle>
<p>
Buttons with the &apos;icon&apos; style cannot have the
&apos;destructive&apos; type. Please choose another type, such as
&apos;square&apos;, &apos;rounded&apos;, or &apos;minimal&apos;.
Buttons with the <strong>icon</strong> or <strong>minimal</strong> styles
cannot have the <strong>destructive</strong> type. Please choose another
type, such as <strong>square</strong> or <strong>rounded</strong>.
</p>
</Callout>
);
Expand Down Expand Up @@ -101,19 +102,15 @@ export const Button = (props: Args): JSX.Element => {
return InvalidSdsTypeTertiaryError;
}

if (sdsStyle === "icon" && sdsType === "destructive") {
if (
(sdsStyle === "icon" || sdsStyle === "minimal") &&
sdsType === "destructive"
) {
return InvalidSdsTypeDestructiveError;
}

return (
<RawButton
sdsType={sdsType}
sdsStyle={sdsStyle}
sdsSize={sdsSize}
{...props}
startIcon={startIconFinal}
endIcon={endIconFinal}
>
<RawButton {...props} startIcon={startIconFinal} endIcon={endIconFinal}>
{text}
</RawButton>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ export const ScreenshotTestDemo = (props: Args): JSX.Element => {
Style: <b>{sdsStyle}</b>
</h3>
{SCREENSHOT_BUTTON_SDS_TYPES.map((type) => {
// (masoudmanson): The minimal style does not have the destructive type.
if (sdsStyle === "minimal" && type === "destructive") return null;

return (
<ButtonTypeOption sdsStyle={sdsStyle} type={type} key={type} />
);
Expand All @@ -113,7 +116,7 @@ export const ScreenshotTestDemo = (props: Args): JSX.Element => {
);
}

// loop through all BUTTON_ICON_OPTIONS_2 + create headers for SCREENSHOT_BUTTON_SDS_TYPES
// loop through all SCREENSHOT_BUTTON_ICON_OPTIONS + create headers for button types
function ButtonTypeOption({
sdsStyle,
type,
Expand Down Expand Up @@ -168,7 +171,7 @@ export const ScreenshotTestDemo = (props: Args): JSX.Element => {
);
}

// loop through all BUTTON_DISABLED_OPTIONS + create headers for BUTTON_ICON_OPTIONS_2
// loop through all BUTTON_DISABLED_OPTIONS + create headers for BUTTON_ICON_OPTIONS
function ButtonIconOption({
sdsStyle,
type,
Expand Down Expand Up @@ -247,7 +250,7 @@ export const ScreenshotTestDemo = (props: Args): JSX.Element => {

// Icon Style

// loop through all SDS_SIZES + create headers for SDS_TYPES
// loop through all BUTTON_ICON_SDS_SIZES + create headers for SDS_TYPES
function ButtonIconTypeOption({ sdsType }: { sdsType: SDSTypes[number] }) {
const LEVEL_STYLE: React.CSSProperties = {
columnGap: "20px",
Expand Down Expand Up @@ -278,7 +281,7 @@ export const ScreenshotTestDemo = (props: Args): JSX.Element => {
);
}

// loop through all ON_OPTIONS + create headers for SDS_SIZES
// loop through all BUTTON_ICON_DISABLED_OPTIONS + create headers for SDS_SIZES
function ButtonIconSizeOption({
sdsType,
sdsSize,
Expand Down
38 changes: 25 additions & 13 deletions packages/components/src/core/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,31 @@ import ButtonIcon from "../ButtonIcon";
import { IconNameToSizes, IconProps } from "../Icon";
import { filterProps } from "src/common/utils";

type ButtonStyle = "rounded" | "square" | "minimal" | "icon";
type ButtonType = "primary" | "secondary" | "tertiary" | "destructive";
type ButtonSize = "small" | "medium" | "large";

type SdsProps = {
sdsStyle?: ButtonStyle;
sdsType?: ButtonType;
isAllCaps?: boolean;
isRounded?: boolean;
sdsSize?: ButtonSize;
icon?: keyof IconNameToSizes | React.ReactElement<CustomSVGProps>;
sdsIconProps?: Partial<IconProps<keyof IconNameToSizes>>;
};
type SdsProps =
| {
sdsStyle?: "icon";
sdsType?: "primary" | "secondary" | "tertiary";
isAllCaps?: boolean;
isRounded?: boolean;
sdsSize?: ButtonSize;
icon?: keyof IconNameToSizes | React.ReactElement<CustomSVGProps>;
sdsIconProps?: Partial<IconProps<keyof IconNameToSizes>>;
}
| {
sdsStyle?: "minimal";
sdsType?: "primary" | "secondary";
isAllCaps?: boolean;
isRounded?: boolean;
}
| {
sdsStyle?: "rounded" | "square";
sdsType?: "primary" | "secondary" | "destructive";
isAllCaps?: boolean;
isRounded?: boolean;
};

export type ButtonProps = RawButtonProps & SdsProps;

Expand All @@ -43,7 +55,7 @@ const Button = React.forwardRef(
props: ButtonProps,
ref: ForwardedRef<HTMLButtonElement>
): JSX.Element | null => {
const { sdsStyle, sdsType, icon } = props;
const { sdsStyle, sdsType } = props;

if (!sdsStyle || !sdsType) {
showWarningIfFirstOccurence(SDSWarningTypes.ButtonMissingSDSProps);
Expand All @@ -62,7 +74,7 @@ const Button = React.forwardRef(

switch (true) {
case sdsStyle === "icon":
if (icon !== undefined) {
if (props?.icon !== undefined) {
// (masoudmanson): We need to remove the props that are not supported by
// the ButtonIcon component.
const excludedProps: (keyof PropsWithDefaultsType)[] = [
Expand All @@ -76,7 +88,7 @@ const Button = React.forwardRef(

return (
<ButtonIcon
icon={icon}
icon={props?.icon}
{...finalProps}
sdsType={sdsType as Exclude<ButtonType, "destructive">}
ref={ref}
Expand Down
37 changes: 0 additions & 37 deletions packages/components/src/core/Button/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,42 +287,6 @@ const SecondaryMinimalButton = (props: ButtonExtraProps): SerializedStyles => {
`;
};

const DestructiveMinimalButton = (
props: ButtonExtraProps
): SerializedStyles => {
const semanticTextColors = getSemanticTextColors(props);
const semanticComponentColors = getSemanticComponentColors(props);

return css`
${Minimal(props)}
color: ${semanticComponentColors?.negative?.fill};
&:hover,
&:focus-visible {
background-color: transparent;
color: ${semanticComponentColors?.negative?.fillHover};
svg {
color: ${semanticComponentColors?.negative?.fillHover};
}
}
&:active {
color: ${semanticComponentColors?.negative?.fillPressed};
svg {
color: ${semanticComponentColors?.negative?.fillPressed};
}
}
&:disabled {
color: ${semanticTextColors?.base?.onFillDisabled};
svg {
color: ${semanticTextColors?.base?.onFillDisabled};
}
}
`;
};

export const StyledMinimalButton = styled(Button, {
shouldForwardProp: (prop: string) => !doNotForwardProps.includes(prop),
})`
Expand All @@ -332,7 +296,6 @@ export const StyledMinimalButton = styled(Button, {
return css`
${sdsType === "primary" && PrimaryMinimalButton(props)}
${sdsType === "secondary" && SecondaryMinimalButton(props)}
${sdsType === "destructive" && DestructiveMinimalButton(props)}
`;
}}
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`<Dialog /> Default story renders snapshot 1`] = `
<button
class="MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-textPrimary MuiButton-sizeMedium MuiButton-textSizeMedium MuiButton-root MuiButton-text MuiButton-textPrimary MuiButton-sizeMedium MuiButton-textSizeMedium css-1evm0vy-MuiButtonBase-root-MuiButton-root"
class="MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-textPrimary MuiButton-sizeMedium MuiButton-textSizeMedium MuiButton-root MuiButton-text MuiButton-textPrimary MuiButton-sizeMedium MuiButton-textSizeMedium css-1nbscw4-MuiButtonBase-root-MuiButton-root"
tabindex="0"
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`<TagFilter /> Default story renders snapshot 1`] = `
>
<div>
<button
class="MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-textPrimary MuiButton-sizeMedium MuiButton-textSizeMedium Mui-disabled MuiButton-root MuiButton-text MuiButton-textPrimary MuiButton-sizeMedium MuiButton-textSizeMedium css-g6h7xk-MuiButtonBase-root-MuiButton-root"
class="MuiButtonBase-root MuiButton-root MuiButton-text MuiButton-textPrimary MuiButton-sizeMedium MuiButton-textSizeMedium Mui-disabled MuiButton-root MuiButton-text MuiButton-textPrimary MuiButton-sizeMedium MuiButton-textSizeMedium css-77d05w-MuiButtonBase-root-MuiButton-root"
disabled=""
tabindex="-1"
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const HeaderLeft = styled("div")`
`;

export const HeaderRight = styled("div")`
display: flex;
display: block;
`;

export const StyledButton = styled(Button)`
Expand Down

0 comments on commit 36bce7f

Please sign in to comment.