|
| 1 | +import React from 'react' |
| 2 | +import { th, system } from '@xstyled/system' |
| 3 | +import { node } from 'prop-desc' |
| 4 | +import { css, createComponent, getSystemPropTypes } from './util' |
| 5 | +import * as theme from './theme/common' |
| 6 | + |
| 7 | +export const Card = createComponent({ |
| 8 | + name: 'Card', |
| 9 | + render: ({ as: As = 'div', ...props }) => <As {...props} />, |
| 10 | + theme: [ |
| 11 | + theme, |
| 12 | + { |
| 13 | + components: { |
| 14 | + Card: p => { |
| 15 | + return css` |
| 16 | + position: relative; |
| 17 | + display: flex; |
| 18 | + flex-direction: column; |
| 19 | + min-width: 0; |
| 20 | + word-wrap: break-word; |
| 21 | + background-color: ${th.color('white')(p)}; |
| 22 | + background-clip: border-box; |
| 23 | + border: 0.0625rem solid; |
| 24 | + border-color: ${th.color('highlightBorder')(p)}; |
| 25 | + border-radius: ${th.radius('base')(p)}; |
| 26 | + font-family: ${th.font('base')(p)}; |
| 27 | +
|
| 28 | + && { |
| 29 | + ${system(p)} |
| 30 | + } |
| 31 | + ` |
| 32 | + }, |
| 33 | + }, |
| 34 | + }, |
| 35 | + ], |
| 36 | + propTypes: { |
| 37 | + children: node, |
| 38 | + ...getSystemPropTypes(system), |
| 39 | + }, |
| 40 | +}) |
| 41 | + |
| 42 | +export const CardBody = createComponent({ |
| 43 | + name: 'CardBody', |
| 44 | + render: ({ as: As = 'div', ...props }) => <As {...props} />, |
| 45 | + theme: [ |
| 46 | + theme, |
| 47 | + { |
| 48 | + components: { |
| 49 | + CardBody: p => { |
| 50 | + return css` |
| 51 | + flex: 1 1 auto; |
| 52 | + padding: 20rpx; |
| 53 | +
|
| 54 | + && { |
| 55 | + ${system(p)} |
| 56 | + } |
| 57 | + ` |
| 58 | + }, |
| 59 | + }, |
| 60 | + }, |
| 61 | + ], |
| 62 | + propTypes: { |
| 63 | + children: node, |
| 64 | + ...getSystemPropTypes(system), |
| 65 | + }, |
| 66 | +}) |
| 67 | + |
| 68 | +export const CardTitle = createComponent({ |
| 69 | + name: 'CardTitle', |
| 70 | + render: ({ as: As = 'div', ...props }) => <As {...props} />, |
| 71 | + theme: [ |
| 72 | + theme, |
| 73 | + { |
| 74 | + components: { |
| 75 | + CardTitle: p => { |
| 76 | + return css` |
| 77 | + margin-bottom: 12rpx; |
| 78 | +
|
| 79 | + && { |
| 80 | + ${system(p)} |
| 81 | + } |
| 82 | + ` |
| 83 | + }, |
| 84 | + }, |
| 85 | + }, |
| 86 | + ], |
| 87 | + propTypes: { |
| 88 | + children: node, |
| 89 | + ...getSystemPropTypes(system), |
| 90 | + }, |
| 91 | +}) |
| 92 | + |
| 93 | +export const CardText = createComponent({ |
| 94 | + name: 'CardText', |
| 95 | + render: ({ as: As = 'p', ...props }) => <As {...props} />, |
| 96 | + theme: [ |
| 97 | + theme, |
| 98 | + { |
| 99 | + components: { |
| 100 | + CardText: p => { |
| 101 | + return css` |
| 102 | + &:last-child { |
| 103 | + margin-bottom: 0; |
| 104 | + } |
| 105 | +
|
| 106 | + && { |
| 107 | + ${system(p)} |
| 108 | + } |
| 109 | + ` |
| 110 | + }, |
| 111 | + }, |
| 112 | + }, |
| 113 | + ], |
| 114 | + propTypes: { |
| 115 | + children: node, |
| 116 | + ...getSystemPropTypes(system), |
| 117 | + }, |
| 118 | +}) |
| 119 | + |
| 120 | +export const CardHeader = createComponent({ |
| 121 | + name: 'CardHeader', |
| 122 | + render: ({ as: As = 'div', ...props }) => <As {...props} />, |
| 123 | + theme: [ |
| 124 | + theme, |
| 125 | + { |
| 126 | + components: { |
| 127 | + CardHeader: p => { |
| 128 | + const baseRadius = th.radius('base')(p) |
| 129 | + return css` |
| 130 | + padding: 0.75rem 1.25rem; |
| 131 | + margin-bottom: 0; /* Removes the default margin-bottom of <hN> */ |
| 132 | + background-color: ${th.color('highlightBackground')(p)}; |
| 133 | + border-bottom: 0.0625rem; |
| 134 | + border-bottom-color: ${th.color('highlightBorder')(p)}; |
| 135 | +
|
| 136 | + &:first-child { |
| 137 | + border-radius: calc(${baseRadius} - 1px) calc(${baseRadius} - 1px) |
| 138 | + 0 0; |
| 139 | + } |
| 140 | +
|
| 141 | + && { |
| 142 | + ${system(p)} |
| 143 | + } |
| 144 | + ` |
| 145 | + }, |
| 146 | + }, |
| 147 | + }, |
| 148 | + ], |
| 149 | + propTypes: { |
| 150 | + children: node, |
| 151 | + ...getSystemPropTypes(system), |
| 152 | + }, |
| 153 | +}) |
| 154 | + |
| 155 | +export const CardFooter = createComponent({ |
| 156 | + name: 'CardFooter', |
| 157 | + render: ({ as: As = 'div', ...props }) => <As {...props} />, |
| 158 | + theme: [ |
| 159 | + theme, |
| 160 | + { |
| 161 | + components: { |
| 162 | + CardFooter: p => { |
| 163 | + const baseRadius = th.radius('base')(p) |
| 164 | + return css` |
| 165 | + padding: 0.75rem 1.25rem; |
| 166 | + background-color: ${th.color('highlightBackground')(p)}; |
| 167 | + border-top: 0.0625rem; |
| 168 | + border-top-color: ${th.color('highlightBorder')(p)}; |
| 169 | +
|
| 170 | + &:last-child { |
| 171 | + border-radius: 0 0 calc(${baseRadius} - 1px) |
| 172 | + calc(${baseRadius} - 1px); |
| 173 | + } |
| 174 | +
|
| 175 | + && { |
| 176 | + ${system(p)} |
| 177 | + } |
| 178 | + ` |
| 179 | + }, |
| 180 | + }, |
| 181 | + }, |
| 182 | + ], |
| 183 | + propTypes: { |
| 184 | + children: node, |
| 185 | + ...getSystemPropTypes(system), |
| 186 | + }, |
| 187 | +}) |
| 188 | + |
| 189 | +export const CardImg = createComponent({ |
| 190 | + name: 'CardImg', |
| 191 | + render: ({ as: As = 'img', ...props }) => <As {...props} />, |
| 192 | + theme: [ |
| 193 | + theme, |
| 194 | + { |
| 195 | + components: { |
| 196 | + CardImg: p => { |
| 197 | + const baseRadius = th.radius('base')(p) |
| 198 | + return css` |
| 199 | + flex-shrink: 0; /* For IE: https://github.com/twbs/bootstrap/issues/29396 */ |
| 200 | + width: 100%; /* Required because we use flexbox and this inherently applies align-self: stretch */ |
| 201 | +
|
| 202 | + &:first-child { |
| 203 | + border-radius: calc(${baseRadius} - 1px) calc(${baseRadius} - 1px) |
| 204 | + 0 0; |
| 205 | + } |
| 206 | +
|
| 207 | + &:last-child { |
| 208 | + border-radius: 0 0 calc(${baseRadius} - 1px) |
| 209 | + calc(${baseRadius} - 1px); |
| 210 | + } |
| 211 | +
|
| 212 | + && { |
| 213 | + ${system(p)} |
| 214 | + } |
| 215 | + ` |
| 216 | + }, |
| 217 | + }, |
| 218 | + }, |
| 219 | + ], |
| 220 | + propTypes: { |
| 221 | + children: node, |
| 222 | + ...getSystemPropTypes(system), |
| 223 | + }, |
| 224 | +}) |
0 commit comments