@pega/cosmos-react-core 8.18.3 → 8.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/AppShell/AppHeader.js +1 -1
- package/lib/components/AppShell/AppHeader.js.map +1 -1
- package/lib/components/AppShell/AppShell.styles.d.ts.map +1 -1
- package/lib/components/AppShell/AppShell.styles.js +5 -3
- package/lib/components/AppShell/AppShell.styles.js.map +1 -1
- package/lib/components/Avatar/Avatar.d.ts.map +1 -1
- package/lib/components/Avatar/Avatar.js +6 -1
- package/lib/components/Avatar/Avatar.js.map +1 -1
- package/lib/components/Button/BareButton.d.ts.map +1 -1
- package/lib/components/Button/BareButton.js +4 -1
- package/lib/components/Button/BareButton.js.map +1 -1
- package/lib/components/Button/Button.d.ts.map +1 -1
- package/lib/components/Button/Button.js +4 -1
- package/lib/components/Button/Button.js.map +1 -1
- package/lib/components/DateTime/DateTime.types.d.ts +6 -0
- package/lib/components/DateTime/DateTime.types.d.ts.map +1 -1
- package/lib/components/DateTime/DateTime.types.js.map +1 -1
- package/lib/components/DateTime/Input/DateInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/DateInput.js +3 -3
- package/lib/components/DateTime/Input/DateInput.js.map +1 -1
- package/lib/components/DateTime/Input/DateRangeInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/DateRangeInput.js +4 -2
- package/lib/components/DateTime/Input/DateRangeInput.js.map +1 -1
- package/lib/components/DateTime/Input/DateTimeInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/DateTimeInput.js +10 -7
- package/lib/components/DateTime/Input/DateTimeInput.js.map +1 -1
- package/lib/components/DateTime/Input/TimeRangeInput.d.ts.map +1 -1
- package/lib/components/DateTime/Input/TimeRangeInput.js +3 -2
- package/lib/components/DateTime/Input/TimeRangeInput.js.map +1 -1
- package/lib/components/DateTime/Input/utils.d.ts +1 -2
- package/lib/components/DateTime/Input/utils.d.ts.map +1 -1
- package/lib/components/DateTime/Input/utils.js +54 -39
- package/lib/components/DateTime/Input/utils.js.map +1 -1
- package/lib/components/DateTime/Picker/Calendar.d.ts +2 -0
- package/lib/components/DateTime/Picker/Calendar.d.ts.map +1 -1
- package/lib/components/DateTime/Picker/Calendar.js +14 -11
- package/lib/components/DateTime/Picker/Calendar.js.map +1 -1
- package/lib/components/DateTime/Picker/DatePicker.d.ts.map +1 -1
- package/lib/components/DateTime/Picker/DatePicker.js +10 -9
- package/lib/components/DateTime/Picker/DatePicker.js.map +1 -1
- package/lib/components/DateTime/Picker/DatePicker.types.d.ts +7 -0
- package/lib/components/DateTime/Picker/DatePicker.types.d.ts.map +1 -1
- package/lib/components/DateTime/Picker/DatePicker.types.js.map +1 -1
- package/lib/components/DateTime/Picker/DateRangePicker.d.ts.map +1 -1
- package/lib/components/DateTime/Picker/DateRangePicker.js +9 -8
- package/lib/components/DateTime/Picker/DateRangePicker.js.map +1 -1
- package/lib/components/DateTime/utils.d.ts +6 -0
- package/lib/components/DateTime/utils.d.ts.map +1 -1
- package/lib/components/DateTime/utils.js +20 -0
- package/lib/components/DateTime/utils.js.map +1 -1
- package/lib/components/Dialog/FormDialog.d.ts.map +1 -1
- package/lib/components/Dialog/FormDialog.js +3 -2
- package/lib/components/Dialog/FormDialog.js.map +1 -1
- package/lib/components/Dialog/InfoDialog.d.ts.map +1 -1
- package/lib/components/Dialog/InfoDialog.js +3 -2
- package/lib/components/Dialog/InfoDialog.js.map +1 -1
- package/lib/components/FieldValueList/FieldValueList.js +1 -1
- package/lib/components/FieldValueList/FieldValueList.js.map +1 -1
- package/lib/components/FormField/FormField.d.ts +2 -0
- package/lib/components/FormField/FormField.d.ts.map +1 -1
- package/lib/components/FormField/FormField.js +9 -7
- package/lib/components/FormField/FormField.js.map +1 -1
- package/lib/components/Menu/Menu.styles.d.ts.map +1 -1
- package/lib/components/Menu/Menu.styles.js +13 -3
- package/lib/components/Menu/Menu.styles.js.map +1 -1
- package/lib/components/Modal/Modal.d.ts.map +1 -1
- package/lib/components/Modal/Modal.js +3 -2
- package/lib/components/Modal/Modal.js.map +1 -1
- package/lib/components/RadioCheck/RadioCheck.d.ts +3 -0
- package/lib/components/RadioCheck/RadioCheck.d.ts.map +1 -1
- package/lib/components/RadioCheck/RadioCheck.js +2 -2
- package/lib/components/RadioCheck/RadioCheck.js.map +1 -1
- package/lib/components/RadioCheckGroup/RadioCheckGroup.d.ts.map +1 -1
- package/lib/components/RadioCheckGroup/RadioCheckGroup.js +1 -0
- package/lib/components/RadioCheckGroup/RadioCheckGroup.js.map +1 -1
- package/lib/components/TextArea/TextArea.d.ts.map +1 -1
- package/lib/components/TextArea/TextArea.js +35 -14
- package/lib/components/TextArea/TextArea.js.map +1 -1
- package/lib/hooks/index.d.ts +1 -0
- package/lib/hooks/index.d.ts.map +1 -1
- package/lib/hooks/index.js +1 -0
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useContentTabIndex.d.ts +17 -0
- package/lib/hooks/useContentTabIndex.d.ts.map +1 -0
- package/lib/hooks/useContentTabIndex.js +48 -0
- package/lib/hooks/useContentTabIndex.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useState, useEffect, useRef } from 'react';
|
|
2
|
+
import { useState, useEffect, useRef, useCallback } from 'react';
|
|
3
3
|
import Flex from '../../Flex';
|
|
4
4
|
import MonthInput from '../Input/MonthInput';
|
|
5
5
|
import Icon, { registerIcon } from '../../Icon';
|
|
@@ -7,7 +7,7 @@ import * as caretLeftIcon from '../../Icon/icons/caret-left.icon';
|
|
|
7
7
|
import * as caretRightIcon from '../../Icon/icons/caret-right.icon';
|
|
8
8
|
import { useConfiguration, useI18n, useTestIds } from '../../../hooks';
|
|
9
9
|
import { getCalendarTypeFromLocale } from '../Input/utils';
|
|
10
|
-
import { getAdjustedUTCDateTime } from '../utils';
|
|
10
|
+
import { getAdjustedUTCDateTime, getAdjustedUTCDateTimeForTimezone } from '../utils';
|
|
11
11
|
import { getDatePickerTestIds } from '../DateTime.test-ids';
|
|
12
12
|
import Calendar from './Calendar';
|
|
13
13
|
import Weeks from './Weeks';
|
|
@@ -16,16 +16,17 @@ import { isValidDate, toDateTimeString } from './utils';
|
|
|
16
16
|
registerIcon(caretLeftIcon, caretRightIcon);
|
|
17
17
|
const DateRangePicker = (props) => {
|
|
18
18
|
const { locale } = useConfiguration();
|
|
19
|
-
const { testId, selected: initial, selectedRange, onChange, min, max, mode, showWeekNumber, ...restProps } = props;
|
|
19
|
+
const { testId, selected: initial, selectedRange, onChange, min, max, mode, showWeekNumber, timeZone, ...restProps } = props;
|
|
20
20
|
const testIds = useTestIds(testId, getDatePickerTestIds);
|
|
21
|
+
const getNow = useCallback(() => (timeZone ? getAdjustedUTCDateTimeForTimezone(timeZone) : getAdjustedUTCDateTime()), [timeZone]);
|
|
21
22
|
const [selected, setSelected] = useState(initial);
|
|
22
|
-
const [current, setCurrent] = useState(selected && isValidDate(selected) ? selected :
|
|
23
|
+
const [current, setCurrent] = useState(() => selected && isValidDate(selected) ? selected : getNow());
|
|
23
24
|
useEffect(() => {
|
|
24
25
|
if (toDateTimeString(initial) !== toDateTimeString(selected)) {
|
|
25
26
|
setSelected(initial);
|
|
26
|
-
setCurrent(initial ||
|
|
27
|
+
setCurrent(initial || getNow());
|
|
27
28
|
}
|
|
28
|
-
}, [toDateTimeString(initial)]);
|
|
29
|
+
}, [toDateTimeString(initial), getNow]);
|
|
29
30
|
const calendarRef = useRef(null);
|
|
30
31
|
useEffect(() => {
|
|
31
32
|
// need to postpone focusing to make sure onFocusWithin has been attached
|
|
@@ -44,7 +45,7 @@ const DateRangePicker = (props) => {
|
|
|
44
45
|
newCurrent.setUTCMonth(newCurrent.getUTCMonth() - 1);
|
|
45
46
|
setCurrent(newCurrent);
|
|
46
47
|
}, children: _jsx(Icon, { name: 'caret-left' }) }), _jsx(StyledMonthNavigationButton, { "data-testid": testIds.setCurrentDate, label: t('set_current_date_a11y'), icon: true, variant: 'simple', onClick: () => {
|
|
47
|
-
const currDate =
|
|
48
|
+
const currDate = getNow();
|
|
48
49
|
setCurrent(currDate);
|
|
49
50
|
setSelected(currDate);
|
|
50
51
|
onChange?.(currDate);
|
|
@@ -58,7 +59,7 @@ const DateRangePicker = (props) => {
|
|
|
58
59
|
setCurrent(date);
|
|
59
60
|
setSelected(date);
|
|
60
61
|
onChange?.(date);
|
|
61
|
-
}, min: min, max: max })] })] }));
|
|
62
|
+
}, min: min, max: max, timeZone: timeZone })] })] }));
|
|
62
63
|
};
|
|
63
64
|
export default DateRangePicker;
|
|
64
65
|
//# sourceMappingURL=DateRangePicker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateRangePicker.js","sourceRoot":"","sources":["../../../../src/components/DateTime/Picker/DateRangePicker.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"DateRangePicker.js","sourceRoot":"","sources":["../../../../src/components/DateTime/Picker/DateRangePicker.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAGjE,OAAO,IAAI,MAAM,YAAY,CAAC;AAC9B,OAAO,UAAU,MAAM,qBAAqB,CAAC;AAC7C,OAAO,IAAI,EAAE,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,aAAa,MAAM,kCAAkC,CAAC;AAClE,OAAO,KAAK,cAAc,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,iCAAiC,EAAE,MAAM,U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AG,GACC,IACzB,EACP,MAAC,IAAI,IAAC,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,aAChC,cAAc,IAAI,KAAC,KAAK,IAAC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,SAAG,EACnF,KAAC,QAAQ,IACP,GAAG,EAAE,WAAW,EAChB,QAAQ,EAAE,QAAQ,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EAClE,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,aAAa,EAC5B,aAAa,QACb,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,IAAI,CAAC,EAAE;4BACd,UAAU,CAAC,IAAI,CAAC,CAAC;wBACnB,CAAC,EACD,QAAQ,EAAE,IAAI,CAAC,EAAE;4BACf,UAAU,CAAC,IAAI,CAAC,CAAC;4BACjB,WAAW,CAAC,IAAI,CAAC,CAAC;4BAClB,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC;wBACnB,CAAC,EACD,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,QAAQ,GAClB,IACG,IACU,CACpB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { useState, useEffect, useRef, useCallback } from 'react';\nimport type { FunctionComponent } from 'react';\n\nimport Flex from '../../Flex';\nimport MonthInput from '../Input/MonthInput';\nimport Icon, { registerIcon } from '../../Icon';\nimport * as caretLeftIcon from '../../Icon/icons/caret-left.icon';\nimport * as caretRightIcon from '../../Icon/icons/caret-right.icon';\nimport { useConfiguration, useI18n, useTestIds } from '../../../hooks';\nimport { getCalendarTypeFromLocale } from '../Input/utils';\nimport { getAdjustedUTCDateTime, getAdjustedUTCDateTimeForTimezone } from '../utils';\nimport { getDatePickerTestIds } from '../DateTime.test-ids';\n\nimport Calendar from './Calendar';\nimport type DatePickerProps from './DatePicker.types';\nimport Weeks from './Weeks';\nimport {\n StyledDatePicker,\n StyledDatePickerMonthInput,\n StyledMonthNavigationButton,\n StyledMonthPicker\n} from './DatePicker.styles';\nimport { isValidDate, toDateTimeString } from './utils';\n\nregisterIcon(caretLeftIcon, caretRightIcon);\n\nexport interface DateRangePickerProps extends DatePickerProps {\n /** Defines dates range that can be set by the user. */\n selectedRange?: { startDate: Date | undefined; endDate: Date | undefined };\n}\n\nconst DateRangePicker: FunctionComponent<DateRangePickerProps> = (props: DateRangePickerProps) => {\n const { locale } = useConfiguration();\n const {\n testId,\n selected: initial,\n selectedRange,\n onChange,\n min,\n max,\n mode,\n showWeekNumber,\n timeZone,\n ...restProps\n } = props;\n const testIds = useTestIds(testId, getDatePickerTestIds);\n const getNow = useCallback(\n () => (timeZone ? getAdjustedUTCDateTimeForTimezone(timeZone) : getAdjustedUTCDateTime()),\n [timeZone]\n );\n const [selected, setSelected] = useState(initial);\n const [current, setCurrent] = useState(() =>\n selected && isValidDate(selected) ? selected : getNow()\n );\n\n useEffect(() => {\n if (toDateTimeString(initial) !== toDateTimeString(selected)) {\n setSelected(initial);\n setCurrent(initial || getNow());\n }\n }, [toDateTimeString(initial), getNow]);\n\n const calendarRef = useRef<HTMLDivElement>(null);\n useEffect(() => {\n // need to postpone focusing to make sure onFocusWithin has been attached\n setTimeout(() => {\n calendarRef.current?.querySelector<HTMLElement>('button[tabindex=\"0\"]:enabled')?.focus();\n });\n }, []);\n\n const calendarType = getCalendarTypeFromLocale(locale);\n const t = useI18n();\n\n return (\n <StyledDatePicker aria-label={t('calendar')} role='region' {...restProps}>\n <Flex as={StyledMonthPicker} container={{ justify: 'between', alignItems: 'end' }}>\n <MonthInput\n data-testid={testIds.month}\n aria-label={t('picker_jump_to_month_and_year')}\n value={current}\n as={StyledDatePickerMonthInput}\n innerLabelsHidden={false}\n required\n role='group'\n onChange={({ valueAsTimestamp }) => {\n const newCurrent = new Date(valueAsTimestamp!);\n newCurrent.setUTCDate(current.getUTCDate());\n setCurrent(newCurrent);\n }}\n min={min}\n max={max}\n />\n <StyledMonthNavigationButton\n data-testid={testIds.previousMonth}\n label={t('picker_prev_month')}\n variant='simple'\n icon\n onClick={() => {\n const newCurrent = new Date(current);\n newCurrent.setUTCMonth(newCurrent.getUTCMonth() - 1);\n setCurrent(newCurrent);\n }}\n >\n <Icon name='caret-left' />\n </StyledMonthNavigationButton>\n <StyledMonthNavigationButton\n data-testid={testIds.setCurrentDate}\n label={t('set_current_date_a11y')}\n icon\n variant='simple'\n onClick={() => {\n const currDate = getNow();\n setCurrent(currDate);\n setSelected(currDate);\n onChange?.(currDate);\n }}\n >\n <Icon name='calendar-now' />\n </StyledMonthNavigationButton>\n <StyledMonthNavigationButton\n data-testid={testIds.nextMonth}\n label={t('picker_next_month')}\n variant='simple'\n icon\n onClick={() => {\n const newCurrent = new Date(current);\n newCurrent.setUTCMonth(newCurrent.getUTCMonth() + 1);\n setCurrent(newCurrent);\n }}\n >\n <Icon name='caret-right' />\n </StyledMonthNavigationButton>\n </Flex>\n <Flex container={{ wrap: 'nowrap' }}>\n {showWeekNumber && <Weeks current={current} calendarType={calendarType} disabled />}\n <Calendar\n ref={calendarRef}\n selected={selected && isValidDate(selected) ? selected : undefined}\n current={current}\n selectedRange={selectedRange}\n showHighlight\n calendarType={calendarType}\n onFocus={date => {\n setCurrent(date);\n }}\n onSelect={date => {\n setCurrent(date);\n setSelected(date);\n onChange?.(date);\n }}\n min={min}\n max={max}\n timeZone={timeZone}\n />\n </Flex>\n </StyledDatePicker>\n );\n};\n\nexport default DateRangePicker;\n"]}
|
|
@@ -38,5 +38,11 @@ export declare function formatDuration(valueInMs: number, { locale, significantU
|
|
|
38
38
|
* @returns Current date and time value adjusted for local time zone.
|
|
39
39
|
*/
|
|
40
40
|
export declare const getAdjustedUTCDateTime: () => Date;
|
|
41
|
+
/**
|
|
42
|
+
* @param timeZone - IANA timezone string (e.g. "America/New_York")
|
|
43
|
+
* @returns Current date and time for the given timezone, with wall-clock time
|
|
44
|
+
* encoded in UTC fields — matching the convention used by DateTime inputs.
|
|
45
|
+
*/
|
|
46
|
+
export declare const getAdjustedUTCDateTimeForTimezone: (timeZone: string) => Date;
|
|
41
47
|
export {};
|
|
42
48
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/DateTime/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/components/DateTime/utils.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,OAAO,KAAK,EAAmB,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AASzF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAwBjD,KAAK,qBAAqB,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,cAAc,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,CACA;IACE,OAAO,EAAE,aAAa,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;IACvD,CAAC,CAAC,EAAE,mBAAmB,CAAC,eAAe,CAAC,CAAC;CAC1C,GACD;IAAE,OAAO,EAAE,aAAa,CAAC;IAAC,CAAC,EAAE,mBAAmB,CAAC,eAAe,CAAC,CAAA;CAAE,CACtE,CAAC;AA6KF,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,IAAI,CAAC,qBAA0B,uBAYzC;AA8BD,wBAAgB,cAAc,CAC5B,KAAK,EAAE,IAAI,EACX,EACE,CAAC,EACD,MAAM,EACN,MAAM,EACN,OAAO,EACP,WAAW,EACX,YAAsC,EACtC,QAAQ,EACT,EAAE,qBAAqB,UAuFzB;AAOD,UAAU,qBAAqB;IAC7B,kDAAkD;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,0DAA0D;IAC1D,gBAAgB,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACpC;;;OAGG;IACH,WAAW,CAAC,EAAE,IAAI,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC;IACtD;;;OAGG;IACH,YAAY,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,aAAa,CAAC;CACrE;AAgBD,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,EACE,MAAM,EACN,gBAAgB,EAChB,WAAsB,EACtB,YAAuB,EACxB,EAAE,qBAAqB,UAgCzB;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,QAAO,IAIzC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,GAAI,UAAU,MAAM,KAAG,IAQpE,CAAC"}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
+
// cspell:ignore DDTHH
|
|
1
2
|
import dayjs from 'dayjs';
|
|
3
|
+
import tz from 'dayjs/plugin/timezone';
|
|
4
|
+
import utc from 'dayjs/plugin/utc';
|
|
2
5
|
import { cap } from '../../utils';
|
|
3
6
|
import { CALENDAR_TYPES } from './Input/local';
|
|
4
7
|
import { getEndOfWeek, getQuarterForDateTimeZone, getStartOfWeek, getWeek, getWeekYear } from './Input/utils';
|
|
8
|
+
dayjs.extend(utc);
|
|
9
|
+
dayjs.extend(tz);
|
|
5
10
|
const unitsInMs = {
|
|
6
11
|
year: 24 * 60 * 60 * 1000 * 365,
|
|
7
12
|
month: (24 * 60 * 60 * 1000 * 365) / 12,
|
|
@@ -282,4 +287,19 @@ export const getAdjustedUTCDateTime = () => {
|
|
|
282
287
|
now.setTime(now.getTime() - now.getTimezoneOffset() * 60000);
|
|
283
288
|
return now;
|
|
284
289
|
};
|
|
290
|
+
/**
|
|
291
|
+
* @param timeZone - IANA timezone string (e.g. "America/New_York")
|
|
292
|
+
* @returns Current date and time for the given timezone, with wall-clock time
|
|
293
|
+
* encoded in UTC fields — matching the convention used by DateTime inputs.
|
|
294
|
+
*/
|
|
295
|
+
export const getAdjustedUTCDateTimeForTimezone = (timeZone) => {
|
|
296
|
+
try {
|
|
297
|
+
// eslint-disable-next-line no-new
|
|
298
|
+
new Intl.DateTimeFormat('en-US', { timeZone });
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
return getAdjustedUTCDateTime();
|
|
302
|
+
}
|
|
303
|
+
return new Date(`${dayjs().tz(timeZone).format('YYYY-MM-DDTHH:mm:ss.SSS')}Z`);
|
|
304
|
+
};
|
|
285
305
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/DateTime/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGlC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACL,YAAY,EACZ,yBAAyB,EACzB,cAAc,EACd,OAAO,EACP,WAAW,EACZ,MAAM,eAAe,CAAC;AAGvB,MAAM,SAAS,GAAG;IAChB,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,GAAG;IAC/B,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,GAAG,CAAC,GAAG,EAAE;IACvC,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IACxB,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IACpB,MAAM,EAAE,EAAE,GAAG,IAAI;IACjB,MAA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CAAC,CAAC,IAAI,KAAK,YAAY;YAAE,MAAM;IACpD,CAAC;IACD,OAAO,GAAG,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAS,EAAE;IAC/C,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,GAAG,CAAC,iBAAiB,EAAE,GAAG,KAAK,CAAC,CAAC;IAC7D,OAAO,GAAG,CAAC;AACb,CAAC,CAAC","sourcesContent":["import dayjs from 'dayjs';\n\nimport type { TranslationFunction, TranslationPack } from '../../i18n';\nimport type { ExcludeStrict } from '../../types';\nimport { cap } from '../../utils';\n\nimport type { AbsoluteVariant, DateTimeFormat, DateTimeVariant } from './DateTime.types';\nimport { CALENDAR_TYPES } from './Input/local';\nimport {\n getEndOfWeek,\n getQuarterForDateTimeZone,\n getStartOfWeek,\n getWeek,\n getWeekYear\n} from './Input/utils';\nimport type { ClockFormat } from './Input/utils';\n\nconst unitsInMs = {\n year: 24 * 60 * 60 * 1000 * 365,\n month: (24 * 60 * 60 * 1000 * 365) / 12,\n day: 24 * 60 * 60 * 1000,\n hour: 60 * 60 * 1000,\n minute: 60 * 1000,\n second: 1000\n} satisfies Partial<Record<Intl.RelativeTimeFormatUnit, number>>;\n\ntype TimeUnit = keyof typeof unitsInMs;\nconst timeUnitsOrdered = [\n 'year',\n 'month',\n 'day',\n 'hour',\n 'minute',\n 'second'\n] as const satisfies TimeUnit[];\n\ntype DateTimeFormatOptions = {\n locale: string;\n format: DateTimeFormat;\n timeZone?: string;\n clockFormat?: ClockFormat;\n calendarType?: string;\n} & (\n | {\n variant: ExcludeStrict<DateTimeVariant, 'quarteryear'>;\n t?: TranslationFunction<TranslationPack>;\n }\n | { variant: 'quarteryear'; t: TranslationFunction<TranslationPack> }\n);\n\ntype DateOptions = Pick<Intl.DateTimeFormatOptions, 'year' | 'month' | 'day'>;\ntype TimeOptions = Pick<Intl.DateTimeFormatOptions, 'hour' | 'minute' | 'second'>;\ntype DateStyle = Pick<Intl.DateTimeFormatOptions, 'dateStyle'>;\ntype TimeStyle = Pick<Intl.DateTimeFormatOptions, 'timeStyle'>;\n\nconst dateShort = {\n dateStyle: 'short'\n} satisfies DateStyle;\n\nconst dateMedium = {\n dateStyle: 'medium'\n} satisfies DateStyle;\n\nconst dateLong = {\n dateStyle: 'long'\n} satisfies DateStyle;\n\nconst dateNumeric = {\n year: 'numeric',\n month: 'numeric',\n day: 'numeric'\n} satisfies DateOptions;\n\nconst timeShort = {\n timeStyle: 'short'\n} satisfies TimeStyle;\n\nconst timeMedium = {\n timeStyle: 'medium'\n} satisfies TimeStyle;\n\nconst timeLong = {\n timeStyle: 'medium'\n} satisfies TimeStyle;\n\nconst timeNumeric = {\n hour: 'numeric',\n minute: 'numeric'\n} satisfies TimeOptions;\n\nconst dateTimeShort = {\n ...dateShort,\n ...timeShort\n} satisfies DateStyle & TimeStyle;\n\nconst dateTimeMedium = {\n ...dateMedium,\n ...timeShort\n} satisfies DateStyle & TimeStyle;\n\nconst dateTimeLong = {\n ...dateLong,\n ...timeMedium\n} satisfies DateStyle & TimeStyle;\n\nconst dateTimeNumeric = {\n ...dateNumeric,\n ...timeNumeric\n} satisfies DateOptions & TimeOptions;\n\nconst timeLongNumeric = {\n ...timeNumeric,\n second: 'numeric'\n} satisfies TimeOptions;\n\nconst dateTimeLongNumeric = {\n ...dateNumeric,\n ...timeLongNumeric\n} satisfies DateOptions & TimeOptions;\n\ntype AddClockFormatToTimeKeys<Key extends DateTimeVariant> = Key extends `${string}time`\n ? `${Key}${'' | 12 | 24}`\n : Key;\n\nconst formatMapping = {\n date: {\n short: dateShort,\n medium: dateMedium,\n long: dateLong,\n numeric: dateNumeric,\n 'long-numeric': dateNumeric\n },\n datetime: {\n short: dateTimeShort,\n medium: dateTimeMedium,\n long: dateTimeLong,\n numeric: dateTimeNumeric,\n 'long-numeric': dateTimeLongNumeric\n },\n datetime12: {\n short: { ...dateTimeShort, hour12: true },\n medium: { ...dateTimeMedium, hour12: true },\n long: { ...dateTimeLong, hour12: true },\n numeric: { ...dateTimeNumeric, hour12: true },\n 'long-numeric': { ...dateTimeLongNumeric, hour12: true }\n },\n datetime24: {\n short: { ...dateTimeShort, hour12: false },\n medium: { ...dateTimeMedium, hour12: false },\n long: { ...dateTimeLong, hour12: false },\n numeric: { ...dateTimeNumeric, hour12: false },\n 'long-numeric': { ...dateTimeLongNumeric, hour12: false }\n },\n time: {\n short: timeShort,\n medium: timeMedium,\n long: timeLong,\n numeric: timeNumeric,\n 'long-numeric': timeLongNumeric\n },\n time12: {\n short: { ...timeShort, hour12: true },\n medium: { ...timeMedium, hour12: true },\n long: { ...timeLong, hour12: true },\n numeric: { ...timeNumeric, hour12: true },\n 'long-numeric': { ...timeLongNumeric, hour12: true }\n },\n time24: {\n short: { ...timeShort, hour12: false },\n medium: { ...timeMedium, hour12: false },\n long: { ...timeLong, hour12: false },\n numeric: { ...timeNumeric, hour12: false },\n 'long-numeric': { ...timeLongNumeric, hour12: false }\n },\n month: {\n short: { month: 'short' },\n medium: { month: 'short' },\n long: { month: 'long' },\n numeric: { month: 'numeric' },\n 'long-numeric': { month: 'numeric' }\n },\n monthyear: {\n short: { year: 'numeric', month: 'short' },\n medium: { year: 'numeric', month: 'short' },\n long: { year: 'numeric', month: 'long' },\n numeric: { year: 'numeric', month: 'numeric' },\n 'long-numeric': { year: 'numeric', month: 'numeric' }\n },\n week: {\n short: { month: 'short', day: 'numeric' },\n medium: { month: 'short', day: 'numeric' },\n long: { month: 'long', day: 'numeric' },\n numeric: { month: 'numeric', day: 'numeric' },\n 'long-numeric': { month: 'numeric', day: 'numeric' }\n },\n year: {\n short: { year: 'numeric' },\n medium: { year: 'numeric' },\n long: { year: 'numeric' },\n numeric: { year: '2-digit' },\n 'long-numeric': { year: '2-digit' }\n },\n relative: {\n short: { style: 'long', numeric: 'auto' },\n medium: { style: 'long', numeric: 'auto' },\n long: { style: 'long', numeric: 'auto' },\n numeric: { style: 'short', numeric: 'auto' },\n 'long-numeric': { style: 'short', numeric: 'auto' }\n }\n} satisfies Record<\n AddClockFormatToTimeKeys<ExcludeStrict<AbsoluteVariant, 'quarteryear'>>,\n Record<DateTimeFormat, Intl.DateTimeFormatOptions>\n> &\n Record<'relative', Record<DateTimeFormat, Intl.RelativeTimeFormatOptions>>;\n\nconst dateTimeFormatCache: Map<\n // locale & stringified sorted Intl.DateTimeFormatOptions\n string,\n Intl.DateTimeFormat\n> = new Map();\n\nexport function getIntlDateTimeFormatFromCache(\n locale: string,\n options: Intl.DateTimeFormatOptions = {}\n) {\n const sortedOptions = JSON.stringify(options, Object.keys(options).sort());\n const key = `${locale}${sortedOptions}`;\n let formatter = dateTimeFormatCache.get(key);\n\n if (!formatter) {\n formatter = new Intl.DateTimeFormat(locale, options);\n dateTimeFormatCache.set(key, formatter);\n }\n\n return formatter;\n}\n\nconst relativeTimeFormatCache: Map<\n // locale & stringified sorted Intl.RelativeTimeFormatOptions\n string,\n Intl.RelativeTimeFormat\n> = new Map();\n\nconst getIntlRelativeTimeFormatFromCache = (\n locale: string,\n options: Intl.RelativeTimeFormatOptions = {}\n) => {\n const sortedOptions = JSON.stringify(options, Object.keys(options).sort());\n const key = `${locale}${sortedOptions}`;\n let formatter = relativeTimeFormatCache.get(key);\n\n if (!formatter) {\n formatter = new Intl.RelativeTimeFormat(locale, options);\n relativeTimeFormatCache.set(key, formatter);\n }\n\n return formatter;\n};\n\nconst displayNamesCache: Record<\n // locale\n string,\n Intl.DateTimeDisplayNames\n> = {};\n\nexport function formatDateTime(\n value: Date,\n {\n t,\n locale,\n format,\n variant,\n clockFormat,\n calendarType = CALENDAR_TYPES.ISO_8601,\n timeZone\n }: DateTimeFormatOptions\n) {\n const getFormattedDate = (\n date: Date,\n dateVariant: ExcludeStrict<AbsoluteVariant, 'quarteryear'>\n ) => {\n const resolvedVariant: AddClockFormatToTimeKeys<typeof dateVariant> =\n dateVariant === 'time' || dateVariant === 'datetime'\n ? `${dateVariant}${clockFormat ?? ''}`\n : dateVariant;\n const resolvedOptions = formatMapping[resolvedVariant][format];\n\n return getIntlDateTimeFormatFromCache(locale, {\n ...resolvedOptions,\n timeZone\n }).format(date);\n };\n\n const relativeTimeFormatter = (\n relativeValue: number,\n unit: TimeUnit,\n enforceNumeric?: boolean\n ) => {\n const resolvedOptions: Intl.RelativeTimeFormatOptions = {\n ...formatMapping.relative[format],\n numeric: enforceNumeric ? 'always' : 'auto'\n };\n\n return getIntlRelativeTimeFormatFromCache(locale, resolvedOptions).format(relativeValue, unit);\n };\n\n const getRelativeTime = (date: Date) => {\n const now = dayjs();\n const targetDate = dayjs(date);\n\n // Deliberately reduce precision to 1 minute, handles \"now\" cases\n const isWithinMinute = Math.abs(targetDate.diff(now, 'millisecond')) < 60000;\n if (isWithinMinute) {\n return relativeTimeFormatter(0, 'second', false);\n }\n\n // Find the most appropriate unit by checking dayjs diff for each unit\n for (const unit of timeUnitsOrdered) {\n const diff = targetDate.diff(now, unit);\n if (Math.abs(diff) >= 1) {\n return relativeTimeFormatter(diff, unit, true);\n }\n }\n\n // Fallback to seconds if no unit has a difference >= 1\n const secondsDiff = targetDate.diff(now, 'second');\n return relativeTimeFormatter(secondsDiff, 'second', true);\n };\n\n const getFormattedWeek = (date: Date) => {\n displayNamesCache[locale] ??= new Intl.DisplayNames(locale, {\n style: 'long',\n type: 'dateTimeField'\n }) as Intl.DateTimeDisplayNames;\n\n const displayNames = displayNamesCache[locale];\n const startDate = getFormattedDate(getStartOfWeek(date, calendarType, timeZone), 'week');\n const endDate = getFormattedDate(getEndOfWeek(date, calendarType, timeZone), 'week');\n\n return `${cap(displayNames.of('weekOfYear'))} ${getWeek(\n date,\n calendarType,\n timeZone\n )}, ${getWeekYear(date, calendarType, timeZone)} (${startDate} - ${endDate})`;\n };\n\n const getFormattedQuarterYear = (date: Date) => {\n const formattedYear = getFormattedDate(date, 'year');\n const quarterNumber = getQuarterForDateTimeZone(date, timeZone);\n return `${t!(`date_quarter_q${quarterNumber}`, [formattedYear])}`;\n };\n\n switch (variant) {\n case 'relative':\n return getRelativeTime(value);\n case 'week':\n return getFormattedWeek(value);\n case 'quarteryear':\n return getFormattedQuarterYear(value);\n default:\n return getFormattedDate(value, variant);\n }\n}\n\nconst dayInMs = 24 * 60 * 60 * 1000;\nconst hourInMs = 60 * 60 * 1000;\nconst minuteInMs = 60 * 1000;\nconst secondInMs = 1000;\n\ninterface DurationFormatOptions {\n /** Locale to be used - en_US, jp_JP, fr_FR etc */\n locale: string;\n /** Determines maximum number of units to be displayed. */\n significantUnits: 5 | 4 | 3 | 2 | 1;\n /**\n * Unit formatting style\n * @default \"narrow\"\n */\n unitDisplay?: Intl.NumberFormatOptions['unitDisplay'];\n /**\n * Unit of maximum precision\n * @default \"second\"\n */\n maxPrecision?: 'day' | 'hour' | 'minute' | 'second' | 'millisecond';\n}\n\nconst numberFormatCache: Record<\n // locale\n string,\n Record<\n // unit\n string,\n Record<\n // unitDisplay\n string,\n Intl.NumberFormat\n >\n >\n> = {};\n\nexport function formatDuration(\n valueInMs: number,\n {\n locale,\n significantUnits,\n unitDisplay = 'narrow',\n maxPrecision = 'second'\n }: DurationFormatOptions\n) {\n numberFormatCache[locale] ??= {};\n\n const sign = valueInMs < 0 ? '-' : '';\n const absMs = Math.abs(valueInMs);\n\n const durationParts = [\n { unit: 'day', value: Math.floor(absMs / dayInMs) },\n { unit: 'hour', value: Math.floor((absMs % dayInMs) / hourInMs) },\n { unit: 'minute', value: Math.floor((absMs % hourInMs) / minuteInMs) },\n { unit: 'second', value: Math.floor((absMs % minuteInMs) / secondInMs) },\n { unit: 'millisecond', value: absMs % secondInMs }\n ];\n\n const result = [];\n for (let i = 0; result.length < significantUnits && i < durationParts.length; i += 1) {\n const { value, unit } = durationParts[i];\n\n if (value > 0 || (unit === maxPrecision && result.length === 0)) {\n numberFormatCache[locale][unit] ??= {};\n numberFormatCache[locale][unit][unitDisplay] ??= new Intl.NumberFormat(locale, {\n style: 'unit',\n unit,\n unitDisplay\n });\n\n result.push(numberFormatCache[locale][unit][unitDisplay].format(value));\n }\n if (durationParts[i].unit === maxPrecision) break;\n }\n return `${sign}${result.join(' ')}`;\n}\n\n/**\n * @returns Current date and time value adjusted for local time zone.\n */\nexport const getAdjustedUTCDateTime = (): Date => {\n const now = new Date();\n now.setTime(now.getTime() - now.getTimezoneOffset() * 60000);\n return now;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/components/DateTime/utils.ts"],"names":[],"mappings":"AAAA,sBAAsB;AACtB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,uBAAuB,CAAC;AACvC,OAAO,GAAG,MAAM,kBAAkB,CAAC;AAInC,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAGlC,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EACL,YAAY,EACZ,yBAAyB,EACzB,cAAc,EACd,OAAO,EACP,WAAW,EACZ,MAAM,eAAe,CAAC;AAGvB,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AAClB,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAEjB,MAAM,SAAS,GAAG;IAChB,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,GAAG;IAC/B,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,GAAG,CAAC,GAAG,EAAE;IACvC,GAAG,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI;IACxB,IAAI,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IACpB,MAAM,EAAE,EAAE,GAAG,IAAI;IACjB,MAAM,EAAE,IAAI;CACkD,CAAC;AAGjE,MAA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AAM;IACpD,CAAC;IACD,OAAO,GAAG,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAS,EAAE;IAC/C,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;IACvB,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,GAAG,CAAC,iBAAiB,EAAE,GAAG,KAAK,CAAC,CAAC;IAC7D,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,QAAgB,EAAQ,EAAE;IAC1E,IAAI,CAAC;QACH,kCAAkC;QAClC,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,sBAAsB,EAAE,CAAC;IAClC,CAAC;IACD,OAAO,IAAI,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,yBAAyB,CAAC,GAAG,CAAC,CAAC;AAChF,CAAC,CAAC","sourcesContent":["// cspell:ignore DDTHH\nimport dayjs from 'dayjs';\nimport tz from 'dayjs/plugin/timezone';\nimport utc from 'dayjs/plugin/utc';\n\nimport type { TranslationFunction, TranslationPack } from '../../i18n';\nimport type { ExcludeStrict } from '../../types';\nimport { cap } from '../../utils';\n\nimport type { AbsoluteVariant, DateTimeFormat, DateTimeVariant } from './DateTime.types';\nimport { CALENDAR_TYPES } from './Input/local';\nimport {\n getEndOfWeek,\n getQuarterForDateTimeZone,\n getStartOfWeek,\n getWeek,\n getWeekYear\n} from './Input/utils';\nimport type { ClockFormat } from './Input/utils';\n\ndayjs.extend(utc);\ndayjs.extend(tz);\n\nconst unitsInMs = {\n year: 24 * 60 * 60 * 1000 * 365,\n month: (24 * 60 * 60 * 1000 * 365) / 12,\n day: 24 * 60 * 60 * 1000,\n hour: 60 * 60 * 1000,\n minute: 60 * 1000,\n second: 1000\n} satisfies Partial<Record<Intl.RelativeTimeFormatUnit, number>>;\n\ntype TimeUnit = keyof typeof unitsInMs;\nconst timeUnitsOrdered = [\n 'year',\n 'month',\n 'day',\n 'hour',\n 'minute',\n 'second'\n] as const satisfies TimeUnit[];\n\ntype DateTimeFormatOptions = {\n locale: string;\n format: DateTimeFormat;\n timeZone?: string;\n clockFormat?: ClockFormat;\n calendarType?: string;\n} & (\n | {\n variant: ExcludeStrict<DateTimeVariant, 'quarteryear'>;\n t?: TranslationFunction<TranslationPack>;\n }\n | { variant: 'quarteryear'; t: TranslationFunction<TranslationPack> }\n);\n\ntype DateOptions = Pick<Intl.DateTimeFormatOptions, 'year' | 'month' | 'day'>;\ntype TimeOptions = Pick<Intl.DateTimeFormatOptions, 'hour' | 'minute' | 'second'>;\ntype DateStyle = Pick<Intl.DateTimeFormatOptions, 'dateStyle'>;\ntype TimeStyle = Pick<Intl.DateTimeFormatOptions, 'timeStyle'>;\n\nconst dateShort = {\n dateStyle: 'short'\n} satisfies DateStyle;\n\nconst dateMedium = {\n dateStyle: 'medium'\n} satisfies DateStyle;\n\nconst dateLong = {\n dateStyle: 'long'\n} satisfies DateStyle;\n\nconst dateNumeric = {\n year: 'numeric',\n month: 'numeric',\n day: 'numeric'\n} satisfies DateOptions;\n\nconst timeShort = {\n timeStyle: 'short'\n} satisfies TimeStyle;\n\nconst timeMedium = {\n timeStyle: 'medium'\n} satisfies TimeStyle;\n\nconst timeLong = {\n timeStyle: 'medium'\n} satisfies TimeStyle;\n\nconst timeNumeric = {\n hour: 'numeric',\n minute: 'numeric'\n} satisfies TimeOptions;\n\nconst dateTimeShort = {\n ...dateShort,\n ...timeShort\n} satisfies DateStyle & TimeStyle;\n\nconst dateTimeMedium = {\n ...dateMedium,\n ...timeShort\n} satisfies DateStyle & TimeStyle;\n\nconst dateTimeLong = {\n ...dateLong,\n ...timeMedium\n} satisfies DateStyle & TimeStyle;\n\nconst dateTimeNumeric = {\n ...dateNumeric,\n ...timeNumeric\n} satisfies DateOptions & TimeOptions;\n\nconst timeLongNumeric = {\n ...timeNumeric,\n second: 'numeric'\n} satisfies TimeOptions;\n\nconst dateTimeLongNumeric = {\n ...dateNumeric,\n ...timeLongNumeric\n} satisfies DateOptions & TimeOptions;\n\ntype AddClockFormatToTimeKeys<Key extends DateTimeVariant> = Key extends `${string}time`\n ? `${Key}${'' | 12 | 24}`\n : Key;\n\nconst formatMapping = {\n date: {\n short: dateShort,\n medium: dateMedium,\n long: dateLong,\n numeric: dateNumeric,\n 'long-numeric': dateNumeric\n },\n datetime: {\n short: dateTimeShort,\n medium: dateTimeMedium,\n long: dateTimeLong,\n numeric: dateTimeNumeric,\n 'long-numeric': dateTimeLongNumeric\n },\n datetime12: {\n short: { ...dateTimeShort, hour12: true },\n medium: { ...dateTimeMedium, hour12: true },\n long: { ...dateTimeLong, hour12: true },\n numeric: { ...dateTimeNumeric, hour12: true },\n 'long-numeric': { ...dateTimeLongNumeric, hour12: true }\n },\n datetime24: {\n short: { ...dateTimeShort, hour12: false },\n medium: { ...dateTimeMedium, hour12: false },\n long: { ...dateTimeLong, hour12: false },\n numeric: { ...dateTimeNumeric, hour12: false },\n 'long-numeric': { ...dateTimeLongNumeric, hour12: false }\n },\n time: {\n short: timeShort,\n medium: timeMedium,\n long: timeLong,\n numeric: timeNumeric,\n 'long-numeric': timeLongNumeric\n },\n time12: {\n short: { ...timeShort, hour12: true },\n medium: { ...timeMedium, hour12: true },\n long: { ...timeLong, hour12: true },\n numeric: { ...timeNumeric, hour12: true },\n 'long-numeric': { ...timeLongNumeric, hour12: true }\n },\n time24: {\n short: { ...timeShort, hour12: false },\n medium: { ...timeMedium, hour12: false },\n long: { ...timeLong, hour12: false },\n numeric: { ...timeNumeric, hour12: false },\n 'long-numeric': { ...timeLongNumeric, hour12: false }\n },\n month: {\n short: { month: 'short' },\n medium: { month: 'short' },\n long: { month: 'long' },\n numeric: { month: 'numeric' },\n 'long-numeric': { month: 'numeric' }\n },\n monthyear: {\n short: { year: 'numeric', month: 'short' },\n medium: { year: 'numeric', month: 'short' },\n long: { year: 'numeric', month: 'long' },\n numeric: { year: 'numeric', month: 'numeric' },\n 'long-numeric': { year: 'numeric', month: 'numeric' }\n },\n week: {\n short: { month: 'short', day: 'numeric' },\n medium: { month: 'short', day: 'numeric' },\n long: { month: 'long', day: 'numeric' },\n numeric: { month: 'numeric', day: 'numeric' },\n 'long-numeric': { month: 'numeric', day: 'numeric' }\n },\n year: {\n short: { year: 'numeric' },\n medium: { year: 'numeric' },\n long: { year: 'numeric' },\n numeric: { year: '2-digit' },\n 'long-numeric': { year: '2-digit' }\n },\n relative: {\n short: { style: 'long', numeric: 'auto' },\n medium: { style: 'long', numeric: 'auto' },\n long: { style: 'long', numeric: 'auto' },\n numeric: { style: 'short', numeric: 'auto' },\n 'long-numeric': { style: 'short', numeric: 'auto' }\n }\n} satisfies Record<\n AddClockFormatToTimeKeys<ExcludeStrict<AbsoluteVariant, 'quarteryear'>>,\n Record<DateTimeFormat, Intl.DateTimeFormatOptions>\n> &\n Record<'relative', Record<DateTimeFormat, Intl.RelativeTimeFormatOptions>>;\n\nconst dateTimeFormatCache: Map<\n // locale & stringified sorted Intl.DateTimeFormatOptions\n string,\n Intl.DateTimeFormat\n> = new Map();\n\nexport function getIntlDateTimeFormatFromCache(\n locale: string,\n options: Intl.DateTimeFormatOptions = {}\n) {\n const sortedOptions = JSON.stringify(options, Object.keys(options).sort());\n const key = `${locale}${sortedOptions}`;\n let formatter = dateTimeFormatCache.get(key);\n\n if (!formatter) {\n formatter = new Intl.DateTimeFormat(locale, options);\n dateTimeFormatCache.set(key, formatter);\n }\n\n return formatter;\n}\n\nconst relativeTimeFormatCache: Map<\n // locale & stringified sorted Intl.RelativeTimeFormatOptions\n string,\n Intl.RelativeTimeFormat\n> = new Map();\n\nconst getIntlRelativeTimeFormatFromCache = (\n locale: string,\n options: Intl.RelativeTimeFormatOptions = {}\n) => {\n const sortedOptions = JSON.stringify(options, Object.keys(options).sort());\n const key = `${locale}${sortedOptions}`;\n let formatter = relativeTimeFormatCache.get(key);\n\n if (!formatter) {\n formatter = new Intl.RelativeTimeFormat(locale, options);\n relativeTimeFormatCache.set(key, formatter);\n }\n\n return formatter;\n};\n\nconst displayNamesCache: Record<\n // locale\n string,\n Intl.DateTimeDisplayNames\n> = {};\n\nexport function formatDateTime(\n value: Date,\n {\n t,\n locale,\n format,\n variant,\n clockFormat,\n calendarType = CALENDAR_TYPES.ISO_8601,\n timeZone\n }: DateTimeFormatOptions\n) {\n const getFormattedDate = (\n date: Date,\n dateVariant: ExcludeStrict<AbsoluteVariant, 'quarteryear'>\n ) => {\n const resolvedVariant: AddClockFormatToTimeKeys<typeof dateVariant> =\n dateVariant === 'time' || dateVariant === 'datetime'\n ? `${dateVariant}${clockFormat ?? ''}`\n : dateVariant;\n const resolvedOptions = formatMapping[resolvedVariant][format];\n\n return getIntlDateTimeFormatFromCache(locale, {\n ...resolvedOptions,\n timeZone\n }).format(date);\n };\n\n const relativeTimeFormatter = (\n relativeValue: number,\n unit: TimeUnit,\n enforceNumeric?: boolean\n ) => {\n const resolvedOptions: Intl.RelativeTimeFormatOptions = {\n ...formatMapping.relative[format],\n numeric: enforceNumeric ? 'always' : 'auto'\n };\n\n return getIntlRelativeTimeFormatFromCache(locale, resolvedOptions).format(relativeValue, unit);\n };\n\n const getRelativeTime = (date: Date) => {\n const now = dayjs();\n const targetDate = dayjs(date);\n\n // Deliberately reduce precision to 1 minute, handles \"now\" cases\n const isWithinMinute = Math.abs(targetDate.diff(now, 'millisecond')) < 60000;\n if (isWithinMinute) {\n return relativeTimeFormatter(0, 'second', false);\n }\n\n // Find the most appropriate unit by checking dayjs diff for each unit\n for (const unit of timeUnitsOrdered) {\n const diff = targetDate.diff(now, unit);\n if (Math.abs(diff) >= 1) {\n return relativeTimeFormatter(diff, unit, true);\n }\n }\n\n // Fallback to seconds if no unit has a difference >= 1\n const secondsDiff = targetDate.diff(now, 'second');\n return relativeTimeFormatter(secondsDiff, 'second', true);\n };\n\n const getFormattedWeek = (date: Date) => {\n displayNamesCache[locale] ??= new Intl.DisplayNames(locale, {\n style: 'long',\n type: 'dateTimeField'\n }) as Intl.DateTimeDisplayNames;\n\n const displayNames = displayNamesCache[locale];\n const startDate = getFormattedDate(getStartOfWeek(date, calendarType, timeZone), 'week');\n const endDate = getFormattedDate(getEndOfWeek(date, calendarType, timeZone), 'week');\n\n return `${cap(displayNames.of('weekOfYear'))} ${getWeek(\n date,\n calendarType,\n timeZone\n )}, ${getWeekYear(date, calendarType, timeZone)} (${startDate} - ${endDate})`;\n };\n\n const getFormattedQuarterYear = (date: Date) => {\n const formattedYear = getFormattedDate(date, 'year');\n const quarterNumber = getQuarterForDateTimeZone(date, timeZone);\n return `${t!(`date_quarter_q${quarterNumber}`, [formattedYear])}`;\n };\n\n switch (variant) {\n case 'relative':\n return getRelativeTime(value);\n case 'week':\n return getFormattedWeek(value);\n case 'quarteryear':\n return getFormattedQuarterYear(value);\n default:\n return getFormattedDate(value, variant);\n }\n}\n\nconst dayInMs = 24 * 60 * 60 * 1000;\nconst hourInMs = 60 * 60 * 1000;\nconst minuteInMs = 60 * 1000;\nconst secondInMs = 1000;\n\ninterface DurationFormatOptions {\n /** Locale to be used - en_US, jp_JP, fr_FR etc */\n locale: string;\n /** Determines maximum number of units to be displayed. */\n significantUnits: 5 | 4 | 3 | 2 | 1;\n /**\n * Unit formatting style\n * @default \"narrow\"\n */\n unitDisplay?: Intl.NumberFormatOptions['unitDisplay'];\n /**\n * Unit of maximum precision\n * @default \"second\"\n */\n maxPrecision?: 'day' | 'hour' | 'minute' | 'second' | 'millisecond';\n}\n\nconst numberFormatCache: Record<\n // locale\n string,\n Record<\n // unit\n string,\n Record<\n // unitDisplay\n string,\n Intl.NumberFormat\n >\n >\n> = {};\n\nexport function formatDuration(\n valueInMs: number,\n {\n locale,\n significantUnits,\n unitDisplay = 'narrow',\n maxPrecision = 'second'\n }: DurationFormatOptions\n) {\n numberFormatCache[locale] ??= {};\n\n const sign = valueInMs < 0 ? '-' : '';\n const absMs = Math.abs(valueInMs);\n\n const durationParts = [\n { unit: 'day', value: Math.floor(absMs / dayInMs) },\n { unit: 'hour', value: Math.floor((absMs % dayInMs) / hourInMs) },\n { unit: 'minute', value: Math.floor((absMs % hourInMs) / minuteInMs) },\n { unit: 'second', value: Math.floor((absMs % minuteInMs) / secondInMs) },\n { unit: 'millisecond', value: absMs % secondInMs }\n ];\n\n const result = [];\n for (let i = 0; result.length < significantUnits && i < durationParts.length; i += 1) {\n const { value, unit } = durationParts[i];\n\n if (value > 0 || (unit === maxPrecision && result.length === 0)) {\n numberFormatCache[locale][unit] ??= {};\n numberFormatCache[locale][unit][unitDisplay] ??= new Intl.NumberFormat(locale, {\n style: 'unit',\n unit,\n unitDisplay\n });\n\n result.push(numberFormatCache[locale][unit][unitDisplay].format(value));\n }\n if (durationParts[i].unit === maxPrecision) break;\n }\n return `${sign}${result.join(' ')}`;\n}\n\n/**\n * @returns Current date and time value adjusted for local time zone.\n */\nexport const getAdjustedUTCDateTime = (): Date => {\n const now = new Date();\n now.setTime(now.getTime() - now.getTimezoneOffset() * 60000);\n return now;\n};\n\n/**\n * @param timeZone - IANA timezone string (e.g. \"America/New_York\")\n * @returns Current date and time for the given timezone, with wall-clock time\n * encoded in UTC fields — matching the convention used by DateTime inputs.\n */\nexport const getAdjustedUTCDateTimeForTimezone = (timeZone: string): Date => {\n try {\n // eslint-disable-next-line no-new\n new Intl.DateTimeFormat('en-US', { timeZone });\n } catch {\n return getAdjustedUTCDateTime();\n }\n return new Date(`${dayjs().tz(timeZone).format('YYYY-MM-DDTHH:mm:ss.SSS')}Z`);\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormDialog.d.ts","sourceRoot":"","sources":["../../../src/components/Dialog/FormDialog.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"FormDialog.d.ts","sourceRoot":"","sources":["../../../src/components/Dialog/FormDialog.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAwB7C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtD,eAAO,MAAM,gBAAgB,gPAAmB,CAAC;AAEjD,QAAA,MAAM,UAAU,6HA0Kf,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useRef, useEffect, useLayoutEffect } from 'react';
|
|
3
3
|
import styled from 'styled-components';
|
|
4
|
-
import { useConsolidatedRef, useEscape, useI18n, useOuterEvent, useUID } from '../../hooks';
|
|
4
|
+
import { useConsolidatedRef, useContentTabIndex, useEscape, useI18n, useOuterEvent, useUID } from '../../hooks';
|
|
5
5
|
import { getActiveElement, getFocusables } from '../../utils';
|
|
6
6
|
import Button from '../Button';
|
|
7
7
|
import Text from '../Text';
|
|
@@ -16,6 +16,7 @@ const FormDialog = forwardRef(function FormDialog({ arrow = true, target, headin
|
|
|
16
16
|
const dialogRef = useConsolidatedRef(ref);
|
|
17
17
|
const dialogContentRef = useRef(null);
|
|
18
18
|
const cancelButtonRef = useRef(null);
|
|
19
|
+
const contentTabIndex = useContentTabIndex(dialogRef, dialogContentRef, [cancelButtonRef], [progress]);
|
|
19
20
|
const setFocus = () => {
|
|
20
21
|
if (progress)
|
|
21
22
|
return;
|
|
@@ -78,7 +79,7 @@ const FormDialog = forwardRef(function FormDialog({ arrow = true, target, headin
|
|
|
78
79
|
}, []);
|
|
79
80
|
return (_jsxs(StyledFormDialog, { ...restProps, ...(heading === undefined
|
|
80
81
|
? { 'aria-label': ariaLabel }
|
|
81
|
-
: { 'aria-labelledby': headingId }), arrow: arrow, target: target, progress: progress, ref: dialogRef, children: [heading !== undefined && (_jsx(Flex, { container: { alignItems: 'center', justify: 'between', pad: 2 }, item: { shrink: 0 }, as: StyledDialogHeader, children: _jsx(Text, { id: headingId, variant: 'h2', children: heading }) })), _jsxs(Flex, { item: { grow: 1 }, as: StyledDialogContent, ref: dialogContentRef, children: [children && (_jsx(StyledChildrenWrap, { inert: progress ? '' : undefined, children: children })), _jsx(Progress, { visible: !!progress, focusOnVisible: true, placement: 'local', message: typeof progress === 'string' ? progress : undefined })] }), _jsxs(Flex, { container: { alignItems: 'center', justify: 'between', pad: 2 }, item: { shrink: 0 }, as: StyledDialogFooter, children: [_jsx(Button, { onClick: () => {
|
|
82
|
+
: { 'aria-labelledby': headingId }), arrow: arrow, target: target, progress: progress, ref: dialogRef, children: [heading !== undefined && (_jsx(Flex, { container: { alignItems: 'center', justify: 'between', pad: 2 }, item: { shrink: 0 }, as: StyledDialogHeader, children: _jsx(Text, { id: headingId, variant: 'h2', children: heading }) })), _jsxs(Flex, { item: { grow: 1 }, as: StyledDialogContent, ref: dialogContentRef, tabIndex: contentTabIndex, children: [children && (_jsx(StyledChildrenWrap, { inert: progress ? '' : undefined, children: children })), _jsx(Progress, { visible: !!progress, focusOnVisible: true, placement: 'local', message: typeof progress === 'string' ? progress : undefined })] }), _jsxs(Flex, { container: { alignItems: 'center', justify: 'between', pad: 2 }, item: { shrink: 0 }, as: StyledDialogFooter, children: [_jsx(Button, { onClick: () => {
|
|
82
83
|
onCancelHandler();
|
|
83
84
|
}, disabled: typeof onCancel !== 'function' ? onCancel.disabled : undefined, ref: cancelButtonRef, children: typeof onCancel !== 'function' && onCancel.text ? onCancel.text : t('cancel') }), _jsx(Button, { variant: 'primary', onClick: () => {
|
|
84
85
|
(typeof onSubmit !== 'function' ? onSubmit.handler : onSubmit)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormDialog.js","sourceRoot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C,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,YAEvE,OAAO,QAAQ,KAAK,UAAU,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GACvE,IACJ,IACU,CACpB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import { forwardRef, useRef, useEffect, useLayoutEffect } from 'react';\nimport type { PropsWithoutRef } from 'react';\nimport styled from 'styled-components';\n\nimport { useConsolidatedRef, useEscape, useI18n, useOuterEvent, useUID } from '../../hooks';\nimport { getActiveElement, getFocusables } from '../../utils';\nimport Button from '../Button';\nimport Text from '../Text';\nimport Progress from '../Progress';\nimport type { RefElement } from '../../types';\nimport Flex from '../Flex';\n\nimport {\n StyledChildrenWrap,\n StyledDialogContent,\n StyledDialogFooter,\n StyledDialogHeader\n} from './Dialog.styles';\nimport type { FormDialogProps } from './Dialog.types';\nimport Dialog from './Dialog';\n\nexport const StyledFormDialog = styled(Dialog)``;\n\nconst FormDialog = forwardRef<RefElement<FormDialogProps>, PropsWithoutRef<FormDialogProps>>(\n function FormDialog(\n {\n arrow = true,\n target,\n heading,\n 'aria-label': ariaLabel,\n children,\n progress,\n onDismiss,\n onCancel,\n onSubmit,\n ...restProps\n },\n ref\n ) {\n const t = useI18n();\n const headingId = useUID();\n const dialogRef = useConsolidatedRef(ref);\n const dialogContentRef = useRef<HTMLDivElement>(null);\n const cancelButtonRef = useRef<HTMLButtonElement>(null);\n\n const setFocus = () => {\n if (progress) return;\n\n const focusables = getFocusables(dialogRef);\n\n const focusable =\n focusables.find(el => {\n return dialogContentRef.current?.contains(el);\n }) ??\n cancelButtonRef.current ??\n focusables[0];\n\n focusable?.focus();\n };\n\n const onCancelHandler = typeof onCancel === 'function' ? onCancel : onCancel.handler;\n\n useEscape(\n e => {\n if (onDismiss) {\n onDismiss();\n } else {\n onCancelHandler();\n }\n e.stopPropagation();\n },\n dialogRef,\n [onDismiss, onCancelHandler]\n );\n\n useOuterEvent('mousedown', [target, dialogRef], () => {\n if (onDismiss) {\n onDismiss();\n } else {\n onCancelHandler();\n }\n });\n\n // Using layout effect to capture the focused element prior to dialog elements taking focus.\n useLayoutEffect(() => {\n const initiatorElement = getActiveElement();\n\n return () => {\n if (initiatorElement instanceof HTMLElement && initiatorElement.isConnected) {\n initiatorElement.focus();\n }\n };\n }, []);\n\n useEffect(() => {\n if (!progress) {\n setFocus();\n }\n }, [progress]);\n\n useEffect(() => {\n const closeDialog = () => {\n setTimeout(() => {\n if (onDismiss) {\n onDismiss();\n } else {\n onCancelHandler();\n }\n // The 0 timeout ensures that the dialog will not re-open immediately after the close event is triggered.\n }, 0);\n };\n\n target.addEventListener('click', closeDialog);\n\n return () => {\n target.removeEventListener('click', closeDialog);\n };\n }, []);\n\n return (\n <StyledFormDialog\n {...restProps}\n {...(heading === undefined\n ? { 'aria-label': ariaLabel }\n : { 'aria-labelledby': headingId })}\n arrow={arrow}\n target={target}\n progress={progress}\n ref={dialogRef}\n >\n {heading !== undefined && (\n <Flex\n container={{ alignItems: 'center', justify: 'between', pad: 2 }}\n item={{ shrink: 0 }}\n as={StyledDialogHeader}\n >\n <Text id={headingId} variant='h2'>\n {heading}\n </Text>\n </Flex>\n )}\n\n <Flex item={{ grow: 1 }} as={StyledDialogContent} ref={dialogContentRef}>\n {children && (\n <StyledChildrenWrap inert={progress ? '' : undefined}>{children}</StyledChildrenWrap>\n )}\n <Progress\n visible={!!progress}\n focusOnVisible\n placement='local'\n message={typeof progress === 'string' ? progress : undefined}\n />\n </Flex>\n\n <Flex\n container={{ alignItems: 'center', justify: 'between', pad: 2 }}\n item={{ shrink: 0 }}\n as={StyledDialogFooter}\n >\n <Button\n onClick={() => {\n onCancelHandler();\n }}\n disabled={typeof onCancel !== 'function' ? onCancel.disabled : undefined}\n ref={cancelButtonRef}\n >\n {typeof onCancel !== 'function' && onCancel.text ? onCancel.text : t('cancel')}\n </Button>\n\n <Button\n variant='primary'\n onClick={() => {\n (typeof onSubmit !== 'function' ? onSubmit.handler : onSubmit)();\n }}\n disabled={typeof onSubmit !== 'function' ? onSubmit.disabled : undefined}\n >\n {typeof onSubmit !== 'function' && onSubmit.text ? onSubmit.text : t('submit')}\n </Button>\n </Flex>\n </StyledFormDialog>\n );\n }\n);\n\nexport default FormDialog;\n"]}
|
|
1
|
+
{"version":3,"file":"FormDialog.js","sourceRoot":"","sources":["../../../src/components/Dialog/FormDialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAEvE,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,SAAS,EACT,OAAO,EACP,aAAa,EACb,MAAM,EACP,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,QAAQ,MAAM,aAAa,CAAC;AAEnC,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,MAAM,MAAM,UAAU,CAAC;AAE9B,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA,EAAE,CAAC;AAEjD,MAAM,UAAU,GAAG,UAAU,CAC3B,SAAS,UAAU,CACjB,EACE,KAAK,GAAG,IAAI,EACZ,MAAM,EACN,OAAO,EACP,YAAY,EAAE,SAAS,EACvB,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,GAAG,SAAS,EACb,EACD,GAAG;IAEH,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CAAC,CAAC,SAAS,EACxE,GAAG,EAAE,eAAe,YAEnB,OAAO,QAAQ,KAAK,UAAU,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GACvE,EAET,KAAC,MAAM,IACL,OAAO,EAAC,SAAS,EACjB,OAAO,EAAE,GAAG,EAAE;4BACZ,CAAC,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC;wBACnE,CAAC,EACD,QAAQ,EAAE,OAAO,QAAQ,KAAK,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,YAEvE,OAAO,QAAQ,KAAK,UAAU,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,GACvE,IACJ,IACU,CACpB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import { forwardRef, useRef, useEffect, useLayoutEffect } from 'react';\nimport type { PropsWithoutRef } from 'react';\nimport styled from 'styled-components';\n\nimport {\n useConsolidatedRef,\n useContentTabIndex,\n useEscape,\n useI18n,\n useOuterEvent,\n useUID\n} from '../../hooks';\nimport { getActiveElement, getFocusables } from '../../utils';\nimport Button from '../Button';\nimport Text from '../Text';\nimport Progress from '../Progress';\nimport type { RefElement } from '../../types';\nimport Flex from '../Flex';\n\nimport {\n StyledChildrenWrap,\n StyledDialogContent,\n StyledDialogFooter,\n StyledDialogHeader\n} from './Dialog.styles';\nimport type { FormDialogProps } from './Dialog.types';\nimport Dialog from './Dialog';\n\nexport const StyledFormDialog = styled(Dialog)``;\n\nconst FormDialog = forwardRef<RefElement<FormDialogProps>, PropsWithoutRef<FormDialogProps>>(\n function FormDialog(\n {\n arrow = true,\n target,\n heading,\n 'aria-label': ariaLabel,\n children,\n progress,\n onDismiss,\n onCancel,\n onSubmit,\n ...restProps\n },\n ref\n ) {\n const t = useI18n();\n const headingId = useUID();\n const dialogRef = useConsolidatedRef(ref);\n const dialogContentRef = useRef<HTMLDivElement>(null);\n const cancelButtonRef = useRef<HTMLButtonElement>(null);\n const contentTabIndex = useContentTabIndex(\n dialogRef,\n dialogContentRef,\n [cancelButtonRef],\n [progress]\n );\n\n const setFocus = () => {\n if (progress) return;\n\n const focusables = getFocusables(dialogRef);\n\n const focusable =\n focusables.find(el => {\n return dialogContentRef.current?.contains(el);\n }) ??\n cancelButtonRef.current ??\n focusables[0];\n\n focusable?.focus();\n };\n\n const onCancelHandler = typeof onCancel === 'function' ? onCancel : onCancel.handler;\n\n useEscape(\n e => {\n if (onDismiss) {\n onDismiss();\n } else {\n onCancelHandler();\n }\n e.stopPropagation();\n },\n dialogRef,\n [onDismiss, onCancelHandler]\n );\n\n useOuterEvent('mousedown', [target, dialogRef], () => {\n if (onDismiss) {\n onDismiss();\n } else {\n onCancelHandler();\n }\n });\n\n // Using layout effect to capture the focused element prior to dialog elements taking focus.\n useLayoutEffect(() => {\n const initiatorElement = getActiveElement();\n\n return () => {\n if (initiatorElement instanceof HTMLElement && initiatorElement.isConnected) {\n initiatorElement.focus();\n }\n };\n }, []);\n\n useEffect(() => {\n if (!progress) {\n setFocus();\n }\n }, [progress]);\n\n useEffect(() => {\n const closeDialog = () => {\n setTimeout(() => {\n if (onDismiss) {\n onDismiss();\n } else {\n onCancelHandler();\n }\n // The 0 timeout ensures that the dialog will not re-open immediately after the close event is triggered.\n }, 0);\n };\n\n target.addEventListener('click', closeDialog);\n\n return () => {\n target.removeEventListener('click', closeDialog);\n };\n }, []);\n\n return (\n <StyledFormDialog\n {...restProps}\n {...(heading === undefined\n ? { 'aria-label': ariaLabel }\n : { 'aria-labelledby': headingId })}\n arrow={arrow}\n target={target}\n progress={progress}\n ref={dialogRef}\n >\n {heading !== undefined && (\n <Flex\n container={{ alignItems: 'center', justify: 'between', pad: 2 }}\n item={{ shrink: 0 }}\n as={StyledDialogHeader}\n >\n <Text id={headingId} variant='h2'>\n {heading}\n </Text>\n </Flex>\n )}\n\n <Flex\n item={{ grow: 1 }}\n as={StyledDialogContent}\n ref={dialogContentRef}\n tabIndex={contentTabIndex}\n >\n {children && (\n <StyledChildrenWrap inert={progress ? '' : undefined}>{children}</StyledChildrenWrap>\n )}\n <Progress\n visible={!!progress}\n focusOnVisible\n placement='local'\n message={typeof progress === 'string' ? progress : undefined}\n />\n </Flex>\n\n <Flex\n container={{ alignItems: 'center', justify: 'between', pad: 2 }}\n item={{ shrink: 0 }}\n as={StyledDialogFooter}\n >\n <Button\n onClick={() => {\n onCancelHandler();\n }}\n disabled={typeof onCancel !== 'function' ? onCancel.disabled : undefined}\n ref={cancelButtonRef}\n >\n {typeof onCancel !== 'function' && onCancel.text ? onCancel.text : t('cancel')}\n </Button>\n\n <Button\n variant='primary'\n onClick={() => {\n (typeof onSubmit !== 'function' ? onSubmit.handler : onSubmit)();\n }}\n disabled={typeof onSubmit !== 'function' ? onSubmit.disabled : undefined}\n >\n {typeof onSubmit !== 'function' && onSubmit.text ? onSubmit.text : t('submit')}\n </Button>\n </Flex>\n </StyledFormDialog>\n );\n }\n);\n\nexport default FormDialog;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InfoDialog.d.ts","sourceRoot":"","sources":["../../../src/components/Dialog/InfoDialog.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"InfoDialog.d.ts","sourceRoot":"","sources":["../../../src/components/Dialog/InfoDialog.tsx"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtD,QAAA,MAAM,UAAU,yHAgKf,CAAC;AAEF,eAAe,UAAU,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { forwardRef, useRef, useEffect, useLayoutEffect } from 'react';
|
|
3
|
-
import { useConsolidatedRef, useEscape, useI18n, useOuterEvent, useUID } from '../../hooks';
|
|
3
|
+
import { useConsolidatedRef, useContentTabIndex, useEscape, useI18n, useOuterEvent, useUID } from '../../hooks';
|
|
4
4
|
import Text from '../Text';
|
|
5
5
|
import Icon from '../Icon';
|
|
6
6
|
import Progress from '../Progress';
|
|
@@ -15,6 +15,7 @@ const InfoDialog = forwardRef(function InfoDialog({ target, heading: headingProp
|
|
|
15
15
|
const dialogRef = useConsolidatedRef(ref);
|
|
16
16
|
const dialogContentRef = useRef(null);
|
|
17
17
|
const closeButtonRef = useRef(null);
|
|
18
|
+
const contentTabIndex = useContentTabIndex(dialogRef, dialogContentRef, [closeButtonRef], [progressProp]);
|
|
18
19
|
const setFocus = () => {
|
|
19
20
|
if (progressProp)
|
|
20
21
|
return;
|
|
@@ -66,7 +67,7 @@ const InfoDialog = forwardRef(function InfoDialog({ target, heading: headingProp
|
|
|
66
67
|
}, label: t('close'), ref: closeButtonRef, children: _jsx(Icon, { name: 'times' }) }));
|
|
67
68
|
return (_jsxs(StyledInfoDialog, { ...restProps, ...(typeof headingProp === 'string'
|
|
68
69
|
? { 'aria-labelledby': headingId }
|
|
69
|
-
: { 'aria-label': headingProp?.primary }), arrow: true, target: target, progress: progressProp, ref: dialogRef, children: [headingProp && heading && (_jsxs(Flex, { container: { alignItems: 'center', justify: 'between', pad: 2, gap: 1 }, item: { shrink: 0 }, as: StyledDialogHeader, children: [typeof headingProp === 'string' ? (heading) : (_jsx(SummaryItem, { primary: heading, secondary: headingProp.secondary ? (_jsx(Text, { variant: 'secondary', children: headingProp.secondary })) : undefined, visual: headingProp.visual })), dismissButton] })), (!headingProp || children || progressProp) && (_jsxs(Flex, { container: { direction: 'column' }, item: { grow: 1 }, as: StyledDialogContent, ref: dialogContentRef, children: [!headingProp && dismissButton, children && (_jsx(StyledChildrenWrap, { inert: progressProp ? '' : undefined, children: children })), progress] }))] }));
|
|
70
|
+
: { 'aria-label': headingProp?.primary }), arrow: true, target: target, progress: progressProp, ref: dialogRef, children: [headingProp && heading && (_jsxs(Flex, { container: { alignItems: 'center', justify: 'between', pad: 2, gap: 1 }, item: { shrink: 0 }, as: StyledDialogHeader, children: [typeof headingProp === 'string' ? (heading) : (_jsx(SummaryItem, { primary: heading, secondary: headingProp.secondary ? (_jsx(Text, { variant: 'secondary', children: headingProp.secondary })) : undefined, visual: headingProp.visual })), dismissButton] })), (!headingProp || children || progressProp) && (_jsxs(Flex, { container: { direction: 'column' }, item: { grow: 1 }, as: StyledDialogContent, ref: dialogContentRef, tabIndex: contentTabIndex, children: [!headingProp && dismissButton, children && (_jsx(StyledChildrenWrap, { inert: progressProp ? '' : undefined, children: children })), progress] }))] }));
|
|
70
71
|
});
|
|
71
72
|
export default InfoDialog;
|
|
72
73
|
//# sourceMappingURL=InfoDialog.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InfoDialog.js","sourceRoot":"","sources":["../../../src/components/Dialog/InfoDialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAGvE,OAAO,
|
|
1
|
+
{"version":3,"file":"InfoDialog.js","sourceRoot":"","sources":["../../../src/components/Dialog/InfoDialog.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAGvE,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,SAAS,EACT,OAAO,EACP,aAAa,EACb,MAAM,EACP,MAAM,aAAa,CAAC;AACrB,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,QAAQ,MAAM,aAAa,CAAC;AACnC,OAAO,IAAI,MAAM,S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F,KAAC,WAAW,IACV,OAAO,EAAE,OAAO,EAChB,SAAS,EACP,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CACtB,KAAC,IAAI,IAAC,OAAO,EAAC,WAAW,YAAE,WAAW,CAAC,SAAS,GAAQ,CACzD,CAAC,CAAC,CAAC,SAAS,EAEf,MAAM,EAAE,WAAW,CAAC,MAAM,GAC1B,CACH,EACA,aAAa,IACT,CACR,EAEA,CAAC,CAAC,WAAW,IAAI,QAAQ,IAAI,YAAY,CAAC,IAAI,CAC7C,MAAC,IAAI,IACH,SAAS,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,EAClC,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,EACjB,EAAE,EAAE,mBAAmB,EACvB,GAAG,EAAE,gBAAgB,EACrB,QAAQ,EAAE,eAAe,aAExB,CAAC,WAAW,IAAI,aAAa,EAC7B,QAAQ,IAAI,CACX,KAAC,kBAAkB,IAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,YACrD,QAAQ,GACU,CACtB,EACA,QAAQ,IACJ,CACR,IACgB,CACpB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,UAAU,CAAC","sourcesContent":["import { forwardRef, useRef, useEffect, useLayoutEffect } from 'react';\nimport type { PropsWithoutRef } from 'react';\n\nimport {\n useConsolidatedRef,\n useContentTabIndex,\n useEscape,\n useI18n,\n useOuterEvent,\n useUID\n} from '../../hooks';\nimport Text from '../Text';\nimport Icon from '../Icon';\nimport Progress from '../Progress';\nimport Flex from '../Flex';\nimport SummaryItem from '../SummaryItem';\nimport { getActiveElement, getFocusables } from '../../utils';\nimport type { RefElement } from '../../types';\n\nimport { StyledChildrenWrap, StyledDialogContent, StyledDialogHeader } from './Dialog.styles';\nimport type { InfoDialogProps } from './Dialog.types';\nimport { StyledDismissButton, StyledInfoDialog } from './InfoDialog.styles';\n\nconst InfoDialog = forwardRef<RefElement<InfoDialogProps>, PropsWithoutRef<InfoDialogProps>>(\n function InfoDialog(\n { target, heading: headingProp, children, progress: progressProp, onDismiss, ...restProps },\n ref\n ) {\n const t = useI18n();\n const headingId = useUID();\n const dialogRef = useConsolidatedRef(ref);\n const dialogContentRef = useRef<HTMLDivElement>(null);\n const closeButtonRef = useRef<HTMLButtonElement>(null);\n const contentTabIndex = useContentTabIndex(\n dialogRef,\n dialogContentRef,\n [closeButtonRef],\n [progressProp]\n );\n\n const setFocus = () => {\n if (progressProp) return;\n\n const focusables = getFocusables(dialogRef);\n\n const focusable =\n focusables.find(el => {\n return dialogContentRef.current?.contains(el);\n }) ??\n closeButtonRef.current ??\n focusables[0];\n\n focusable?.focus();\n };\n\n useEscape(\n e => {\n onDismiss?.();\n e.stopPropagation();\n },\n dialogRef,\n [onDismiss]\n );\n\n useOuterEvent('mousedown', [target, dialogRef], () => {\n onDismiss?.();\n });\n\n // Using layout effect to capture the focused element prior to dialog elements taking focus.\n useLayoutEffect(() => {\n const initiatorElement = getActiveElement();\n\n return () => {\n if (initiatorElement instanceof HTMLElement && initiatorElement.isConnected) {\n initiatorElement.focus();\n }\n };\n }, []);\n\n useEffect(() => {\n if (!progressProp) {\n setFocus();\n }\n }, [progressProp]);\n\n useEffect(() => {\n const closeDialog = () => {\n setTimeout(() => {\n onDismiss?.();\n // The 0 timeout ensures that the dialog will not re-open immediately after the close event is triggered.\n }, 0);\n };\n\n target.addEventListener('click', closeDialog);\n\n return () => {\n target.removeEventListener('click', closeDialog);\n };\n }, []);\n\n const heading = headingProp ? (\n <Text id={headingId} variant='h2'>\n {typeof headingProp === 'string' ? headingProp : headingProp.primary}\n </Text>\n ) : null;\n\n const progress = (\n <Progress\n visible={!!progressProp}\n focusOnVisible\n placement='local'\n message={typeof progressProp === 'string' ? progressProp : undefined}\n />\n );\n\n const dismissButton = (\n <StyledDismissButton\n icon\n variant='simple'\n onClick={() => {\n onDismiss();\n }}\n label={t('close')}\n ref={closeButtonRef}\n >\n <Icon name='times' />\n </StyledDismissButton>\n );\n\n return (\n <StyledInfoDialog\n {...restProps}\n {...(typeof headingProp === 'string'\n ? { 'aria-labelledby': headingId }\n : { 'aria-label': headingProp?.primary })}\n arrow\n target={target}\n progress={progressProp}\n ref={dialogRef}\n >\n {headingProp && heading && (\n <Flex\n container={{ alignItems: 'center', justify: 'between', pad: 2, gap: 1 }}\n item={{ shrink: 0 }}\n as={StyledDialogHeader}\n >\n {typeof headingProp === 'string' ? (\n heading\n ) : (\n <SummaryItem\n primary={heading}\n secondary={\n headingProp.secondary ? (\n <Text variant='secondary'>{headingProp.secondary}</Text>\n ) : undefined\n }\n visual={headingProp.visual}\n />\n )}\n {dismissButton}\n </Flex>\n )}\n\n {(!headingProp || children || progressProp) && (\n <Flex\n container={{ direction: 'column' }}\n item={{ grow: 1 }}\n as={StyledDialogContent}\n ref={dialogContentRef}\n tabIndex={contentTabIndex}\n >\n {!headingProp && dismissButton}\n {children && (\n <StyledChildrenWrap inert={progressProp ? '' : undefined}>\n {children}\n </StyledChildrenWrap>\n )}\n {progress}\n </Flex>\n )}\n </StyledInfoDialog>\n );\n }\n);\n\nexport default InfoDialog;\n"]}
|
|
@@ -69,7 +69,7 @@ StyledFieldValueList.defaultProps = defaultThemeProp;
|
|
|
69
69
|
export const FieldValueItem = withTestIds(({ testId, name, value, variant = 'inline', truncate = true }) => {
|
|
70
70
|
const testIds = useTestIds(testId, getFieldValueItemTestIds);
|
|
71
71
|
const displayValue = typeof value === 'string' && truncate ? (_jsx(ShowMoreLess, { lines: 3, children: value })) : (value);
|
|
72
|
-
const labelAndValue = (_jsxs(_Fragment, { children: [_jsx(StyledLabel, { "data-testid": testIds.name, as: StyledFieldName,
|
|
72
|
+
const labelAndValue = (_jsxs(_Fragment, { children: [_jsx(StyledLabel, { "data-testid": testIds.name, as: StyledFieldName, children: name }), _jsx(StyledFieldValue, { "data-testid": testIds.value, children: value ? displayValue : _jsx(NoValue, {}) })] }));
|
|
73
73
|
return variant === 'stacked' ? (_jsx(StyledStackedFieldValue, { "data-testid": testIds.root, children: labelAndValue })) : (_jsx(_Fragment, { children: labelAndValue }));
|
|
74
74
|
}, getFieldValueItemTestIds);
|
|
75
75
|
const FieldValueList = forwardRef(function FieldValueList({ testId, fields, variant = 'inline', ...restProps }, ref) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldValueList.js","sourceRoot":"","sources":["../../../src/components/FieldValueList/FieldValueList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAShD,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,OAAO,MAAM,oBAAoB,CAAC;AAEzC,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AA8B/F,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,EAAE,CAAA;;CAEvC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,EAAE,CAAA;;CAExC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAA,EAAE,CAAC;AAIpD,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC,EAAE,CAA4B,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE;IAC9F,MAAM,EACJ,UAAU,EAAE,EACV,kBAAkB,EAAE,EAClB,MAAM,E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AAC,CAAC;YAC3D,MAAM,EAAE,CAAC,QAAQ,IAAI,OAAO,KAAK,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG;SAC9D,EACD,EAAE,EAAE,oBAAoB,EACxB,IAAI,EAAC,MAAM,EACX,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,YAErD,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE;YAC1E,MAAM,WAAW,GAA2B;gBAC1C,IAAI;gBACJ,OAAO,EACL,CAAC,YAAY,IAAI,OAAO,CAAC,KAAK,SAAS,IAAI,CAAC,uBAAuB;oBACjE,CAAC,CAAC,SAAS;oBACX,CAAC,CAAC,QAAQ;aACf,CAAC;YAEF,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC9B,OAAO,CACL,KAAC,cAAc,OAAsB,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,IAA7D,EAAE,IAAI,IAAI,CAAuD,CACvF,CAAC;YACJ,CAAC;YAED,OAAO,KAAC,cAAc,OAAsB,WAAW,EAAE,KAAK,EAAE,KAAK,IAAzC,EAAE,IAAI,IAAI,CAAmC,CAAC;QAC5E,CAAC,CAAC,GACG,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,WAAW,CAAC,cAAc,EAAE,wBAAwB,CAAC,CAAC","sourcesContent":["import { forwardRef } from 'react';\nimport type { ReactNode, FunctionComponent, Ref } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport type {\n BaseProps,\n ExcludeStrict,\n ForwardProps,\n NoChildrenProp,\n TestIdProp\n} from '../../types';\nimport Grid from '../Grid';\nimport { StyledLabel } from '../Label';\nimport { useBreakpoint, useConsolidatedRef, useTestIds, useTheme } from '../../hooks';\nimport { defaultThemeProp } from '../../theme';\nimport ShowMoreLess from '../ShowMoreLess';\nimport { withTestIds } from '../../utils';\nimport NoValue from '../NoValue/NoValue';\n\nimport { getFieldValueListTestIds, getFieldValueItemTestIds } from './FieldValueList.test-ids';\n\nexport type FieldValueVariant = 'inline' | 'stacked';\n\ninterface BaseFieldValueListItem extends TestIdProp {\n name: string;\n id?: string;\n variant?: FieldValueVariant;\n}\n\nexport type FieldValueListItemProps =\n | (BaseFieldValueListItem & {\n value?: ExcludeStrict<ReactNode, 'string'>;\n truncate?: never;\n })\n | (BaseFieldValueListItem & {\n value: string;\n truncate?: boolean;\n });\n\nexport interface FieldValueListProps extends BaseProps, NoChildrenProp, TestIdProp {\n /** The set of field values to render in the list. */\n fields: FieldValueListItemProps[];\n /**\n * Determines if the field and values should be displayed on the same line, or stacked with the field above the value.\n * @default 'inline'\n */\n variant?: FieldValueVariant | 'value-comparison';\n}\n\nexport const StyledFieldName = styled.dt`\n word-break: break-word;\n`;\n\nexport const StyledFieldValue = styled.dd`\n word-break: break-word;\n`;\n\nexport const StyledStackedFieldValue = styled.div``;\n\nexport type StyledFieldValueListProps = Pick<FieldValueListProps, 'variant'>;\n\nexport const StyledFieldValueList = styled.dl<StyledFieldValueListProps>(({ variant, theme }) => {\n const {\n components: {\n 'field-value-list': {\n inline: { detached }\n }\n }\n } = theme;\n return css`\n width: 100%;\n\n ${variant === 'value-comparison' &&\n css`\n dt {\n width: 100%;\n }\n && dd {\n text-align: end;\n padding-inline-start: calc(2 * ${theme.base.spacing});\n\n /* Unset negative margin from Details to prevent field value misalignment */\n margin: unset;\n }\n ${StyledLabel} {\n max-width: unset;\n }\n dd:not(:last-of-type),\n dt:not(:last-of-type) {\n border-bottom: 0.0625rem solid ${theme.base.palette['border-line']};\n padding-bottom: calc(0.5 * ${theme.base.spacing});\n }\n `}\n\n ${detached &&\n variant === 'inline' &&\n css`\n dt {\n width: 100%;\n padding-inline-end: calc(${theme.base.spacing});\n }\n ${StyledLabel} {\n max-width: unset;\n }\n dd:not(:last-of-type),\n dt:not(:last-of-type),\n dd:has(+ ${StyledStackedFieldValue}),\n dt:has(+ dd + ${StyledStackedFieldValue}),\n ${StyledStackedFieldValue}:has(+ dt + dd),\n ${StyledStackedFieldValue}:not(:last-of-type) {\n border-bottom: 0.0625rem dashed ${theme.base.palette['border-line']};\n padding-bottom: calc(0.5 * ${theme.base.spacing});\n }\n `}\n `;\n});\n\nStyledFieldValueList.defaultProps = defaultThemeProp;\n\nexport const FieldValueItem = withTestIds(\n ({ testId, name, value, variant = 'inline', truncate = true }: FieldValueListItemProps) => {\n const testIds = useTestIds(testId, getFieldValueItemTestIds);\n\n const displayValue =\n typeof value === 'string' && truncate ? (\n <ShowMoreLess lines={3}>{value}</ShowMoreLess>\n ) : (\n value\n );\n\n const labelAndValue = (\n <>\n <StyledLabel data-testid={testIds.name} as={StyledFieldName} role='none'>\n {name}\n </StyledLabel>\n <StyledFieldValue data-testid={testIds.value} role='none'>\n {value ? displayValue : <NoValue />}\n </StyledFieldValue>\n </>\n );\n\n return variant === 'stacked' ? (\n <StyledStackedFieldValue data-testid={testIds.root}>{labelAndValue}</StyledStackedFieldValue>\n ) : (\n <>{labelAndValue}</>\n );\n },\n getFieldValueItemTestIds\n);\n\nconst FieldValueList: FunctionComponent<FieldValueListProps & ForwardProps> = forwardRef(\n function FieldValueList(\n { testId, fields, variant = 'inline', ...restProps }: FieldValueListProps,\n ref: Ref<HTMLDivElement>\n ) {\n const testIds = useTestIds(testId, getFieldValueListTestIds);\n\n const fieldValueListRef = useConsolidatedRef<HTMLDivElement>(ref);\n\n const isXSContentWidthOrAbove = useBreakpoint('xs', {\n breakpointRef: fieldValueListRef,\n themeProp: 'content-width'\n });\n\n const {\n components: {\n 'field-value-list': {\n inline: { detached }\n }\n }\n } = useTheme();\n\n return (\n <Grid\n data-testid={testIds.root}\n {...restProps}\n ref={fieldValueListRef}\n container={{\n cols:\n ['inline', 'value-comparison'].includes(variant) && isXSContentWidthOrAbove\n ? '16ch minmax(0, 1fr)'\n : 'minmax(0, 1fr)',\n colGap: !detached && variant !== 'value-comparison' ? 2 : 0,\n rowGap: !detached && variant !== 'value-comparison' ? 1 : 0.5\n }}\n as={StyledFieldValueList}\n role='none'\n variant={isXSContentWidthOrAbove ? variant : 'stacked'}\n >\n {fields.map(({ id, name, value, truncate = true, variant: fieldVariant }) => {\n const sharedProps: BaseFieldValueListItem = {\n name,\n variant:\n (fieldVariant ?? variant) === 'stacked' || !isXSContentWidthOrAbove\n ? 'stacked'\n : 'inline'\n };\n\n if (typeof value === 'string') {\n return (\n <FieldValueItem key={id ?? name} {...sharedProps} value={value} truncate={truncate} />\n );\n }\n\n return <FieldValueItem key={id ?? name} {...sharedProps} value={value} />;\n })}\n </Grid>\n );\n }\n);\n\nexport default withTestIds(FieldValueList, getFieldValueListTestIds);\n"]}
|
|
1
|
+
{"version":3,"file":"FieldValueList.js","sourceRoot":"","sources":["../../../src/components/FieldValueList/FieldValueList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,OAAO,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAShD,OAAO,IAAI,MAAM,SAAS,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,YAAY,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,OAAO,MAAM,oBAAoB,CAAC;AAEzC,OAAO,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AA8B/F,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,EAAE,CAAA;;CAEvC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CAAC,cAAc,EAAE,wBAAwB,CAAC,CAAC","sourcesContent":["import { forwardRef } from 'react';\nimport type { ReactNode, FunctionComponent, Ref } from 'react';\nimport styled, { css } from 'styled-components';\n\nimport type {\n BaseProps,\n ExcludeStrict,\n ForwardProps,\n NoChildrenProp,\n TestIdProp\n} from '../../types';\nimport Grid from '../Grid';\nimport { StyledLabel } from '../Label';\nimport { useBreakpoint, useConsolidatedRef, useTestIds, useTheme } from '../../hooks';\nimport { defaultThemeProp } from '../../theme';\nimport ShowMoreLess from '../ShowMoreLess';\nimport { withTestIds } from '../../utils';\nimport NoValue from '../NoValue/NoValue';\n\nimport { getFieldValueListTestIds, getFieldValueItemTestIds } from './FieldValueList.test-ids';\n\nexport type FieldValueVariant = 'inline' | 'stacked';\n\ninterface BaseFieldValueListItem extends TestIdProp {\n name: string;\n id?: string;\n variant?: FieldValueVariant;\n}\n\nexport type FieldValueListItemProps =\n | (BaseFieldValueListItem & {\n value?: ExcludeStrict<ReactNode, 'string'>;\n truncate?: never;\n })\n | (BaseFieldValueListItem & {\n value: string;\n truncate?: boolean;\n });\n\nexport interface FieldValueListProps extends BaseProps, NoChildrenProp, TestIdProp {\n /** The set of field values to render in the list. */\n fields: FieldValueListItemProps[];\n /**\n * Determines if the field and values should be displayed on the same line, or stacked with the field above the value.\n * @default 'inline'\n */\n variant?: FieldValueVariant | 'value-comparison';\n}\n\nexport const StyledFieldName = styled.dt`\n word-break: break-word;\n`;\n\nexport const StyledFieldValue = styled.dd`\n word-break: break-word;\n`;\n\nexport const StyledStackedFieldValue = styled.div``;\n\nexport type StyledFieldValueListProps = Pick<FieldValueListProps, 'variant'>;\n\nexport const StyledFieldValueList = styled.dl<StyledFieldValueListProps>(({ variant, theme }) => {\n const {\n components: {\n 'field-value-list': {\n inline: { detached }\n }\n }\n } = theme;\n return css`\n width: 100%;\n\n ${variant === 'value-comparison' &&\n css`\n dt {\n width: 100%;\n }\n && dd {\n text-align: end;\n padding-inline-start: calc(2 * ${theme.base.spacing});\n\n /* Unset negative margin from Details to prevent field value misalignment */\n margin: unset;\n }\n ${StyledLabel} {\n max-width: unset;\n }\n dd:not(:last-of-type),\n dt:not(:last-of-type) {\n border-bottom: 0.0625rem solid ${theme.base.palette['border-line']};\n padding-bottom: calc(0.5 * ${theme.base.spacing});\n }\n `}\n\n ${detached &&\n variant === 'inline' &&\n css`\n dt {\n width: 100%;\n padding-inline-end: calc(${theme.base.spacing});\n }\n ${StyledLabel} {\n max-width: unset;\n }\n dd:not(:last-of-type),\n dt:not(:last-of-type),\n dd:has(+ ${StyledStackedFieldValue}),\n dt:has(+ dd + ${StyledStackedFieldValue}),\n ${StyledStackedFieldValue}:has(+ dt + dd),\n ${StyledStackedFieldValue}:not(:last-of-type) {\n border-bottom: 0.0625rem dashed ${theme.base.palette['border-line']};\n padding-bottom: calc(0.5 * ${theme.base.spacing});\n }\n `}\n `;\n});\n\nStyledFieldValueList.defaultProps = defaultThemeProp;\n\nexport const FieldValueItem = withTestIds(\n ({ testId, name, value, variant = 'inline', truncate = true }: FieldValueListItemProps) => {\n const testIds = useTestIds(testId, getFieldValueItemTestIds);\n\n const displayValue =\n typeof value === 'string' && truncate ? (\n <ShowMoreLess lines={3}>{value}</ShowMoreLess>\n ) : (\n value\n );\n\n const labelAndValue = (\n <>\n <StyledLabel data-testid={testIds.name} as={StyledFieldName}>\n {name}\n </StyledLabel>\n <StyledFieldValue data-testid={testIds.value}>\n {value ? displayValue : <NoValue />}\n </StyledFieldValue>\n </>\n );\n\n return variant === 'stacked' ? (\n <StyledStackedFieldValue data-testid={testIds.root}>{labelAndValue}</StyledStackedFieldValue>\n ) : (\n <>{labelAndValue}</>\n );\n },\n getFieldValueItemTestIds\n);\n\nconst FieldValueList: FunctionComponent<FieldValueListProps & ForwardProps> = forwardRef(\n function FieldValueList(\n { testId, fields, variant = 'inline', ...restProps }: FieldValueListProps,\n ref: Ref<HTMLDivElement>\n ) {\n const testIds = useTestIds(testId, getFieldValueListTestIds);\n\n const fieldValueListRef = useConsolidatedRef<HTMLDivElement>(ref);\n\n const isXSContentWidthOrAbove = useBreakpoint('xs', {\n breakpointRef: fieldValueListRef,\n themeProp: 'content-width'\n });\n\n const {\n components: {\n 'field-value-list': {\n inline: { detached }\n }\n }\n } = useTheme();\n\n return (\n <Grid\n data-testid={testIds.root}\n {...restProps}\n ref={fieldValueListRef}\n container={{\n cols:\n ['inline', 'value-comparison'].includes(variant) && isXSContentWidthOrAbove\n ? '16ch minmax(0, 1fr)'\n : 'minmax(0, 1fr)',\n colGap: !detached && variant !== 'value-comparison' ? 2 : 0,\n rowGap: !detached && variant !== 'value-comparison' ? 1 : 0.5\n }}\n as={StyledFieldValueList}\n role='none'\n variant={isXSContentWidthOrAbove ? variant : 'stacked'}\n >\n {fields.map(({ id, name, value, truncate = true, variant: fieldVariant }) => {\n const sharedProps: BaseFieldValueListItem = {\n name,\n variant:\n (fieldVariant ?? variant) === 'stacked' || !isXSContentWidthOrAbove\n ? 'stacked'\n : 'inline'\n };\n\n if (typeof value === 'string') {\n return (\n <FieldValueItem key={id ?? name} {...sharedProps} value={value} truncate={truncate} />\n );\n }\n\n return <FieldValueItem key={id ?? name} {...sharedProps} value={value} />;\n })}\n </Grid>\n );\n }\n);\n\nexport default withTestIds(FieldValueList, getFieldValueListTestIds);\n"]}
|
|
@@ -67,6 +67,8 @@ export interface FormFieldProps extends OmitStrict<FormControlProps, 'placeholde
|
|
|
67
67
|
'aria-describedby'?: string;
|
|
68
68
|
/** Callback invoked when the clear button is clicked. If provided will render the clear button. */
|
|
69
69
|
onClear?: () => void;
|
|
70
|
+
/** Suppresses announcements for status changes. */
|
|
71
|
+
suppressAnnouncements?: boolean;
|
|
70
72
|
}
|
|
71
73
|
export declare const StyledFormFieldInfo: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, Pick<FormControlProps, "status">, never>;
|
|
72
74
|
export declare const StyledLabelRow: import("styled-components").StyledComponent<"div", import("styled-components").DefaultTheme, {}, never>;
|
|
@@ -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E,UAAU,CAAC,SAAS,CAAC,CAAC;IACjC;;;OAGG;IACH,OAAO,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IAC3B;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,EAAE,CAAC,EAAE,KAAK,GAAG,UAAU,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;IAC7C;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,gDAAgD;IAChD,SAAS,CAAC,EAAE,aAAa,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC,CAAC;IACxD,kEAAkE;IAClE,gBAAgB,CAAC,EAAE,SAAS,CAAC;IAC7B,2CAA2C;IAC3C,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,mGAAmG;IACnG,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,mDAAmD;IACnD,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC;AAgCD,eAAO,MAAM,mBAAmB,uIA6B/B,CAAC;AAIF,eAAO,MAAM,cAAc,yGAAe,CAAC;AAE3C,eAAO,MAAM,eAAe;mBACQ,OAAO;wBAAsB,OAAO;SAoFtE,CAAC;;;;AA4TH,wBAA2D"}
|
|
@@ -166,7 +166,7 @@ StyledSuggestionButton.defaultProps = defaultThemeProp;
|
|
|
166
166
|
const statusIconMap = { error: 'warn-solid', warning: 'diamond-minus', success: 'check' };
|
|
167
167
|
const FormField = forwardRef(function FormField(props, ref) {
|
|
168
168
|
const uid = useUID();
|
|
169
|
-
const { testId, children: controlElement, id = uid, as = 'div', label, labelAs = 'label', labelFor = id, labelId, labelHidden = false, labelAfter = false, info, status, isRadioCheck, charLimitDisplay, required = false, disabled = false, readOnly = false, inline = false, onClear, actions, container, additionalInfo, onResolveSuggestion, 'aria-describedby': ariaDescribedBy, className, ...restProps } = props;
|
|
169
|
+
const { testId, children: controlElement, id = uid, as = 'div', label, labelAs = 'label', labelFor = id, labelId, labelHidden = false, labelAfter = false, info, status, suppressAnnouncements, isRadioCheck, charLimitDisplay, required = false, disabled = false, readOnly = false, inline = false, onClear, actions, container, additionalInfo, onResolveSuggestion, 'aria-describedby': ariaDescribedBy, className, ...restProps } = props;
|
|
170
170
|
const testIds = useTestIds(testId, getFormFieldTestIds);
|
|
171
171
|
const t = useI18n();
|
|
172
172
|
const { announceAssertive } = useLiveLog();
|
|
@@ -185,12 +185,14 @@ const FormField = forwardRef(function FormField(props, ref) {
|
|
|
185
185
|
setLabelText(labelRef.current?.textContent ?? null);
|
|
186
186
|
}, [label]);
|
|
187
187
|
useEffect(() => {
|
|
188
|
-
if (status
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
188
|
+
if (suppressAnnouncements || (status !== 'error' && status !== 'warning'))
|
|
189
|
+
return;
|
|
190
|
+
let message = t(status);
|
|
191
|
+
if (typeof info === 'string')
|
|
192
|
+
message = `${message} ${info}`;
|
|
193
|
+
if (labelRef.current?.textContent)
|
|
194
|
+
message = `${labelRef.current?.textContent} ${message}`;
|
|
195
|
+
announceAssertive({ message, type: status });
|
|
194
196
|
}, [status, info]);
|
|
195
197
|
// fieldset or single form control element
|
|
196
198
|
let content;
|