Skip to content

Commit 1829296

Browse files
committed
feat(admin-ui): add background prop to Accordion component
- Add `background` prop with options: "base", "light", "transparent" - Set default background to "light" for consistency - Update nested accordion background logic to respect explicit prop - Remove hardcoded margin line from AccordionTrigger - Update documentation and Storybook examples with new prop - Add background control to Storybook Documentation story
1 parent 4bcf2b7 commit 1829296

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

packages/admin-ui/src/Accordion/Accordion.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ReactComponent as TrashIcon } from "@webiny/icons/delete.svg";
1919
2020
const AccordionExample = () => {
2121
return (
22-
<Accordion variant="underline">
22+
<Accordion variant="underline" background="base">
2323
<Accordion.Item
2424
title="Accordion Item 1"
2525
description="This is a description for the first item"
@@ -80,7 +80,7 @@ import { ReactComponent as TrashIcon } from "@webiny/icons/delete.svg";
8080

8181
const AccordionExample = () => {
8282
return (
83-
<Accordion variant="underline">
83+
<Accordion variant="underline" background="base">
8484
<Accordion.Item
8585
title="Accordion Item 1"
8686
description="This is a description for the first item"
@@ -458,7 +458,7 @@ import { ReactComponent as WarningIcon } from "@webiny/icons/insert_chart.svg";
458458
459459
const LightBackgroundExample = () => {
460460
return (
461-
<Accordion>
461+
<Accordion background="base">
462462
<Accordion.Item
463463
title="Accordion item 1"
464464
description="Lorem ipsum dolor sit amet, consectetur adipiscing elit."
@@ -491,7 +491,7 @@ import { ReactComponent as WarningIcon } from "@webiny/icons/insert_chart.svg";
491491
492492
const ContainerLightExample = () => {
493493
return (
494-
<Accordion variant="container">
494+
<Accordion variant="container" background="base">
495495
<Accordion.Item
496496
title="Accordion item 1"
497497
description="Lorem ipsum dolor sit amet, consectetur adipiscing elit."

packages/admin-ui/src/Accordion/Accordion.stories.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ export const LightBackground: Story = {
298298
)
299299
],
300300
args: {
301+
background: "light",
301302
children: (
302303
<>
303304
<AccordionItem
@@ -326,6 +327,7 @@ export const ContainerVariantWithLightBackground: Story = {
326327
],
327328
args: {
328329
variant: "container",
330+
background: "light",
329331
children: (
330332
<>
331333
<AccordionItem
@@ -350,6 +352,7 @@ export const Documentation: Story = {
350352
},
351353
args: {
352354
variant: "underline",
355+
background: "base",
353356
children: (
354357
<>
355358
<Accordion.Item
@@ -391,6 +394,11 @@ export const Documentation: Story = {
391394
options: ["underline", "container"],
392395
description: "The visual style of the accordion"
393396
},
397+
background: {
398+
control: "select",
399+
options: ["base", "light", "transparent"],
400+
description: "The background color of the accordion"
401+
},
394402
children: {
395403
description:
396404
"The content of the accordion. Please refer to the example code for details."

packages/admin-ui/src/Accordion/Accordion.tsx

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ const accordionVariants = cva("wby-group wby-w-full", {
1010
container:
1111
"wby-accordion-variant-container wby-gap-xs wby-flex wby-flex-col wby-rounded-lg",
1212
underline: "wby-accordion-variant-underline"
13+
},
14+
background: {
15+
base: "wby-bg-neutral-base",
16+
light: "wby-bg-neutral-light",
17+
transparent: "wby-bg-transparent"
1318
}
1419
},
1520
defaultVariants: {
16-
variant: "container"
21+
variant: "container",
22+
background: "light"
1723
}
1824
});
1925

@@ -22,16 +28,30 @@ type AccordionProps = React.ComponentPropsWithoutRef<typeof AccordionRoot> &
2228
children: React.ReactNode;
2329
};
2430

25-
const getBackgroundByDepth = (depth: number): string => {
26-
return depth % 2 === 0 ? "wby-bg-neutral-base" : "wby-bg-neutral-light";
31+
const getBackgroundByDepth = (
32+
depth: number,
33+
background?: string | null
34+
): "base" | "light" | "transparent" | undefined => {
35+
// If background is explicitly provided, use it at any depth
36+
if (background !== undefined && background !== null) {
37+
return background as "base" | "light" | "transparent";
38+
}
39+
40+
// For depth 0, return undefined to let defaultVariants apply
41+
if (depth === 0) {
42+
return undefined;
43+
}
44+
45+
// For nested levels, alternate between light and base
46+
return depth % 2 === 0 ? "light" : "base";
2747
};
2848

29-
const AccordionBase = ({ children, variant, className }: AccordionProps) => {
49+
const AccordionBase = ({ children, variant, background, className }: AccordionProps) => {
3050
const currentDepth = useDepth() + 1;
31-
const background = getBackgroundByDepth(currentDepth);
51+
const bg = getBackgroundByDepth(currentDepth, background);
3252

3353
return (
34-
<div className={cn(accordionVariants({ variant }), className, background)}>
54+
<div className={cn(accordionVariants({ variant, background: bg }), className)}>
3555
<DepthProvider value={currentDepth}>{children}</DepthProvider>
3656
</div>
3757
);

packages/admin-ui/src/Accordion/components/AccordionTrigger.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ const AccordionTrigger = ({
7676
cursorClass
7777
)}
7878
>
79-
{!icon && !isInteractable && (
80-
<div className={"wby-ml-sm wby-w-[20px] wby-h-[1px] wby-bg-neutral-strong"} />
81-
)}
8279
{draggable ? <AccordionItemDragHandle /> : null}
8380
{isInteractable ? <OpenCloseIndicator /> : null}
8481

0 commit comments

Comments
 (0)