Liking cljdoc? Tell your friends :D

x-card

Themeable surface container for grouping related content.

Attributes

AttributeValuesDefault
variantelevated | outlined | filled | ghostelevated
paddingnone | sm | md | lgmd
radiusnone | sm | md | lg | xllg
interactiveboolean (presence)absent
disabledboolean (presence)absent
labelstring—

Properties

PropertyTypeReflects to attribute
interactivebooleanyes (interactive)
disabledbooleanyes (disabled)
variantstringyes (variant), default "elevated"
paddingstringyes (padding), default "md"
radiusstringyes (radius), default "lg"
labelstringyes (label), default ""

Event

EventDetailBubblesComposed
press{}yesyes

Fired on click, Enter, or Space when interactive is set and disabled is absent.

Accessibility

Default state: no role or tabindex set.

Interactive mode:

  • role="button" added to host
  • tabindex="0" (focusable) when not disabled
  • tabindex="-1" (non-focusable) when disabled
  • aria-disabled="true" when disabled
  • Enter and Space trigger press; Space also calls preventDefault

The label attribute maps to aria-label on the host.

Slot

Default slot only. Accepts arbitrary content.

Styling

Override CSS custom properties on the host element:

x-card {
  --x-card-background: white;
  --x-card-color: black;
}

Custom properties

PropertyDefault (light)Purpose
--x-card-backgroundvar(--x-color-surface, rgba(255, 255, 255, 0.92))Base surface colour
--x-card-colorvar(--x-color-text, #111827)Text colour
--x-card-border-colorvar(--x-color-border, rgba(17, 24, 39, 0.12))Outlined variant border
--x-card-filled-backgroundvar(--x-color-surface-active, rgba(241, 245, 249, 0.96))Filled variant surface
--x-card-ghost-backgroundtransparentGhost variant surface
--x-card-hover-backgroundvar(--x-color-surface-hover, rgba(15, 23, 42, 0.04))Interactive hover state
--x-card-press-backgroundvar(--x-color-surface-active, rgba(15, 23, 42, 0.08))Interactive active/press state
--x-card-shadowvar(--x-shadow-md, 0 10px 24px rgba(15, 23, 42, 0.10))Elevated variant shadow
--x-card-focus-ringvar(--x-color-focus-ring, rgba(59, 130, 246, 0.55))Focus ring colour
--x-card-disabled-opacity0.6Opacity when disabled
--x-card-padding-none0Padding token — none
--x-card-padding-sm0.5remPadding token — sm
--x-card-padding-md1remPadding token — md
--x-card-padding-lg1.5remPadding token — lg
--x-card-radius-none0Radius token — none
--x-card-radius-smvar(--x-radius-sm, 0.375rem)Radius token — sm
--x-card-radius-mdvar(--x-radius-md, 0.75rem)Radius token — md
--x-card-radius-lgvar(--x-radius-lg, 1rem)Radius token — lg
--x-card-radius-xlvar(--x-radius-xl,1.5rem)Radius token — xl
--x-card-transition-durationvar(--x-transition-duration, 140ms)Hover/press transition speed
--x-card-transition-timingvar(--x-transition-easing,ease)Hover/press transition easing

Dark mode values are set automatically via @media (prefers-color-scheme: dark). Transition animations are suppressed via @media (prefers-reduced-motion: reduce).

Internal styling hooks (part="base")

The inner wrapper div carries part="base" and the following data-* attributes that can be targeted in external stylesheets:

AttributeValues
data-variantelevated | outlined | filled | ghost
data-paddingnone | sm | md | lg
data-radiusnone | sm | md | lg | xl
data-interactive"true" or absent
data-disabled"true" or absent

Note: data-* values reflect the normalised value, not the raw attribute. Invalid attribute values are silently corrected to the default.

Example

<!-- Static card -->
<x-card variant="outlined" padding="md">
  <h3>Title</h3>
  <p>Content here.</p>
</x-card>

<!-- Interactive card -->
<x-card variant="elevated" padding="md" interactive label="Open details">
  <h3>Click me</h3>
  <p>Fires a press event.</p>
</x-card>

<script>
  document.querySelector('x-card[interactive]')
    .addEventListener('press', () => console.log('pressed'));
</script>

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close