Equicord/src/components/Notice.tsx
prism 89f93e245e
Components: add plugin (dev) (#585)
* Components: add plugin (dev)

* fix: rename alert component to notice and some fixes
2025-12-20 22:01:32 -05:00

72 lines
2.4 KiB
TypeScript

/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { filters, mapMangledModuleLazy } from "@webpack";
import type { ComponentType, CSSProperties, ReactNode } from "react";
export type NoticeType = "warn" | "info" | "danger" | "positive" | "preview";
export const NoticeTypes: Record<"WARNING" | "INFO" | "ERROR" | "POSITIVE" | "PREVIEW", NoticeType> = {
WARNING: "warn",
INFO: "info",
ERROR: "danger",
POSITIVE: "positive",
PREVIEW: "preview"
};
const { HelpMessage } = mapMangledModuleLazy('POSITIVE="positive"', {
HelpMessage: filters.byCode(".iconDiv")
});
export interface NoticeProps {
children: ReactNode;
className?: string;
style?: CSSProperties;
icon?: ComponentType<{ className?: string; color?: string; }>;
action?: ReactNode;
textColor?: string;
textVariant?: string;
hidden?: boolean;
}
function Warning({ children, className, style, icon, action, textColor, textVariant, hidden }: NoticeProps) {
return (
<HelpMessage messageType={NoticeTypes.WARNING} className={className} style={style} icon={icon} action={action} textColor={textColor} textVariant={textVariant} hidden={hidden}>
{children}
</HelpMessage>
);
}
function Info({ children, className, style, icon, action, textColor, textVariant, hidden }: NoticeProps) {
return (
<HelpMessage messageType={NoticeTypes.INFO} className={className} style={style} icon={icon} action={action} textColor={textColor} textVariant={textVariant} hidden={hidden}>
{children}
</HelpMessage>
);
}
function Error({ children, className, style, icon, action, textColor, textVariant, hidden }: NoticeProps) {
return (
<HelpMessage messageType={NoticeTypes.ERROR} className={className} style={style} icon={icon} action={action} textColor={textColor} textVariant={textVariant} hidden={hidden}>
{children}
</HelpMessage>
);
}
function Positive({ children, className, style, icon, action, textColor, textVariant, hidden }: NoticeProps) {
return (
<HelpMessage messageType={NoticeTypes.POSITIVE} className={className} style={style} icon={icon} action={action} textColor={textColor} textVariant={textVariant} hidden={hidden}>
{children}
</HelpMessage>
);
}
export const Notice = {
Warning,
Info,
Error,
Positive
};