New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-placehodl

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-placehodl

React placeholders made simple.

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by75%
Maintainers
1
Weekly downloads
 
Created
Source

react-placehodl 📌

React placeholders made simple.

react-placehodl

Installation

$ npm i react-placehodl

Motivation

Placeholders are cool. Placeholder are way cooler than spinners. Current libraries implementing placeholder are super complicated. There's prefabricated components with pre-made styles you must import, and there's ways to make custom ones that interact with these libraries. This doesn't really allow much flexibility, which is the motivation of this lib.

Render Prop

Yeah, yeah, yeah... We're all aware of the hype going on with the render prop. Just happens to be that a placeholder is the perfect use case for them.

API

Props

The <Placehodl /> component has the following props:

  • seed => Seed for the size randomizer. (Powered by fast-random).
  • sizes => Array of size classNames that will be applied to each word.
  • prefix => Prefix used in all elements classes.
  • className => Root level class name.
  • children => Function that gets passed the generator methods.

Generator methods

  • getParagraph => Returns a paragraph composed by lines.
// lines - corresponds with number of lines in the paragraph
// words - corresponds with number of words per line
// size - corresponds with number of size possibilities for each word.
getParagraph(lines: int, words: int, size: int) => (paragraph: jsx)
  • getLine => Returns a line composed by words
// words - corresponds with number of words in the line
// size - corresponds with number of size possibilities for each word.
getLine(words: int, size: int) => (line: jsx)
  • getSize => Returns a className corresponding to one of the size possibilities.
// size - corresponds with number of size possibilities in the returned className.
getSize(size: int) => (className: string)

Examples

Use of getParagraph (works out of the box use case)

 import Placehodl from 'react-placehodl';
 
 // outputs paragraph with 10 lines, 3 words, 5 sizes
 const Placeholder = props => {
   return (
     <Placehodl seed={props.seed} prefix="my-placeholder">
       {({ getParagraph }) => getParagraph(10, 3, 5)}
     </Placehodl>
   );
 };

Use of getLine (medium customization use case)

  import Placehodl from 'react-placehodl';
  
  // outputs line with 3 words, 5 sizes
  const Placeholder = props => {
    return (
      <Placehodl seed={props.seed} prefix="my-placeholder">
        {({ getLine }) => (
          <div className="my-placeholder-paragraph">
            {Array(10)
              .fill(0)
              .map((line, i) => (
                <div
                  key={`placeholder-line-container-${i}`}
                  className="my-placeholder-line-container"
                >
                  {getLine(3, 5)}
                  <Icon name="info" />
                </div>
              ))}
          </div>
        )}
      </Placehodl>
    );
  };

Use of getSize (advanced customization use case)

import Placehodl from 'react-placehodl';

// outputs word 5 possible sizes
const Placeholder = props => {
  return (
    <Placehodl seed={props.seed} prefix="my-placeholder">
      {({ getSize }) => (
        <div className="my-placeholder-paragraph">
          {Array(10)
            .fill(0)
            .map((line, i) => (
              <div key={`placeholer-line-${i}`} className="my-placeholder-line">
                {Array(3)
                  .fill(0)
                  .map((word, j) => (
                    <div
                      key={`placeholder-word-${j}`}
                      className={`my-placeholder-line-container ${getSize(5)}`}
                    />
                  ))}
              </div>
            ))}
        </div>
      )}
    </Placehodl>
  );
};

Keywords

FAQs

Package last updated on 05 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc