All Projects → donavon → Styled Shortcuts

donavon / Styled Shortcuts

Licence: mit
Provides convenient props shortcut helper for Styled Components 💅

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Styled Shortcuts

Bank
🏦 Full Stack Web Application similar to financial software that is used in banking institutions | React.js and Node.js
Stars: ✭ 1,158 (+1186.67%)
Mutual labels:  styled-components
React Starter
🚀 A minimal react boilerplate featuring easy-peasy state management and styled-components
Stars: ✭ 79 (-12.22%)
Mutual labels:  styled-components
Styled Elements
Styled components for the DOM.
Stars: ✭ 87 (-3.33%)
Mutual labels:  styled-components
French Press Editor
☕ An offline-first rich text editor component.
Stars: ✭ 69 (-23.33%)
Mutual labels:  styled-components
Waveforms
An interactive, explorable explanation about the peculiar magic of sound waves.
Stars: ✭ 1,218 (+1253.33%)
Mutual labels:  styled-components
React Eyepetizer
react版「Eyepetizer」开眼短视频
Stars: ✭ 83 (-7.78%)
Mutual labels:  styled-components
Blog Admin
使用React全家桶开发的一套博客后台管理系统
Stars: ✭ 68 (-24.44%)
Mutual labels:  styled-components
Ui
React Styled Components with bootstrap grid system
Stars: ✭ 89 (-1.11%)
Mutual labels:  styled-components
Gatsby Starter Typescript Rebass Netlifycms
My default Gatsby setup. Includes rich MDX support.
Stars: ✭ 79 (-12.22%)
Mutual labels:  styled-components
Netflix
Subscribe to my YouTube channel: https://bit.ly/CognitiveSurge - Building Netflix Using React
Stars: ✭ 1,254 (+1293.33%)
Mutual labels:  styled-components
React Hipstaplate
A ReactJS full-stack boilerplate based on typescript with ssr, custom apollo-server and huge stack of modern utilities which will help you to start your own project
Stars: ✭ 74 (-17.78%)
Mutual labels:  styled-components
Horror
😱 React HTML elements with CSS-in-JS
Stars: ✭ 78 (-13.33%)
Mutual labels:  styled-components
Theme Builder
The theming system helps you in building a theme of your choice and apply it to test live. Why wait? Just give it a try.
Stars: ✭ 82 (-8.89%)
Mutual labels:  styled-components
React Redux Hooks Starter
React-redux boilerplate using hooks 🎣
Stars: ✭ 69 (-23.33%)
Mutual labels:  styled-components
Placeline Nextjs
HyperTrack Placeline web application sample using NextJS, Ant-Design, Styled-Components, and Heroku
Stars: ✭ 88 (-2.22%)
Mutual labels:  styled-components
Restyled
Styled Components concept for Reason React, only works with bs-react-native for now
Stars: ✭ 68 (-24.44%)
Mutual labels:  styled-components
Square React Dashboard
👨‍🎤 React Dashboard Template built with TypeScript
Stars: ✭ 81 (-10%)
Mutual labels:  styled-components
Next Starter
Next.js Starter using GraphQL, MobX (Next.js, TypeScript, Babel, Express.js, Apollo Client, React Apollo, React Apollo Hooks, GraphQL Codegen, MobX, mobx-state-tree, styled-components, next-optimized-images, Serverless Framework, AWS Lambda, Dotenv)
Stars: ✭ 90 (+0%)
Mutual labels:  styled-components
React Rasta
React Rasta is a powerful and flexible grid system for React
Stars: ✭ 88 (-2.22%)
Mutual labels:  styled-components
React Image Smooth Loading
[not maintained] Images which just flick to appear aren't cool. Images which appear smoothly with a fade like Instagram are cool
Stars: ✭ 84 (-6.67%)
Mutual labels:  styled-components

Styled Shortcuts 💅

Build Status npm version Coverage Status

TL;DR

  • Now with Theme Support!
  • Provides convenient props shortcut helper for Styled Components 💅
  • Small footprint with No Dependencies!
  • With Styled Shortcuts you can now do this:
    font-size: ${'fontSize:px'};
    
    instead of this:
    font-size: ${({ fontSize }) => `${fontSize}px`};
    
  • Use any unit (e.g. px, %, cm, you name it) or no unit at all.

Install

$ npm i --save styled-shortcuts

API

Here's the beauty... There's only one function! Styled Shortcut provides a higher order function that you use to wrap Styled Components, like this:

import rawStyled from 'styled-components';
import shortcuts from 'styled-shortcuts';

const styled = shortcuts(rawStyled);

And to make everyone's life easier, there's now a package that does this for you. In fact, it is a direct replacement for styled-components. It imports both styled-components and styled-shortcuts and exports the wrapped styled.

All you have to do is make a one-line change your components to import from styled-shortcut-components instead of styled-components.

// import styled from 'styled-components';
import styled from 'styled-shortcut-components';

Usage

Any template string value is assumed to be a props key. For example, ${'color'} will return the prop named color. Your can also assign a "unit" suffix. It can be anything, such as px, %, em, etc. Simply separate the unit from the prop key with a colon. For example ${'width:px'} will return the width prop with the "px" suffix.

See this example below:

import styled from 'styled-shortcut-components';

const Button = styled.button`
  padding: ${'padding:em'};
  border-radius: ${'borderRadius:px'};
  width: ${'width:%'};
  color: ${'color'};
`;

Button.defaultProps = {
  padding: 1,
  borderRadius: 4,
  width: 100,
  color: 'red',
};

Using with Themes

You can specify a props key that contains a dotted object notation.

For example:

const Button = styled.button`
  padding: 0.25em 1em;
  border-radius: ${'theme.button.borderRadius:px'};
  color: ${'theme.color'};
  border: 2px solid ${'theme.color'};
`;

See the Styled Components documentation for complete details on how to enable theming.

Do It Live!

Check out this live example on CodeSandbox.

Do It Live!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].