|
| 1 | +import { style } from '@vanilla-extract/css'; |
| 2 | +import { recipe } from '@vanilla-extract/recipes'; |
| 3 | + |
| 4 | +import { breakpoints } from '../../styles/breakpoints.css'; |
| 5 | +import { tokens } from '../../styles/tokens.css'; |
| 6 | + |
| 7 | +// Elevation variants matching Elevation component |
| 8 | +const elevationVariants = { |
| 9 | + 0: { |
| 10 | + boxShadow: 'none', |
| 11 | + }, |
| 12 | + 1: { |
| 13 | + backgroundColor: tokens.colors['01dp'], |
| 14 | + boxShadow: |
| 15 | + '0 1px 5px 0 hsla(0, 0%, 0%, 0.2), 0 3px 1px -2px hsla(0, 0%, 0%, 0.12), 0 2px 2px 0 hsla(0, 0%, 0%, 0.14)', |
| 16 | + }, |
| 17 | + 2: { |
| 18 | + backgroundColor: tokens.colors['02dp'], |
| 19 | + boxShadow: |
| 20 | + '0 2px 4px -1px hsla(0, 0%, 0%, 0.2), 0 1px 10px 0 hsla(0, 0%, 0%, 0.12), 0 4px 5px 0 hsla(0, 0%, 0%, 0.14)', |
| 21 | + }, |
| 22 | + 3: { |
| 23 | + backgroundColor: tokens.colors['03dp'], |
| 24 | + boxShadow: |
| 25 | + '0 3px 5px -1px hsla(0, 0%, 0%, 0.2), 0 1px 18px 0 hsla(0, 0%, 0%, 0.12), 0 6px 10px 0 hsla(0, 0%, 0%, 0.14)', |
| 26 | + }, |
| 27 | + 4: { |
| 28 | + backgroundColor: tokens.colors['04dp'], |
| 29 | + boxShadow: |
| 30 | + '0 7px 8px -4px hsla(0, 0%, 0%, 0.2), 0 5px 22px 4px hsla(0, 0%, 0%, 0.12), 0 12px 17px 2px hsla(0, 0%, 0%, 0.14)', |
| 31 | + }, |
| 32 | + 5: { |
| 33 | + backgroundColor: tokens.colors['05dp'], |
| 34 | + boxShadow: |
| 35 | + '0 11px 15px -7px hsla(0, 0%, 0%, 0.2), 0 9px 46px 8px hsla(0, 0%, 0%, 0.12), 0 24px 38px 3px hsla(0, 0%, 0%, 0.14)', |
| 36 | + }, |
| 37 | +} as const; |
| 38 | + |
| 39 | +// Base card styles |
| 40 | +const cardBase = style({ |
| 41 | + appearance: 'none', |
| 42 | + border: 'none', |
| 43 | + boxSizing: 'border-box', |
| 44 | + font: 'inherit', |
| 45 | + lineHeight: '1', |
| 46 | + outline: 'none', |
| 47 | + padding: tokens.space['3'], |
| 48 | + textAlign: 'inherit', |
| 49 | + verticalAlign: 'middle', |
| 50 | + WebkitTapHighlightColor: 'rgba(0, 0, 0, 0)', |
| 51 | + backgroundColor: tokens.colors.cardBackground, |
| 52 | + display: 'block', |
| 53 | + textDecoration: 'none', |
| 54 | + color: 'inherit', |
| 55 | + borderRadius: tokens.radii['3'], |
| 56 | + position: 'relative', |
| 57 | + |
| 58 | + '::before': { |
| 59 | + boxSizing: 'border-box', |
| 60 | + content: '""', |
| 61 | + position: 'absolute', |
| 62 | + top: 0, |
| 63 | + right: 0, |
| 64 | + bottom: 0, |
| 65 | + left: 0, |
| 66 | + borderRadius: tokens.radii['3'], |
| 67 | + pointerEvents: 'none', |
| 68 | + }, |
| 69 | +}); |
| 70 | + |
| 71 | +export const cardRecipe = recipe({ |
| 72 | + base: cardBase, |
| 73 | + |
| 74 | + variants: { |
| 75 | + elevation: elevationVariants, |
| 76 | + variant: { |
| 77 | + inner: { |
| 78 | + backgroundColor: tokens.colors.innerCardBgColor, |
| 79 | + }, |
| 80 | + ghost: { |
| 81 | + backgroundColor: 'transparent', |
| 82 | + boxShadow: 'none', |
| 83 | + }, |
| 84 | + }, |
| 85 | + active: { |
| 86 | + true: { |
| 87 | + '::before': { |
| 88 | + outline: `1px solid ${tokens.colors.cardActiveBorder}`, |
| 89 | + backgroundColor: tokens.colors.cardActiveBackground, |
| 90 | + }, |
| 91 | + }, |
| 92 | + }, |
| 93 | + }, |
| 94 | + |
| 95 | + defaultVariants: { |
| 96 | + elevation: 1, |
| 97 | + }, |
| 98 | +}); |
| 99 | + |
| 100 | +// Interactive card styles (for button element) |
| 101 | +const interactiveCardBase = style([ |
| 102 | + cardBase, |
| 103 | + { |
| 104 | + '@media': { |
| 105 | + [breakpoints.hover]: { |
| 106 | + selectors: { |
| 107 | + '&:hover': { |
| 108 | + cursor: 'pointer', |
| 109 | + }, |
| 110 | + '&:hover::before': { |
| 111 | + outline: `1px solid ${tokens.colors.cardHoverBorder}`, |
| 112 | + backgroundColor: tokens.colors.cardHoverBackground, |
| 113 | + }, |
| 114 | + }, |
| 115 | + }, |
| 116 | + }, |
| 117 | + selectors: { |
| 118 | + '&:focus': { |
| 119 | + outline: `2px solid ${tokens.colors.primary}`, |
| 120 | + }, |
| 121 | + '&:active::before': { |
| 122 | + outline: `1px solid ${tokens.colors.cardActiveBorder}`, |
| 123 | + backgroundColor: tokens.colors.cardActiveBackground, |
| 124 | + }, |
| 125 | + }, |
| 126 | + }, |
| 127 | +]); |
| 128 | + |
| 129 | +export const interactiveCardRecipe = recipe({ |
| 130 | + base: interactiveCardBase, |
| 131 | + |
| 132 | + variants: { |
| 133 | + elevation: elevationVariants, |
| 134 | + variant: { |
| 135 | + inner: { |
| 136 | + backgroundColor: tokens.colors.innerCardBgColor, |
| 137 | + }, |
| 138 | + ghost: { |
| 139 | + backgroundColor: 'transparent', |
| 140 | + boxShadow: 'none', |
| 141 | + }, |
| 142 | + }, |
| 143 | + active: { |
| 144 | + true: { |
| 145 | + '::before': { |
| 146 | + outline: `1px solid ${tokens.colors.cardActiveBorder}`, |
| 147 | + backgroundColor: tokens.colors.cardActiveBackground, |
| 148 | + }, |
| 149 | + }, |
| 150 | + }, |
| 151 | + }, |
| 152 | + |
| 153 | + defaultVariants: { |
| 154 | + elevation: 1, |
| 155 | + }, |
| 156 | +}); |
0 commit comments