Skip to content

Commit a0593c8

Browse files
committed
feat: Add dark mode support for cards
1 parent 2fd4fb0 commit a0593c8

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

pages/index.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ import { Container, StackCard } from '../src'
55
export default ({ children }) => <Container my={8}>{children}</Container>
66

77
Foo
8+
9+
<StackCard>
10+
<Text>Bar</Text>
11+
</StackCard>

src/components/cards.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,47 @@
11
import React from 'react'
2-
import Box, { BoxProps } from '@chakra-ui/core/dist/Box'
2+
import PseudoBox, { PseudoBoxProps } from '@chakra-ui/core/dist/PseudoBox'
33
import Flex, { FlexProps } from '@chakra-ui/core/dist/Flex'
44
import Stack, { StackProps } from '@chakra-ui/core/dist/Stack'
5+
import { useColorMode } from '@chakra-ui/core/dist/ColorModeProvider'
56

67
// --
78

8-
const baseProps: BoxProps = {
9+
export const cardBackgroundColors = {
10+
light: 'white',
11+
dark: 'gray.900',
12+
}
13+
14+
export const cardProps: PseudoBoxProps = {
915
p: 4,
1016
borderRadius: 4,
11-
bg: 'white',
1217
shadow: 'md',
1318
}
1419

15-
export interface CardProps extends BoxProps {}
20+
export interface CardProps extends PseudoBoxProps {}
1621

1722
export const Card: React.FC<CardProps> = ({ ...props }) => {
18-
return <Box {...baseProps} {...props} />
23+
const { colorMode } = useColorMode()
24+
return (
25+
<PseudoBox {...cardProps} bg={cardBackgroundColors[colorMode]} {...props} />
26+
)
1927
}
2028

2129
// --
2230

2331
export interface FlexCardProps extends FlexProps {}
2432

2533
export const FlexCard: React.FC<FlexCardProps> = ({ ...props }) => {
26-
return <Flex {...baseProps} {...props} />
34+
const { colorMode } = useColorMode()
35+
return <Flex {...cardProps} bg={cardBackgroundColors[colorMode]} {...props} />
2736
}
2837

2938
// --
3039

3140
export interface StackCardProps extends StackProps {}
3241

3342
export const StackCard: React.FC<StackCardProps> = ({ ...props }) => {
34-
return <Stack {...baseProps} {...props} />
43+
const { colorMode } = useColorMode()
44+
return (
45+
<Stack {...cardProps} bg={cardBackgroundColors[colorMode]} {...props} />
46+
)
3547
}

src/pages/_app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const defaultGetGlobalConfig: GetGlobalConfig = (theme) => ({
1717
},
1818
dark: {
1919
color: theme.colors.gray[400],
20-
bg: theme.colors.gray[800],
21-
borderColor: theme.colors.whiteAlpha[300],
20+
bg: '#0f141c', // theme.colors.gray[900],
21+
borderColor: theme.colors.gray[800],
2222
placeholderColor: theme.colors.gray[600],
2323
},
2424
})

0 commit comments

Comments
 (0)