-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Pass kwargs to mixin from hash? #1695
Comments
No, this is not possible currently, but I like the idea. I'll implement this feature. BTW in simple cases you can use hashes interpolation. |
Thanks Panya! :) I'm mostly a front end coder, but can I help out at all? |
@kezzbracey You can think about how you would like to see this feature implemented: which syntax should it have, how should you pass the hash in a way Stylus would understand it is a kwargs? We can't allow just passing a hash and treating its keys as kwargs, so we'd need something to help Stylus understand what you need from it. All I can think atm is using a reserved
But it is rather obscure and then we'd need to find out how to manage a case when such |
splat, js-like ( |
I guess I like |
Reading the above, I'd agree |
Totally agree about the syntax :-) Is there any news about this feature ? That's only the missing part to my little component framework :-) |
@kezzbracey if you are interested, I write a little plugin to do that : https://github.com/hikkyu/advanced-css-component-stylus/blob/master/plugin/callWithObjArg.js // include plugin
use('./path/callWithObjArg.js')
hash = {
foo: 'bar'
}
myMixin($foo: 'foo')
body
color $foo
callWithObjArg(myMixin, hash) It's not perfect but work's :-) |
That's awesome, thanks a lot for the effort and the share @hikkyu :-) |
Hey guys,
First, thanks for the awesome maintenance you're doing on Stylus. I really appreciate it. :)
I'm wondering if it's currently possible to pass a set of keyword arguments through a mixin from a hash?
I took a run at creating a plugin to handle the process, but didn't really know what I was doing well enough I'm afraid.
What I'm trying to achieve is the ability to create hashes inside styles that define a series of mixins and their associated args to be output against the style. These hashes then get run through an "output-mixins" mixin.
It works beautifully if the mixin being called consumes rest params or if I just apply the values directly against a property, but I haven't been able to figure out how to pass kwargs from a hash, or from a predefined variable. I've also tried to use various BIFs to process the hash into usable kwargs, but didn't succeed. Each of my attempts have led to either the hash being output as a literal, or the comma separated list of key value pairs being processed as the first argument only.
This is where I'm at so far:
Stylus:
Output:
What do you think?
Is there a way to do this that I'm missing? Could I perhaps make it work via a custom js function / plugin? Or am I attempting something that can't really come off at this stage?
Thanks for any insight you can share!
Cheers,
Kezz
The text was updated successfully, but these errors were encountered: