(
34 | nodeOrFunc: ReactNode | ((props: P) => ReactNode),
35 | props: P
36 | ) => ReactNode = (nodeOrFunc, props) =>
37 | typeof nodeOrFunc === 'function' ? nodeOrFunc(props) : nodeOrFunc;
38 |
39 | const WrappedItem = memo(
40 | ({
41 | forwardedRef,
42 | itemRef,
43 | state,
44 | toggle,
45 | className,
46 | disabled,
47 | header,
48 | headingTag: Heading = 'h3',
49 | headingProps,
50 | buttonProps,
51 | contentProps,
52 | panelProps,
53 | children,
54 | ...rest
55 | }: WrappedItemProps (
12 | WrappedItem: MemoExoticComponent<(props: ItemStateProps (className?: ClassNameProp , props?: P) => {
10 | const blockElement = element ? `${block}__${element}` : block;
11 |
12 | let classString = blockElement;
13 | modifiers &&
14 | Object.keys(modifiers).forEach((name) => {
15 | const value = modifiers[name];
16 | if (value) classString += ` ${blockElement}--${value === true ? name : `${name}-${value}`}`;
17 | });
18 |
19 | let expandedClassName = typeof className === 'function' ? className(props!) : className;
20 | if (typeof expandedClassName === 'string') {
21 | expandedClassName = expandedClassName.trim();
22 | if (expandedClassName) classString += ` ${expandedClassName}`;
23 | }
24 |
25 | return classString;
26 | };
27 |
28 | export { bem };
29 |
--------------------------------------------------------------------------------
/src/utils/constants.ts:
--------------------------------------------------------------------------------
1 | import { createContext, HTMLAttributes } from 'react';
2 | import {
3 | TransitionState,
4 | TransitionMapResult,
5 | TransitionMapOptions,
6 | TransitionOptions
7 | } from 'react-transition-state';
8 |
9 | export const ACCORDION_BLOCK = 'szh-accordion';
10 | export const ACCORDION_PREFIX = 'szh-adn';
11 | export const ACCORDION_ATTR: string = `data-${ACCORDION_PREFIX}`;
12 | export const ACCORDION_BTN_ATTR = `data-${ACCORDION_PREFIX}-btn`;
13 |
14 | export type Modifiers = {
15 | readonly [index: string]: boolean | string;
16 | };
17 | export type ClassNameProp = string | ((props: P) => string);
18 | export interface ElementProps ;
21 | 'data-testid'?: string | number;
22 | }
23 |
24 | export type ItemKey = Element | string | number;
25 | export type TransitionProp =
26 | | boolean
27 | | {
28 | enter?: boolean;
29 | exit?: boolean;
30 | preEnter?: boolean;
31 | preExit?: boolean;
32 | };
33 |
34 | export interface ItemState {
35 | readonly state: TransitionState;
36 | readonly toggle: (toEnter?: boolean) => void;
37 | disabled?: boolean;
38 | }
39 |
40 | export interface ItemStateOptions {
41 | itemKey?: string | number;
42 | initialEntered?: boolean;
43 | disabled?: boolean;
44 | }
45 |
46 | export interface AccordionProviderOptions
47 | extends Omit<
48 | TransitionMapOptions (WrappedItem: MemoExoticComponent<(props: ItemStateProps (className?: ClassNameProp , props?: P) => string;
7 | export { bem };
8 |
--------------------------------------------------------------------------------
/types/utils/constants.d.ts:
--------------------------------------------------------------------------------
1 | import { HTMLAttributes } from 'react';
2 | import { TransitionState, TransitionMapResult, TransitionMapOptions, TransitionOptions } from 'react-transition-state';
3 | export declare const ACCORDION_BLOCK = "szh-accordion";
4 | export declare const ACCORDION_PREFIX = "szh-adn";
5 | export declare const ACCORDION_ATTR: string;
6 | export declare const ACCORDION_BTN_ATTR = "data-szh-adn-btn";
7 | export type Modifiers = {
8 | readonly [index: string]: boolean | string;
9 | };
10 | export type ClassNameProp = string | ((props: P) => string);
11 | export interface ElementProps ;
13 | 'data-testid'?: string | number;
14 | }
15 | export type ItemKey = Element | string | number;
16 | export type TransitionProp = boolean | {
17 | enter?: boolean;
18 | exit?: boolean;
19 | preEnter?: boolean;
20 | preExit?: boolean;
21 | };
22 | export interface ItemState {
23 | readonly state: TransitionState;
24 | readonly toggle: (toEnter?: boolean) => void;
25 | disabled?: boolean;
26 | }
27 | export interface ItemStateOptions {
28 | itemKey?: string | number;
29 | initialEntered?: boolean;
30 | disabled?: boolean;
31 | }
32 | export interface AccordionProviderOptions extends Omit
14 | Lorem ipsum dolor sit amet, consectetur adipiscing elit,
15 | sed do eiusmod tempor incididunt ut labore et dolore magna
16 | aliqua.
17 |
73 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
74 | do eiusmod tempor incididunt ut labore et dolore magna
75 | aliqua.
76 | What is Lorem Ipsum?
13 | Lorem ipsum is a placeholder text commonly used to
14 | demonstrate the visual form of a document.
15 | {description}
14 | {/* Accessing item state by providing an `itemKey` */}
15 | {/* highlight-next-line */}
16 | Next item expanded: {getItemState('next').isEnter.toString()}
17 | {siteConfig.tagline}
45 |
53 |
54 | {isMounted && (
55 | // Add an extra `div` around the panel `div` for the
56 | // height transition to work as intended
57 | // highlight-next-line
58 |
40 |
48 |
49 | {isMounted && (
50 |
42 |
50 |
51 | {isMounted && (
52 | {title}
60 |
6 |
10 |
11 |
16 | {siteConfig.title}
17 |
18 |