logo polydile dile-components

dile-card

Web Component to create a customized Card.

Installation

npm i @dile/dile-card

Usage

Import the component

import '@dile/dile-card/dile-card.js';

Use the component

<dile-card shadow-md title="Welcome to this card">
  <div>
    This card has title and main body
  </div>
  <div slot="footer">
    <a href="#">Action 1</a>
  </div>
</dile-card>

Slots

This component has two slots.

Properties

Shadow attributes

By default the card has a light shadow (between sm and md). but you can set the shadow using some attributes.

If a responsive shadow needed, you can use the --dile-card-box-shadow CSS Custom property.

dile-card {
  --dile-card-box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
}
@media(min-width: 500px) {
  dile-card {
    --dile-card-box-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
  } 
}

CSS Custom Properties

You can customize it using CSS Custom Properties.

Custom propertyDescriptionDefault
--dile-card-padding-yVertical padding0.5rem
--dile-card-padding-xHorizontal padding0.8rem
--dile-card-borderCard border1px solid #ccc
--dile-card-border-radiusCard border radius0.5rem
--dile-card-background-colorBackground color#fff
--dile-card-text-colorText color#303030
--dile-card-text-alignText alignleft
--dile-card-font-weightFont weightnormal
--dile-card-title-font-sizeTitle font size1.5rem
--dile-card-title-colorTitle text color--dile-card-text-color or #303030
--dile-card-title-font-weightTitle font weight300
--dile-card-title-margin-bottomAditional margin-bottom for the title0
--dile-card-footer-border-separatorFooter border separator1px solid #ccc
--dile-card-footer-background-colorFooter background colortransparent
--dile-card-footer-padding-topFooter padding top0.75rem
--dile-card-box-shadowBox shadowDefined by the shadow attributes

dile-card demos

Regular card

<style>
  dile-card {
    margin: 1.2rem;
  }
</style>
<dile-card shadow-sm>This card has only main body</dile-card>

Card with title

<style>
  dile-card {
    margin: 1.2rem;
  }
</style>
<dile-card shadow-xl title="Welcome to this card">This card has title and main body</dile-card>

Card with title, footer and main content

<style>
  dile-card {
    margin: 1.2rem;
  }
</style>
<dile-card shadow-md title="Welcome to this card">
  <div>
    This card has title and main body
  </div>
  <div slot="footer">
    <a href="#">Action test</a>
  </div>
</dile-card>

Styled card

<style>
  .styled {
    --dile-card-border: 2px solid #add;
    --dile-card-border-radius: 20px;
    --dile-card-background-color: #f4f4f4;
    --dile-card-text-color: #36f;
    --dile-card-title-font-weight: 700;
    --dile-card-footer-border-separator: 2px solid #add;
    --dile-card-footer-background-color: #eff;
    --dile-card-footer-padding-top: 12px;
  }
  .footer-styled {
    color: #666;
  }
</style>
<dile-card shadow-none title="I am a styled card" class="styled">
  Styled card main content
  <span slot="footer" class="footer-styled">
    Footer content
  </span>
</dile-card>

Responsive card

<style>
  .responsive-card {
    --dile-card-box-shadow: 0 0 #0000;
    --dile-card-border-radius: 1px;
  }
  @media (min-width: 400px) {
    .responsive-card {
      --dile-card-border-radius: 5px;
      --dile-card-box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    }
  }
  @media (min-width: 600px) {
    .responsive-card {
      --dile-card-border-radius: 10px;
      --dile-card-box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    }
  }
  @media (min-width: 800px) {
    .responsive-card {
      --dile-card-border-radius: 15px;
      --dile-card-box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    }
  }
</style>
<dile-card class="responsive-card" title="Shadow responsive">
  The shadow of this card has a responsive change.
</dile-card>