Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flyout component #176

Merged
merged 7 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"@radix-ui/react-avatar": "^1.0.3",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-context-menu": "^2.1.4",
"@radix-ui/react-dialog": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-dropdown-menu": "^2.0.5",
"@radix-ui/react-hover-card": "^1.0.6",
"@radix-ui/react-popover": "^1.0.6",
Expand Down
1 change: 1 addition & 0 deletions src/App.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,5 @@
display: flex;
flex-flow: row wrap;
gap: 10px;
padding: 10px 0;
}
133 changes: 115 additions & 18 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from "react";
import { useRef, useState } from "react";

import "@/styles/globals.css";
import "./styles/variables.css";
Expand Down Expand Up @@ -28,6 +28,9 @@ import {
Tabs,
WarningAlert,
CardPrimary,
Flyout,
Select,
Text,
} from "@/components";
import { Dialog } from "@/components/Dialog/Dialog";

Expand All @@ -37,6 +40,7 @@ const App = () => {
const [checked, setChecked] = useState(false);
const [disabled] = useState(false);
const [open, setOpen] = useState(true);
const ref = useRef(null);

return (
<ClickUIProvider
Expand Down Expand Up @@ -94,23 +98,115 @@ const App = () => {
onClick={() => console.log("click")}
/>
</div>
<div className={styles.flexWrap}>
<IconButton
type="secondary"
icon="user"
onClick={() => console.log("click")}
/>
<IconButton
type="secondary"
icon="user"
onClick={() => console.log("click")}
/>
<IconButton
type="secondary"
disabled
icon="user"
onClick={() => console.log("click")}
/>
<div
ref={ref}
style={{ position: "relative", minHeight: 200 }}
>
<Text>Flyout</Text>
<div className={styles.flexWrap}>
<Flyout>
<Flyout.Trigger>
<Button
iconLeft="user"
onClick={() => console.log("click")}
>
Flyout Relative
</Button>
</Flyout.Trigger>
<Flyout.Content container={ref.current}>
<Flyout.Header
title="test1"
description="test2"
/>
<Flyout.Body>
Flyout Text
<Select>
<Select.Item value="test">test</Select.Item>
<Select.Item value="test2">test2</Select.Item>
<Select.Item value="test3">test3</Select.Item>
<Select.Item value="test4">test4</Select.Item>
<Select.Item value="test5">test5</Select.Item>
<Select.Item value="test6">test6</Select.Item>
<Select.Item value="test7">test7</Select.Item>
<Select.Item value="test8">test8</Select.Item>
</Select>
</Flyout.Body>
<Flyout.Footer>
<Button type="primary">Primary Button</Button>
</Flyout.Footer>
</Flyout.Content>
</Flyout>
<Flyout>
<Flyout.Trigger>
<Button
iconLeft="user"
onClick={() => console.log("click")}
>
Flyout Absolute
</Button>
</Flyout.Trigger>
<Flyout.Content
container={ref.current}
strategy="absolute"
>
<Flyout.Header
title="test1"
description="test2"
/>
<Flyout.Body>
Flyout Text
<Select>
<Select.Item value="test">test</Select.Item>
<Select.Item value="test2">test2</Select.Item>
<Select.Item value="test3">test3</Select.Item>
<Select.Item value="test4">test4</Select.Item>
<Select.Item value="test5">test5</Select.Item>
<Select.Item value="test6">test6</Select.Item>
<Select.Item value="test7">test7</Select.Item>
<Select.Item value="test8">test8</Select.Item>
</Select>
</Flyout.Body>
<Flyout.Footer>
<Button type="primary">Primary Button</Button>
</Flyout.Footer>
</Flyout.Content>
</Flyout>
<Flyout>
<Flyout.Trigger>
<Button
iconLeft="user"
onClick={() => console.log("click")}
>
Flyout Fixed
</Button>
</Flyout.Trigger>
<Flyout.Content
container={ref.current}
strategy="fixed"
>
<Flyout.Header
title="test1"
description="test2"
/>
<Flyout.Body>
Flyout Text
<Select>
<Select.Item value="test">test</Select.Item>
<Select.Item value="test2">test2</Select.Item>
<Select.Item value="test3">test3</Select.Item>
<Select.Item value="test4">test4</Select.Item>
<Select.Item value="test5">test5</Select.Item>
<Select.Item value="test6">test6</Select.Item>
<Select.Item value="test7">test7</Select.Item>
<Select.Item value="test8">test8</Select.Item>
</Select>
</Flyout.Body>
<Flyout.Footer>
<Button type="primary">Primary Button</Button>
</Flyout.Footer>
</Flyout.Content>
</Flyout>
</div>
</div>
<div className={styles.flexWrap}>
<Badge text={"default"}></Badge>
Expand Down Expand Up @@ -274,6 +370,7 @@ const App = () => {
<Dialog
open={open}
onOpenChange={setOpen}
modal={false}
>
<Dialog.Content
title="Hello"
Expand Down
79 changes: 79 additions & 0 deletions src/components/Flyout/Flyout.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { Button } from "..";
import { Flyout, FlyoutProps } from "./Flyout";

interface Props extends FlyoutProps {
title: string;
description?: string;
showClose?: boolean;
}

const FlyoutExample = ({ title, description, showClose, ...props }: Props) => {
return (
<Flyout {...props}>
<Flyout.Trigger>Flyout Trigger</Flyout.Trigger>
<Flyout.Content strategy="fixed">
<Flyout.Header
title={title}
description={description}
/>
<Flyout.Body>
<Flyout.Element>Content1 long text content</Flyout.Element>
</Flyout.Body>
<Flyout.Footer showClose={showClose}>
<Button>Test Primary</Button>
</Flyout.Footer>
</Flyout.Content>
</Flyout>
);
};
export default {
component: FlyoutExample,
title: "Display/Flyout",
tags: ["form-field", "select", "autodocs"],
argTypes: {
title: { control: "text" },
description: { control: "text" },
showClose: { control: "boolean" },
},
};

export const Playground = {
args: {
title: "Title",
description: "Description",
showClose: true,
},
parameters: {
docs: {
source: {
transform: (_: string, story: { args: Props; [x: string]: unknown }) => {
const { title, description, showClose, ...props } = story.args;
return `<Flyout\n
${Object.entries(props)
.flatMap(([key, value]) =>
typeof value === "boolean"
? value
? ` ${key}`
: []
: ` ${key}=${typeof value == "string" ? `"${value}"` : `{${value}}`}`
)
.join("\n")}
>

<Flyout.Header
title="${title}"
description="${description}"
/>
<Flyout.Body>
<Flyout.Element>Content1 long text content</Flyout.Element>
</Flyout.Body>
<Flyout.Footer showClose={${showClose}}>
<Button>Test Primary</Button>
</Flyout.Footer>
</Flyout>
`;
},
},
},
},
};
69 changes: 69 additions & 0 deletions src/components/Flyout/Flyout.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { fireEvent } from "@testing-library/react";
import { Flyout } from "./Flyout";
import { renderCUI } from "@/utils/test-utils";
import { Button } from "..";
import { DialogProps } from "@radix-ui/react-dialog";

describe("Flyout", () => {
const renderFlyout = (props: DialogProps) => {
return renderCUI(
<Flyout {...props}>
<Flyout.Trigger>
<Button iconLeft="user">Flyout Fixed</Button>
</Flyout.Trigger>
<Flyout.Content strategy="fixed">
<Flyout.Header
title="test1"
description="test2"
/>
<Flyout.Body>Flyout Text</Flyout.Body>
<Flyout.Footer showClose>
<Button type="primary">Primary Button</Button>
</Flyout.Footer>
</Flyout.Content>
</Flyout>
);
};
it("should open flyout on click", () => {
const { queryByText } = renderFlyout({});
const selectTrigger = queryByText("Flyout Fixed");
expect(selectTrigger).not.toBeNull();
expect(queryByText("Flyout Text")).toBeNull();
selectTrigger && fireEvent.click(selectTrigger);

expect(queryByText("Flyout Text")).not.toBeNull();
expect(queryByText("test1")).not.toBeNull();
});

it("should open on updating open param", () => {
const { queryByText } = renderFlyout({
open: true,
});
expect(queryByText("Flyout Text")).not.toBeNull();
});

it("should close flyout on clicking close Button in header", () => {
const { queryByText, getByTestId } = renderFlyout({});
const selectTrigger = queryByText("Flyout Fixed");
expect(selectTrigger).not.toBeNull();
expect(queryByText("Flyout Text")).toBeNull();
selectTrigger && fireEvent.click(selectTrigger);

expect(queryByText("Flyout Text")).not.toBeNull();
expect(queryByText("test1")).not.toBeNull();
fireEvent.click(getByTestId("flyout-header-close-btn"));
expect(queryByText("Flyout Text")).toBeNull();
});

it("should close flyout on clicking close Button in footer", () => {
const { queryByText, getByText } = renderFlyout({});
const selectTrigger = queryByText("Flyout Fixed");
expect(selectTrigger).not.toBeNull();
expect(queryByText("Flyout Text")).toBeNull();
selectTrigger && fireEvent.click(selectTrigger);

expect(queryByText("Flyout Text")).not.toBeNull();
fireEvent.click(getByText("Cancel"));
expect(queryByText("Flyout Text")).toBeNull();
});
});
Loading