@yamada-ui/react
Version:
React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion
1 lines • 7.2 kB
Source Map (JSON)
{"version":3,"file":"notice.cjs","names":["PLACEMENT_MAP: {\n [key in NoticePlacement]: ToasterPosition\n}","createSlotComponent","noticeStyle","useNoticeContext","limit","styled","Toaster","toast","CloseButton"],"sources":["../../../../src/components/notice/notice.tsx"],"sourcesContent":["\"use client\"\n\nimport type { RefObject } from \"react\"\nimport type { ToasterProps } from \"sonner\"\nimport type {\n HTMLStyledProps,\n NoticeCloseStrategy,\n NoticeConfig,\n NoticePlacement,\n} from \"../../core\"\nimport type { CloseButtonProps } from \"../close-button\"\nimport type { Controller, NoticeMethods } from \"./notice-provider\"\nimport type { NoticeStyle } from \"./notice.style\"\nimport type { UseNoticeOptions } from \"./use-notice\"\nimport { useCallback, useMemo, useState } from \"react\"\nimport { toast, Toaster } from \"sonner\"\nimport { createSlotComponent, styled } from \"../../core\"\nimport { assignRef, dataAttr, handlerAll, noop } from \"../../utils\"\nimport { Alert } from \"../alert\"\nimport { CloseButton } from \"../close-button\"\nimport { useNoticeContext } from \"./notice-provider\"\nimport { noticeStyle } from \"./notice.style\"\n\ntype ToasterPosition = Required<ToasterProps>[\"position\"]\n\nexport const PLACEMENT_MAP: {\n [key in NoticePlacement]: ToasterPosition\n} = {\n end: \"bottom-center\",\n \"end-center\": \"bottom-center\",\n \"end-end\": \"bottom-right\",\n \"end-start\": \"bottom-left\",\n start: \"top-center\",\n \"start-center\": \"top-center\",\n \"start-end\": \"top-right\",\n \"start-start\": \"top-left\",\n}\n\nexport interface NoticeRootProps\n extends Pick<Required<NoticeConfig>, \"expand\" | \"limit\" | \"placement\"> {\n ref: RefObject<Controller>\n}\n\nconst {\n PropsContext: NoticePropsContext,\n usePropsContext: useNoticePropsContext,\n withContext,\n withProvider,\n} = createSlotComponent<NoticeRootProps, NoticeStyle>(\"notice\", noticeStyle)\n\nexport { NoticePropsContext, useNoticePropsContext }\n\nexport const NoticeRoot = withProvider<\"fragment\", NoticeRootProps>(\n ({ ref, expand, limit, placement, ...rest }) => {\n const { getId } = useNoticeContext()\n const position = useMemo(() => PLACEMENT_MAP[placement], [placement])\n const [updatedLimit, setUpdatedLimit] = useState(limit)\n\n const getLimit = useCallback<NoticeMethods[\"getLimit\"]>(\n (target) => {\n if (target === placement && updatedLimit !== limit) {\n return updatedLimit\n } else {\n return limit\n }\n },\n [placement, limit, updatedLimit],\n )\n\n const updateLimit = useCallback<NoticeMethods[\"updateLimit\"]>(\n ({ limit, placement: target }) => {\n if (target === placement) setUpdatedLimit(limit)\n },\n [placement],\n )\n\n assignRef(ref.current.updateLimit, updateLimit)\n assignRef(ref.current.getLimit, getLimit)\n\n return (\n <styled.div {...rest}>\n <Toaster\n id={getId(placement)}\n containerAriaLabel=\"\"\n expand={expand}\n gap={16}\n hotkey={[\"\"]}\n mobileOffset=\"var(--mobile-offset)\"\n offset=\"var(--offset)\"\n position={position}\n visibleToasts={updatedLimit}\n />\n </styled.div>\n )\n },\n \"root\",\n)()\n\nexport interface NoticeItemProps\n extends UseNoticeOptions,\n Omit<HTMLStyledProps, \"id\" | \"title\"> {\n closeStrategies?: NoticeCloseStrategy[]\n}\n\nexport const NoticeItem = withContext<\"div\", NoticeItemProps>(\n ({\n id,\n variant = \"plain\",\n closable,\n closeStrategies = [\"click\", \"drag\"],\n description,\n loadingScheme,\n status,\n title,\n withIcon = true,\n closeButtonProps,\n contentProps,\n descriptionProps,\n iconProps,\n loadingProps,\n titleProps,\n onClick,\n ...rest\n }) => {\n const onClose = useCallback(() => toast.dismiss(id), [id])\n\n return (\n <Alert.Root\n variant={variant}\n status={status}\n {...rest}\n onClick={handlerAll(\n onClick,\n closable && closeStrategies.includes(\"click\") ? onClose : noop,\n )}\n >\n {withIcon ? (\n loadingScheme ? (\n <Alert.Loading loadingScheme={loadingScheme} {...loadingProps} />\n ) : (\n <Alert.Icon {...iconProps} />\n )\n ) : null}\n\n <NoticeContent\n data-close-button={dataAttr(\n closable && closeStrategies.includes(\"button\"),\n )}\n {...contentProps}\n >\n {title ? (\n <Alert.Title me=\"0\" {...titleProps}>\n {title}\n </Alert.Title>\n ) : null}\n {description ? (\n <Alert.Description lineClamp={2} {...descriptionProps}>\n {description}\n </Alert.Description>\n ) : null}\n </NoticeContent>\n\n {closable && closeStrategies.includes(\"button\") ? (\n <NoticeCloseButton\n data-variant={variant}\n {...closeButtonProps}\n onClick={handlerAll(closeButtonProps?.onClick, onClose)}\n />\n ) : null}\n </Alert.Root>\n )\n },\n \"item\",\n)()\n\nexport interface NoticeContentProps extends HTMLStyledProps {}\n\nexport const NoticeContent = withContext<\"div\", NoticeContentProps>(\n \"div\",\n \"content\",\n)()\n\nexport interface NoticeCloseButtonProps extends CloseButtonProps {}\n\nexport const NoticeCloseButton = withContext<\"button\", NoticeCloseButtonProps>(\n CloseButton,\n \"closeButton\",\n)()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAyBA,MAAaA,gBAET;CACF,KAAK;CACL,cAAc;CACd,WAAW;CACX,aAAa;CACb,OAAO;CACP,gBAAgB;CAChB,aAAa;CACb,eAAe;CAChB;AAOD,MAAM,EACJ,cAAc,oBACd,iBAAiB,uBACjB,aACA,iBACEC,6CAAkD,UAAUC,iCAAY;AAI5E,MAAa,aAAa,cACvB,EAAE,KAAK,QAAQ,OAAO,UAAW,GAAG,WAAW;CAC9C,MAAM,EAAE,UAAUC,0CAAkB;CACpC,MAAM,oCAAyB,cAAc,YAAY,CAAC,UAAU,CAAC;CACrE,MAAM,CAAC,cAAc,uCAA4B,MAAM;CAEvD,MAAM,mCACH,WAAW;AACV,MAAI,WAAW,aAAa,iBAAiB,MAC3C,QAAO;MAEP,QAAO;IAGX;EAAC;EAAW;EAAO;EAAa,CACjC;CAED,MAAM,sCACH,EAAE,gBAAO,WAAW,aAAa;AAChC,MAAI,WAAW,UAAW,iBAAgBC,QAAM;IAElD,CAAC,UAAU,CACZ;AAED,uBAAU,IAAI,QAAQ,aAAa,YAAY;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