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

earthtoday-react-split-flap-effect

v1.0.1

Published

Forked Split-flap display for React

Downloads

449

Readme

earthtoday-react-split-flap-effect

Forked Split-flap display for React

NPM JavaScript Style Guide

Description

This component recreates the look of "split-flap" (a/k/a Solari) displays that used to be common in train stations and on alarm clocks.

Install

npm install --save earthtoday-react-split-flap-effect

or

yarn add earthtoday-react-split-flap-effect

Usage

import { FlapDisplay, Presets } from 'earthtoday-react-split-flap-effect'

const App = () => {
  return (
    <FlapDisplay
      chars={Presets.ALPHANUM + ',!'}
      length={13}
      value={'Hello, World!'}
    />
  )
}

Props

Prop | Type | Default | Usage ---- | ---- | ------- | ----- id | string | | Applies an id to the enclosing div css | Object | | Style object to pass to emotion or styled-components className | string | | Class names to apply to the enclosing div value | string | required | The value to display. Will be uppercased unless words is also supplied. chars | string | Presets.NUM | Single string containing the list of valid characters to display. The package provides Presets.NUM and Presets.ALPHANUM as starting points. Append whatever punctionation you need to those strings. The presets include space as the first character, which is recommended so that you'll be able to display blank values. words | Array[string] | | Optional array of strings to use as states for the flaps instead of single characters. When this is supplied, chars will be ignored, and value won't be split into individual characters. length | int | required | The number of digits to display padChar | char | ' ' | The character to use to fill empty digits. padMode | string | 'auto' | Controls padding of values; auto will try to align numbers to the right and strings to the left; start will align values to the right and end will align values to the left. timing | int | 30 | Milliseconds to use for the rapid change animation. Numbers from 10-50 work best here. (This value doesn't affect the final flap of the animation, which is fixed at 300ms.) hinge | bool | true | Controls whether to show the thin line through the center of flaps render | func | | A functional component that can be used to customize rendering. The individual flap digit components will be passed as the component's children. This can be used to insert things between the digits (for instance, you might want to show fixed symbols like decimal points and commas between digits, rather than using an extra digit for these.)

Themes

The package comes with a stylesheet in extras/themes.css with some pre-built themes. These themes will load a Google font called 'Share' that resembles real-life Solari displays.

Import the stylesheet and apply some combination of the following in the className prop:

Class name | Usage ---------- | ----- S | Custom font at 18px M | Custom font at 30px L | Custom font at 48px XL | Custom font at 78px light | Dark-gray text on a light-gray background lightBordered | Light color theme plus a subtle border and margins between digits dark | Light-gray text on a dark-gray background darkBordered | Dark color theme plus a subtle border and margins between digits

Custom styling

The split-flap display's appearance is controlled using CSS. This allows you to use whatever strategy you want (plain CSS, CSS modules, styled components, etc.) for styling and responsive design.

To create a custom style, add a custom className (or id) and override these rules. (Values shown are defaults just for clarity's sake—you can leave them out of your custom CSS if you're not changing them.) You can also take a look at extras/themes.css for examples.

.myClassName [data-kind="digit"] {
  // set fonts and add borders, margins, backgrounds, etc. here
  color: white;
  background-color: black;
  font-family: sans-serif;
  line-height: 1em;
  width: 1.1ch;
  height: 1em;
  text-align: center;
}

.myClassName [data-kind="digit"][data-mode="words"] {
  // width override for single-word flaps
  width: 100%;
}

.myClassName [data-kind="digit"][data-mode="alpha"] {
  // width override for A-Z flaps
  width: 1.7ch;  
}

.myClassName [data-kind="hinge"] {
  // set the width of the hinge stripe
  height: 0.04em;
}

Be aware that if you change any position, display or transform properties in these rules, I can't guarantee what the animation'll look like. 😀

The default values above will work OK for Arial/Helvetica (the default sans-serif font on most clients.) But, in general it's better to choose a narrow or "condensed" font because these generally have skinnier capital letters, and less variation between letter widths.

If you choose a custom font, pay close attention to the line-height of your text. Because there's no consistent sizing between different typefaces, you'll need to manually adjust this to make the text appear centered vertically in the flaps.

Caveats

I'm using the clip-path CSS property, which isn't well-supported on IE or Edge (Trident). On these clients the animation will look a little strange, but it shouldn't break the layout of your page or be unreadable.

Chrome in particular has some subpixel rendering issues that can cause the two halves of each letter to be slightly misaligned. You might also see some very minor screen tearing if you disable the hinge effect. Safari seems to deal better with these issues. (I also suspect the alignment issue might go away if you set fixed pixel widths on your digits, instead of the relative units I'm using for flexibility.)

License

MIT © 2019 Justin Kerr Sheckler