Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
bf86e07
feat(time-input): add utils for toggling select and formatparts
shaneeza Nov 26, 2025
612b474
wip
shaneeza Nov 30, 2025
a578ecb
refactor(time-input): enhance time formatting utilities and improve d…
shaneeza Dec 1, 2025
804cd88
refactor(time-input): improve time input handling and formatting logic
shaneeza Dec 1, 2025
1db42af
feat(time-input): add TimeFormField and TimeFormFieldInputContainer c…
shaneeza Dec 1, 2025
206e145
temp remove ts check
shaneeza Dec 1, 2025
bb3916d
refactor(time-input): clean up unused select unit logic and improve s…
shaneeza Dec 1, 2025
df69d22
feat(time-input): enhance TimeInput component with new constants for …
shaneeza Dec 2, 2025
2f5707f
refactor(time-input): update time segment rules and default values to…
shaneeza Dec 2, 2025
9715407
refactor(time-input): simplify getFormatParts function by removing lo…
shaneeza Dec 2, 2025
dad7b62
test(time-input): add unit tests for getFormatParts utility to verify…
shaneeza Dec 2, 2025
f559593
refactor(time-input): remove locale dependency from formatParts in Ti…
shaneeza Dec 2, 2025
3e6f6be
feat(time-input): add default time parts and enhance time input conte…
shaneeza Dec 3, 2025
1ef4c97
merge conflits
shaneeza Dec 3, 2025
87023fb
feat(time-input): enhance TimeInput stories with new argTypes for dar…
shaneeza Dec 3, 2025
580c90f
test(time-input): add comprehensive unit tests for TimeInputSegment c…
shaneeza Dec 3, 2025
2495aa1
test(time-input): add comprehensive unit tests for TimeInputSegment c…
shaneeza Dec 3, 2025
4cad730
refactor(time-input): update time segment handling to use explicit is…
shaneeza Dec 3, 2025
1afe57e
refactor(time-input): rename shouldShowSelect to is12hFormat for clar…
shaneeza Dec 12, 2025
cb84996
refactor(time-input): clean up unused state and comments in TimeInput…
shaneeza Dec 12, 2025
6e265a7
chore(pnpm-lock): add workspace links for @leafygreen-ui/input-box to…
shaneeza Dec 12, 2025
2547fdc
refactor(time-input): remove unused console logs and simplify time fo…
shaneeza Dec 12, 2025
10d4039
merge conflict
shaneeza Dec 12, 2025
e46a73c
refactor(time-input): clean up comments and improve test descriptions…
shaneeza Dec 12, 2025
94ed98f
refactor(time-input): remove outdated TODO comment in TimeInputContex…
shaneeza Dec 12, 2025
7e42f34
merge conflict
shaneeza Dec 12, 2025
2d2fbd5
Merge branch 'shaneeza/segment-logic-integration' of github.com:mongo…
shaneeza Dec 12, 2025
d9b99ec
Merge branch 'LG-5538/segments-parse-time' of github.com:mongodb/leaf…
shaneeza Dec 12, 2025
f07a1b8
merge conflict
shaneeza Dec 12, 2025
ed87ee7
test(time-input): add unit tests for TimeInputBox component
shaneeza Dec 14, 2025
e18c444
feat(time-input): integrate LGIDs into TimeInput components for impro…
shaneeza Dec 14, 2025
a361ba7
test(time-input): add test to verify seconds input is not rendered wh…
shaneeza Dec 14, 2025
aa4e7a2
feat(time-input): implement getNonLiteralTimeParts utility function w…
shaneeza Dec 16, 2025
d38ee94
refactor(time-input): rename defaultTimeParts to defaultDateTimeParts…
shaneeza Dec 16, 2025
d57c109
refactor(time-input): simplify import structure for getFormatPartsVal…
shaneeza Dec 16, 2025
aff3376
refactor(time-input): enhance getFormatter utility to conditionally i…
shaneeza Dec 16, 2025
9e343ff
refactor(time-input): consolidate imports for utility functions in Ti…
shaneeza Dec 16, 2025
346cb74
feat(time-input): add getFormattedDateTimeParts utility with tests fo…
shaneeza Dec 19, 2025
31dba0b
refactor(time-input): rename TimeParts to DateTimeParts and update re…
shaneeza Dec 19, 2025
388339e
refactor(time-input): update documentation in getFormattedDateTimePar…
shaneeza Dec 19, 2025
cea6a1d
merge conflict
shaneeza Dec 19, 2025
8abc708
refactor(time-input): remove unused state and error message from Time…
shaneeza Dec 19, 2025
4458f6f
refactor(time-input): update styles for seamless input display and cl…
shaneeza Dec 19, 2025
5455489
Merge branch 'shaneeza/segment-logic-integration' of github.com:mongo…
shaneeza Dec 19, 2025
237c4ee
chore(version): update version to 5.2.0
shaneeza Dec 19, 2025
617ebb7
Merge branch 'LG-5538/segments-parse-time' of github.com:mongodb/leaf…
shaneeza Dec 19, 2025
a736467
merge conflict
shaneeza Dec 19, 2025
c9751da
fix(time-input): update minExplicitValue for hour segment to ensure c…
shaneeza Dec 19, 2025
7ccb116
feat(time-input): enhance time input context and segment change event…
shaneeza Dec 20, 2025
2b4acae
refactor(time-input): remove unused TimeInputDisplayContext utility file
shaneeza Dec 20, 2025
574a23a
refactor(time-input): streamline imports and enhance context utility …
shaneeza Dec 20, 2025
96b9ebd
feat(time-input): add TimeInputDisplayContext utility functions and d…
shaneeza Dec 20, 2025
e032c8b
refactor(time-input): update imports to use TimeInputDisplayContext u…
shaneeza Dec 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ export const useDateSegments = (
(isNull(date) || isUndefined(date)) && isValidDate(prevDate);

if (hasDateValueChanged || hasDateBeenCleared) {
// This returns a new state object with the updated segments from the new date
const newSegments = getFormattedSegmentsFromDate(date);
// Pass the new state and a copy of the previous state to the callback
onUpdate?.(newSegments, { ...segments });
// This updates all segments in the internal state of the hook
// This internally invokes `dateSegmentsReducer` and passes `updateObject` as the second argument. `segments` is the first argument. This updates the internal state of the hook.
dispatch(newSegments);
}
}, [date, onUpdate, prevDate, segments]);
Expand All @@ -69,8 +73,11 @@ export const useDateSegments = (
// finally, commit the new state

const updateObject = { [segment]: value };
// This returns a new state object with the updated segment
const nextState = dateSegmentsReducer(segments, updateObject);
// Pass the new state and a copy of the previous state to the callback
onUpdate?.(nextState, { ...segments }, segment);
// This internally invokes `dateSegmentsReducer` and passes `updateObject` as the second argument. `segments` is the first argument. This updates the internal state of the hook.
dispatch(updateObject);
};

Expand Down
1 change: 1 addition & 0 deletions packages/time-input/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@leafygreen-ui/emotion": "workspace:^",
"@leafygreen-ui/form-field": "workspace:^",
"@leafygreen-ui/hooks": "workspace:^",
"@leafygreen-ui/input-box": "workspace:^",
"@leafygreen-ui/lib": "workspace:^",
"@leafygreen-ui/palette": "workspace:^",
"@leafygreen-ui/select": "workspace:^",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import { renderHook } from '@leafygreen-ui/testing-lib';
import { BaseFontSize } from '@leafygreen-ui/tokens';

import { Size } from '../../TimeInput/TimeInput.types';
import { getLgIds } from '../../utils';

import {
TimeInputDisplayProvider,
useTimeInputDisplayContext,
} from './TimeInputDisplayContext';
import { type TimeInputDisplayProviderProps } from './TimeInputDisplayContext.types';
import { defaultTimeInputDisplayContext } from './TimePickerDisplayContext.utils';
import { defaultTimeInputDisplayContext } from './TimeInputDisplayContext.utils';

const lgIds = getLgIds();
const overrideLgIds = getLgIds('lg-override-lgids');

const renderTimeInputDisplayProvider = (
props?: Partial<TimeInputDisplayProviderProps>,
Expand Down Expand Up @@ -60,6 +64,7 @@ describe('packages/time-input-display-context', () => {
defaultTimeInputDisplayContext.isDirty,
);
expect(typeof result.current.setIsDirty).toBe('function');
expect(result.current.lgIds).toEqual(lgIds);
});

test('overrides default values with provided props', () => {
Expand All @@ -73,6 +78,7 @@ describe('packages/time-input-display-context', () => {
disabled: true,
size: Size.Large,
errorMessage: 'Custom error message',
lgIds: overrideLgIds,
};

const { result } = renderTimeInputDisplayProvider(customProps);
Expand All @@ -86,6 +92,7 @@ describe('packages/time-input-display-context', () => {
expect(result.current.disabled).toBe(true);
expect(result.current.size).toBe(Size.Large);
expect(result.current.errorMessage).toBe('Custom error message');
expect(result.current.lgIds).toEqual(overrideLgIds);
});

describe('isDirty', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
TimeInputDisplayContextProps,
TimeInputDisplayProviderProps,
} from './TimeInputDisplayContext.types';
import { defaultTimeInputDisplayContext } from './TimePickerDisplayContext.utils';
import { defaultTimeInputDisplayContext } from './TimeInputDisplayContext.utils';

export const TimeInputDisplayContext =
createContext<TimeInputDisplayContextProps>(defaultTimeInputDisplayContext);
Expand All @@ -39,12 +39,14 @@ export const TimeInputDisplayProvider = ({
...defaults(rest, defaultTimeInputDisplayContext),
};

// TODO: min, max helpers

// Determines if the input should show a select for the day period (AM/PM)
const is12hFormat = hasDayPeriod(providerValue.locale);
/**
* Determines if the input should show a select for the day period (AM/PM)
*/
const is12HourFormat = hasDayPeriod(providerValue.locale);

// Only used to track the presentation format of the segments, not the value itself
/**
* Only used to track the presentation format of the segments, not the value itself
*/
const formatParts = getFormatParts({
showSeconds: providerValue.showSeconds,
});
Expand All @@ -58,7 +60,7 @@ export const TimeInputDisplayProvider = ({
ariaLabelledbyProp,
isDirty,
setIsDirty,
is12hFormat,
is12HourFormat,
formatParts,
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ import { AriaLabelPropsWithLabel } from '@leafygreen-ui/a11y';
import { DarkModeProps } from '@leafygreen-ui/lib';

import { DisplayTimeInputProps } from '../../TimeInput/TimeInput.types';
import { GetLgIdsReturnType } from '../../utils/getLgIds';

type AriaLabelKeys = keyof AriaLabelPropsWithLabel;
type AriaLabelKeysWithoutLabel = Exclude<AriaLabelKeys, 'label'>;
type DarkModeKeys = keyof DarkModeProps;

/**
* Dynamically generated LGIDs that will be used for the data-lgid and data-testid attributes in child components
*/
interface LgIds {
lgIds: GetLgIdsReturnType;
}

/**
* The values in context that can be used in the component
* Omits the aria-label and aria-labelledby props and replaces them with the ariaLabelProp and ariaLabelledbyProp
Expand All @@ -18,38 +26,41 @@ type DarkModeKeys = keyof DarkModeProps;
export type TimeInputDisplayContextProps = Omit<
Required<DisplayTimeInputProps>,
AriaLabelKeysWithoutLabel | 'state' | DarkModeKeys
> & {
/**
* The aria-label prop
*/
ariaLabelProp: string;
> &
LgIds & {
/**
* The aria-label prop
*/
ariaLabelProp: string;

/**
* The aria-labelledby prop
*/
ariaLabelledbyProp: string;
/**
* The aria-labelledby prop
*/
ariaLabelledbyProp: string;

/**
* Whether the input has been interacted with
*/
isDirty: boolean;
/**
* Whether the input has been interacted with
*/
isDirty: boolean;

/**
* Setter for whether the input has been interacted with
*/
setIsDirty: React.Dispatch<React.SetStateAction<boolean>>;
/**
* Setter for whether the input has been interacted with
*/
setIsDirty: React.Dispatch<React.SetStateAction<boolean>>;

/**
* Whether the AM/PM select should be shown
*/
is12hFormat: boolean;
/**
* Whether the time input is in 12-hour format. Helps determine if the AM/PM select should be shown.
*
* @default false
*/
is12HourFormat: boolean;

/**
* An array of {@link Intl.DateTimeFormatPart},
* used to determine the order of segments in the input
*/
formatParts?: Array<Intl.DateTimeFormatPart>;
};
/**
* An array of {@link Intl.DateTimeFormatPart},
* used to determine the order of segments in the input
*/
formatParts?: Array<Intl.DateTimeFormatPart>;
};

/**
* The props expected to pass into the provider
Expand All @@ -58,19 +69,20 @@ export type TimeInputDisplayContextProps = Omit<
export type TimeInputDisplayProviderProps = Omit<
DisplayTimeInputProps,
AriaLabelKeys | DarkModeKeys
> & {
/**
* The label prop
*/
label?: ReactNode;
> &
Partial<LgIds> & {
/**
* The label prop
*/
label?: ReactNode;

/**
* The aria-label prop
*/
'aria-label'?: string;
/**
* The aria-label prop
*/
'aria-label'?: string;

/**
* The aria-labelledby prop
*/
'aria-labelledby'?: string;
};
/**
* The aria-labelledby prop
*/
'aria-labelledby'?: string;
};
Original file line number Diff line number Diff line change
@@ -1 +1,62 @@
// TODO: min, max helpers
import {
MAX_DATE,
MIN_DATE,
SupportedLocales,
} from '@leafygreen-ui/date-utils';
import { BaseFontSize } from '@leafygreen-ui/tokens';

import { Size } from '../../TimeInput/TimeInput.types';
import { getLgIds } from '../../utils';

import {
TimeInputDisplayContextProps,
TimeInputDisplayProviderProps,
} from './TimeInputDisplayContext.types';

export type DisplayContextPropKeys = Exclude<
keyof TimeInputDisplayProviderProps,
'lgIds'
>;

/**
* Props names that that are added to the context and used to pick and omit props
*/
export const displayContextPropNames: Array<DisplayContextPropKeys> = [
'aria-label',
'aria-labelledby',
'label',
'description',
'locale',
'timeZone',
'min',
'max',
'baseFontSize',
'disabled',
'size',
'errorMessage',
'state',
'showSeconds',
];

/**
* The default display context values
*/
export const defaultTimeInputDisplayContext: TimeInputDisplayContextProps = {
ariaLabelProp: '',
ariaLabelledbyProp: '',
label: '',
description: '',
locale: SupportedLocales.ISO_8601,
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
min: MIN_DATE,
max: MAX_DATE,
baseFontSize: BaseFontSize.Body1,
disabled: false,
size: Size.Default,
errorMessage: '',
isDirty: false,
setIsDirty: () => {},
is12HourFormat: false,
showSeconds: true,
lgIds: getLgIds(),
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ export {
type TimeInputDisplayContextProps,
type TimeInputDisplayProviderProps,
} from './TimeInputDisplayContext.types';
export { defaultTimeInputDisplayContext } from './TimePickerDisplayContext.utils';
export {
defaultTimeInputDisplayContext,
DisplayContextPropKeys,
displayContextPropNames,
} from './TimeInputDisplayContext.utils';
2 changes: 2 additions & 0 deletions packages/time-input/src/Context/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './TimeInputContext';
export * from './TimeInputDisplayContext';
Loading
Loading