Skip to content

Commit

Permalink
refactor(Accordion): update styling integration with tailwind-variants
Browse files Browse the repository at this point in the history
  • Loading branch information
websiddu committed Dec 24, 2024
1 parent 5d11aaf commit 0b22790
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
4 changes: 0 additions & 4 deletions lib/Accordion/Accordion.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,3 @@
}
}
}

.accordion-content {
@apply p-4;
}
24 changes: 20 additions & 4 deletions lib/Accordion/Accordion.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import './Accordion.scss';

import { tv } from 'tailwind-variants';

interface AccordionProps {
title: string;
children: React.ReactNode;
Expand All @@ -10,15 +12,29 @@ interface AccordionGroupProps {
children: React.ReactNode | React.ReactNode[];
}

const accordionStyles = tv({
slots: {
accordionGroup: 'rounded-none border-b-0 gap-2 flex flex-col',
accordion: 'overflow-hidden rounded-xl border border-gray-950/10 dark:border-gray-100/10',
accordionSummary:
'm-0 cursor-pointer select-none px-4 py-2.5 font-medium bg-gray-800/5 dark:bg-gray-300/5 before:content-[""] before:mr-2',
accordionContent: 'p-4',
},
});

export const Accordion: React.FC<AccordionProps> = ({ title = '', children }) => {
const { accordion, accordionSummary, accordionContent } = accordionStyles();

return (
<details className={'accordion'}>
<summary className={'accordion-summary'}>{title}</summary>
<div className={'accordion-content'}>{children}</div>
<details className={accordion()}>
<summary className={accordionSummary()}>{title}</summary>
<div className={accordionContent()}>{children}</div>
</details>
);
};

export const AccordionGroup: React.FC<AccordionGroupProps> = ({ children }) => {
return <div className={'accordion-group'}>{children}</div>;
const { accordionGroup } = accordionStyles();

return <div className={accordionGroup()}>{children}</div>;
};
13 changes: 8 additions & 5 deletions lib/Callout/Callout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { VariantProps } from 'tailwind-variants';
const callout = tv({
slots: {
base: 'mt-6 overflow-hidden rounded-xl border px-5 py-4 flex items-start space-x-3',
icon: 'mt-0.5 h-5 w-5',
icon: 'h-5 w-5 mt-[1px]',
content: 'flex-1 overflow-x-auto first:mt-0 last:mb-0',
},
variants: {
Expand Down Expand Up @@ -91,10 +91,13 @@ const Callout = ({ variant = 'info', children }: CalloutProps) => {

return (
<div className={base()}>
<Icon
size={20}
className={icon()}
/>
<div className="flex items-center justify-center">
<Icon
size={20}
className={icon()}
/>
<span className="-ml-[4px]">&nbsp;</span>
</div>
<div className={content()}>{children}</div>
</div>
);
Expand Down
5 changes: 5 additions & 0 deletions src/pages/CalloutSamples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ export function CalloutSamples() {
return (
<>
<Tip>Content for the tip goes here!</Tip>
<Tip>
Content for the tip goes here! Content for the tip goes here!Content for the tip goes
here!Content for the tip goes here!Content for the tip goes here!Content for the tip goes
here!
</Tip>
<Info>This is an info</Info>
<Warning>This is a warning</Warning>
<Success>This is a success</Success>
Expand Down

0 comments on commit 0b22790

Please sign in to comment.