Skip to content

Commit

Permalink
feat(component): add custom iconColor option to notify
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmFly committed Apr 16, 2024
1 parent 02a387b commit d1169da
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getCardBorderColor,
getCardColor,
getCardForegroundColor,
getIconColor,
} from './utils';

export interface NotificationCardProps extends HTMLAttributes<HTMLDivElement> {
Expand All @@ -22,6 +23,7 @@ export const NotificationCard = ({ notification }: NotificationCardProps) => {
theme = 'info',
style = 'normal',
icon = <InformationFillDuotoneIcon />,
iconColor,
thumb,
action,
title,
Expand All @@ -44,6 +46,7 @@ export const NotificationCard = ({ notification }: NotificationCardProps) => {
[styles.cardBorderColor]: getCardBorderColor(style),
[styles.cardForeground]: getCardForegroundColor(style),
[styles.actionTextColor]: getActionTextColor(style, theme),
[styles.iconColor]: getIconColor(style, theme, iconColor),
})}
data-with-icon={icon ? '' : undefined}
className={styles.card}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
InformationFillDuotoneIcon,
SingleSelectSelectSolidIcon,
} from '@blocksuite/icons';
import { cssVar } from '@toeverything/theme';
import { assignInlineVars } from '@vanilla-extract/dynamic';
import { type CSSProperties, type FC, useMemo } from 'react';
import { type ExternalToast, toast, Toaster } from 'sonner';
Expand Down Expand Up @@ -61,7 +60,7 @@ export function notify(notification: Notification, options?: ExternalToast) {
notify.error = (notification: Notification, options?: ExternalToast) => {
return notify(
{
icon: <InformationFillDuotoneIcon color={cssVar('errorColor')} />,
icon: <InformationFillDuotoneIcon />,
style: 'normal',
theme: 'error',
...notification,
Expand All @@ -73,7 +72,7 @@ notify.error = (notification: Notification, options?: ExternalToast) => {
notify.success = (notification: Notification, options?: ExternalToast) => {
return notify(
{
icon: <SingleSelectSelectSolidIcon color={cssVar('successColor')} />,
icon: <SingleSelectSelectSolidIcon />,
style: 'normal',
theme: 'success',
...notification,
Expand All @@ -85,7 +84,7 @@ notify.success = (notification: Notification, options?: ExternalToast) => {
notify.warning = (notification: Notification, options?: ExternalToast) => {
return notify(
{
icon: <InformationFillDuotoneIcon color={cssVar('warningColor')} />,
icon: <InformationFillDuotoneIcon />,
style: 'normal',
theme: 'warning',
...notification,
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend/component/src/ui/notification/styles.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const cardColor = createVar();
export const cardForeground = createVar();
export const cardBorderColor = createVar();
export const actionTextColor = createVar();
export const iconColor = createVar();

export const card = style({
borderRadius: 8,
Expand Down Expand Up @@ -38,6 +39,7 @@ export const icon = style({
globalStyle(`${icon} svg`, {
width: '100%',
height: '100%',
color: iconColor,
});
export const title = style({
width: 0,
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/component/src/ui/notification/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface Notification {
title?: ReactNode;
message?: ReactNode;
icon?: ReactNode;
iconColor?: string;
footer?: ReactNode;

// events
Expand Down
18 changes: 18 additions & 0 deletions packages/frontend/component/src/ui/notification/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,21 @@ export const getCardBorderColor = (style: NotificationStyle) => {
export const getCardForegroundColor = (style: NotificationStyle) => {
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');
};
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export const AIOnboardingEdgeless = ({
{
title: t['com.affine.ai-onboarding.edgeless.title'](),
message: t['com.affine.ai-onboarding.edgeless.message'](),
icon: <AiIcon color={cssVar('processingColor')} />,
icon: <AiIcon />,
iconColor: cssVar('brandColor'),
thumb: <EdgelessOnboardingAnimation />,
alignMessage: 'icon',
onDismiss,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ export const AIResume = ({
setIdempotencyKey(nanoid());
onSubscriptionUpdate?.(data.resumeSubscription);
notify({
icon: (
<SingleSelectSelectSolidIcon
color={cssVar('processingColor')}
/>
),
icon: <SingleSelectSelectSolidIcon />,
iconColor: cssVar('processingColor'),
title:
t[
'com.affine.payment.ai.action.resume.confirm.notify.title'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,8 @@ const Settings = () => {
onNotify={({ detail, recurring }) => {
notify({
style: 'normal',
icon: (
<SingleSelectSelectSolidIcon color={cssVar('primaryColor')} />
),
icon: <SingleSelectSelectSolidIcon />,
iconColor: cssVar('primaryColor'),
title: t['com.affine.payment.updated-notify-title'](),
message:
detail.plan === SubscriptionPlan.Free
Expand Down

0 comments on commit d1169da

Please sign in to comment.