Giter VIP home page Giter VIP logo

spec's Introduction


Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress πŸ’…

downloads: 600k/month Discord gzip size module formats: umd, cjs, esm Code Coverage

Upgrading from v5? See the migration guide.

Utilizing tagged template literals (a recent addition to JavaScript) and the power of CSS, styled-components allow you to write actual CSS code to style your components. It also removes the mapping between components and styles – using components as a low-level styling construct could not be easier!

const Button = styled.button`
  color: grey;
`;

Alternatively, you may use style objects. This allows for easy porting of CSS from inline styles, while still supporting the more advanced styled-components capabilities like component selectors and media queries.

const Button = styled.button({
  color: 'grey',
});

Equivalent to:

const Button = styled.button`
  color: grey;
`;

styled-components is compatible with both React (for web) and React Native – meaning it's the perfect choice even for truly universal apps! See the documentation about React Native for more information.

Supported by Front End Center. Thank you for making this possible!


See the documentation at styled-components.com/docs for more information about using styled-components!

Quicklinks to some of the most-visited pages:


Example

import React from 'react';

import styled from 'styled-components';

// Create a <Title> react component that renders an <h1> which is
// centered, palevioletred and sized at 1.5em
const Title = styled.h1`
  font-size: 1.5em;
  text-align: center;
  color: palevioletred;
`;

// Create a <Wrapper> react component that renders a <section> with
// some padding and a papayawhip background
const Wrapper = styled.section`
  padding: 4em;
  background: papayawhip;
`;

function MyUI() {
  return (
    // Use them like any other React component – except they're styled!
    <Wrapper>
      <Title>Hello World, this is my first styled component!</Title>
    </Wrapper>
  );
}

This is what you'll see in your browser:


Looking for v5?

The main branch is for the most-current version of styled-components, currently v6. For changes targeting v5, please point your PRs at the legacy-v5 branch.


Built with styled-components

A lot of hard work goes into community libraries, projects, and guides. A lot of them make it easier to get started or help you with your next project! There are also a whole lot of interesting apps and sites that people have built using styled-components.

Make sure to head over to awesome-styled-components to see them all! And please contribute and add your own work to the list so others can find it.


Contributing

If you want to contribute to styled-components please see our contributing and community guidelines, they'll help you get set up locally and explain the whole process.

Please also note that all repositories under the styled-components organization follow our Code of Conduct, make sure to review and follow it.


Badge

Let everyone know you're using styled-components β†’ style: styled-components

[![style: styled-components](https://img.shields.io/badge/style-%F0%9F%92%85%20styled--components-orange.svg?colorB=daa357&colorA=db748e)](https://github.com/styled-components/styled-components)

Contributors

This project exists thanks to all the people who contribute. [Contribute].


Backers

Thank you to all our backers! πŸ™ [Become a backer]


Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]


License

Licensed under the MIT License, Copyright Β© 2016-present Glen Maddern and Maximilian Stoiber.

See LICENSE for more information.


Acknowledgements

This project builds on a long line of earlier work by clever folks all around the world. We'd like to thank Charlie Somerville, Nik Graf, Sunil Pai, Michael Chan, Andrey Popp, Jed Watson & Andrey Sitnik who contributed ideas, code or inspiration.

Special thanks to @okonet for the fantastic logo.

spec's People

Contributors

gitter-badger avatar jedwatson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spec's Issues

"how do I" questions

I expect the pure css folk (like myself) to ask simple, basic questions, regarding how they'd do what they already do easily in css, with xyz css-in-js solution. I'm just starting the same for glamor, but sharing the qn titles to get some feedback -

how do I -

  • apply a style to a single element
  • apply a style to a class of elements
  • attribute selectors
  • pseudo classes
  • specificity
  • apply style based on relationships with other elements
  • font faces/keyframes/media queries

what am I missing? cheers.

The Purpose / Is there a library that meets these goals?

I just wanted to make it more explicit that it is in the Readme:

This org's purpose is to collect discussion about all the possible requirements of a component-oriented CSS solution for JavaScript. There are a lot of libraries out there already, many of which solve most of these problems, but all the discussions around them are fractured across twitter, medium, issues and gists.

So we're trying to approach it from a different perspective: collect the ideas and discuss the issues in a single place, making it easier for the community to follow and engage with.

Hopefully, one (or more) of the current crop of libraries evolves to a point where they meet the goals & requirements we work out through this collaborative process. If not, maybe we have a spec to build one. If any of the existing libraries have either (a) technical limitations preventing them from being the whole solution, or (b) different design goals, that's cool - that is no judgement on them, and it's very unlikely a "one size fits all" solution is possible.

If you lead, or know of, a library that works well for css components, shout out here and consider adding an implementation to the comparison repo!

Only JavaScript approaches?

Of the listed competing solutions, two are essentially runtime solutions in JS (CSS in JS and inline styles) and two are available to be handled by generic build tools (css + postcss and sass).

Should cross-language be a concern?

CSS modules

Which item in the dot points does CSS modules not meet?

What does overridable mean?

So I guess because of the Cascade and Selector parts of CSS, no matter what's chosen there's no real way to restrict someone including a stylesheet that styles a "pre-styled" component.

Are there more specific features desired when it comes to overriding styles?

Lightweightness vs Setup Complexity

Based on a discussion in styled-components/comparison#31 (comment), I think we might need to rename the lightweightness category. In the comparison repo I changed the Checklist for the different methods to be this:

- βœ… No build requirements
- πŸ˜• Small and lightweight
- βœ… Supports global CSS
- βœ… Supports entirety of CSS
- βœ… Colocated
- βœ… Isolated
- βœ… Doesn’t break inline styles
- πŸ˜• Easy to override
- ❌ Theming
- ❌ Pre-build
- βœ… Server side rendering
- ❌ No wrapper components

Legend: βœ… = Yes, ❌ = No, πŸ˜• = Kinda, refer to notes or parentheses

But I think what we really want to say with lightweightness is setup complexity. None of the current methods is anywhere near "too big" imo.

/cc @kof

Overriding styles on child elements

cc @jquense @threepointone @vjeux @JedWatson @ryanflorence

ref Medium article, @Vjeux Gist, @taion Gist (esp. @threepointone comment), css-modules/css-modules#147

It's somewhat difficult in the current componentized CSS solutions to handle cases like:

<InlineForm>
  <EmailInput />
  <PasswordInput />
  <LoginButton />
</InlineForm>

or

<InlineForm>
  <EmailInput />
  <PasswordInput />
  <SomeComponent>
    <LoginButton />
  </SomeComponent>
</InlineForm>

There may well be styling that you want to attach to buttons that render in specific contexts. With normal CSS, you'd write selectors that look like .form-inline > .btn or .form-inline .btn.

With componentized CSS, it can be more difficult. Depending on use case, sometimes this styling should go in <Button>, and sometimes perhaps it should go in <InlineForm>.

You can achieve similar behavior to these selectors with various combinations of React context and cloning children with additional props. However, for more complex selectors including e.g. :first-child or :last-child, the equivalent code gets a bit more complicated.

I think the question becomes:

  • Is it possible to make a nice JS API that can cover similar use cases to CSS selectors, with a similar level of ease-of-use
  • Is it possible to just incorporate CSS selectors while still keeping styles encapsulated, and while limiting the scope for overriding styles

Well, that's the best high-level summary I can synthesize. Let me know what I got wrong.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.