From b539658fbf830d97628a9015ec9ad5e52e71f456 Mon Sep 17 00:00:00 2001 From: aizad-deriv Date: Fri, 2 Feb 2024 14:52:12 +0800 Subject: [PATCH 1/4] fix: added Inline Message Component --- .../InlineMessage/InlineMessage.scss | 68 +++++++++++++++++++ lib/components/InlineMessage/VariantIcons.tsx | 58 ++++++++++++++++ lib/components/InlineMessage/index.tsx | 64 +++++++++++++++++ lib/main.ts | 1 + 4 files changed, 191 insertions(+) create mode 100644 lib/components/InlineMessage/InlineMessage.scss create mode 100644 lib/components/InlineMessage/VariantIcons.tsx create mode 100644 lib/components/InlineMessage/index.tsx diff --git a/lib/components/InlineMessage/InlineMessage.scss b/lib/components/InlineMessage/InlineMessage.scss new file mode 100644 index 00000000..a70ab384 --- /dev/null +++ b/lib/components/InlineMessage/InlineMessage.scss @@ -0,0 +1,68 @@ +$error-borderColor: #ec3f3f; +$warning-borderColor: #ffad3a; +$success-borderColor: #4bb4b3; +$info-borderColor: #377cfc; +$error-bgColor: rgba(236, 63, 63, 0.16); +$warning-bgColor: rgba(255, 173, 58, 0.16); +$success-bgColor: rgba(75, 180, 179, 0.16); +$info-bgColor: rgba(55, 124, 252, 0.16); +$general-color: #f2f3f4; +$border: 1px solid; + +.deriv-inline-message { + width: 100%; + position: relative; + display: inline-flex; + align-items: center; + gap: 8px; + border-radius: 4px; + padding: 16px; + + &__info { + &--filled { + border: none; + background-color: $info-bgColor; + } + &--outlined { + border: $border $info-borderColor; + background-color: transparent; + } + } + + &__success { + &--filled { + border: none; + background-color: $success-bgColor; + } + &--outlined { + border: $border $success-borderColor; + background-color: transparent; + } + } + + &__warning { + &--filled { + border: none; + background-color: $warning-bgColor; + } + &--outlined { + border: $border $warning-borderColor; + background-color: transparent; + } + } + + &__error { + &--filled { + border: none; + background-color: $error-bgColor; + } + &--outlined { + border: $border $error-borderColor; + background-color: transparent; + } + } + + &__general { + background-color: $general-color; + } +} diff --git a/lib/components/InlineMessage/VariantIcons.tsx b/lib/components/InlineMessage/VariantIcons.tsx new file mode 100644 index 00000000..ba747768 --- /dev/null +++ b/lib/components/InlineMessage/VariantIcons.tsx @@ -0,0 +1,58 @@ +export const ErrorIcon = () => ( + + + + + + + + + + +); + +export const InfoIcon = () => ( + + + + + + + + + +); + +export const SuccessIcon = () => ( + + + + +); + +export const WarningIcon = () => ( + + + +); diff --git a/lib/components/InlineMessage/index.tsx b/lib/components/InlineMessage/index.tsx new file mode 100644 index 00000000..f3663a60 --- /dev/null +++ b/lib/components/InlineMessage/index.tsx @@ -0,0 +1,64 @@ +import React, { ReactNode } from "react"; +import clsx from "clsx"; +import { ErrorIcon, InfoIcon, SuccessIcon, WarningIcon } from "./VariantIcons"; +import "./InlineMessage.scss"; + +type TVariant = "warning" | "info" | "success" | "error" | "general"; + +type InlineMessageProps = { + children: ReactNode; + className?: string; + icon?: JSX.Element; + variant?: TVariant; + type?: "outlined" | "filled"; +}; + +const VariantIcons: Record, JSX.Element> = { + error: , + info: , + success: , + warning: , +}; + +const VariantClasses = { + error: { + filled: "deriv-inline-message__error--filled", + outlined: "deriv-inline-message__error--outlined", + }, + general: "deriv-inline-message__general", + info: { + filled: "deriv-inline-message__info--filled", + outlined: "deriv-inline-message__info--outlined", + }, + success: { + filled: "deriv-inline-message__success--filled", + outlined: "deriv-inline-message__success--outlined", + }, + warning: { + filled: "deriv-inline-message__warning--filled", + outlined: "deriv-inline-message__warning--outlined", + }, +}; + +export const InlineMessage = ({ + icon, + children, + className, + variant = "general", + type = "filled", +}: InlineMessageProps) => { + return ( +
+ {variant !== "general" ? VariantIcons[variant] : icon ?? null} + {children} +
+ ); +}; diff --git a/lib/main.ts b/lib/main.ts index 7818aaff..676ea882 100644 --- a/lib/main.ts +++ b/lib/main.ts @@ -10,3 +10,4 @@ export { Tooltip } from "./components/Tooltip"; export { useDevice } from "./hooks/useDevice"; export { useOnClickOutside } from "./hooks/useOnClickOutside"; export { PasswordInput } from "./components/PasswordInput"; +export { InlineMessage } from "./components/InlineMessage"; From 8dd77a270bc42fbe03d5ad82abc7dc58eb3a8bb1 Mon Sep 17 00:00:00 2001 From: aizad-deriv Date: Fri, 2 Feb 2024 15:17:53 +0800 Subject: [PATCH 2/4] fix: added storybook for Inline Message --- lib/components/InlineMessage/index.tsx | 30 +++---- src/stories/InlineMessage.stories.ts | 116 +++++++++++++++++++++++++ 2 files changed, 130 insertions(+), 16 deletions(-) create mode 100644 src/stories/InlineMessage.stories.ts diff --git a/lib/components/InlineMessage/index.tsx b/lib/components/InlineMessage/index.tsx index f3663a60..229f39a3 100644 --- a/lib/components/InlineMessage/index.tsx +++ b/lib/components/InlineMessage/index.tsx @@ -46,19 +46,17 @@ export const InlineMessage = ({ className, variant = "general", type = "filled", -}: InlineMessageProps) => { - return ( -
- {variant !== "general" ? VariantIcons[variant] : icon ?? null} - {children} -
- ); -}; +}: InlineMessageProps) => ( +
+ {variant !== "general" ? VariantIcons[variant] : icon ?? null} + {children} +
+); diff --git a/src/stories/InlineMessage.stories.ts b/src/stories/InlineMessage.stories.ts new file mode 100644 index 00000000..bc7c9117 --- /dev/null +++ b/src/stories/InlineMessage.stories.ts @@ -0,0 +1,116 @@ +import { StoryObj, Meta } from "@storybook/react"; +import { InlineMessage } from "../../lib/main"; + +const meta = { + title: "Components/InlineMessage", + component: InlineMessage, + parameters: { layout: "centered" }, + tags: ["autodocs"], + argTypes: { + children: { + control: { + type: "text", + }, + }, + icon: { + disable: true, + }, + className: { + disable: true, + }, + variant: { + control: { + type: "select", + }, + defaultValue: "general", + options: ["warning", "info", "success", "error", "general"], + }, + type: { + control: { + type: "select", + }, + defaultValue: "filled", + options: ["outlined", "filled"], + }, + }, +} satisfies Meta; + +export default meta; +type Story = StoryObj; + +export const Default: Story = { + name: "Default Inline Message", + args: { + variant: "general", + type: "outlined", + children: "This is a default inline message", + }, +}; + +export const WarningFilled: Story = { + name: "Warning filled Inline Message", + args: { + variant: "warning", + children: "This is a default inline message", + }, +}; + +export const WarningOutlined: Story = { + name: "Warning outlined Inline Message", + args: { + variant: "warning", + type: "outlined", + children: "This is a default inline message", + }, +}; + +export const InfoFilled: Story = { + name: "Info filled Inline Message", + args: { + variant: "info", + children: "This is a default inline message", + }, +}; + +export const InfoOutlined: Story = { + name: "Info outlined Inline Message", + args: { + variant: "info", + type: "outlined", + children: "This is a default inline message", + }, +}; + +export const SuccessFilled: Story = { + name: "Success filled Inline Message", + args: { + variant: "success", + children: "This is a default inline message", + }, +}; + +export const SuccessOutlined: Story = { + name: "Success outlined Inline Message", + args: { + variant: "success", + type: "outlined", + children: "This is a default inline message", + }, +}; + +export const ErrorFilled: Story = { + name: "Error filled Inline Message", + args: { + variant: "error", + children: "This is a default inline message", + }, +}; + +export const ErrorOutlined: Story = { + name: "Error outlined Inline Message", + args: { + variant: "error", + type: "outlined", + children: "This is a default inline message", + }, +}; From fce70abdb4132b4caeabe5787d69ef1ff5b65bde Mon Sep 17 00:00:00 2001 From: aizad-deriv Date: Fri, 2 Feb 2024 15:41:49 +0800 Subject: [PATCH 3/4] chore added classname for icon --- lib/components/InlineMessage/InlineMessage.scss | 5 +++++ lib/components/InlineMessage/index.tsx | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/components/InlineMessage/InlineMessage.scss b/lib/components/InlineMessage/InlineMessage.scss index a70ab384..2457b074 100644 --- a/lib/components/InlineMessage/InlineMessage.scss +++ b/lib/components/InlineMessage/InlineMessage.scss @@ -18,6 +18,11 @@ $border: 1px solid; border-radius: 4px; padding: 16px; + &__icon { + width: 16px; + height: 16px; + } + &__info { &--filled { border: none; diff --git a/lib/components/InlineMessage/index.tsx b/lib/components/InlineMessage/index.tsx index 229f39a3..96006ca5 100644 --- a/lib/components/InlineMessage/index.tsx +++ b/lib/components/InlineMessage/index.tsx @@ -56,7 +56,11 @@ export const InlineMessage = ({ className )} > - {variant !== "general" ? VariantIcons[variant] : icon ?? null} + {(variant !== "general" || icon) && ( +
+ {variant !== "general" ? VariantIcons[variant] : icon ?? null} +
+ )} {children} ); From 49504af1cf64e80d510a9680daba880323031339 Mon Sep 17 00:00:00 2001 From: aizad-deriv Date: Fri, 2 Feb 2024 16:22:11 +0800 Subject: [PATCH 4/4] fix: padding inside of inline message --- lib/components/InlineMessage/InlineMessage.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/components/InlineMessage/InlineMessage.scss b/lib/components/InlineMessage/InlineMessage.scss index 2457b074..1e7c387d 100644 --- a/lib/components/InlineMessage/InlineMessage.scss +++ b/lib/components/InlineMessage/InlineMessage.scss @@ -16,7 +16,7 @@ $border: 1px solid; align-items: center; gap: 8px; border-radius: 4px; - padding: 16px; + padding: 8px; &__icon { width: 16px;