1.0.2 • Published 3 years ago

react-placards v1.0.2

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

React Placards

Installation

  yarn add react-placards

Getting Started

A default height and width is given to the component but is required to render the component: Refer

  import React from 'react';
  import { Placards } from 'react-placards'
  import {CustomComponents} from '../somepath/CustomComponentLibrary.js'
  function App() {
    const items = [
      {
        id: "content-types",
        content: "You can pass in a plain text string.",
      },
      {
        id: "custom-components",
        content: <CustomComponents
          heading="Custom Components"
          date="31-01-2021"
          description={"OR you can create your own custom components"}
          {...extraProps}
        />
      }, ...];
    return (
      <div className="App">
        <Placards
          items={items}
        />
      </div>
    );
  }
  export default App;

Props

namedescriptionrequireddefault
itemscollection of Item Typetrue[]
widthwidth of the componentfalse200
heightheight of the componentfalse200
timingdelay between card switchfalse5000
cardStylesstyle definitions for Top Card Style Propsfalsecheck Top Card Style Props
stackCardStylesstyle definitions for Stacked Cards Style Propsfalsecheck Stacked Cards Style Props
containerStylesstyle definitions for Container Style Propsfalsecheck Container Style Props

Item Type

namedescriptionrequiredtype
idunique key for each component being renderedtruestring
contentcontent that renders inside the cardstruestring or custom Component
items = [
  {
    id: 'unique-id',
    content: <MyCustomComponent {...props} />
  },
  {
    id: 'unique-id-2',
    content: 'Text content'
  }
];

Top Card Style Props

Use the props below to change the styles of top card.

Note: Top card's styles will be applied to all the item's content

For more control on styles, reset the default styles and create your own Custom Card component

namedescriptionrequireddefault
backgroundColorbackground-color applied to top cardfalse#ffffff
borderRadiusborder-radius applied to ALL sides of top cardfalse0px
boxShadowbox-shadow behind top cardfalse0 15px 35px rgba(50, 50, 93, 0.1),0 5px 15px rgba(0, 0, 0, 0.07)
paddingpadding applied to top cardfalse0px
cardStyles = {
  backgroundColor: 'red',
  borderRadius: '4px',
  boxShadow: '0 10px 30px black',
  padding: '10px'
};

Stacked Card Style Props

namedescriptionrequireddefault
secondColorbackground-color applied to second cardfalse#f0f0f0
thirdColorbackground-color applied to third cardfalse#fafafa
stackCardStyles = {
  secondColor: 'red',
  thirdColor: 'yellow'
};

Container Style Props

use these to place your cards inside the container

namedescriptionrequireddefault
heightheight of the containerfalse200px
widthwidth of the containerfalse200px
overflowoverflow of the containerfalsehidden
paddingpadding of the containerfalse5%
stackCardStyles = {
  height: 200,
  width: 200,
  overflow: 'hidden',
  padding: '5%'
};

Passing custom height/width

By default height & width have been set to 200px. Overide them by passing custom values.

<Placards items={items} width="400" height="400" />

Passing custom timing

By default timing has been set to 5000ms. Overide it by passing custom timing.

<Placards items={items} timing="7000" />

Passing custom styling for Card

Override cardStyles by passing custom styles

<Placards
  items={items}
  cardStyles={{
    padding: '10px',
    borderRadius: '4px',
    ...moreProperties
  }}
/>

Change second and third card's background

Override background colors of second and third cards

<Placards
  items={items}
  stackCardStyles={{
    secondColor: 'red',
    thirdColor: 'yellow'
  }}
/>

Meta

Inspired from Stripe's Announcement Banners. (Sadly has been removed now :'( )

Distributed under the MIT license. See LICENSE for more information.