Use transient props for Alert component

This commit is contained in:
Koen Vlaswinkel
2023-11-02 14:05:11 +01:00
parent eaf3a1ce1b
commit 8e8399988e

View File

@@ -3,16 +3,16 @@ import { ReactNode } from "react";
import { styled } from "styled-components";
type ContainerProps = {
type: "warning" | "error";
inverse?: boolean;
$type: "warning" | "error";
$inverse?: boolean;
};
const getBackgroundColor = ({ type, inverse }: ContainerProps): string => {
if (!inverse) {
const getBackgroundColor = ({ $type, $inverse }: ContainerProps): string => {
if (!$inverse) {
return "var(--vscode-notifications-background)";
}
switch (type) {
switch ($type) {
case "warning":
return "var(--vscode-editorWarning-foreground)";
case "error":
@@ -20,12 +20,12 @@ const getBackgroundColor = ({ type, inverse }: ContainerProps): string => {
}
};
const getTextColor = ({ type, inverse }: ContainerProps): string => {
if (!inverse) {
const getTextColor = ({ $type, $inverse }: ContainerProps): string => {
if (!$inverse) {
return "var(--vscode-editor-foreground)";
}
switch (type) {
switch ($type) {
case "warning":
return "var(--vscode-editor-background)";
case "error":
@@ -33,8 +33,8 @@ const getTextColor = ({ type, inverse }: ContainerProps): string => {
}
};
const getBorderColor = ({ type }: ContainerProps): string => {
switch (type) {
const getBorderColor = ({ $type }: ContainerProps): string => {
switch ($type) {
case "warning":
return "var(--vscode-editorWarning-foreground)";
case "error":
@@ -42,7 +42,7 @@ const getBorderColor = ({ type }: ContainerProps): string => {
}
};
const getTypeText = (type: ContainerProps["type"]): string => {
const getTypeText = (type: ContainerProps["$type"]): string => {
switch (type) {
case "warning":
return "Warning";
@@ -108,7 +108,7 @@ export const Alert = ({
role,
}: Props) => {
return (
<Container type={type} inverse={inverse} role={role}>
<Container $type={type} $inverse={inverse} role={role}>
<Title>
{getTypeText(type)}: {title}
</Title>