import { t } from "@lingui/core/macro"; import { Trans } from "@lingui/react/macro"; import { TagIcon } from "@phosphor-icons/react"; import { useCallback, useMemo } from "react"; import type z from "zod"; import type { urlSchema } from "@/schema/resume/data"; import { cn } from "@/utils/style"; import { Input } from "../ui/input"; import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText } from "../ui/input-group"; import { Label } from "../ui/label"; import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover"; const PREFIX = "https://"; function stripPrefix(url: string) { return url.startsWith(PREFIX) ? url.slice(PREFIX.length) : url; } function ensurePrefix(url: string) { if (url === "") return ""; return url.startsWith(PREFIX) ? url : PREFIX + url; } type Props = Omit, "value" | "onChange"> & { value: z.infer; onChange: (value: z.infer) => void; hideLabelButton?: boolean; }; export function URLInput({ value, onChange, hideLabelButton, ...props }: Props) { const handleUrlChange = useCallback( (e: React.ChangeEvent) => { onChange({ url: ensurePrefix(e.target.value), label: value.label, }); }, [onChange, value.label], ); const handleLabelChange = useCallback( (e: React.ChangeEvent) => { onChange({ url: value.url, label: e.target.value }); }, [onChange, value.url], ); const urlValue = useMemo(() => stripPrefix(value.url), [value.url]); return ( {PREFIX} {!hideLabelButton && ( } />
e.stopPropagation()}>
)}
); }