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: token/utility/codegen hooks #2094

Merged
merged 15 commits into from
Feb 1, 2024
Merged

feat: token/utility/codegen hooks #2094

merged 15 commits into from
Feb 1, 2024

Conversation

astahmer
Copy link
Collaborator

@astahmer astahmer commented Jan 27, 2024

Closes #2056
Closes #1848

📝 Description

Introduce 3 new hooks:

tokens:created

This hook is called when the token engine has been created. You can use this hook to add your format token names and
variables.

This is especially useful when migrating from other css-in-js libraries, like Stitches.

export default defineConfig({
  // ...
  hooks: {
    'tokens:created': ({ configure }) => {
      configure({
        formatTokenName: (path) => '$' + path.join('-'),
      })
    },
  },
})

utility:created

This hook is called when the internal classname engine has been created. You can override the default toHash function
used when config.hash is set to true

export default defineConfig({
  // ...
  hooks: {
    'utility:created': ({ configure }) => {
      configure({
        toHash(paths, toHash) {
          const stringConds = paths.join(':')
          const splitConds = stringConds.split('_')
          const hashConds = splitConds.map(toHash)
          return hashConds.join('_')
        },
      })
    },
  },
})

codegen:prepare

This hook is called right before writing the codegen files to disk. You can use this hook to tweak the codegen files

export default defineConfig({
  // ...
  hooks: {
    'codegen:prepare': ({ artifacts, changed }) => {
      // do something with the emitted js/d.ts files
    },
  },
})

💣 Is this a breaking change (Yes/No):

no

📝 Additional Information

With those hooks, the features from the two mentioned PR should be possible without introducing new config options or changing much about Panda internals

Copy link

changeset-bot bot commented Jan 27, 2024

🦋 Changeset detected

Latest commit: 8a41b6e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 20 packages
Name Type
@pandacss/token-dictionary Patch
@pandacss/generator Patch
@pandacss/fixture Patch
@pandacss/shared Patch
@pandacss/studio Patch
@pandacss/types Patch
@pandacss/core Patch
@pandacss/node Patch
@pandacss/config Patch
@pandacss/dev Patch
@pandacss/parser Patch
@pandacss/extractor Patch
@pandacss/logger Patch
@pandacss/preset-atlaskit Patch
@pandacss/preset-base Patch
@pandacss/preset-open-props Patch
@pandacss/preset-panda Patch
@pandacss/astro-plugin-studio Patch
@pandacss/postcss Patch
@pandacss/is-valid-prop Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Jan 27, 2024

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

Name Status Preview Updated (UTC)
panda-docs ✅ Ready (Inspect) Visit Preview Feb 1, 2024 6:53pm
panda-playground ✅ Ready (Inspect) Visit Preview Feb 1, 2024 6:53pm
panda-studio ✅ Ready (Inspect) Visit Preview Feb 1, 2024 6:53pm

test: allow passing custom hooks

refactor: dict.formatTokenName
refactor: use array of string as path rather than dot-delimited string for colorPalette
-> so that the formatTokenName can be replaced with custom logic with hooks, we couldnt before because the join('.') logic was hardcoded everywhere
@segunadebayo segunadebayo merged commit ab32d1d into main Feb 1, 2024
7 checks passed
@segunadebayo segunadebayo deleted the feat/token-hooks branch February 1, 2024 18:53
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.

None yet

2 participants