Skip to content

Commit

Permalink
feat: ✨ add money input
Browse files Browse the repository at this point in the history
  • Loading branch information
neopromic committed Nov 9, 2024
1 parent 52d8f05 commit ede8a12
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/_components/money-input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { NumericFormat, NumericFormatProps } from "react-number-format";

import { Input, InputProps } from "@/app/_components/ui/input";
import { forwardRef } from "react";

export const MoneyInput = forwardRef(
(
props: NumericFormatProps<InputProps>,
ref: React.ForwardedRef<HTMLInputElement>,
) => {
return (
<NumericFormat
{...props}
thousandSeparator="."
decimalSeparator=","
prefix="R$ "
allowNegative={false}
customInput={Input}
getInputRef={ref}
/>
);
},
);

MoneyInput.displayName = "MoneyInput";
25 changes: 25 additions & 0 deletions app/_components/ui/input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import * as React from "react";

import { cn } from "@/app/_lib/utils";

export interface InputProps
extends React.InputHTMLAttributes<HTMLInputElement> {}

const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ className, type, ...props }, ref) => {
return (
<input
type={type}
className={cn(
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
className,
)}
ref={ref}
{...props}
/>
);
},
);
Input.displayName = "Input";

export { Input };
26 changes: 26 additions & 0 deletions app/_components/ui/label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use client";

import * as React from "react";
import * as LabelPrimitive from "@radix-ui/react-label";
import { cva, type VariantProps } from "class-variance-authority";

import { cn } from "@/app/_lib/utils";

const labelVariants = cva(
"text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
);

const Label = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> &
VariantProps<typeof labelVariants>
>(({ className, ...props }, ref) => (
<LabelPrimitive.Root
ref={ref}
className={cn(labelVariants(), className)}
{...props}
/>
));
Label.displayName = LabelPrimitive.Root.displayName;

export { Label };

0 comments on commit ede8a12

Please sign in to comment.