-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: add shouldExclude option to pluginStrictTokenScope #58
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -10,6 +10,7 @@ import type { PandaContext } from '@pandacss/node' | |||
export interface StrictTokensScopeOptions { | |||
categories?: TokenCategory[] | |||
props?: Array<keyof CssProperties | (string & {})> | |||
shouldExclude?: boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the excludeCategories: ['colors', 'spacing']
made more sense here instead of a boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fix it.
} | ||
|
||
// const regex = new RegExp(`(${strictTokenProps.join('|')})\?: ConditionalValue<WithEscapeHatch<(.+)>>`, 'g') | ||
const regex = /(\w+)\?: ConditionalValue<WithEscapeHatch<(.+)>>/g | ||
|
||
const transformed = | ||
content.code.replace(regex, (match, prop, value) => { | ||
if (shouldExclude) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in my mind, this feature could be done simply by re-using the current logic in transformPropTypes
and filling the categories
with every possible TokenCategory
(when excludeCategories
is not empty) then filtering the array using excludeCategories
something like:
const allCategories = ["zIndex", "opacity", "colors", "fonts", "fontSizes", "fontWeights", "lineHeights", "letterSpacings", "sizes", "shadows", "spacing", "radii", "borders", "durations", "easings", "animations", "blurs", "gradients", "assets", "borderWidths", "aspectRatios", "containerNames"]
// excludeCategories: ['colors', spacing'] -> allCategories.filter((cat) => !excludeCategories.include(cat))
We noticed that the type of values not included in The type below will be {
textStyle?: ConditionalValue<UtilityValues["textStyle"] | CssProperties["textStyle"]>
} I had to fix it in a separate issue or pr. And, incidentally, that did not happen with the first way it was implemented. if (strictTokenProps.includes(prop)) {
const longhand = ctx.utility.shorthands.get(prop);
return `${prop}?: ConditionalValue<${value} | CssProperties["${longhand || prop}"]>`;
};
return match; |
Close #54