@@ -2,78 +2,25 @@ import React, { createContext, forwardRef, HTMLAttributes, useState } from 'reac
|
2 | 2 | import PropTypes from 'prop-types'
|
3 | 3 | import classNames from 'classnames'
|
4 | 4 |
|
5 |
| -import { mergeClassNames } from '../../utils' |
6 |
| - |
7 | 5 | export interface CAccordionProps extends HTMLAttributes<HTMLDivElement> {
|
8 | 6 | /**
|
9 |
| -* Determines which accordion item is currently active (expanded) by default. |
10 |
| -* Accepts a number or string corresponding to the `itemKey` of the desired accordion item. |
11 |
| -* |
12 |
| -* @example |
13 |
| -* <CAccordion activeItemKey="1">...</CAccordion> |
| 7 | +* The active item key. |
14 | 8 | */
|
15 | 9 | activeItemKey?: number | string
|
16 |
| - |
17 | 10 | /**
|
18 |
| -* When set to `true`, multiple accordion items within the React Accordion can be open simultaneously. |
19 |
| -* This is ideal for scenarios where users need to view multiple sections at once without collapsing others. |
20 |
| -* |
21 |
| -* @default false |
22 |
| -* |
23 |
| -* @example |
24 |
| -* <CAccordion alwaysOpen>...</CAccordion> |
| 11 | +* Make accordion items stay open when another item is opened |
25 | 12 | */
|
26 | 13 | alwaysOpen?: boolean
|
27 |
| - |
28 | 14 | /**
|
29 |
| -* Allows you to apply custom CSS classes to the React Accordion for enhanced styling and theming. |
30 |
| -* |
31 |
| -* @example |
32 |
| -* <CAccordion className="my-custom-accordion">...</CAccordion> |
| 15 | +* A string of all className you want applied to the base component. |
33 | 16 | */
|
34 | 17 | className?: string
|
35 |
| - |
36 | 18 | /**
|
37 |
| -* Allows overriding or extending the default CSS class names used in the component. |
38 |
| -* |
39 |
| -* - `ACCORDION`: Base class for the accordion component. |
40 |
| -* - `ACCORDION_FLUSH`: Class applied when the `flush` prop is set to true, ensuring an edge-to-edge layout. |
41 |
| -* |
42 |
| -* Use this prop to customize the styles of specific parts of the accordion. |
43 |
| -* |
44 |
| -* @example |
45 |
| -* const customClasses = { |
46 |
| -* ACCORDION: 'custom-accordion', |
47 |
| -* ACCORDION_FLUSH: 'custom-accordion-flush' |
48 |
| -* } |
49 |
| -* <CAccordion customClassNames={customClasses}>...</CAccordion> |
50 |
| -*/ |
51 |
| -customClassNames?: Partial<typeof ACCORDION_CLASS_NAMES> |
52 |
| - |
53 |
| -/** |
54 |
| -* When `flush` is set to `true`, the React Accordion renders edge-to-edge with its parent container, |
55 |
| -* creating a seamless and modern look ideal for minimalist designs. |
56 |
| -* |
57 |
| -* @default false |
58 |
| -* |
59 |
| -* @example |
60 |
| -* <CAccordion flush>...</CAccordion> |
| 19 | +* Removes the default background-color, some borders, and some rounded corners to render accordions edge-to-edge with their parent container. |
61 | 20 | */
|
62 | 21 | flush?: boolean
|
63 | 22 | }
|
64 | 23 |
|
65 |
| -export const ACCORDION_CLASS_NAMES = { |
66 |
| -/** |
67 |
| -* Base class for the accordion container. |
68 |
| -*/ |
69 |
| -ACCORDION: 'accordion', |
70 |
| - |
71 |
| -/** |
72 |
| -* Applied when the `flush` prop is enabled. |
73 |
| -*/ |
74 |
| -ACCORDION_FLUSH: 'accordion-flush', |
75 |
| -} |
76 |
| - |
77 | 24 | export interface CAccordionContextProps {
|
78 | 25 | _activeItemKey?: number | string
|
79 | 26 | alwaysOpen?: boolean
|
@@ -83,24 +30,12 @@ export interface CAccordionContextProps {
|
83 | 30 | export const CAccordionContext = createContext({} as CAccordionContextProps)
|
84 | 31 |
|
85 | 32 | export const CAccordion = forwardRef<HTMLDivElement, CAccordionProps>(
|
86 |
| -( |
87 |
| -{ children, activeItemKey, alwaysOpen = false, className, customClassNames, flush, ...rest }, |
88 |
| -ref, |
89 |
| -) => { |
| 33 | +({ children, activeItemKey, alwaysOpen = false, className, flush, ...rest }, ref) => { |
90 | 34 | const [_activeItemKey, setActiveKey] = useState(activeItemKey)
|
91 | 35 |
|
92 |
| -const mergedClassNames = mergeClassNames<typeof ACCORDION_CLASS_NAMES>( |
93 |
| -ACCORDION_CLASS_NAMES, |
94 |
| -customClassNames, |
95 |
| -) |
96 |
| - |
97 | 36 | return (
|
98 | 37 | <div
|
99 |
| -className={classNames( |
100 |
| -mergedClassNames.ACCORDION, |
101 |
| -{ [mergedClassNames.ACCORDION_FLUSH]: flush }, |
102 |
| -className, |
103 |
| -)} |
| 38 | +className={classNames('accordion', { 'accordion-flush': flush }, className)} |
104 | 39 | {...rest}
|
105 | 40 | ref={ref}
|
106 | 41 | >
|
|
0 commit comments