Skip to content

Commit

Permalink
Merge pull request #247 from heorhi-deriv/FEQ-2641-Implement-Section-…
Browse files Browse the repository at this point in the history
…Message-Component

[FEQ] george / FEQ-2641 / Implement Section Message Component
  • Loading branch information
shayan-deriv authored Sep 10, 2024
2 parents 0a09fdd + 40fbb4f commit 2fb8416
Show file tree
Hide file tree
Showing 7 changed files with 336 additions and 14 deletions.
15 changes: 5 additions & 10 deletions src/components/Badge/Badge.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ $white_color: linear-gradient(#e6e9e9, #f2f3f4);
$success_color: $gradient-color-blue-5;
$warning_color: $gradient-color-yellow;
$danger_color: var(--du-badge-danger, #ec3f3f);
$blue_color: var(--du-badge-blue, #115BFF);
$purple_color: var(--du-badge-purple, #722FE4);
$light_blue_color: var(--du-badge-light-blue, #0DC2E7);
$blue_color: var(--du-badge-blue, #115bff);
$purple_color: var(--du-badge-purple, #722fe4);
$light_blue_color: var(--du-badge-light-blue, #0dc2e7);
$gold_color: $gradient-color-gold;
$gold_color_border: $color_yellow;
$green_color: $gradient-color-green-4;
Expand Down Expand Up @@ -168,7 +168,7 @@ $green_color_border: $color-green-6;
}

&--bordered {
border-style: solid;
border: solid 1px;
background: none;

&.deriv-badge__color--general {
Expand Down Expand Up @@ -242,7 +242,6 @@ $green_color_border: $color-green-6;
color: $font-color-gray;
}
}

}

&--bold-text {
Expand All @@ -265,10 +264,8 @@ $green_color_border: $color-green-6;
border-radius: 24px;
}
}

}


@include desktop {
.deriv-badge {
display: inline-flex;
Expand Down Expand Up @@ -424,7 +421,7 @@ $green_color_border: $color-green-6;
}

&--bordered {
border-style: solid;
border: solid 1px;
background: none;

&.deriv-badge__color--general {
Expand Down Expand Up @@ -498,7 +495,6 @@ $green_color_border: $color-green-6;
color: $font-color-gray;
}
}

}

&--bold-text {
Expand All @@ -521,6 +517,5 @@ $green_color_border: $color-green-6;
border-radius: 24px;
}
}

}
}
72 changes: 72 additions & 0 deletions src/components/SectionMessage/SectionMessage.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
$error-bgColor: $color-status-error-1;
$error-icColor: $color-red-11;
$warning-bgColor: $color-status-warning-1;
$warning-icColor: $color-yellow-4;
$success-bgColor: $color-status-success;
$success-icColor: $color-green-9;
$info-bgColor: $color-status-information-1;
$info-icColor: $color-blue-11;
$description-color: $alpha-color-black-8;
$general-color: $color-gray-2;

.deriv-section-message {
width: 100%;
display: inline-flex;
align-items: center;
column-gap: 8px;
border-radius: 16px;
padding: 16px;

&__title {
margin-bottom: 8px;
}

&__description {
color: $description-color;
}

&__cta-section {
margin-top: 16px;
}

&__icon {
display: flex;
align-self: flex-start;

&--info {
fill: $info-icColor;
}

&--success {
fill: $success-icColor;
}

&--warning {
fill: $warning-icColor;
}

&--error {
fill: $error-icColor;
}
}

&--info {
background-color: $info-bgColor;
}

&--success {
background-color: $success-bgColor;
}

&--warning {
background-color: $warning-bgColor;
}

&--error {
background-color: $error-bgColor;
}

&--general {
background-color: $general-color;
}
}
59 changes: 59 additions & 0 deletions src/components/SectionMessage/__test__/SectionMessage.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from "react";
import { render } from "@testing-library/react";
import { SectionMessage } from "..";

describe("SectionMessage Component", () => {
it("renders with all props", () => {
const ctaSection = <button type="button">Click me</button>;
const { getByText, getByRole } = render(
<SectionMessage title="Title" ctaSection={ctaSection}>
Warning Message
</SectionMessage>,
);
expect(getByText("Warning Message")).toBeInTheDocument();
expect(getByText("Title")).toBeInTheDocument();
expect(getByRole("button", { name: "Click me" })).toBeInTheDocument();
});

it("renders with specified variant", () => {
const { container } = render(
<SectionMessage variant="error">Error Message</SectionMessage>,
);
expect(container.firstChild).toHaveClass(
"deriv-section-message--error",
);
});

it("renders with predefined error icon", () => {
const { container } = render(
<SectionMessage variant="error">Message with Icon</SectionMessage>,
);
expect(
container.querySelector(".deriv-section-message__icon"),
).toBeInTheDocument();
expect(
container.querySelector(".deriv-section-message__icon--error"),
).toBeInTheDocument();
});

it("renders with custom icon", () => {
const Img = <img src="" alt="icon" />;

const { container, getByAltText } = render(
<SectionMessage icon={Img}>Message with Icon</SectionMessage>,
);
expect(getByAltText("icon")).toBeInTheDocument();
expect(
container.querySelector(".deriv-section-message__icon"),
).toBeInTheDocument();
});

it("renders with custom class name", () => {
const { container } = render(
<SectionMessage className="custom-class">
Custom Message
</SectionMessage>,
);
expect(container.firstChild).toHaveClass("custom-class");
});
});
96 changes: 96 additions & 0 deletions src/components/SectionMessage/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import React from "react";
import {
LabelPairedCircleCheckMdBoldIcon,
LabelPairedCircleExclamationMdBoldIcon,
LabelPairedCircleInfoMdBoldIcon,
LabelPairedTriangleExclamationMdBoldIcon,
IconTypes,
} from "@deriv/quill-icons";
import clsx from "clsx";
import { Text } from "../Text";
import "./SectionMessage.scss";

type TVariant = "warning" | "info" | "success" | "error" | "general";

type SectionMessageProps = {
children: JSX.Element | string;
className?: string;
ctaSection?: JSX.Element;
icon?: JSX.Element;
title?: JSX.Element | string;
variant?: TVariant;
};

const VariantIcons: Record<Exclude<TVariant, "general">, IconTypes> = {
error: LabelPairedTriangleExclamationMdBoldIcon,
info: LabelPairedCircleInfoMdBoldIcon,
success: LabelPairedCircleCheckMdBoldIcon,
warning: LabelPairedCircleExclamationMdBoldIcon,
};

/**
* `SectionMessage` is a React component designed to display a styled section message.
* It includes an optional icon, title, description, and call-to-action (CTA) section.
*
* @component
* @param {Object} props - Component props.
* @param {JSX.Element|string} props.children - The main content or message of the section.
* @param {string} [props.className] - Optional additional class names for styling.
* @param {JSX.Element} [props.ctaSection] - Optional CTA section element, such as a button / button group or link.
* @param {JSX.Element} [props.icon] - Optional icon element.
* @param {JSX.Element|string} [props.title] - Optional title element or string to summarize the message.
* @param {TVariant} [props.variant="general"] - Optional variant to style the section with different themes: "warning", "info", "success", "error", or "general".
*/
export const SectionMessage = ({
children,
className,
ctaSection,
icon,
title,
variant = "general",
}: SectionMessageProps) => {
const IconComponent = variant !== "general" && VariantIcons[variant];

return (
<div
className={clsx(
"deriv-section-message",
`deriv-section-message--${variant}`,
className,
)}
>
{(icon || IconComponent) && (
<div className="deriv-section-message__icon">
{IconComponent ? (
<IconComponent
className={`deriv-section-message__icon--${variant}`}
/>
) : (
icon
)}
</div>
)}
<div className="deriv-section-message__content">
{title && (
<Text
as="div"
align="start"
size="md"
weight="bold"
className="deriv-section-message__title"
>
{title}
</Text>
)}
<div className="deriv-section-message__description">
{children}
</div>
{ctaSection && (
<div className="deriv-section-message__cta-section">
{ctaSection}
</div>
)}
</div>
</div>
);
};
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export { Loader } from "./components/Loader";
export { Modal } from "./components/Modal";
export { PageLayout } from "./components/PageLayout";
export { PasswordInput } from "./components/PasswordInput";
export { SectionMessage } from "./components/SectionMessage";
export { SideNote } from "./components/SideNote";
export { Tab, Tabs } from "./components/Tabs";
export { Table } from "./components/Table";
Expand Down
17 changes: 13 additions & 4 deletions src/styles/abstracts/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ $color-blue-5: #dfeaff;
$color-blue-6: #92b8ff;
$color-blue-7: #182130;
$color-blue-8: #e6f5ff;
$color-blue-9:#00C6EF;
$color-blue-10:#115BFF;
$color-blue-9: #00c6ef;
$color-blue-10: #115bff;
$color-blue-11: #0777c4;
$color-brown: #664407;
$color-green: #85acb0;
$color-green-1: #4bb4b3;
Expand All @@ -80,6 +81,7 @@ $color-green-5: #4bb4b329;
$color-green-6: #17eabd;
$color-green-7: #e8fdf8;
$color-green-8: #cedddf;
$color-green-9: #007a22;
$color-gray: #c2c2c2;
$color-gray-1: #999999;
$color-gray-2: #f2f3f4;
Expand All @@ -95,9 +97,9 @@ $color-gray-11: #fafafa;
$color-gray-12: #f5f7fa;
$color-gray-13: #2e2e2e;
$color-orange: #ff6444;
$color-orange-1:#ff9c13;
$color-orange-1: #ff9c13;
$color-purple: #722fe4;
$color-purple-1:#8F4BFF;
$color-purple-1: #8f4bff;
$color-red: #ff444f;
$color-red-1: #ec3f3f;
$color-red-2: #cc2e3d;
Expand All @@ -110,18 +112,24 @@ $color-red-8: #661b20;
$color-red-9: #b33037;
$color-red-10: #ff444f;
$color-red-11: #fce3e3;
$color-red-11: #c40000;
$color-violet: #4a3871;
$color-white: #ffffff;
$color-yellow: #ffad3a;
$color-yellow-1: #b3760d;
$color-yellow-2: #ffa912;
$color-yellow-3: rgba(255, 173, 58, 0.16);
$color-yellow-4: #c47d00;

/* STATUS COLORS */
$color-status-warning: rgba(255, 173, 58, 0.16);
$color-status-warning-1: rgba(255, 156, 19, 0.08);
$color-status-information: rgba(55, 124, 252, 0.16);
$color-status-information-1: rgba(44, 154, 255, 0.08);
$color-status-announcement: rgba(75, 180, 179, 0.16);
$color-status-success: rgba(0, 136, 50, 0.08);
$color-status-error: rgba(236, 63, 63, 0.16);
$color-status-error-1: rgba(230, 25, 14, 0.08);

/* ALPHA COLORS */
$alpha-color-black-1: transparentize($color-black-7, 0.28);
Expand All @@ -131,6 +139,7 @@ $alpha-color-black-4: transparentize($color-black-7, 0.84);
$alpha-color-black-5: transparentize($color-black-7, 0.16);
$alpha-color-black-6: transparentize($color-black-7, 0.36);
$alpha-color-black-7: transparentize($color-black, 0.5);
$alpha-color-black-8: transparentize($color-black-7, 0.72);
$alpha-color-blue-1: transparentize($color-blue, 0.84);
$alpha-color-blue-2: transparentize($color-blue-3, 0.84);
$alpha-color-blue-3: transparentize($color-blue, 0.92);
Expand Down
Loading

0 comments on commit 2fb8416

Please sign in to comment.