Skip to content

Commit

Permalink
fix: composite border token reference
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Oct 26, 2024
1 parent 50fc8ef commit 144113f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/light-rings-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@pandacss/token-dictionary': patch
---

Fix issue where token reference in composite border token generates incorrect css.
42 changes: 42 additions & 0 deletions packages/token-dictionary/__tests__/transform-border.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ test('transform / border', () => {
colors: {
red: { value: '#ff0000' },
},
borderWidths: {
thick: { value: '2px' },
},
borders: {
sm: { value: '1px solid {colors.red}' },
md: { value: { width: 2, style: 'solid', color: '{colors.red}' } },
lg: { value: { width: '2px', style: 'solid', color: 'pink' } },
xl: { value: { width: '2', style: 'dashed', color: 'green' } },
brand: { value: { width: '{borderWidths.thick}', color: '#fff', style: 'solid' } },
},
},
semanticTokens: {
Expand Down Expand Up @@ -53,6 +57,25 @@ test('transform / border', () => {
"type": "color",
"value": "#ff0000",
},
Token {
"deprecated": undefined,
"description": undefined,
"extensions": {
"category": "borderWidths",
"condition": "base",
"prop": "thick",
"var": "--border-widths-thick",
"varRef": "var(--border-widths-thick)",
},
"name": "borderWidths.thick",
"originalValue": "2px",
"path": [
"borderWidths",
"thick",
],
"type": "borderWidth",
"value": "2px",
},
Token {
"deprecated": undefined,
"description": undefined,
Expand Down Expand Up @@ -129,6 +152,25 @@ test('transform / border', () => {
"type": "border",
"value": "2px dashed green",
},
Token {
"deprecated": undefined,
"description": undefined,
"extensions": {
"category": "borders",
"condition": "base",
"prop": "brand",
"var": "--borders-brand",
"varRef": "var(--borders-brand)",
},
"name": "borders.brand",
"originalValue": "{borderWidths.thick} solid #fff",
"path": [
"borders",
"brand",
],
"type": "border",
"value": "var(--border-widths-thick) solid #fff",
},
Token {
"deprecated": undefined,
"description": undefined,
Expand Down
4 changes: 2 additions & 2 deletions packages/token-dictionary/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import type { TokenTransformer } from './dictionary'
import { isCompositeBorder, isCompositeGradient, isCompositeShadow } from './is-composite'
import { svgToDataUri } from './mini-svg-uri'
import type { Token } from './token'
import { expandReferences, getReferences } from './utils'
import { expandReferences, getReferences, hasReference } from './utils'

function toUnit(v: string | number) {
return isCssUnit(v) ? v : `${v}px`
return isCssUnit(v) || hasReference(v.toString()) ? v : `${v}px`
}

/* -----------------------------------------------------------------------------
Expand Down

0 comments on commit 144113f

Please sign in to comment.