Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[styled-jss] Styled Primitive Components #341

Closed
kof opened this issue Nov 3, 2016 · 11 comments
Closed

[styled-jss] Styled Primitive Components #341

kof opened this issue Nov 3, 2016 · 11 comments
Labels
idea What if we turn JSS into styled-components?

Comments

@kof
Copy link
Member

kof commented Nov 3, 2016

Create a small library that allows to style primitives similar to styled-components. Some pseudo code.

@kof kof added task idea What if we turn JSS into styled-components? labels Nov 3, 2016
@kof
Copy link
Member Author

kof commented Feb 5, 2017

Variant 1

import styled from 'styled-jss'

const Button = styled('button', {
  fontSize: 12,
  color: (props) => props.theme.textColor
})

const PrimaryButton = styled(Button, {
  color: 'red'
})

@kof kof changed the title [react-jss-components] Styled Primitive Components [styled-jss] Styled Primitive Components Feb 22, 2017
@kof kof mentioned this issue Feb 22, 2017
3 tasks
@kof
Copy link
Member Author

kof commented Mar 22, 2017

Variant 2

import Styled from 'styled-jss'
import injectSheet from 'react-jss'

// Base styles, like a regular jss object.
const styled = Styled({
  root: {
    margin: 10
  },
  baseButton{
    padding: 10
  }
})

const NormalButton = styled('button', {
  composes: '$baseButton',
  border: '1px solid grey'
  color: 'black'
})

// Composition over styled() same like styled-components
const PrimaryButton = styled(NormalButton, {
  color: 'red'
})

// One can use classes AND styled primitives.
const MyComponent = ({classes}) => (
  <div className={classes.root}>
    <PrimaryButton>
  </div>
)

const MyStyledComponent = injectSheet(styled)(MyComponent)

cc @cssinjs/core

@sergeysova
Copy link
Contributor

@kof any progress here?

@kof
Copy link
Member Author

kof commented Mar 22, 2017

Yes, me and @lttb are evaluating some interesting interfaces, but its not ready yet.

@sergeysova
Copy link
Contributor

@kof Can I help you?

@kof
Copy link
Member Author

kof commented Mar 22, 2017

Yes, we are preparing some syntax variants and will need user feedbacks, we will post the poll here soon cc @lttb

@kof
Copy link
Member Author

kof commented Mar 22, 2017

You see actually already 2 possible syntaxes, what are your thoughts on them? What do you NOT understand?

@sergeysova
Copy link
Contributor

All syntaxes is readable.

@sergeysova
Copy link
Contributor

https://gist.github.com/kof/3277ee04d2100bab3e6c6c33656edce7#gistcomment-2034780

@lttb
Copy link
Member

lttb commented Mar 22, 2017

Variant 3

There are some points about yet another concept:

  • we declare style primitives for component in lower case on the top level:
{
  button: {
    color: 'red' 
  }
}
  • we can use primitive modifier starts with Capital letter, eg:
{
  App: { padding: '10px' }, // on the top level it turns into <div> with modifier className

  button: {
    color: 'black',

    Primary: {
      color: 'red'
    }
  }
}
  • we can compose modifiers with something like primitiveModifier:
{
  button: {
    color: 'black',

    Normal: {
      border: '1px solid black'
    },
    Secondary: {
      composes: '$buttonNormal' // -> button.Normal styles
    }
  }
}
  • we can also declare modifiers just on the top level:
{
  button: {
    color: 'black',
  },
  buttonNormal: {
    border: '1px solid black'
  },
  buttonSecondary: {
    composes: '$buttonNormal'
  }
}
  • full example
const styles = {
  App: { padding: 30px },
  
  button: { 
    padding: '10px', 

    Normal: { 
      border: '1px solid black' 
    }, 
    Primary: { 
      color: 'red' 
    }, 
    Secondary: { 
      composes: '$buttonNormal', 
      color: 'green' 
    }
  } 
}

const MyComponent = ({ styled }) => (
  <styled.App>
    <styled.button />
    <styled.button.Primary />
  </styled.App>
)

const MyStyledComponent = injectStyled(styles)(MyComponent)

@kof
Copy link
Member Author

kof commented Apr 27, 2017

closing, as we got it released https://github.com/cssinjs/styled-jss

@kof kof closed this as completed Apr 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
idea What if we turn JSS into styled-components?
Projects
None yet
Development

No branches or pull requests

3 participants