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

[Feature Proposal] - Safelist values should have access to RuleContext #3531

Closed
4 tasks done
AndrewBogdanovTSS opened this issue Jan 26, 2024 · 1 comment · Fixed by #3693
Closed
4 tasks done

[Feature Proposal] - Safelist values should have access to RuleContext #3531

AndrewBogdanovTSS opened this issue Jan 26, 2024 · 1 comment · Fixed by #3693

Comments

@AndrewBogdanovTSS
Copy link
Contributor

Clear and concise description of the problem

Variants, rules and shortcuts supports syntax that allows to access RuleContext object that contains active theme and other useful information. Safelist for some reason doesn't support such syntax which prevents generating safelist based on main project configuration.

Suggested solution

I will provide a practical example why access to theme might be needed.
Let's suppose we want to generate safelist for utility on all media breakpoints specified in the project.
In theme we may have something like this:

const breakpoints = {
  "md": 768,
  "lg": 1024
}
...
theme: {
    screens: mapObject(breakpoints, (size) => `${size}px`),
}

than I would like to access those screens in my safelist to generate utility on those resolutions

safelist: ['md:p-1 lg:m-1'] // Currently I have to define them manually which is misaligned with a theme

sagelist should allow such syntax:

safelist: [( { theme } ) => Objec.keys(theme.screens).map(mq => `${mq}:m-1`)]

Alternative

At the moment I have to manually import needed data from a JSON file but this is inflexible solution taking into account that my project uses Nuxt layers where every layer potentially can override/augment Uno theme object. So breakpoints as any other parts of config are determined only once unocss:config Nuxt hook was executed.

Additional context

No response

Validations

  • Read the Contributing Guidelines.
  • Read the README.md of using the package.
  • Already used the Interactive Docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@AndrewBogdanovTSS AndrewBogdanovTSS changed the title Safelist values should have access to RuleContext [Feature Request] - Safelist values should have access to RuleContext Jan 26, 2024
@AndrewBogdanovTSS AndrewBogdanovTSS changed the title [Feature Request] - Safelist values should have access to RuleContext [Feature Proposal] - Safelist values should have access to RuleContext Jan 26, 2024
@antfu
Copy link
Member

antfu commented Jan 26, 2024

I am not against it. Feel free to PR - tho I am not sure if the timing allows it to have such context, but if we do, happy to have that capability

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants