question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What about SASS-like stuff

See original GitHub issue

Hi there, I’ve made some extension for my projects. Do you think it’s useful? Here is description

Extension

Extend style-components with object of following shape

{
  vars: {
    variableName: 'Variable string value'
  },
  mixins: {
    flex: (flex) => `flex: ${flex}`
  }
}

Here is usage example

Extension

variables are the strings, like padding: #minSpace;

mixins are the functions, like @flex(1 1 auto);

mixin accepts varible as argument, like @margin(#minSpace)

mixin accepts multiple arguments, like @tint(#primaryRed, -10%)

styled.init({
  vars: {
    minSpace: '0.5em',
    primaryRed: 'red',
    'd:f': 'display: flex',
    'ff:rn': 'display: flex; flex-flow: row nowrap',
    'ff:cn': 'display: flex; flex-flow: column nowrap',
    'jc:sb': 'justify-content: space-between',
    'f:a': 'flex: auto'
  },
  mixins: {
    flex: (flex) => `flex: ${flex}`,
    margin: (margin) => `margin: ${margin}`,
    tint: (color, value) => coolTintColorFunctionFromOutside(color, value)
  },
});

Invocation

const Wrapper = styled.div`
  padding: #minSpace;
  #ff:cn;
  #jc:sb;
  @flex(1 1 auto);
  @margin(#minSpace);
  background-color: @tint(#red, -10%);
`;

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

9reactions
k15acommented, Mar 17, 2017

In my opinion the better way would be to have JS care about variables and mixins. What speaks against using JS for all this for you?

const minSpace = '0.5rem'
const primaryRed = 'red'
const df = css`display: flex;`
const ffrn = css`display: flex; flex-flow: ro nowrap;`
const ffcn = css`display: flex; flex-flow: column nowrap;`
cont jcsb = css`justify-content: space-between;`
const fa = css`flex: auto;`

const flex = flex => css`flex: ${flex};`
const margin = margin => css`margin: ${margin};`
const tint = (color, value) => coolTintColorFunctionFromOutside(color, value)


const Wrapper = styled.div`
  padding: ${minSpace};
  ${ffcn}
  ${jcsb}
  ${flex(1, 1, 'auto')}
  ${margin('minSpace')}
  background-color: ${tint(primaryRed, -10)};
`;

This way nobody has to learn a new pseudo CSS language and we don’t have to bload the styled-components with things JS does very good.

2reactions
kittencommented, Mar 18, 2017

@VicStor I’m sorry, but I meant globals as in variables in a global namespace. injectGlobal is an exception to what we normally do and we’re very clear about this in the docs:

We do not encourage the use of this. Use once per app at most, contained in a single file. This is an escape hatch.

It’s only for reset-like / normalize-like stylesheets.

The thing with adding sth like this is, while you’re getting rid of import-statements for some variables, you’re adding globals and changing the expected css syntax. I mean, stylis even supports ~~foo and var(~~foo) similar to css’s --foo and var(--foo), but it’s all custom and adds more mental overhead.

I’m not that concerned about the mental overhead however, but I’m more concerned that adding something like this would mean that we’re departing from being a pure css-in-js approach.

For reference: download-1

Thanks btw, I always appreciate a good discussion 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sass like Isla | Baby wearing, Isla, Sass - Pinterest
Sass like Isla. 100% cotton onesies with sass Inspired by family and finding the beauty in chaos. Babywear that brings out our little...
Read more >
Sass Like Isla - Facebook
Sass Like Isla. 156 likes. 100% cotton baby onesies and Tees with personality. Inspired by my gorgeous but temperamental daughter, seeing the beauty...
Read more >
Throwin sass like confetti ❤︎ #HowYaLikeThat presave in ...
Throwin sass like confetti ❤︎ #HowYaLikeThat presave in comments! ... the only thing a #rambler needs, is a suitcase & a gun ...
Read more >
Throw Sass Like Confetti Sassy Shirt Confetti Shirt Sassy - Etsy
Instant download items don't accept returns, exchanges or cancellations. Please contact the seller about any problems with your order.
Read more >
Throw Sass Like Confetti Zip Hoodie : Clothing, Shoes ... - Amazon.com
To calculate the overall star rating and percentage breakdown by star, we don't use a simple average. Instead, our system considers things like...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found