0.1.6 • Published 4 years ago

@draftcraft/cards v0.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

@draftcraft/cards

Comprehensive React Cards library

NPM JavaScript Style Guide

Requires React > 16.8 for hooks support.

Demo examples availabe here

Install

With npm

npm install --save @draftcraft/cards

...or with yarn

yarn add @draftcraft/cards

Styles

Add the cards style to your project by importing the stylesheet:

import "@draftcraft/cards/dist/index.css";

Usage

Given the nature of a card, the majority of features are predicated on a fixed width. Sizes of cards are calculated as 1.5 times the height of the width for a desireable ratio. As such the Size enum is a property that might be passed to many components. All components in this library can take a className and style prop to override any existing styles.

Possible values for the Size enum that is passed to the size prop in components:

Enum LabelValue
Size.SMALL100
Size.MEDIUM200
Size.LARGE300
Size.XLARGE400

You can also provide any numerical value to the size prop.

Card

The basic card component comes with a few stylistic options that wrap the children passed to it.

import "@draftcraft/cards/dist/index.css";
import React, { Component } from 'react'

import { Card, Size } from '@draftcraft/cards';

export const Example = (props) => {
    return (
      <Card
        size={Size.Large}
        imgUrl={props.url}
        imgAlt={'Alternate Text'}
        shadow
        rounded
      >
        {props.content}
      </Card>
    );
}
PropsTypeRequired
sizeNumberYes
imgUrlStringNo
imgAltStringNo
shadowbooleanNo
roundedbooleanNo

Flippable

Flippable is a component that can flip content from one side to the other. It takes children but only renders the first two children given to it. The first child will render on the front of the flippable content and the second child will render on the back. Any content can be passed to flippable as a child. Below is an example of a flippable Card.

import "@draftcraft/cards/dist/index.css";
import React, { Component } from 'react'

import { Flippable, Card, Size } from '@draftcraft/cards';

export const Example = (props) => {
    return (
      <Flippable
        flipped={props.flipped}
        direction={RotationType.HORIZONTAL}
      >
        <Card
          size={Size.Large}
          imgUrl={props.url}
          imgAlt={'Alternate Text'}
          shadow
          rounded
        >
          {props.frontContent}
        </Card>
        <Card
          size={Size.Large}
          shadow
          rounded
        >
          {props.backContent}
        </Card>
      </Flippable>
    );
}
PropsTypeRequired
flippedbooleanYes
directionRotationType, 'Vertical', or 'Horizontal'Yes

Deck

The Deck component takes any children and stacks them on top of eachother with the option to swipe them left or right. You can provide functions as props that determine what might occur when a card is swiped left vs right.

import "@draftcraft/cards/dist/index.css";
import React, { Component } from 'react'

import { Deck, Card, Size } from '@draftcraft/cards';

export const Example = (props) => {
    return (
      <Deck
        swipeable
        onSwipeLeft={props.swipeLeft}
        onSwipeRight={props.swipeRight}
      >
        <Card
          size={Size.Large}
          imgUrl={props.url}
          imgAlt={'Alternate Text'}
          shadow
          rounded
        >
          First Card
        </Card>
        <Card
          size={Size.Large}
          shadow
          rounded
        >
          Second Card
        </Card>
        <Card
          size={Size.Large}
          shadow
          rounded
        >
          Third Card
        </Card>
      </Deck>
    );
}
PropsTypeRequired
swipeablebooleanNo
onSwipeLeftFunctionNo
onSwipeRightFunctionNo

Card Carousel

The CardCarousel component is used to swipe through a paginated list of cards (or any other children). It is responsive to page resizing and needs to determine the width of each page and each child to determine how many children should be on each page. As such, it takes two required props: cardSize and spacing. If inaccurate values are provided to these props the carousel will not be able to accurately calculate the number of children that should render on each page. The implementation of the CardCarousel component uses another component, PaginationDots, which can be used separately for other implementations if you like.

import "@draftcraft/cards/dist/index.css";
import React, { Component } from 'react'

import { CardCarousel, Card, Size } from '@draftcraft/cards';

export const Example = (props) => {
    return (
      <CardCarousel
        cardSize={Size.Large}
        spacing={10}
        showPagination
        showArrows
      >
        <Card
          size={Size.Large}
          imgUrl={props.url}
          imgAlt={'Alternate Text'}
          shadow
          rounded
        >
          First Card
        </Card>
        <Card
          size={Size.Large}
          shadow
          rounded
        >
          Second Card
        </Card>
        <Card
          size={Size.Large}
          shadow
          rounded
        >
          Third Card
        </Card>
      </CardCarousel>
    );
}
PropsTypeRequired
cardSizeNumberYes
spacingNumberYes
showPaginationbooleanNo
showArrowsbooleanNo

Pagination Dots

import "@draftcraft/cards/dist/index.css";
import React, { Component, useState } from 'react'

import { PaginationDots } from '@draftcraft/cards';

export const Example = (props) => {
  const [index, setIndex] = useState<number>(0);

  return (<PaginationDots
    numOfPages={props.numOfPages}
    currentPage={index}
    onPageSelect={setIndex}
  />);
};
PropsTypeRequired
numOfPagesNumberYes
currentPageNumberYes
onPageSelectFunctionNo

Action

An Action in the cards design system is like a mini card that is used to call attention to an action that may need to occur. This can be used like a button or a bullet point in many cases and can be shaped as a circle (like a poker chip) or a rectangle.

import "@draftcraft/cards/dist/index.css";
import React, { Component } from 'react'

import { Action, Shape } from '@draftcraft/cards';

export const Example = (props) => {

  return (
    <Action
      shape={Shape.RECTANGLE}
      hoverable
      hoverColor={'rgba(255,75,75,.5)'}
    >
      { props.icon }
    </Action>
  );
};
PropsTypeRequired
shapeShapeNo
hoverablebooleanNo
hoverColorbooleanNo

Action Details

The ActionDetails component simply wraps the Action component and provides additional details to the right. It must be provided a description prop that will display text next to the Action component and can optionally also be given a title.

import "@draftcraft/cards/dist/index.css";
import React, { Component } from 'react'

import { ActionDetails, Shape } from '@draftcraft/cards';

export const Example = (props) => {

  return (
    <ActionDetails
      title={'Example Title'}
      description={'This is an Action Details component'}
      shape={Shape.RECTANGLE}
      hoverable
      hoverColor={'rgba(255,75,75,.5)'}
    >
      { props.icon }
    </ActionDetails>
  );
};
PropsTypeRequired
descriptionStringYes
titleStringNo
shapeShapeNo
hoverablebooleanNo
hoverColorbooleanNo

License

MIT © draftcraft Park City Concepts, LLC dba Draftcraft