@yamada-ui/notice 2.0.0-next-20240706053520 → 2.0.0-next-20240706062355

Sign up to get free protection for your applications and to get access to all the features.
@@ -218,7 +218,7 @@ var Notice = ({
218
218
  ),
219
219
  /* @__PURE__ */ jsxs(ui.div, { flex: "1", children: [
220
220
  title ? /* @__PURE__ */ jsx(AlertTitle, { className: "ui-notice__title", lineClamp: 1, children: title }) : null,
221
- description ? /* @__PURE__ */ jsx(AlertDescription, { className: "ui-notice__desc", lineClamp: 3, children: description }) : null
221
+ description ? /* @__PURE__ */ jsx(AlertDescription, { className: "ui-notice__description", lineClamp: 3, children: description }) : null
222
222
  ] }),
223
223
  isClosable ? /* @__PURE__ */ jsx(
224
224
  CloseButton,
@@ -240,4 +240,4 @@ export {
240
240
  useNotice,
241
241
  noticeStore
242
242
  };
243
- //# sourceMappingURL=chunk-QJZAGAE4.mjs.map
243
+ //# sourceMappingURL=chunk-O26YP2LY.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/notice.tsx"],"sourcesContent":["import type { AlertProps } from \"@yamada-ui/alert\"\nimport {\n Alert,\n AlertDescription,\n AlertIcon,\n AlertTitle,\n} from \"@yamada-ui/alert\"\nimport { CloseButton } from \"@yamada-ui/close-button\"\nimport type {\n CSSUIObject,\n NoticePlacement,\n NoticeComponentProps,\n NoticeConfigOptions,\n StyledTheme,\n} from \"@yamada-ui/core\"\nimport { ui, useTheme } from \"@yamada-ui/core\"\nimport { cx, merge } from \"@yamada-ui/utils\"\nimport type { FC, ReactNode } from \"react\"\nimport { useMemo } from \"react\"\n\nexport type UseNoticeOptions = NoticeConfigOptions\n\nexport type NoticeOptions = {\n id: string | number\n placement: NoticePlacement\n duration: UseNoticeOptions[\"duration\"]\n status: UseNoticeOptions[\"status\"]\n message: (props: NoticeComponentProps) => ReactNode\n isDelete?: boolean\n onDelete: () => void\n onCloseComplete?: () => void\n style?: CSSUIObject\n}\n\nconst findId = (\n options: NoticeOptions[],\n id: string | number,\n): NoticeOptions | undefined => options.find((notice) => notice.id === id)\n\nconst findNotice = (\n state: State,\n id: string | number,\n): {\n placement: NoticePlacement | undefined\n index: number\n} => {\n const placement = getNoticePlacement(state, id)\n\n const index = placement\n ? state[placement].findIndex((notice) => notice.id === id)\n : -1\n\n return { placement, index }\n}\n\nconst getNoticePlacement = (\n state: State,\n id: string | number,\n): NoticePlacement | undefined => {\n for (const [placement, values] of Object.entries(state)) {\n if (findId(values, id)) return placement as NoticePlacement\n }\n}\n\ntype CreateNoticeOptions = Partial<\n Pick<\n NoticeOptions,\n \"id\" | \"placement\" | \"status\" | \"duration\" | \"onCloseComplete\" | \"style\"\n >\n>\n\nlet counter = 0\n\nconst createNotice = (\n message: (props: NoticeComponentProps) => ReactNode,\n {\n id,\n placement = \"top\",\n duration,\n onCloseComplete,\n status,\n style,\n }: CreateNoticeOptions,\n) => {\n counter += 1\n\n id ??= counter\n\n return {\n id,\n placement,\n status,\n duration,\n message,\n onDelete: () => noticeStore.remove(String(id), placement),\n isDelete: false,\n onCloseComplete,\n style,\n }\n}\n\nconst createRender = (options: UseNoticeOptions): FC<NoticeComponentProps> => {\n const { component } = options\n\n const Render: FC<NoticeComponentProps> = (props) => {\n if (typeof component === \"function\") {\n return component({ ...props, ...options }) as JSX.Element\n } else {\n return <Notice {...props} {...options} />\n }\n }\n\n return Render\n}\n\nconst createNoticeFunc = (\n defaultOptions: UseNoticeOptions,\n theme: StyledTheme,\n) => {\n const themeOptions = theme.__config.notice?.options ?? {}\n\n const computedOptions = (options: UseNoticeOptions) =>\n merge(themeOptions, merge(defaultOptions, options))\n\n const notice = (options: UseNoticeOptions = {}) => {\n options = computedOptions(options)\n\n const message = createRender(options)\n\n return noticeStore.create(message, options)\n }\n\n notice.update = (\n id: string | number,\n options: Omit<UseNoticeOptions, \"id\">,\n ) => {\n options = computedOptions(options)\n\n noticeStore.update(id, options)\n }\n\n notice.closeAll = noticeStore.closeAll\n notice.close = noticeStore.close\n notice.isActive = noticeStore.isActive\n\n return notice\n}\n\ntype CreateNoticeReturn = ReturnType<typeof createNoticeFunc>\n\n/**\n * `useNotice` is a custom hook that controls the notifications of the application.\n *\n * @see Docs https://yamada-ui.com/hooks/use-notice\n */\nexport const useNotice = (\n defaultOptions?: UseNoticeOptions,\n): CreateNoticeReturn => {\n const { theme } = useTheme()\n\n return useMemo(\n () => createNoticeFunc(defaultOptions ?? {}, theme),\n [defaultOptions, theme],\n )\n}\n\ntype State = {\n [K in NoticePlacement]: NoticeOptions[]\n}\n\ntype Store = {\n subscribe: (onStoreChange: () => void) => () => void\n getSnapshot: () => State\n create: (\n message: (props: NoticeComponentProps) => ReactNode,\n options: UseNoticeOptions,\n ) => string | number\n close: (id: string | number) => void\n closeAll: (options?: { placement?: NoticePlacement[] }) => void\n update: (id: string | number, options: Omit<UseNoticeOptions, \"id\">) => void\n remove: (id: string | number, placement: NoticePlacement) => void\n isActive: (id: string | number) => boolean\n}\n\nconst initialState = {\n top: [],\n \"top-left\": [],\n \"top-right\": [],\n bottom: [],\n \"bottom-left\": [],\n \"bottom-right\": [],\n}\n\nconst createNoticeStore = (initialState: State): Store => {\n let state = initialState\n const storeChangeCache = new Set<() => void>()\n\n const setState = (setStateFunc: (values: State) => State) => {\n state = setStateFunc(state)\n storeChangeCache.forEach((onStoreChange) => onStoreChange())\n }\n\n return {\n getSnapshot: () => state,\n\n subscribe: (onStoreChange) => {\n storeChangeCache.add(onStoreChange)\n\n return () => {\n setState(() => initialState)\n storeChangeCache.delete(onStoreChange)\n }\n },\n\n remove: (id, placement) => {\n setState((prevState) => ({\n ...prevState,\n [placement]: prevState[placement].filter((notice) => notice.id != id),\n }))\n },\n\n create: (message, options) => {\n const limit = options.limit\n\n const notice = createNotice(message, options)\n const { placement, id } = notice\n\n setState((prev) => {\n let prevNotices = prev[placement] ?? []\n\n if (\n limit !== undefined &&\n limit > 0 &&\n prevNotices.length > limit - 1\n ) {\n const n = prevNotices.length - (limit - 1)\n const notices = placement.includes(\"top\")\n ? prevNotices.slice(n * -1)\n : prevNotices.slice(0, n)\n\n const ids = notices.map(({ id }) => id)\n\n prevNotices = prevNotices.map((notice) =>\n ids.includes(notice.id) ? { ...notice, isDelete: true } : notice,\n )\n }\n\n const notices = placement.includes(\"top\")\n ? [notice, ...prevNotices]\n : [...prevNotices, notice]\n\n return { ...prev, [placement]: notices }\n })\n\n return id\n },\n\n update: (id, options) => {\n setState((prev) => {\n const next = { ...prev }\n const { placement, index } = findNotice(next, id)\n\n if (placement && index !== -1) {\n next[placement][index] = {\n ...next[placement][index],\n ...options,\n message: createRender(options),\n }\n }\n\n return next\n })\n },\n\n closeAll: ({ placement } = {}) => {\n setState((prev) => {\n let placements: NoticePlacement[] = [\n \"bottom\",\n \"bottom-right\",\n \"bottom-left\",\n \"top\",\n \"top-left\",\n \"top-right\",\n ]\n\n if (placement) placements = placement\n\n return placements.reduce(\n (acc, placement) => {\n acc[placement] = prev[placement].map((notice) => ({\n ...notice,\n isDelete: true,\n }))\n\n return acc\n },\n { ...prev },\n )\n })\n },\n\n close: (id) => {\n setState((prev) => {\n const placement = getNoticePlacement(prev, id)\n\n if (!placement) return prev\n\n return {\n ...prev,\n [placement]: prev[placement].map((notice) =>\n notice.id == id ? { ...notice, isDelete: true } : notice,\n ),\n }\n })\n },\n\n isActive: (id) =>\n Boolean(findNotice(noticeStore.getSnapshot(), id).placement),\n }\n}\n\nexport const noticeStore = createNoticeStore(initialState)\n\nexport type NoticeProps = Omit<AlertProps, keyof UseNoticeOptions> &\n UseNoticeOptions & {\n onClose?: () => void\n }\n\nconst Notice: FC<NoticeProps> = ({\n variant = \"basic\",\n colorScheme,\n status,\n icon,\n title,\n description,\n isClosable,\n className,\n onClose,\n}) => {\n return (\n <Alert\n status={status}\n variant={variant}\n colorScheme={colorScheme}\n alignItems=\"start\"\n boxShadow=\"fallback(lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05))\"\n className={cx(\"ui-notice\", className)}\n pe={isClosable ? 8 : undefined}\n >\n <AlertIcon\n variant={icon?.variant}\n className=\"ui-notice__icon\"\n {...(icon?.color ? { color: icon.color } : {})}\n >\n {icon?.children}\n </AlertIcon>\n\n <ui.div flex=\"1\">\n {title ? (\n <AlertTitle className=\"ui-notice__title\" lineClamp={1}>\n {title}\n </AlertTitle>\n ) : null}\n {description ? (\n <AlertDescription className=\"ui-notice__desc\" lineClamp={3}>\n {description}\n </AlertDescription>\n ) : null}\n </ui.div>\n\n {isClosable ? (\n <CloseButton\n className=\"ui-notice__close-button\"\n size=\"sm\"\n onClick={onClose}\n position=\"absolute\"\n top={2}\n right={2}\n />\n ) : null}\n </Alert>\n )\n}\n"],"mappings":";;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAQ5B,SAAS,IAAI,gBAAgB;AAC7B,SAAS,IAAI,aAAa;AAE1B,SAAS,eAAe;AA0FX,cAyPP,YAzPO;AA1Eb,IAAM,SAAS,CACb,SACA,OAC8B,QAAQ,KAAK,CAAC,WAAW,OAAO,OAAO,EAAE;AAEzE,IAAM,aAAa,CACjB,OACA,OAIG;AACH,QAAM,YAAY,mBAAmB,OAAO,EAAE;AAE9C,QAAM,QAAQ,YACV,MAAM,SAAS,EAAE,UAAU,CAAC,WAAW,OAAO,OAAO,EAAE,IACvD;AAEJ,SAAO,EAAE,WAAW,MAAM;AAC5B;AAEA,IAAM,qBAAqB,CACzB,OACA,OACgC;AAChC,aAAW,CAAC,WAAW,MAAM,KAAK,OAAO,QAAQ,KAAK,GAAG;AACvD,QAAI,OAAO,QAAQ,EAAE,EAAG,QAAO;AAAA,EACjC;AACF;AASA,IAAI,UAAU;AAEd,IAAM,eAAe,CACnB,SACA;AAAA,EACE;AAAA,EACA,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MACG;AACH,aAAW;AAEX,yBAAO;AAEP,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAA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AAG;AAAA,UACH,CAAC,SAAS,GAAG,KAAK,SAAS,EAAE;AAAA,YAAI,CAAC,WAChC,OAAO,MAAM,KAAK,EAAE,GAAG,QAAQ,UAAU,KAAK,IAAI;AAAA,UACpD;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IAEA,UAAU,CAAC,OACT,QAAQ,WAAW,YAAY,YAAY,GAAG,EAAE,EAAE,SAAS;AAAA,EAC/D;AACF;AAEO,IAAM,cAAc,kBAAkB,YAAY;AAOzD,IAAM,SAA0B,CAAC;AAAA,EAC/B,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAW;AAAA,MACX,WAAU;AAAA,MACV,WAAW,GAAG,aAAa,SAAS;AAAA,MACpC,IAAI,aAAa,IAAI;AAAA,MAErB;AAAA;AAAA,UAAC;AAAA;AAAA,YACC,SAAS,6BAAM;AAAA,YACf,WAAU;AAAA,YACT,IAAI,6BAAM,SAAQ,EAAE,OAAO,KAAK,MAAM,IAAI,CAAC;AAAA,YAE3C,uCAAM;AAAA;AAAA,QACT;AAAA,QAEA,qBAAC,GAAG,KAAH,EAAO,MAAK,KACV;AAAA,kBACC,oBAAC,cAAW,WAAU,oBAAmB,WAAW,GACjD,iBACH,IACE;AAAA,UACH,cACC,oBAAC,oBAAiB,WAAU,mBAAkB,WAAW,GACtD,uBACH,IACE;AAAA,WACN;AAAA,QAEC,aACC;AAAA,UAAC;AAAA;AAAA,YACC,WAAU;AAAA,YACV,MAAK;AAAA,YACL,SAAS;AAAA,YACT,UAAS;AAAA,YACT,KAAK;AAAA,YACL,OAAO;AAAA;AAAA,QACT,IACE;AAAA;AAAA;AAAA,EACN;AAEJ;","names":["initialState","notices","id","notice","placement"]}
1
+ {"version":3,"sources":["../src/notice.tsx"],"sourcesContent":["import type { AlertProps } from \"@yamada-ui/alert\"\nimport {\n Alert,\n AlertDescription,\n AlertIcon,\n AlertTitle,\n} from \"@yamada-ui/alert\"\nimport { CloseButton } from \"@yamada-ui/close-button\"\nimport type {\n CSSUIObject,\n NoticePlacement,\n NoticeComponentProps,\n NoticeConfigOptions,\n StyledTheme,\n} from \"@yamada-ui/core\"\nimport { ui, useTheme } from \"@yamada-ui/core\"\nimport { cx, merge } from \"@yamada-ui/utils\"\nimport type { FC, ReactNode } from \"react\"\nimport { useMemo } from \"react\"\n\nexport type UseNoticeOptions = NoticeConfigOptions\n\nexport type NoticeOptions = {\n id: string | number\n placement: NoticePlacement\n duration: UseNoticeOptions[\"duration\"]\n status: UseNoticeOptions[\"status\"]\n message: (props: NoticeComponentProps) => ReactNode\n isDelete?: boolean\n onDelete: () => void\n onCloseComplete?: () => void\n style?: CSSUIObject\n}\n\nconst findId = (\n options: NoticeOptions[],\n id: string | number,\n): NoticeOptions | undefined => options.find((notice) => notice.id === id)\n\nconst findNotice = (\n state: State,\n id: string | number,\n): {\n placement: NoticePlacement | undefined\n index: number\n} => {\n const placement = getNoticePlacement(state, id)\n\n const index = placement\n ? state[placement].findIndex((notice) => notice.id === id)\n : -1\n\n return { placement, index }\n}\n\nconst getNoticePlacement = (\n state: State,\n id: string | number,\n): NoticePlacement | undefined => {\n for (const [placement, values] of Object.entries(state)) {\n if (findId(values, id)) return placement as NoticePlacement\n }\n}\n\ntype CreateNoticeOptions = Partial<\n Pick<\n NoticeOptions,\n \"id\" | \"placement\" | \"status\" | \"duration\" | \"onCloseComplete\" | \"style\"\n >\n>\n\nlet counter = 0\n\nconst createNotice = (\n message: (props: NoticeComponentProps) => ReactNode,\n {\n id,\n placement = \"top\",\n duration,\n onCloseComplete,\n status,\n style,\n }: CreateNoticeOptions,\n) => {\n counter += 1\n\n id ??= counter\n\n return {\n id,\n placement,\n status,\n duration,\n message,\n onDelete: () => noticeStore.remove(String(id), placement),\n isDelete: false,\n onCloseComplete,\n style,\n }\n}\n\nconst createRender = (options: UseNoticeOptions): FC<NoticeComponentProps> => {\n const { component } = options\n\n const Render: FC<NoticeComponentProps> = (props) => {\n if (typeof component === \"function\") {\n return component({ ...props, ...options }) as JSX.Element\n } else {\n return <Notice {...props} {...options} />\n }\n }\n\n return Render\n}\n\nconst createNoticeFunc = (\n defaultOptions: UseNoticeOptions,\n theme: StyledTheme,\n) => {\n const themeOptions = theme.__config.notice?.options ?? {}\n\n const computedOptions = (options: UseNoticeOptions) =>\n merge(themeOptions, merge(defaultOptions, options))\n\n const notice = (options: UseNoticeOptions = {}) => {\n options = computedOptions(options)\n\n const message = createRender(options)\n\n return noticeStore.create(message, options)\n }\n\n notice.update = (\n id: string | number,\n options: Omit<UseNoticeOptions, \"id\">,\n ) => {\n options = computedOptions(options)\n\n noticeStore.update(id, options)\n }\n\n notice.closeAll = noticeStore.closeAll\n notice.close = noticeStore.close\n notice.isActive = noticeStore.isActive\n\n return notice\n}\n\ntype CreateNoticeReturn = ReturnType<typeof createNoticeFunc>\n\n/**\n * `useNotice` is a custom hook that controls the notifications of the application.\n *\n * @see Docs https://yamada-ui.com/hooks/use-notice\n */\nexport const useNotice = (\n defaultOptions?: UseNoticeOptions,\n): CreateNoticeReturn => {\n const { theme } = useTheme()\n\n return useMemo(\n () => createNoticeFunc(defaultOptions ?? {}, theme),\n [defaultOptions, theme],\n )\n}\n\ntype State = {\n [K in NoticePlacement]: NoticeOptions[]\n}\n\ntype Store = {\n subscribe: (onStoreChange: () => void) => () => void\n getSnapshot: () => State\n create: (\n message: (props: NoticeComponentProps) => ReactNode,\n options: UseNoticeOptions,\n ) => string | number\n close: (id: string | number) => void\n closeAll: (options?: { placement?: NoticePlacement[] }) => void\n update: (id: string | number, options: Omit<UseNoticeOptions, \"id\">) => void\n remove: (id: string | number, placement: NoticePlacement) => void\n isActive: (id: string | number) => boolean\n}\n\nconst initialState = {\n top: [],\n \"top-left\": [],\n \"top-right\": [],\n bottom: [],\n \"bottom-left\": [],\n \"bottom-right\": [],\n}\n\nconst createNoticeStore = (initialState: State): Store => {\n let state = initialState\n const storeChangeCache = new Set<() => void>()\n\n const setState = (setStateFunc: (values: State) => State) => {\n state = setStateFunc(state)\n storeChangeCache.forEach((onStoreChange) => onStoreChange())\n }\n\n return {\n getSnapshot: () => state,\n\n subscribe: (onStoreChange) => {\n storeChangeCache.add(onStoreChange)\n\n return () => {\n setState(() => initialState)\n storeChangeCache.delete(onStoreChange)\n }\n },\n\n remove: (id, placement) => {\n setState((prevState) => ({\n ...prevState,\n [placement]: prevState[placement].filter((notice) => notice.id != id),\n }))\n },\n\n create: (message, options) => {\n const limit = options.limit\n\n const notice = createNotice(message, options)\n const { placement, id } = notice\n\n setState((prev) => {\n let prevNotices = prev[placement] ?? []\n\n if (\n limit !== undefined &&\n limit > 0 &&\n prevNotices.length > limit - 1\n ) {\n const n = prevNotices.length - (limit - 1)\n const notices = placement.includes(\"top\")\n ? prevNotices.slice(n * -1)\n : prevNotices.slice(0, n)\n\n const ids = notices.map(({ id }) => id)\n\n prevNotices = prevNotices.map((notice) =>\n ids.includes(notice.id) ? { ...notice, isDelete: true } : notice,\n )\n }\n\n const notices = placement.includes(\"top\")\n ? [notice, ...prevNotices]\n : [...prevNotices, notice]\n\n return { ...prev, [placement]: notices }\n })\n\n return id\n },\n\n update: (id, options) => {\n setState((prev) => {\n const next = { ...prev }\n const { placement, index } = findNotice(next, id)\n\n if (placement && index !== -1) {\n next[placement][index] = {\n ...next[placement][index],\n ...options,\n message: createRender(options),\n }\n }\n\n return next\n })\n },\n\n closeAll: ({ placement } = {}) => {\n setState((prev) => {\n let placements: NoticePlacement[] = [\n \"bottom\",\n \"bottom-right\",\n \"bottom-left\",\n \"top\",\n \"top-left\",\n \"top-right\",\n ]\n\n if (placement) placements = placement\n\n return placements.reduce(\n (acc, placement) => {\n acc[placement] = prev[placement].map((notice) => ({\n ...notice,\n isDelete: true,\n }))\n\n return acc\n },\n { ...prev },\n )\n })\n },\n\n close: (id) => {\n setState((prev) => {\n const placement = getNoticePlacement(prev, id)\n\n if (!placement) return prev\n\n return {\n ...prev,\n [placement]: prev[placement].map((notice) =>\n notice.id == id ? { ...notice, isDelete: true } : notice,\n ),\n }\n })\n },\n\n isActive: (id) =>\n Boolean(findNotice(noticeStore.getSnapshot(), id).placement),\n }\n}\n\nexport const noticeStore = createNoticeStore(initialState)\n\nexport type NoticeProps = Omit<AlertProps, keyof UseNoticeOptions> &\n UseNoticeOptions & {\n onClose?: () => void\n }\n\nconst Notice: FC<NoticeProps> = ({\n variant = \"basic\",\n colorScheme,\n status,\n icon,\n title,\n description,\n isClosable,\n className,\n onClose,\n}) => {\n return (\n <Alert\n status={status}\n variant={variant}\n colorScheme={colorScheme}\n alignItems=\"start\"\n boxShadow=\"fallback(lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05))\"\n className={cx(\"ui-notice\", className)}\n pe={isClosable ? 8 : undefined}\n >\n <AlertIcon\n variant={icon?.variant}\n className=\"ui-notice__icon\"\n {...(icon?.color ? { color: icon.color } : {})}\n >\n {icon?.children}\n </AlertIcon>\n\n <ui.div flex=\"1\">\n {title ? (\n <AlertTitle className=\"ui-notice__title\" lineClamp={1}>\n {title}\n </AlertTitle>\n ) : null}\n {description ? (\n <AlertDescription className=\"ui-notice__description\" lineClamp={3}>\n {description}\n </AlertDescription>\n ) : null}\n </ui.div>\n\n {isClosable ? (\n <CloseButton\n className=\"ui-notice__close-button\"\n size=\"sm\"\n onClick={onClose}\n position=\"absolute\"\n top={2}\n right={2}\n />\n ) : null}\n </Alert>\n )\n}\n"],"mappings":";;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAQ5B,SAAS,IAAI,gBAAgB;AAC7B,SAAS,IAAI,aAAa;AAE1B,SAAS,eAAe;AA0FX,cAyPP,YAzPO;AA1Eb,IAAM,SAAS,CACb,SACA,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AAA,MAErB;AAAA;AAAA,UAAC;AAAA;AAAA,YACC,SAAS,6BAAM;AAAA,YACf,WAAU;AAAA,YACT,IAAI,6BAAM,SAAQ,EAAE,OAAO,KAAK,MAAM,IAAI,CAAC;AAAA,YAE3C,uCAAM;AAAA;AAAA,QACT;AAAA,QAEA,qBAAC,GAAG,KAAH,EAAO,MAAK,KACV;AAAA,kBACC,oBAAC,cAAW,WAAU,oBAAmB,WAAW,GACjD,iBACH,IACE;AAAA,UACH,cACC,oBAAC,oBAAiB,WAAU,0BAAyB,WAAW,GAC7D,uBACH,IACE;AAAA,WACN;AAAA,QAEC,aACC;AAAA,UAAC;AAAA;AAAA,YACC,WAAU;AAAA,YACV,MAAK;AAAA,YACL,SAAS;AAAA,YACT,UAAS;AAAA,YACT,KAAK;AAAA,YACL,OAAO;AAAA;AAAA,QACT,IACE;AAAA;AAAA;AAAA,EACN;AAEJ;","names":["initialState","notices","id","notice","placement"]}
@@ -1,7 +1,7 @@
1
1
  "use client"
2
2
  import {
3
3
  noticeStore
4
- } from "./chunk-QJZAGAE4.mjs";
4
+ } from "./chunk-O26YP2LY.mjs";
5
5
 
6
6
  // src/notice-provider.tsx
7
7
  import { ui } from "@yamada-ui/core";
@@ -143,4 +143,4 @@ NoticeComponent.displayName = "NoticeComponent";
143
143
  export {
144
144
  NoticeProvider
145
145
  };
146
- //# sourceMappingURL=chunk-RRHRITCX.mjs.map
146
+ //# sourceMappingURL=chunk-PVKDAVUE.mjs.map
package/dist/index.js CHANGED
@@ -240,7 +240,7 @@ var Notice = ({
240
240
  ),
241
241
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_core.ui.div, { flex: "1", children: [
242
242
  title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertTitle, { className: "ui-notice__title", lineClamp: 1, children: title }) : null,
243
- description ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertDescription, { className: "ui-notice__desc", lineClamp: 3, children: description }) : null
243
+ description ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertDescription, { className: "ui-notice__description", lineClamp: 3, children: description }) : null
244
244
  ] }),
245
245
  isClosable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
246
246
  import_close_button.CloseButton,
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/notice.tsx","../src/notice-provider.tsx"],"sourcesContent":["export { useNotice, noticeStore } from \"./notice\"\nexport type { NoticeProps, NoticeOptions, UseNoticeOptions } from \"./notice\"\nexport * from \"./notice-provider\"\n","import type { AlertProps } from \"@yamada-ui/alert\"\nimport {\n Alert,\n AlertDescription,\n AlertIcon,\n AlertTitle,\n} from \"@yamada-ui/alert\"\nimport { CloseButton } from \"@yamada-ui/close-button\"\nimport type {\n CSSUIObject,\n NoticePlacement,\n NoticeComponentProps,\n NoticeConfigOptions,\n StyledTheme,\n} from \"@yamada-ui/core\"\nimport { ui, useTheme } from \"@yamada-ui/core\"\nimport { cx, merge } from \"@yamada-ui/utils\"\nimport type { FC, ReactNode } from \"react\"\nimport { useMemo } from \"react\"\n\nexport type UseNoticeOptions = NoticeConfigOptions\n\nexport type NoticeOptions = {\n id: string | number\n placement: NoticePlacement\n duration: UseNoticeOptions[\"duration\"]\n status: UseNoticeOptions[\"status\"]\n message: (props: NoticeComponentProps) => ReactNode\n isDelete?: boolean\n onDelete: () => void\n onCloseComplete?: () => void\n style?: CSSUIObject\n}\n\nconst findId = (\n options: NoticeOptions[],\n id: string | number,\n): NoticeOptions | undefined => options.find((notice) => notice.id === id)\n\nconst findNotice = (\n state: State,\n id: string | number,\n): {\n placement: NoticePlacement | undefined\n index: number\n} => {\n const placement = getNoticePlacement(state, id)\n\n const index = placement\n ? state[placement].findIndex((notice) => notice.id === id)\n : -1\n\n return { placement, index }\n}\n\nconst getNoticePlacement = (\n state: State,\n id: string | number,\n): NoticePlacement | undefined => {\n for (const [placement, values] of Object.entries(state)) {\n if (findId(values, id)) return placement as NoticePlacement\n }\n}\n\ntype CreateNoticeOptions = Partial<\n Pick<\n NoticeOptions,\n \"id\" | \"placement\" | \"status\" | \"duration\" | \"onCloseComplete\" | \"style\"\n >\n>\n\nlet counter = 0\n\nconst createNotice = (\n message: (props: NoticeComponentProps) => ReactNode,\n {\n id,\n placement = \"top\",\n duration,\n onCloseComplete,\n status,\n style,\n }: CreateNoticeOptions,\n) => {\n counter += 1\n\n id ??= counter\n\n return {\n id,\n placement,\n status,\n duration,\n message,\n onDelete: () => noticeStore.remove(String(id), placement),\n isDelete: false,\n onCloseComplete,\n style,\n }\n}\n\nconst createRender = (options: UseNoticeOptions): FC<NoticeComponentProps> => {\n const { component } = options\n\n const Render: FC<NoticeComponentProps> = (props) => {\n if (typeof component === \"function\") {\n return component({ ...props, ...options }) as JSX.Element\n } else {\n return <Notice {...props} {...options} />\n }\n }\n\n return Render\n}\n\nconst createNoticeFunc = (\n defaultOptions: UseNoticeOptions,\n theme: StyledTheme,\n) => {\n const themeOptions = theme.__config.notice?.options ?? {}\n\n const computedOptions = (options: UseNoticeOptions) =>\n merge(themeOptions, merge(defaultOptions, options))\n\n const notice = (options: UseNoticeOptions = {}) => {\n options = computedOptions(options)\n\n const message = createRender(options)\n\n return noticeStore.create(message, options)\n }\n\n notice.update = (\n id: string | number,\n options: Omit<UseNoticeOptions, \"id\">,\n ) => {\n options = computedOptions(options)\n\n noticeStore.update(id, options)\n }\n\n notice.closeAll = noticeStore.closeAll\n notice.close = noticeStore.close\n notice.isActive = noticeStore.isActive\n\n return notice\n}\n\ntype CreateNoticeReturn = ReturnType<typeof createNoticeFunc>\n\n/**\n * `useNotice` is a custom hook that controls the notifications of the application.\n *\n * @see Docs https://yamada-ui.com/hooks/use-notice\n */\nexport const useNotice = (\n defaultOptions?: UseNoticeOptions,\n): CreateNoticeReturn => {\n const { theme } = useTheme()\n\n return useMemo(\n () => createNoticeFunc(defaultOptions ?? {}, theme),\n [defaultOptions, theme],\n )\n}\n\ntype State = {\n [K in NoticePlacement]: NoticeOptions[]\n}\n\ntype Store = {\n subscribe: (onStoreChange: () => void) => () => void\n getSnapshot: () => State\n create: (\n message: (props: NoticeComponentProps) => ReactNode,\n options: UseNoticeOptions,\n ) => string | number\n close: (id: string | number) => void\n closeAll: (options?: { placement?: NoticePlacement[] }) => void\n update: (id: string | number, options: Omit<UseNoticeOptions, \"id\">) => void\n remove: (id: string | number, placement: NoticePlacement) => void\n isActive: (id: string | number) => boolean\n}\n\nconst initialState = {\n top: [],\n \"top-left\": [],\n \"top-right\": [],\n bottom: [],\n \"bottom-left\": [],\n \"bottom-right\": [],\n}\n\nconst createNoticeStore = (initialState: State): Store => {\n let state = initialState\n const storeChangeCache = new Set<() => void>()\n\n const setState = (setStateFunc: (values: State) => State) => {\n state = setStateFunc(state)\n storeChangeCache.forEach((onStoreChange) => onStoreChange())\n }\n\n return {\n getSnapshot: () => state,\n\n subscribe: (onStoreChange) => {\n storeChangeCache.add(onStoreChange)\n\n return () => {\n setState(() => initialState)\n storeChangeCache.delete(onStoreChange)\n }\n },\n\n remove: (id, placement) => {\n setState((prevState) => ({\n ...prevState,\n [placement]: prevState[placement].filter((notice) => notice.id != id),\n }))\n },\n\n create: (message, options) => {\n const limit = options.limit\n\n const notice = createNotice(message, options)\n const { placement, id } = notice\n\n setState((prev) => {\n let prevNotices = prev[placement] ?? []\n\n if (\n limit !== undefined &&\n limit > 0 &&\n prevNotices.length > limit - 1\n ) {\n const n = prevNotices.length - (limit - 1)\n const notices = placement.includes(\"top\")\n ? prevNotices.slice(n * -1)\n : prevNotices.slice(0, n)\n\n const ids = notices.map(({ id }) => id)\n\n prevNotices = prevNotices.map((notice) =>\n ids.includes(notice.id) ? { ...notice, isDelete: true } : notice,\n )\n }\n\n const notices = placement.includes(\"top\")\n ? [notice, ...prevNotices]\n : [...prevNotices, notice]\n\n return { ...prev, [placement]: notices }\n })\n\n return id\n },\n\n update: (id, options) => {\n setState((prev) => {\n const next = { ...prev }\n const { placement, index } = findNotice(next, id)\n\n if (placement && index !== -1) {\n next[placement][index] = {\n ...next[placement][index],\n ...options,\n message: createRender(options),\n }\n }\n\n return next\n })\n },\n\n closeAll: ({ placement } = {}) => {\n setState((prev) => {\n let placements: NoticePlacement[] = [\n \"bottom\",\n \"bottom-right\",\n \"bottom-left\",\n \"top\",\n \"top-left\",\n \"top-right\",\n ]\n\n if (placement) placements = placement\n\n return placements.reduce(\n (acc, placement) => {\n acc[placement] = prev[placement].map((notice) => ({\n ...notice,\n isDelete: true,\n }))\n\n return acc\n },\n { ...prev },\n )\n })\n },\n\n close: (id) => {\n setState((prev) => {\n const placement = getNoticePlacement(prev, id)\n\n if (!placement) return prev\n\n return {\n ...prev,\n [placement]: prev[placement].map((notice) =>\n notice.id == id ? { ...notice, isDelete: true } : notice,\n ),\n }\n })\n },\n\n isActive: (id) =>\n Boolean(findNotice(noticeStore.getSnapshot(), id).placement),\n }\n}\n\nexport const noticeStore = createNoticeStore(initialState)\n\nexport type NoticeProps = Omit<AlertProps, keyof UseNoticeOptions> &\n UseNoticeOptions & {\n onClose?: () => void\n }\n\nconst Notice: FC<NoticeProps> = ({\n variant = \"basic\",\n colorScheme,\n status,\n icon,\n title,\n description,\n isClosable,\n className,\n onClose,\n}) => {\n return (\n <Alert\n status={status}\n variant={variant}\n colorScheme={colorScheme}\n alignItems=\"start\"\n boxShadow=\"fallback(lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05))\"\n className={cx(\"ui-notice\", className)}\n pe={isClosable ? 8 : undefined}\n >\n <AlertIcon\n variant={icon?.variant}\n className=\"ui-notice__icon\"\n {...(icon?.color ? { color: icon.color } : {})}\n >\n {icon?.children}\n </AlertIcon>\n\n <ui.div flex=\"1\">\n {title ? (\n <AlertTitle className=\"ui-notice__title\" lineClamp={1}>\n {title}\n </AlertTitle>\n ) : null}\n {description ? (\n <AlertDescription className=\"ui-notice__desc\" lineClamp={3}>\n {description}\n </AlertDescription>\n ) : null}\n </ui.div>\n\n {isClosable ? (\n <CloseButton\n className=\"ui-notice__close-button\"\n size=\"sm\"\n onClick={onClose}\n position=\"absolute\"\n top={2}\n right={2}\n />\n ) : null}\n </Alert>\n )\n}\n","import type { CSSUIObject, ThemeConfig } from \"@yamada-ui/core\"\nimport { ui } from \"@yamada-ui/core\"\nimport type { MotionVariants, MotionStyle } from \"@yamada-ui/motion\"\nimport { AnimatePresence, motion, useIsPresent } from \"@yamada-ui/motion\"\nimport { Portal } from \"@yamada-ui/portal\"\nimport { useTimeout } from \"@yamada-ui/use-timeout\"\nimport { cx, runIfFunc, useUpdateEffect } from \"@yamada-ui/utils\"\nimport type { FC } from \"react\"\nimport { memo, useEffect, useState, useSyncExternalStore } from \"react\"\nimport type { NoticeOptions } from \"./notice\"\nimport { noticeStore } from \"./notice\"\n\nexport type NoticeProviderProps = Omit<\n Required<ThemeConfig>[\"notice\"],\n \"options\"\n>\n\nexport const NoticeProvider: FC<NoticeProviderProps> = ({\n variants,\n gap = \"fallback(4, 1rem)\",\n appendToParentPortal,\n containerRef,\n}) => {\n const state = useSyncExternalStore(\n noticeStore.subscribe,\n noticeStore.getSnapshot,\n noticeStore.getSnapshot,\n )\n\n const components = Object.entries(state).map(([placement, notices]) => {\n const top = placement.includes(\"top\")\n ? \"env(safe-area-inset-top, 0px)\"\n : undefined\n const bottom = placement.includes(\"bottom\")\n ? \"env(safe-area-inset-bottom, 0px)\"\n : undefined\n const right = !placement.includes(\"left\")\n ? \"env(safe-area-inset-right, 0px)\"\n : undefined\n const left = !placement.includes(\"right\")\n ? \"env(safe-area-inset-left, 0px)\"\n : undefined\n\n const css: CSSUIObject = {\n position: \"fixed\",\n zIndex: \"fallback(zarbon, 160)\",\n pointerEvents: \"none\",\n display: \"flex\",\n flexDirection: \"column\",\n margin: gap,\n gap,\n top,\n bottom,\n right,\n left,\n }\n\n return (\n <ui.ul\n key={placement}\n className={cx(\"ui-notice__list\", `ui-notice__list--${placement}`)}\n __css={css}\n >\n <AnimatePresence initial={false}>\n {notices.map((notice) => (\n <NoticeComponent key={notice.id} variants={variants} {...notice} />\n ))}\n </AnimatePresence>\n </ui.ul>\n )\n })\n\n return (\n <Portal\n appendToParentPortal={appendToParentPortal}\n containerRef={containerRef}\n >\n {components}\n </Portal>\n )\n}\n\nconst defaultVariants: MotionVariants = {\n initial: ({ placement }) => ({\n opacity: 0,\n [[\"top\", \"bottom\"].includes(placement) ? \"y\" : \"x\"]:\n (placement === \"bottom\" ? 1 : placement.includes(\"right\") ? 1 : -1) * 24,\n }),\n animate: {\n opacity: 1,\n y: 0,\n x: 0,\n scale: 1,\n transition: {\n duration: 0.4,\n ease: [0.4, 0, 0.2, 1],\n },\n },\n exit: {\n opacity: 0,\n scale: 0.95,\n transition: {\n duration: 0.2,\n ease: [0.4, 0, 1, 1],\n },\n },\n}\n\ntype NoticeComponentProps = NoticeOptions &\n Pick<NoticeProviderProps, \"variants\">\n\nconst NoticeComponent = memo(\n ({\n variants = defaultVariants,\n placement,\n duration = 5000,\n message,\n onCloseComplete,\n isDelete = false,\n onDelete,\n style,\n }: NoticeComponentProps) => {\n const [delay, setDelay] = useState(duration)\n const isPresent = useIsPresent()\n\n useUpdateEffect(() => {\n if (!isPresent) onCloseComplete?.()\n }, [isPresent])\n\n useUpdateEffect(() => {\n setDelay(duration)\n }, [duration])\n\n const onMouseEnter = () => setDelay(null)\n const onMouseLeave = () => setDelay(duration)\n\n const onClose = () => {\n if (isPresent) onDelete()\n }\n\n useEffect(() => {\n if (isPresent && isDelete) onDelete()\n }, [isPresent, isDelete, onDelete])\n\n useTimeout(onClose, delay)\n\n const css: CSSUIObject = {\n pointerEvents: \"auto\",\n maxW: \"36rem\",\n minW: \"20rem\",\n ...style,\n }\n\n return (\n <motion.li\n layout\n className=\"ui-notice__item\"\n variants={variants}\n initial=\"initial\"\n animate=\"animate\"\n exit=\"exit\"\n onHoverStart={onMouseEnter}\n onHoverEnd={onMouseLeave}\n custom={{ placement }}\n style={\n {\n display: \"flex\",\n justifyContent: placement.includes(\"left\")\n ? \"flex-start\"\n : placement.includes(\"right\")\n ? \"flex-end\"\n : \"center\",\n } as MotionStyle\n }\n >\n <ui.div className=\"ui-notice__item-inner\" __css={css}>\n {runIfFunc(message, { onClose })}\n </ui.div>\n </motion.li>\n )\n },\n)\n\nNoticeComponent.displayName = \"NoticeComponent\"\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,mBAKO;AACP,0BAA4B;AAQ5B,kBAA6B;AAC7B,mBAA0B;AAE1B,mBAAwB;AA0FX;AA1Eb,IAAM,SAAS,CACb,SACA,OAC8B,QAAQ,KAAK,CAAC,WAAW,OAAO,OAAO,EAAE;AAEzE,IAAM,aAAa,CACjB,OACA,OAIG;AACH,QAAM,YAAY,mBAAmB,OAAO,EAAE;AAE9C,QAAM,QAAQ,YACV,MAAM,SAAS,EAAE,UAAU,CAAC,WAAW,OAAO,OAAO,EAAE,IACvD;AAEJ,SAAO,EAAE,WAAW,MAAM;AAC5B;AAEA,IAAM,qBAAqB,CACzB,OACA,OACgC;AAChC,aAAW,CAAC,WAAW,MAAM,KAAK,OAAO,QAAQ,KAAK,GAAG;AACvD,QAAI,OAAO,QAAQ,EAAE,EAAG,QAAO;AAAA,EACjC;AACF;AASA,IAAI,UAAU;AAEd,IAAM,eAAe,CACnB,SACA;AAAA,EACE;AAAA,EACA,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MACG;AACH,aAAW;AAEX,yBAAO;AAEP,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,MAAM,YAAY,OAAO,OAAO,EAAE,GAAG,SAAS;AAAA,IACxD,UAAU;AAAA,IACV;AAAA,IACA;AAAA,EACF;AACF;AAEA,IAAM,eAAe,CAAC,YAAwD;AAC5E,QAAM,EAAE,UAAU,IAAI;AAEtB,QAAM,S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ACE;AAAA,UACE,SAAS;AAAA,UACT,gBAAgB,UAAU,SAAS,MAAM,IACrC,eACA,UAAU,SAAS,OAAO,IACxB,aACA;AAAA,QACR;AAAA,QAGF,uDAAC,gBAAG,KAAH,EAAO,WAAU,yBAAwB,OAAO,KAC9C,uCAAU,SAAS,EAAE,QAAQ,CAAC,GACjC;AAAA;AAAA,IACF;AAAA,EAEJ;AACF;AAEA,gBAAgB,cAAc;","names":["initialState","notices","id","notice","placement","import_core","import_utils","import_react","import_jsx_runtime"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/notice.tsx","../src/notice-provider.tsx"],"sourcesContent":["export { useNotice, noticeStore } from \"./notice\"\nexport type { NoticeProps, NoticeOptions, UseNoticeOptions } from \"./notice\"\nexport * from \"./notice-provider\"\n","import type { AlertProps } from \"@yamada-ui/alert\"\nimport {\n Alert,\n AlertDescription,\n AlertIcon,\n AlertTitle,\n} from \"@yamada-ui/alert\"\nimport { CloseButton } from \"@yamada-ui/close-button\"\nimport type {\n CSSUIObject,\n NoticePlacement,\n NoticeComponentProps,\n NoticeConfigOptions,\n StyledTheme,\n} from \"@yamada-ui/core\"\nimport { ui, useTheme } from \"@yamada-ui/core\"\nimport { cx, merge } from \"@yamada-ui/utils\"\nimport type { FC, ReactNode } from \"react\"\nimport { useMemo } from \"react\"\n\nexport type UseNoticeOptions = NoticeConfigOptions\n\nexport type NoticeOptions = {\n id: string | number\n placement: NoticePlacement\n duration: UseNoticeOptions[\"duration\"]\n status: UseNoticeOptions[\"status\"]\n message: (props: NoticeComponentProps) => ReactNode\n isDelete?: boolean\n onDelete: () => void\n onCloseComplete?: () => void\n style?: CSSUIObject\n}\n\nconst findId = (\n options: NoticeOptions[],\n id: string | number,\n): NoticeOptions | undefined => options.find((notice) => notice.id === id)\n\nconst findNotice = (\n state: State,\n id: string | number,\n): {\n placement: NoticePlacement | undefined\n index: number\n} => {\n const placement = getNoticePlacement(state, id)\n\n const index = placement\n ? state[placement].findIndex((notice) => notice.id === id)\n : -1\n\n return { placement, index }\n}\n\nconst getNoticePlacement = (\n state: State,\n id: string | number,\n): NoticePlacement | undefined => {\n for (const [placement, values] of Object.entries(state)) {\n if (findId(values, id)) return placement as NoticePlacement\n }\n}\n\ntype CreateNoticeOptions = Partial<\n Pick<\n NoticeOptions,\n \"id\" | \"placement\" | \"status\" | \"duration\" | \"onCloseComplete\" | \"style\"\n >\n>\n\nlet counter = 0\n\nconst createNotice = (\n message: (props: NoticeComponentProps) => ReactNode,\n {\n id,\n placement = \"top\",\n duration,\n onCloseComplete,\n status,\n style,\n }: CreateNoticeOptions,\n) => {\n counter += 1\n\n id ??= counter\n\n return {\n id,\n placement,\n status,\n duration,\n message,\n onDelete: () => noticeStore.remove(String(id), placement),\n isDelete: false,\n onCloseComplete,\n style,\n }\n}\n\nconst createRender = (options: UseNoticeOptions): FC<NoticeComponentProps> => {\n const { component } = options\n\n const Render: FC<NoticeComponentProps> = (props) => {\n if (typeof component === \"function\") {\n return component({ ...props, ...options }) as JSX.Element\n } else {\n return <Notice {...props} {...options} />\n }\n }\n\n return Render\n}\n\nconst createNoticeFunc = (\n defaultOptions: UseNoticeOptions,\n theme: StyledTheme,\n) => {\n const themeOptions = theme.__config.notice?.options ?? {}\n\n const computedOptions = (options: UseNoticeOptions) =>\n merge(themeOptions, merge(defaultOptions, options))\n\n const notice = (options: UseNoticeOptions = {}) => {\n options = computedOptions(options)\n\n const message = createRender(options)\n\n return noticeStore.create(message, options)\n }\n\n notice.update = (\n id: string | number,\n options: Omit<UseNoticeOptions, \"id\">,\n ) => {\n options = computedOptions(options)\n\n noticeStore.update(id, options)\n }\n\n notice.closeAll = noticeStore.closeAll\n notice.close = noticeStore.close\n notice.isActive = noticeStore.isActive\n\n return notice\n}\n\ntype CreateNoticeReturn = ReturnType<typeof createNoticeFunc>\n\n/**\n * `useNotice` is a custom hook that controls the notifications of the application.\n *\n * @see Docs https://yamada-ui.com/hooks/use-notice\n */\nexport const useNotice = (\n defaultOptions?: UseNoticeOptions,\n): CreateNoticeReturn => {\n const { theme } = useTheme()\n\n return useMemo(\n () => createNoticeFunc(defaultOptions ?? {}, theme),\n [defaultOptions, theme],\n )\n}\n\ntype State = {\n [K in NoticePlacement]: NoticeOptions[]\n}\n\ntype Store = {\n subscribe: (onStoreChange: () => void) => () => void\n getSnapshot: () => State\n create: (\n message: (props: NoticeComponentProps) => ReactNode,\n options: UseNoticeOptions,\n ) => string | number\n close: (id: string | number) => void\n closeAll: (options?: { placement?: NoticePlacement[] }) => void\n update: (id: string | number, options: Omit<UseNoticeOptions, \"id\">) => void\n remove: (id: string | number, placement: NoticePlacement) => void\n isActive: (id: string | number) => boolean\n}\n\nconst initialState = {\n top: [],\n \"top-left\": [],\n \"top-right\": [],\n bottom: [],\n \"bottom-left\": [],\n \"bottom-right\": [],\n}\n\nconst createNoticeStore = (initialState: State): Store => {\n let state = initialState\n const storeChangeCache = new Set<() => void>()\n\n const setState = (setStateFunc: (values: State) => State) => {\n state = setStateFunc(state)\n storeChangeCache.forEach((onStoreChange) => onStoreChange())\n }\n\n return {\n getSnapshot: () => state,\n\n subscribe: (onStoreChange) => {\n storeChangeCache.add(onStoreChange)\n\n return () => {\n setState(() => initialState)\n storeChangeCache.delete(onStoreChange)\n }\n },\n\n remove: (id, placement) => {\n setState((prevState) => ({\n ...prevState,\n [placement]: prevState[placement].filter((notice) => notice.id != id),\n }))\n },\n\n create: (message, options) => {\n const limit = options.limit\n\n const notice = createNotice(message, options)\n const { placement, id } = notice\n\n setState((prev) => {\n let prevNotices = prev[placement] ?? []\n\n if (\n limit !== undefined &&\n limit > 0 &&\n prevNotices.length > limit - 1\n ) {\n const n = prevNotices.length - (limit - 1)\n const notices = placement.includes(\"top\")\n ? prevNotices.slice(n * -1)\n : prevNotices.slice(0, n)\n\n const ids = notices.map(({ id }) => id)\n\n prevNotices = prevNotices.map((notice) =>\n ids.includes(notice.id) ? { ...notice, isDelete: true } : notice,\n )\n }\n\n const notices = placement.includes(\"top\")\n ? [notice, ...prevNotices]\n : [...prevNotices, notice]\n\n return { ...prev, [placement]: notices }\n })\n\n return id\n },\n\n update: (id, options) => {\n setState((prev) => {\n const next = { ...prev }\n const { placement, index } = findNotice(next, id)\n\n if (placement && index !== -1) {\n next[placement][index] = {\n ...next[placement][index],\n ...options,\n message: createRender(options),\n }\n }\n\n return next\n })\n },\n\n closeAll: ({ placement } = {}) => {\n setState((prev) => {\n let placements: NoticePlacement[] = [\n \"bottom\",\n \"bottom-right\",\n \"bottom-left\",\n \"top\",\n \"top-left\",\n \"top-right\",\n ]\n\n if (placement) placements = placement\n\n return placements.reduce(\n (acc, placement) => {\n acc[placement] = prev[placement].map((notice) => ({\n ...notice,\n isDelete: true,\n }))\n\n return acc\n },\n { ...prev },\n )\n })\n },\n\n close: (id) => {\n setState((prev) => {\n const placement = getNoticePlacement(prev, id)\n\n if (!placement) return prev\n\n return {\n ...prev,\n [placement]: prev[placement].map((notice) =>\n notice.id == id ? { ...notice, isDelete: true } : notice,\n ),\n }\n })\n },\n\n isActive: (id) =>\n Boolean(findNotice(noticeStore.getSnapshot(), id).placement),\n }\n}\n\nexport const noticeStore = createNoticeStore(initialState)\n\nexport type NoticeProps = Omit<AlertProps, keyof UseNoticeOptions> &\n UseNoticeOptions & {\n onClose?: () => void\n }\n\nconst Notice: FC<NoticeProps> = ({\n variant = \"basic\",\n colorScheme,\n status,\n icon,\n title,\n description,\n isClosable,\n className,\n onClose,\n}) => {\n return (\n <Alert\n status={status}\n variant={variant}\n colorScheme={colorScheme}\n alignItems=\"start\"\n boxShadow=\"fallback(lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05))\"\n className={cx(\"ui-notice\", className)}\n pe={isClosable ? 8 : undefined}\n >\n <AlertIcon\n variant={icon?.variant}\n className=\"ui-notice__icon\"\n {...(icon?.color ? { color: icon.color } : {})}\n >\n {icon?.children}\n </AlertIcon>\n\n <ui.div flex=\"1\">\n {title ? (\n <AlertTitle className=\"ui-notice__title\" lineClamp={1}>\n {title}\n </AlertTitle>\n ) : null}\n {description ? (\n <AlertDescription className=\"ui-notice__description\" lineClamp={3}>\n {description}\n </AlertDescription>\n ) : null}\n </ui.div>\n\n {isClosable ? (\n <CloseButton\n className=\"ui-notice__close-button\"\n size=\"sm\"\n onClick={onClose}\n position=\"absolute\"\n top={2}\n right={2}\n />\n ) : null}\n </Alert>\n )\n}\n","import type { CSSUIObject, ThemeConfig } from \"@yamada-ui/core\"\nimport { ui } from \"@yamada-ui/core\"\nimport type { MotionVariants, MotionStyle } from \"@yamada-ui/motion\"\nimport { AnimatePresence, motion, useIsPresent } from \"@yamada-ui/motion\"\nimport { Portal } from \"@yamada-ui/portal\"\nimport { useTimeout } from \"@yamada-ui/use-timeout\"\nimport { cx, runIfFunc, useUpdateEffect } from \"@yamada-ui/utils\"\nimport type { FC } from \"react\"\nimport { memo, useEffect, useState, useSyncExternalStore } from \"react\"\nimport type { NoticeOptions } from \"./notice\"\nimport { noticeStore } from \"./notice\"\n\nexport type NoticeProviderProps = Omit<\n Required<ThemeConfig>[\"notice\"],\n \"options\"\n>\n\nexport const NoticeProvider: FC<NoticeProviderProps> = ({\n variants,\n gap = \"fallback(4, 1rem)\",\n appendToParentPortal,\n containerRef,\n}) => {\n const state = useSyncExternalStore(\n noticeStore.subscribe,\n noticeStore.getSnapshot,\n noticeStore.getSnapshot,\n )\n\n const components = Object.entries(state).map(([placement, notices]) => {\n const top = placement.includes(\"top\")\n ? \"env(safe-area-inset-top, 0px)\"\n : undefined\n const bottom = placement.includes(\"bottom\")\n ? \"env(safe-area-inset-bottom, 0px)\"\n : undefined\n const right = !placement.includes(\"left\")\n ? \"env(safe-area-inset-right, 0px)\"\n : undefined\n const left = !placement.includes(\"right\")\n ? \"env(safe-area-inset-left, 0px)\"\n : undefined\n\n const css: CSSUIObject = {\n position: \"fixed\",\n zIndex: \"fallback(zarbon, 160)\",\n pointerEvents: \"none\",\n display: \"flex\",\n flexDirection: \"column\",\n margin: gap,\n gap,\n top,\n bottom,\n right,\n left,\n }\n\n return (\n <ui.ul\n key={placement}\n className={cx(\"ui-notice__list\", `ui-notice__list--${placement}`)}\n __css={css}\n >\n <AnimatePresence initial={false}>\n {notices.map((notice) => (\n <NoticeComponent key={notice.id} variants={variants} {...notice} />\n ))}\n </AnimatePresence>\n </ui.ul>\n )\n })\n\n return (\n <Portal\n appendToParentPortal={appendToParentPortal}\n containerRef={containerRef}\n >\n {components}\n </Portal>\n )\n}\n\nconst defaultVariants: MotionVariants = {\n initial: ({ placement }) => ({\n opacity: 0,\n [[\"top\", \"bottom\"].includes(placement) ? \"y\" : \"x\"]:\n (placement === \"bottom\" ? 1 : placement.includes(\"right\") ? 1 : -1) * 24,\n }),\n animate: {\n opacity: 1,\n y: 0,\n x: 0,\n scale: 1,\n transition: {\n duration: 0.4,\n ease: [0.4, 0, 0.2, 1],\n },\n },\n exit: {\n opacity: 0,\n scale: 0.95,\n transition: {\n duration: 0.2,\n ease: [0.4, 0, 1, 1],\n },\n },\n}\n\ntype NoticeComponentProps = NoticeOptions &\n Pick<NoticeProviderProps, \"variants\">\n\nconst NoticeComponent = memo(\n ({\n variants = defaultVariants,\n placement,\n duration = 5000,\n message,\n onCloseComplete,\n isDelete = false,\n onDelete,\n style,\n }: NoticeComponentProps) => {\n const [delay, setDelay] = useState(duration)\n const isPresent = useIsPresent()\n\n useUpdateEffect(() => {\n if (!isPresent) onCloseComplete?.()\n }, [isPresent])\n\n useUpdateEffect(() => {\n setDelay(duration)\n }, [duration])\n\n const onMouseEnter = () => setDelay(null)\n const onMouseLeave = () => setDelay(duration)\n\n const onClose = () => {\n if (isPresent) onDelete()\n }\n\n useEffect(() => {\n if (isPresent && isDelete) onDelete()\n }, [isPresent, isDelete, onDelete])\n\n useTimeout(onClose, delay)\n\n const css: CSSUIObject = {\n pointerEvents: \"auto\",\n maxW: \"36rem\",\n minW: \"20rem\",\n ...style,\n }\n\n return (\n <motion.li\n layout\n className=\"ui-notice__item\"\n variants={variants}\n initial=\"initial\"\n animate=\"animate\"\n exit=\"exit\"\n onHoverStart={onMouseEnter}\n onHoverEnd={onMouseLeave}\n custom={{ placement }}\n style={\n {\n display: \"flex\",\n justifyContent: placement.includes(\"left\")\n ? \"flex-start\"\n : placement.includes(\"right\")\n ? \"flex-end\"\n : \"center\",\n } as MotionStyle\n }\n >\n <ui.div className=\"ui-notice__item-inner\" __css={css}>\n {runIfFunc(message, { onClose })}\n </ui.div>\n </motion.li>\n )\n },\n)\n\nNoticeComponent.displayName = \"NoticeComponent\"\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,mBAKO;AACP,0BAA4B;AAQ5B,kBAA6B;AAC7B,mBAA0B;AAE1B,mBAAwB;AA0FX;AA1Eb,IAAM,SAAS,CACb,SACA,OAC8B,QAAQ,KAAK,CAAC,WAAW,OAAO,OAAO,EAAE;AAEzE,IAAM,aAAa,CACjB,OACA,OAIG;AACH,QAAM,YAAY,mBAAmB,OAAO,EAAE;AAE9C,QAAM,QAAQ,YACV,MAAM,SAAS,EAAE,UAAU,CAAC,WAAW,OAAO,OAAO,EAAE,IACvD;AAEJ,SAAO,EAAE,WAAW,MAAM;AAC5B;AAEA,IAAM,qBAAqB,CACzB,OACA,OACgC;AAChC,aAAW,CAAC,WAAW,MAAM,KAAK,OAAO,QAAQ,KAAK,GAAG;AACvD,QAAI,OAAO,QAAQ,EAAE,EAAG,QAAO;AAAA,EACjC;AACF;AASA,IAAI,UAAU;AAEd,IAAM,eAAe,CACnB,SACA;AAAA,EACE;AAAA,EACA,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MACG;AACH,aAAW;AAEX,yBAAO;AAEP,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,MAAM,YAAY,OAAO,OAAO,EAAE,GAAG,SAAS;AAAA,IACxD,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,SAAQ;AAAA,QACR,SAAQ;AAAA,QACR,MAAK;AAAA,QACL,cAAc;AAAA,QACd,YAAY;AAAA,QACZ,QAAQ,EAAE,UAAU;AAAA,QACpB,OACE;AAAA,UACE,SAAS;AAAA,UACT,gBAAgB,UAAU,SAAS,MAAM,IACrC,eACA,UAAU,SAAS,OAAO,IACxB,aACA;AAAA,QACR;AAAA,QAGF,uDAAC,gBAAG,KAAH,EAAO,WAAU,yBAAwB,OAAO,KAC9C,uCAAU,SAAS,EAAE,QAAQ,CAAC,GACjC;AAAA;AAAA,IACF;AAAA,EAEJ;AACF;AAEA,gBAAgB,cAAc;","names":["initialState","notices","id","notice","placement","import_core","import_utils","import_react","import_jsx_runtime"]}
package/dist/index.mjs CHANGED
@@ -1,11 +1,11 @@
1
1
  "use client"
2
2
  import {
3
3
  NoticeProvider
4
- } from "./chunk-RRHRITCX.mjs";
4
+ } from "./chunk-PVKDAVUE.mjs";
5
5
  import {
6
6
  noticeStore,
7
7
  useNotice
8
- } from "./chunk-QJZAGAE4.mjs";
8
+ } from "./chunk-O26YP2LY.mjs";
9
9
  export {
10
10
  NoticeProvider,
11
11
  noticeStore,
@@ -219,7 +219,7 @@ var Notice = ({
219
219
  ),
220
220
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_core.ui.div, { flex: "1", children: [
221
221
  title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertTitle, { className: "ui-notice__title", lineClamp: 1, children: title }) : null,
222
- description ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertDescription, { className: "ui-notice__desc", lineClamp: 3, children: description }) : null
222
+ description ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertDescription, { className: "ui-notice__description", lineClamp: 3, children: description }) : null
223
223
  ] }),
224
224
  isClosable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
225
225
  import_close_button.CloseButton,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/notice-provider.tsx","../src/notice.tsx"],"sourcesContent":["import type { CSSUIObject, ThemeConfig } from \"@yamada-ui/core\"\nimport { ui } from \"@yamada-ui/core\"\nimport type { MotionVariants, MotionStyle } from \"@yamada-ui/motion\"\nimport { AnimatePresence, motion, useIsPresent } from \"@yamada-ui/motion\"\nimport { Portal } from \"@yamada-ui/portal\"\nimport { useTimeout } from \"@yamada-ui/use-timeout\"\nimport { cx, runIfFunc, useUpdateEffect } from \"@yamada-ui/utils\"\nimport type { FC } from \"react\"\nimport { memo, useEffect, useState, useSyncExternalStore } from \"react\"\nimport type { NoticeOptions } from \"./notice\"\nimport { noticeStore } from \"./notice\"\n\nexport type NoticeProviderProps = Omit<\n Required<ThemeConfig>[\"notice\"],\n \"options\"\n>\n\nexport const NoticeProvider: FC<NoticeProviderProps> = ({\n variants,\n gap = \"fallback(4, 1rem)\",\n appendToParentPortal,\n containerRef,\n}) => {\n const state = useSyncExternalStore(\n noticeStore.subscribe,\n noticeStore.getSnapshot,\n noticeStore.getSnapshot,\n )\n\n const components = Object.entries(state).map(([placement, notices]) => {\n const top = placement.includes(\"top\")\n ? \"env(safe-area-inset-top, 0px)\"\n : undefined\n const bottom = placement.includes(\"bottom\")\n ? \"env(safe-area-inset-bottom, 0px)\"\n : undefined\n const right = !placement.includes(\"left\")\n ? \"env(safe-area-inset-right, 0px)\"\n : undefined\n const left = !placement.includes(\"right\")\n ? \"env(safe-area-inset-left, 0px)\"\n : undefined\n\n const css: CSSUIObject = {\n position: \"fixed\",\n zIndex: \"fallback(zarbon, 160)\",\n pointerEvents: \"none\",\n display: \"flex\",\n flexDirection: \"column\",\n margin: gap,\n gap,\n top,\n bottom,\n right,\n left,\n }\n\n return (\n <ui.ul\n key={placement}\n className={cx(\"ui-notice__list\", `ui-notice__list--${placement}`)}\n __css={css}\n >\n <AnimatePresence initial={false}>\n {notices.map((notice) => (\n <NoticeComponent key={notice.id} variants={variants} {...notice} />\n ))}\n </AnimatePresence>\n </ui.ul>\n )\n })\n\n return (\n <Portal\n appendToParentPortal={appendToParentPortal}\n containerRef={containerRef}\n >\n {components}\n </Portal>\n )\n}\n\nconst defaultVariants: MotionVariants = {\n initial: ({ placement }) => ({\n opacity: 0,\n [[\"top\", \"bottom\"].includes(placement) ? \"y\" : \"x\"]:\n (placement === \"bottom\" ? 1 : placement.includes(\"right\") ? 1 : -1) * 24,\n }),\n animate: {\n opacity: 1,\n y: 0,\n x: 0,\n scale: 1,\n transition: {\n duration: 0.4,\n ease: [0.4, 0, 0.2, 1],\n },\n },\n exit: {\n opacity: 0,\n scale: 0.95,\n transition: {\n duration: 0.2,\n ease: [0.4, 0, 1, 1],\n },\n },\n}\n\ntype NoticeComponentProps = NoticeOptions &\n Pick<NoticeProviderProps, \"variants\">\n\nconst NoticeComponent = memo(\n ({\n variants = defaultVariants,\n placement,\n duration = 5000,\n message,\n onCloseComplete,\n isDelete = false,\n onDelete,\n style,\n }: NoticeComponentProps) => {\n const [delay, setDelay] = useState(duration)\n const isPresent = useIsPresent()\n\n useUpdateEffect(() => {\n if (!isPresent) onCloseComplete?.()\n }, [isPresent])\n\n useUpdateEffect(() => {\n setDelay(duration)\n }, [duration])\n\n const onMouseEnter = () => setDelay(null)\n const onMouseLeave = () => setDelay(duration)\n\n const onClose = () => {\n if (isPresent) onDelete()\n }\n\n useEffect(() => {\n if (isPresent && isDelete) onDelete()\n }, [isPresent, isDelete, onDelete])\n\n useTimeout(onClose, delay)\n\n const css: CSSUIObject = {\n pointerEvents: \"auto\",\n maxW: \"36rem\",\n minW: \"20rem\",\n ...style,\n }\n\n return (\n <motion.li\n layout\n className=\"ui-notice__item\"\n variants={variants}\n initial=\"initial\"\n animate=\"animate\"\n exit=\"exit\"\n onHoverStart={onMouseEnter}\n onHoverEnd={onMouseLeave}\n custom={{ placement }}\n style={\n {\n display: \"flex\",\n justifyContent: placement.includes(\"left\")\n ? \"flex-start\"\n : placement.includes(\"right\")\n ? \"flex-end\"\n : \"center\",\n } as MotionStyle\n }\n >\n <ui.div className=\"ui-notice__item-inner\" __css={css}>\n {runIfFunc(message, { onClose })}\n </ui.div>\n </motion.li>\n )\n },\n)\n\nNoticeComponent.displayName = \"NoticeComponent\"\n","import type { AlertProps } from \"@yamada-ui/alert\"\nimport {\n Alert,\n AlertDescription,\n AlertIcon,\n AlertTitle,\n} from \"@yamada-ui/alert\"\nimport { CloseButton } from \"@yamada-ui/close-button\"\nimport type {\n CSSUIObject,\n NoticePlacement,\n NoticeComponentProps,\n NoticeConfigOptions,\n StyledTheme,\n} from \"@yamada-ui/core\"\nimport { ui, useTheme } from \"@yamada-ui/core\"\nimport { cx, merge } from \"@yamada-ui/utils\"\nimport type { FC, ReactNode } from \"react\"\nimport { useMemo } from \"react\"\n\nexport type UseNoticeOptions = NoticeConfigOptions\n\nexport type NoticeOptions = {\n id: string | number\n placement: NoticePlacement\n duration: UseNoticeOptions[\"duration\"]\n status: UseNoticeOptions[\"status\"]\n message: (props: NoticeComponentProps) => ReactNode\n isDelete?: boolean\n onDelete: () => void\n onCloseComplete?: () => void\n style?: CSSUIObject\n}\n\nconst findId = (\n options: NoticeOptions[],\n id: string | number,\n): NoticeOptions | undefined => options.find((notice) => notice.id === id)\n\nconst findNotice = (\n state: State,\n id: string | number,\n): {\n placement: NoticePlacement | undefined\n index: number\n} => {\n const placement = getNoticePlacement(state, id)\n\n const index = placement\n ? state[placement].findIndex((notice) => notice.id === id)\n : -1\n\n return { placement, index }\n}\n\nconst getNoticePlacement = (\n state: State,\n id: string | number,\n): NoticePlacement | undefined => {\n for (const [placement, values] of Object.entries(state)) {\n if (findId(values, id)) return placement as NoticePlacement\n }\n}\n\ntype CreateNoticeOptions = Partial<\n Pick<\n NoticeOptions,\n \"id\" | \"placement\" | \"status\" | \"duration\" | \"onCloseComplete\" | \"style\"\n >\n>\n\nlet counter = 0\n\nconst createNotice = (\n message: (props: NoticeComponentProps) => ReactNode,\n {\n id,\n placement = \"top\",\n duration,\n onCloseComplete,\n status,\n style,\n }: CreateNoticeOptions,\n) => {\n counter += 1\n\n id ??= counter\n\n return {\n id,\n placement,\n status,\n duration,\n message,\n onDelete: () => noticeStore.remove(String(id), placement),\n isDelete: false,\n onCloseComplete,\n style,\n }\n}\n\nconst createRender = (options: UseNoticeOptions): FC<NoticeComponentProps> => {\n const { component } = options\n\n const Render: FC<NoticeComponentProps> = (props) => {\n if (typeof component === \"function\") {\n return component({ ...props, ...options }) as JSX.Element\n } else {\n return <Notice {...props} {...options} />\n }\n }\n\n return Render\n}\n\nconst createNoticeFunc = (\n defaultOptions: UseNoticeOptions,\n theme: StyledTheme,\n) => {\n const themeOptions = theme.__config.notice?.options ?? {}\n\n const computedOptions = (options: UseNoticeOptions) =>\n merge(themeOptions, merge(defaultOptions, options))\n\n const notice = (options: UseNoticeOptions = {}) => {\n options = computedOptions(options)\n\n const message = createRender(options)\n\n return noticeStore.create(message, options)\n }\n\n notice.update = (\n id: string | number,\n options: Omit<UseNoticeOptions, \"id\">,\n ) => {\n options = computedOptions(options)\n\n noticeStore.update(id, options)\n }\n\n notice.closeAll = noticeStore.closeAll\n notice.close = noticeStore.close\n notice.isActive = noticeStore.isActive\n\n return notice\n}\n\ntype CreateNoticeReturn = ReturnType<typeof createNoticeFunc>\n\n/**\n * `useNotice` is a custom hook that controls the notifications of the application.\n *\n * @see Docs https://yamada-ui.com/hooks/use-notice\n */\nexport const useNotice = (\n defaultOptions?: UseNoticeOptions,\n): CreateNoticeReturn => {\n const { theme } = useTheme()\n\n return useMemo(\n () => createNoticeFunc(defaultOptions ?? {}, theme),\n [defaultOptions, theme],\n )\n}\n\ntype State = {\n [K in NoticePlacement]: NoticeOptions[]\n}\n\ntype Store = {\n subscribe: (onStoreChange: () => void) => () => void\n getSnapshot: () => State\n create: (\n message: (props: NoticeComponentProps) => ReactNode,\n options: UseNoticeOptions,\n ) => string | number\n close: (id: string | number) => void\n closeAll: (options?: { placement?: NoticePlacement[] }) => void\n update: (id: string | number, options: Omit<UseNoticeOptions, \"id\">) => void\n remove: (id: string | number, placement: NoticePlacement) => void\n isActive: (id: string | number) => boolean\n}\n\nconst initialState = {\n top: [],\n \"top-left\": [],\n \"top-right\": [],\n bottom: [],\n \"bottom-left\": [],\n \"bottom-right\": [],\n}\n\nconst createNoticeStore = (initialState: State): Store => {\n let state = initialState\n const storeChangeCache = new Set<() => void>()\n\n const setState = (setStateFunc: (values: State) => State) => {\n state = setStateFunc(state)\n storeChangeCache.forEach((onStoreChange) => onStoreChange())\n }\n\n return {\n getSnapshot: () => state,\n\n subscribe: (onStoreChange) => {\n storeChangeCache.add(onStoreChange)\n\n return () => {\n setState(() => initialState)\n storeChangeCache.delete(onStoreChange)\n }\n },\n\n remove: (id, placement) => {\n setState((prevState) => ({\n ...prevState,\n [placement]: prevState[placement].filter((notice) => notice.id != id),\n }))\n },\n\n create: (message, options) => {\n const limit = options.limit\n\n const notice = createNotice(message, options)\n const { placement, id } = notice\n\n setState((prev) => {\n let prevNotices = prev[placement] ?? []\n\n if (\n limit !== undefined &&\n limit > 0 &&\n prevNotices.length > limit - 1\n ) {\n const n = prevNotices.length - (limit - 1)\n const notices = placement.includes(\"top\")\n ? prevNotices.slice(n * -1)\n : prevNotices.slice(0, n)\n\n const ids = notices.map(({ id }) => id)\n\n prevNotices = prevNotices.map((notice) =>\n ids.includes(notice.id) ? { ...notice, isDelete: true } : notice,\n )\n }\n\n const notices = placement.includes(\"top\")\n ? [notice, ...prevNotices]\n : [...prevNotices, notice]\n\n return { ...prev, [placement]: notices }\n })\n\n return id\n },\n\n update: (id, options) => {\n setState((prev) => {\n const next = { ...prev }\n const { placement, index } = findNotice(next, id)\n\n if (placement && index !== -1) {\n next[placement][index] = {\n ...next[placement][index],\n ...options,\n message: createRender(options),\n }\n }\n\n return next\n })\n },\n\n closeAll: ({ placement } = {}) => {\n setState((prev) => {\n let placements: NoticePlacement[] = [\n \"bottom\",\n \"bottom-right\",\n \"bottom-left\",\n \"top\",\n \"top-left\",\n \"top-right\",\n ]\n\n if (placement) placements = placement\n\n return placements.reduce(\n (acc, placement) => {\n acc[placement] = prev[placement].map((notice) => ({\n ...notice,\n isDelete: true,\n }))\n\n return acc\n },\n { ...prev },\n )\n })\n },\n\n close: (id) => {\n setState((prev) => {\n const placement = getNoticePlacement(prev, id)\n\n if (!placement) return prev\n\n return {\n ...prev,\n [placement]: prev[placement].map((notice) =>\n notice.id == id ? { ...notice, isDelete: true } : notice,\n ),\n }\n })\n },\n\n isActive: (id) =>\n Boolean(findNotice(noticeStore.getSnapshot(), id).placement),\n }\n}\n\nexport const noticeStore = createNoticeStore(initialState)\n\nexport type NoticeProps = Omit<AlertProps, keyof UseNoticeOptions> &\n UseNoticeOptions & {\n onClose?: () => void\n }\n\nconst Notice: FC<NoticeProps> = ({\n variant = \"basic\",\n colorScheme,\n status,\n icon,\n title,\n description,\n isClosable,\n className,\n onClose,\n}) => {\n return (\n <Alert\n status={status}\n variant={variant}\n colorScheme={colorScheme}\n alignItems=\"start\"\n boxShadow=\"fallback(lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05))\"\n className={cx(\"ui-notice\", className)}\n pe={isClosable ? 8 : undefined}\n >\n <AlertIcon\n variant={icon?.variant}\n className=\"ui-notice__icon\"\n {...(icon?.color ? { color: icon.color } : {})}\n >\n {icon?.children}\n </AlertIcon>\n\n <ui.div flex=\"1\">\n {title ? (\n <AlertTitle className=\"ui-notice__title\" lineClamp={1}>\n {title}\n </AlertTitle>\n ) : null}\n {description ? (\n <AlertDescription className=\"ui-notice__desc\" lineClamp={3}>\n {description}\n </AlertDescription>\n ) : null}\n </ui.div>\n\n {isClosable ? (\n <CloseButton\n className=\"ui-notice__close-button\"\n size=\"sm\"\n onClick={onClose}\n position=\"absolute\"\n top={2}\n right={2}\n />\n ) : null}\n </Alert>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,IAAAA,eAAmB;AAEnB,oBAAsD;AACtD,oBAAuB;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AAAA,QACN,WAAU;AAAA,QACV;AAAA,QACA,SAAQ;AAAA,QACR,SAAQ;AAAA,QACR,MAAK;AAAA,QACL,cAAc;AAAA,QACd,YAAY;AAAA,QACZ,QAAQ,EAAE,UAAU;AAAA,QACpB,OACE;AAAA,UACE,SAAS;AAAA,UACT,gBAAgB,UAAU,SAAS,MAAM,IACrC,eACA,UAAU,SAAS,OAAO,IACxB,aACA;AAAA,QACR;AAAA,QAGF,uDAAC,gBAAG,KAAH,EAAO,WAAU,yBAAwB,OAAO,KAC9C,uCAAU,SAAS,EAAE,QAAQ,CAAC,GACjC;AAAA;AAAA,IACF;AAAA,EAEJ;AACF;AAEA,gBAAgB,cAAc;","names":["import_core","import_utils","import_react","initialState","notices","id","notice","placement","import_jsx_runtime"]}
1
+ {"version":3,"sources":["../src/notice-provider.tsx","../src/notice.tsx"],"sourcesContent":["import type { CSSUIObject, ThemeConfig } from \"@yamada-ui/core\"\nimport { ui } from \"@yamada-ui/core\"\nimport type { MotionVariants, MotionStyle } from \"@yamada-ui/motion\"\nimport { AnimatePresence, motion, useIsPresent } from \"@yamada-ui/motion\"\nimport { Portal } from \"@yamada-ui/portal\"\nimport { useTimeout } from \"@yamada-ui/use-timeout\"\nimport { cx, runIfFunc, useUpdateEffect } from \"@yamada-ui/utils\"\nimport type { FC } from \"react\"\nimport { memo, useEffect, useState, useSyncExternalStore } from \"react\"\nimport type { NoticeOptions } from \"./notice\"\nimport { noticeStore } from \"./notice\"\n\nexport type NoticeProviderProps = Omit<\n Required<ThemeConfig>[\"notice\"],\n \"options\"\n>\n\nexport const NoticeProvider: FC<NoticeProviderProps> = ({\n variants,\n gap = \"fallback(4, 1rem)\",\n appendToParentPortal,\n containerRef,\n}) => {\n const state = useSyncExternalStore(\n noticeStore.subscribe,\n noticeStore.getSnapshot,\n noticeStore.getSnapshot,\n )\n\n const components = Object.entries(state).map(([placement, notices]) => {\n const top = placement.includes(\"top\")\n ? \"env(safe-area-inset-top, 0px)\"\n : undefined\n const bottom = placement.includes(\"bottom\")\n ? \"env(safe-area-inset-bottom, 0px)\"\n : undefined\n const right = !placement.includes(\"left\")\n ? \"env(safe-area-inset-right, 0px)\"\n : undefined\n const left = !placement.includes(\"right\")\n ? \"env(safe-area-inset-left, 0px)\"\n : undefined\n\n const css: CSSUIObject = {\n position: \"fixed\",\n zIndex: \"fallback(zarbon, 160)\",\n pointerEvents: \"none\",\n display: \"flex\",\n flexDirection: \"column\",\n margin: gap,\n gap,\n top,\n bottom,\n right,\n left,\n }\n\n return (\n <ui.ul\n key={placement}\n className={cx(\"ui-notice__list\", `ui-notice__list--${placement}`)}\n __css={css}\n >\n <AnimatePresence initial={false}>\n {notices.map((notice) => (\n <NoticeComponent key={notice.id} variants={variants} {...notice} />\n ))}\n </AnimatePresence>\n </ui.ul>\n )\n })\n\n return (\n <Portal\n appendToParentPortal={appendToParentPortal}\n containerRef={containerRef}\n >\n {components}\n </Portal>\n )\n}\n\nconst defaultVariants: MotionVariants = {\n initial: ({ placement }) => ({\n opacity: 0,\n [[\"top\", \"bottom\"].includes(placement) ? \"y\" : \"x\"]:\n (placement === \"bottom\" ? 1 : placement.includes(\"right\") ? 1 : -1) * 24,\n }),\n animate: {\n opacity: 1,\n y: 0,\n x: 0,\n scale: 1,\n transition: {\n duration: 0.4,\n ease: [0.4, 0, 0.2, 1],\n },\n },\n exit: {\n opacity: 0,\n scale: 0.95,\n transition: {\n duration: 0.2,\n ease: [0.4, 0, 1, 1],\n },\n },\n}\n\ntype NoticeComponentProps = NoticeOptions &\n Pick<NoticeProviderProps, \"variants\">\n\nconst NoticeComponent = memo(\n ({\n variants = defaultVariants,\n placement,\n duration = 5000,\n message,\n onCloseComplete,\n isDelete = false,\n onDelete,\n style,\n }: NoticeComponentProps) => {\n const [delay, setDelay] = useState(duration)\n const isPresent = useIsPresent()\n\n useUpdateEffect(() => {\n if (!isPresent) onCloseComplete?.()\n }, [isPresent])\n\n useUpdateEffect(() => {\n setDelay(duration)\n }, [duration])\n\n const onMouseEnter = () => setDelay(null)\n const onMouseLeave = () => setDelay(duration)\n\n const onClose = () => {\n if (isPresent) onDelete()\n }\n\n useEffect(() => {\n if (isPresent && isDelete) onDelete()\n }, [isPresent, isDelete, onDelete])\n\n useTimeout(onClose, delay)\n\n const css: CSSUIObject = {\n pointerEvents: \"auto\",\n maxW: \"36rem\",\n minW: \"20rem\",\n ...style,\n }\n\n return (\n <motion.li\n layout\n className=\"ui-notice__item\"\n variants={variants}\n initial=\"initial\"\n animate=\"animate\"\n exit=\"exit\"\n onHoverStart={onMouseEnter}\n onHoverEnd={onMouseLeave}\n custom={{ placement }}\n style={\n {\n display: \"flex\",\n justifyContent: placement.includes(\"left\")\n ? \"flex-start\"\n : placement.includes(\"right\")\n ? \"flex-end\"\n : \"center\",\n } as MotionStyle\n }\n >\n <ui.div className=\"ui-notice__item-inner\" __css={css}>\n {runIfFunc(message, { onClose })}\n </ui.div>\n </motion.li>\n )\n },\n)\n\nNoticeComponent.displayName = \"NoticeComponent\"\n","import type { AlertProps } from \"@yamada-ui/alert\"\nimport {\n Alert,\n AlertDescription,\n AlertIcon,\n AlertTitle,\n} from \"@yamada-ui/alert\"\nimport { CloseButton } from \"@yamada-ui/close-button\"\nimport type {\n CSSUIObject,\n NoticePlacement,\n NoticeComponentProps,\n NoticeConfigOptions,\n StyledTheme,\n} from \"@yamada-ui/core\"\nimport { ui, useTheme } from \"@yamada-ui/core\"\nimport { cx, merge } from \"@yamada-ui/utils\"\nimport type { FC, ReactNode } from \"react\"\nimport { useMemo } from \"react\"\n\nexport type UseNoticeOptions = NoticeConfigOptions\n\nexport type NoticeOptions = {\n id: string | number\n placement: NoticePlacement\n duration: UseNoticeOptions[\"duration\"]\n status: UseNoticeOptions[\"status\"]\n message: (props: NoticeComponentProps) => ReactNode\n isDelete?: boolean\n onDelete: () => void\n onCloseComplete?: () => void\n style?: CSSUIObject\n}\n\nconst findId = (\n options: NoticeOptions[],\n id: string | number,\n): NoticeOptions | undefined => options.find((notice) => notice.id === id)\n\nconst findNotice = (\n state: State,\n id: string | number,\n): {\n placement: NoticePlacement | undefined\n index: number\n} => {\n const placement = getNoticePlacement(state, id)\n\n const index = placement\n ? state[placement].findIndex((notice) => notice.id === id)\n : -1\n\n return { placement, index }\n}\n\nconst getNoticePlacement = (\n state: State,\n id: string | number,\n): NoticePlacement | undefined => {\n for (const [placement, values] of Object.entries(state)) {\n if (findId(values, id)) return placement as NoticePlacement\n }\n}\n\ntype CreateNoticeOptions = Partial<\n Pick<\n NoticeOptions,\n \"id\" | \"placement\" | \"status\" | \"duration\" | \"onCloseComplete\" | \"style\"\n >\n>\n\nlet counter = 0\n\nconst createNotice = (\n message: (props: NoticeComponentProps) => ReactNode,\n {\n id,\n placement = \"top\",\n duration,\n onCloseComplete,\n status,\n style,\n }: CreateNoticeOptions,\n) => {\n counter += 1\n\n id ??= counter\n\n return {\n id,\n placement,\n status,\n duration,\n message,\n onDelete: () => noticeStore.remove(String(id), placement),\n isDelete: false,\n onCloseComplete,\n style,\n }\n}\n\nconst createRender = (options: UseNoticeOptions): FC<NoticeComponentProps> => {\n const { component } = options\n\n const Render: FC<NoticeComponentProps> = (props) => {\n if (typeof component === \"function\") {\n return component({ ...props, ...options }) as JSX.Element\n } else {\n return <Notice {...props} {...options} />\n }\n }\n\n return Render\n}\n\nconst createNoticeFunc = (\n defaultOptions: UseNoticeOptions,\n theme: StyledTheme,\n) => {\n const themeOptions = theme.__config.notice?.options ?? {}\n\n const computedOptions = (options: UseNoticeOptions) =>\n merge(themeOptions, merge(defaultOptions, options))\n\n const notice = (options: UseNoticeOptions = {}) => {\n options = computedOptions(options)\n\n const message = createRender(options)\n\n return noticeStore.create(message, options)\n }\n\n notice.update = (\n id: string | number,\n options: Omit<UseNoticeOptions, \"id\">,\n ) => {\n options = computedOptions(options)\n\n noticeStore.update(id, options)\n }\n\n notice.closeAll = noticeStore.closeAll\n notice.close = noticeStore.close\n notice.isActive = noticeStore.isActive\n\n return notice\n}\n\ntype CreateNoticeReturn = ReturnType<typeof createNoticeFunc>\n\n/**\n * `useNotice` is a custom hook that controls the notifications of the application.\n *\n * @see Docs https://yamada-ui.com/hooks/use-notice\n */\nexport const useNotice = (\n defaultOptions?: UseNoticeOptions,\n): CreateNoticeReturn => {\n const { theme } = useTheme()\n\n return useMemo(\n () => createNoticeFunc(defaultOptions ?? {}, theme),\n [defaultOptions, theme],\n )\n}\n\ntype State = {\n [K in NoticePlacement]: NoticeOptions[]\n}\n\ntype Store = {\n subscribe: (onStoreChange: () => void) => () => void\n getSnapshot: () => State\n create: (\n message: (props: NoticeComponentProps) => ReactNode,\n options: UseNoticeOptions,\n ) => string | number\n close: (id: string | number) => void\n closeAll: (options?: { placement?: NoticePlacement[] }) => void\n update: (id: string | number, options: Omit<UseNoticeOptions, \"id\">) => void\n remove: (id: string | number, placement: NoticePlacement) => void\n isActive: (id: string | number) => boolean\n}\n\nconst initialState = {\n top: [],\n \"top-left\": [],\n \"top-right\": [],\n bottom: [],\n \"bottom-left\": [],\n \"bottom-right\": [],\n}\n\nconst createNoticeStore = (initialState: State): Store => {\n let state = initialState\n const storeChangeCache = new Set<() => void>()\n\n const setState = (setStateFunc: (values: State) => State) => {\n state = setStateFunc(state)\n storeChangeCache.forEach((onStoreChange) => onStoreChange())\n }\n\n return {\n getSnapshot: () => state,\n\n subscribe: (onStoreChange) => {\n storeChangeCache.add(onStoreChange)\n\n return () => {\n setState(() => initialState)\n storeChangeCache.delete(onStoreChange)\n }\n },\n\n remove: (id, placement) => {\n setState((prevState) => ({\n ...prevState,\n [placement]: prevState[placement].filter((notice) => notice.id != id),\n }))\n },\n\n create: (message, options) => {\n const limit = options.limit\n\n const notice = createNotice(message, options)\n const { placement, id } = notice\n\n setState((prev) => {\n let prevNotices = prev[placement] ?? []\n\n if (\n limit !== undefined &&\n limit > 0 &&\n prevNotices.length > limit - 1\n ) {\n const n = prevNotices.length - (limit - 1)\n const notices = placement.includes(\"top\")\n ? prevNotices.slice(n * -1)\n : prevNotices.slice(0, n)\n\n const ids = notices.map(({ id }) => id)\n\n prevNotices = prevNotices.map((notice) =>\n ids.includes(notice.id) ? { ...notice, isDelete: true } : notice,\n )\n }\n\n const notices = placement.includes(\"top\")\n ? [notice, ...prevNotices]\n : [...prevNotices, notice]\n\n return { ...prev, [placement]: notices }\n })\n\n return id\n },\n\n update: (id, options) => {\n setState((prev) => {\n const next = { ...prev }\n const { placement, index } = findNotice(next, id)\n\n if (placement && index !== -1) {\n next[placement][index] = {\n ...next[placement][index],\n ...options,\n message: createRender(options),\n }\n }\n\n return next\n })\n },\n\n closeAll: ({ placement } = {}) => {\n setState((prev) => {\n let placements: NoticePlacement[] = [\n \"bottom\",\n \"bottom-right\",\n \"bottom-left\",\n \"top\",\n \"top-left\",\n \"top-right\",\n ]\n\n if (placement) placements = placement\n\n return placements.reduce(\n (acc, placement) => {\n acc[placement] = prev[placement].map((notice) => ({\n ...notice,\n isDelete: true,\n }))\n\n return acc\n },\n { ...prev },\n )\n })\n },\n\n close: (id) => {\n setState((prev) => {\n const placement = getNoticePlacement(prev, id)\n\n if (!placement) return prev\n\n return {\n ...prev,\n [placement]: prev[placement].map((notice) =>\n notice.id == id ? { ...notice, isDelete: true } : notice,\n ),\n }\n })\n },\n\n isActive: (id) =>\n Boolean(findNotice(noticeStore.getSnapshot(), id).placement),\n }\n}\n\nexport const noticeStore = createNoticeStore(initialState)\n\nexport type NoticeProps = Omit<AlertProps, keyof UseNoticeOptions> &\n UseNoticeOptions & {\n onClose?: () => void\n }\n\nconst Notice: FC<NoticeProps> = ({\n variant = \"basic\",\n colorScheme,\n status,\n icon,\n title,\n description,\n isClosable,\n className,\n onClose,\n}) => {\n return (\n <Alert\n status={status}\n variant={variant}\n colorScheme={colorScheme}\n alignItems=\"start\"\n boxShadow=\"fallback(lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05))\"\n className={cx(\"ui-notice\", className)}\n pe={isClosable ? 8 : undefined}\n >\n <AlertIcon\n variant={icon?.variant}\n className=\"ui-notice__icon\"\n {...(icon?.color ? { color: icon.color } : {})}\n >\n {icon?.children}\n </AlertIcon>\n\n <ui.div flex=\"1\">\n {title ? (\n <AlertTitle className=\"ui-notice__title\" lineClamp={1}>\n {title}\n </AlertTitle>\n ) : null}\n {description ? (\n <AlertDescription className=\"ui-notice__description\" lineClamp={3}>\n {description}\n </AlertDescription>\n ) : null}\n </ui.div>\n\n {isClosable ? (\n <CloseButton\n className=\"ui-notice__close-button\"\n size=\"sm\"\n onClick={onClose}\n position=\"absolute\"\n top={2}\n right={2}\n />\n ) : null}\n </Alert>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,IAAAA,eAAmB;AAEnB,oBAAsD;AACtD,oBAAuB;AACvB,yBAA2B;AAC3B,IAAAC,gBAA+C;AAE/C,IAAAC,gBAAgE;;;ACPhE,mBAKO;AACP,0BAA4B;AAQ5B,kBAA6B;AAC7B,mBAA0B;AAE1B,mBAAwB;AA0FX;AA1Eb,IAAM,SAAS,CACb,SACA,OAC8B,QAAQ,KAAK,CAAC,WAAW,OAAO,OAAO,EAAE;AAEzE,IAAM,aAAa,CACjB,OACA,OAIG;AACH,QAAM,YAAY,mBAAmB,OAAO,EAAE;AAE9C,QAAM,QAAQ,YACV,MAAM,SAAS,EAAE,UAAU,CAAC,WAAW,OAAO,OAAO,EAAE,IACvD;AAEJ,SAAO,EAAE,WAAW,MAAM;AAC5B;AAEA,IAAM,qBAAqB,CACzB,OACA,OACgC;AAChC,aAAW,CAAC,WAAW,MAAM,KAAK,OAAO,QAAQ,KAAK,GAAG;AACvD,QAAI,OAAO,QAAQ,EAAE,EAAG,QAAO;AAAA,EACjC;AACF;AASA,IAAI,UAAU;AAEd,IAAM,eAAe,CACnB,SACA;AAAA,EACE;AAAA,EACA,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MACG;AACH,aAA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G,CAAC,SAAS,CAAC;AAEd,uCAAgB,MAAM;AACpB,eAAS,QAAQ;AAAA,IACnB,GAAG,CAAC,QAAQ,CAAC;AAEb,UAAM,eAAe,MAAM,SAAS,IAAI;AACxC,UAAM,eAAe,MAAM,SAAS,QAAQ;AAE5C,UAAM,UAAU,MAAM;AACpB,UAAI,UAAW,UAAS;AAAA,IAC1B;AAEA,iCAAU,MAAM;AACd,UAAI,aAAa,SAAU,UAAS;AAAA,IACtC,GAAG,CAAC,WAAW,UAAU,QAAQ,CAAC;AAElC,uCAAW,SAAS,KAAK;AAEzB,UAAM,MAAmB;AAAA,MACvB,eAAe;AAAA,MACf,MAAM;AAAA,MACN,MAAM;AAAA,MACN,GAAG;AAAA,IACL;AAEA,WACE;AAAA,MAAC,qBAAO;AAAA,MAAP;AAAA,QACC,QAAM;AAAA,QACN,WAAU;AAAA,QACV;AAAA,QACA,SAAQ;AAAA,QACR,SAAQ;AAAA,QACR,MAAK;AAAA,QACL,cAAc;AAAA,QACd,YAAY;AAAA,QACZ,QAAQ,EAAE,UAAU;AAAA,QACpB,OACE;AAAA,UACE,SAAS;AAAA,UACT,gBAAgB,UAAU,SAAS,MAAM,IACrC,eACA,UAAU,SAAS,OAAO,IACxB,aACA;AAAA,QACR;AAAA,QAGF,uDAAC,gBAAG,KAAH,EAAO,WAAU,yBAAwB,OAAO,KAC9C,uCAAU,SAAS,EAAE,QAAQ,CAAC,GACjC;AAAA;AAAA,IACF;AAAA,EAEJ;AACF;AAEA,gBAAgB,cAAc;","names":["import_core","import_utils","import_react","initialState","notices","id","notice","placement","import_jsx_runtime"]}
@@ -1,8 +1,8 @@
1
1
  "use client"
2
2
  import {
3
3
  NoticeProvider
4
- } from "./chunk-RRHRITCX.mjs";
5
- import "./chunk-QJZAGAE4.mjs";
4
+ } from "./chunk-PVKDAVUE.mjs";
5
+ import "./chunk-O26YP2LY.mjs";
6
6
  export {
7
7
  NoticeProvider
8
8
  };
package/dist/notice.js CHANGED
@@ -237,7 +237,7 @@ var Notice = ({
237
237
  ),
238
238
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_core.ui.div, { flex: "1", children: [
239
239
  title ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertTitle, { className: "ui-notice__title", lineClamp: 1, children: title }) : null,
240
- description ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertDescription, { className: "ui-notice__desc", lineClamp: 3, children: description }) : null
240
+ description ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_alert.AlertDescription, { className: "ui-notice__description", lineClamp: 3, children: description }) : null
241
241
  ] }),
242
242
  isClosable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
243
243
  import_close_button.CloseButton,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/notice.tsx"],"sourcesContent":["import type { AlertProps } from \"@yamada-ui/alert\"\nimport {\n Alert,\n AlertDescription,\n AlertIcon,\n AlertTitle,\n} from \"@yamada-ui/alert\"\nimport { CloseButton } from \"@yamada-ui/close-button\"\nimport type {\n CSSUIObject,\n NoticePlacement,\n NoticeComponentProps,\n NoticeConfigOptions,\n StyledTheme,\n} from \"@yamada-ui/core\"\nimport { ui, useTheme } from \"@yamada-ui/core\"\nimport { cx, merge } from \"@yamada-ui/utils\"\nimport type { FC, ReactNode } from \"react\"\nimport { useMemo } from \"react\"\n\nexport type UseNoticeOptions = NoticeConfigOptions\n\nexport type NoticeOptions = {\n id: string | number\n placement: NoticePlacement\n duration: UseNoticeOptions[\"duration\"]\n status: UseNoticeOptions[\"status\"]\n message: (props: NoticeComponentProps) => ReactNode\n isDelete?: boolean\n onDelete: () => void\n onCloseComplete?: () => void\n style?: CSSUIObject\n}\n\nconst findId = (\n options: NoticeOptions[],\n id: string | number,\n): NoticeOptions | undefined => options.find((notice) => notice.id === id)\n\nconst findNotice = (\n state: State,\n id: string | number,\n): {\n placement: NoticePlacement | undefined\n index: number\n} => {\n const placement = getNoticePlacement(state, id)\n\n const index = placement\n ? state[placement].findIndex((notice) => notice.id === id)\n : -1\n\n return { placement, index }\n}\n\nconst getNoticePlacement = (\n state: State,\n id: string | number,\n): NoticePlacement | undefined => {\n for (const [placement, values] of Object.entries(state)) {\n if (findId(values, id)) return placement as NoticePlacement\n }\n}\n\ntype CreateNoticeOptions = Partial<\n Pick<\n NoticeOptions,\n \"id\" | \"placement\" | \"status\" | \"duration\" | \"onCloseComplete\" | \"style\"\n >\n>\n\nlet counter = 0\n\nconst createNotice = (\n message: (props: NoticeComponentProps) => ReactNode,\n {\n id,\n placement = \"top\",\n duration,\n onCloseComplete,\n status,\n style,\n }: CreateNoticeOptions,\n) => {\n counter += 1\n\n id ??= counter\n\n return {\n id,\n placement,\n status,\n duration,\n message,\n onDelete: () => noticeStore.remove(String(id), placement),\n isDelete: false,\n onCloseComplete,\n style,\n }\n}\n\nconst createRender = (options: UseNoticeOptions): FC<NoticeComponentProps> => {\n const { component } = options\n\n const Render: FC<NoticeComponentProps> = (props) => {\n if (typeof component === \"function\") {\n return component({ ...props, ...options }) as JSX.Element\n } else {\n return <Notice {...props} {...options} />\n }\n }\n\n return Render\n}\n\nconst createNoticeFunc = (\n defaultOptions: UseNoticeOptions,\n theme: StyledTheme,\n) => {\n const themeOptions = theme.__config.notice?.options ?? {}\n\n const computedOptions = (options: UseNoticeOptions) =>\n merge(themeOptions, merge(defaultOptions, options))\n\n const notice = (options: UseNoticeOptions = {}) => {\n options = computedOptions(options)\n\n const message = createRender(options)\n\n return noticeStore.create(message, options)\n }\n\n notice.update = (\n id: string | number,\n options: Omit<UseNoticeOptions, \"id\">,\n ) => {\n options = computedOptions(options)\n\n noticeStore.update(id, options)\n }\n\n notice.closeAll = noticeStore.closeAll\n notice.close = noticeStore.close\n notice.isActive = noticeStore.isActive\n\n return notice\n}\n\ntype CreateNoticeReturn = ReturnType<typeof createNoticeFunc>\n\n/**\n * `useNotice` is a custom hook that controls the notifications of the application.\n *\n * @see Docs https://yamada-ui.com/hooks/use-notice\n */\nexport const useNotice = (\n defaultOptions?: UseNoticeOptions,\n): CreateNoticeReturn => {\n const { theme } = useTheme()\n\n return useMemo(\n () => createNoticeFunc(defaultOptions ?? {}, theme),\n [defaultOptions, theme],\n )\n}\n\ntype State = {\n [K in NoticePlacement]: NoticeOptions[]\n}\n\ntype Store = {\n subscribe: (onStoreChange: () => void) => () => void\n getSnapshot: () => State\n create: (\n message: (props: NoticeComponentProps) => ReactNode,\n options: UseNoticeOptions,\n ) => string | number\n close: (id: string | number) => void\n closeAll: (options?: { placement?: NoticePlacement[] }) => void\n update: (id: string | number, options: Omit<UseNoticeOptions, \"id\">) => void\n remove: (id: string | number, placement: NoticePlacement) => void\n isActive: (id: string | number) => boolean\n}\n\nconst initialState = {\n top: [],\n \"top-left\": [],\n \"top-right\": [],\n bottom: [],\n \"bottom-left\": [],\n \"bottom-right\": [],\n}\n\nconst createNoticeStore = (initialState: State): Store => {\n let state = initialState\n const storeChangeCache = new Set<() => void>()\n\n const setState = (setStateFunc: (values: State) => State) => {\n state = setStateFunc(state)\n storeChangeCache.forEach((onStoreChange) => onStoreChange())\n }\n\n return {\n getSnapshot: () => state,\n\n subscribe: (onStoreChange) => {\n storeChangeCache.add(onStoreChange)\n\n return () => {\n setState(() => initialState)\n storeChangeCache.delete(onStoreChange)\n }\n },\n\n remove: (id, placement) => {\n setState((prevState) => ({\n ...prevState,\n [placement]: prevState[placement].filter((notice) => notice.id != id),\n }))\n },\n\n create: (message, options) => {\n const limit = options.limit\n\n const notice = createNotice(message, options)\n const { placement, id } = notice\n\n setState((prev) => {\n let prevNotices = prev[placement] ?? []\n\n if (\n limit !== undefined &&\n limit > 0 &&\n prevNotices.length > limit - 1\n ) {\n const n = prevNotices.length - (limit - 1)\n const notices = placement.includes(\"top\")\n ? prevNotices.slice(n * -1)\n : prevNotices.slice(0, n)\n\n const ids = notices.map(({ id }) => id)\n\n prevNotices = prevNotices.map((notice) =>\n ids.includes(notice.id) ? { ...notice, isDelete: true } : notice,\n )\n }\n\n const notices = placement.includes(\"top\")\n ? [notice, ...prevNotices]\n : [...prevNotices, notice]\n\n return { ...prev, [placement]: notices }\n })\n\n return id\n },\n\n update: (id, options) => {\n setState((prev) => {\n const next = { ...prev }\n const { placement, index } = findNotice(next, id)\n\n if (placement && index !== -1) {\n next[placement][index] = {\n ...next[placement][index],\n ...options,\n message: createRender(options),\n }\n }\n\n return next\n })\n },\n\n closeAll: ({ placement } = {}) => {\n setState((prev) => {\n let placements: NoticePlacement[] = [\n \"bottom\",\n \"bottom-right\",\n \"bottom-left\",\n \"top\",\n \"top-left\",\n \"top-right\",\n ]\n\n if (placement) placements = placement\n\n return placements.reduce(\n (acc, placement) => {\n acc[placement] = prev[placement].map((notice) => ({\n ...notice,\n isDelete: true,\n }))\n\n return acc\n },\n { ...prev },\n )\n })\n },\n\n close: (id) => {\n setState((prev) => {\n const placement = getNoticePlacement(prev, id)\n\n if (!placement) return prev\n\n return {\n ...prev,\n [placement]: prev[placement].map((notice) =>\n notice.id == id ? { ...notice, isDelete: true } : notice,\n ),\n }\n })\n },\n\n isActive: (id) =>\n Boolean(findNotice(noticeStore.getSnapshot(), id).placement),\n }\n}\n\nexport const noticeStore = createNoticeStore(initialState)\n\nexport type NoticeProps = Omit<AlertProps, keyof UseNoticeOptions> &\n UseNoticeOptions & {\n onClose?: () => void\n }\n\nconst Notice: FC<NoticeProps> = ({\n variant = \"basic\",\n colorScheme,\n status,\n icon,\n title,\n description,\n isClosable,\n className,\n onClose,\n}) => {\n return (\n <Alert\n status={status}\n variant={variant}\n colorScheme={colorScheme}\n alignItems=\"start\"\n boxShadow=\"fallback(lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05))\"\n className={cx(\"ui-notice\", className)}\n pe={isClosable ? 8 : undefined}\n >\n <AlertIcon\n variant={icon?.variant}\n className=\"ui-notice__icon\"\n {...(icon?.color ? { color: icon.color } : {})}\n >\n {icon?.children}\n </AlertIcon>\n\n <ui.div flex=\"1\">\n {title ? (\n <AlertTitle className=\"ui-notice__title\" lineClamp={1}>\n {title}\n </AlertTitle>\n ) : null}\n {description ? (\n <AlertDescription className=\"ui-notice__desc\" lineClamp={3}>\n {description}\n </AlertDescription>\n ) : null}\n </ui.div>\n\n {isClosable ? (\n <CloseButton\n className=\"ui-notice__close-button\"\n size=\"sm\"\n onClick={onClose}\n position=\"absolute\"\n top={2}\n right={2}\n />\n ) : null}\n </Alert>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAKO;AACP,0BAA4B;AAQ5B,kBAA6B;AAC7B,mBAA0B;AAE1B,mBAAwB;AA0FX;AA1Eb,IAAM,SAAS,CACb,SACA,OAC8B,QAAQ,KAAK,CAAC,WAAW,OAAO,OAAO,EAAE;AAEzE,IAAM,aAAa,CACjB,OACA,OAIG;AACH,QAAM,YAAY,mBAAmB,OAAO,EAAE;AAE9C,QAAM,QAAQ,YACV,MAAM,SAAS,EAAE,UAAU,CAAC,WAAW,OAAO,OAAO,EAAE,IACvD;AAEJ,SAAO,EAAE,WAAW,MAAM;AAC5B;AAEA,IAAM,qBAAqB,CACzB,OACA,OACgC;AAChC,aAAW,CAAC,WAAW,MAAM,KAAK,OAAO,QAAQ,KAAK,GAAG;AACvD,QAAI,OAAO,QAAQ,EAAE,EAAG,QAAO;AAAA,EACjC;AACF;AASA,IAAI,UAAU;AAEd,IAAM,eAAe,CACnB,SACA;AAAA,EACE;AAAA,EACA,YAAY;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MACG;AACH,aAAW;AAEX,yBAAO;AAEP,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,MAAM,YAAY,OAAO,OAAO,EAAE,GAAG,SAAS;AAAA,IACxD,UAAU;AAAA,IACV;AAAA,IACA;AAAA,EACF;AACF;AAEA,IAAM,eAAe,CAAC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ACpD;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,IAEA,UAAU,CAAC,OACT,QAAQ,WAAW,YAAY,YAAY,GAAG,EAAE,EAAE,SAAS;AAAA,EAC/D;AACF;AAEO,IAAM,cAAc,kBAAkB,YAAY;AAOzD,IAAM,SAA0B,CAAC;AAAA,EAC/B,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA,YAAW;AAAA,MACX,WAAU;AAAA,MACV,eAAW,iBAAG,aAAa,SAAS;AAAA,MACpC,IAAI,aAAa,IAAI;AAAA,MAErB;AAAA;AAAA,UAAC;AAAA;AAAA,YACC,SAAS,6BAAM;AAAA,YACf,WAAU;AAAA,YACT,IAAI,6BAAM,SAAQ,EAAE,OAAO,KAAK,MAAM,IAAI,CAAC;AAAA,YAE3C,uCAAM;AAAA;AAAA,QACT;AAAA,QAEA,6CAAC,eAAG,KAAH,EAAO,MAAK,KACV;AAAA,kBACC,4CAAC,2BAAW,WAAU,oBAAmB,WAAW,GACjD,iBACH,IACE;AAAA,UACH,cACC,4CAAC,iCAAiB,WAAU,mBAAkB,WAAW,GACtD,uBACH,IACE;AAAA,WACN;AAAA,QAEC,aACC;AAAA,UAAC;AAAA;AAAA,YACC,WAAU;AAAA,YACV,MAAK;AAAA,YACL,SAAS;AAAA,YACT,UAAS;AAAA,YACT,KAAK;AAAA,YACL,OAAO;AAAA;AAAA,QACT,IACE;AAAA;AAAA;AAAA,EACN;AAEJ;","names":["initialState","notices","id","notice","placement"]}
1
+ {"version":3,"sources":["../src/notice.tsx"],"sourcesContent":["import type { AlertProps } from \"@yamada-ui/alert\"\nimport {\n Alert,\n AlertDescription,\n AlertIcon,\n AlertTitle,\n} from \"@yamada-ui/alert\"\nimport { CloseButton } from \"@yamada-ui/close-button\"\nimport type {\n CSSUIObject,\n NoticePlacement,\n NoticeComponentProps,\n NoticeConfigOptions,\n StyledTheme,\n} from \"@yamada-ui/core\"\nimport { ui, useTheme } from \"@yamada-ui/core\"\nimport { cx, merge } from \"@yamada-ui/utils\"\nimport type { FC, ReactNode } from \"react\"\nimport { useMemo } from \"react\"\n\nexport type UseNoticeOptions = NoticeConfigOptions\n\nexport type NoticeOptions = {\n id: string | number\n placement: NoticePlacement\n duration: UseNoticeOptions[\"duration\"]\n status: UseNoticeOptions[\"status\"]\n message: (props: NoticeComponentProps) => ReactNode\n isDelete?: boolean\n onDelete: () => void\n onCloseComplete?: () => void\n style?: CSSUIObject\n}\n\nconst findId = (\n options: NoticeOptions[],\n id: string | number,\n): NoticeOptions | undefined => options.find((notice) => notice.id === id)\n\nconst findNotice = (\n state: State,\n id: string | number,\n): {\n placement: NoticePlacement | undefined\n index: number\n} => {\n const placement = getNoticePlacement(state, id)\n\n const index = placement\n ? state[placement].findIndex((notice) => notice.id === id)\n : -1\n\n return { placement, index }\n}\n\nconst getNoticePlacement = (\n state: State,\n id: string | number,\n): NoticePlacement | undefined => {\n for (const [placement, values] of Object.entries(state)) {\n if (findId(values, id)) return placement as NoticePlacement\n }\n}\n\ntype CreateNoticeOptions = Partial<\n Pick<\n NoticeOptions,\n \"id\" | \"placement\" | \"status\" | \"duration\" | \"onCloseComplete\" | \"style\"\n >\n>\n\nlet counter = 0\n\nconst createNotice = (\n message: (props: NoticeComponentProps) => ReactNode,\n {\n id,\n placement = \"top\",\n duration,\n onCloseComplete,\n status,\n style,\n }: CreateNoticeOptions,\n) => {\n counter += 1\n\n id ??= counter\n\n return {\n id,\n placement,\n status,\n duration,\n message,\n onDelete: () => noticeStore.remove(String(id), placement),\n isDelete: false,\n onCloseComplete,\n style,\n }\n}\n\nconst createRender = (options: UseNoticeOptions): FC<NoticeComponentProps> => {\n const { component } = options\n\n const Render: FC<NoticeComponentProps> = (props) => {\n if (typeof component === \"function\") {\n return component({ ...props, ...options }) as JSX.Element\n } else {\n return <Notice {...props} {...options} />\n }\n }\n\n return Render\n}\n\nconst createNoticeFunc = (\n defaultOptions: UseNoticeOptions,\n theme: StyledTheme,\n) => {\n const themeOptions = theme.__config.notice?.options ?? {}\n\n const computedOptions = (options: UseNoticeOptions) =>\n merge(themeOptions, merge(defaultOptions, options))\n\n const notice = (options: UseNoticeOptions = {}) => {\n options = computedOptions(options)\n\n const message = createRender(options)\n\n return noticeStore.create(message, options)\n }\n\n notice.update = (\n id: string | number,\n options: Omit<UseNoticeOptions, \"id\">,\n ) => {\n options = computedOptions(options)\n\n noticeStore.update(id, options)\n }\n\n notice.closeAll = noticeStore.closeAll\n notice.close = noticeStore.close\n notice.isActive = noticeStore.isActive\n\n return notice\n}\n\ntype CreateNoticeReturn = ReturnType<typeof createNoticeFunc>\n\n/**\n * `useNotice` is a custom hook that controls the notifications of the application.\n *\n * @see Docs https://yamada-ui.com/hooks/use-notice\n */\nexport const useNotice = (\n defaultOptions?: UseNoticeOptions,\n): CreateNoticeReturn => {\n const { theme } = useTheme()\n\n return useMemo(\n () => createNoticeFunc(defaultOptions ?? {}, theme),\n [defaultOptions, theme],\n )\n}\n\ntype State = {\n [K in NoticePlacement]: NoticeOptions[]\n}\n\ntype Store = {\n subscribe: (onStoreChange: () => void) => () => void\n getSnapshot: () => State\n create: (\n message: (props: NoticeComponentProps) => ReactNode,\n options: UseNoticeOptions,\n ) => string | number\n close: (id: string | number) => void\n closeAll: (options?: { placement?: NoticePlacement[] }) => void\n update: (id: string | number, options: Omit<UseNoticeOptions, \"id\">) => void\n remove: (id: string | number, placement: NoticePlacement) => void\n isActive: (id: string | number) => boolean\n}\n\nconst initialState = {\n top: [],\n \"top-left\": [],\n \"top-right\": [],\n bottom: [],\n \"bottom-left\": [],\n \"bottom-right\": [],\n}\n\nconst createNoticeStore = (initialState: State): Store => {\n let state = initialState\n const storeChangeCache = new Set<() => void>()\n\n const setState = (setStateFunc: (values: State) => State) => {\n state = setStateFunc(state)\n storeChangeCache.forEach((onStoreChange) => onStoreChange())\n }\n\n return {\n getSnapshot: () => state,\n\n subscribe: (onStoreChange) => {\n storeChangeCache.add(onStoreChange)\n\n return () => {\n setState(() => initialState)\n storeChangeCache.delete(onStoreChange)\n }\n },\n\n remove: (id, placement) => {\n setState((prevState) => ({\n ...prevState,\n [placement]: prevState[placement].filter((notice) => notice.id != id),\n }))\n },\n\n create: (message, options) => {\n const limit = options.limit\n\n const notice = createNotice(message, options)\n const { placement, id } = notice\n\n setState((prev) => {\n let prevNotices = prev[placement] ?? []\n\n if (\n limit !== undefined &&\n limit > 0 &&\n prevNotices.length > limit - 1\n ) {\n const n = prevNotices.length - (limit - 1)\n const notices = placement.includes(\"top\")\n ? prevNotices.slice(n * -1)\n : prevNotices.slice(0, n)\n\n const ids = notices.map(({ id }) => id)\n\n prevNotices = prevNotices.map((notice) =>\n ids.includes(notice.id) ? { ...notice, isDelete: true } : notice,\n )\n }\n\n const notices = placement.includes(\"top\")\n ? [notice, ...prevNotices]\n : [...prevNotices, notice]\n\n return { ...prev, [placement]: notices }\n })\n\n return id\n },\n\n update: (id, options) => {\n setState((prev) => {\n const next = { ...prev }\n const { placement, index } = findNotice(next, id)\n\n if (placement && index !== -1) {\n next[placement][index] = {\n ...next[placement][index],\n ...options,\n message: createRender(options),\n }\n }\n\n return next\n })\n },\n\n closeAll: ({ placement } = {}) => {\n setState((prev) => {\n let placements: NoticePlacement[] = [\n \"bottom\",\n \"bottom-right\",\n \"bottom-left\",\n \"top\",\n \"top-left\",\n \"top-right\",\n ]\n\n if (placement) placements = placement\n\n return placements.reduce(\n (acc, placement) => {\n acc[placement] = prev[placement].map((notice) => ({\n ...notice,\n isDelete: true,\n }))\n\n return acc\n },\n { ...prev },\n )\n })\n },\n\n close: (id) => {\n setState((prev) => {\n const placement = getNoticePlacement(prev, id)\n\n if (!placement) return prev\n\n return {\n ...prev,\n [placement]: prev[placement].map((notice) =>\n notice.id == id ? { ...notice, isDelete: true } : notice,\n ),\n }\n })\n },\n\n isActive: (id) =>\n Boolean(findNotice(noticeStore.getSnapshot(), id).placement),\n }\n}\n\nexport const noticeStore = createNoticeStore(initialState)\n\nexport type NoticeProps = Omit<AlertProps, keyof UseNoticeOptions> &\n UseNoticeOptions & {\n onClose?: () => void\n }\n\nconst Notice: FC<NoticeProps> = ({\n variant = \"basic\",\n colorScheme,\n status,\n icon,\n title,\n description,\n isClosable,\n className,\n onClose,\n}) => {\n return (\n <Alert\n status={status}\n variant={variant}\n colorScheme={colorScheme}\n alignItems=\"start\"\n boxShadow=\"fallback(lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05))\"\n className={cx(\"ui-notice\", className)}\n pe={isClosable ? 8 : undefined}\n >\n <AlertIcon\n variant={icon?.variant}\n className=\"ui-notice__icon\"\n {...(icon?.color ? { color: icon.color } : {})}\n >\n {icon?.children}\n </AlertIcon>\n\n <ui.div flex=\"1\">\n {title ? (\n <AlertTitle className=\"ui-notice__title\" lineClamp={1}>\n {title}\n </AlertTitle>\n ) : null}\n {description ? (\n <AlertDescription className=\"ui-notice__description\" lineClamp={3}>\n {description}\n </AlertDescription>\n ) : null}\n </ui.div>\n\n {isClosable ? (\n <CloseButton\n className=\"ui-notice__close-button\"\n size=\"sm\"\n onClick={onClose}\n position=\"absolute\"\n top={2}\n right={2}\n />\n ) : null}\n </Alert>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAKO;AACP,0BAA4B;AAQ5B,kBAA6B;AAC7B,mBAA0B;AAE1B,mBAAwB;AA0FX;AA1Eb,IAAM,SAAS,CACb,SACA,OAC8B,QAAQ,KAAK,CAAC,WAAW,OAAO,OAAO,EAAE;AAEzE,IAAM,aAAa,CACjB,OACA,OAIG;AACH,QAAM,YAAY,mBAAmB,OAAO,EAAE;AAE9C,QAAM,QAAQ,YACV,MAAM,SAAS,EAAE,UAA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AAAA;AAAA,QACT;AAAA,QAEA,6CAAC,eAAG,KAAH,EAAO,MAAK,KACV;AAAA,kBACC,4CAAC,2BAAW,WAAU,oBAAmB,WAAW,GACjD,iBACH,IACE;AAAA,UACH,cACC,4CAAC,iCAAiB,WAAU,0BAAyB,WAAW,GAC7D,uBACH,IACE;AAAA,WACN;AAAA,QAEC,aACC;AAAA,UAAC;AAAA;AAAA,YACC,WAAU;AAAA,YACV,MAAK;AAAA,YACL,SAAS;AAAA,YACT,UAAS;AAAA,YACT,KAAK;AAAA,YACL,OAAO;AAAA;AAAA,QACT,IACE;AAAA;AAAA;AAAA,EACN;AAEJ;","names":["initialState","notices","id","notice","placement"]}
package/dist/notice.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  noticeStore,
4
4
  useNotice
5
- } from "./chunk-QJZAGAE4.mjs";
5
+ } from "./chunk-O26YP2LY.mjs";
6
6
  export {
7
7
  noticeStore,
8
8
  useNotice
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yamada-ui/notice",
3
- "version": "2.0.0-next-20240706053520",
3
+ "version": "2.0.0-next-20240706062355",
4
4
  "description": "Yamada UI notice component",
5
5
  "keywords": [
6
6
  "yamada",
@@ -37,8 +37,8 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@yamada-ui/core": "1.9.1",
40
- "@yamada-ui/close-button": "2.0.0-next-20240706053520",
41
- "@yamada-ui/alert": "2.0.0-next-20240706053520",
40
+ "@yamada-ui/close-button": "2.0.0-next-20240706062355",
41
+ "@yamada-ui/alert": "2.0.0-next-20240706062355",
42
42
  "@yamada-ui/portal": "1.0.17",
43
43
  "@yamada-ui/motion": "2.0.2",
44
44
  "@yamada-ui/use-timeout": "1.0.16",