-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a491dd9
commit d3c243e
Showing
7 changed files
with
138 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Meta, StoryObj } from "@storybook/react"; | ||
|
||
import { Callout } from "./callout"; | ||
|
||
const story = { | ||
title: "Components/Callout", | ||
component: Callout, | ||
} satisfies Meta<typeof Callout>; | ||
|
||
type Story = StoryObj<typeof Callout>; | ||
|
||
export const Success: Story = { | ||
args: { | ||
children: | ||
"Eaque non tempore porro quod voluptates rerum ipsam. Consequatur ea voluptate quo tempora autem quod. Voluptatem perspiciatis non mollitia. Dicta non necessitatibus laboriosam est aut cum eos et. Animi pariatur aliquid sint ipsum nam occaecati nisi sit.", | ||
variant: "success", | ||
}, | ||
}; | ||
|
||
export const Info: Story = { | ||
args: { | ||
children: | ||
"Eaque non tempore porro quod voluptates rerum ipsam. Consequatur ea voluptate quo tempora autem quod. Voluptatem perspiciatis non mollitia. Dicta non necessitatibus laboriosam est aut cum eos et. Animi pariatur aliquid sint ipsum nam occaecati nisi sit.", | ||
variant: "info", | ||
}, | ||
}; | ||
|
||
export const Warning: Story = { | ||
args: { | ||
children: | ||
"Eaque non tempore porro quod voluptates rerum ipsam. Consequatur ea voluptate quo tempora autem quod. Voluptatem perspiciatis non mollitia. Dicta non necessitatibus laboriosam est aut cum eos et. Animi pariatur aliquid sint ipsum nam occaecati nisi sit.", | ||
variant: "warning", | ||
}, | ||
}; | ||
|
||
export const Danger: Story = { | ||
args: { | ||
children: | ||
"Eaque non tempore porro quod voluptates rerum ipsam. Consequatur ea voluptate quo tempora autem quod. Voluptatem perspiciatis non mollitia. Dicta non necessitatibus laboriosam est aut cum eos et. Animi pariatur aliquid sint ipsum nam occaecati nisi sit.", | ||
variant: "danger", | ||
}, | ||
}; | ||
|
||
export default story; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
|
||
import { Callout } from "./callout"; | ||
|
||
describe("<Callout />", () => { | ||
it("should render children correctly", () => { | ||
render(<Callout variant="info">Hello World</Callout>); | ||
|
||
expect(screen.getByText("Hello World")).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
// ------------------------------ | ||
// Type tests | ||
// ------------------------------ | ||
|
||
// @ts-expect-error - Callout does not accept `role` | ||
<Callout variant="success" role="alert"> | ||
Hello World | ||
</Callout>; | ||
|
||
// @ts-expect-error - Callout does not accept `role` | ||
<Callout variant="info" role="alert"> | ||
Hello World | ||
</Callout>; | ||
|
||
// @ts-expect-error - Callout does not accept `role` | ||
<Callout variant="warning" role="alert"> | ||
Hello World | ||
</Callout>; | ||
|
||
// @ts-expect-error - Callout does not accept `role` | ||
<Callout variant="danger" role="alert"> | ||
Hello World | ||
</Callout>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from "react"; | ||
import { CalloutProps } from "./types"; | ||
|
||
const variantClasses = { | ||
success: "text-green-700 bg-green-50 border-green-700", | ||
info: "text-blue-700 bg-blue-50 border-blue-700", | ||
warning: "text-yellow-700 bg-yellow-50 border-yellow-700", | ||
danger: "text-red-700 bg-red-50 border-red-700", | ||
}; | ||
|
||
/** | ||
* A `Callout` is used to emphasize an important snippet of information within the flow of a page. | ||
* Content in a callout should be something on the page that you want to highlight, but that is not critical information. | ||
* Use `Alert` instead of `Callout` if you want to communicate system-level information. | ||
*/ | ||
export const Callout = ({ | ||
children, | ||
className, | ||
variant, | ||
...others | ||
}: CalloutProps): JSX.Element => { | ||
const variantClass = variantClasses[variant]; | ||
|
||
const classes = [ | ||
"p-4 mb-6 border border-solid border-1 break-words", | ||
variantClass, | ||
className, | ||
].join(" "); | ||
|
||
return ( | ||
<div className={classes} {...others}> | ||
{children} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Callout } from "./callout"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
type CalloutVariant = "success" | "info" | "warning" | "danger"; | ||
|
||
export interface CalloutProps | ||
extends Omit<React.HTMLAttributes<HTMLDivElement>, "role"> { | ||
variant: CalloutVariant; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,25 @@ | ||
// Use this file as the entry point for component export | ||
export { Alert, type AlertProps } from "./alert"; | ||
export { Button, type ButtonProps } from "./button"; | ||
export { Callout } from "./callout"; | ||
export { CloseButton } from "./close-button"; | ||
export { Image } from "./image"; | ||
export { Table } from "./table"; | ||
export { Panel } from "./panel"; | ||
// export { ToggleButton } from './toggle-button'; | ||
export { Dropdown } from "./drop-down"; | ||
export { MenuItem } from "./drop-down/menu-item"; | ||
export { Container } from "./container"; | ||
export { Tabs, TabsList, TabsTrigger, TabsContent } from "./tabs"; | ||
export { Col } from "./col"; | ||
export { Container } from "./container"; | ||
export { ControlLabel } from "./control-label"; | ||
export { FormGroup, type FormGroupProps } from "./form-group"; | ||
export { Dropdown } from "./drop-down"; | ||
export { FormControl } from "./form-control"; | ||
export { FormGroup, type FormGroupProps } from "./form-group"; | ||
export { HelpBlock } from "./help-block"; | ||
export { Row } from "./row"; | ||
export { Image } from "./image"; | ||
export { MenuItem } from "./drop-down/menu-item"; | ||
export { Modal, type ModalProps, type HeaderProps } from "./modal"; | ||
export { getThemingClass } from "./utils"; | ||
export { Spacer } from "./spacer"; | ||
export { Panel } from "./panel"; | ||
export { PrismFormatted } from "./prism-formatted"; | ||
export { QuizQuestion } from "./quiz-question"; | ||
export { Row } from "./row"; | ||
export { Spacer } from "./spacer"; | ||
export { Table } from "./table"; | ||
export { Tabs, TabsList, TabsTrigger, TabsContent } from "./tabs"; | ||
export { Quiz, useQuiz } from "./quiz"; | ||
export { QuizQuestion } from "./quiz-question"; | ||
|
||
export { getThemingClass } from "./utils"; |