All files / src/components/DateField DateField.tsx

100% Statements 7/7
100% Branches 2/2
100% Functions 3/3
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                          20x     139x   139x   139x   20x       14x   1x                
'use client';
 
import {TextInput} from '@gravity-ui/uikit';
 
import {block} from '../../utils/cn';
import {HiddenInput} from '../HiddenInput/HiddenInput';
 
import {useDateFieldProps} from './hooks/useDateFieldProps';
import type {DateFieldProps} from './hooks/useDateFieldProps';
import {useDateFieldState} from './hooks/useDateFieldState';
 
import './DateField.scss';
 
const b = block('date-field');
 
export function DateField({className, ...props}: DateFieldProps) {
    const state = useDateFieldState(props);
 
    const {groupProps, inputProps} = useDateFieldProps(state, props);
 
    return (
        <div {...groupProps} className={b(null, className)} style={props.style}>
            <TextInput {...inputProps} />
            <HiddenInput
                name={props.name}
                value={state.value}
                toStringValue={(value) => value?.toISOString() ?? ''}
                onReset={(value) => {
                    state.setValue(value);
                }}
                disabled={state.disabled}
                form={props.form}
            />
        </div>
    );
}