1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-12-23 07:04:22 +00:00
festa/components/InputEventSlug.tsx

28 lines
706 B
TypeScript
Raw Normal View History

2022-05-27 00:46:30 +00:00
import * as React from "react"
export interface InputSlug extends React.HTMLProps<HTMLInputElement> {
onSlugChange?: (val: string) => void,
}
export function InputSlug(props: InputSlug) {
const [text, setText] = React.useState("")
const handleChange = React.useCallback((event: React.ChangeEvent<HTMLInputElement>) => {
props.onChange?.(event)
let slug = event.target.value.toLowerCase().replaceAll(/[^a-z0-9]/g, "-")
props.onSlugChange?.(slug)
setText(slug)
},
[]
)
return (
<input
type="text"
value={text}
onChange={handleChange}
{...props}
/>
)
}