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

@abw/react-one-louder

v0.0.6

Published

Theme provider for React components

Downloads

32

Readme

react-one-louder

This is a simple React library for customising components. It is typically used for theming UI components, but more generally it can be used to provide sensible "global" defaults for any components in a web site or other application.

If you can see... the numbers all go to eleven. Look... right across the board. Eleven... eleven... eleven. You see, most blokes will be playing at ten. You're on ten here... all the way up, all the way up. You're on ten on your guitar... where can you go from there? Where? Nowhere. Exactly. What we do is if we need that extra push over the cliff, you know what we do? Put it up to eleven. Eleven. Exactly. One louder.

Documentation

Read the full documentation for full details. The abridged version is included below.

Getting Started

Add the @abw/react-one-louder module to your project using your favourite package manager.

## using npm
$ npm add @abw/one-louder

## using yarn
$ yarn add @abw/one-louder

## using pnpm
$ pnpm add @abw/one-louder

You can then import the modules and start using them.

import { Theme, Themed } from '@abw/react-one-louder'

Themed Components

Consider a simple React component like this Amplifier.

const Amplifier = ({ volume=10 }) =>
  <div>Amplifier volume is {volume}</div>

export default Amplifier

If you don't explicitly provide a volume property when you use it then it defaults to 10.

import Amplifier from './Amplifier.jsx'

const AmplifierExample = () =>
  <Amplifier/>

The output would be:

Amplifier volume is 10

Of course you can always provide a volume property to override the default value.

import Amplifier from './Amplifier.jsx'

const AmplifierExample = () =>
  <Amplifier volume={9}/>

Now the output is:

Amplifier volume is 9

That's all very well as long as you remember to set the volume explicitly every time. Apart from being easy to forget, it's also hard to change. If you've got lots of places where you're using this component and one day someone decides to change the volume across the whole site then you've got lots of code you need to change.

This is where the Themed function can be used. Instead of exporting your bare component, wrap it up in a call to Themed and provide a name that you can reference it by. In most cases, this will be the same name as the component, but it doesn't have to be.

import { Themed } from '@abw/react-one-louder'

const Amplifier = ({ volume=10 }) =>
  <div>Amplifier volume is {volume}</div>

export default Themed(Amplifier, 'Amplifier')

You can still use it just like you did before.

import Amplifier from './Amplifier.jsx'

const AmplifierExample = () =>
  <>
    <Amplifier/>
    <Amplifier volume={9}/>
  </>

The output is:

Amplifier volume is 10
Amplifier volume is 9

When you need that extra push over the cliff, you can define a Theme.Provider. This can be anywhere in your code but it's usually best to put it somewhere near the "top" of your application so that it encloses all the components that want to use it.

You provide it with a new set of defaults for any components that you're using and they will automatically be applied to your Themed components matching the name. You can still provide an explicit volume when you use the component if you need to.

import Amplifier from './Amplifier.jsx'
import { Theme } from '@abw/react-one-louder'

const MyTheme = {
  Amplifier: {
    volume: 11
  }
}

const AmplifierExample = () =>
  <Theme.Provider {...MyTheme}>
    <Amplifier/>
    <Amplifier volume={9}/>
  </Theme.Provider>

The output is now:

Amplifier volume is 11
Amplifier volume is 9

Defining Themes

We've already seen the typical case where you define your theme using default properties. You can include theming options for as many components as you need to.

import { Theme } from '@abw/react-one-louder'

const MyTheme = {
  Guitar: {
    volume: 11,
  },
  Amplifier: {
    volume: 11
  },
  Drummer: {
    lifeInsurance: true,
    fireExtinguisher: true,
    gardeningAccident: false,
  }
}

const YourApplication = () =>
  <Theme.Provider {...MyTheme}>
    {/* ...your site code... */}
  </Theme.Provider>

You can also theme a component using a function. The function will be passed any properties that have been specified with the component. It should return a set of properties that will be used as defaults. Note that these are only the defaults. In the third case below, the quiet property sets the default volume to 5 and color to black, but we can still provide an explicit volume property which will take precedence.

import { Theme } from '@abw/react-one-louder'

const MyTheme = {
  Amplifier: props => props.quiet
    ? { volume: 5,  color: 'black' }
    : { volume: 11, color: 'none more black' }
}

const YourApplication = () =>
  <Theme.Provider {...MyTheme}>
    <Amplifier/>
    <Amplifier quiet/>
    <Amplifier quiet volume={6}/>
  </Theme.Provider>

The output is:

Amplifier volume is 11
Amplifier volume is 5
Amplifier volume is 6