-
Notifications
You must be signed in to change notification settings - Fork 8
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
How does this project compare to jss? #2
Comments
tl;dr: CurrentlyAPIJSS has an API to attach/detach style sheets to the DOM and to add/modify the properties of a given "rule".
Both support "local" class names, but the JSS local names may clash if JSS is included more than once in a page. The probability of that happening with Features/plugins
Out of the box, There's no smart auto-prefixing at the moment. You can either prefix all properties in bulk or do it manually using the _o$_ms$_moz$_webkit$: {
box_shadow: "0 0 10px rgba(0,0,0,0.6)",
transform: "rotate(-45deg) scaleX(0.85)",
user_select: "none"
} This adds the prefixes in order, ending with the unprefixed property names thanks to the final
In the works:In the
(edit: actually, in the latest version everything is folded into a single
All of it is already functional and tested, but I need to fine tune the API and document it. |
tl;dr: i'm confused how to improve the way i do components and everytime i try to explain that, I end up with a relatively unstructured braindump - sry for that. Sounds great. I'm also watching css-modulesify. Atomify is using
You can pass in variables to imported stylesheets using: :root {
--variablename: #fff;
} and later in a css property: A presentation about atomify is here and the slides in the end show how to do themeing across css components In the issue links above i write some code of how my frameworkless components in javascript approximately look like and how i'm trying to think about how to use all that stuff - ideally to have somehow the same awesome features i get from the node javascript Currently:
If they will be autoprefixed to make the application of BEM conventions simpler across many composed modules, it's hard for me how to write my |
The use case I had in mind when writing I think that it could accommodate your server-based use case, but we'd have to rethink the gluing process... I'll read your slides. I had to clean them up a bit, the backgrounds and animations were distracting. Thankfully you host them here, which means I could just fork your repo and get rid of the noise :-). A first thought is about BEM. It is mostly a way to namespace your CSS classes to avoid name clashes. You can use the same design philosophy in Using this example: https://css-tricks.com/bem-101/ /* Block component */
.btn {}
/* Element that depends upon the block */
.btn__price {}
/* Modifier that changes the style of the block */
.btn--orange {}
.btn--big {} <a class="btn btn--big btn--orange" href="http://css-tricks.com">
<span class="btn__price">$9.99</span>
<span class="btn__text">Subscribe</span>
</a> With the css = j2c.sheet({
".btn": {
...,
"& .price": {...},
"&.orange": {...},
"&.big": {...}
}
}) .btn_j2c_330681706_1434027505456_3{
...
}
.btn_j2c_330681706_1434027505456_3.big_j2c_330681706_1434027505456_3{
...
}
.btn_j2c_330681706_1434027505456_3.orange_j2c_330681706_1434027505456_3{
...
}
.btn_j2c_330681706_1434027505456_3 .price_j2c_330681706_1434027505456_3{
...
} <a class="{css.btn} {css.big} {css.orange}" href="http://css-tricks.com">
<span class="{css.price}">$9.99</span>
<span class="{css.text}">Subscribe</span>
</a> That's the idea for a client-side framework. For your server-based use case you could use normal classes in the source ( You could either use The last two options are not very good (stream of thoughts here). Custom attributes mean you fall back to the global namespace, and relying on the tree structure is brittle. I'll read your slides and add more later. |
Actually, I was talking about client side updates. I like Once my component rendered, i'd like to attach event listeners that change a components styling. // BUTTON USAGE
var messageBus = require('./messageBus.js')
var buttonComponent = require('button-component')
var specialColorCode = '#a339d2'
var buttonStyle = buttonComponent(document.body, messageBus)
messageBus.on('requestUpdates', function () {
messageBus.emit('newUpdates', {
data: prompt('What is the new data?')
})
buttonStyle.create({ Info__content: { color: specialColorCode } })
}) // BUTTON IMPLEMENTATION
var buttonStyle = require('./buttonStyle')
module.exports = function ButtonComponent (parentDOM, eventBus) {
parentDOM.innerHTML = '<div class="Info">' +
'Info: <input class="Info__content" type="text" name="info"><br>' +
'<button class="Info__button">Refresh</button>' +
'</div>'
var Info = parentDOM.querySelector('.Info')
var __content = parentDOM.querySelector('.Info__content')
var __button = parentDOM.querySelector('.Info__button')
__button.addEventListener('click', function onclick (event) {
// check for updates
Info.setAttribute('class', 'Info Info--loading')
eventBus.emit('requestUpdates')
})
eventBus.on('newUpdates', function (update) {
Info.setAttribute('class', 'Info')
if (update && update.data) {
__content.value = update.data
}
})
buttonStyle.on('update', function () {
var newCSS = buttonStyle.render()
console.log(newCSS)
})
return buttonStyle
} |
Indeed, JSS is probably a better solution since it supports style sheet mutations after DOM insertion (which are handledd automatically under the hood. That being said, for your use case, you probably need per component instance updates rather than the per selector updates that JSS provides... Maybe you could, using JSS, create one class per component instance for the styles that need to be updated, and operate on that in your event handlers...
Edit: also, yikes! yet another competitor! Hello Edit2: You could also create per component instance |
This is arleady solved. You just create own Jss instances if this is an issue for you.
Don't see the power, see a simpler version of jss) |
Thanks for passing by @kof.
Look better: mixin = {
" .child": {
float:"left"
},
".modifier": {
color:"green"
},
font_size: "10px"
}
j2c.sheet({"@global":{
".foo":{
color: "#f00",
"@media bar": {
".firefox &": {margin: "33px"},
" .baz": [
mixin,
{
"@supports qux": {
border: [
'3px solid green',
{left$right: '1px solid red'}
]
}
}
]
}
}
}}) .foo{
color:#f00;
}
@media bar{
.firefox .foo{
margin:33px;
}
.foo .baz .child{
float:left;
}
.foo .baz.modifier{
color:green;
}
.foo .baz{
font-size:10px;
}
@supports qux{
.foo .baz{
border:3px solid green;
border-left:1px solid red;
border-right:1px solid red;
}
}
} See now ;-)? This is out of the box, no plugin required (I indented the result manually for readability). I'm using the Sadly I had to break the 1KB barrier, and I'm now at 1031 bytes mingzipped for the CommonJS version. /humblebrag ;-) BTW, for @serapath, I was looking for your input on this:
Is it reasonable to update properties continuously (say, on mouse movement or light/tilt sensor events) using JSS? |
Well, scoped selectors are by default in jss too, nested at-rules is something I never used and though not implemented ... but if I get some requests on this I am open to support it too. The weird thing is (same in postcss) that you actually treat selectors as namespaces to access them later from javascript. In jss I strongly differentiate namespaces for rules and selectors. Selectors defined by user are only possible in global style mode. ({named: false} option) As for plugins I didn't put all of them into core to make core smaller and faster and allow people to use just plugins they need. Core is also platform agnostic. Dynamic props is the only part of jss core which is browser dependent. It makes sense to change rules dynamically when the rule is applied to lots of elements. So that updating styles on every element would be less performant than changing it on the rule. |
https://github.com/jsstyles/jss
The text was updated successfully, but these errors were encountered: