Skip to content

Commit

Permalink
feat(button-toggle): add minor child
Browse files Browse the repository at this point in the history
feat(button-toggle): rm variant prop

feat(button-toggle): rm variant prop, tests

feat(button-toggle): fix ts errors

feat(button-toggle): update snaps

feat(button-toggle): rm variant prop
  • Loading branch information
DobroTora committed Oct 16, 2023
1 parent 853a926 commit fe4da3b
Show file tree
Hide file tree
Showing 9 changed files with 279 additions and 73 deletions.
34 changes: 0 additions & 34 deletions cypress/components/button-toggle/button-toggle.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,40 +94,6 @@ context("Testing Button-Toggle component", () => {
});
});

describe("rounded corners", () => {
it("has the expected border-radius styling on a single toggle button", () => {
CypressMountWithProviders(
<ButtonToggleComponent>Foo</ButtonToggleComponent>
);

buttonToggleButton().each((el) =>
expect(el.css("border-radius")).equals("32px")
);
});

it("should have the expected border-radius styling when the children have the grouped prop set", () => {
CypressMountWithProviders(
<stories.ButtonToggleGroupComponentGroupedChildren />
);

buttonToggleButton()
.eq(0)
.should("have.css", "border-radius", "32px 0px 0px 32px");
buttonToggleButton().eq(1).should("have.css", "border-radius", "0px");
buttonToggleButton()
.eq(2)
.should("have.css", "border-radius", "0px 32px 32px 0px");
});

it("should have the expected border-radius styling when children do not have grouped prop set", () => {
CypressMountWithProviders(<stories.ButtonToggleGroupComponent />);

buttonToggleButton().eq(0).should("have.css", "border-radius", "32px");
buttonToggleButton().eq(1).should("have.css", "border-radius", "32px");
buttonToggleButton().eq(2).should("have.css", "border-radius", "32px");
});
});

it("should render Button-Toggle with aria-label prop", () => {
CypressMountWithProviders(
<ButtonToggleComponent aria-label="cypress-aria" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ exports[`ButtonToggle General styling renders correctly when grouped 1`] = `
text-align: start;
color: inherit;
border: 1px solid var(--colorsActionMinor500);
color: var(--colorsActionMinor500);
border: 1px solid var(--colorsActionMinor500);
}
.c2:focus {
Expand Down Expand Up @@ -56,8 +58,43 @@ exports[`ButtonToggle General styling renders correctly when grouped 1`] = `
color: var(--colorsActionMinor500);
}
.c2 .c4 {
color: var(--colorsActionMinor500);
}
.c2 .c4:not([aria-pressed="true"]):not(:disabled):hover {
color: var(--colorsActionMinorYang100);
}
.c2:not([aria-pressed="true"]):not(:disabled):hover {
color: var(--colorsActionMinorYang100);
background-color: var(--colorsActionMinor600);
}
.c2:not([aria-pressed="true"]):not(:disabled):hover .c4 {
color: var(--colorsActionMinorYang100);
}
.c2:not(:disabled):hover {
background-color: var(--colorsActionMinor600);
color: var(--colorsActionMinorYang100);
}
.c2:not(:disabled):hover .c4 {
color: var(--colorsActionMinorYang100);
}
.c2[aria-pressed="true"]:not(:hover) {
box-shadow: inset 0px 0px 0px 3px var(--colorsActionMinor500);
background-color: transparent;
}
.c2[aria-pressed="true"]:not(:hover):focus {
box-shadow: inset 0px 0px 0px 3px var(--colorsActionMinor500), 0px 0px 0px var(--borderWidth300) var(--colorsSemanticFocus500), 0px 0px 0px var(--borderWidth600) var(--colorsUtilityYin090);
}
.c3.c3.c3.c3 .c1 {
border-radius: var(--borderRadius400);
border-radius: var(--borderRadius050);
}
.c0 {
Expand All @@ -66,13 +103,13 @@ exports[`ButtonToggle General styling renders correctly when grouped 1`] = `
}
.c0.c0.c0.c0:first-of-type .c1 {
border-top-left-radius: var(--borderRadius400);
border-bottom-left-radius: var(--borderRadius400);
border-top-left-radius: var(--borderRadius050);
border-bottom-left-radius: var(--borderRadius050);
}
.c0.c0.c0.c0:last-of-type .c1 {
border-top-right-radius: var(--borderRadius400);
border-bottom-right-radius: var(--borderRadius400);
border-top-right-radius: var(--borderRadius050);
border-bottom-right-radius: var(--borderRadius050);
}
.c0:not(:first-of-type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ export const Grouped: ComponentStory<typeof ButtonToggleGroup> = () => (
</ButtonToggleGroup>
);

export const GroupedMinor: ComponentStory<typeof ButtonToggleGroup> = () => (
<ButtonToggleGroup
id="button-toggle-group-grouped-id"
label="Grouped example"
labelHelp="help message"
helpAriaLabel="Help"
fieldHelp="field help mesage"
onChange={() => {}}
>
<ButtonToggle value="foo" grouped>
Foo
</ButtonToggle>
<ButtonToggle value="bar" grouped>
Bar
</ButtonToggle>
<ButtonToggle value="baz" grouped>
Baz
</ButtonToggle>
</ButtonToggleGroup>
);

export const FullWidth: ComponentStory<typeof ButtonToggleGroup> = () => (
<ButtonToggleGroup
id="button-toggle-group-fullWidth-id"
Expand Down
37 changes: 37 additions & 0 deletions src/components/button-toggle/button-toggle-test.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,43 @@ export const DefaultStory = () => {
);
};

export const ButtonToggleGroupMinorStory = () => {
const [value, setValue] = useState<string | undefined>("bar");
function onChangeHandler(
event: React.MouseEvent<HTMLButtonElement>,
selectedButtonValue?: string
) {
setValue(selectedButtonValue);
action("value set")(selectedButtonValue);
}
return (
<ButtonToggleGroup
id="button-toggle-group"
name="button-toggle-group"
label="Button Toggle Group test"
labelHelp="help message"
helpAriaLabel="Help"
fieldHelp="field help mesage"
onChange={onChangeHandler}
value={value}
<<<<<<< HEAD
=======
<<<<<<< HEAD
<<<<<<< HEAD
=======
variant="minor"
>>>>>>> 8c445eebb (feat(button-toggle): add minor child)
=======
>>>>>>> 71a7991e9 (feat(button-toggle): rm variant prop, tests)
>>>>>>> df20abe7b (feat(button-toggle): rm variant prop)
>
<ButtonToggle value="foo">Foo</ButtonToggle>
<ButtonToggle value="bar">Bar</ButtonToggle>
<ButtonToggle value="baz">Baz</ButtonToggle>
</ButtonToggleGroup>
);
};

export const WithoutGroup = (args: Partial<ButtonToggleProps>) => (
<div>
<ButtonToggle
Expand Down
1 change: 0 additions & 1 deletion src/components/button-toggle/button-toggle.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export const ButtonToggle = ({
firstButton,
childButtonCallbackRef,
} = useContext(ButtonToggleGroupContext);

const callbackRef = (element: HTMLButtonElement | null) => {
buttonRef.current = element;
if (childButtonCallbackRef) {
Expand Down
13 changes: 0 additions & 13 deletions src/components/button-toggle/button-toggle.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
StyledButtonToggleIcon,
ButtonToggleIconSizes,
StyledButtonToggle,
StyledButtonToggleWrapper,
} from "./button-toggle.style";
import { InputGroupContext } from "../../__internal__/input-behaviour";
import { ThemeObject } from "../../style/themes/base";
Expand Down Expand Up @@ -396,16 +395,4 @@ describe("ButtonToggle", () => {
describe("coverage filler for else path", () => {
mount(<ButtonToggle buttonIcon="add">toggle</ButtonToggle>);
});

it("renders with the expected border radius styling", () => {
assertStyleMatch(
{
borderRadius: "var(--borderRadius400)",
},
mount(<ButtonToggle>toggle</ButtonToggle>).find(
StyledButtonToggleWrapper
),
{ modifier: `&&&& ${StyledButtonToggle}` }
);
});
});
9 changes: 6 additions & 3 deletions src/components/button-toggle/button-toggle.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ButtonToggle } from ".";
import * as stories from "./button-toggle.stories";
import * as groupStories from "./button-toggle-group/button-toggle-group.stories";

<Meta
<Meta
title="Button Toggle"
parameters={{
info: { disable: true },
Expand All @@ -19,7 +19,7 @@ import * as groupStories from "./button-toggle-group/button-toggle-group.stories
<a
target="_blank"
href="https://zeroheight.com/2ccf2b601/p/996a28-button-toggle/b/7384f9"
style={{ color: '#007E45', fontWeight: 'bold', textDecoration: 'underline' }}
style={{ color: "#007E45", fontWeight: "bold", textDecoration: "underline" }}
>
Product Design System component
</a>
Expand All @@ -35,7 +35,10 @@ Press one of the buttons to make selection. This component should be used when u
## Quick Start

```javascript
import { ButtonToggle, ButtonToggleGroup } from "carbon-react/lib/components/button-toggle";
import {
ButtonToggle,
ButtonToggleGroup,
} from "carbon-react/lib/components/button-toggle";
```

- You should use the <LinkTo kind="Button Toggle Group" story="default">ButtonToggleGroup component</LinkTo> if you need to wrap multiple `ButtonToggle` components together.
Expand Down
19 changes: 8 additions & 11 deletions src/components/button-toggle/button-toggle.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from "react";
import { ComponentStory } from "@storybook/react";

import { ButtonToggle, ButtonToggleGroup } from ".";
import Box from "../box";

export const Default: ComponentStory<typeof ButtonToggle> = () => (
<ButtonToggleGroup id="button-toggle-group-id" label="Default example">
Expand All @@ -13,16 +12,14 @@ export const Default: ComponentStory<typeof ButtonToggle> = () => (
);

export const DefaultWrappedText: ComponentStory<typeof ButtonToggle> = () => (
<Box margin={4} width="250px" display="flex" flexWrap="nowrap">
<ButtonToggleGroup id="button-toggle-group-id" label="Wrapped text example">
<ButtonToggle value="wraps" grouped>
Some text that wraps
</ButtonToggle>
<ButtonToggle value="foobar" grouped>
FooBar
</ButtonToggle>
</ButtonToggleGroup>
</Box>
<ButtonToggleGroup id="button-toggle-group-id" label="Wrapped text example">
<ButtonToggle value="wraps" grouped>
Some text that wraps
</ButtonToggle>
<ButtonToggle value="foobar" grouped>
FooBar
</ButtonToggle>
</ButtonToggleGroup>
);

export const DefaultSmallIcon: ComponentStory<typeof ButtonToggle> = () => (
Expand Down
Loading

0 comments on commit fe4da3b

Please sign in to comment.