aboutsummaryrefslogtreecommitdiffstats
path: root/apps/mobile/components/ui/Input.tsx
blob: 2bd5e1900302cda9eb48e41da929625ce44a3ff3 (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
import type { TextInputProps } from "react-native";
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 TextInputProps {
  label?: string;
  labelClasses?: string;
  inputClasses?: string;
  loading?: boolean;
}

export const Input = forwardRef<TextInput, InputProps>(
  (
    { className, label, labelClasses, inputClasses, loading, ...props },
    ref,
  ) => {
    return (
      <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
              ref={ref}
              placeholderTextColor={styles?.color?.toString()}
              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>
    );
  },
);