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

docs: Add new card component documentation #12

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
296 changes: 296 additions & 0 deletions content/docs/components/data-display/card/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,296 @@
# Card

## Import

Chakra UI exports 4 components to help you create a Card.

```js
import { Card, CardHeader, CardBody, CardFooter } from '@chakra-ui/react';
```

- **Card:** The parent wrapper that provides context for its children.
- **CardHeader:** The wrapper that contains a card's header.
- **CardBody:** The wrapper that houses the card's main content.
- **CardFooter:** The footer that houses the card actions.

## Usage

### Basic Card

Put in some content in the `CardBody` to get a basic card.

```jsx live
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to check if the examples are rendered properly. I've added a way to make the live preview box different sizes so you don't have scrolling examples

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I get what you mean. The examples render correctly with the live tag, although there's a scroll in the preview. In what way did you make the examples non-scrolling?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you check other components live blocks in the code. There is in some places sm,md,lg to describe which high it should have. This is because some components are to big for the default high of the iframe.

<Card>
<CardBody>
<Text>View a summary of all your customers over the last month.</Text>
</CardBody>
</Card>
```

### Card with Divider

There are instances when you have multiple content to display in the `CardBody`
and you may want to add dividers between them.

```jsx live
<Card>
<CardHeader>
<Heading size='md'>Client Report</Heading>
</CardHeader>

<CardBody>
<Stack divider={<StackDivider />} spacing='4'>
<Box>
<Heading size='xs' textTransform='uppercase'>
Summary
</Heading>
<Text pt='2' fontSize='sm'>
View a summary of all your clients over the last month.
</Text>
</Box>
<Box>
<Heading size='xs' textTransform='uppercase'>
Overview
</Heading>
<Text pt='2' fontSize='sm'>
Check out the overview of your clients.
</Text>
</Box>
<Box>
<Heading size='xs' textTransform='uppercase'>
Analysis
</Heading>
<Text pt='2' fontSize='sm'>
See a detailed analysis of all your business clients.
</Text>
</Box>
</Stack>
</CardBody>
</Card>
```

### Card with Image

Place the content within the `CardBody` to get a nice padding around.

```jsx live
<Card maxW='sm'>
<CardBody>
<Image
src='https://images.unsplash.com/photo-1555041469-a586c61ea9bc?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1770&q=80'
alt='Green double couch with wooden legs'
borderRadius='lg'
/>
<Stack mt='6' spacing='3'>
<Heading size='md'>Living room Sofa</Heading>
<Text>
This sofa is perfect for modern tropical spaces, baroque inspired
spaces, earthy toned spaces and for people who love a chic design with a
sprinkle of vintage design.
</Text>
<Text color='blue.600' fontSize='2xl'>
$450
</Text>
</Stack>
</CardBody>
<Divider />
<CardFooter>
<ButtonGroup spacing='2'>
<Button variant='solid' colorScheme='blue'>
Buy now
</Button>
<Button variant='ghost' colorScheme='blue'>
Add to cart
</Button>
</ButtonGroup>
</CardFooter>
</Card>
```

### Horizontal Card

The card component has `display: flex` by default. This means you make the
content in a horizontal direction by passing `direction="row`.

```jsx live
<Card direction='row' overflow='hidden' variant='outline'>
<Image
objectFit='cover'
maxW='200px'
src='https://images.unsplash.com/photo-1667489022797-ab608913feeb?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw5fHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=800&q=60'
alt='Caffe Latte'
/>
<Stack>
<CardBody>
<Heading size='md'>The perfect latte</Heading>
<Text py='2'>
Caffè latte is a coffee beverage of Italian origin made with espresso
and steamed milk.
</Text>
</CardBody>
<CardFooter>
<Button variant='solid' colorScheme='blue'>
Buy Latte
</Button>
</CardFooter>
</Stack>
</Card>
```

### Advanced Composition

You can compose `Card` with other components like `Avatar`, `Icon Button` and
more for a more advanced layout.

```jsx live
<Card maxW='md'>
<CardHeader>
<HStack spacing='4'>
<Avatar name='Segun Adebayo' src='https://bit.ly/sage-adebayo' />

<Box flex='1'>
<Heading size='sm'>Segun Adebayo</Heading>
<Text>Creator, Chakra UI</Text>
</Box>
<IconButton
variant='ghost'
colorScheme='gray'
aria-label='See menu'
icon={<BsThreeDotsVertical />}
/>
</HStack>
</CardHeader>
<CardBody>
<Text>
With Chakra UI, I wanted to sync the speed of development with the speed
of design. I wanted the developer to be just as excited as the designer to
create a screen.
</Text>
</CardBody>
<Image
objectFit='cover'
src='https://images.unsplash.com/photo-1531403009284-440f080d1e12?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1770&q=80'
alt='Chakra UI'
/>

<CardFooter justify='space-between'>
<Button flex='1' variant='ghost' leftIcon={<BiLike />}>
Like
</Button>
<Button flex='1' variant='ghost' leftIcon={<BiChat />}>
Comment
</Button>
<Button flex='1' variant='ghost' leftIcon={<BiShare />}>
Share
</Button>
</CardFooter>
</Card>
```

### Multiple cards

Render multiple cards to display content by using the `SimpleGrid` or your
preferred layout method.

```jsx live
<SimpleGrid columns={3} spacing={4}>
<Card>
<CardHeader>
<Heading size='md'> Customer dashboard</Heading>
</CardHeader>
<CardBody>
<Text>View a summary of all your customers over the last month.</Text>
</CardBody>
<CardFooter>
<Button>View here</Button>
</CardFooter>
</Card>
<Card>
<CardHeader>
<Heading size='md'> Customer dashboard</Heading>
</CardHeader>
<CardBody>
<Text>View a summary of all your customers over the last month.</Text>
</CardBody>
<CardFooter>
<Button>View here</Button>
</CardFooter>
</Card>
<Card>
<CardHeader>
<Heading size='md'> Customer dashboard</Heading>
</CardHeader>
<CardBody>
<Text>View a summary of all your customers over the last month.</Text>
</CardBody>
<CardFooter>
<Button>View here</Button>
</CardFooter>
</Card>
</SimpleGrid>
```

### Centering content in a card

Card comes with an inherent `display="flex"` on it, so if you'd like to center
the content of your card, you can do this easily by passing `align="center"` to
the Card.

```jsx live
<Card align='center'>
<CardHeader>
<Heading size='md'> Customer dashboard</Heading>
</CardHeader>
<CardBody>
<Text>View a summary of all your customers over the last month.</Text>
</CardBody>
<CardFooter>
<Button colorScheme='blue'>View here</Button>
</CardFooter>
</Card>
```

## Variants

Chakra UI provides 4 card variants - `elevated`, `outline`, `filled`, and
`unstyled`. Use the `variant` prop to change the style of your card. If the
variant prop is not passed, the default variant, `elevated` is used.

```jsx live
<Stack spacing='4'>
{['elevated', 'outline', 'filled', 'unstyled'].map((variant) => (
<Card key={variant} variant={variant}>
<CardHeader>
<Heading size='md'> {variant}</Heading>
</CardHeader>
<CardBody>
<Text>variant = {variant}</Text>
</CardBody>
</Card>
))}
</Stack>
```

## Sizes

Chakra UI provides 3 Card sizes. Use the `size` prop to change the size and set
the value to `sm`, `md`, or `lg`.

```jsx live
<Stack spacing='4'>
{['sm', 'md', 'lg'].map((size) => (
<Card key={size} size={size}>
<CardHeader>
<Heading size='md'> {size}</Heading>
</CardHeader>
<CardBody>
<Text>size = {size}</Text>
</CardBody>
</Card>
))}
</Stack>
```

## Props

<PropsTable of='Card' />
7 changes: 7 additions & 0 deletions content/docs/components/data-display/card/theming.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Theming

:::info

We are working on providing content for this. Feel free to help us out here https://github.com/chakra-ui/chakra-ui-docs

:::
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
},
"dependencies": {
"@algolia/client-search": "^4.14.2",
"@chakra-ui/icons": "^2.0.11",
"@chakra-ui/props-docs": "^2.0.23",
"@chakra-ui/react": "2.3.7",
"@chakra-ui/icons": "^2.0.12",
"@chakra-ui/props-docs": "^2.0.25",
"@chakra-ui/react": "2.4.1",
"@codesandbox/sandpack-react": "^1.17.0",
"@codesandbox/sandpack-themes": "^1.17.0",
"@docusaurus/core": "^2.2.0",
Expand Down
32 changes: 19 additions & 13 deletions src/theme/ReactLiveScope/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react";
import * as Chakra from "@chakra-ui/react";
import * as Icons from "@chakra-ui/icons";
import * as Formik from "formik";
import { AiOutlineUser } from "react-icons/ai";
import { FaFacebook, FaTwitter } from "react-icons/fa";
import React from 'react';
import * as Chakra from '@chakra-ui/react';
import * as Icons from '@chakra-ui/icons';
import * as Formik from 'formik';
import { AiOutlineUser } from 'react-icons/ai';
import { FaFacebook, FaTwitter } from 'react-icons/fa';
import {
MdArrowDropDown,
MdBuild,
Expand All @@ -14,15 +14,17 @@ import {
MdPhone,
MdReceipt,
MdSettings,
} from "react-icons/md";
import Lorem from "react-lorem-component";
import * as Loaders from "react-spinners";
import * as ReactTable from "react-table";
import { chakra } from "@chakra-ui/react";
} from 'react-icons/md';
import { BsThreeDotsVertical } from 'react-icons/bs';
import { BiLike, BiChat, BiShare } from 'react-icons/bi';
import Lorem from 'react-lorem-component';
import * as Loaders from 'react-spinners';
import * as ReactTable from 'react-table';
import { chakra } from '@chakra-ui/react';

const StarIcon = (props) => (
<chakra.svg m="2px" fill="current" boxSize="3" viewBox="0 0 24 24" {...props}>
<path d="M23.555 8.729a1.505 1.505 0 0 0-1.406-.98h-6.087a.5.5 0 0 1-.472-.334l-2.185-6.193a1.5 1.5 0 0 0-2.81 0l-.005.016-2.18 6.177a.5.5 0 0 1-.471.334H1.85A1.5 1.5 0 0 0 .887 10.4l5.184 4.3a.5.5 0 0 1 .155.543l-2.178 6.531a1.5 1.5 0 0 0 2.31 1.684l5.346-3.92a.5.5 0 0 1 .591 0l5.344 3.919a1.5 1.5 0 0 0 2.312-1.683l-2.178-6.535a.5.5 0 0 1 .155-.543l5.194-4.306a1.5 1.5 0 0 0 .433-1.661z" />
<chakra.svg m='2px' fill='current' boxSize='3' viewBox='0 0 24 24' {...props}>
<path d='M23.555 8.729a1.505 1.505 0 0 0-1.406-.98h-6.087a.5.5 0 0 1-.472-.334l-2.185-6.193a1.5 1.5 0 0 0-2.81 0l-.005.016-2.18 6.177a.5.5 0 0 1-.471.334H1.85A1.5 1.5 0 0 0 .887 10.4l5.184 4.3a.5.5 0 0 1 .155.543l-2.178 6.531a1.5 1.5 0 0 0 2.31 1.684l5.346-3.92a.5.5 0 0 1 .591 0l5.344 3.919a1.5 1.5 0 0 0 2.312-1.683l-2.178-6.535a.5.5 0 0 1 .155-.543l5.194-4.306a1.5 1.5 0 0 0 .433-1.661z' />
</chakra.svg>
);

Expand All @@ -39,6 +41,10 @@ const reactIcons = {
AiOutlineUser,
FaFacebook,
FaTwitter,
BsThreeDotsVertical,
BiLike,
BiShare,
BiChat,
};

const ReactLiveScope = {
Expand Down
25 changes: 25 additions & 0 deletions static/img/components/card.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading