Skip to content

Commit

Permalink
fix(Alert): adjust styles when closable is true and inlineActions is set
Browse files Browse the repository at this point in the history
  • Loading branch information
sarkaaa committed Aug 7, 2024
1 parent 8718b59 commit 2a9e765
Show file tree
Hide file tree
Showing 27 changed files with 122 additions and 5 deletions.
99 changes: 98 additions & 1 deletion packages/orbit-components/src/Alert/Alert.ct-story.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import * as React from "react";

import * as Icons from "../icons";
import TextLink from "../TextLink";
import type { Type } from "./types";
import { TYPE_OPTIONS } from "./consts";

import { AlertButton } from ".";
import Alert, { AlertButton } from ".";

export function TestLeftIcon({ type }: { type: Type }) {
return (
Expand All @@ -14,3 +16,98 @@ export function TestLeftIcon({ type }: { type: Type }) {
</div>
);
}

export function TestAlert() {
return (
<div className="gap-md p-xxs flex flex-col items-stretch">
<h2>Only title, icon and inline button</h2>
<div className="gap-md flex flex-col items-stretch">
{Object.values(TYPE_OPTIONS).map(type => {
const Icon = typeof type === "string" && Icons[type];

return (
<Alert
title="You can change the title by changing the Title control"
type={type}
icon={Icon ? <Icon /> : true}
inlineActions={
<AlertButton type={type} href="#">
Link
</AlertButton>
}
/>
);
})}
</div>
<h2>Title and text, closable and inline button</h2>
<div className="gap-md flex flex-col items-stretch">
{Object.values(TYPE_OPTIONS).map(type => (
<Alert
title="You can change the title by changing the Title control"
type={type}
icon={false}
closable
inlineActions={
<AlertButton type={type} href="#">
Link
</AlertButton>
}
>
<p>The quick, brown fox jumps over a lazy dog.</p>
</Alert>
))}
</div>
<h2>Title and text, icon, closable and inline button</h2>
<div className="gap-md flex flex-col items-stretch">
{Object.values(TYPE_OPTIONS).map(type => (
<Alert
title="You can change the title by changing the Title control"
type={type}
icon={<Icons.Ai />}
closable
inlineActions={
<AlertButton type={type} href="#">
Link
</AlertButton>
}
>
<p>The quick, brown fox jumps over a lazy dog.</p>
</Alert>
))}
</div>
<h2>With custom icon</h2>
<div className="gap-md flex flex-col items-stretch">
{Object.values(TYPE_OPTIONS).map(type => (
<Alert
title="You can change the title by changing the Title control"
type={type}
icon={<Icons.Ai />}
>
The quick, brown fox jumps over a lazy dog.
</Alert>
))}
</div>
<h2>With multiline text, closable, without icon</h2>
<div className="gap-md flex flex-col items-stretch">
{Object.values(TYPE_OPTIONS).map(type => (
<Alert type={type} closable icon={false}>
<p>
<TextLink type="primary">This is</TextLink> a primary textlink.
<br />
<TextLink type="secondary">This is</TextLink> a secondary textlink.
</p>
</Alert>
))}
</div>
<h2>Suppressed</h2>
<div className="gap-md flex flex-col items-stretch">
<Alert
title="You can change the title by changing the Title control"
type="info"
suppressed
icon
/>
</div>
</div>
);
}
21 changes: 20 additions & 1 deletion packages/orbit-components/src/Alert/Alert.ct.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as React from "react";
import { test, expect } from "@playwright/experimental-ct-react";

import { TYPE_OPTIONS } from "./consts";
import { TestLeftIcon } from "./Alert.ct-story";
import { TestLeftIcon, TestAlert } from "./Alert.ct-story";
import RenderInRtl from "../utils/rtl/RenderInRtl";

test.describe("visual AlertButton", () => {
Object.values(TYPE_OPTIONS).forEach(type => {
Expand Down Expand Up @@ -34,3 +35,21 @@ test.describe("visual AlertButton", () => {
});
});
});

test.describe("visual Alert", () => {
test("Alert component", async ({ mount }) => {
const component = await mount(<TestAlert />);

await expect(component).toHaveScreenshot();
});

test("Alert component RTL", async ({ mount }) => {
const component = await mount(
<RenderInRtl>
<TestAlert />
</RenderInRtl>,
);

await expect(component).toHaveScreenshot();
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions packages/orbit-components/src/Alert/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const AlertCloseButton = ({
icon: React.ReactNode;
}) => {
return (
<div className={cx("absolute end-0", hasChildren ? "top-0" : "me-xs top-1/2 -translate-y-1/2")}>
<div className={cx("end-0", hasChildren && "top-0")}>
<ButtonLink
dataTest={dataTest}
onClick={onClick}
Expand Down Expand Up @@ -131,9 +131,9 @@ const Alert = (props: Props) => {
<div
className={cx(
"rounded-large text-ink-dark font-base text-normal p-sm relative box-border flex w-full border border-t-[3px] leading-normal",
closable && "pe-lg",
"lm:border-s-[3px] lm:border-t",
"tb:rounded-normal",
inlineActions && "items-center",
suppressed ? "bg-cloud-light border-cloud-normal lm:border-t-cloud-normal" : COLORS[type],
ACCENT_BORDER[type],
spaceAfter && spaceAfterClasses[spaceAfter],
Expand All @@ -145,7 +145,7 @@ const Alert = (props: Props) => {
<div
className={cx(
"me-xs m-0 shrink-0 leading-none",
inlineActions && "flex items-center",
inlineActions && "lm:mt-[6px] flex items-center self-baseline", // TODO: [6px] can be replaced by space tokens
ICON_COLOR[type],
"tb:me-xs tb:[&_svg]:size-icon-medium",
)}
Expand All @@ -166,6 +166,7 @@ const Alert = (props: Props) => {
className={cx(
"text-ink-dark flex min-h-[20px] items-center font-bold",
!!children && (inlineActions ? "mb-0" : "mb-xxs"),
inlineActions && "grow basis-0",
)}
>
{title}
Expand Down

0 comments on commit 2a9e765

Please sign in to comment.