From 5a14488e05c4a902eea2a5cee216ec4c84d1a0cf Mon Sep 17 00:00:00 2001 From: drl990114 Date: Tue, 16 Apr 2024 21:19:54 +0800 Subject: [PATCH] fix: toast use sonner --- .dumi/theme/layouts/GlobalLayout.tsx | 3 +- package.json | 3 +- src/Toast/demo/basic.tsx | 48 +++++++++++++++++++++++ src/Toast/index.md | 17 ++++++++ src/Toast/index.tsx | 58 ++++++---------------------- yarn.lock | 12 ------ 6 files changed, 80 insertions(+), 61 deletions(-) create mode 100644 src/Toast/demo/basic.tsx create mode 100644 src/Toast/index.md diff --git a/.dumi/theme/layouts/GlobalLayout.tsx b/.dumi/theme/layouts/GlobalLayout.tsx index cc65214..48e8abd 100644 --- a/.dumi/theme/layouts/GlobalLayout.tsx +++ b/.dumi/theme/layouts/GlobalLayout.tsx @@ -1,5 +1,5 @@ import { useOutlet, usePrefersColor } from 'dumi'; -import { ThemeProvider } from '../../../src'; +import { ThemeProvider, Notifications } from '../../../src'; const GlobalLayout = () => { const [color] = usePrefersColor(); @@ -12,6 +12,7 @@ const GlobalLayout = () => { }} > {outlet} + ); }; diff --git a/package.json b/package.json index fcd17b6..cf836ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zens", - "version": "0.0.14", + "version": "0.0.16", "description": "MarkFlowy's ui component library.", "keywords": [], "homepage": "https://github.com/drl990114/zens#readme", @@ -68,7 +68,6 @@ "rc-image": "^7.5.1", "react": "^18.2.0", "react-dom": "^18.2.0", - "react-hot-toast": "^2.4.1", "react-spinners": "^0.13.8", "sonner": "^1.4.0", "styled-components": "^6.1.0", diff --git a/src/Toast/demo/basic.tsx b/src/Toast/demo/basic.tsx new file mode 100644 index 0000000..1aa4d2d --- /dev/null +++ b/src/Toast/demo/basic.tsx @@ -0,0 +1,48 @@ +import { Button, Space, toast } from 'zens'; + +export default () => { + const normalToast = () => { + toast('normal toast'); + }; + + const errorToast = () => { + toast.error('error toast'); + }; + + const longtextToast = () => { + toast('longtext toast'.repeat(20), { + duration: 10000, + }); + }; + + const successToast = () => { + toast.success('success toast'); + }; + + const promiseToast = () => { + let a = 'qweq'; + const n = toast.loading('loading'); + + setTimeout(() => { + toast.dismiss(n); + toast.success('success', { + action: { + label: 'action', + onClick: () => { + toast('action'); + }, + }, + }); + }, 2000); + }; + + return ( + + + + + + + + ); +}; diff --git a/src/Toast/index.md b/src/Toast/index.md new file mode 100644 index 0000000..b1caf3e --- /dev/null +++ b/src/Toast/index.md @@ -0,0 +1,17 @@ +--- +title: Toast 提示 +nav: + title: 组件 + order: 2 +group: + title: 反馈 + order: 1 +--- + +# Toast 提示 + +提示 + +### 基本用法 + + diff --git a/src/Toast/index.tsx b/src/Toast/index.tsx index 2cdf2f2..22e9341 100644 --- a/src/Toast/index.tsx +++ b/src/Toast/index.tsx @@ -1,61 +1,27 @@ -import { memo, useContext } from 'react' -import { ToastBar, Toaster, toast } from 'react-hot-toast' -import styled, { ThemeContext } from 'styled-components' +import { memo, useContext } from 'react'; +import { Toaster } from 'sonner'; +import styled, { ThemeContext } from 'styled-components'; -export { toast } from 'react-hot-toast' +export { toast } from 'sonner'; -export type Variant = 'default' | 'error' | 'warning' | 'info' | 'success' - -const ToastIcon = styled.div` - padding-top: ${({ theme }) => theme?.spaceXs}; -` - -const ToastDismiss = styled.div` - padding: ${({ theme }) => theme?.spaceXs} ${({ theme }) => theme?.spaceSm}; - border-radius: ${({ theme }) => theme?.smallBorderRadius}; - cursor: pointer; - - &:hover { - color: ${({ theme }) => theme?.white}; - background: ${({ theme }) => theme?.accentColor}; - } -` +export type Variant = 'default' | 'error' | 'warning' | 'info' | 'success'; export const Notifications = memo(() => { - const context = useContext(ThemeContext) + const context = useContext(ThemeContext); return ( - {(t) => ( - - {({ icon, message }) => ( - <> - {icon} - {message} - {t.type !== 'loading' && ( - toast.dismiss(t.id)}> - x - - )} - - )} - - )} - - ) -}) + > + ); +}); diff --git a/yarn.lock b/yarn.lock index df88ec1..64c7364 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9205,11 +9205,6 @@ gonzales-pe@^4.3.0: dependencies: minimist "^1.2.5" -goober@^2.1.10: - version "2.1.14" - resolved "https://registry.yarnpkg.com/goober/-/goober-2.1.14.tgz#4a5c94fc34dc086a8e6035360ae1800005135acd" - integrity sha512-4UpC0NdGyAFqLNPnhCT2iHpza2q+RAY3GV85a/mRPdzyPQMsj0KmMMuetdIkzWRbJ+Hgau1EZztq8ImmiMGhsg== - gopd@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/gopd/-/gopd-1.0.1.tgz#29ff76de69dac7489b7c0918a5788e56477c332c" @@ -15842,13 +15837,6 @@ react-helmet-async@1.3.0: react-fast-compare "^3.2.0" shallowequal "^1.1.0" -react-hot-toast@^2.4.1: - version "2.4.1" - resolved "https://registry.yarnpkg.com/react-hot-toast/-/react-hot-toast-2.4.1.tgz#df04295eda8a7b12c4f968e54a61c8d36f4c0994" - integrity sha512-j8z+cQbWIM5LY37pR6uZR6D4LfseplqnuAO4co4u8917hBUvXlEqyP1ZzqVLcqoyUesZZv/ImreoCeHVDpE5pQ== - dependencies: - goober "^2.1.10" - react-intl@^6.4.4: version "6.6.2" resolved "https://registry.yarnpkg.com/react-intl/-/react-intl-6.6.2.tgz#97a044afa9cac65ae62f404c8bb9cbd3aec52d41"