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

@clds/theme-helper

v0.38.0

Published

Helper for themes

Downloads

3,606

Readme

@clds/theme-helper


npm version

This package was created to simplify the usage of themes when working with styled-components. It provides a default theme (that all applications themes should merge with),
a theme API so components will be able to access the theme values easily and some utility functions to work with themes

Installation

Install the package using Package Manager:

yarn add @clds/theme-helper
pnpm add @clds/theme-helper
npm install --save @clds/theme-helper

switchProp

In case your component receive a prop and you want to get different theme variable based on the prop value you can use this function

API:

generateTheme

When using the the ThemeProvider from styled-components you should provide a theme object,
In order to support some extra features like base theme, references to other theme variables (from application or default theme) and more we created this function.

You should invoke it with your theme and send the result to the ThemeProvider

import { ThemeProvider } from 'styled-components';
import { generateTheme } from '@clds/theme-helper';
import { theme } from './myTheme';

const App = (props) => (
  <ThemeProvider theme={generateTheme(theme)}>
    <MyButton high={true}>Button</MyButton>
  </ThemeProvider>
);

Default theme

this package also contains a default theme,
this is the base theme and every application can override it by providing it's own theme with overrides,

When adding or updating a component that should be affected from the theme variables there are few steps that should be done

1. add the relevant variables to the default theme

We should add variables for each component and not use existing global variables,
this will give the applications much more flexibility when creating their own themes.
We should use references to other theme variables so we won't need to duplicate values.
The default theme filename is default.theme.js.

Example:

//default.theme.js

const myComponent = {
  color: 'colors.primary',
};

module.exports = {
  ...myComponent,
};

This will take our component color from the primary color that's under the colors section in the theme.

2. add the mappings to the variables that we added to the theme

In order to provide the themeApi we have a mappings file,
when updating the default theme we should also update the mappings file so the themeApi will expose our variables and point to the correct locations in the theme The mappings filename is mappings.js.

Example:

//mappings.js

export default {
  ...,
  myComponentColor: 'myComponent.color',
}

Now you will be able to use theme.myComponentColor in your component and let the applications customize it when providing their theme

Versioning

This library follows Semantic Versioning.

License

See LICENSE