css icon indicating copy to clipboard operation
css copied to clipboard

✨ Functional styles

Open bhvngt opened this issue 2 years ago • 9 comments

Description

It will be very useful if master-css can allow passing parameters to custom classes.

For example

Style.extend('classes', 
    {
        btn: (size,blue) => `font:${size}rem text:center h:40 bg:${blue}`
    },
);
<div class="btn(1,blue)">

bhvngt avatar Aug 17 '22 10:08 bhvngt

It would be great, If we can also pass parameter to custom values.

Styles.extend('values', {
    'box-shadow': {
        push(color): `0 .2rem 0 ${color}`
}
})

ansarizafar avatar Aug 24 '22 05:08 ansarizafar

Description

It will be very useful if master-css can allow passing parameters to custom classes.

For example

Style.extend('classes', 
    {
        btn: (size,blue) => `font:${size}rem text:center h:40 bg:${blue}`
    },
);
<div class="btn(1,blue)">

The feature was on our internal R&D list a long time ago. 😎

1aron avatar Oct 27 '22 17:10 1aron

Thanks @1aron. Is this feature available in v2-beta? As I could not find any reference of this feature in the v2 documentation.

Thanks for doing all the great work. I will be trying out v2 for my project.

bhvngt avatar Oct 30 '22 17:10 bhvngt

@bhvngt The feature will not be implemented at this time, but it'll definitely be. We still need to do more investigations and practical applications internally, probably in the later stage of v2.

1aron avatar Oct 30 '22 17:10 1aron

I think this feature should be titled "mixins" to avoid any confusion

itsezc avatar Nov 11 '22 17:11 itsezc

Is there any new update on this feature? I really need Functional classes.

ansarizafar avatar Jan 09 '23 14:01 ansarizafar

Is there any new update on this feature? I really need Functional classes.

same here

Awilum avatar Jan 09 '23 14:01 Awilum

I also really like this feature, it will probably be implemented in v2.1 or v2.2

1aron avatar Jan 09 '23 19:01 1aron

Using v2 configuration, it will look like:

export default {
    styles: {
        btn: (size, color) => `h:${size === 'md' ? 40 : 48} text:center inline-flex bg:${color}`
    }
}
<button class="btn(md,blue)">Submit</button>

You can also use it with class-variant:

import cv from 'class-variant'

const btn = cv('text:center inline-flex', {
    size: {
        sm: 32,
        md: 40
    },
    ({ color }) => `bg:${color}`
})

btn.default = {
    size: 48,
    color: 'white'
}

export default {
    styles: {
        btn: (size, color) => btn({ size, color })
    }
}

1aron avatar Oct 18 '23 14:10 1aron