Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

More control over configuration extension #1899

Closed
BorisZubchenko opened this issue Jan 1, 2024 · 2 comments
Closed

More control over configuration extension #1899

BorisZubchenko opened this issue Jan 1, 2024 · 2 comments

Comments

@BorisZubchenko
Copy link

BorisZubchenko commented Jan 1, 2024

Description

I have a simple scenario:

  1. I want my theme to be based on the preset-panda.
  2. I want to overwrite (not extend) some tokens, i.e. colors.
{  bg: 'accent.5' } // ✅ Custom colors
{  bg: 'red.500' } // ❌ I don't want to have an access to the colors provided by Panda (Tailwind colors)
  1. I want other tokens to be preserved, i.e. spacing.

Here's my configuration:

import { defineConfig } from '@pandacss/dev'

const pandaConfig = defineConfig({
  // ...
  theme: {
    semanticTokens: {
      colors:  {
        accent: {
          5: { value: '{colors.green.500}' }
        }
      }
    },
    tokens: { 
      colors: {
        green: {
          500: { value: { '#0f0' } }
        }
      }
    },
  },
})

export default pandaConfig

With this configuration, I can't use spacing tokens:

css({
  background: 'accent.5', // ok
  padding: '4', // outputs '4px', not '1rem'
})

Problem Statement/Justification

  1. I was wondered why Park UI literally duplicated some of Panda's tokens. I think this is because they didn't have the ability to just extend from the preset-panda. It only extends preset-base, which lacks spacing tokens.
  2. Tailwind allows this kind of extension. It can be harder to migrate.
  3. It make the developer to duplicate "convenient" tokens from the preset-panda.

Proposed Solution or API

  • To overwrite tokens, provide new ones:
{
  theme: {
    tokens: {
      colors: {
        red: {...}
      }
    }
  }
}
  • To remove tokens, provide an empty object:
{
  theme: {
    tokens: {
      colors: {} // no more colors
    }
  }
}
  • To extend tokens, use extend:
{
  theme: {
    extend: {} // already implemented
  }
}

Alternatives

  • Duplicate tokens from the preset-panda.
  • Extend, not overwrite. It creates typings mess (and I think increases the size of the output CSS file due to CSS variables).
@astahmer
Copy link
Collaborator

astahmer commented Jan 1, 2024

currently the solution is to just use javascript and pick/omit whatever you need, as described here

we thought of maybe making it easier with a syntax similar to the one you proposed but we're mostly waiting to see if there's enough demand before adding more features, maybe you could make it a feature request ? https://panda-css.canny.io/feature-request

@BorisZubchenko
Copy link
Author

I thought this was a feature request :)

Anyway, I've created a feature request that links here:
https://panda-css.canny.io/feature-request/p/more-control-over-configuration-extension

@chakra-ui chakra-ui locked and limited conversation to collaborators Jan 2, 2024
@segunadebayo segunadebayo converted this issue into discussion #1902 Jan 2, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants