@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
1 lines • 1.78 kB
Source Map (JSON)
{"version":3,"file":"use-avatar-group.cjs","names":["useValidChildren","getRootProps: PropGetter"],"sources":["../../../../src/components/avatar/use-avatar-group.ts"],"sourcesContent":["import type { HTMLProps, PropGetter } from \"../../core\"\nimport { useCallback, useMemo } from \"react\"\nimport { isUndefined, useValidChildren } from \"../../utils\"\n\nexport interface UseAvatarGroupProps extends HTMLProps {\n /**\n * The maximum number of visible avatars.\n */\n max?: number\n /**\n * Whether to reverse the order of the avatars.\n */\n reverse?: boolean\n}\n\nexport const useAvatarGroup = ({\n children,\n max,\n reverse,\n ...rest\n}: UseAvatarGroupProps = {}) => {\n const validChildren = useValidChildren(children)\n const excess = !isUndefined(max) ? validChildren.length - max : 0\n\n const getRootProps: PropGetter = useCallback(\n (props) => ({ ...rest, ...props, role: \"group\" }),\n [rest],\n )\n\n const cloneChildren = useMemo(() => {\n const omittedChildren = !isUndefined(max)\n ? validChildren.slice(0, max)\n : [...validChildren]\n\n return reverse ? omittedChildren.reverse() : omittedChildren\n }, [max, validChildren, reverse])\n\n return {\n children: cloneChildren,\n excess,\n getRootProps,\n }\n}\n\nexport type UseAvatarGroupReturn = ReturnType<typeof useAvatarGroup>\n"],"mappings":";;;;;;;AAeA,MAAa,kBAAkB,EAC7B,UACA,KACA,QACA,GAAG,SACoB,EAAE,KAAK;CAC9B,MAAM,gBAAgBA,kCAAiB,SAAS;CAChD,MAAM,SAAS,oDAAa,IAAI,GAAG,cAAc,SAAS,MAAM;CAEhE,MAAMC,uCACH,WAAW;EAAE,GAAG;EAAM,GAAG;EAAO,MAAM;EAAS,GAChD,CAAC,KAAK,CACP;AAUD,QAAO;EACL,mCATkC;GAClC,MAAM,kBAAkB,oDAAa,IAAI,GACrC,cAAc,MAAM,GAAG,IAAI,GAC3B,CAAC,GAAG,cAAc;AAEtB,UAAO,UAAU,gBAAgB,SAAS,GAAG;KAC5C;GAAC;GAAK;GAAe;GAAQ,CAAC;EAI/B;EACA;EACD"}