-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add multi accordion component (#468)
* Add Multi Accordion * Add background color to demo * Fix import * Add token changes * Add accordion changes * Add multi accordion to root * Add multi accordion changes * Add border radius changes
- Loading branch information
1 parent
0b8db2e
commit 2e674d3
Showing
13 changed files
with
500 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { MultiAccordion } from "./MultiAccordion"; | ||
|
||
export default { | ||
component: MultiAccordion, | ||
title: "Accordion/MultiAccordion", | ||
tags: ["multi-accordion", "autodocs"], | ||
argTypes: { | ||
gap: { | ||
control: "select", | ||
options: ["none", "xxs", "xs", "sm", "md", "lg", "xl", "xxl"], | ||
}, | ||
size: { | ||
control: "radio", | ||
options: ["none", "sm", "md", "lg"], | ||
}, | ||
fillWidth: { control: "boolean" }, | ||
showBorder: { control: "boolean" }, | ||
showCheck: { control: "boolean" }, | ||
type: { control: "radio", options: ["single", "multiple"] }, | ||
collapsible: { control: "boolean", if: { arg: "type", eq: "single" } }, | ||
}, | ||
}; | ||
|
||
export const Playground = { | ||
args: { | ||
type: "single", | ||
collapsible: true, | ||
showBorder: true, | ||
showCheck: true, | ||
children: ( | ||
<> | ||
<MultiAccordion.Item | ||
value="content0" | ||
icon="user" | ||
title="Option 1" | ||
isCompleted | ||
> | ||
Content0 | ||
</MultiAccordion.Item> | ||
<MultiAccordion.Item | ||
value="content1" | ||
title="Option 2" | ||
> | ||
Content1 long text content | ||
</MultiAccordion.Item> | ||
</> | ||
), | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { fireEvent } from "@testing-library/react"; | ||
import { MultiAccordion, MultiAccordionProps } from "./MultiAccordion"; | ||
import { renderCUI } from "@/utils/test-utils"; | ||
const children = ( | ||
<> | ||
<MultiAccordion.Item | ||
value="content0" | ||
icon="user" | ||
title="Option 1" | ||
isCompleted | ||
> | ||
Content0 | ||
</MultiAccordion.Item> | ||
<MultiAccordion.Item | ||
value="content1" | ||
title="Option 2" | ||
> | ||
Content1 long text content | ||
</MultiAccordion.Item> | ||
</> | ||
); | ||
describe("MultiAccordion", () => { | ||
const renderAccordion = (props: MultiAccordionProps) => | ||
renderCUI(<MultiAccordion {...props} />); | ||
|
||
it("should render the multi accordion type single", () => { | ||
const { getByText, queryByText } = renderAccordion({ type: "single", children }); | ||
const trigger1 = getByText("Option 1"); | ||
const trigger2 = getByText("Option 2"); | ||
expect(trigger1).toBeTruthy(); | ||
fireEvent.click(trigger1); | ||
expect(getByText("Content0")).toBeTruthy(); | ||
expect(queryByText("Content1 long text content")).toBeNull(); | ||
fireEvent.click(trigger2); | ||
expect(getByText("Content1 long text content")).toBeTruthy(); | ||
expect(queryByText("Content0")).toBeNull(); | ||
fireEvent.click(trigger2); | ||
expect(getByText("Content1 long text content")).toBeTruthy(); | ||
}); | ||
|
||
it("should render the multi accordion type single collapsible", () => { | ||
const { getByText, queryAllByTestId, queryByText } = renderAccordion({ | ||
type: "single", | ||
collapsible: true, | ||
children, | ||
}); | ||
const trigger1 = getByText("Option 1"); | ||
const trigger2 = getByText("Option 2"); | ||
expect(trigger1).toBeTruthy(); | ||
fireEvent.click(trigger1); | ||
expect(getByText("Content0")).toBeTruthy(); | ||
expect(queryByText("Content1 long text content")).toBeNull(); | ||
fireEvent.click(trigger2); | ||
expect(getByText("Content1 long text content")).toBeTruthy(); | ||
expect(queryByText("Content0")).toBeNull(); | ||
fireEvent.click(trigger2); | ||
expect(queryByText("Content1 long text content")).toBeNull(); | ||
expect(queryAllByTestId("accordion-status-icon")).toHaveLength(0); | ||
}); | ||
|
||
it("should render the multi accordion type multiple", () => { | ||
const { getByText, queryByText } = renderAccordion({ type: "multiple", children }); | ||
const trigger1 = getByText("Option 1"); | ||
const trigger2 = getByText("Option 2"); | ||
expect(trigger1).toBeTruthy(); | ||
fireEvent.click(trigger1); | ||
expect(getByText("Content0")).toBeTruthy(); | ||
expect(queryByText("Content1 long text content")).toBeNull(); | ||
fireEvent.click(trigger2); | ||
expect(getByText("Content1 long text content")).toBeTruthy(); | ||
expect(getByText("Content0")).toBeTruthy(); | ||
fireEvent.click(trigger2); | ||
expect(queryByText("Content1 long text content")).toBeNull(); | ||
}); | ||
|
||
it("should show check", () => { | ||
const { getAllByTestId, getByText } = renderAccordion({ | ||
type: "single", | ||
showCheck: true, | ||
children, | ||
}); | ||
expect(getByText("Option 1")).toBeTruthy(); | ||
expect(getByText("Option 2")).toBeTruthy(); | ||
expect(getAllByTestId("accordion-status-icon")).toHaveLength(2); | ||
}); | ||
|
||
it("should trigger markAsCompleted onClicking check", () => { | ||
const markAsCompleted = vi.fn(); | ||
const { getAllByTestId, getByText } = renderAccordion({ | ||
type: "single", | ||
showCheck: true, | ||
markAsCompleted, | ||
children, | ||
}); | ||
expect(getByText("Option 1")).toBeTruthy(); | ||
expect(getByText("Option 2")).toBeTruthy(); | ||
const statusIcons = getAllByTestId("accordion-status-icon"); | ||
expect(statusIcons).toHaveLength(2); | ||
fireEvent.click(statusIcons[0]); | ||
expect(markAsCompleted).toHaveBeenCalledOnce(); | ||
}); | ||
}); |
Oops, something went wrong.