Skip to content
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

Support “custom units” #221

Open
nicksrandall opened this issue Jul 2, 2022 · 2 comments
Open

Support “custom units” #221

nicksrandall opened this issue Jul 2, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@nicksrandall
Copy link
Contributor

CSS Custom Units proposal was recently accepted and it would be awesome if parcel CSS allowed us to use that syntax today and then compile it down to what is currently supported by browsers.

See: w3c/csswg-drafts#7379 (comment)

@devongovett
Copy link
Member

Interesting. Perhaps a bit early to implement, but I look forward to seeing the spec.

@devongovett devongovett added the enhancement New feature or request label Jul 3, 2022
@devongovett
Copy link
Member

This could be implemented as a custom transform now: https://lightningcss.dev/transforms.html. There's an example of this in the tests:

test('custom units', () => {
// https://github.com/csstools/custom-units
let res = transform({
filename: 'test.css',
minify: true,
code: Buffer.from(`
.foo {
--step: .25rem;
font-size: 3--step;
}
`),
visitor: {
Token: {
dimension(token) {
if (token.unit.startsWith('--')) {
return {
type: 'function',
value: {
name: 'calc',
arguments: [
{
type: 'token',
value: {
type: 'number',
value: token.value
}
},
{
type: 'token',
value: {
type: 'delim',
value: '*'
}
},
{
type: 'var',
value: {
name: {
ident: token.unit
}
}
}
]
}
}
}
}
}
}
});
assert.equal(res.code.toString(), '.foo{--step:.25rem;font-size:calc(3*var(--step))}');
});
.

I'll leave this open to implement natively once it appears in a spec though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants