feat(component): adjust notify styles (#6578)

Change the styles of `notify.error`, `notify.warning`, and `notify.success` from `alert` to `normal`
Add custom `iconColor` option
This commit is contained in:
JimmFly
2024-04-17 12:36:42 +00:00
parent 8b66c1d752
commit bcee1bbd81
7 changed files with 48 additions and 8 deletions

View File

@@ -11,6 +11,7 @@ import {
getCardBorderColor, getCardBorderColor,
getCardColor, getCardColor,
getCardForegroundColor, getCardForegroundColor,
getIconColor,
} from './utils'; } from './utils';
export interface NotificationCardProps extends HTMLAttributes<HTMLDivElement> { export interface NotificationCardProps extends HTMLAttributes<HTMLDivElement> {
@@ -22,6 +23,7 @@ export const NotificationCard = ({ notification }: NotificationCardProps) => {
theme = 'info', theme = 'info',
style = 'normal', style = 'normal',
icon = <InformationFillDuotoneIcon />, icon = <InformationFillDuotoneIcon />,
iconColor,
thumb, thumb,
action, action,
title, title,
@@ -44,6 +46,7 @@ export const NotificationCard = ({ notification }: NotificationCardProps) => {
[styles.cardBorderColor]: getCardBorderColor(style), [styles.cardBorderColor]: getCardBorderColor(style),
[styles.cardForeground]: getCardForegroundColor(style), [styles.cardForeground]: getCardForegroundColor(style),
[styles.actionTextColor]: getActionTextColor(style, theme), [styles.actionTextColor]: getActionTextColor(style, theme),
[styles.iconColor]: getIconColor(style, theme, iconColor),
})} })}
data-with-icon={icon ? '' : undefined} data-with-icon={icon ? '' : undefined}
className={styles.card} className={styles.card}

View File

@@ -1,4 +1,7 @@
import { SingleSelectSelectSolidIcon } from '@blocksuite/icons'; import {
InformationFillDuotoneIcon,
SingleSelectSelectSolidIcon,
} from '@blocksuite/icons';
import { assignInlineVars } from '@vanilla-extract/dynamic'; import { assignInlineVars } from '@vanilla-extract/dynamic';
import { type CSSProperties, type FC, useMemo } from 'react'; import { type CSSProperties, type FC, useMemo } from 'react';
import { type ExternalToast, toast, Toaster } from 'sonner'; import { type ExternalToast, toast, Toaster } from 'sonner';
@@ -55,14 +58,22 @@ export function notify(notification: Notification, options?: ExternalToast) {
} }
notify.error = (notification: Notification, options?: ExternalToast) => { notify.error = (notification: Notification, options?: ExternalToast) => {
return notify({ style: 'alert', theme: 'error', ...notification }, options); return notify(
{
icon: <InformationFillDuotoneIcon />,
style: 'normal',
theme: 'error',
...notification,
},
options
);
}; };
notify.success = (notification: Notification, options?: ExternalToast) => { notify.success = (notification: Notification, options?: ExternalToast) => {
return notify( return notify(
{ {
icon: <SingleSelectSelectSolidIcon />, icon: <SingleSelectSelectSolidIcon />,
style: 'alert', style: 'normal',
theme: 'success', theme: 'success',
...notification, ...notification,
}, },
@@ -72,7 +83,12 @@ notify.success = (notification: Notification, options?: ExternalToast) => {
notify.warning = (notification: Notification, options?: ExternalToast) => { notify.warning = (notification: Notification, options?: ExternalToast) => {
return notify( return notify(
{ style: 'information', theme: 'warning', ...notification }, {
icon: <InformationFillDuotoneIcon />,
style: 'normal',
theme: 'warning',
...notification,
},
options options
); );
}; };

View File

@@ -5,6 +5,7 @@ export const cardColor = createVar();
export const cardForeground = createVar(); export const cardForeground = createVar();
export const cardBorderColor = createVar(); export const cardBorderColor = createVar();
export const actionTextColor = createVar(); export const actionTextColor = createVar();
export const iconColor = createVar();
export const card = style({ export const card = style({
borderRadius: 8, borderRadius: 8,
@@ -38,6 +39,7 @@ export const icon = style({
globalStyle(`${icon} svg`, { globalStyle(`${icon} svg`, {
width: '100%', width: '100%',
height: '100%', height: '100%',
color: iconColor,
}); });
export const title = style({ export const title = style({
width: 0, width: 0,

View File

@@ -28,6 +28,7 @@ export interface Notification {
title?: ReactNode; title?: ReactNode;
message?: ReactNode; message?: ReactNode;
icon?: ReactNode; icon?: ReactNode;
iconColor?: string;
footer?: ReactNode; footer?: ReactNode;
// events // events

View File

@@ -53,3 +53,21 @@ export const getCardBorderColor = (style: NotificationStyle) => {
export const getCardForegroundColor = (style: NotificationStyle) => { export const getCardForegroundColor = (style: NotificationStyle) => {
return style === 'alert' ? cssVar('pureWhite') : cssVar('textPrimaryColor'); return style === 'alert' ? cssVar('pureWhite') : cssVar('textPrimaryColor');
}; };
export const getIconColor = (
style: NotificationStyle,
theme: NotificationTheme,
iconColor?: string
) => {
if (style === 'normal') {
const map: Record<NotificationTheme, string> = {
error: cssVar('errorColor'),
info: cssVar('processingColor'),
success: cssVar('successColor'),
warning: cssVar('warningColor'),
};
return iconColor || map[theme];
}
return iconColor || cssVar('pureWhite');
};

View File

@@ -70,7 +70,8 @@ export const AIOnboardingEdgeless = ({
{ {
title: t['com.affine.ai-onboarding.edgeless.title'](), title: t['com.affine.ai-onboarding.edgeless.title'](),
message: t['com.affine.ai-onboarding.edgeless.message'](), message: t['com.affine.ai-onboarding.edgeless.message'](),
icon: <AiIcon color={cssVar('processingColor')} />, icon: <AiIcon />,
iconColor: cssVar('brandColor'),
thumb: <EdgelessOnboardingAnimation />, thumb: <EdgelessOnboardingAnimation />,
alignMessage: 'icon', alignMessage: 'icon',
onDismiss, onDismiss,

View File

@@ -44,9 +44,8 @@ export const AIResume = ({ ...btnProps }: AIResumeProps) => {
SubscriptionPlan.AI SubscriptionPlan.AI
); );
notify({ notify({
icon: ( icon: <SingleSelectSelectSolidIcon />,
<SingleSelectSelectSolidIcon color={cssVar('processingColor')} /> iconColor: cssVar('processingColor'),
),
title: title:
t['com.affine.payment.ai.action.resume.confirm.notify.title'](), t['com.affine.payment.ai.action.resume.confirm.notify.title'](),
message: message: