@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
1 lines • 4.87 kB
Source Map (JSON)
{"version":3,"file":"stat.cjs","names":["createSlotComponent","statStyle","useSplitChildren","styled","useI18n","TriangleIcon"],"sources":["../../../../src/components/stat/stat.tsx"],"sourcesContent":["\"use client\"\n\nimport type { ReactNode } from \"react\"\nimport type { HTMLStyledProps, ThemeProps } from \"../../core\"\nimport type { StatStyle } from \"./stat.style\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { useI18n } from \"../../providers/i18n-provider\"\nimport { useSplitChildren } from \"../../utils\"\nimport { TriangleIcon } from \"../icon\"\nimport { statStyle } from \"./stat.style\"\n\nexport interface StatRootProps\n extends HTMLStyledProps<\"dl\">,\n ThemeProps<StatStyle> {\n /**\n * If `true`, container will center its children regardless of their width.\n *\n * @default false\n */\n centerContent?: boolean\n /**\n * The stat helper message to use.\n */\n helperMessage?: ReactNode\n /**\n * The stat icon to use.\n */\n icon?: StatIconProps[\"type\"]\n /**\n * The stat label to use.\n */\n label?: ReactNode\n /**\n * The stat value to use.\n */\n value?: ReactNode\n /**\n * Props for stat helper message component.\n */\n helperMessageProps?: StatHelperMessageProps\n /**\n * Props for stat icon component.\n */\n iconProps?: Omit<StatIconProps, \"type\">\n /**\n * Props for stat label component.\n */\n labelProps?: StatLabelProps\n /**\n * Props for stat value component.\n */\n valueProps?: StatValueProps\n}\n\nconst {\n PropsContext: StatPropsContext,\n usePropsContext: useStatPropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<StatRootProps, StatStyle>(\"stat\", statStyle)\n\nexport { StatPropsContext, useStatPropsContext }\n\n/**\n * `Stat` is used to show numbers and data in a box.\n *\n * @see https://yamada-ui.com/docs/components/stat\n */\nexport const StatRoot = withProvider<\"dl\", StatRootProps>(\n ({\n children,\n helperMessage,\n icon,\n label,\n value,\n helperMessageProps,\n iconProps,\n labelProps,\n valueProps,\n ...rest\n }) => {\n const [\n omittedChildren,\n customStatLabel,\n customStatValue,\n customStatHelperMessage,\n ] = useSplitChildren(children, StatLabel, StatValue, StatHelperMessage)\n\n return (\n <styled.dl {...rest}>\n {customStatLabel ?? <StatLabel {...labelProps}>{label}</StatLabel>}\n {customStatValue ?? <StatValue {...valueProps}>{value}</StatValue>}\n {customStatHelperMessage ?? (\n <StatHelperMessage {...helperMessageProps}>\n {icon ? <StatIcon type={icon} {...iconProps} /> : null}\n {helperMessage}\n </StatHelperMessage>\n )}\n {omittedChildren}\n </styled.dl>\n )\n },\n \"root\",\n)()\n\nexport interface StatIconProps extends HTMLStyledProps<\"svg\"> {\n /**\n * The type of the icon.\n *\n * @default 'increase'\n */\n type?: \"decrease\" | \"increase\"\n}\n\nexport const StatIcon = withContext<\"svg\", StatIconProps>(\n ({ type = \"increase\", ...rest }) => {\n const { t } = useI18n(\"stat\")\n\n return (\n <TriangleIcon\n aria-label={type === \"increase\" ? t(\"Increased by\") : t(\"Decreased by\")}\n data-type={type}\n {...rest}\n />\n )\n },\n \"icon\",\n)()\n\nexport interface StatLabelProps extends HTMLStyledProps<\"dt\"> {}\n\nexport const StatLabel = withContext<\"dt\", StatLabelProps>(\"dt\", \"label\")()\n\nexport interface StatValueProps extends HTMLStyledProps<\"dd\"> {}\n\nexport const StatValue = withContext<\"dd\", StatValueProps>(\"dd\", \"value\")()\n\nexport interface StatUnitProps extends HTMLStyledProps<\"span\"> {}\n\nexport const StatUnit = withContext<\"span\", StatUnitProps>(\"span\", \"unit\")()\n\nexport interface StatHelperMessageProps extends HTMLStyledProps<\"dd\"> {}\n\nexport const StatHelperMessage = withContext<\"dd\", StatHelperMessageProps>(\n \"dd\",\n \"helperMessage\",\n)()\n"],"mappings":";;;;;;;;;;;;;;AAsDA,MAAM,EACJ,cAAc,kBACd,iBAAiB,qBACjB,aACA,iBACEA,6CAA8C,QAAQC,6BAAU;;;;;;AASpE,MAAa,WAAW,cACrB,EACC,UACA,eACA,MACA,OACA,OACA,oBACA,WACA,YACA,WACA,GAAG,WACC;CACJ,MAAM,CACJ,iBACA,iBACA,iBACA,2BACEC,kCAAiB,UAAU,WAAW,WAAW,kBAAkB;AAEvE,QACE,4CAACC,uBAAO;EAAG,GAAI;;GACZ,mBAAmB,2CAAC;IAAU,GAAI;cAAa;KAAkB;GACjE,mBAAmB,2CAAC;IAAU,GAAI;cAAa;KAAkB;GACjE,2BACC,4CAAC;IAAkB,GAAI;eACpB,OAAO,2CAAC;KAAS,MAAM;KAAM,GAAI;MAAa,GAAG,MACjD;KACiB;GAErB;;GACS;GAGhB,OACD,EAAE;AAWH,MAAa,WAAW,aACrB,EAAE,OAAO,WAAY,GAAG,WAAW;CAClC,MAAM,EAAE,MAAMC,8BAAQ,OAAO;AAE7B,QACE,2CAACC;EACC,cAAY,SAAS,aAAa,EAAE,eAAe,GAAG,EAAE,eAAe;EACvE,aAAW;EACX,GAAI;GACJ;GAGN,OACD,EAAE;AAIH,MAAa,YAAY,YAAkC,MAAM,QAAQ,EAAE;AAI3E,MAAa,YAAY,YAAkC,MAAM,QAAQ,EAAE;AAI3E,MAAa,WAAW,YAAmC,QAAQ,OAAO,EAAE;AAI5E,MAAa,oBAAoB,YAC/B,MACA,gBACD,EAAE"}