aboutsummaryrefslogtreecommitdiffstats
path: root/apps/mobile/components/ui/Input.tsx
blob: dc84f54f0870144a1673c9c7e5e3a7ad2dbd9e20 (plain) (blame)
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
import { forwardRef } from "react";
import { ActivityIndicator, Text, TextInput, View } from "react-native";
import { cn } from "@/lib/utils";

import { TailwindResolver } from "../TailwindResolver";

export interface InputProps
  extends React.ComponentPropsWithoutRef<typeof TextInput> {
  label?: string;
  labelClasses?: string;
  inputClasses?: string;
}

const Input = forwardRef<
  React.ElementRef<typeof TextInput>,
  InputProps & { loading?: boolean }
>(
  (
    { className, label, labelClasses, inputClasses, loading, ...props },
    ref,
  ) => (
    <View className={cn("flex flex-col gap-1.5", className)}>
      {label && <Text className={cn("text-base", labelClasses)}>{label}</Text>}
      <TailwindResolver
        className="text-gray-400"
        comp={(styles) => (
          <TextInput
            placeholderTextColor={styles?.color?.toString()}
            ref={ref}
            className={cn(
              "bg-background text-foreground",
              inputClasses,
              "rounded-lg border border-input px-4 py-2.5",
            )}
            {...props}
          />
        )}
      />
      {loading && (
        <ActivityIndicator className="absolute bottom-0 right-0 p-2" />
      )}
    </View>
  ),
);
Input.displayName = "Input";

export { Input };