1.3.0 • Published 3 years ago

react-cool-cards v1.3.0

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

react-cool-cards

A cool way to display cards in React.js

NPM JavaScript Style Guide

Install

npm install --save react-cool-cards

Usage

import React from 'react'
import './App.css'

import {Cards, Card} from 'react-cool-cards'

const App = () => {

  const settings = {
    width: '300px',
    maxWidth: '500px',
    height: '300px',
    maxHeight: '300px',
    margin: '30px',
    shadow: true,
    theme : {
      color: 'red',
      type: 'rounded',
      fill: 'gradient'
    }
  }

  return (
      <div>
      <Cards common={settings}>
        <Card>
          This is a Card
        </Card>
        <Card>
          This is a Card
        </Card>
        <Card>
          This is a Card
        </Card>
        <Card>
          This is a Card
        </Card>
      </Cards>
      </div>
  )
}

Component Props

Cards Wrapper

The Cards Wrapper Component acts as a div in form of a row.

property nametypedescription
backgroundany color e.g. #FFFFFFDefines the background color
paddingany padding value e.g. 10pxDefines the inner padding
paddingSideany padding value e.g. 10pxDefines the left and right padding
commonan objectDefines a common style object for all the child Card Components
<Cards padding={'50px'} background={'#FFFFFF'} common={settings}>
  <Card>
    Card Content
  </Card>
</Cards>

Card Component

property nameoptionsdescription
widthvalue of width e.g. 100pxsets the minimum width of the card
maxWidthvalue of width e.g. 150pxsets the maximum width the card can grow to due to flex grow - you can keep it the same value as width to have a fixed size
heightvalue of height e.g. 200pxsets the minimum height of the card
maxHeightvalue of height e.g. 200pxsets the maximum height of the card
marginvalue of margin e.g. 15pxsets the margin between cards
shadowboolean e.g. truesets a default shadow to override this shadow, set the 'style' prop to custom and define it in CSS
overflowvalue for overflow e.g. hiddensets the overflow in the card.
Theme property nameoptionsdescription
color'red', 'blue', 'green', 'dark'sets the theme color of the card
type'rounded', 'square'sets the corners of the card
fill'solid', 'gradient'sets the fill type of the card. by default, it's set to gradient
animation'grow', 'shrink', 'rotate'sets different types of pre-made animations to the cards

Make sure you've defined 'theme' as an object in the settings prop as shown below.

const App = () => {

  const settings = {
    width: '300px',
    maxWidth: '500px',
    height: '300px',
    maxHeight: '300px',
    margin: '30px',
    shadow: true,
    theme : {
      color: 'red',
      type: 'rounded',
      fill: 'gradient'
    }
  }

  return (
      <div>
      <Cards common={settings}>
        <Card>
          This is a Card
        </Card>
        <Card>
          This is a Card
        </Card>
        <Card>
          This is a Card
        </Card>
        <Card>
          This is a Card
        </Card>
      </Cards>
      </div>
  )
}

The 'settings' prop

The syntax for providing styles of a card is

const settings = {
  // All the general styels of the card here
  theme: {
    // Theme styles here
  }
}

The 'common' prop

To define every card's style and theme, you need to pass in a prop called 'settings' in the Card Wrapper Component (Cards) with an object containing the necessary settings

This is useful as you don't have to keep passing in a settings object to each card.

While you use the common prop and you want to style a custom card you can pass the settings of the Card with a custom object as shown below

const settings = {
  // Common Styles
}

const custom = {
  // Individual custom style for the 1st card
}

<Cards common={settings}>
  <Card settings={custom}>
    Card Content
  </Card>
</Cards>

Default Styles

Theme

If not specified, but the theme object has been created with a color, the default theme has a soft gradient of the color and rounded corners.

The current theme colors are:

  1. Red
  2. Green
  3. Blue
  4. Dark (A Dark grey card used in darkmode)

You can also add any hex color / background image (gradients) resulting in a solid background of your hex color

General Styles

If not specified, the Card component has its own defined styles for its inner content. To override this settings pass the 'style: 'custom'' property in the General styles section of the settings object

CSS Classes

To access the Card Wrapper Class use the classname '.cool-card-wrapper'

To access the Card Class use the classname '.cool-card'

License

MIT © AnshC

1.3.0

3 years ago

1.2.0

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.1

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago