Skip to content

Commit d4b75ac

Browse files
fix(secondary-button): split button additional secondary style
added additional secondary style to the split button
1 parent ef41bcc commit d4b75ac

6 files changed

+67
-5
lines changed

src/components/button/button-types.style.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ const gradientSharedStyle = `
3737
}
3838
`;
3939

40-
export default (isDisabled?: boolean, destructive?: boolean) => ({
40+
export default (
41+
isDisabled?: boolean,
42+
destructive?: boolean,
43+
isWhite?: boolean,
44+
) => ({
4145
primary: `
4246
background: var(--colorsActionMajor500);
4347
border-color: transparent;
@@ -93,6 +97,20 @@ export default (isDisabled?: boolean, destructive?: boolean) => ({
9397
${makeColors("var(--colorsActionMajorYang100)")};
9498
}
9599
100+
${
101+
isWhite && !isDisabled && !destructive
102+
? `
103+
border-color: var(--colorsActionMajorYang100);
104+
${makeColors("var(--colorsActionMajorYang100)")};
105+
&:hover {
106+
background: var(--colorsActionMajorYang100);
107+
border-color: var(--colorsActionMajorYang100);
108+
${makeColors("var(--colorsYin100)")};
109+
}
110+
`
111+
: ""
112+
}
113+
96114
${
97115
destructive
98116
? `

src/components/button/button.component.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export interface ButtonProps extends SpaceProps, TagProps {
9292
* Set a class name on the button element. INTERNAL USE ONLY.
9393
*/
9494
className?: string;
95+
isWhite?: boolean;
9596
}
9697

9798
interface RenderChildrenProps
@@ -195,6 +196,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
195196
children,
196197
destructive = false,
197198
disabled = false,
199+
isWhite = false,
198200
fullWidth: fullWidthProp = false,
199201
href,
200202
iconPosition: iconPositionProp = "before",
@@ -292,6 +294,7 @@ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
292294
buttonType={buttonType}
293295
disabled={isDisabled}
294296
destructive={destructive}
297+
isWhite={isWhite}
295298
type={href ? undefined : "button"}
296299
iconType={iconType}
297300
size={size}

src/components/button/button.style.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ function stylingForType({
3737
buttonType,
3838
size,
3939
destructive,
40-
}: Pick<ButtonProps, "disabled" | "size" | "destructive"> & {
40+
isWhite,
41+
}: Pick<ButtonProps, "disabled" | "size" | "destructive" | "isWhite"> & {
4142
iconOnly?: boolean;
4243
buttonType: Required<ButtonProps>["buttonType"];
4344
}) {
4445
return css`
45-
${buttonTypes(disabled, destructive)[buttonType]};
46+
${buttonTypes(disabled, destructive, isWhite)[buttonType]};
4647
4748
${size === "small" &&
4849
css`

src/components/split-button/split-button-toggle.style.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ type StyledSplitButtonToggleProps = {
1414
disabled: boolean;
1515
displayed: boolean;
1616
size: "small" | "medium" | "large";
17+
isWhite?: boolean;
1718
};
1819

1920
const StyledSplitButtonToggle = styled(
2021
StyledButton,
2122
)<StyledSplitButtonToggleProps>`
22-
${({ buttonType, disabled, displayed, size }) => css`
23+
${({ buttonType, disabled, displayed, size, isWhite }) => css`
2324
border-top-left-radius: var(--borderRadius000);
2425
border-bottom-left-radius: var(--borderRadius000);
2526
26-
${!disabled && displayed
27+
${!disabled && displayed && !isWhite
2728
? css`
2829
background-color: var(--colorsActionMajor500);
2930
border-color: var(--colorsActionMajor500);
@@ -73,6 +74,20 @@ const StyledSplitButtonToggle = styled(
7374
color: var(--colorsActionMajorYang100);
7475
}
7576
}
77+
78+
${!disabled &&
79+
isWhite &&
80+
`
81+
&:focus {
82+
background-color: var(--colorsActionMajorYang100);
83+
border-color: var(--colorsActionMajorYang100);
84+
85+
&,
86+
${StyledIcon} {
87+
color: var(--colorsYin100);
88+
}
89+
}
90+
`}
7691
`}
7792
`;
7893

src/components/split-button/split-button.component.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ export interface SplitButtonProps
5757
text: string;
5858
/** Sets rendering position of menu */
5959
position?: "left" | "right";
60+
/** Renders the white variant of the secondary split button */
61+
isWhite?: boolean;
6062
}
6163

6264
export type SplitButtonHandle = {
@@ -83,6 +85,7 @@ export const SplitButton = forwardRef<SplitButtonHandle, SplitButtonProps>(
8385
"data-element": dataElement,
8486
"data-role": dataRole,
8587
"aria-label": ariaLabel,
88+
isWhite = false,
8689
...rest
8790
},
8891
ref,
@@ -97,6 +100,8 @@ export const SplitButton = forwardRef<SplitButtonHandle, SplitButtonProps>(
97100
const { isInFlatTable } =
98101
useContext<FlatTableContextProps>(FlatTableContext);
99102

103+
const shouldRenderIsWhiteVariant = buttonType === "secondary" && isWhite;
104+
100105
useImperativeHandle<SplitButtonHandle, SplitButtonHandle>(
101106
ref,
102107
() => ({
@@ -140,6 +145,7 @@ export const SplitButton = forwardRef<SplitButtonHandle, SplitButtonProps>(
140145
onClick: handleMainClick,
141146
size,
142147
subtext,
148+
isWhite: shouldRenderIsWhiteVariant,
143149
...filterOutStyledSystemSpacingProps(rest),
144150
};
145151

@@ -148,6 +154,7 @@ export const SplitButton = forwardRef<SplitButtonHandle, SplitButtonProps>(
148154
};
149155

150156
const toggleButtonProps = {
157+
isWhite: shouldRenderIsWhiteVariant,
151158
disabled,
152159
displayed: showAdditionalButtons,
153160
onTouchStart: showButtons,

src/components/split-button/split-button.stories.tsx

+18
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,21 @@ export const InOverflowHiddenContainer: Story = () => (
220220
);
221221
InOverflowHiddenContainer.storyName = "In Overflow Hidden Container";
222222
InOverflowHiddenContainer.parameters = { chromatic: { disableSnapshot: true } };
223+
224+
export const SecondaryIsWhite: Story = () => {
225+
return (
226+
<Box p={3} backgroundColor="#000" width="500px" height="500px">
227+
<SplitButton
228+
buttonType="secondary"
229+
text="Split button - secondary - isWhite"
230+
isWhite
231+
>
232+
<Button>Button 1</Button>
233+
<Button>Button 2</Button>
234+
<Button>Button 3</Button>
235+
</SplitButton>
236+
</Box>
237+
);
238+
};
239+
SecondaryIsWhite.storyName = "Secondary Is White";
240+
SecondaryIsWhite.parameters = { chromatic: { disableSnapshot: false } };

0 commit comments

Comments
 (0)