Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎁 Wrap form field messages to single row #207

Merged
merged 1 commit into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/app/waves/[waveId]/applications/create/steps/mainDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
FormItem,
FormLabel,
FormMessage,
FormMessages,
} from "@/components/ui/form";
import { ImageUpload } from "@/components/ui/imageUpload";
import { Input } from "@/components/ui/input";
Expand Down Expand Up @@ -129,11 +130,13 @@ export function MainDetails() {
placeholder="Enter the name of your project"
/>
</FormControl>
<FormCounter
current={field.value.length}
limit={FORM_FIELD_PARAMS.name.max}
/>
<FormMessage />
<FormMessages>
<FormMessage />
<FormCounter
current={field.value.length}
limit={FORM_FIELD_PARAMS.name.max}
/>
</FormMessages>
</FormItem>
)}
/>
Expand Down
27 changes: 18 additions & 9 deletions src/components/ui/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,21 @@ const FormDescription = forwardRef<
});
FormDescription.displayName = "FormDescription";

const FormMessages = forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>(
({ className, children, ...props }, ref) => {
return (
<div
ref={ref}
className={cn("flex gap-4 [&>p]:mt-0.5 [&>span]:mt-0.5", className)}
{...props}
>
{children}
</div>
);
},
);
FormMessages.displayName = "FormMessages";

const FormMessage = forwardRef<
HTMLParagraphElement,
HTMLAttributes<HTMLParagraphElement>
Expand All @@ -204,11 +219,7 @@ const FormMessage = forwardRef<
data-role="message"
ref={ref}
id={formMessageId}
className={cn(
"text-sm font-medium text-destructive",
"[input+&]:mt-0.5 [textarea+&]:mt-0.5",
className,
)}
className={cn("text-xs font-medium text-destructive", className)}
{...props}
>
{body}
Expand All @@ -226,10 +237,7 @@ interface FormCounterProps
const FormCounter = ({ current, limit, className }: FormCounterProps) => {
return (
<p
className={cn(
"group !mt-0 ml-auto mr-4 w-fit text-xs opacity-60",
className,
)}
className={cn("group ml-auto mr-4 w-fit text-xs opacity-60", className)}
data-overlimit={current > limit}
>
<span className="transition-colors group-data-[overlimit=true]:text-destructive">
Expand Down Expand Up @@ -267,6 +275,7 @@ export {
FormHint,
FormItem,
FormLabel,
FormMessages,
FormMessage,
useFormField,
};
Loading