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

[idea] pseudo inline styles #3

Closed
shama opened this Issue Mar 2, 2016 · 6 comments

Comments

Projects
None yet
4 participants
@shama
Member

shama commented Mar 2, 2016

An idea for handling CSS:

var bel = require('bel')
var css = {
  position: 'absolute',
  top: 100,
  left: 200
}
var element = bel`<div style=${css}>Hello!</div>`

Which would detect the style key and use dom-css to set the .style[prop] directly on the elements (CSP safe). It will even do vendor prefixing.

@shama shama closed this in 2286d59 Mar 3, 2016

@tunnckoCore

This comment has been minimized.

Show comment
Hide comment
@tunnckoCore

tunnckoCore May 21, 2017

@shama @yoshuawuyts could we revive that by adding really few bytes?

Very basic and almost enough support for this can be implemented in 2-4 lines

      // support style as object
      // both `fontSize` and `font-size` work that way
      if (key === 'style' && typeof val === 'object') {
        for (var k in val) {
          el.style[k] = val[k]
        }
        continue
      }

The cool thing is that DOM is smart enough, so it accepts el.style.fontSize and el.style['font-size'] by default.

tunnckoCore commented May 21, 2017

@shama @yoshuawuyts could we revive that by adding really few bytes?

Very basic and almost enough support for this can be implemented in 2-4 lines

      // support style as object
      // both `fontSize` and `font-size` work that way
      if (key === 'style' && typeof val === 'object') {
        for (var k in val) {
          el.style[k] = val[k]
        }
        continue
      }

The cool thing is that DOM is smart enough, so it accepts el.style.fontSize and el.style['font-size'] by default.

@shama

This comment has been minimized.

Show comment
Hide comment
@shama

shama May 21, 2017

Member
var bel = require('bel')
var css = require('dom-css')
var element = bel`<div>Hello!</div>`
css(element, {
  position: 'absolute',
  top: 100,
  left: 200
})

Is pretty much the same code but then you can control which version of dom-css you use or even use an entirely different CSS library. It's not about implementation difficultly but rather keeping this library generic.

Member

shama commented May 21, 2017

var bel = require('bel')
var css = require('dom-css')
var element = bel`<div>Hello!</div>`
css(element, {
  position: 'absolute',
  top: 100,
  left: 200
})

Is pretty much the same code but then you can control which version of dom-css you use or even use an entirely different CSS library. It's not about implementation difficultly but rather keeping this library generic.

@timwis

This comment has been minimized.

Show comment
Hide comment
@timwis

timwis May 21, 2017

Member

That starts to be a lot less convenient when element is a tree and you want to style its children though. You'd have to use querySelector and such. :-/

Member

timwis commented May 21, 2017

That starts to be a lot less convenient when element is a tree and you want to style its children though. You'd have to use querySelector and such. :-/

@shama

This comment has been minimized.

Show comment
Hide comment
@shama

shama May 21, 2017

Member

Maybe it's because I rarely use inline styles and when I do, it's almost always directly on the element. Non-inline CSS is far superior IMO so this convenience isn't useful to me.

But, if the overwhelming consensus is to add this back then we can.

Member

shama commented May 21, 2017

Maybe it's because I rarely use inline styles and when I do, it's almost always directly on the element. Non-inline CSS is far superior IMO so this convenience isn't useful to me.

But, if the overwhelming consensus is to add this back then we can.

@tunnckoCore

This comment has been minimized.

Show comment
Hide comment
@tunnckoCore

tunnckoCore May 21, 2017

Probably. But it cost nothing and DOM itself supports it. If anyone want more then he can use something like dom-css or such.

tunnckoCore commented May 21, 2017

Probably. But it cost nothing and DOM itself supports it. If anyone want more then he can use something like dom-css or such.

@yoshuawuyts

This comment has been minimized.

Show comment
Hide comment
@yoshuawuyts

yoshuawuyts May 21, 2017

Member
Member

yoshuawuyts commented May 21, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment