Skip to content

Commit 0019184

Browse files
committed
fix: gradient token issue
1 parent 1257dd2 commit 0019184

File tree

9 files changed

+127
-51
lines changed

9 files changed

+127
-51
lines changed

.changeset/fair-pets-occur.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@pandacss/preset-base': patch
3+
---
4+
5+
Fix issue where `bgGradient` did not respect the gradient token.

packages/generator/__tests__/generate-prop-types.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { describe, expect, test } from 'vitest'
33
import { generatePropTypes } from '../src/artifacts/types/prop-types'
44

55
describe('generate property types', () => {
6-
test('should ', () => {
6+
test('should work', () => {
77
expect(generatePropTypes(createContext())).toMatchInlineSnapshot(`
88
"import type { ConditionalValue } from './conditions';
99
import type { CssProperties } from './system-types';
@@ -93,9 +93,9 @@ describe('generate property types', () => {
9393
truncate: boolean;
9494
background: Tokens["colors"];
9595
backgroundColor: Tokens["colors"];
96-
backgroundGradient: 'to-t' | 'to-tr' | 'to-r' | 'to-br' | 'to-b' | 'to-bl' | 'to-l' | 'to-tl';
97-
backgroundLinear: 'to-t' | 'to-tr' | 'to-r' | 'to-br' | 'to-b' | 'to-bl' | 'to-l' | 'to-tl';
98-
textGradient: 'to-t' | 'to-tr' | 'to-r' | 'to-br' | 'to-b' | 'to-bl' | 'to-l' | 'to-tl';
96+
backgroundGradient: "to-t" | "to-tr" | "to-r" | "to-br" | "to-b" | "to-bl" | "to-l" | "to-tl";
97+
backgroundLinear: "to-t" | "to-tr" | "to-r" | "to-br" | "to-b" | "to-bl" | "to-l" | "to-tl";
98+
textGradient: "to-t" | "to-tr" | "to-r" | "to-br" | "to-b" | "to-bl" | "to-l" | "to-tl";
9999
gradientFrom: Tokens["colors"];
100100
gradientTo: Tokens["colors"];
101101
gradientVia: Tokens["colors"];

packages/preset-base/src/utilities/gradient.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ import { createColorMixTransform } from '../color-mix-transform'
33

44
const gradientVia = createColorMixTransform('--gradient-via')
55

6-
const union = (values: Iterable<string>) => {
7-
return Array.from(values)
8-
.map((value) => `'${value}'`)
9-
.join(' | ')
10-
}
11-
126
const linearGradientDirectionMap = new Map([
137
['to-t', 'to top'],
148
['to-tr', 'to top right'],
@@ -20,8 +14,11 @@ const linearGradientDirectionMap = new Map([
2014
['to-tl', 'to top left'],
2115
])
2216

23-
const linearGradientValues: PropertyValues = {
24-
type: union(linearGradientDirectionMap.keys()),
17+
const linearGradientValues: PropertyValues = (theme) => {
18+
return {
19+
...theme('gradients'),
20+
...Object.fromEntries(linearGradientDirectionMap.entries()),
21+
}
2522
}
2623

2724
const gradientStops =
@@ -36,7 +33,11 @@ export const backgroundGradients: UtilityConfig = {
3633
className: 'bg-grad',
3734
group: 'Background Gradient',
3835
values: linearGradientValues,
39-
transform(value) {
36+
transform(_value, { raw: value, token }) {
37+
const tokenValue = token(`gradients.${value}`)
38+
if (tokenValue) {
39+
return { backgroundImage: tokenValue }
40+
}
4041
return {
4142
'--gradient-stops': gradientStops,
4243
'--gradient-position': linearGradientDirectionMap.get(value) || value,
@@ -50,7 +51,11 @@ export const backgroundGradients: UtilityConfig = {
5051
className: 'bg-linear',
5152
group: 'Background Gradient',
5253
values: linearGradientValues,
53-
transform(value) {
54+
transform(_value, { raw: value, token }) {
55+
const tokenValue = token(`gradients.${value}`)
56+
if (tokenValue) {
57+
return { backgroundImage: tokenValue }
58+
}
5459
return {
5560
'--gradient-stops': gradientStops,
5661
'--gradient-position': linearGradientDirectionMap.get(value) || value,
@@ -63,7 +68,12 @@ export const backgroundGradients: UtilityConfig = {
6368
shorthand: 'bgRadial',
6469
className: 'bg-radial',
6570
group: 'Background Gradient',
66-
transform(value) {
71+
values: 'gradients',
72+
transform(_value, { raw: value, token }) {
73+
const tokenValue = token(`gradients.${value}`)
74+
if (tokenValue) {
75+
return { backgroundImage: tokenValue }
76+
}
6777
return {
6878
'--gradient-stops': gradientStops,
6979
'--gradient-position': value,
@@ -89,7 +99,15 @@ export const backgroundGradients: UtilityConfig = {
8999
className: 'txt-grad',
90100
group: 'Background Gradient',
91101
values: linearGradientValues,
92-
transform(value) {
102+
transform(_value, { raw: value, token }) {
103+
const tokenValue = token(`gradients.${value}`)
104+
if (tokenValue) {
105+
return {
106+
backgroundImage: tokenValue,
107+
WebkitBackgroundClip: 'text',
108+
color: 'transparent',
109+
}
110+
}
93111
return {
94112
'--gradient-stops': gradientStops,
95113
'--gradient-position': linearGradientDirectionMap.get(value) || value,

packages/studio/styled-system/types/prop-type.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ export interface UtilityValues {
8989
background: Tokens["colors"];
9090
backgroundColor: Tokens["colors"];
9191
backgroundImage: Tokens["assets"];
92-
backgroundGradient: 'to-t' | 'to-tr' | 'to-r' | 'to-br' | 'to-b' | 'to-bl' | 'to-l' | 'to-tl';
93-
backgroundLinear: 'to-t' | 'to-tr' | 'to-r' | 'to-br' | 'to-b' | 'to-bl' | 'to-l' | 'to-tl';
94-
textGradient: 'to-t' | 'to-tr' | 'to-r' | 'to-br' | 'to-b' | 'to-bl' | 'to-l' | 'to-tl';
92+
backgroundGradient: "to-t" | "to-tr" | "to-r" | "to-br" | "to-b" | "to-bl" | "to-l" | "to-tl";
93+
backgroundLinear: "to-t" | "to-tr" | "to-r" | "to-br" | "to-b" | "to-bl" | "to-l" | "to-tl";
94+
textGradient: "to-t" | "to-tr" | "to-r" | "to-br" | "to-b" | "to-bl" | "to-l" | "to-tl";
9595
gradientFrom: Tokens["colors"];
9696
gradientTo: Tokens["colors"];
9797
gradientVia: Tokens["colors"];

sandbox/solid-ts/panda.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ export default defineConfig({
77
theme: {
88
extend: {
99
tokens: {
10+
gradients: {
11+
simple: { value: 'linear-gradient(to right, red, blue)' },
12+
primary: {
13+
value: {
14+
type: 'linear',
15+
placement: 'to right',
16+
stops: ['pink', 'green'],
17+
},
18+
},
19+
},
1020
colors: {
1121
black: { value: 'black' },
1222
white: { value: 'white' },

sandbox/solid-ts/src/App.tsx

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,10 @@
1-
import { ParentProps } from 'solid-js'
2-
import { RecipeVariantProps, css, cva } from '../styled-system/css'
3-
import { splitCssProps } from '../styled-system/jsx'
4-
import { HTMLStyledProps, JsxStyleProps } from '../styled-system/types'
5-
6-
const btn = cva({ variants: { size: { sm: { textStyle: 'sm' }, md: { textStyle: 'md' } } } })
7-
8-
type ButtonProps = RecipeVariantProps<typeof btn>
9-
10-
const Button = (props: ParentProps<ButtonProps & JsxStyleProps>) => {
11-
const [variants, rest] = btn.splitVariantProps(props)
12-
const [cssProps, elementProps] = splitCssProps(rest)
13-
return (
14-
<button {...elementProps} class={css(btn.raw(variants), cssProps)}>
15-
aaa
16-
</button>
17-
)
18-
}
19-
20-
type DivProps = HTMLStyledProps<'div'>
21-
22-
export const Div = ({ css: cssProp = {}, children }: DivProps) => {
23-
const className = css(cssProp)
24-
// Argument of type 'SystemStyleObject | SystemStyleObject[]' is not assignable to parameter of type 'false | SystemStyleObject | null | undefined'.
25-
26-
return <div class={className}>{children}</div>
27-
}
1+
import { Gradient } from './scenarios/gradient'
282

293
export function App() {
304
return (
31-
<>
32-
<Div css={[{ color: 'red.300' }, { backgroundColor: 'blue.100' }]}>Div</Div>
33-
<Div css={{ color: 'blue.500' }}>Div</Div>
34-
<Button size="md">button</Button>
35-
</>
5+
<div>
6+
<Gradient />
7+
</div>
368
)
379
}
3810

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { css } from '../../styled-system/css'
2+
import { HTMLStyledProps } from '../../styled-system/types'
3+
4+
type DivProps = HTMLStyledProps<'div'>
5+
6+
const Div = ({ css: cssProp = {}, children }: DivProps) => {
7+
const className = css(cssProp)
8+
return <div class={className}>{children}</div>
9+
}
10+
11+
export const CssProp = () => {
12+
return (
13+
<div>
14+
<Div css={[{ color: 'red.300' }, { backgroundColor: 'blue.100' }]}>Div</Div>
15+
<Div css={{ color: 'blue.500' }}>Div</Div>
16+
</div>
17+
)
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { css } from '../../styled-system/css'
2+
3+
export const Gradient = () => {
4+
return (
5+
<div class={css({ display: 'flex', gap: '4', p: '4' })}>
6+
<div class={css({ boxSize: '100px', bgLinear: 'simple' })} />
7+
<div class={css({ boxSize: '100px', bgLinear: 'primary' })} />
8+
<div
9+
class={css({
10+
boxSize: '100px',
11+
bgGradient: 'to-r',
12+
gradientFrom: 'red.200',
13+
gradientTo: 'blue.200',
14+
})}
15+
/>
16+
<h1 class={css({ textGradient: 'simple' })}>Hello</h1>
17+
<h1 class={css({ textGradient: 'to-r', gradientFrom: 'red.200', gradientTo: 'blue.200' })}>Hello</h1>
18+
</div>
19+
)
20+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { ParentProps } from 'solid-js'
2+
import { RecipeVariantProps, css, cva } from '../../styled-system/css'
3+
import { splitCssProps } from '../../styled-system/jsx'
4+
import { JsxStyleProps } from '../../styled-system/types'
5+
6+
const btn = cva({
7+
variants: {
8+
size: {
9+
sm: { textStyle: 'sm' },
10+
md: { textStyle: 'md' },
11+
},
12+
},
13+
})
14+
15+
type VariantProps = RecipeVariantProps<typeof btn>
16+
17+
const Button = (props: ParentProps<VariantProps & JsxStyleProps>) => {
18+
const [variants, rest] = btn.splitVariantProps(props)
19+
const [cssProps, elementProps] = splitCssProps(rest)
20+
return (
21+
<button {...elementProps} class={css(btn.raw(variants), cssProps)}>
22+
aaa
23+
</button>
24+
)
25+
}
26+
27+
export const SplitCssProps = () => {
28+
return (
29+
<div>
30+
<Button size="md">button</Button>
31+
</div>
32+
)
33+
}

0 commit comments

Comments
 (0)