-
Notifications
You must be signed in to change notification settings - Fork 2
/
patterns.ts
89 lines (81 loc) · 2.11 KB
/
patterns.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import type { PatternConfig } from '@pandacss/types'
export function definePattern<T extends PatternConfig>(
config: T,
): PatternConfig {
return config
}
/**
* A container that allows for scrolling
* @param direction - 'horizontal' or 'vertical'
* @param hideScrollbar - boolean to hide the scrollbar
* @example
* ```tsx
* <div css={scrollable({ direction: 'vertical', hideScrollbar: true })}>
* <p>Scroll me</p>
* </div>
* ```
*/
const scrollable: PatternConfig = definePattern({
description: 'A container that allows for scrolling',
properties: {
// The direction of the scroll
direction: { type: 'enum', value: ['horizontal', 'vertical'] },
// Whether to hide the scrollbar
hideScrollbar: { type: 'boolean' },
},
// disallow the `overflow` property (in TypeScript)
blocklist: ['overflow'],
transform(props) {
const { direction, hideScrollbar, ...rest } = props
return {
overflow: 'auto',
height: direction === 'horizontal' ? '100%' : 'auto',
width: direction === 'vertical' ? '100%' : 'auto',
scrollbarWidth: hideScrollbar ? 'none' : 'auto',
WebkitOverflowScrolling: 'touch',
'&::-webkit-scrollbar': {
display: hideScrollbar ? 'none' : 'auto',
},
...rest,
}
},
})
/**
* A container that fades in the content
* @param delay - The delay of the animation
* @example
* ```tsx
* <div css={animateIn({ delay: '200ms' })}>
* <p>Fade in</p>
* </div>
* ```
*/
const animateIn: PatternConfig = definePattern({
description: 'A container that fades in the content',
properties: {
// The delay of the animation
delay: { type: 'string' },
},
// disallow the `overflow` property (in TypeScript)
blocklist: ['overflow'],
transform(props) {
const { delay, ...rest } = props
return {
animationName: 'fadeIn',
animationDuration: '2s',
animationFillMode: 'forwards',
animationDelay: delay ?? '200ms',
opacity: '0',
...rest,
_motionReduce: {
animationName: 'none',
},
}
},
})
export const patterns = {
extend: {
animateIn,
scrollable,
},
}