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

Styles override doesn't work properly #804

Closed
1 of 3 tasks
Emiliano-Bucci opened this issue Jun 23, 2023 · 6 comments
Closed
1 of 3 tasks

Styles override doesn't work properly #804

Emiliano-Bucci opened this issue Jun 23, 2023 · 6 comments

Comments

@Emiliano-Bucci
Copy link

Emiliano-Bucci commented Jun 23, 2023

Description

It seems that when trying to override styles from outside a component using the cx() utility to merge internal and external classes, the ones that should override the internal ones doesn't work. It seems that if the className arrives from an external prop it doesn't work properly, but if the classNames are defined internally, it does.

Link to Reproduction

https://stackblitz.com/edit/vitejs-vite-2cufqt?file=src%2FApp.tsx,src%2FComp.tsx&terminal=dev

Steps to reproduce

  1. Go to '...'
  2. Click on '...'
  3. Scroll down to '...'
  4. See error

JS Framework

React

Panda CSS Version

0.4.0

Browser

No response

Operating System

  • macOS
  • Windows
  • Linux

Additional Information

No response

@pawelblaszczyk5
Copy link
Contributor

pawelblaszczyk5 commented Jun 23, 2023

The cx function just concatenates strings https://github.com/chakra-ui/panda/blob/5d5888c516114556aafcd2174fbebe0105561f7c/packages/generator/src/artifacts/js/cx.ts

To achieve the expected effect I recommend using a pattern

@Emiliano-Bucci
Copy link
Author

@pawelblaszczyk5 mmm, what i want is to be able to override existing styles from outside the component in a simple way; i guess that the pattern is something that is already predefined.

@pawelblaszczyk5
Copy link
Contributor

I think it depends on an exact use case, you can create a custom pattern if you want a full flexibility. You can also create recipe if you want some predefined variants.

I know it's not a direct answer to your question, but usually your components shouldn't have a fully modifiable styles from the outside 😃 If you could point me to an example use case I could try to provide some better explanation/solution

@segunadebayo
Copy link
Member

Hi @Emiliano-Bucci,

The cx function only joins class names. To get style merging working as expected, you'll need to use the JSX API, which implements style merging correctly.

https://stackblitz.com/edit/vitejs-vite-7hwybm?file=src%2FApp.tsx,src%2FComp.tsx,styled-system%2Fjsx%2Findex.d.ts,styled-system%2Fjsx%2Ffactory.d.ts&terminal=dev

@Emiliano-Bucci
Copy link
Author

@segunadebayo Hi! I reopen because i have a doubt: is correct that this doesn't work as expected? -> https://stackblitz.com/edit/vitejs-vite-3qw93q?file=src%2FApp.tsx&terminal=dev

Should i always pass the prop css in order to panda.css understand and override correctly?

Thanks!

@anubra266
Copy link
Collaborator

@Emiliano-Bucci your example is against how Panda works. Panda can't know that those styles in the styles prop should be extracted.

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

No branches or pull requests

4 participants