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

@roast-cms/react-sugar-styled

v1.0.4

Published

Customizable and extendable theming dictionary for Styled Components.

Downloads

2

Readme

react-sugar-styled

NPM version

🍬 Customizable and extendable theming dictionary for Styled Components.

demo

  • Create more flexible designs with React and Styled Components.
  • Pre-built design system that works across all your projects.
  • Focus on design, not variables.

Installation:

yarn add @roast-cms/react-sugar-styled

Then, in your project:

import styled, { ThemeProvider } from "styled-components"
import { Sugar } from "@roast-cms/react-sugar-styled"
//
// you can access the dictionary values from Styled Components within
// any component that's wrapped in <ThemeProvider />
const MyComponent = styled.div`
  color: ${props => props.theme.color.brand()};
`
//
// pass the dictionary Sugar() as a theme to your app:
const App = props =>
  <ThemeProvider theme={Sugar()}><MyComponent /></ThemeProvider>

Why?

Styled Components lets you apply CSS to your React components with ease. Their theming support adds a level of flexibility and organization to your application. You can make your components visually behave in an organized fashion, while remaining independent.

Theming in this context works as defining a dictionary of values which could be reused across the children components. However, what those values are is a mystery until you finish building your project.

react-sugar-styled provides you with a set of defaults that you can easily customize and extend. They include basics like colours, fonts, key sizes, and more. A set of convenience functions also helps you with responsive design (breakpoints), as well as size and colour modifications.

Theme globals.

All of the values in the theme object are accessible across all your components which are children of <ThemeProvider/>. Here's what they do and how to access them:

To access a value within your CSS (that you wrote with Styled Components) simply include ${props => props.theme.[OBJECT REFERENCE]}, where OBJECT REFERENCE is one of the following:

Colours

OBJECT REFERENCE | Description | Usage Example --- | --- | --- color.brand(alpha) | An rgba value for your "special" theme colour. | color: ${props => props.theme.color.brand()}; color.foreground(alpha) | An rgba value for your foreground colour, typically the colour of your body text. | color: ${props => props.theme.color.foreground()}; color.background(alpha) | An rgba value for your background colour, typically the colour of your background. | background: ${props => props.theme.color.background()};

Typography

OBJECT REFERENCE | Description | Usage Example --- | --- | --- typography.title.auto | Return CSS that sets color, font-family, letter-spacing, line-height, font-weight, and margin designed for title/heading tags. | h1 { ${props => props.theme.typography.title.auto} } typography.text.auto | Same as above, but for body text. | p { ${props => props.theme.typography.text.auto} }

Block measuring sizes

OBJECT REFERENCE | Description | Usage Example --- | --- | --- size.block.padding | Returns a number meant to be used as em value for standard padding width | padding: ${props => props.theme.size.block.padding}em; size.block.padding | Returns a number meant to be used as em value for standard spacing between blocks | margin: ${props => props.theme.size.block.spacing}em; size.block.border | Returns a number meant to be used as px value for standard border widths | border: ${props => props.theme.size.block.border}px solid; size.block.column.m | Returns a number meant to be used as px value for a medium-width content column | article { width: ${props => props.theme.size.column.m} } size.block.column.l | Same as above, but for wider screens | article { width: ${props => props.theme.size.column.l} }

Complete list can be found here

Customizing & extending the theme.

Although you can immediately start designing your components using the default theme dictionary, you may want to customize it. Luckily there's an easy way to do this:

<ThemeProvider
  theme={Sugar({
      color_brand: "rgb(189,67,54)",
      color_background: "rgb(44,44,44)",
      color_foreground: "rgb(224,213,255)",
      //
      font_heading: "'Yanone Kaffeesatz', sans-serif",
      font_heading_weight: 400,
      //
      font_body: "'Lobster Two', serif",
      //
      size_base: 28,
      size_column_medium: 700,
      size_column_large: 900,
      size_block_padding: 2,
      size_block_spacing: 1.5,
      size_block_border: 10,
      //
      effects_border_radius: 1
    })
  }
>
{/* components */}
</ThemeProvider>

You can also extend the theme with your own dictionary values or system using ES6 spread operator:

<ThemeProvider
  theme={{
    ...Sugar(),
    font_special: "'Indie Flower', cursive"
  }}
>
{/* components */}
</ThemeProvider>

Contributions welcome!

To get started with the code: clone the repo, run yarn install then yarn start and open up http://localhost:3002 in your browser.