mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-11 06:29:04 +00:00
fix: alert component styles
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
import { faTriangleExclamation } from "@fortawesome/free-solid-svg-icons";
|
import { faPlus } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import type { Meta, StoryObj } from "@storybook/react";
|
import type { Meta, StoryObj } from "@storybook/react";
|
||||||
|
|
||||||
import { Alert, AlertDescription, AlertTitle } from "./Alert";
|
import { Alert, AlertDescription } from "./Alert";
|
||||||
|
|
||||||
const meta: Meta<typeof Alert> = {
|
const meta: Meta<typeof Alert> = {
|
||||||
title: "Components/Alert",
|
title: "Components/Alert",
|
||||||
@@ -14,12 +14,7 @@ export default meta;
|
|||||||
|
|
||||||
type Story = StoryObj<typeof Alert>;
|
type Story = StoryObj<typeof Alert>;
|
||||||
|
|
||||||
const ExampleComponent = () => (
|
const ExampleComponent = () => <AlertDescription>this is a description</AlertDescription>;
|
||||||
<>
|
|
||||||
<AlertTitle>this is a title</AlertTitle>
|
|
||||||
<AlertDescription>this is a description</AlertDescription>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
export const Default: Story = {
|
export const Default: Story = {
|
||||||
args: {
|
args: {
|
||||||
@@ -41,14 +36,26 @@ export const Destructive: Story = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const WithIcon: Story = {
|
export const WithCustomIcon: Story = {
|
||||||
args: {
|
args: {
|
||||||
children: (
|
children: <ExampleComponent />,
|
||||||
<>
|
variant: "warning",
|
||||||
<FontAwesomeIcon icon={faTriangleExclamation} />
|
icon: <FontAwesomeIcon icon={faPlus} />
|
||||||
<ExampleComponent />
|
}
|
||||||
</>
|
};
|
||||||
),
|
|
||||||
variant: "warning"
|
export const WithOutIcon: Story = {
|
||||||
|
args: {
|
||||||
|
children: <ExampleComponent />,
|
||||||
|
variant: "warning",
|
||||||
|
icon: null
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const WithOutTitle: Story = {
|
||||||
|
args: {
|
||||||
|
children: <ExampleComponent />,
|
||||||
|
variant: "warning",
|
||||||
|
hideTitle: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
|
/* eslint-disable react/prop-types */
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
|
import {
|
||||||
|
faExclamationCircle,
|
||||||
|
faExclamationTriangle,
|
||||||
|
faInfoCircle
|
||||||
|
} from "@fortawesome/free-solid-svg-icons";
|
||||||
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { type VariantProps, cva } from "cva";
|
import { type VariantProps, cva } from "cva";
|
||||||
|
import { twMerge } from "tailwind-merge";
|
||||||
import { cn } from "@app/helpers/classNames";
|
|
||||||
|
|
||||||
const alertVariants = cva(
|
const alertVariants = cva(
|
||||||
"relative w-full bg-mineshaft-800 rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7",
|
"w-full bg-mineshaft-800 rounded-lg border px-4 py-3 text-sm flex items-center gap-x-4",
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
@@ -19,33 +25,62 @@ const alertVariants = cva(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
type AlertProps = {
|
||||||
|
title?: string;
|
||||||
|
hideTitle?: boolean;
|
||||||
|
icon?: React.ReactNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
const variantTitleMap = {
|
||||||
|
default: "Info",
|
||||||
|
destructive: "Danger",
|
||||||
|
warning: "Warning"
|
||||||
|
};
|
||||||
|
|
||||||
|
const variantIconMap = {
|
||||||
|
default: faInfoCircle,
|
||||||
|
destructive: faExclamationCircle,
|
||||||
|
warning: faExclamationTriangle
|
||||||
|
};
|
||||||
|
|
||||||
const Alert = React.forwardRef<
|
const Alert = React.forwardRef<
|
||||||
HTMLDivElement,
|
HTMLDivElement,
|
||||||
React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>
|
React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants> & AlertProps
|
||||||
>(({ className, variant, ...props }, ref) => (
|
>(({ className, variant, title, icon, hideTitle = false, children, ...props }, ref) => {
|
||||||
<div ref={ref} role="alert" className={cn(alertVariants({ variant }), className)} {...props} />
|
const defaultTitle = title ?? variantTitleMap[variant ?? "default"];
|
||||||
));
|
return (
|
||||||
Alert.displayName = "Alert";
|
<div
|
||||||
|
|
||||||
const AlertTitle = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLHeadingElement>>(
|
|
||||||
({ className, children, ...props }, ref) => (
|
|
||||||
<h5
|
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn("mb-1 font-medium leading-none tracking-tight", className)}
|
role="alert"
|
||||||
|
className={twMerge(alertVariants({ variant }), className)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{children}
|
<div>
|
||||||
</h5>
|
{typeof icon !== "undefined" ? (
|
||||||
)
|
<>{icon} </>
|
||||||
);
|
) : (
|
||||||
AlertTitle.displayName = "AlertTitle";
|
<FontAwesomeIcon className="text-lg" icon={variantIconMap[variant ?? "default"]} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-y-1">
|
||||||
|
{hideTitle ? null : (
|
||||||
|
<h5 className="font-medium leading-none tracking-tight" {...props}>
|
||||||
|
{defaultTitle}
|
||||||
|
</h5>
|
||||||
|
)}
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
Alert.displayName = "Alert";
|
||||||
|
|
||||||
const AlertDescription = React.forwardRef<
|
const AlertDescription = React.forwardRef<
|
||||||
HTMLParagraphElement,
|
HTMLParagraphElement,
|
||||||
React.HTMLAttributes<HTMLParagraphElement>
|
React.HTMLAttributes<HTMLParagraphElement>
|
||||||
>(({ className, ...props }, ref) => (
|
>(({ className, ...props }, ref) => (
|
||||||
<div ref={ref} className={cn("text-sm [&_p]:leading-relaxed", className)} {...props} />
|
<div ref={ref} className={twMerge("text-sm [&_p]:leading-relaxed", className)} {...props} />
|
||||||
));
|
));
|
||||||
AlertDescription.displayName = "AlertDescription";
|
AlertDescription.displayName = "AlertDescription";
|
||||||
|
|
||||||
export { Alert, AlertDescription, AlertTitle };
|
export { Alert, AlertDescription };
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
export { Alert, AlertDescription, AlertTitle } from "./Alert";
|
export { Alert, AlertDescription } from "./Alert";
|
||||||
|
|||||||
+2
-3
@@ -1,5 +1,5 @@
|
|||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { faArrowRight, faExclamationTriangle, faXmark } from "@fortawesome/free-solid-svg-icons";
|
import { faArrowRight, faXmark } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
import { integrationSlugNameMapping } from "public/data/frequentConstants";
|
import { integrationSlugNameMapping } from "public/data/frequentConstants";
|
||||||
|
|
||||||
@@ -55,8 +55,7 @@ export const IntegrationsSection = ({
|
|||||||
|
|
||||||
{!bot?.isActive && (
|
{!bot?.isActive && (
|
||||||
<div className="px-6 py-4">
|
<div className="px-6 py-4">
|
||||||
<Alert variant="warning">
|
<Alert hideTitle variant="warning">
|
||||||
<FontAwesomeIcon icon={faExclamationTriangle} />
|
|
||||||
<AlertDescription>
|
<AlertDescription>
|
||||||
All the active integrations will be disabled. Disable End-to-End Encryption in{" "}
|
All the active integrations will be disabled. Disable End-to-End Encryption in{" "}
|
||||||
<Link href={`/project/${currentWorkspace?._id}/settings`} passHref>
|
<Link href={`/project/${currentWorkspace?._id}/settings`} passHref>
|
||||||
|
|||||||
+1
-6
@@ -1,12 +1,9 @@
|
|||||||
import { faExclamationTriangle } from "@fortawesome/free-solid-svg-icons";
|
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
||||||
|
|
||||||
import { ProjectPermissionCan } from "@app/components/permissions";
|
import { ProjectPermissionCan } from "@app/components/permissions";
|
||||||
import {
|
import {
|
||||||
decryptAssymmetric,
|
decryptAssymmetric,
|
||||||
encryptAssymmetric
|
encryptAssymmetric
|
||||||
} from "@app/components/utilities/cryptography/crypto";
|
} from "@app/components/utilities/cryptography/crypto";
|
||||||
import { Alert, AlertDescription, AlertTitle, Checkbox } from "@app/components/v2";
|
import { Alert, AlertDescription, Checkbox } from "@app/components/v2";
|
||||||
import { ProjectPermissionActions, ProjectPermissionSub, useWorkspace } from "@app/context";
|
import { ProjectPermissionActions, ProjectPermissionSub, useWorkspace } from "@app/context";
|
||||||
import { useGetUserWsKey, useGetWorkspaceBot, useUpdateBotActiveStatus } from "@app/hooks/api";
|
import { useGetUserWsKey, useGetWorkspaceBot, useUpdateBotActiveStatus } from "@app/hooks/api";
|
||||||
|
|
||||||
@@ -107,8 +104,6 @@ export const E2EESection = () => {
|
|||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Alert variant="warning">
|
<Alert variant="warning">
|
||||||
<FontAwesomeIcon icon={faExclamationTriangle} />
|
|
||||||
<AlertTitle>Warning !</AlertTitle>
|
|
||||||
<AlertDescription>
|
<AlertDescription>
|
||||||
Enabling End-to-end encryption disables all the integrations
|
Enabling End-to-end encryption disables all the integrations
|
||||||
</AlertDescription>
|
</AlertDescription>
|
||||||
|
|||||||
Reference in New Issue
Block a user