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

Css Variable Custom Resolver Configuration #1053

Closed
jerrywithaz opened this issue Aug 22, 2022 · 2 comments · Fixed by #1078
Closed

Css Variable Custom Resolver Configuration #1053

jerrywithaz opened this issue Aug 22, 2022 · 2 comments · Fixed by #1078
Labels
enhancement: proposal 💬 Improvement of current behaviour that needs to be discussed needs: triage 🏷 Issue needs to be checked and prioritized

Comments

@jerrywithaz
Copy link

jerrywithaz commented Aug 22, 2022

Describe the enhancement

It would be great to have the ability to format the css variable names via the linaria.config.js file.

I prefer my css variable names to be the following format: {componentName}-{cssProperty}-{slug}-{index}.

So an example would be: --flexbox-flex-direction-f22br00-0

Motivation

My team prefers descriptive variable id's because it makes the css easier to read and makes it easy to determine what each variable is being used for rather than having to look back and forth between the variables and the css to determine which variable belongs to which css property. I am sure that other teams would like to customize their formats to their needs as well but I don't think linaria should force a format on anyone.

I implemented this by using my own tagResolver and extending StyledProcessor. However, it required a lot of code for this simple functionality.

Possible implementations

Add an idResolver option to the linaria config with the following shape: idResolver: (displayName, source, unit, currentCssText, slug) => string.

  • displayName - the displayName of the component
  • source - the string source of the css property value
  • unit - the unit
  • currentCssText - the current value of the cssText as its being processed i.e. flex: 1; flex-direction: . This allows for developers to extract the current css variable via regex (my usecase).
  • slug - the component slug

Related Issues

@jerrywithaz jerrywithaz added the enhancement: proposal 💬 Improvement of current behaviour that needs to be discussed label Aug 22, 2022
@github-actions github-actions bot added the needs: triage 🏷 Issue needs to be checked and prioritized label Aug 22, 2022
@Anber Anber closed this as completed in 87ffe61 Oct 13, 2022
@Anber
Copy link
Collaborator

Anber commented Oct 13, 2022

Hi @jerrywithaz!

Thank you for your proposal. It has been implemented in #1079 and will be released soon.

@jerrywithaz
Copy link
Author

@Anber this is awesome, thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement: proposal 💬 Improvement of current behaviour that needs to be discussed needs: triage 🏷 Issue needs to be checked and prioritized
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants