1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/elements/emby-input/Input.tsx

58 lines
1.6 KiB
TypeScript
Raw Normal View History

2024-02-13 17:10:48 -05:00
import classNames from 'classnames';
import React, { type DetailedHTMLProps, type InputHTMLAttributes, useState, useCallback, forwardRef } from 'react';
2024-02-13 01:09:08 -05:00
import './emby-input.scss';
interface InputProps extends DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
id: string,
label?: string
}
const Input = forwardRef<HTMLInputElement, InputProps>(
({ id, label, className, onBlur, onFocus, ...props }, ref) => {
const [isFocused, setIsFocused] = useState(false);
const onBlurInternal = useCallback(
(e) => {
setIsFocused(false);
onBlur?.(e);
},
[onBlur]
);
const onFocusInternal = useCallback(
(e) => {
setIsFocused(true);
onFocus?.(e);
},
[onFocus]
);
return (
<>
<label
htmlFor={id}
className={classNames('inputLabel', {
2024-02-13 01:09:08 -05:00
inputLabelUnfocused: !isFocused,
inputLabelFocused: isFocused
})}
>
{label}
</label>
<input
ref={ref}
id={id}
className={classNames('emby-input', className)}
onBlur={onBlurInternal}
onFocus={onFocusInternal}
{...props}
/>
</>
);
}
);
Input.displayName = 'Input';
2024-02-13 01:09:08 -05:00
export default Input;