-
Notifications
You must be signed in to change notification settings - Fork 2
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
Discussion: replace bracket syntax used in property names #130
Comments
Can you explain how this new To answer one question:
Currently if you use If you use To your questions I would add:
The reason why the bracket syntax was added was because I believed that declarations were always destructive, meaning they replaced all previous declarations of that property. If that's not the case then it changes the reason for the syntax. I want to understand this better so I'm going to play around with |
Ok, at least for On Twitter you suggested this syntax for explicitly removing existing listeners, which I like: button {
event: * unset;
} In Corset, what should As an example: <main class="app"></main> main {
class-toggle: app false;
}
main.condition {
class-toggle: app unset;
} Should the |
In order to support multiple events of the same type, I think there needs to be a way to name an event. I want to preserve this ability: button {
event: click var(--close);
}
.modal button {
event-capture: click true;
} The above is modifying the same event listener in another selector. Another use-case is overriding a listener itself: button {
event: click var(--close);
}
button.open {
event: click var(--open);
} This is not meaning to add a second event listener, but rather to replace the previous one. I think we can get the best of both worlds by allowing a listener to be named similar to how a grid line can be named. button {
event: [close] click var(--close), [second] click var(--second);
}
.modal button {
event-capture: [close] click true;
} In this way we can modify the The |
I think the grid line naming convention fits great here. Although the I think such comma-separated list of shorthand property values is only used in one place currently in CSS: for the transition property. It is interesting to note that with this syntax, if you do this: .element {
transition-property: opacity, left, top, height;
transition-duration: 3s, 5s;
} It is treated like this: .element {
transition-property: opacity, left, top, height;
transition-duration: 3s, 5s, 3s, 5s;
} I.e. the values are repeated as necessary. You can read about it here and here. So in your last example, because you have only set the However, you actually forked the model here. The way you set the value of event-capture defers from the way it would be set for the transition CSS property: you used the identifier of the listener (actually you used both identifiers: the custom name (close) and the type (click)). Therefore, it wouldn't make sense for the value to be repeated for the other listeners, because it targets precisely this one. I think such syntax is relevant, and that in that case the values of the other listeners should not be changed. The model could be: to modify a value with longhand property, you have to use the identifier of that value. The order doesn't matter, and what is not declared remains untouched. Now, this only allows to update the values of an existing listener, not to add new ones or remove some without touching the other. Here are some ideas to further circumvent the destructivity of declarations and allow that: Allow a
|
@brunostasse Very open to all of these ideas! |
@matthewp When you say The global values in CSS (which can be used with any property) are:
So, since no event, attribute, prop, etc, is inherited from the parent element (right?) Do you affect a different meaning to |
Hey @brunostasse sorry for taking so long to get back and thanks for the detailed thoughts. I had created another issue for As far as |
Hi @matthewp, so yeah:
So you want: button {
event: all initial;
} |
I have seen in your blog post about v2.0 that you're considering making properties additive. I have to say it's a big paradigm shift, and it might confuse people coming from CSS. Having to first reset a property value and then set its new value to replace the original one also feels a bit cumbersome. button {
event: click var(--increment);
}
button.disabled {
event: all initial;
event: click var(--alert);
} If I may, I have an alternate proposal to replace the bracket syntax that might fit better the CSS paradigm. The idea is to use the nested longhand property syntax from Sass and PostCSS, like this: button {
event: {
click: var(--increment);
mouseenter: var(--display-stuff);
}
}
button.disabled {
event: {
click: var(--alert);
}
} This syntax is not valid CSS, but feels close, and is supported by all tooling that works with both Sass and PostCSS. Properties remain destructive, so you stay in the CSS paradigm, but you can easily add a new one or replace an existing one without touching the others. You can also remove all grouped properties with This can be used for attr, event, prop, data...! |
Hey @brunostasse, by additive I don't mean that it adds an extra event like your example implies. button {
event: click var(--increment);
}
button.disabled {
event: click var(--alert);
} This will replace the click event, not add a second one. This is because button {
event: [one] click var(--increment);
event: [two] click var(--alert);
} This would add two click events, because you have given them distinct names. You could think later reset a single one: button {
event: [one] click var(--increment);
event: [two] click var(--alert);
}
button.disabled {
event: [two] unset;
} This would remove the To explain what I mean by additive it's best to look at other properties like button {
class-toggle: one true;
class-toggle: two true;
} In Corset 1.0 this only adds the Thanks also for the perspective on unset vs. initial. I'll think more about this and respond later. I might create a spreadsheet showing how unset / initial work in CSS to compare how they might work in Corset, to better show the similarities and differences. |
Oh alright, so the additivity is only for the values accepting the custom-key-value syntax. So, in this case: button {
event: [one] click var(--increment);
event: [two] click var(--alert);
}
button.enabled {
event: focus var(--handle-focus);
}
button.disabled {
event: [three] mouseenter var(--handle-enter), [four] mouseleave var(--handle-leave);
}
|
No, You can think about the So the same rules apply whether you provide an explicit key (tentatively called a Events are the only property that will use this feature. The So it might be easier to understand the behavior if you think about these properties first and think about events only after you understand, for ex. To illustrate, take this example: button {
class-toggle: one true;
}
button[disabled] {
class-toggle: two true;
} In Corset 1.0 only the In Corset 2.0 both the |
This feature is down to 1 skipped test. Can see the branch here: https://github.com/matthewp/corset/compare/labeled-events?expand=1 Naming is still very much up for discussion. I think the behavior as described here is the way to go. Will follow up on naming. |
I should say, everything is open to discussion, but the branch implements the additive behavior discussed in this thread. @brunostasse brings up an interesting idea for continuing the destructive behavior but adding a Curious @jonathantneal your thoughts on this idea. My instinct is that Corset, unlike CSS, is mostly made up of properties that contain multiple values. So I say this to say, it feels like it is ok for Corset to deviate in this respect. But obviously I did feel differently before when I made them be initially destructive. So I appreciate all thoughts on this. |
On One could see some value in having unset-like behavior in the future though: body {
--role: "User";
}
.admin {
--role: "Admin";
}
.admin.revoked {
--role: unset;
} Given that, does it make more sense to:
I don't think I will implement the |
Actually I think I lean towards |
Draft PR: #134 |
Discussed more with @brunostasse offline and this really isn't button {
class-toggle: one true;
}
button[disabled] {
class-toggle: all revert-sheet;
} |
|
Also see w3c/csswg-drafts#1594 which talks about Additive Cascade. No progress or consensus in it right now, but maybe worth a read. |
Maybe it would make sense to support the keywords |
Additive behavior was merged in #134. It will likely be a while before 2.0 is released so plenty of time to change things if needed. |
@brunostasse and I went back and forth about the naming of the |
2.0 is released: https://github.com/matthewp/corset/releases/tag/v2.0.0 |
This issue is to discuss whether it would be possible and best for corset to avoid the bracket syntax used in CSS property names. The brackets would be avoided to follow the CSS Syntax rules for consuming a list of declarations, which limits property names to identifiers.
Current Syntax
Possible Solutions
An
event-set
property to add a given event type with a given event listener.Questions:
The text was updated successfully, but these errors were encountered: