From 0968a8dcadfbdeceb64459d0b9446670b88d51fd Mon Sep 17 00:00:00 2001 From: Powerplex Date: Tue, 18 Jun 2024 14:29:28 +0200 Subject: [PATCH] feat(accordion): outlined and filled designs --- .../accordion/src/Accordion.doc.mdx | 6 ++ .../accordion/src/Accordion.stories.tsx | 56 +++++++++++++++++-- .../components/accordion/src/Accordion.tsx | 13 ++++- .../accordion/src/AccordionItem.tsx | 4 +- 4 files changed, 70 insertions(+), 9 deletions(-) diff --git a/packages/components/accordion/src/Accordion.doc.mdx b/packages/components/accordion/src/Accordion.doc.mdx index 5f6367349..3e76b8e6c 100644 --- a/packages/components/accordion/src/Accordion.doc.mdx +++ b/packages/components/accordion/src/Accordion.doc.mdx @@ -71,6 +71,12 @@ Use `value` to control which panels are opened. +### Design + +Use `design` to pick the overall look of the component (`filled` or `outlined`). + + + ### Disabled Use `disabled` to disabled the full `Accordion`. diff --git a/packages/components/accordion/src/Accordion.stories.tsx b/packages/components/accordion/src/Accordion.stories.tsx index e72f3b1b9..6a5254089 100644 --- a/packages/components/accordion/src/Accordion.stories.tsx +++ b/packages/components/accordion/src/Accordion.stories.tsx @@ -1,4 +1,5 @@ import { Checkbox, CheckboxGroup } from '@spark-ui/checkbox' +import { Tag } from '@spark-ui/tag' import { Meta, StoryFn } from '@storybook/react' import { useState } from 'react' @@ -13,7 +14,7 @@ export default meta export const Default: StoryFn = () => { return ( - +

@@ -95,9 +96,56 @@ export const Disabled: StoryFn = () => { ) } +export const Design: StoryFn = _args => { + const designs = ['outlined', 'filled'] as const + + return ( +
+ {designs.map(design => { + return ( +
+ {design} + + + Watercraft + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor + incididunt ut labore et dolore magna aliqua. +

+
+
+ + + Automobiles + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor + incididunt ut labore et dolore magna aliqua. +

+
+
+ + + Aircrafts + +

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor + incididunt ut labore et dolore magna aliqua. +

+
+
+
+
+ ) + })} +
+ ) +} + export const DisabledItem: StoryFn = () => { return ( - + Watercraft @@ -133,7 +181,7 @@ export const DisabledItem: StoryFn = () => { export const Multiple: StoryFn = () => { return ( - + Watercraft @@ -168,7 +216,7 @@ export const Multiple: StoryFn = () => { } export const Controlled: StoryFn = () => { - const [value, setValue] = useState(['automobiles', 'aircrafts']) + const [value, setValue] = useState(['watercraft']) return (
diff --git a/packages/components/accordion/src/Accordion.tsx b/packages/components/accordion/src/Accordion.tsx index d0c331b62..fe9c6c291 100644 --- a/packages/components/accordion/src/Accordion.tsx +++ b/packages/components/accordion/src/Accordion.tsx @@ -36,9 +36,15 @@ export interface AccordionProps extends ExtentedZagInterface { * The callback fired when the state of expanded/collapsed accordion items changes. */ onValueChange?: (value: string[]) => void + design?: 'filled' | 'outlined' } -const AccordionContext = createContext | null>(null) +const AccordionContext = createContext< + | (accordion.Api & { + design: 'filled' | 'outlined' + }) + | null +>(null) export const Accordion = forwardRef( ( @@ -48,6 +54,7 @@ export const Accordion = forwardRef( collapsible = true, className, defaultValue, + design = 'outlined', disabled = false, multiple = false, value, @@ -63,7 +70,7 @@ export const Accordion = forwardRef( value, disabled, // onValueChange, - className: cx('bg-surface rounded-lg', className), + className: cx('bg-surface rounded-lg h-fit', className), ...props, }) @@ -86,7 +93,7 @@ export const Accordion = forwardRef( const mergedProps = mergeProps(api.getRootProps(), localProps) return ( - + {children} diff --git a/packages/components/accordion/src/AccordionItem.tsx b/packages/components/accordion/src/AccordionItem.tsx index 5eeaa5ef2..de3859c31 100644 --- a/packages/components/accordion/src/AccordionItem.tsx +++ b/packages/components/accordion/src/AccordionItem.tsx @@ -18,9 +18,9 @@ export const Item = forwardRef( const localProps = { className: cx( - 'relative border-sm border-outline', - 'first:rounded-t-lg last:rounded-b-lg', + 'relative first:rounded-t-lg last:rounded-b-lg', '[&:not(:last-child)]:border-b-none', + { 'border-sm border-outline': accordion.design === 'outlined' }, className ), asChild,