File tree Expand file tree Collapse file tree 4 files changed +98
-0
lines changed Expand file tree Collapse file tree 4 files changed +98
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {fontFamilyToken} from './fontFamilyToken.js'
12
12
import { shadowToken } from './shadowToken.js'
13
13
import { durationToken } from './durationToken.js'
14
14
import { cubicBezierToken } from './cubicBezierToken.js'
15
+ import { gradientToken } from './gradientToken.js'
15
16
16
17
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
17
18
// @ts -ignore: TODO: fix this
@@ -27,6 +28,7 @@ export const designToken = z.record(
27
28
borderToken ,
28
29
fontFamilyToken ,
29
30
fontWeightToken ,
31
+ gradientToken ,
30
32
typographyToken ,
31
33
viewportRangeToken ,
32
34
numberToken ,
Original file line number Diff line number Diff line change
1
+ import { gradientToken } from './gradientToken.js'
2
+
3
+ describe ( 'Schema: gradientToken' , ( ) => {
4
+ it ( 'parses valid value' , ( ) => {
5
+ const validGradientTokens = [
6
+ {
7
+ $value : [
8
+ {
9
+ color : '#000000' ,
10
+ position : 0 ,
11
+ } ,
12
+ {
13
+ color : '#ffffff' ,
14
+ position : 1 ,
15
+ } ,
16
+ ] ,
17
+ $type : 'gradient' ,
18
+ } ,
19
+ {
20
+ $value : [
21
+ {
22
+ color : '#000000' ,
23
+ position : 0 ,
24
+ } ,
25
+ {
26
+ color : '#555' ,
27
+ position : 0.3 ,
28
+ } ,
29
+ {
30
+ color : '#ffffff' ,
31
+ position : 0.5 ,
32
+ } ,
33
+ ] ,
34
+ $type : 'gradient' ,
35
+ } ,
36
+ ]
37
+
38
+ for ( const gradient of validGradientTokens ) {
39
+ expect ( gradientToken . safeParse ( gradient ) . success ) . toStrictEqual ( true )
40
+ }
41
+ } )
42
+
43
+ it ( 'fails on invalid values' , ( ) => {
44
+ const invalidGradientTokens = [
45
+ {
46
+ $value : [
47
+ {
48
+ color : '#000000' ,
49
+ position : 0 ,
50
+ } ,
51
+ ] ,
52
+ $type : 'gradient' ,
53
+ } ,
54
+ {
55
+ $value : [
56
+ {
57
+ color : '#000000' ,
58
+ position : 0 ,
59
+ } ,
60
+ {
61
+ color : '#ffffff' ,
62
+ position : 2 ,
63
+ } ,
64
+ ] ,
65
+ $type : 'gradient' ,
66
+ } ,
67
+ ]
68
+
69
+ for ( const gradient of invalidGradientTokens ) {
70
+ expect ( gradientToken . safeParse ( gradient ) . success ) . toStrictEqual ( false )
71
+ }
72
+ } )
73
+ } )
Original file line number Diff line number Diff line change
1
+ import { z } from 'zod'
2
+ import { baseToken } from './baseToken.js'
3
+ import { referenceValue } from './referenceValue.js'
4
+ import { tokenType } from './tokenType.js'
5
+ import { colorHexValue } from './colorHexValue.js'
6
+
7
+ export const gradientToken = baseToken
8
+ . extend ( {
9
+ $value : z . union ( [
10
+ z
11
+ . array (
12
+ z . object ( {
13
+ color : z . union ( [ colorHexValue , referenceValue ] ) ,
14
+ position : z . number ( ) . min ( 0 ) . max ( 1 ) ,
15
+ } ) ,
16
+ )
17
+ . min ( 2 ) ,
18
+ referenceValue ,
19
+ ] ) ,
20
+ $type : tokenType ( 'gradient' ) ,
21
+ } )
22
+ . strict ( )
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ const validTypes = [
11
11
'shadow' ,
12
12
'fontFamily' ,
13
13
'fontWeight' ,
14
+ 'gradient' ,
14
15
'number' ,
15
16
'string' ,
16
17
'custom-viewportRange' ,
You can’t perform that action at this time.
0 commit comments