All files / src/section Ellipsis.tsx

100% Statements 16/16
78.57% Branches 11/14
100% Functions 2/2
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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        22x 4x 4x 4x     22x               22x 119x 119x 119x   119x 119x   117x 1x     22x  
import { type TagType } from '../store/Types';
import { type SectionElement, useSectionStore } from '../store/Section';
import { useSectionRender } from '../utils/useRender';
 
export const Ellipsis = <K extends TagType>(props: SectionElement<K>) => {
  const { Ellipsis: Comp = {} } = useSectionStore();
  useSectionRender(Comp, props, 'Ellipsis');
  return null;
};
 
Ellipsis.displayName = 'JVR.Ellipsis';
 
export interface EllipsisCompProps<T extends object> {
  value?: T;
  keyName: string | number;
  isExpanded: boolean;
}
 
export const EllipsisComp = <T extends object>({ isExpanded, value, keyName }: EllipsisCompProps<T>) => {
  const { Ellipsis: Comp = {} } = useSectionStore();
  const { as, render, ...reset } = Comp;
  const Elm = as || 'span';
  const child =
    render && typeof render === 'function' && render({ ...reset, 'data-expanded': isExpanded }, { value, keyName });
  if (child) return child;
 
  if (!isExpanded || (typeof value === 'object' && Object.keys(value).length == 0)) return null;
  return <Elm {...reset} />;
};
 
EllipsisComp.displayName = 'JVR.EllipsisComp';