diff --git a/documentation/specs/CheckableCard.md b/documentation/specs/CheckableCard.md new file mode 100644 index 000000000..6f6848a51 --- /dev/null +++ b/documentation/specs/CheckableCard.md @@ -0,0 +1,154 @@ +# `CheckableCard` Component Specification + +## Overview + +A `CheckableCard` is a styled container with a `Checkbox` form element. + +### Use Cases + +- Use a CheckableCard to display a checkbox for users inside a styled container + +### Features + +- Supports use of `Checkbox` form element within a `Card` container +- Supports existing features of `Card` component +- Supports existing features of `Checkbox` component + +### Prior Art + +### Design + +Design of `CheckableCard` is comprised of the `Checkbox` component wrapped by the `Card` container component. + +### API + +```ts +export type CheckableCardProps = CheckboxProps & { + /** + * Card children + */ + children: ReactNode; +}; +``` + +### Example Usage + +```tsx +import { CheckableCard } from "@easypost/easy-ui/CheckableCard"; + +function Component() { + return Checkbox item; +} +``` + +_Default value:_ + +```tsx +import { CheckableCard } from "@easypost/easy-ui/CheckableCard"; + +function Component() { + return Checkbox item; +} +``` + +_Controlled:_ + +```tsx +import { CheckableCard } from "@easypost/easy-ui/CheckableCard"; + +function Component() { + const [isSelected, setIsSelected] = useState(false); + return ( + setIsSelected(isSelected)} + > + Checkbox item + + ); +} +``` + +_Disabled:_ + +```tsx +import { CheckableCard } from "@easypost/easy-ui/CheckableCard"; + +function Component() { + return Checkbox item; +} +``` + +_Read-only:_ + +```tsx +import { CheckableCard } from "@easypost/easy-ui/CheckableCard"; + +function Component() { + return ( + + Checkbox item + + ); +} +``` + +_Form submission data:_ + +```tsx +import { CheckableCard } from "@easypost/easy-ui/CheckableCard"; + +function Component() { + return ( + + Checkbox item + + ); +} +``` + +_Error:_ + +```tsx +import { CheckableCard } from "@easypost/easy-ui/CheckableCard"; + +function Component() { + return ( + + Checkbox item + + ); +} +``` + +### Anatomy + +The `CheckableCard` component will render a `Card` component that wraps a `Checkbox` component. + +```tsx +function CheckableCard() { + return ( + + setIsSelected(isSelected)} + > + Checkbox item + + + ); +} +``` + +--- + +## Behavior + +### Accessibility + +### Dependencies + +- React Aria's `useCheckbox`, `useFocusRing`, `VisuallyHidden`, `useToggleState`, and `ValidationState` diff --git a/easy-ui-react/src/CheckableCard/CheckableCard.mdx b/easy-ui-react/src/CheckableCard/CheckableCard.mdx new file mode 100644 index 000000000..34269b5a1 --- /dev/null +++ b/easy-ui-react/src/CheckableCard/CheckableCard.mdx @@ -0,0 +1,10 @@ +import React from "react"; +import { ArgTypes, Canvas, Meta, Controls } from "@storybook/blocks"; +import { CheckableCard } from "./CheckableCard"; +import * as CheckableCardStories from "./CheckableCard.stories"; + + + +# CheckableCard + + diff --git a/easy-ui-react/src/CheckableCard/CheckableCard.stories.tsx b/easy-ui-react/src/CheckableCard/CheckableCard.stories.tsx new file mode 100644 index 000000000..e23538d22 --- /dev/null +++ b/easy-ui-react/src/CheckableCard/CheckableCard.stories.tsx @@ -0,0 +1,21 @@ +import { Meta, StoryObj } from "@storybook/react"; +import React from "react"; +import { CheckableCardProps, CheckableCard } from "./CheckableCard"; + +type Story = StoryObj; + +const Template = (args: CheckableCardProps) => ; + +const meta: Meta = { + title: "Components/CheckableCard", + component: CheckableCard, +}; + +export default meta; + +export const Default: Story = { + render: Template.bind({}), + args: { + children: "Content", + }, +}; diff --git a/easy-ui-react/src/CheckableCard/CheckableCard.tsx b/easy-ui-react/src/CheckableCard/CheckableCard.tsx new file mode 100644 index 000000000..7d6cab490 --- /dev/null +++ b/easy-ui-react/src/CheckableCard/CheckableCard.tsx @@ -0,0 +1,36 @@ +import React, { ReactNode, forwardRef } from "react"; +import { Card } from "../Card"; +import { Text } from "../Text"; +import { Checkbox } from "../Checkbox"; +import { HorizontalStack } from "../HorizontalStack"; +import { VerticalStack } from "../VerticalStack"; + +export type CheckableCardProps = { + children?: ReactNode; +}; + +export const CheckableCard = forwardRef( + (props) => { + const { children } = props; + return ( + + + + + + + Header + + + {children} + + + + + + + ); + }, +); + +CheckableCard.displayName = "CheckableCard"; diff --git a/easy-ui-react/src/CheckableCard/index.ts b/easy-ui-react/src/CheckableCard/index.ts new file mode 100644 index 000000000..d5dc8bb50 --- /dev/null +++ b/easy-ui-react/src/CheckableCard/index.ts @@ -0,0 +1 @@ +export * from "./CheckableCard";