-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththemed-button.tsx
More file actions
81 lines (77 loc) · 2.41 KB
/
themed-button.tsx
File metadata and controls
81 lines (77 loc) · 2.41 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
73
74
75
76
77
78
79
80
81
import { GestureResponderEvent, PressableProps } from 'react-native';
import { Pressable } from './css-wrapped-components';
import '@/global.css';
import { ThemedText, ThemedTextType } from '@/components/themed-text';
import { ThemedColorNames } from '@/hooks/use-theme-colors';
export enum ThemedButtonBehavior {
scaleOnFocusHover = 'scaleOnFocusHover',
borderOnFocusHover = 'borderOnFocusHover',
none = 'none',
}
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:
'justify-center items-center 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:
'rounded-[2vh] p-[0.5vh] ' +
'transition-all duration-500 ' +
'focus:scale-(--scale-focus) ' +
'hover:scale-(--scale-hover) ' +
'active:scale-(--scale-active)',
/* No focus styling, used for tab bar buttons */
none: 'rounded-[2vh] p-[0.5vh]',
};
/**
* Themed button component.
*/
export function ThemedButton({
onPress,
children,
className,
textType,
textColor,
additionalTextClassName,
focusHoverBehavior,
...props
}: PressableProps & {
onPress?: ((event: GestureResponderEvent) => void) | null | undefined;
children: string;
className?: string;
textType?: ThemedTextType | undefined;
textColor?: ThemedColorNames | 'none';
additionalTextClassName?: string;
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}
color={textColor}
additionalClassName={additionalTextClassName}
>
{children}
</ThemedText>
</Pressable>
);
}