Skip to content

Commit

Permalink
feat: Add cards
Browse files Browse the repository at this point in the history
  • Loading branch information
franky47 committed Apr 2, 2020
1 parent f1a76a5 commit 9bf2b95
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Opinionated design system for React, based on Chakra UI + Next.js.
- Components:
- 🔗 [Links](#links)
- 🗜 [Containers](#containers)
- ◻️ [Cards](#cards)
- 🧪 _More to come_

## Installation
Expand Down Expand Up @@ -168,6 +169,34 @@ export default () => (
)
```

### Cards

```tsx
import { Card, FlexCard, StackCard } from '@47ng/chakra-next'

export default () => (
<>
{/* Card as Box */}
<Card>I'm in a card</Card>

{/* Card + Flex */}
<FlexCard>
<Box>Direction is column by default</Box>
<Box>Foo</Box>
<Box>Bar</Box>
<Box>Egg</Box>
</FlexCard>

{/* Card + Stack */}
<StackCard spacing={8}>
<Box>Foo</Box>
<Box>Bar</Box>
<Box>Egg</Box>
</StackCard>
</>
)
```

## License

[MIT](https://github.com/47ng/chakra-next/blob/next/LICENSE) - Made with ❤️ by [François Best](https://francoisbest.com).
47 changes: 47 additions & 0 deletions src/components/cards.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react'
import { render } from '../../test/render'
import '@testing-library/jest-dom/extend-expect'
import { Card, FlexCard, StackCard } from './cards'

describe('Cards', () => {
test('Card', () => {
const { getByTestId } = render(<Card data-testid="card" />)
const element = getByTestId('card')
expect(element.tagName).toEqual('DIV')
const style = getComputedStyle(element)
expect(style.display).toEqual('block')
expect(style.backgroundColor).toEqual('rgb(255, 255, 255)')
expect(style.borderRadius).toEqual('4px')
expect(style.padding).toEqual('1rem')
expect(style.boxShadow).toEqual(
'0 4px 6px -1px rgba(0,0,0,0.1),0 2px 4px -1px rgba(0,0,0,0.06)'
)
})
test('FlexCard', () => {
const { getByTestId } = render(<FlexCard data-testid="card" />)
const element = getByTestId('card')
expect(element.tagName).toEqual('DIV')
const style = getComputedStyle(element)
expect(style.display).toEqual('flex')
expect(style.backgroundColor).toEqual('rgb(255, 255, 255)')
expect(style.borderRadius).toEqual('4px')
expect(style.padding).toEqual('1rem')
expect(style.boxShadow).toEqual(
'0 4px 6px -1px rgba(0,0,0,0.1),0 2px 4px -1px rgba(0,0,0,0.06)'
)
})

test('StackCard', () => {
const { getByTestId } = render(<StackCard data-testid="card" />)
const element = getByTestId('card')
expect(element.tagName).toEqual('DIV')
const style = getComputedStyle(element)
expect(style.display).toEqual('flex')
expect(style.backgroundColor).toEqual('rgb(255, 255, 255)')
expect(style.borderRadius).toEqual('4px')
expect(style.padding).toEqual('1rem')
expect(style.boxShadow).toEqual(
'0 4px 6px -1px rgba(0,0,0,0.1),0 2px 4px -1px rgba(0,0,0,0.06)'
)
})
})
40 changes: 40 additions & 0 deletions src/components/cards.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react'
import {
Box,
Flex,
Stack,
BoxProps,
FlexProps,
StackProps
} from '@chakra-ui/core'

// --

const baseProps: BoxProps = {
p: 4,
borderRadius: 4,
bg: 'white',
shadow: 'md'
}

export interface CardProps extends BoxProps {}

export const Card: React.FC<CardProps> = ({ ...props }) => {
return <Box {...baseProps} {...props} />
}

// --

export interface FlexCardProps extends FlexProps {}

export const FlexCard: React.FC<FlexCardProps> = ({ ...props }) => {
return <Flex {...baseProps} {...props} />
}

// --

export interface StackCardProps extends StackProps {}

export const StackCard: React.FC<StackCardProps> = ({ ...props }) => {
return <Stack {...baseProps} {...props} />
}

0 comments on commit 9bf2b95

Please sign in to comment.