Skip to content

Commit

Permalink
fix scope for focus outline (#1027)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasoppermann authored Aug 16, 2024
1 parent 401fef1 commit 8301cb9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/schemas/colorToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const colorToken = baseToken
'light tritanopia',
'dark tritanopia',
]).optional(),
scopes: scopes(['all', 'bgColor', 'fgColor', 'borderColor']).optional(),
scopes: scopes(['all', 'bgColor', 'fgColor', 'borderColor', 'effectColor']).optional(),
}),
})
.optional(),
Expand Down
1 change: 1 addition & 0 deletions src/schemas/dimensionToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const dimensionToken = baseToken
'gap',
'radius',
'borderColor',
'effectFloat',
'fontSize',
'letterSpacing',
'lineHeight',
Expand Down
31 changes: 10 additions & 21 deletions src/schemas/scopes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,17 @@ import {z} from 'zod'
import {joinFriendly} from '../utilities/joinFriendly'
import {schemaErrorMessage} from '../utilities/schemaErrorMessage'

export type ValidScope =
| 'all'
| 'bgColor'
| 'fgColor'
| 'borderColor'
| 'size'
| 'gap'
| 'radius'
| 'effectColor'
| 'opacity'
| 'fontFamily'
| 'fontStyle'
| 'fontWeight'
| 'fontSize'
| 'lineHeight'
| 'letterSpacing'
| 'paragraphSpacing'
| 'paragraphIndent'
const validScopes: ValidScope[] = [
const validScopes = [
'all',
'bgColor',
'fgColor',
'borderColor',
'borderWidth',
'size',
'gap',
'radius',
'effectColor',
'effectFloat',
'opacity',
'fontFamily',
'fontStyle',
Expand All @@ -38,14 +22,19 @@ const validScopes: ValidScope[] = [
'letterSpacing',
'paragraphSpacing',
'paragraphIndent',
]
] as const

export type ValidScope = (typeof validScopes)[number]

export const scopes = (scopeSubset?: ValidScope[]) => {
const scopeArray = scopeSubset ?? validScopes
return z.array(z.string()).refine(
value => value.every(item => scopeArray.includes(item as ValidScope)),
value => ({
message: schemaErrorMessage(`Invalid scope: "${value}"`, `Valid scopes are: ${joinFriendly(scopeArray)}`),
message: schemaErrorMessage(
`Invalid scope: "${value}"`,
`Valid scopes are: ${joinFriendly(scopeArray as string[])}`,
),
}),
)
}
2 changes: 1 addition & 1 deletion src/tokens/functional/color/light/patterns-light.json5
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@
collection: 'mode',
mode: 'light',
group: 'component (internal)',
scopes: ['borderColor'],
scopes: ['borderColor', 'effectColor'],
},
},
},
Expand Down
6 changes: 6 additions & 0 deletions src/transformers/figmaAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ type FigmaVariableScope =
| 'SHAPE_FILL'
| 'TEXT_FILL'
| 'STROKE_COLOR'
| 'STROKE_FLOAT'
| 'EFFECT_COLOR'
| 'EFFECT_FLOAT'
| 'OPACITY'
| 'FONT_FAMILY'
| 'FONT_STYLE'
Expand All @@ -28,7 +31,10 @@ const figmaScopes: Record<string, FigmaVariableScope[]> = {
gap: ['GAP'],
bgColor: ['FRAME_FILL', 'SHAPE_FILL'],
fgColor: ['TEXT_FILL', 'SHAPE_FILL'],
effectColor: ['EFFECT_COLOR'],
effectFloat: ['EFFECT_FLOAT'],
borderColor: ['STROKE_COLOR'],
borderWidth: ['STROKE_FLOAT'],
opacity: ['OPACITY'],
fontFamily: ['FONT_FAMILY'],
fontStyle: ['FONT_STYLE'],
Expand Down

0 comments on commit 8301cb9

Please sign in to comment.