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

feat: add shouldExclude option to pluginStrictTokenScope #58

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

k35o
Copy link
Contributor

@k35o k35o commented May 30, 2024

Close #54

Copy link

vercel bot commented May 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
pandabox-z5kx ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 31, 2024 3:14am

@@ -10,6 +10,7 @@ import type { PandaContext } from '@pandacss/node'
export interface StrictTokensScopeOptions {
categories?: TokenCategory[]
props?: Array<keyof CssProperties | (string & {})>
shouldExclude?: boolean
Copy link
Owner

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

Copy link
Contributor Author

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) {
Copy link
Owner

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))

@k35o
Copy link
Contributor Author

k35o commented May 31, 2024

We noticed that the type of values not included in CssProperties, such as textStyle, is broken, although from existing.

The type below will be any.

{
  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;

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

Successfully merging this pull request may close these issues.

Request for deny list when using pluginStrictTokensScope
2 participants