|
| 1 | +/** |
| 2 | + * @license |
| 3 | + * Copyright (c) 2024 - 2025 Vaadin Ltd. |
| 4 | + * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ |
| 5 | + */ |
| 6 | +import { css } from 'lit'; |
| 7 | + |
| 8 | +export const cardStyles = css` |
| 9 | + :host { |
| 10 | + display: flex; |
| 11 | + flex-direction: column; |
| 12 | + box-sizing: border-box; |
| 13 | + padding: var(--_padding); |
| 14 | + gap: var(--_gap); |
| 15 | + --_padding: var(--vaadin-card-padding, 1em); |
| 16 | + --_gap: var(--vaadin-card-gap, 1em); |
| 17 | + --_media: 0; |
| 18 | + --_title: 0; |
| 19 | + --_subtitle: 0; |
| 20 | + --_header: max(var(--_header-prefix), var(--_title), var(--_subtitle), var(--_header-suffix)); |
| 21 | + --_header-prefix: 0; |
| 22 | + --_header-suffix: 0; |
| 23 | + --_content: 0; |
| 24 | + --_footer: 0; |
| 25 | + } |
| 26 | +
|
| 27 | + :host([hidden]) { |
| 28 | + display: none !important; |
| 29 | + } |
| 30 | +
|
| 31 | + :host(:not([theme~='horizontal'])) { |
| 32 | + justify-content: space-between; |
| 33 | + } |
| 34 | +
|
| 35 | + :host([_m]) { |
| 36 | + --_media: 1; |
| 37 | + } |
| 38 | +
|
| 39 | + :host([_t]) { |
| 40 | + --_title: 1; |
| 41 | + } |
| 42 | +
|
| 43 | + :host([_st]) { |
| 44 | + --_subtitle: 1; |
| 45 | + } |
| 46 | +
|
| 47 | + :host([_h]) { |
| 48 | + --_header: 1; |
| 49 | + --_title: 0; |
| 50 | + --_subtitle: 0; |
| 51 | + } |
| 52 | +
|
| 53 | + :host([_hp]) { |
| 54 | + --_header-prefix: 1; |
| 55 | + } |
| 56 | +
|
| 57 | + :host([_hs]) { |
| 58 | + --_header-suffix: 1; |
| 59 | + } |
| 60 | +
|
| 61 | + :host([_c]) { |
| 62 | + --_content: 1; |
| 63 | + } |
| 64 | +
|
| 65 | + :host([_f]) { |
| 66 | + --_footer: 1; |
| 67 | + } |
| 68 | +
|
| 69 | + [part='media'], |
| 70 | + [part='header'], |
| 71 | + [part='content'], |
| 72 | + [part='footer'] { |
| 73 | + display: none; |
| 74 | + } |
| 75 | +
|
| 76 | + :host([_m]) [part='media'], |
| 77 | + :host([_c]) [part='content'] { |
| 78 | + display: block; |
| 79 | + } |
| 80 | +
|
| 81 | + :host([_f]) [part='footer'] { |
| 82 | + display: flex; |
| 83 | + gap: var(--_gap); |
| 84 | + } |
| 85 | +
|
| 86 | + :host(:is([_h], [_t], [_st], [_hp], [_hs])) [part='header'] { |
| 87 | + display: grid; |
| 88 | + align-items: center; |
| 89 | + gap: var(--_gap); |
| 90 | + row-gap: 0; |
| 91 | + } |
| 92 | +
|
| 93 | + :host([_hs]) [part='header'] { |
| 94 | + grid-template-columns: 1fr auto; |
| 95 | + } |
| 96 | +
|
| 97 | + :host([_hp]) [part='header'] { |
| 98 | + grid-template-columns: repeat(var(--_header-prefix), auto) 1fr; |
| 99 | + } |
| 100 | +
|
| 101 | + slot { |
| 102 | + border-radius: inherit; |
| 103 | + } |
| 104 | +
|
| 105 | + ::slotted([slot='header-prefix']) { |
| 106 | + grid-column: 1; |
| 107 | + grid-row: 1 / span calc(var(--_title) + var(--_subtitle)); |
| 108 | + } |
| 109 | +
|
| 110 | + ::slotted([slot='header']), |
| 111 | + ::slotted([slot='title']) { |
| 112 | + grid-column: calc(1 + var(--_header-prefix)); |
| 113 | + grid-row: 1; |
| 114 | + } |
| 115 | +
|
| 116 | + ::slotted([slot='subtitle']) { |
| 117 | + grid-column: calc(1 + var(--_header-prefix)); |
| 118 | + grid-row: calc(1 + var(--_title)); |
| 119 | + } |
| 120 | +
|
| 121 | + ::slotted([slot='header-suffix']) { |
| 122 | + grid-column: calc(2 + var(--_header-prefix)); |
| 123 | + grid-row: 1 / span calc(var(--_title) + var(--_subtitle)); |
| 124 | + } |
| 125 | +
|
| 126 | + /* Horizontal */ |
| 127 | + :host([theme~='horizontal']) { |
| 128 | + display: grid; |
| 129 | + grid-template-columns: repeat(var(--_media), minmax(auto, max-content)) 1fr; |
| 130 | + align-items: start; |
| 131 | + } |
| 132 | +
|
| 133 | + :host([theme~='horizontal'][_f]) { |
| 134 | + grid-template-rows: 1fr auto; |
| 135 | + } |
| 136 | +
|
| 137 | + :host([theme~='horizontal'][_c]) { |
| 138 | + grid-template-rows: repeat(var(--_header), auto) 1fr; |
| 139 | + } |
| 140 | +
|
| 141 | + [part='media'] { |
| 142 | + grid-column: 1; |
| 143 | + grid-row: 1 / span calc(var(--_header) + var(--_content) + var(--_footer)); |
| 144 | + align-self: stretch; |
| 145 | + border-radius: inherit; |
| 146 | + } |
| 147 | +
|
| 148 | + [part='header'] { |
| 149 | + margin-bottom: auto; |
| 150 | + grid-column: calc(1 + var(--_media)); |
| 151 | + grid-row: 1; |
| 152 | + } |
| 153 | +
|
| 154 | + [part='content'] { |
| 155 | + grid-column: calc(1 + var(--_media)); |
| 156 | + grid-row: calc(1 + var(--_header)); |
| 157 | + flex: auto; |
| 158 | + min-height: 0; |
| 159 | + } |
| 160 | +
|
| 161 | + [part='footer'] { |
| 162 | + grid-column: calc(1 + var(--_media)); |
| 163 | + grid-row: calc(1 + var(--_header) + var(--_content)); |
| 164 | + border-radius: inherit; |
| 165 | + } |
| 166 | +
|
| 167 | + :host([theme~='horizontal']) [part='footer'] { |
| 168 | + align-self: end; |
| 169 | + } |
| 170 | +
|
| 171 | + :host(:not([theme~='horizontal'])) ::slotted([slot='media']:is(img, video, svg)) { |
| 172 | + max-width: 100%; |
| 173 | + } |
| 174 | +
|
| 175 | + ::slotted([slot='media']) { |
| 176 | + vertical-align: middle; |
| 177 | + } |
| 178 | +
|
| 179 | + :host(:is([theme~='cover-media'], [theme~='stretch-media'])) |
| 180 | + ::slotted([slot='media']:is(img, video, svg, vaadin-icon)) { |
| 181 | + width: 100%; |
| 182 | + height: auto; |
| 183 | + aspect-ratio: var(--vaadin-card-media-aspect-ratio, 16/9); |
| 184 | + object-fit: cover; |
| 185 | + /* Fixes an issue where an icon overflows the card boundaries on Firefox: https://github.com/vaadin/web-components/issues/8641 */ |
| 186 | + overflow: hidden; |
| 187 | + } |
| 188 | +
|
| 189 | + :host([theme~='horizontal']:is([theme~='cover-media'], [theme~='stretch-media'])) { |
| 190 | + grid-template-columns: repeat(var(--_media), minmax(auto, 0.5fr)) 1fr; |
| 191 | + } |
| 192 | +
|
| 193 | + :host([theme~='horizontal']:is([theme~='cover-media'], [theme~='stretch-media'])) |
| 194 | + ::slotted([slot='media']:is(img, video, svg, vaadin-icon)) { |
| 195 | + height: 100%; |
| 196 | + aspect-ratio: auto; |
| 197 | + } |
| 198 | +
|
| 199 | + :host([theme~='cover-media']) ::slotted([slot='media']:is(img, video, svg, vaadin-icon)) { |
| 200 | + margin-top: calc(var(--_padding) * -1); |
| 201 | + margin-inline: calc(var(--_padding) * -1); |
| 202 | + width: calc(100% + var(--_padding) * 2); |
| 203 | + max-width: none; |
| 204 | + border-radius: inherit; |
| 205 | + border-end-end-radius: 0; |
| 206 | + border-end-start-radius: 0; |
| 207 | + } |
| 208 | +
|
| 209 | + :host([theme~='horizontal'][theme~='cover-media']) ::slotted([slot='media']:is(img, video, svg, vaadin-icon)) { |
| 210 | + margin-inline-end: 0; |
| 211 | + width: calc(100% + var(--_padding)); |
| 212 | + height: calc(100% + var(--_padding) * 2); |
| 213 | + border-radius: inherit; |
| 214 | + border-start-end-radius: 0; |
| 215 | + border-end-end-radius: 0; |
| 216 | + } |
| 217 | +
|
| 218 | + /* Scroller in content */ |
| 219 | + [part='content'] ::slotted(vaadin-scroller) { |
| 220 | + margin-inline: calc(var(--_padding) * -1); |
| 221 | + padding-inline: var(--_padding); |
| 222 | + } |
| 223 | +
|
| 224 | + [part='content'] ::slotted(vaadin-scroller)::before, |
| 225 | + [part='content'] ::slotted(vaadin-scroller)::after { |
| 226 | + margin-inline: calc(var(--_padding) * -1); |
| 227 | + } |
| 228 | +`; |
0 commit comments