šŸš€ Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

shorted-theme

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shorted-theme

Shorted theme references for Styled Components.

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

shorted-theme - Shorted theme references for Styled Components.

Comparison: before and after




Features

  • Zero dependencies.
  • TypeScript support.
  • Write less characters.
  • Tests with 100% coverage.

Installation

npm i shorted-theme

Usage

import styled from 'styled-components'
import shorted from 'shorted-theme'

const theme = {
  colors: {
    primary: 'red',
    secondary: 'blue'
  },
  fontFamily: '"Roboto", sans-serif',
  fontSizes: {
    small: 12,
    regular: 14,
    large: 18
  }
}

const t = shorted(theme) // šŸ‘ˆ short your theme then use everywhere.

const Button = styled.button`
  color: ${t.colors.primary};
  color: ${t.colors.primary};
  font-family: ${t.fontFamily};
  font-size: ${t.fontSizes.regular};
`

TypeScript Support

shorted-theme use all your typings.

Suggestion

You can destructure the shorted theme object. That way you can reference direct children properties instead of a root object.

const { colors, fontFamily, fontSizes } = shorted(theme)

const Button = styled.button`
  color: ${colors.primary};
  color: ${colors.primary};
  font-family: ${fontFamily};
  font-size: ${fontSizes.regular};
`

Limitations

shorted-theme is useful for writing less when referencing theme values. However, it can't be used in expressions. For example:

// THIS WILL NOT WORK
const Button = styled.button`
  padding: ${t.padding.default * 10};
`

Instead you should use the function expression:

const Button = styled.button`
  padding: ${(props) => props.theme.padding.default * 10};
`

Development

  • Clone this repository.
  • Install dependencies: npm i.
  • Run it locally: npm start or ./src/bin.js

Tests

npm run test

Releases

Releases are triggered by npm version and handled by GitHub Actions.




Made with ♄ by @rmariuzzo

Keywords

styled-components

FAQs

Package last updated on 23 Sep 2020

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