Card Deck
Web Component

Simple swappable card deck

No more cards :(
Go to Github Go to NPM

How to use

An event named discard is triggered by the <card-desk> component when a card is removed from the deck. Event Detail Properties:

CSS and Component Import

To use the component, ensure you include the CSS from the dist folder, as the package only includes the Web Component JavaScript when imported into your project.

<link rel="stylesheet" href="@salvadorsru/card-deck/dist/style.min.css" />
<script type="module" src="@salvadorsru/card-deck/index.min.js"></script>

Alternatively, you can import the package directly in your JavaScript/TypeScript files:

import "@salvadorsru/card-deck";

Note: Importing the package via JavaScript does not include the CSS. You will need to manually include the CSS from the dist folder in your project.

The event’s detail includes the direction in which the card was removed and a full reference to the HTML element.

Behavior

These variables allow flexibility in adjusting the appearance and behavior of the card deck without modifying the core CSS.

Events

The card-deck component emits a custom event named discard whenever a card is removed from the deck.

An event called cardRemoved is also emitted when a card has been discarded and is permanently removed. This means that the discarded card has completely disappeared from the screen after its animation finishes, and its HTML element has been remove

Triggered By: The <card-desk> component when a card is removed.

Event Detail Properties:

Use example

Basic usage

You can statically define all the elements as follows:

<card-deck>
  // Card container
  <div></div>
  // Card container
  <div></div>
  // Card container
</card-deck>

External card deck management

You can programmatically control the behavior of a <card-deck> using the following subpackage.

Include via HTML

<script type="module" src="@salvadorsru/card-deck/emulate.min.js"></script>

Or import via JavaScript

import emulate from "@salvadorsru/card-deck/emulate";
// or
import { discardToRight, discardToLeft } from "@salvadorsru/card-deck/emulate";

This module provides the discardToRight and discardToLeft functions, which allow you to move the card deck to the right or left through code, easily and programmatically.

Example Usage

import { discardToRight, discardToLeft } from "@salvadorsru/card-deck/emulate";

const $deck = document.querySelector("card-deck");

discardToRight($deck);
// or
discardToLeft($deck);

CSS Variables for card-deck

The card-deck component supports various CSS variables to allow customization of its appearance and behavior.

Size Variables

Animation Variables