@devopness/ui-react
Version:
Devopness Design System React Components - Painless essential DevOps to everyone
85 lines (84 loc) • 2.65 kB
TypeScript
import { ComponentType } from 'react';
import { DropdownOption } from '../Dropdown';
/**
* Base props shared by both Accordion variations
*/
type AccordionExpandBaseProps = {
/** Label displayed in the accordion summary */
label: string;
/** Optional tooltip for the accordion summary */
tooltip?: string;
/** Disables the accordion if true */
isDisabled?: boolean;
/**
* Optional callback for handling errors on item click.
* Receives the error thrown by the item's onClick.
*/
onItemClickError?: (error: unknown) => void;
};
/**
* Props when using navigationComponent (requires url in items)
*/
type AccordionWithNavigation = AccordionExpandBaseProps & {
/**
* List of items that **must** have `url` defined
*/
items: DropdownOption[];
/**
* Component to use for navigation links
*/
navigationComponent: ComponentType<{
to: string;
children: React.ReactNode;
hideUnderline?: boolean;
style?: React.CSSProperties;
}>;
};
/**
* Props when NOT using navigationComponent (items cannot have url)
*/
type AccordionWithoutNavigation = AccordionExpandBaseProps & {
items: (Omit<DropdownOption, 'url'> & {
url?: undefined;
})[];
navigationComponent?: never;
};
/**
* Union type for Accordion props
*/
type AccordionExpandProps = AccordionWithNavigation | AccordionWithoutNavigation;
/**
* Accordion component that displays a list of items with optional tooltips and navigation links.
*
* This component supports two usage modes:
*
* 1. **Navigation Mode:** If any item in `items` contains a `url`, you **must** provide a
* `navigationComponent` to render the link. The `navigationComponent` receives `to`,
* `children`, `hideUnderline`, and `style` props.
*
* 2. **Standard Mode:** If none of the items have a `url`, `navigationComponent` should **not** be provided.
*
*
* @example
* // Standard usage without links
* <AccordionExpand
* label="My Accordion"
* items={[
* { label: 'Option 1', onClick: async () => console.log('clicked') },
* { label: 'Option 2', onClick: () => console.log('clicked too') }
* ]}
* />
*
* @example
* // Navigation mode with links
* <AccordionExpand
* label="My Accordion"
* items={[
* { label: 'Option 1', url: '/home' },
* { label: 'Option 2', url: '/about' }
* ]}
* navigationComponent={MyNavLink}
* />
*/
declare const AccordionExpand: ({ label, tooltip, isDisabled, items, navigationComponent, onItemClickError, }: AccordionExpandProps) => import("react/jsx-runtime").JSX.Element;
export { AccordionExpand };