-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(unplugin): HMR + transform (#46)
* fix(unplugin): outfile HMR * wip e2e test with vitest + playwright * test: make snapshot of scenarios folder before running tests / restore original state after * chore: simplify stuff * test: add virtual-file scenario * chore: rm unused deps * feat(unplugin): optimizeJs by default * feat: transform cva to optimized fn * chore: copy test from unplugin-panda-macro to unplugin refactor: dont transform cva for unplugin-panda-macro * chore: dont version panda.css file * feat(unplugin): granular JS optimization logic + ignore `with { type: "runtime" }` * chore: add changeset
- Loading branch information
Showing
55 changed files
with
2,601 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
'@pandabox/unplugin': minor | ||
--- | ||
|
||
- Fix CSS generation when using `outfile` | ||
|
||
- Add `optimizeJs` option to optionally transform your source code by inlining the `css` / `cva` / `${patternFn}` | ||
resulting classNames or even simplify `styled` JSX factory to their primitive HTML tags (originally coming from | ||
`@pandabox/unplugin-panda-macro`) | ||
|
||
-> This is enabled by default and can be disabled by setting `optimizeJs` to `false` or `"macro"` (to only transform | ||
functions using `with { type: "macro" }`) | ||
|
||
- Transform `cva` to an optimized string-version of the `cva` function : | ||
|
||
-> Style objects are converted to class strings, this might not work when styles should be merged and you can opt-out | ||
of this by using `with { type: "runtime" }` on your `cva` import or by setting `optimizeJs` to false (or `macro` to | ||
only transform functions using `with { type: "macro" }`) | ||
|
||
- Add e2e tests (in-browser + HMR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,5 @@ pnpm-debug.log* | |
styled-system | ||
.vercel | ||
.turbo | ||
scenarios-temp | ||
panda.css |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
declare module '*?raw' { | ||
const src: string | ||
export default src | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import 'virtual:panda.css' | ||
import { css } from '../styled-system/css' | ||
|
||
const overrides = css.raw({ | ||
bg: 'green.100', | ||
}) | ||
|
||
export const App = () => { | ||
return ( | ||
<div | ||
className={css( | ||
{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
fontWeight: 'semibold', | ||
color: 'green.300', | ||
textAlign: 'center', | ||
textStyle: '4xl', | ||
}, | ||
{ | ||
bg: 'yellow.200', | ||
color: 'red.500', | ||
}, | ||
overrides, | ||
)} | ||
> | ||
<span>Hello from Panda</span> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { css, cva } from '../styled-system/css' | ||
import { center } from '../styled-system/patterns' | ||
import { button } from '../styled-system/recipes' | ||
import 'virtual:panda.css' | ||
|
||
const overrides = css.raw({ | ||
bg: 'green.100', | ||
}) | ||
|
||
const atomicRecipe = cva({ | ||
base: { | ||
display: 'flex', | ||
}, | ||
variants: { | ||
visual: { | ||
solid: { bg: 'red.200', color: 'white' }, | ||
outline: { borderWidth: '1px', borderColor: 'red.200' }, | ||
}, | ||
size: { | ||
sm: { padding: '4', fontSize: '12px' }, | ||
lg: { padding: '8', fontSize: '24px' }, | ||
}, | ||
}, | ||
}) | ||
|
||
export const App = () => { | ||
return ( | ||
<div className={center({ h: 'full' })}> | ||
<div | ||
className={css( | ||
{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
fontWeight: 'semibold', | ||
color: 'green.300', | ||
textAlign: 'center', | ||
textStyle: '4xl', | ||
}, | ||
{ | ||
bg: 'yellow.200', | ||
color: 'red.500', | ||
}, | ||
overrides, | ||
)} | ||
> | ||
<span>🐼</span> | ||
<span>Hello from Panda</span> | ||
</div> | ||
<div className={button({ visual: 'funky', size: 'lg' })}>Button</div> | ||
<div className={atomicRecipe({ visual: 'solid', size: 'sm' })}>Atomic Button</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'virtual:panda.css' | ||
import { css } from '../styled-system/css' | ||
|
||
const styles = css.raw({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
fontWeight: 'semibold', | ||
color: 'green.300', | ||
textAlign: 'center', | ||
textStyle: '4xl', | ||
}) | ||
|
||
export const App = () => { | ||
return ( | ||
<div> | ||
<span>Hello from Panda</span> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import 'virtual:panda.css' | ||
import { css } from '../styled-system/css' | ||
|
||
export const App = () => { | ||
return ( | ||
<div | ||
className={css({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
fontWeight: 'semibold', | ||
color: 'green.300', | ||
textAlign: 'center', | ||
textStyle: '4xl', | ||
})} | ||
> | ||
<span>Hello from Panda</span> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'virtual:panda.css' | ||
import { cva } from '../styled-system/css' | ||
|
||
const atomicRecipe = cva({ | ||
base: { | ||
display: 'flex', | ||
}, | ||
variants: { | ||
visual: { | ||
solid: { bg: 'red.200', color: 'white' }, | ||
outline: { borderWidth: '1px', borderColor: 'red.200' }, | ||
}, | ||
size: { | ||
sm: { padding: '4', fontSize: '12px' }, | ||
lg: { padding: '8', fontSize: '24px' }, | ||
}, | ||
}, | ||
compoundVariants: [ | ||
{ | ||
visual: 'outline', | ||
size: 'lg', | ||
css: { | ||
borderWidth: '3px', | ||
}, | ||
}, | ||
], | ||
defaultVariants: { | ||
visual: 'solid', | ||
}, | ||
}) | ||
|
||
export const App = () => { | ||
return <div className={atomicRecipe({ visual: 'solid', size: 'sm' })}>Atomic Button</div> | ||
} |
Oops, something went wrong.