Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | 125x 135x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 123x 123x 125x 125x 125x 125x 125x 122x 122x 146x 123x 123x 123x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 125x 2x 2x 2x 2x 2x 2x 5x 5x 5x 5x 5x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 149x 149x 123x 123x 123x 123x 123x 123x 123x 123x 123x 123x 149x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x 125x | import { css, html, TemplateResult } from 'lit';
import { property } from 'lit/decorators.js';
import { RapidElement } from '../RapidElement';
import { designTokens } from '../styles/designTokens';
import { getClasses } from '../utils';
import { Icon } from '../Icons';
/**
* A collapsible card with a header showing an icon, label and optional
* count badge. Designed to live inside a temba-card-stack where the header
* doubles as the drag handle, but works standalone too. The body never
* scrolls internally — cards grow to their content.
*/
export class Card extends RapidElement {
static get styles() {
return css`
${designTokens}
:host {
display: block;
/* as a grid/flex item (cards flatten into the card stack's
grid through its slots) the automatic minimum is
min-content — allow shrinking so long unbreakable content
inside ellipsizes instead of widening the card */
min-width: 0;
}
/* an empty panel drops its card entirely — in tab (plain) mode the
pane still renders so the tab keeps working */
:host([empty]:not([plain])) {
display: none;
}
/* The chrome lives on an inner frame rather than the host so
document-level universal rules (e.g. tailwind's preflight
border-color) can't override it. */
.frame {
background: var(--card-bg, var(--surface));
border: 1px solid var(--card-border, var(--border-strong));
border-radius: var(--r-sm);
box-shadow: var(--shadow-2);
}
/* note variant — the sticky-note surface, header included */
:host([variant='note']) .frame {
background: var(--surface-note);
border-color: var(--border-note);
}
.card-header {
display: flex;
align-items: center;
padding: 8px 10px;
cursor: pointer;
user-select: none;
border-radius: var(--r-sm);
}
.card-header temba-icon {
--icon-color: var(--text-3);
}
.grip {
margin-right: 0.5em;
cursor: grab;
--icon-color: var(--text-4);
}
.card-header:hover .grip {
--icon-color: var(--text-3);
}
.label {
display: flex;
align-items: center;
flex-grow: 1;
font-size: 13px;
font-weight: var(--w-medium);
color: var(--text-2);
}
.label temba-icon {
margin-right: 0.5em;
}
.count {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 16px;
height: 16px;
padding: 0 4px;
margin-right: 0.5em;
border-radius: 999px;
background: var(--accent-100);
color: var(--accent-700);
font-size: 11px;
font-weight: var(--w-semibold);
font-variant-numeric: tabular-nums;
}
.dot {
height: 0.5em;
width: 0.5em;
margin-right: 0.5em;
background: var(--accent-600);
border-radius: 99px;
}
.toggle {
transition: transform 200ms ease;
}
.toggle.collapsed {
transform: rotate(-90deg);
}
/* Grid trick so collapse animates to natural content height without
capping how tall an expanded card can grow. */
.body {
display: grid;
grid-template-rows: 1fr;
/* the implicit column track is auto-sized and would grow to
the content's max-content (one long unbreakable line widens
the card instead of ellipsizing) — pin it to the card width */
grid-template-columns: minmax(0, 1fr);
transition: grid-template-rows 200ms ease;
}
.body.collapsed {
grid-template-rows: 0fr;
}
.inner {
min-height: 0;
overflow: hidden;
}
/* once fully expanded, let popovers (date pickers etc.) escape */
.body:not(.collapsed):not(.animating) .inner {
overflow: visible;
}
.content {
padding: 0 10px 10px;
}
/* card chrome bounds the panel tightly — slotted panels scale their
empty-state treatment down from the roomy tab-pane default to a
single quiet line */
:host(:not([plain])) .content ::slotted(*) {
--empty-padding: 1em;
--empty-extras-display: none;
--empty-title-size: 0.9em;
--empty-title-color: var(--text-3);
}
/* bleed mode: the body content runs edge-to-edge so a panel with its
own surface (e.g. the notepad) fills the card, clipped to the card
radius. The footer of such content sits on the card's bottom edge. */
:host([bleed]) .content {
padding: 0;
}
:host([bleed]) .body:not(.collapsed):not(.animating) .inner {
overflow: hidden;
border-radius: 0 0 var(--r-sm) var(--r-sm);
}
/* plain mode: headerless and non-collapsible — the wrapper (e.g. a
tab pane) supplies the label — but still a proper card surface
with padding. Fills its pane and scrolls its content internally,
since a tab pane is height-bounded. */
:host([plain]) {
display: flex;
flex-direction: column;
flex-grow: 1;
min-height: 0;
margin-top: var(--layout-spacing, 8px);
margin-bottom: var(--layout-spacing, 8px);
}
:host([plain]) .frame,
:host([plain]) .body,
:host([plain]) .inner {
display: flex;
flex-direction: column;
flex-grow: 1;
min-height: 0;
overflow: hidden;
}
:host([plain]) .inner {
border-radius: var(--r-sm);
}
:host([plain]) .content {
display: flex;
flex-direction: column;
flex-grow: 1;
min-height: 0;
padding: 10px;
overflow-y: auto;
}
/* no header row in plain mode, so bleeding content gets a top inset
directly against the card surface */
:host([plain][bleed]) .content {
padding: 10px 0 0 0;
}
`;
}
@property({ type: String })
label = '';
@property({ type: String })
icon = '';
@property({ type: Number })
count = 0;
// show a dot instead of the count
@property({ type: Boolean })
activity = false;
@property({ type: Boolean, reflect: true })
collapsed = false;
// render without chrome (no header, border or collapse) — content only
@property({ type: Boolean, reflect: true })
plain = false;
// body content runs edge-to-edge instead of getting the inset padding
@property({ type: Boolean, reflect: true })
bleed = false;
// the slotted panel reported (via temba-details-changed) that it has
// nothing to show — the card hides entirely in card mode, though its
// tab remains available in narrow mode
@property({ type: Boolean, reflect: true })
empty = false;
// named surface treatments, e.g. "note" for the sticky-note look
@property({ type: String, reflect: true })
variant = '';
@property({ type: Boolean })
dirty = false;
private animating = false;
private handleHeaderClick() {
this.collapsed = !this.collapsed;
this.animating = true;
this.requestUpdate();
this.dispatchEvent(
new CustomEvent('toggle', {
bubbles: true,
composed: true,
detail: { collapsed: this.collapsed, label: this.label }
})
);
}
private handleTransitionEnd(event: TransitionEvent) {
// transitionend bubbles composed out of slotted content — only our own
// grid collapse animation should clear the clipping state
if (
event.target !== event.currentTarget ||
event.propertyName !== 'grid-template-rows'
) {
return;
}
this.animating = false;
this.requestUpdate();
}
private handleDetailsChanged(event: CustomEvent) {
if ('dirty' in event.detail) {
this.dirty = event.detail.dirty;
}
if ('count' in event.detail) {
this.count = event.detail.count;
}
if ('empty' in event.detail) {
this.empty = event.detail.empty;
}
}
public render(): TemplateResult {
if (this.plain) {
return html`
<div class="frame">
<div class="body">
<div class="inner">
<div class="content">
<slot
@temba-details-changed=${this.handleDetailsChanged}
></slot>
</div>
</div>
</div>
</div>
`;
}
return html`
<div class="frame">
<div class="card-header" @click=${this.handleHeaderClick}>
<temba-icon name=${Icon.drag} class="grip"></temba-icon>
<div class="label">
${this.icon
? html`<temba-icon name=${this.icon}></temba-icon>`
: null}
${this.label}${this.dirty ? ' *' : ''}
</div>
<slot name="header-actions"></slot>
${this.count > 0
? this.activity
? html`<div class="dot"></div>`
: html`<div class="count">${this.count.toLocaleString()}</div>`
: null}
<temba-icon
name=${Icon.arrow_down}
class="toggle ${this.collapsed ? 'collapsed' : ''}"
></temba-icon>
</div>
<div
class="body ${getClasses({
collapsed: this.collapsed,
animating: this.animating
})}"
@transitionend=${this.handleTransitionEnd}
>
<div class="inner">
<div class="content">
<slot @temba-details-changed=${this.handleDetailsChanged}></slot>
</div>
</div>
</div>
</div>
`;
}
}
|