aboutsummaryrefslogtreecommitdiffstats
path: root/apps/mobile/components/ui/ActionButton.tsx
blob: 1f2e05cae09e12ffaad102652fa6047fb63e4f10 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import type { PressableProps } from "react-native";
import { ActivityIndicator, Pressable } from "react-native";

export function ActionButton({
  children,
  loading,
  disabled,
  ...props
}: PressableProps & {
  loading: boolean;
}) {
  if (disabled !== undefined) {
    disabled ||= loading;
  } else if (loading) {
    disabled = true;
  }
  return (
    <Pressable {...props} disabled={disabled}>
      {loading ? <ActivityIndicator /> : children}
    </Pressable>
  );
}