@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
1 lines • 3.56 kB
Source Map (JSON)
{"version":3,"file":"use-group.cjs","names":["useValidChildren"],"sources":["../../../../src/components/group/use-group.ts"],"sourcesContent":["import type { CSSProperties, DataAttributes, ReactNode } from \"react\"\nimport { cloneElement, useMemo } from \"react\"\nimport { dataAttr, isNull, isUndefined, useValidChildren } from \"../../utils\"\n\nexport const useGroup = (children?: ReactNode) => {\n const validChildren = useValidChildren(children)\n const omittedChildren = useMemo(\n () =>\n validChildren.filter((child) => {\n const ungrouped = child.props[\"data-ungrouped\"]\n\n return isUndefined(ungrouped) || isNull(ungrouped)\n }),\n [validChildren],\n )\n const count = omittedChildren.length\n const cloneChildren = useMemo(\n () =>\n validChildren.map((child) => {\n const index = omittedChildren.indexOf(child)\n const ungrouped = index === -1\n\n if (ungrouped) return child\n\n return cloneElement(child, {\n ...child.props,\n style: {\n \"--group-count\": count,\n \"--group-index\": index,\n ...(child.props?.style ?? {}),\n },\n \"data-group-between\": dataAttr(index > 0 && index < count - 1),\n \"data-group-end\": dataAttr(index === count - 1),\n \"data-group-start\": dataAttr(index === 0),\n \"data-peer\": \"\",\n })\n }),\n [validChildren, omittedChildren, count],\n )\n\n return cloneChildren\n}\n\nexport type UseGroupReturn = ReturnType<typeof useGroup>\n\ninterface Props extends DataAttributes {\n style?: CSSProperties\n}\n\nexport const useGroupItemProps = <Y extends Props>({\n style: {\n \"--group-count\": groupCount,\n \"--group-index\": groupIndex,\n ...style\n } = {},\n \"data-group-between\": dataGroupBetween,\n \"data-group-end\": dataGroupEnd,\n \"data-group-start\": dataGroupStart,\n \"data-peer\": dataPeer,\n ...rest\n}: Y) => {\n const pickedProps = useMemo(\n () => ({\n style: {\n \"--group-count\": groupCount!,\n \"--group-index\": groupIndex!,\n },\n \"data-group-between\": dataGroupBetween,\n \"data-group-end\": dataGroupEnd,\n \"data-group-start\": dataGroupStart,\n \"data-peer\": dataPeer,\n }),\n [\n groupCount,\n groupIndex,\n dataGroupBetween,\n dataGroupEnd,\n dataGroupStart,\n dataPeer,\n ],\n )\n const omittedProps = useMemo(() => ({ style, ...rest }), [style, rest])\n\n return [pickedProps, omittedProps] as const\n}\n\nexport type UseGroupItemReturn = ReturnType<typeof useGroupItemProps>\n"],"mappings":";;;;;;;AAIA,MAAa,YAAY,aAAyB;CAChD,MAAM,gBAAgBA,kCAAiB,SAAS;CAChD,MAAM,2CAEF,cAAc,QAAQ,UAAU;EAC9B,MAAM,YAAY,MAAM,MAAM;AAE9B,4DAAmB,UAAU,kDAAW,UAAU;GAClD,EACJ,CAAC,cAAc,CAChB;CACD,MAAM,QAAQ,gBAAgB;AAyB9B,iCAtBI,cAAc,KAAK,UAAU;EAC3B,MAAM,QAAQ,gBAAgB,QAAQ,MAAM;AAG5C,MAFkB,UAAU,GAEb,QAAO;AAEtB,iCAAoB,OAAO;GACzB,GAAG,MAAM;GACT,OAAO;IACL,iBAAiB;IACjB,iBAAiB;IACjB,GAAI,MAAM,OAAO,SAAS,EAAE;IAC7B;GACD,sEAA+B,QAAQ,KAAK,QAAQ,QAAQ,EAAE;GAC9D,kEAA2B,UAAU,QAAQ,EAAE;GAC/C,oEAA6B,UAAU,EAAE;GACzC,aAAa;GACd,CAAC;GACF,EACJ;EAAC;EAAe;EAAiB;EAAM,CACxC;;AAWH,MAAa,qBAAsC,EACjD,OAAO,EACL,iBAAiB,YACjB,iBAAiB,WACjB,GAAG,UACD,EAAE,EACN,sBAAsB,kBACtB,kBAAkB,cAClB,oBAAoB,gBACpB,aAAa,SACb,GAAG,WACI;AAuBP,QAAO,2BArBE;EACL,OAAO;GACL,iBAAiB;GACjB,iBAAiB;GAClB;EACD,sBAAsB;EACtB,kBAAkB;EAClB,oBAAoB;EACpB,aAAa;EACd,GACD;EACE;EACA;EACA;EACA;EACA;EACA;EACD,CACF,4BACmC;EAAE;EAAO,GAAG;EAAM,GAAG,CAAC,OAAO,KAAK,CAAC,CAErC"}