npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jouwomgeving/react-cardsort

v2.0.3

Published

Jouw Omgeving React Cardsort component.

Downloads

51

Readme

@jouwomgeving/react-cardsort

Jouw Omgeving React Cardsort component.

Installation

Install this package and its peerDependencies:

$ npm i -S @jouwomgeving/react-cardsort \
    classnames \
    react \
    react-dnd \
    react-dnd-html5-backend \
    react-dnd-touch-backend \
    react-motion

Usage

import Cardsort /* component */, {
  // state reducers
  drop, // drop card in a pile
  pull, // (optional) pull highest card in stack to bottom
  push  // (optional) push lowest card in stack to top
} from '@jouwomgeving/react-cardsort';

This automatically wraps the Cardsort board with react-dnd's DragDropContext. If you already have an existing DragDropContext higher up the component hierarchy (e.g. at route level), you should just import the Board component:

import { 
  Board,
  drop, 
  // ...
},  from '@jouwomgeving/react-cardsort';

Provide the following props with your Cardsort HoC:

  • {Object} actions: state manager methods that wrap the component methods with the same name
    • {Function} drop
    • {Function} [pull]
    • {Function} [push]
  • {Object} board: state
  • {Object} [content] (optional):
    • object of custom content formatters where the key is a pile value and the value a function that receives the card props and returns a React element
  • {Function} [formatSourceCaption]: add a caption to the start pile
  • {Function} [formatTargetCaption]: format the target pile label
  • {boolean} [hasRedo=true]: prevents dragging a dropped card again if false
  • {boolean} [isCompact=true]: expands all cards in a pile if false
  • next / prev: React elements that trigger the pull/push actions from the UI
  • {Object} theme: CSS module selectors
    • .Board
    • .Board-group
    • .Board-compact
    • .Pile
    • .Pile-hover
    • .Card
    • .Card-figure
    • .Card-image
    • .Card-text
    • .Card-valid
    • .Card-wallpaper

State signature

Note: this state can be serialized; for complex card formatting options, see the content property above.

const myState = {
  cards: [
    {
      {string} id, // unique identifier
      {string} pile, // current pile value
      {string} [image], // image URL, takes precedence over 'text'
        // - set as a background image because of cross browser problems with SVG dragging
        // - 'text' is used for the title attribute
      {string} [template=wallpaper], // fills the card with 'image' 
      {string} [template=figure], // like wallpaper, but displays 'text' as a caption 
      {string} [text], // text content 
      {Array} [values], // valid pile values 
    },
    // ...
  ],
  piles: [
    {
      image: "", // optional
      label: "", // optional
      text: "",
      value: "",
    },
    // ...
  ],
  groups: [ // optional
    [0],
    [1, 2],
    // ...
  ],
};

If groups is omitted, it defaults to

[
  [0],
  [/* the remaining card indices */],
]

Run the example (sources and hot-loader)

$ npm install
$ cd ./example
$ npm start

TODO

  • it would probably be better to refactor the rendering configuration (template in the card properties and the custom formatter mapping of the component's content prop) as a single formatter
  • there's too much data mapping required in consuming components (e.g. JO treatments); if the application state just contains the card data, (almost) everything else should be done by this package

License

UNLICENSED