Skip to content

Commit

Permalink
feat: 처리방법 accordion shadcn ui로 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
cham0287 committed May 6, 2024
1 parent bdf5e3b commit 6e98eb8
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 37 deletions.
86 changes: 86 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"lint": "next lint"
},
"dependencies": {
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-select": "^2.0.0",
"@tanstack/react-query": "^5.29.2",
"@typescript-eslint/eslint-plugin": "6.0",
Expand Down
39 changes: 39 additions & 0 deletions src/components/ui/AccordionBase.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import React from 'react';
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from './shadcn-ui/accordion';
import { methodTypes } from '@/utils/methodTypes';

const AccordionBase = ({ tag }: { tag: string }) => {
const DM = methodTypes.filter((item) => item.tag === tag)[0].methods;
return (
<Accordion className="flex flex-col gap-4" type="single" collapsible>
{DM.map((method, index) => (
<AccordionItem
key={method.title}
className="rounded-[8px] bg-Green-50 px-S-12"
value={`item-${index}`}
>
<AccordionTrigger className="text-Green-500 Title-Small">
{method.title}
</AccordionTrigger>
<AccordionContent className="text-Gray-600">
{method.descriptions.map((content, index) => (
<p
key={`description-${index}`}
className="text-Gray-600 Label-Large-Custom"
>
{content}
</p>
))}
</AccordionContent>
</AccordionItem>
))}
</Accordion>
);
};

export default AccordionBase;
6 changes: 3 additions & 3 deletions src/components/ui/icons/Down.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
interface Props {
w?: number;
h?: number;
color?: string;
}

const Down = ({ w, h, color }: Props) => {
const Down = ({ w, h }: Props) => {
return (
<svg
className="shrink-0 transition-transform duration-200"
width={w ? w : '24'}
height={h ? h : '24'}
viewBox="0 0 24 24"
Expand All @@ -17,7 +17,7 @@ const Down = ({ w, h, color }: Props) => {
fill-rule="evenodd"
clip-rule="evenodd"
d="M3.50173 6.93944C3.81132 6.66425 4.28538 6.69214 4.56056 7.00173L12 15.3711L19.4395 7.00173C19.7146 6.69214 20.1887 6.66425 20.4983 6.93944C20.8079 7.21463 20.8358 7.68868 20.5606 7.99827L12.5606 16.9983C12.4182 17.1584 12.2142 17.25 12 17.25C11.7858 17.25 11.5818 17.1584 11.4395 16.9983L3.43945 7.99827C3.16426 7.68869 3.19215 7.21463 3.50173 6.93944Z"
fill={color ? color : '#625F5D'}
fill="currentColor"
/>
</svg>
);
Expand Down
59 changes: 59 additions & 0 deletions src/components/ui/shadcn-ui/accordion.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use client';

import * as React from 'react';
import * as AccordionPrimitive from '@radix-ui/react-accordion';
import { ChevronDown } from 'lucide-react';

import { cn } from '@/lib/utils';
import Down from '../icons/Down';

const Accordion = AccordionPrimitive.Root;

const AccordionItem = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item>
>(({ className, ...props }, ref) => (
<AccordionPrimitive.Item
ref={ref}
className={cn('border-b', className)}
{...props}
/>
));
AccordionItem.displayName = 'AccordionItem';

const AccordionTrigger = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
<AccordionPrimitive.Header className="flex">
<AccordionPrimitive.Trigger
ref={ref}
className={cn(
'flex flex-1 items-center justify-between py-4 font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180',
className,
)}
{...props}
>
{children}
<Down />
</AccordionPrimitive.Trigger>
</AccordionPrimitive.Header>
));
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName;

const AccordionContent = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<AccordionPrimitive.Content
ref={ref}
className="overflow-hidden text-sm transition-all data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down"
{...props}
>
<div className={cn('pb-4 pt-0', className)}>{children}</div>
</AccordionPrimitive.Content>
));

AccordionContent.displayName = AccordionPrimitive.Content.displayName;

export { Accordion, AccordionItem, AccordionTrigger, AccordionContent };
60 changes: 26 additions & 34 deletions src/components/ui/sidebars/DiscardMethod.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,43 @@
import { useState } from 'react';
import Down from '../icons/Down';
import Up from '../icons/Up';
import { methodTypes } from '@/utils/methodTypes';
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from '../shadcn-ui/accordion';

interface Props {
tag: string;
}

export default function DiscardMethod({ tag }: Props) {
const DM = methodTypes.filter((item) => item.tag === tag)[0].methods;
const [openIndex, SetOpenIndex] = useState(-1);
return (
<section className="flex flex-col gap-S-20 bg-white p-S-24">
<h5 className="text-Gray-700 Title-Small">배출 방법</h5>
<div className="flex flex-col gap-S-14">
<Accordion className="flex flex-col gap-4" type="single" collapsible>
{DM.map((method, index) => (
<div
key={index}
className="flex flex-col gap-S-16 rounded-[8px] bg-Green-50 p-S-16"
<AccordionItem
key={method.title}
className="rounded-[8px] bg-Green-50 px-S-12"
value={`item-${index}`}
>
<div className="flex justify-between">
<p className="text-Green-500 Title-Small">{method.title}</p>
{openIndex !== index ? (
<span onClick={() => SetOpenIndex(index)}>
<Down color="#45995E" />
</span>
) : (
<span onClick={() => SetOpenIndex(-1)}>
<Up color="#45995E" />
</span>
)}
</div>
{openIndex === index && (
<div className="bg-transparent">
{method.descriptions.map((content, index) => (
<p
key={`description-${index}`}
className="text-Gray-600 Label-Large-Custom"
>
{content}
</p>
))}
</div>
)}
</div>
<AccordionTrigger className="text-Green-500 Title-Small">
{method.title}
</AccordionTrigger>
<AccordionContent className="text-Gray-600">
{method.descriptions.map((content, index) => (
<p
key={`description-${index}`}
className="text-Gray-600 Label-Large-Custom"
>
{content}
</p>
))}
</AccordionContent>
</AccordionItem>
))}
</div>
</Accordion>
</section>
);
}

0 comments on commit 6e98eb8

Please sign in to comment.