Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
feat: Implement Container (#23)
Browse files Browse the repository at this point in the history
* container component

* container export

* container props

* export

* interactive container story

* container tests
  • Loading branch information
Tiernebre committed Jun 21, 2021
1 parent d5c57bc commit 7cce006
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/components/container/Container.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { render, screen } from "@testing-library/react";
import { Container } from "./Container";

it("renders children", () => {
const message = "This is a test container. Cool!";
render(<Container>{message}</Container>);
const container = screen.getByText(message);
expect(container).toBeInTheDocument();
});

it("renders in fluid mode if provided", () => {
const message = "This is a test container. Cool!";
render(<Container fluid>{message}</Container>);
const container = screen.getByText(message);
expect(container).toHaveClass("is-fluid");
});

it("renders in non-fluid mode if provided as false", () => {
const message = "This is a test container. Cool!";
render(<Container fluid={false}>{message}</Container>);
const container = screen.getByText(message);
expect(container).not.toHaveClass("is-fluid");
});

it("renders in non-fluid mode by default", () => {
const message = "This is a test container. Cool!";
render(<Container>{message}</Container>);
const container = screen.getByText(message);
expect(container).not.toHaveClass("is-fluid");
});
17 changes: 17 additions & 0 deletions src/components/container/Container.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { PropsWithChildren } from "react";

export type ContainerProps = PropsWithChildren<{
fluid?: boolean;
}>;

export const Container = ({ fluid, children }: ContainerProps): JSX.Element => {
const classes = ["container"];

if (fluid) {
classes.push("is-fluid");
}

const className = classes.join(" ");

return <div className={className}>{children}</div>;
};
1 change: 1 addition & 0 deletions src/components/container/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Container";
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export * from "./button";
export * from "./buttons";
export * from "./column";
export * from "./columns";
export * from "./container";
export * from "./icon";
export * from "./icon-button";
29 changes: 29 additions & 0 deletions src/stories/Container.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Story, Meta } from "@storybook/react";

import { Container, ContainerProps } from "../components";

export default {
component: Container,
title: "Example/Container",
argTypes: {
fluid: {
control: {
type: "boolean",
},
},
children: {
control: {
type: "text",
},
},
},
} as Meta<ContainerProps>;

const Template: Story<ContainerProps> = (args) => (
<Container {...args}>{args.children}</Container>
);

export const InteractiveContainer = Template.bind({});
InteractiveContainer.args = {
children: "This is an interactive container.",
};

0 comments on commit 7cce006

Please sign in to comment.