-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathValueExtra.tsx
More file actions
40 lines (29 loc) · 1.24 KB
/
ValueExtra.tsx
File metadata and controls
40 lines (29 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { type TagType } from '../store/Types';
import { type SectionElement, useSectionStore } from '../store/Section';
import { useSectionRender } from '../utils/useRender';
import { type SectionElementResult } from '../store/Section';
export const ValueExtra = <K extends TagType>(props: SectionElement<K>) => {
const { ValueExtra: Comp = {} } = useSectionStore();
useSectionRender(Comp, props, 'ValueExtra');
return null;
};
ValueExtra.displayName = 'JVR.ValueExtra';
export interface ValueExtraCompProps<T extends object> extends React.HTMLAttributes<HTMLDivElement>, SectionElementResult<T> {
}
export const ValueExtraComp = <T extends object>(props: React.PropsWithChildren<ValueExtraCompProps<T>>) => {
const { children, value, parentValue, keyName, keys, expandKey, ...other } = props;
const { ValueExtra: Comp = {} } = useSectionStore();
const { as, render, children: _, ...reset } = Comp;
const Elm = as || 'div';
const child =
render &&
typeof render === 'function' &&
render({ ...other, ...reset, children }, { value, keyName, parentValue, keys, expandKey });
if (child) return child;
return (
<Elm {...other} {...reset}>
{children}
</Elm>
);
};
ValueExtraComp.displayName = 'JVR.ValueExtraComp';