|
| 1 | +import { tableAnatomy } from "@chakra-ui/anatomy" |
| 2 | +import { |
| 3 | + createMultiStyleConfigHelpers, |
| 4 | + cssVar, |
| 5 | + defineStyle, |
| 6 | +} from "@chakra-ui/react" |
| 7 | +import { defineMergeStyles, tableDefaultTheme } from "./components.utils" |
| 8 | + |
| 9 | +const { defineMultiStyleConfig, definePartsStyle } = |
| 10 | + createMultiStyleConfigHelpers(tableAnatomy.keys) |
| 11 | + |
| 12 | +const $bgColor = cssVar("bg-color") |
| 13 | + |
| 14 | +const cellPadding = defineStyle({ |
| 15 | + p: 4, |
| 16 | +}) |
| 17 | + |
| 18 | +const baseStyle = defineMergeStyles( |
| 19 | + tableDefaultTheme.baseStyle, |
| 20 | + definePartsStyle({ |
| 21 | + table: { |
| 22 | + [$bgColor.variable]: "colors.background.highlight", |
| 23 | + minW: "556px", |
| 24 | + }, |
| 25 | + th: { |
| 26 | + borderBottom: "1px", |
| 27 | + borderColor: "body.base", |
| 28 | + color: "body.base", |
| 29 | + textTransform: "capitalize", |
| 30 | + verticalAlign: "bottom", |
| 31 | + ...cellPadding, |
| 32 | + }, |
| 33 | + tr: { |
| 34 | + "th, td": { |
| 35 | + _notLast: { |
| 36 | + borderRight: "2px", |
| 37 | + borderRightColor: "background.base", |
| 38 | + }, |
| 39 | + }, |
| 40 | + }, |
| 41 | + td: { |
| 42 | + ...cellPadding, |
| 43 | + }, |
| 44 | + tbody: { |
| 45 | + tr: { |
| 46 | + verticalAlign: "top", |
| 47 | + _hover: { |
| 48 | + /** |
| 49 | + * Override specificity when hovering |
| 50 | + * over even rows in 'striped' variant. |
| 51 | + */ |
| 52 | + bg: $bgColor.reference, |
| 53 | + }, |
| 54 | + }, |
| 55 | + }, |
| 56 | + }) |
| 57 | +) |
| 58 | + |
| 59 | +const variantMinimalStriped = definePartsStyle({ |
| 60 | + tbody: { |
| 61 | + tr: { |
| 62 | + _even: { |
| 63 | + bg: $bgColor.reference, |
| 64 | + }, |
| 65 | + }, |
| 66 | + }, |
| 67 | +}) |
| 68 | + |
| 69 | +const variantSimpleStriped = definePartsStyle({ |
| 70 | + ...variantMinimalStriped, |
| 71 | + thead: { |
| 72 | + bg: $bgColor.reference, |
| 73 | + }, |
| 74 | +}) |
| 75 | + |
| 76 | +const variantSimple = definePartsStyle({ |
| 77 | + thead: { |
| 78 | + bg: $bgColor.reference, |
| 79 | + }, |
| 80 | +}) |
| 81 | + |
| 82 | +export const Table = defineMultiStyleConfig({ |
| 83 | + baseStyle, |
| 84 | + variants: { |
| 85 | + minimal: {}, |
| 86 | + "minimal-striped": variantMinimalStriped, |
| 87 | + simple: variantSimple, |
| 88 | + "simple-striped": variantSimpleStriped, |
| 89 | + }, |
| 90 | + defaultProps: { |
| 91 | + variant: "simple", |
| 92 | + }, |
| 93 | +}) |
0 commit comments