Files
react/components/card/card-content.tsx
2020-05-06 14:25:10 +08:00

47 lines
1012 B
TypeScript

import React from 'react'
import useTheme from '../styles/use-theme'
import withDefaults from '../utils/with-defaults'
interface Props {
className?: string
}
const defaultProps = {
className: '',
}
type NativeAttrs = Omit<React.HTMLAttributes<any>, keyof Props>
export type CardContentProps = Props & typeof defaultProps & NativeAttrs
const CardContent: React.FC<React.PropsWithChildren<CardContentProps>> = ({
className,
children,
...props
}) => {
const theme = useTheme()
return (
<div className={`content ${className}`} {...props}>
{children}
<style jsx>{`
.content {
width: 100%;
padding: ${theme.layout.gap} ${theme.layout.gap};
}
.content > :global(*:first-child) {
margin-top: 0;
}
.content > :global(*:last-child) {
margin-bottom: 0;
}
`}</style>
</div>
)
}
const MemoCardContent = React.memo(CardContent)
export default withDefaults(MemoCardContent, defaultProps)