@@ -4,7 +4,7 @@ import type {DateTime} from '@gravity-ui/date-utils';
44
55import type { ValidationState } from '../../types' ;
66import { createPlaceholderValue } from '../../utils/dates' ;
7- import type { DateFieldSection , DateFieldSectionType } from '../types' ;
7+ import type { DateFieldSection , DateFieldSectionType , FormatInfo } from '../types' ;
88import {
99 EDITABLE_SEGMENTS ,
1010 formatSections ,
@@ -14,6 +14,7 @@ import {
1414
1515const PAGE_STEP : Partial < Record < DateFieldSectionType , number > > = {
1616 year : 5 ,
17+ quarter : 2 ,
1718 month : 2 ,
1819 weekday : 3 ,
1920 day : 7 ,
@@ -29,6 +30,7 @@ export type BaseDateFieldStateOptions<T = DateTime> = {
2930 timeZone : string ;
3031 validationState ?: ValidationState ;
3132 editableSections : DateFieldSection [ ] ;
33+ formatInfo : FormatInfo ;
3234 readOnly ?: boolean ;
3335 disabled ?: boolean ;
3436 selectedSectionIndexes : { startIndex : number ; endIndex : number } | null ;
@@ -66,9 +68,17 @@ export type DateFieldState<T = DateTime> = {
6668 disabled ?: boolean ;
6769 /** A list of segments for the current value. */
6870 sections : DateFieldSection [ ] ;
69- /** Whether the the format is containing date parts */
71+ /** Some info about available sections */
72+ formatInfo : FormatInfo ;
73+ /**
74+ * @deprecated use formatInfo.hasDate instead.
75+ * Whether the the format is containing date parts
76+ */
7077 hasDate : boolean ;
71- /** Whether the the format is containing time parts */
78+ /**
79+ * @deprecated use formatInfo.hasTime instead.
80+ * Whether the the format is containing time parts
81+ */
7282 hasTime : boolean ;
7383 /** Selected sections */
7484 selectedSectionIndexes : { startIndex : number ; endIndex : number } | null ;
@@ -122,6 +132,7 @@ export function useBaseDateFieldState<T = DateTime>(
122132 validationState,
123133 displayValue,
124134 editableSections,
135+ formatInfo,
125136 selectedSectionIndexes,
126137 selectedSections,
127138 isEmpty,
@@ -140,19 +151,6 @@ export function useBaseDateFieldState<T = DateTime>(
140151
141152 const enteredKeys = React . useRef ( '' ) ;
142153
143- const { hasDate, hasTime} = React . useMemo ( ( ) => {
144- let hasDateInner = false ;
145- let hasTimeInner = false ;
146- for ( const s of editableSections ) {
147- hasTimeInner ||= [ 'hour' , 'minute' , 'second' ] . includes ( s . type ) ;
148- hasDateInner ||= [ 'day' , 'month' , 'year' ] . includes ( s . type ) ;
149- }
150- return {
151- hasTime : hasTimeInner ,
152- hasDate : hasDateInner ,
153- } ;
154- } , [ editableSections ] ) ;
155-
156154 return {
157155 value,
158156 isEmpty,
@@ -163,8 +161,9 @@ export function useBaseDateFieldState<T = DateTime>(
163161 readOnly : props . readOnly ,
164162 disabled : props . disabled ,
165163 sections : editableSections ,
166- hasDate,
167- hasTime,
164+ formatInfo,
165+ hasDate : formatInfo . hasDate ,
166+ hasTime : formatInfo . hasTime ,
168167 selectedSectionIndexes,
169168 validationState,
170169 setSelectedSections ( position ) {
@@ -425,6 +424,7 @@ export function useBaseDateFieldState<T = DateTime>(
425424 case 'hour' :
426425 case 'minute' :
427426 case 'second' :
427+ case 'quarter' :
428428 case 'year' : {
429429 if ( ! Number . isInteger ( Number ( newValue ) ) ) {
430430 return ;
0 commit comments