-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathThemedButton.tsx
More file actions
72 lines (68 loc) · 2.02 KB
/
ThemedButton.tsx
File metadata and controls
72 lines (68 loc) · 2.02 KB
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
import { GestureResponderEvent, Pressable, PressableProps } from 'react-native';
import '@/global.css';
import { ThemedText, ThemedTextType } from './ThemedText';
export enum ThemedButtonBehavior {
scaleOnFocusHover = 'scaleOnFocusHover',
borderOnFocusHover = 'borderOnFocusHover',
}
const pressableClassNames: { [key in ThemedButtonBehavior]: string } = {
/*
Default behavior:
This style provides a rounded border on focus and hover, and scales the button when it is active, with a smooth 0.5 second animation.
*/
borderOnFocusHover:
'rounded-[2vh] p-[0.5vh] border-[0.25vh] border-[--color-background] ' +
'transition-all duration-500 ' +
'focus:border-[--color-text] ' +
'hover:border-[--color-text] ' +
'active:scale-[--scale-active]',
/*
Alternative behavior:
This style scales the button when it is focused, hovered, or active, with a smooth 0.5 second animation.
*/
scaleOnFocusHover:
'transition-all duration-500 ' +
'focus:scale-[--scale-focus] ' +
'hover:scale-[--scale-hover] ' +
'active:scale-[--scale-active]',
};
/**
* Themed button component.
*/
export function ThemedButton({
onPress,
children,
className,
textClassName,
textType,
focusHoverBehavior,
...props
}: PressableProps & {
onPress?: ((event: GestureResponderEvent) => void) | null | undefined;
children: string;
className?: string;
textClassName?: string;
textType?: ThemedTextType | undefined;
focusHoverBehavior?: ThemedButtonBehavior | undefined;
}) {
const behavior =
focusHoverBehavior ?? ThemedButtonBehavior.borderOnFocusHover;
return (
<Pressable
accessible
accessibilityLabel={children}
accessibilityRole="button"
onPress={onPress}
tvParallaxProperties={{ enabled: false }}
className={`${pressableClassNames[behavior]} ${className ?? ''}`}
{...props}
>
<ThemedText
type={textType ?? ThemedTextType.link}
className={textClassName}
>
{children}
</ThemedText>
</Pressable>
);
}