/** * Copyright 2025 LY Corporation * * LY Corporation licenses this file to you under the Apache License, * version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at: * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ 'use client'; import * as React from 'react'; import * as AccordionPrimitive from '@radix-ui/react-accordion'; import { Slottable } from '@radix-ui/react-slot'; import { cva } from 'class-variance-authority'; import { ICON_SIZE } from '../constants'; import { cn } from '../lib/utils'; import type { Size } from '../types'; import { Icon } from './icon'; const DefaultValue = { iconSize: 'small', iconAlign: 'right', border: false, } as const; const AccordionContext = React.createContext<{ iconSize: Size; iconAlign: 'left' | 'right'; }>({ iconSize: DefaultValue.iconSize, iconAlign: DefaultValue.iconAlign, }); const Accordion = React.forwardRef< React.ComponentRef, React.ComponentPropsWithoutRef & { iconSize?: Size; iconAlign?: 'left' | 'right'; border?: boolean; } >( ( { iconAlign = DefaultValue.iconAlign, iconSize = DefaultValue.iconSize, border = DefaultValue.border, className, ...props }, ref, ) => ( ), ); Accordion.displayName = 'Accordion'; const AccordionItem = React.forwardRef< React.ComponentRef, React.ComponentPropsWithoutRef & { divider?: boolean; } >(({ divider = true, className, ...props }, ref) => { return ( ); }); AccordionItem.displayName = 'AccordionItem'; const AccordionTrigger = React.forwardRef< React.ComponentRef, React.ComponentPropsWithoutRef >(({ className, children, ...props }, ref) => { const { iconSize, iconAlign } = React.useContext(AccordionContext); return ( {iconAlign === 'left' && ( )} {children} {iconAlign === 'right' && ( )} ); }); AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName; const accordionContentVariants = cva('accordion-content', { variants: { iconAlign: { left: '', right: '', }, iconSize: { small: '', medium: '', large: '', }, }, compoundVariants: [ { iconAlign: 'left', iconSize: 'small', className: 'accordion-content-inset-small', }, { iconAlign: 'left', iconSize: 'medium', className: 'accordion-content-inset-medium', }, { iconAlign: 'left', iconSize: 'large', className: 'accordion-content-inset-large', }, ], defaultVariants: { iconAlign: DefaultValue.iconAlign, iconSize: DefaultValue.iconSize, }, }); const AccordionContent = React.forwardRef< React.ComponentRef, React.ComponentPropsWithoutRef >(({ className, children, ...props }, ref) => { const { iconAlign, iconSize } = React.useContext(AccordionContext); return (
{children}
); }); AccordionContent.displayName = AccordionPrimitive.Content.displayName; export { Accordion, AccordionItem, AccordionTrigger, AccordionContent };