Skip to content

Commit 3742248

Browse files
acstllmgadewoll
andauthored
[EuiSuperDatePicker] Time zone display (#9191)
Co-authored-by: Lene Gadewoll <[email protected]>
1 parent 621ba86 commit 3742248

19 files changed

+427
-12
lines changed
28.4 KB
Loading
1 Byte
Loading
53.3 KB
Loading
103 Bytes
Loading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Updated `EuiSuperDatePicker` with new time zone information, opt-in via `timeZoneDisplayProps`.
2+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`EuiTimeZoneDisplay renders 1`] = `
4+
<div>
5+
<div
6+
aria-label="UTC-8 (America/Los_Angeles)"
7+
class="euiFlexGroup emotion-euiFlexGroup-responsive-xs-flexStart-center-row-euiTimeZoneDisplay"
8+
data-test-subj="euiTimeZoneDisplay"
9+
>
10+
<span
11+
color="subdued"
12+
data-euiicon-type="globe"
13+
/>
14+
<span
15+
class="euiText emotion-euiText-s-euiTextColor-subdued"
16+
>
17+
UTC-8 (America/Los_Angeles)
18+
</span>
19+
</div>
20+
</div>
21+
`;

packages/eui/src/components/date_picker/super_date_picker/date_popover/absolute_tab.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ describe('EuiAbsoluteTab', () => {
150150

151151
describe('allows several other common date formats, and autoformats them to the `dateFormat` prop', () => {
152152
const assertOutput = (input: HTMLInputElement) => {
153-
// Exclude hours from assertion, because moment uses local machine timezone
153+
// Exclude hours from assertion, because moment uses local machine time zone
154154
expect(input.value).toContain('Jan 1, 1970');
155155
};
156156

packages/eui/src/components/date_picker/super_date_picker/date_popover/absolute_tab.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ import React, {
1717
import moment, { Moment, LocaleSpecifier } from 'moment';
1818
import dateMath from '@elastic/datemath';
1919

20-
import { useUpdateEffect, useEuiMemoizedStyles } from '../../../../services';
20+
import {
21+
useUpdateEffect,
22+
useEuiMemoizedStyles,
23+
useGeneratedHtmlId,
24+
} from '../../../../services';
2125
import { useEuiI18n } from '../../../i18n';
2226
import { EuiFormRow, EuiFieldText, EuiFormLabel } from '../../../form';
2327
import { EuiFlexGroup } from '../../../flex';
@@ -26,6 +30,10 @@ import { EuiCode } from '../../../code';
2630

2731
import { EuiDatePicker, EuiDatePickerProps } from '../../date_picker';
2832
import { EuiDatePopoverContentProps } from './date_popover_content';
33+
import {
34+
EuiTimeZoneDisplay,
35+
type EuiTimeZoneDisplayProps,
36+
} from './timezone_display';
2937
import { euiAbsoluteTabDateFormStyles } from './absolute_tab.styles';
3038

3139
// Allow users to paste in and have the datepicker parse multiple common date formats,
@@ -47,6 +55,7 @@ export interface EuiAbsoluteTabProps {
4755
utcOffset?: number;
4856
minDate?: Moment;
4957
maxDate?: Moment;
58+
timeZoneDisplayProps?: EuiTimeZoneDisplayProps;
5059
}
5160

5261
export const EuiAbsoluteTab: FunctionComponent<EuiAbsoluteTabProps> = ({
@@ -60,6 +69,7 @@ export const EuiAbsoluteTab: FunctionComponent<EuiAbsoluteTabProps> = ({
6069
minDate,
6170
maxDate,
6271
labelPrefix,
72+
timeZoneDisplayProps = {},
6373
}) => {
6474
const styles = useEuiMemoizedStyles(euiAbsoluteTabDateFormStyles);
6575

@@ -80,6 +90,7 @@ export const EuiAbsoluteTab: FunctionComponent<EuiAbsoluteTabProps> = ({
8090
[dateFormat]
8191
);
8292

93+
const timeZomeDescriptionId = useGeneratedHtmlId();
8394
const submitButtonLabel = useEuiI18n(
8495
'euiAbsoluteTab.dateFormatButtonLabel',
8596
'Parse date'
@@ -181,6 +192,7 @@ export const EuiAbsoluteTab: FunctionComponent<EuiAbsoluteTabProps> = ({
181192
helpText={
182193
hasUnparsedText && !isTextInvalid ? dateFormatError : undefined
183194
}
195+
describedByIds={[timeZomeDescriptionId]}
184196
>
185197
<EuiFieldText
186198
compressed
@@ -212,6 +224,10 @@ export const EuiAbsoluteTab: FunctionComponent<EuiAbsoluteTabProps> = ({
212224
/>
213225
)}
214226
</EuiFlexGroup>
227+
<EuiTimeZoneDisplay
228+
id={timeZomeDescriptionId}
229+
{...timeZoneDisplayProps}
230+
/>
215231
</>
216232
);
217233
};

packages/eui/src/components/date_picker/super_date_picker/date_popover/date_popover_button.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
EuiDatePopoverContent,
2626
EuiDatePopoverContentProps,
2727
} from './date_popover_content';
28+
import { type EuiTimeZoneDisplayProps } from './timezone_display';
2829

2930
import { euiDatePopoverButtonStyles } from './date_popover_button.styles';
3031

@@ -50,6 +51,7 @@ export interface EuiDatePopoverButtonProps {
5051
maxDate?: Moment;
5152
compressed?: boolean;
5253
timeOptions: TimeOptions;
54+
timeZoneDisplayProps?: EuiTimeZoneDisplayProps;
5355
}
5456

5557
export const EuiDatePopoverButton: FunctionComponent<
@@ -76,6 +78,7 @@ export const EuiDatePopoverButton: FunctionComponent<
7678
onPopoverClose,
7779
compressed,
7880
timeOptions,
81+
timeZoneDisplayProps = {},
7982
...rest
8083
} = props;
8184

@@ -157,6 +160,7 @@ export const EuiDatePopoverButton: FunctionComponent<
157160
timeOptions={timeOptions}
158161
minDate={minDate}
159162
maxDate={maxDate}
163+
timeZoneDisplayProps={timeZoneDisplayProps}
160164
/>
161165
</EuiPopover>
162166
);

packages/eui/src/components/date_picker/super_date_picker/date_popover/date_popover_content.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
import { EuiAbsoluteTab } from './absolute_tab';
2727
import { EuiRelativeTab } from './relative_tab';
2828
import { euiDatePopoverContentStyles } from './date_popover_content.styles';
29+
import { type EuiTimeZoneDisplayProps } from './timezone_display';
2930

3031
export interface EuiDatePopoverContentProps {
3132
value: string;
@@ -40,6 +41,7 @@ export interface EuiDatePopoverContentProps {
4041
minDate?: Moment;
4142
maxDate?: Moment;
4243
timeOptions: TimeOptions;
44+
timeZoneDisplayProps?: EuiTimeZoneDisplayProps;
4345
}
4446

4547
export const EuiDatePopoverContent: FunctionComponent<
@@ -57,6 +59,7 @@ export const EuiDatePopoverContent: FunctionComponent<
5759
timeOptions,
5860
minDate,
5961
maxDate,
62+
timeZoneDisplayProps = {},
6063
}) => {
6164
const styles = useEuiMemoizedStyles(euiDatePopoverContentStyles);
6265

@@ -107,6 +110,7 @@ export const EuiDatePopoverContent: FunctionComponent<
107110
utcOffset={utcOffset}
108111
minDate={minDate}
109112
maxDate={maxDate}
113+
timeZoneDisplayProps={timeZoneDisplayProps}
110114
/>
111115
),
112116
'data-test-subj': 'superDatePickerAbsoluteTab',
@@ -126,6 +130,7 @@ export const EuiDatePopoverContent: FunctionComponent<
126130
roundUp={roundUp}
127131
labelPrefix={labelPrefix}
128132
timeOptions={timeOptions}
133+
timeZoneDisplayProps={timeZoneDisplayProps}
129134
/>
130135
),
131136
'data-test-subj': 'superDatePickerRelativeTab',

0 commit comments

Comments
 (0)