ldc-groupe/resources/ts/back/Components/Inputs/Slugifycator.tsx

57 lines
1.8 KiB
TypeScript
Raw Permalink Normal View History

2026-02-12 15:42:22 +01:00
// * Packages
import { GavelIcon } from "lucide-react";
// * Other
import SimpleString from "@/back/Components/Inputs/SimpleString";
import BtnOptionnalLinkWithTooltip from "@/back/Components/BtnOptionnalLinkWithTooltip";
2026-02-10 15:52:48 +01:00
import str from "@/hooks/use-string";
import useTrans from "@/hooks/use-translations";
2026-02-12 15:42:22 +01:00
interface SlugifycatorProps {
2026-02-10 15:52:48 +01:00
value: string;
targetValue: string;
wordCounter?: boolean;
2026-02-10 15:52:48 +01:00
disabled?: boolean;
2026-02-12 15:42:22 +01:00
// eslint-disable-next-line no-unused-vars
setData: (name: string, value: string) => void;
}
2026-02-12 15:42:22 +01:00
export default function Slugifycator(props: SlugifycatorProps) {
2026-02-10 15:52:48 +01:00
const {
value,
targetValue,
setData,
wordCounter = false,
disabled = false,
} = props;
return (
<div className="flex items-end gap-1">
<SimpleString
name="slug"
label={str(
useTrans("back.form_associate_to", {
params: {
attribute: useTrans("validation.custom.slug"),
},
choice: 1,
}),
2026-02-10 15:52:48 +01:00
)
.ucFirst()
.value()}
placeholder="ex: John Doe"
wordCounter={wordCounter}
value={value}
setData={setData}
disabled={disabled}
/>
<BtnOptionnalLinkWithTooltip
content={<GavelIcon className="w-4 h-4 m-auto" />}
2026-02-10 15:52:48 +01:00
tooltipContent={str(useTrans("back.slugify")).ucFirst().value()}
type="button"
variant="secondary"
onClick={() => setData("slug", str(targetValue).slug().value())}
disabled={disabled}
/>
</div>
2026-02-10 15:52:48 +01:00
);
}