Skip to content
Open
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
150 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
0a149d4
wip - getting all segment parts
shaneeza Dec 5, 2025
c741b7d
feat(time-input): add date-fns-tz dependency and enhance TimeInput co…
shaneeza Dec 5, 2025
4e067b4
wip
shaneeza Dec 6, 2025
d821382
refactor(time-input): clean up logging and improve date and timezone …
shaneeza Dec 8, 2025
d719191
refactor(time-input): remove console logs and update time formatting …
shaneeza Dec 8, 2025
13b0636
refactor(time-input): enhance TimeInputInputs with improved segment v…
shaneeza Dec 8, 2025
395029c
refactor(time-input): streamline date handling and validation logic i…
shaneeza Dec 9, 2025
179b69d
refactor(time-input): enhance logging in useTimeSegments and update t…
shaneeza Dec 9, 2025
c91bf4d
refactor(time-input): simplify TimeInputInputs logic by consolidating…
shaneeza Dec 9, 2025
84c8c65
test(time-input): enhance isEverySegmentValueExplicit tests for 12 an…
shaneeza Dec 10, 2025
a4e8ff3
refactor(time-input): improve logging and streamline utility imports …
shaneeza Dec 10, 2025
8b93255
refactor(time-input): improve useTimeSegments logic and logging for d…
shaneeza Dec 10, 2025
f1f6830
refactor(time-input): streamline useSelectUnit and useTimeSegments ho…
shaneeza Dec 10, 2025
7bb59dc
refactor(time-input): integrate useTimeSegmentsAndSelect hook into Ti…
shaneeza Dec 10, 2025
e63805e
WIP TESTS
shaneeza Dec 10, 2025
874cc31
refactor(time-input): integrate useTimeSegmentsAndSelectUnit hook int…
shaneeza Dec 11, 2025
328d4bf
refactor(time-input): enhance useTimeSegmentsAndSelectUnit hook with …
shaneeza Dec 12, 2025
86d7de7
refactor(time-input): remove unused hooks and streamline TimeInputInp…
shaneeza Dec 12, 2025
b249677
test(time-input): add initial tests for TimeInputBox, verifying input…
shaneeza Dec 12, 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
c12420f
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
75cd7e6
Merge branch 'LG-5532/segments-display-values' of github.com:mongodb/…
shaneeza Dec 12, 2025
4d41446
refactor(time-input): update TimeInput story with new default date an…
shaneeza Dec 12, 2025
7887c6a
test(time-input): enhance TimeInputInputs tests for rendering and re-…
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
eb630cd
merge conflict
shaneeza Dec 14, 2025
e1d6f3e
refactor(time-input): remove unused is12HourFormat prop and enhance t…
shaneeza Dec 14, 2025
3e506bd
test(time-input): expand TimeInputInputs tests for various time zones…
shaneeza Dec 14, 2025
d971c5a
refactor(date-picker, time-input): remove commented debug logs and up…
shaneeza Dec 14, 2025
8071e07
refactor(time-input): streamline UTC date conversion by removing unne…
shaneeza Dec 14, 2025
9b9abb2
refactor(time-input): remove date-fns-tz dependency and utilize newUT…
shaneeza Dec 14, 2025
a361ba7
test(time-input): add test to verify seconds input is not rendered wh…
shaneeza Dec 14, 2025
2b0dfd4
Merge branch 'LG-5532/segments-display-values' of github.com:mongodb/…
shaneeza Dec 14, 2025
332709d
refactor(time-input): rename handleSegmentUpdate to handleSegmentAndS…
shaneeza Dec 14, 2025
cf91ea4
refactor(time-input): simplify select unit handling by removing redun…
shaneeza Dec 14, 2025
ac4b5d2
refactor(time-input): consolidate hook exports for improved organization
shaneeza Dec 14, 2025
87fa353
feat(date-utils): add newUTCFromTimeZone function to create UTC dates…
shaneeza Dec 14, 2025
4909e9e
Merge branch 'LG-5532/segments-state-utils' of github.com:mongodb/lea…
shaneeza Dec 14, 2025
bf0c1a9
fix(time-input): update minExplicitValue for hour segment to ensure c…
shaneeza Dec 15, 2025
fdcbd44
fix(time-input): correct typos in test descriptions for segment valid…
shaneeza Dec 15, 2025
55c8007
Merge branch 'LG-5532/segments-state-utils' of github.com:mongodb/lea…
shaneeza Dec 15, 2025
569f86c
fix(time-input): correct import statement formatting in TimeInputInpu…
shaneeza Dec 15, 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
cc26d00
merge conflict
shaneeza Dec 19, 2025
7b81e33
Merge branch 'LG-5532/segments-state-utils' of github.com:mongodb/lea…
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
438f8ea
Merge branch 'LG-5532/segments-display-values' of github.com:mongodb/…
shaneeza Dec 19, 2025
5f46187
Merge branch 'LG-5532/segments-state-utils' of github.com:mongodb/lea…
shaneeza Dec 19, 2025
819fbdf
feat(time-input): add utility functions for padded time segments and …
shaneeza Dec 19, 2025
cfcca09
feat(time-input): introduce DayPeriod type and update related utiliti…
shaneeza Dec 19, 2025
36e9fd9
feat(date-utils): add isSameUTCDayAndTime utility and corresponding t…
shaneeza Dec 19, 2025
97e751b
feat(date-utils): export isSameUTCDayAndTime utility and remove it fr…
shaneeza Dec 19, 2025
01c6487
fix(time-input): correct import structure for getPaddedTimeSegmentsFr…
shaneeza Dec 19, 2025
3730806
refactor(time-input): update tests for shouldSetValue utility to impr…
shaneeza Dec 19, 2025
f3d3102
refactor(date-utils): streamline imports in isSameUTCDayAndTime utili…
shaneeza Dec 20, 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
26fec0b
merge conflict
shaneeza Dec 20, 2025
20d0b0e
refactor(time-input): update component props to use ComponentPropsWit…
shaneeza Dec 22, 2025
ba1dcd9
refactor(time-input): reorganize imports and move utility functions t…
shaneeza Dec 22, 2025
a04fca7
refactor(time-input): update component props to use ComponentPropsWit…
shaneeza Dec 22, 2025
379f871
refactor(time-input): move time segment rules and default min/max fun…
shaneeza Dec 22, 2025
ee79838
merge conflict
shaneeza Dec 22, 2025
80a5367
refactor(time-input): simplify aria attributes in TimeFormFieldInputC…
shaneeza Dec 22, 2025
4a62b19
refactor(time-input): simplify aria attributes in TimeFormFieldInputC…
shaneeza Dec 22, 2025
7ba3bab
Merge branch 'LG-5532/segments-display-values' of github.com:mongodb/…
shaneeza Dec 22, 2025
b7d5c15
refactor(date-utils): remove deprecated newUTCFromTimeZone function a…
shaneeza Dec 22, 2025
4c14124
fix(date-utils): update test descriptions for clarity on UTC offsets …
shaneeza Dec 22, 2025
522a987
refactor(date-utils): simplify test comments for better readability a…
shaneeza Dec 22, 2025
7d3d139
refactor(time-input): replace deprecated newUTCFromTimeZone with newT…
shaneeza Dec 22, 2025
e88a937
refactor(time-input): remove unused TimeInputSegmentChangeEvent type …
shaneeza Dec 22, 2025
a714dc8
refactor(time-input): rename defaultPlaceholder to defaultPlaceholder…
shaneeza Dec 22, 2025
9e0dd01
Merge branch 'LG-5532/segments-display-values' of github.com:mongodb/…
shaneeza Dec 22, 2025
2993da5
refactor(time-input): remove unused import of keyMap in shared types …
shaneeza Dec 22, 2025
b2fc9b5
merge conflict
shaneeza Dec 22, 2025
bf03d5f
merge conflict
shaneeza Dec 23, 2025
644288d
testing
shaneeza Dec 23, 2025
d818cba
revert
shaneeza Dec 23, 2025
f4d1f3c
Merge branch 'LG-5532/segments-state-utils' of github.com:mongodb/lea…
shaneeza Dec 23, 2025
969f5a1
refactor(time-input): simplify TimeInputInputs component by consolida…
shaneeza Dec 23, 2025
31ae325
refactor(time-input): enhance useTimeSegmentsAndSelectUnit logic by s…
shaneeza Dec 23, 2025
7993758
refactor(time-input): improve comments in TimeInputInputs and useTime…
shaneeza Dec 23, 2025
a19f3a4
test(time-input): add tests for locale handling and select unit updat…
shaneeza Dec 23, 2025
5a528ba
test(time-input): add locale conversion tests for 12-hour and 24-hour…
shaneeza Dec 23, 2025
be44130
refactor(time-input): simplify isEverySegmentFilled utility and clean…
shaneeza Dec 23, 2025
451b0ea
refactor(time-input): enhance validation utilities by simplifying seg…
shaneeza Dec 23, 2025
2a4ffd3
refactor(time-input): rename isExplicitSegmentValue to createExplicit…
shaneeza Dec 23, 2025
10fb946
refactor(time-input): improve test descriptions in isEverySegmentValu…
shaneeza Dec 23, 2025
b0726e0
refactor(time-input): simplify doesSomeSegmentExist utility and enhan…
shaneeza Dec 23, 2025
06ee1ef
refactor(time-input): update DateTimeParts type to include dayPeriod …
shaneeza Dec 29, 2025
b11b0ec
refactor(time-input): introduce DateParts type for better date segmen…
shaneeza Dec 29, 2025
055f87c
refactor(date-utils): streamline test cases in isSameUTCDayAndTime.sp…
shaneeza Dec 29, 2025
dd11802
refactor(date-utils): enhance test clarity in isSameUTCDay.spec by im…
shaneeza Dec 29, 2025
85e285e
refactor(date-utils): improve test consistency in isSameUTCMonth.spec…
shaneeza Dec 29, 2025
3399988
refactor(time-input): enhance test descriptions and structure for cla…
shaneeza Dec 29, 2025
18e30a2
refactor(date-utils): improve test descriptions in isSameUTCDay.spec …
shaneeza Dec 29, 2025
5682f66
refactor(date-utils): rename isSameUTCDayAndTime to isSameUTCDateTime
shaneeza Dec 29, 2025
17210c4
refactor(date-utils): update exports and tests for isSameUTCDateTime
shaneeza Dec 29, 2025
4ab1e7d
refactor(time-input): consolidate unit option types and improve usage…
shaneeza Dec 30, 2025
f8b2bb2
merge conflict
shaneeza Dec 30, 2025
f7dba60
refactor(time-input): enhance test structure and descriptions in useT…
shaneeza Dec 30, 2025
c3e4829
refactor(time-input): simplify test cases in getInitialState.spec and…
shaneeza Dec 30, 2025
a667409
merge conflict;
shaneeza Dec 31, 2025
be93d6e
refactor(time-input): update lodash import for isEqual to improve cod…
shaneeza Dec 31, 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/date-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export { maxDate } from './maxDate';
export { minDate } from './minDate';
export { newTZDate } from './newTZDate';
export { newUTC } from './newUTC';
export { newUTCFromTimeZone } from './newUTCFromTimeZone';
export { setToUTCMidnight } from './setToUTCMidnight';
export { setUTCDate } from './setUTCDate';
export { setUTCMonth } from './setUTCMonth';
Expand Down
1 change: 1 addition & 0 deletions packages/date-utils/src/newUTCFromTimeZone/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { newUTCFromTimeZone } from './newUTCFromTimeZone';
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { newUTCFromTimeZone } from './newUTCFromTimeZone';

describe('packages/date-utils/newUTCFromTimeZone', () => {
describe('UTC', () => {
test('creates a new UTC date from a given time zone', () => {
const date = newUTCFromTimeZone({
year: '2026',
month: '02',
day: '20',
hour: '23',
minute: '00',
second: '00',
timeZone: 'UTC',
});

// February 20, 2026 11:00:00 PM/23:00:00 in UTC is February 20, 2026 23:00:00 UTC
expect(date).toEqual(new Date('2026-02-20T23:00:00Z'));
});
});

describe('America/New_York', () => {
test('creates a new UTC date from a given time zone', () => {
const date = newUTCFromTimeZone({
year: '2026',
month: '02',
day: '20',
hour: '23',
minute: '00',
second: '00',
timeZone: 'America/New_York',
});

// February 20, 2026 11:00:00 PM/23:00:00 in America/New_York is February 21, 2026 04:00:00 UTC (UTC-5 hours)
expect(date).toEqual(new Date('2026-02-21T04:00:00Z'));
});
});

describe('Pacific/Kiritimati', () => {
test('creates a new UTC date from a given time zone', () => {
const date = newUTCFromTimeZone({
year: '2026',
month: '02',
day: '20',
hour: '23',
minute: '00',
second: '00',
timeZone: 'Pacific/Kiritimati',
});

// February 20, 2026 11:00:00 PM/23:00:00 in Pacific/Kiritimati is February 20, 2026 09:00:00 UTC (UTC+14 hours)
expect(date).toEqual(new Date('2026-02-20T09:00:00Z'));
});
});
});
50 changes: 50 additions & 0 deletions packages/date-utils/src/newUTCFromTimeZone/newUTCFromTimeZone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { zonedTimeToUtc } from 'date-fns-tz';

/**
* Creates a new UTC date from a given time zone.
* This takes the local date created above and converts it to UTC using the `zonedTimeToUtc` helper function.
*
* @param year - The year
* @param month - The month (1-12)
* @param day - The day
* @param hour - The hour in 24 hour format
* @param minute - The minute
* @param second - The second
* @param timeZone - The time zone
* @returns The new UTC date
*
* @example
* ```js
* // February 20, 2026 11:00:00 PM/23:00:00 in America/New_York is February 21, 2026 04:00:00 UTC
* newUTCFromTimeZone({ year: '2026', month: '02', day: '20', hour: '11', minute: '00', second: '00', timeZone: 'America/New_York' });
* // returns new Date('2026-02-21T04:00:00Z')
* ```
*/
export const newUTCFromTimeZone = ({
year,
month,
day,
hour,
minute,
second,
timeZone,
}: {
year: string;
month: string;
day: string;
hour: string;
minute: string;
second: string;
timeZone: string;
}) => {
const newDate = new Date(
Number(year),
Number(month) - 1,
Number(day),
Number(hour),
Number(minute),
Number(second),
);

return zonedTimeToUtc(newDate, timeZone);
};
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 @@ -5,6 +5,10 @@ import React, {
useState,
} from 'react';
import defaults from 'lodash/defaults';
import defaultTo from 'lodash/defaultTo';

import { hasDayPeriod } from '../../utils';
import { getFormatParts } from '../../utils/getFormatParts/getFormatParts';

import {
TimeInputDisplayContextProps,
Expand Down Expand Up @@ -37,7 +41,27 @@ 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 is12HourFormat = !!hasDayPeriod(providerValue.locale);

/**
* Only used to track the presentation format of the segments, not the value itself
*/
const formatParts = getFormatParts({
showSeconds: providerValue.showSeconds,
});

/**
* Gets the time zone from the provider value or the browser's default
*/
const timeZone = defaultTo(
providerValue.timeZone,
Intl.DateTimeFormat().resolvedOptions().timeZone,
);

// TODO: min, max helpers will be in a future PR

return (
<TimeInputDisplayContext.Provider
Expand All @@ -48,6 +72,9 @@ export const TimeInputDisplayProvider = ({
ariaLabelledbyProp,
isDirty,
setIsDirty,
is12HourFormat,
formatParts,
timeZone,
}}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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'>;
Expand Down Expand Up @@ -38,6 +39,24 @@ export type TimeInputDisplayContextProps = Omit<
* Setter for whether the input has been interacted with
*/
setIsDirty: React.Dispatch<React.SetStateAction<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>;

/**
* LGIDs for the code snippet.
*/
lgIds: GetLgIdsReturnType;
};

/**
Expand All @@ -62,4 +81,9 @@ export type TimeInputDisplayProviderProps = Omit<
* The aria-labelledby prop
*/
'aria-labelledby'?: string;

/**
* LGIDs for the code snippet.
*/
lgIds?: GetLgIdsReturnType;
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import {
import { BaseFontSize } from '@leafygreen-ui/tokens';

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

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

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

/**
* Props names that that are added to the context and used to pick and omit props
Expand All @@ -31,6 +35,7 @@ export const displayContextPropNames: Array<DisplayContextPropKeys> = [
'size',
'errorMessage',
'state',
'showSeconds',
];

/**
Expand All @@ -51,4 +56,7 @@ export const defaultTimeInputDisplayContext: TimeInputDisplayContextProps = {
errorMessage: '',
isDirty: false,
setIsDirty: () => {},
is12HourFormat: false,
showSeconds: true,
lgIds: getLgIds(),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';

import { FormField } from '@leafygreen-ui/form-field';

import { useTimeInputDisplayContext } from '../../Context/TimeInputDisplayContext';

import { TimeFormFieldProps } from './TimeFormField.types';

/**
* A wrapper around `FormField` that sets the relevant
* attributes, and styling
*/
export const TimeFormField = React.forwardRef<
HTMLDivElement,
TimeFormFieldProps
>(({ children, ...rest }: TimeFormFieldProps, fwdRef) => {
const {
label,
description,
// stateNotification: { state, message: errorMessage },
disabled,
size,
} = useTimeInputDisplayContext();

return (
<FormField
label={label}
description={description}
disabled={disabled}
// state={state}
// errorMessage={errorMessage}
size={size}
ref={fwdRef}
{...rest}
>
{children}
</FormField>
);
});

TimeFormField.displayName = 'TimeFormField';
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { FormFieldProps } from '@leafygreen-ui/form-field';

export type TimeFormFieldProps = React.ComponentPropsWithoutRef<'div'> & {
children: FormFieldProps['children'];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { css, cx } from '@leafygreen-ui/emotion';

const selectStyles = css`
border-top-right-radius: 0;
border-bottom-right-radius: 0;
`;

const baseStyles = css`
&:hover,
&:focus-within {
z-index: 1;
}
`;

export const getContainerStyles = ({
is12HourFormat,
}: {
is12HourFormat: boolean;
}) =>
cx(baseStyles, {
[selectStyles]: is12HourFormat,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';

import { FormFieldInputContainer } from '@leafygreen-ui/form-field';

import { useTimeInputDisplayContext } from '../../Context/TimeInputDisplayContext';

import { getContainerStyles } from './TimeFormFieldInputContainer.styles';
import { TimeFormFieldInputContainerProps } from './TimeFormFieldInputContainer.types';

/**
* A wrapper around `FormField` that sets the relevant
* attributes, and styling
*/
export const TimeFormFieldInputContainer = React.forwardRef<
HTMLDivElement,
TimeFormFieldInputContainerProps
>(({ children, onInputClick }: TimeFormFieldInputContainerProps, fwdRef) => {
const { label, ariaLabelProp, ariaLabelledbyProp, is12HourFormat } =
useTimeInputDisplayContext();

return (
<FormFieldInputContainer
ref={fwdRef}
role="combobox"
tabIndex={-1}
aria-label={!label && ariaLabelProp ? ariaLabelProp : undefined}
aria-labelledby={
!label && !ariaLabelProp && ariaLabelledbyProp
? ariaLabelledbyProp
: undefined
}
onClick={onInputClick}
className={getContainerStyles({ is12HourFormat })}
>
{children}
</FormFieldInputContainer>
);
});

TimeFormFieldInputContainer.displayName = 'TimeFormFieldInputContainer';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { FormFieldProps } from '@leafygreen-ui/form-field';

export type TimeFormFieldInputContainerProps =
React.ComponentPropsWithoutRef<'div'> & {
children: FormFieldProps['children'];
onInputClick?: React.MouseEventHandler<HTMLDivElement>;
};
2 changes: 2 additions & 0 deletions packages/time-input/src/TimeFormField/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { TimeFormField } from './TimeFormField/TimeFormField';
export { TimeFormFieldInputContainer } from './TimeFormFieldInputContainer/TimeFormFieldInputContainer';
Loading
Loading