@terreno/ui 57.8.0 → 57.10.1
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/README.md +2 -0
- package/dist/AreaChart.d.ts +1 -1
- package/dist/AreaChart.d.ts.map +1 -1
- package/dist/AreaChart.js +70 -22
- package/dist/AreaChart.js.map +1 -1
- package/dist/BarChart.d.ts.map +1 -1
- package/dist/BarChart.js +55 -13
- package/dist/BarChart.js.map +1 -1
- package/dist/Button.d.ts.map +1 -1
- package/dist/Button.js +19 -4
- package/dist/Button.js.map +1 -1
- package/dist/ChartCard.d.ts +5 -0
- package/dist/ChartCard.d.ts.map +1 -0
- package/dist/ChartCard.js +18 -0
- package/dist/ChartCard.js.map +1 -0
- package/dist/Common.d.ts +147 -6
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/DashboardGrid.d.ts +6 -2
- package/dist/DashboardGrid.d.ts.map +1 -1
- package/dist/DashboardGrid.js +43 -10
- package/dist/DashboardGrid.js.map +1 -1
- package/dist/DateTimeField.d.ts.map +1 -1
- package/dist/DateTimeField.js +90 -17
- package/dist/DateTimeField.js.map +1 -1
- package/dist/DonutChart.d.ts.map +1 -1
- package/dist/DonutChart.js +20 -10
- package/dist/DonutChart.js.map +1 -1
- package/dist/DropdownMenuItem.d.ts +16 -0
- package/dist/DropdownMenuItem.d.ts.map +1 -0
- package/dist/DropdownMenuItem.js +11 -0
- package/dist/DropdownMenuItem.js.map +1 -0
- package/dist/FilePickerButton.d.ts +15 -1
- package/dist/FilePickerButton.d.ts.map +1 -1
- package/dist/FilePickerButton.js +90 -13
- package/dist/FilePickerButton.js.map +1 -1
- package/dist/GPTChat.d.ts +57 -1
- package/dist/GPTChat.d.ts.map +1 -1
- package/dist/GPTChat.js +301 -20
- package/dist/GPTChat.js.map +1 -1
- package/dist/HtmlFrame.d.ts +11 -0
- package/dist/HtmlFrame.d.ts.map +1 -0
- package/dist/HtmlFrame.js +29 -0
- package/dist/HtmlFrame.js.map +1 -0
- package/dist/LineChart.d.ts +1 -1
- package/dist/LineChart.d.ts.map +1 -1
- package/dist/LineChart.js +62 -21
- package/dist/LineChart.js.map +1 -1
- package/dist/Scorecard.d.ts +5 -0
- package/dist/Scorecard.d.ts.map +1 -0
- package/dist/Scorecard.js +11 -0
- package/dist/Scorecard.js.map +1 -0
- package/dist/SparklineChart.d.ts +5 -0
- package/dist/SparklineChart.d.ts.map +1 -0
- package/dist/SparklineChart.js +35 -0
- package/dist/SparklineChart.js.map +1 -0
- package/dist/Text.d.ts +1 -1
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +2 -2
- package/dist/Text.js.map +1 -1
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TextField.js +12 -4
- package/dist/TextField.js.map +1 -1
- package/dist/ToastNotifications.d.ts.map +1 -1
- package/dist/ToastNotifications.js +29 -6
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/WebDropdownMenu.d.ts +2 -1
- package/dist/WebDropdownMenu.d.ts.map +1 -1
- package/dist/WebDropdownMenu.js +2 -6
- package/dist/WebDropdownMenu.js.map +1 -1
- package/dist/asks/AskCard.d.ts +34 -0
- package/dist/asks/AskCard.d.ts.map +1 -0
- package/dist/asks/AskCard.js +91 -0
- package/dist/asks/AskCard.js.map +1 -0
- package/dist/asks/AskChoice.d.ts +11 -0
- package/dist/asks/AskChoice.d.ts.map +1 -0
- package/dist/asks/AskChoice.js +146 -0
- package/dist/asks/AskChoice.js.map +1 -0
- package/dist/asks/AskConfirm.d.ts +15 -0
- package/dist/asks/AskConfirm.d.ts.map +1 -0
- package/dist/asks/AskConfirm.js +17 -0
- package/dist/asks/AskConfirm.js.map +1 -0
- package/dist/asks/AskFiles.d.ts +18 -0
- package/dist/asks/AskFiles.d.ts.map +1 -0
- package/dist/asks/AskFiles.js +149 -0
- package/dist/asks/AskFiles.js.map +1 -0
- package/dist/asks/AskForm.d.ts +27 -0
- package/dist/asks/AskForm.d.ts.map +1 -0
- package/dist/asks/AskForm.js +146 -0
- package/dist/asks/AskForm.js.map +1 -0
- package/dist/asks/AskMarkdown.d.ts +25 -0
- package/dist/asks/AskMarkdown.d.ts.map +1 -0
- package/dist/asks/AskMarkdown.js +73 -0
- package/dist/asks/AskMarkdown.js.map +1 -0
- package/dist/asks/SimpleAskCard.d.ts +23 -0
- package/dist/asks/SimpleAskCard.d.ts.map +1 -0
- package/dist/asks/SimpleAskCard.js +32 -0
- package/dist/asks/SimpleAskCard.js.map +1 -0
- package/dist/asks/askControls.d.ts +33 -0
- package/dist/asks/askControls.d.ts.map +1 -0
- package/dist/asks/askControls.js +30 -0
- package/dist/asks/askControls.js.map +1 -0
- package/dist/asks/askFileRefs.d.ts +26 -0
- package/dist/asks/askFileRefs.d.ts.map +1 -0
- package/dist/asks/askFileRefs.js +75 -0
- package/dist/asks/askFileRefs.js.map +1 -0
- package/dist/asks/askFormDraft.d.ts +60 -0
- package/dist/asks/askFormDraft.d.ts.map +1 -0
- package/dist/asks/askFormDraft.js +224 -0
- package/dist/asks/askFormDraft.js.map +1 -0
- package/dist/asks/askSummary.d.ts +10 -0
- package/dist/asks/askSummary.d.ts.map +1 -0
- package/dist/asks/askSummary.js +138 -0
- package/dist/asks/askSummary.js.map +1 -0
- package/dist/asks/askTypes.d.ts +21 -0
- package/dist/asks/askTypes.d.ts.map +1 -0
- package/dist/asks/askTypes.js +2 -0
- package/dist/asks/askTypes.js.map +1 -0
- package/dist/asks/simpleCardButtonVariants.d.ts +5 -0
- package/dist/asks/simpleCardButtonVariants.d.ts.map +1 -0
- package/dist/asks/simpleCardButtonVariants.js +8 -0
- package/dist/asks/simpleCardButtonVariants.js.map +1 -0
- package/dist/blocks/BlocksError.d.ts +8 -0
- package/dist/blocks/BlocksError.d.ts.map +1 -0
- package/dist/blocks/BlocksError.js +14 -0
- package/dist/blocks/BlocksError.js.map +1 -0
- package/dist/blocks/BlocksView.d.ts +10 -0
- package/dist/blocks/BlocksView.d.ts.map +1 -0
- package/dist/blocks/BlocksView.js +90 -0
- package/dist/blocks/BlocksView.js.map +1 -0
- package/dist/blocks/blockRenderers.d.ts +25 -0
- package/dist/blocks/blockRenderers.d.ts.map +1 -0
- package/dist/blocks/blockRenderers.js +136 -0
- package/dist/blocks/blockRenderers.js.map +1 -0
- package/dist/blocks/datasetToPoints.d.ts +22 -0
- package/dist/blocks/datasetToPoints.d.ts.map +1 -0
- package/dist/blocks/datasetToPoints.js +28 -0
- package/dist/blocks/datasetToPoints.js.map +1 -0
- package/dist/blocks/useBlockSelections.d.ts +6 -0
- package/dist/blocks/useBlockSelections.d.ts.map +1 -0
- package/dist/blocks/useBlockSelections.js +10 -0
- package/dist/blocks/useBlockSelections.js.map +1 -0
- package/dist/blocks/useResolvedDatasets.d.ts +18 -0
- package/dist/blocks/useResolvedDatasets.d.ts.map +1 -0
- package/dist/blocks/useResolvedDatasets.js +59 -0
- package/dist/blocks/useResolvedDatasets.js.map +1 -0
- package/dist/blocks/useResolvedImages.d.ts +15 -0
- package/dist/blocks/useResolvedImages.d.ts.map +1 -0
- package/dist/blocks/useResolvedImages.js +66 -0
- package/dist/blocks/useResolvedImages.js.map +1 -0
- package/dist/charts/ChartFacadeContainer.d.ts +10 -0
- package/dist/charts/ChartFacadeContainer.d.ts.map +1 -0
- package/dist/charts/ChartFacadeContainer.js +10 -0
- package/dist/charts/ChartFacadeContainer.js.map +1 -0
- package/dist/charts/ChartFrame.d.ts +4 -0
- package/dist/charts/ChartFrame.d.ts.map +1 -1
- package/dist/charts/ChartFrame.js +4 -2
- package/dist/charts/ChartFrame.js.map +1 -1
- package/dist/charts/layout.d.ts +9 -2
- package/dist/charts/layout.d.ts.map +1 -1
- package/dist/charts/layout.js +28 -6
- package/dist/charts/layout.js.map +1 -1
- package/dist/charts/scales.d.ts +3 -1
- package/dist/charts/scales.d.ts.map +1 -1
- package/dist/charts/scales.js +7 -7
- package/dist/charts/scales.js.map +1 -1
- package/dist/charts/series.d.ts +15 -0
- package/dist/charts/series.d.ts.map +1 -0
- package/dist/charts/series.js +19 -0
- package/dist/charts/series.js.map +1 -0
- package/dist/charts/types/chartTypes.d.ts +7 -0
- package/dist/charts/types/chartTypes.d.ts.map +1 -1
- package/dist/dashboardGridLayout.d.ts +6 -0
- package/dist/dashboardGridLayout.d.ts.map +1 -1
- package/dist/dashboardGridLayout.js +19 -3
- package/dist/dashboardGridLayout.js.map +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +15 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.js +10 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
- package/dist/resolveDocumentBodyPortalTarget.d.ts +7 -0
- package/dist/resolveDocumentBodyPortalTarget.d.ts.map +1 -0
- package/dist/resolveDocumentBodyPortalTarget.js +12 -0
- package/dist/resolveDocumentBodyPortalTarget.js.map +1 -0
- package/package.json +2 -1
- package/src/AIRequestExplorer.test.tsx +2 -2
- package/src/AreaChart.test.tsx +81 -0
- package/src/AreaChart.tsx +171 -62
- package/src/BarChart.test.tsx +119 -0
- package/src/BarChart.tsx +94 -20
- package/src/Button.test.tsx +72 -0
- package/src/Button.tsx +34 -4
- package/src/ChartCard.test.tsx +79 -0
- package/src/ChartCard.tsx +80 -0
- package/src/Common.ts +136 -2
- package/src/DashboardGrid.test.tsx +98 -1
- package/src/DashboardGrid.tsx +71 -20
- package/src/DateTimeField.test.tsx +185 -2
- package/src/DateTimeField.tsx +106 -16
- package/src/DonutChart.test.tsx +78 -10
- package/src/DonutChart.tsx +87 -14
- package/src/DropdownMenuItem.tsx +48 -0
- package/src/FilePickerButton.test.tsx +116 -9
- package/src/FilePickerButton.tsx +177 -23
- package/src/GPTChat.test.tsx +891 -8
- package/src/GPTChat.tsx +713 -45
- package/src/HtmlFrame.tsx +60 -0
- package/src/LineChart.test.tsx +109 -10
- package/src/LineChart.tsx +154 -58
- package/src/Scorecard.test.tsx +65 -0
- package/src/Scorecard.tsx +45 -0
- package/src/SparklineChart.test.tsx +69 -0
- package/src/SparklineChart.tsx +85 -0
- package/src/Text.test.tsx +22 -0
- package/src/Text.tsx +10 -1
- package/src/TextField.test.tsx +16 -0
- package/src/TextField.tsx +13 -3
- package/src/ToastNotifications.tsx +33 -6
- package/src/ToastNotifications.webModal.test.tsx +285 -0
- package/src/WebDropdownMenu.tsx +3 -7
- package/src/asks/AskCard.test.tsx +1428 -0
- package/src/asks/AskCard.tsx +240 -0
- package/src/asks/AskChoice.tsx +368 -0
- package/src/asks/AskConfirm.tsx +42 -0
- package/src/asks/AskFiles.test.tsx +347 -0
- package/src/asks/AskFiles.tsx +246 -0
- package/src/asks/AskForm.tsx +334 -0
- package/src/asks/AskMarkdown.tsx +176 -0
- package/src/asks/SimpleAskCard.test.tsx +253 -0
- package/src/asks/SimpleAskCard.tsx +82 -0
- package/src/asks/askControls.tsx +98 -0
- package/src/asks/askFileRefs.test.ts +155 -0
- package/src/asks/askFileRefs.ts +98 -0
- package/src/asks/askFormDraft.test.ts +347 -0
- package/src/asks/askFormDraft.ts +309 -0
- package/src/asks/askSummary.test.ts +255 -0
- package/src/asks/askSummary.ts +160 -0
- package/src/asks/askTypes.ts +25 -0
- package/src/asks/asksUseTerrenoComponents.test.ts +55 -0
- package/src/asks/simpleCardButtonVariants.ts +14 -0
- package/src/blocks/BlocksError.tsx +28 -0
- package/src/blocks/BlocksView.test.tsx +607 -0
- package/src/blocks/BlocksView.tsx +125 -0
- package/src/blocks/blockRenderers.tsx +288 -0
- package/src/blocks/datasetToPoints.test.ts +31 -0
- package/src/blocks/datasetToPoints.ts +48 -0
- package/src/blocks/useBlockSelections.ts +13 -0
- package/src/blocks/useResolvedDatasets.ts +78 -0
- package/src/blocks/useResolvedImages.ts +81 -0
- package/src/bunSetup.ts +1 -0
- package/src/charts/ChartFacadeContainer.tsx +35 -0
- package/src/charts/ChartFrame.tsx +39 -1
- package/src/charts/layout.test.ts +22 -1
- package/src/charts/layout.ts +37 -4
- package/src/charts/scales.test.ts +33 -0
- package/src/charts/scales.ts +10 -6
- package/src/charts/series.ts +43 -0
- package/src/charts/types/chartTypes.ts +8 -0
- package/src/dashboardGridLayout.test.ts +59 -1
- package/src/dashboardGridLayout.ts +30 -3
- package/src/index.tsx +13 -0
- package/src/isolated/HtmlFrame.isolated.tsx +54 -0
- package/src/lazyBoundaries/heavyOptionalExports.test.tsx +2 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +35 -0
- package/src/resolveDocumentBodyPortalTarget.ts +11 -0
package/src/Common.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import type {Block, BlockAction, BlocksDocument, InlineDataset} from "@terreno/blocks";
|
|
1
2
|
import type {CountryCode} from "libphonenumber-js";
|
|
2
3
|
import type React from "react";
|
|
3
4
|
import type {FC, ReactElement, ReactNode} from "react";
|
|
4
5
|
import type {
|
|
5
6
|
ImageStyle,
|
|
6
7
|
ListRenderItemInfo,
|
|
8
|
+
Text as NativeText,
|
|
7
9
|
ScrollView,
|
|
8
10
|
StyleProp,
|
|
9
11
|
TextInput,
|
|
@@ -19,6 +21,7 @@ import type {
|
|
|
19
21
|
FontAwesome6RegularNames,
|
|
20
22
|
FontAwesome6SolidNames,
|
|
21
23
|
} from "./CommonIconTypes";
|
|
24
|
+
import type {ChartPoint, ChartSeries} from "./charts/types/chartTypes";
|
|
22
25
|
import type {DropdownPanelAlign} from "./dropdownPanelLayout";
|
|
23
26
|
import type {
|
|
24
27
|
DataTableTestIDs,
|
|
@@ -993,6 +996,11 @@ export interface TextFieldProps extends BaseFieldProps, HelperTextProps, ErrorTe
|
|
|
993
996
|
returnKeyType?: "done" | "go" | "next" | "search" | "send";
|
|
994
997
|
|
|
995
998
|
grow?: boolean;
|
|
999
|
+
/**
|
|
1000
|
+
* Caps the height (in pixels) a `grow` field expands to. Past the cap the field
|
|
1001
|
+
* stops growing and its content scrolls.
|
|
1002
|
+
*/
|
|
1003
|
+
maxHeight?: number;
|
|
996
1004
|
multiline?: boolean;
|
|
997
1005
|
rows?: number;
|
|
998
1006
|
|
|
@@ -1016,10 +1024,22 @@ export interface NumberRangeFieldProps extends BaseFieldProps, HelperTextProps,
|
|
|
1016
1024
|
max: number;
|
|
1017
1025
|
}
|
|
1018
1026
|
|
|
1027
|
+
/**
|
|
1028
|
+
* What the typed parts of a {@link DateTimeFieldProps | DateTimeField} hold: nothing, an unfinished
|
|
1029
|
+
* or invalid entry, or a complete value.
|
|
1030
|
+
*/
|
|
1031
|
+
export type DateTimeEntryStatus = "empty" | "invalid" | "valid";
|
|
1032
|
+
|
|
1019
1033
|
export interface DateTimeFieldProps extends BaseFieldProps, HelperTextProps, ErrorTextProps {
|
|
1020
1034
|
type: "date" | "datetime" | "time";
|
|
1021
1035
|
value?: string; // ISO string always
|
|
1022
1036
|
onChange: (date: string) => void;
|
|
1037
|
+
/**
|
|
1038
|
+
* Called after each typed change and picker selection with what the field now holds.
|
|
1039
|
+
* `onChange` only fires for complete values, so use this to refuse an unfinished entry
|
|
1040
|
+
* (such as "0 / 5 / 026") or to notice the user cleared the field.
|
|
1041
|
+
*/
|
|
1042
|
+
onEntryStatusChange?: (status: DateTimeEntryStatus) => void;
|
|
1023
1043
|
onTimezoneChange?: (timezone: string) => void;
|
|
1024
1044
|
dateFormat?: string;
|
|
1025
1045
|
pickerType?: "default" | "compact" | "inline" | "spinner";
|
|
@@ -1101,6 +1121,15 @@ export interface HeadingProps extends WithTestID {
|
|
|
1101
1121
|
truncate?: boolean; // default false
|
|
1102
1122
|
}
|
|
1103
1123
|
|
|
1124
|
+
export interface HtmlFrameProps {
|
|
1125
|
+
/** Frame height. `sm` is 240px, `md` is 400px, and `lg` is 640px. */
|
|
1126
|
+
height?: "lg" | "md" | "sm";
|
|
1127
|
+
/** Sanitized HTML. The frame prepends a Content-Security-Policy meta tag. */
|
|
1128
|
+
html: string;
|
|
1129
|
+
/** Accessible name for the frame. Defaults to Agent-generated preview. */
|
|
1130
|
+
title?: string;
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1104
1133
|
export interface MetaProps {
|
|
1105
1134
|
itemProp?: string;
|
|
1106
1135
|
content?: string;
|
|
@@ -1978,6 +2007,36 @@ export type BannerProps =
|
|
|
1978
2007
|
| (BannerPropsBase & {buttonOnClick?: undefined})
|
|
1979
2008
|
| (BannerPropsBase & {buttonOnClick: () => void | Promise<void>} & BannerButtonProps);
|
|
1980
2009
|
|
|
2010
|
+
export interface BlocksViewProps extends WithTestID {
|
|
2011
|
+
/** When true, an `html` block renders in a sandboxed frame. Otherwise it stays a placeholder. */
|
|
2012
|
+
allowHtml?: boolean;
|
|
2013
|
+
/** A whole-reply YAML or JSON string, or a document that already parsed. */
|
|
2014
|
+
document: string | BlocksDocument;
|
|
2015
|
+
/** Names the host will run. A callback outside this list is disabled. Omit to leave callbacks enabled. */
|
|
2016
|
+
hostActions?: readonly string[];
|
|
2017
|
+
/** Hostnames allowed on https image sources. Empty rejects every https image. */
|
|
2018
|
+
imageHosts?: readonly string[];
|
|
2019
|
+
/** Called for reply, open, select, and callback. Select also updates the target chart locally. */
|
|
2020
|
+
onAction?: (event: {action: BlockAction; blockId: string; elementId: string}) => void;
|
|
2021
|
+
/** Block ids replaced in place. The key is the original block id. */
|
|
2022
|
+
overrides?: Record<string, Block>;
|
|
2023
|
+
/** Element ids whose buttons show a loading state. */
|
|
2024
|
+
pendingElementIds?: readonly string[];
|
|
2025
|
+
/** Loads a `ref` dataset. Inline datasets do not call this. */
|
|
2026
|
+
resolveDataset?: (ref: {
|
|
2027
|
+
grain?: "day" | "hour" | "month" | "week";
|
|
2028
|
+
id: string;
|
|
2029
|
+
limit?: number;
|
|
2030
|
+
}) => Promise<InlineDataset | undefined>;
|
|
2031
|
+
/**
|
|
2032
|
+
* Turns a `file:` image id into a URL. Until it resolves, the image is omitted and the alt
|
|
2033
|
+
* text stays. Data and https sources do not call this.
|
|
2034
|
+
*/
|
|
2035
|
+
resolveImage?: (fileId: string) => Promise<string | undefined>;
|
|
2036
|
+
/** While a reply is still streaming, `html` stays a placeholder. */
|
|
2037
|
+
streaming?: boolean;
|
|
2038
|
+
}
|
|
2039
|
+
|
|
1981
2040
|
export interface BodyProps {
|
|
1982
2041
|
scroll?: boolean;
|
|
1983
2042
|
loading?: boolean;
|
|
@@ -2071,6 +2130,13 @@ export interface ButtonProps extends WithTestID {
|
|
|
2071
2130
|
* If true, a confirmation modal will be shown before the onClick action.
|
|
2072
2131
|
*/
|
|
2073
2132
|
withConfirmation?: boolean;
|
|
2133
|
+
/**
|
|
2134
|
+
* If true, the button is never wider than its container, and a label that does not fit wraps
|
|
2135
|
+
* onto centered lines while the button grows taller. A small button grows from its 28px height.
|
|
2136
|
+
* If false, the label stays on one line.
|
|
2137
|
+
* @default false
|
|
2138
|
+
*/
|
|
2139
|
+
wrapText?: boolean;
|
|
2074
2140
|
/**
|
|
2075
2141
|
* The function to call when the button is clicked.
|
|
2076
2142
|
*/
|
|
@@ -2734,8 +2800,10 @@ export interface PaginationProps extends WithTestID {
|
|
|
2734
2800
|
export interface LineChartProps extends WithTestID {
|
|
2735
2801
|
/** Summary announced for the whole chart. */
|
|
2736
2802
|
accessibilityLabel?: string;
|
|
2803
|
+
/** Optional previous-period values drawn as a dotted overlay. */
|
|
2804
|
+
comparisonData?: ChartPoint[];
|
|
2737
2805
|
/** Single series of labeled numeric points. */
|
|
2738
|
-
data:
|
|
2806
|
+
data: ChartPoint[];
|
|
2739
2807
|
/** Copy shown when `data` is empty. */
|
|
2740
2808
|
emptyText?: string;
|
|
2741
2809
|
/** Formats the numeric value in tooltips. */
|
|
@@ -2746,12 +2814,65 @@ export interface LineChartProps extends WithTestID {
|
|
|
2746
2814
|
legendLabel?: string;
|
|
2747
2815
|
/** When true, shows a spinner instead of the plot. */
|
|
2748
2816
|
loading?: boolean;
|
|
2817
|
+
/** Makes `periodLabel` pressable when provided. */
|
|
2818
|
+
onPeriodPress?: () => void;
|
|
2819
|
+
/** Relative or absolute reporting period shown with `title`. */
|
|
2820
|
+
periodLabel?: string;
|
|
2821
|
+
/** Named series. When non-empty, these replace the single `data` series. */
|
|
2822
|
+
series?: ChartSeries[];
|
|
2823
|
+
/** Optional chart-card title shortcut. */
|
|
2824
|
+
title?: string;
|
|
2825
|
+
/** X-label collision policy. `auto` rotates when more than seven labels are present. */
|
|
2826
|
+
xTickPolicy?: "auto" | "rotate" | "truncate";
|
|
2827
|
+
}
|
|
2828
|
+
|
|
2829
|
+
export interface SparklineChartProps extends WithTestID {
|
|
2830
|
+
/** Summary announced for the whole sparkline. */
|
|
2831
|
+
accessibilityLabel?: string;
|
|
2832
|
+
/** Optional previous-period values drawn as a dotted line. */
|
|
2833
|
+
comparisonData?: Array<{label: string; value: number}>;
|
|
2834
|
+
/** Current labeled numeric values. */
|
|
2835
|
+
data: Array<{label: string; value: number}>;
|
|
2836
|
+
/** Whole sparkline height in pixels. */
|
|
2837
|
+
height?: number;
|
|
2838
|
+
}
|
|
2839
|
+
|
|
2840
|
+
export interface ChartCardProps extends WithTestID {
|
|
2841
|
+
children: React.ReactNode;
|
|
2842
|
+
/** Optional context shown below the title row. */
|
|
2843
|
+
filterSummary?: string;
|
|
2844
|
+
/** Makes the period badge pressable when provided. */
|
|
2845
|
+
onPeriodPress?: () => void;
|
|
2846
|
+
/** Date range or relative period shown in the header. */
|
|
2847
|
+
periodLabel?: string;
|
|
2848
|
+
/** Card heading. */
|
|
2849
|
+
title: string;
|
|
2850
|
+
}
|
|
2851
|
+
|
|
2852
|
+
export interface ScorecardProps extends WithTestID {
|
|
2853
|
+
/** Optional previous-period sparkline values. */
|
|
2854
|
+
comparisonData?: Array<{label: string; value: number}>;
|
|
2855
|
+
/** Formats numeric values. String values render unchanged. */
|
|
2856
|
+
formatValue?: (value: number) => string;
|
|
2857
|
+
onPeriodPress?: () => void;
|
|
2858
|
+
periodLabel?: string;
|
|
2859
|
+
/** Current-period sparkline values. */
|
|
2860
|
+
sparklineData?: Array<{label: string; value: number}>;
|
|
2861
|
+
title: string;
|
|
2862
|
+
value: number | string;
|
|
2749
2863
|
}
|
|
2750
2864
|
|
|
2751
2865
|
export interface AreaChartProps extends LineChartProps {}
|
|
2752
2866
|
export interface BarChartProps extends LineChartProps {}
|
|
2753
2867
|
|
|
2754
|
-
export interface DonutChartProps extends LineChartProps {
|
|
2868
|
+
export interface DonutChartProps extends LineChartProps {
|
|
2869
|
+
/** Small copy below the center value. */
|
|
2870
|
+
centerTitle?: string;
|
|
2871
|
+
/** Primary copy inside the donut hole. */
|
|
2872
|
+
centerValue?: string;
|
|
2873
|
+
/** Formats each slice's legend share. Defaults to a rounded percentage. */
|
|
2874
|
+
formatShare?: (value: number, total: number) => string;
|
|
2875
|
+
}
|
|
2755
2876
|
|
|
2756
2877
|
export interface DashboardGridProps extends WithTestID {
|
|
2757
2878
|
children?: React.ReactNode;
|
|
@@ -2760,6 +2881,12 @@ export interface DashboardGridProps extends WithTestID {
|
|
|
2760
2881
|
gap?: UnsignedUpTo12;
|
|
2761
2882
|
}
|
|
2762
2883
|
|
|
2884
|
+
export interface DashboardGridItemProps extends WithTestID {
|
|
2885
|
+
children?: React.ReactNode;
|
|
2886
|
+
/** Number of grid columns occupied at each breakpoint. Defaults to one. */
|
|
2887
|
+
span?: {lg?: number; md?: number; sm?: number};
|
|
2888
|
+
}
|
|
2889
|
+
|
|
2763
2890
|
/**
|
|
2764
2891
|
* Data Table
|
|
2765
2892
|
*/
|
|
@@ -2963,6 +3090,8 @@ export interface TableContextProviderProps extends TableContextType {
|
|
|
2963
3090
|
}
|
|
2964
3091
|
|
|
2965
3092
|
export interface TextProps extends WithTestID {
|
|
3093
|
+
/** `"header"` marks the text as a heading, so screen readers announce it and can jump to it. */
|
|
3094
|
+
accessibilityRole?: "header";
|
|
2966
3095
|
align?: "left" | "right" | "center" | "justify"; // default "left"
|
|
2967
3096
|
children?: React.ReactNode;
|
|
2968
3097
|
bold?: boolean; // default false
|
|
@@ -2972,6 +3101,11 @@ export interface TextProps extends WithTestID {
|
|
|
2972
3101
|
truncate?: boolean; // default false
|
|
2973
3102
|
underline?: boolean;
|
|
2974
3103
|
numberOfLines?: number;
|
|
3104
|
+
/**
|
|
3105
|
+
* The native text, for example to move screen reader focus to it with
|
|
3106
|
+
* `AccessibilityInfo.setAccessibilityFocus`.
|
|
3107
|
+
*/
|
|
3108
|
+
ref?: React.Ref<NativeText>;
|
|
2975
3109
|
skipLinking?: boolean;
|
|
2976
3110
|
}
|
|
2977
3111
|
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import {describe, expect, it} from "bun:test";
|
|
2
2
|
import {act, fireEvent} from "@testing-library/react-native";
|
|
3
|
+
import {assert} from "chai";
|
|
4
|
+
import {memo} from "react";
|
|
3
5
|
|
|
4
6
|
import {Box} from "./Box";
|
|
5
7
|
import {getSpacing} from "./Common";
|
|
6
|
-
import {DashboardGrid} from "./DashboardGrid";
|
|
8
|
+
import {DashboardGrid, DashboardGridItem} from "./DashboardGrid";
|
|
7
9
|
import {getDashboardCellWidth} from "./dashboardGridLayout";
|
|
10
|
+
import {sharedResponsiveBreakpointStore} from "./ResponsiveBreakpoint";
|
|
8
11
|
import {renderWithTheme} from "./test-utils";
|
|
9
12
|
|
|
13
|
+
const MemoDashboardGridItem = memo(DashboardGridItem);
|
|
14
|
+
|
|
10
15
|
describe("DashboardGrid", () => {
|
|
11
16
|
it("keeps child testIDs", () => {
|
|
12
17
|
const {getByTestId} = renderWithTheme(
|
|
@@ -72,4 +77,96 @@ describe("DashboardGrid", () => {
|
|
|
72
77
|
width: expectedWidth,
|
|
73
78
|
});
|
|
74
79
|
});
|
|
80
|
+
|
|
81
|
+
it("lets an item span responsive column units without changing plain children", async () => {
|
|
82
|
+
const {getByTestId} = renderWithTheme(
|
|
83
|
+
<DashboardGrid columns={{lg: 4, md: 4, sm: 4}} gap={4} testID="grid">
|
|
84
|
+
<DashboardGridItem span={{lg: 2, md: 2, sm: 2}} testID="wide-item">
|
|
85
|
+
<Box>Wide</Box>
|
|
86
|
+
</DashboardGridItem>
|
|
87
|
+
<Box testID="plain-item">Plain</Box>
|
|
88
|
+
</DashboardGrid>
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
await act(async () => {
|
|
92
|
+
fireEvent(getByTestId("grid"), "layout", {
|
|
93
|
+
nativeEvent: {layout: {height: 80, width: 332}},
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const baseWidth = getDashboardCellWidth({
|
|
98
|
+
columnCount: 4,
|
|
99
|
+
gapPx: getSpacing(4),
|
|
100
|
+
rowWidth: 332,
|
|
101
|
+
});
|
|
102
|
+
assert.include(getByTestId("grid.cell.0").props.style, {
|
|
103
|
+
width: baseWidth * 2 + getSpacing(4),
|
|
104
|
+
});
|
|
105
|
+
assert.include(getByTestId("grid.cell.1").props.style, {width: baseWidth});
|
|
106
|
+
assert.exists(getByTestId("wide-item"));
|
|
107
|
+
assert.exists(getByTestId("plain-item"));
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("resolves asymmetric spans at each responsive breakpoint", async () => {
|
|
111
|
+
const result = renderWithTheme(
|
|
112
|
+
<DashboardGrid columns={{lg: 4, md: 4, sm: 4}} gap={4} testID="grid">
|
|
113
|
+
<DashboardGridItem span={{lg: 3, md: 2, sm: 1}}>
|
|
114
|
+
<Box>Responsive</Box>
|
|
115
|
+
</DashboardGridItem>
|
|
116
|
+
</DashboardGrid>
|
|
117
|
+
);
|
|
118
|
+
await act(async () => {
|
|
119
|
+
fireEvent(result.getByTestId("grid"), "layout", {
|
|
120
|
+
nativeEvent: {layout: {height: 80, width: 332}},
|
|
121
|
+
});
|
|
122
|
+
sharedResponsiveBreakpointStore.updateWidth(319);
|
|
123
|
+
});
|
|
124
|
+
const baseWidth = getDashboardCellWidth({
|
|
125
|
+
columnCount: 4,
|
|
126
|
+
gapPx: getSpacing(4),
|
|
127
|
+
rowWidth: 332,
|
|
128
|
+
});
|
|
129
|
+
assert.equal(result.getByTestId("grid.cell.0").props.style.width, baseWidth);
|
|
130
|
+
|
|
131
|
+
act((): void => {
|
|
132
|
+
sharedResponsiveBreakpointStore.updateWidth(375);
|
|
133
|
+
});
|
|
134
|
+
assert.equal(
|
|
135
|
+
result.getByTestId("grid.cell.0").props.style.width,
|
|
136
|
+
baseWidth * 2 + getSpacing(4)
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
act((): void => {
|
|
140
|
+
sharedResponsiveBreakpointStore.updateWidth(600);
|
|
141
|
+
});
|
|
142
|
+
assert.equal(
|
|
143
|
+
result.getByTestId("grid.cell.0").props.style.width,
|
|
144
|
+
baseWidth * 3 + getSpacing(4) * 2
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
result.unmount();
|
|
148
|
+
sharedResponsiveBreakpointStore.updateWidth(375);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("keeps span metadata through React memo wrappers", async () => {
|
|
152
|
+
const {getByTestId} = renderWithTheme(
|
|
153
|
+
<DashboardGrid columns={{lg: 4, md: 4, sm: 4}} gap={4} testID="grid">
|
|
154
|
+
<MemoDashboardGridItem span={{lg: 2, md: 2, sm: 2}}>
|
|
155
|
+
<Box>Memo item</Box>
|
|
156
|
+
</MemoDashboardGridItem>
|
|
157
|
+
</DashboardGrid>
|
|
158
|
+
);
|
|
159
|
+
await act(async () => {
|
|
160
|
+
fireEvent(getByTestId("grid"), "layout", {
|
|
161
|
+
nativeEvent: {layout: {height: 80, width: 332}},
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
const baseWidth = getDashboardCellWidth({
|
|
165
|
+
columnCount: 4,
|
|
166
|
+
gapPx: getSpacing(4),
|
|
167
|
+
rowWidth: 332,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
assert.equal(getByTestId("grid.cell.0").props.style.width, baseWidth * 2 + getSpacing(4));
|
|
171
|
+
});
|
|
75
172
|
});
|
package/src/DashboardGrid.tsx
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import type {FC, ReactNode} from "react";
|
|
2
|
-
import {Children, useCallback, useState} from "react";
|
|
2
|
+
import {Children, isValidElement, useCallback, useState} from "react";
|
|
3
3
|
|
|
4
4
|
import {Box} from "./Box";
|
|
5
|
-
import type {DashboardGridProps, LayoutChangeEvent} from "./Common";
|
|
5
|
+
import type {DashboardGridItemProps, DashboardGridProps, LayoutChangeEvent} from "./Common";
|
|
6
6
|
import {getSpacing} from "./Common";
|
|
7
|
-
import {
|
|
7
|
+
import {getDashboardSpanCellBoxStyle} from "./dashboardGridLayout";
|
|
8
8
|
import {useResponsiveBreakpoint} from "./ResponsiveBreakpoint";
|
|
9
9
|
import {resolveTestID} from "./testing/resolveTestId";
|
|
10
10
|
|
|
11
11
|
const DEFAULT_COLUMNS = {lg: 3, md: 2, sm: 1};
|
|
12
12
|
|
|
13
|
+
type MarkedDashboardGridItem = FC<DashboardGridItemProps> & {
|
|
14
|
+
isDashboardGridItem?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
13
17
|
const resolveColumnCount = ({
|
|
14
18
|
breakpoint,
|
|
15
19
|
columns,
|
|
@@ -26,6 +30,44 @@ const resolveColumnCount = ({
|
|
|
26
30
|
return columns.sm;
|
|
27
31
|
};
|
|
28
32
|
|
|
33
|
+
const resolveItemSpan = ({
|
|
34
|
+
breakpoint,
|
|
35
|
+
span,
|
|
36
|
+
}: {
|
|
37
|
+
breakpoint: "xs" | "sm" | "md" | "lg" | "xl";
|
|
38
|
+
span?: DashboardGridItemProps["span"];
|
|
39
|
+
}): number => {
|
|
40
|
+
if (!span) {
|
|
41
|
+
return 1;
|
|
42
|
+
}
|
|
43
|
+
if (breakpoint === "lg" || breakpoint === "xl") {
|
|
44
|
+
return span.lg ?? span.md ?? span.sm ?? 1;
|
|
45
|
+
}
|
|
46
|
+
if (breakpoint === "md") {
|
|
47
|
+
return span.md ?? span.sm ?? 1;
|
|
48
|
+
}
|
|
49
|
+
return span.sm ?? 1;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const DashboardGridItem: MarkedDashboardGridItem = ({children, testID}) => {
|
|
53
|
+
return (
|
|
54
|
+
<Box minWidth={0} testID={testID} width="100%">
|
|
55
|
+
{children}
|
|
56
|
+
</Box>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
DashboardGridItem.isDashboardGridItem = true;
|
|
60
|
+
|
|
61
|
+
const isDashboardGridItemType = (type: unknown): boolean => {
|
|
62
|
+
if (typeof type === "function") {
|
|
63
|
+
return (type as MarkedDashboardGridItem).isDashboardGridItem === true;
|
|
64
|
+
}
|
|
65
|
+
if (type && typeof type === "object" && "type" in type) {
|
|
66
|
+
return isDashboardGridItemType(type.type);
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
};
|
|
70
|
+
|
|
29
71
|
export const DashboardGrid: FC<DashboardGridProps> = ({
|
|
30
72
|
children,
|
|
31
73
|
columns = DEFAULT_COLUMNS,
|
|
@@ -36,11 +78,7 @@ export const DashboardGrid: FC<DashboardGridProps> = ({
|
|
|
36
78
|
const breakpoint = useResponsiveBreakpoint({enabled: true});
|
|
37
79
|
const [rowWidth, setRowWidth] = useState(0);
|
|
38
80
|
const columnCount = Math.max(resolveColumnCount({breakpoint, columns}), 1);
|
|
39
|
-
const
|
|
40
|
-
columnCount,
|
|
41
|
-
gapPx: getSpacing(gap),
|
|
42
|
-
rowWidth,
|
|
43
|
-
});
|
|
81
|
+
const gapPx = getSpacing(gap);
|
|
44
82
|
|
|
45
83
|
const handleLayout = useCallback((event: LayoutChangeEvent): void => {
|
|
46
84
|
const nextWidth = event.nativeEvent.layout.width;
|
|
@@ -51,19 +89,32 @@ export const DashboardGrid: FC<DashboardGridProps> = ({
|
|
|
51
89
|
|
|
52
90
|
return (
|
|
53
91
|
<Box direction="row" gap={gap} onLayout={handleLayout} testID={testID} width="100%" wrap>
|
|
54
|
-
{renderedChildren.map((child: ReactNode, index: number) =>
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
92
|
+
{renderedChildren.map((child: ReactNode, index: number) => {
|
|
93
|
+
const itemSpan =
|
|
94
|
+
isValidElement<DashboardGridItemProps>(child) && isDashboardGridItemType(child.type)
|
|
95
|
+
? child.props.span
|
|
96
|
+
: undefined;
|
|
97
|
+
const span = resolveItemSpan({breakpoint, span: itemSpan});
|
|
98
|
+
const cellStyle = getDashboardSpanCellBoxStyle({
|
|
99
|
+
columnCount,
|
|
100
|
+
gapPx,
|
|
101
|
+
rowWidth,
|
|
102
|
+
span,
|
|
103
|
+
});
|
|
104
|
+
return (
|
|
105
|
+
<Box
|
|
106
|
+
dangerouslySetInlineStyle={{
|
|
107
|
+
__style: cellStyle,
|
|
108
|
+
}}
|
|
109
|
+
key={`dashboard-cell-${index}`}
|
|
110
|
+
testID={resolveTestID(testID, `cell.${index}`)}
|
|
111
|
+
>
|
|
112
|
+
{child}
|
|
113
|
+
</Box>
|
|
114
|
+
);
|
|
115
|
+
})}
|
|
65
116
|
</Box>
|
|
66
117
|
);
|
|
67
118
|
};
|
|
68
119
|
|
|
69
|
-
export type {DashboardGridProps} from "./Common";
|
|
120
|
+
export type {DashboardGridItemProps, DashboardGridProps} from "./Common";
|
|
@@ -8,14 +8,24 @@ import {
|
|
|
8
8
|
type mock as MockType,
|
|
9
9
|
mock,
|
|
10
10
|
} from "bun:test";
|
|
11
|
-
import {act, userEvent} from "@testing-library/react-native";
|
|
11
|
+
import {act, fireEvent, userEvent} from "@testing-library/react-native";
|
|
12
12
|
import {assert} from "chai";
|
|
13
13
|
import {DateTime} from "luxon";
|
|
14
|
+
import {useState} from "react";
|
|
14
15
|
import type {ReactTestInstance} from "react-test-renderer";
|
|
15
|
-
|
|
16
|
+
import type {DateTimeFieldProps} from "./Common";
|
|
16
17
|
import {DateTimeField} from "./DateTimeField";
|
|
17
18
|
import {renderWithTheme, setupComponentTest, teardownComponentTest} from "./test-utils";
|
|
18
19
|
|
|
20
|
+
/** A parent that passes every emitted value back, as a form does. */
|
|
21
|
+
const ControlledDateTimeField = ({
|
|
22
|
+
initialValue,
|
|
23
|
+
...props
|
|
24
|
+
}: Omit<DateTimeFieldProps, "onChange" | "value"> & {initialValue: string}): React.ReactElement => {
|
|
25
|
+
const [value, setValue] = useState(initialValue);
|
|
26
|
+
return <DateTimeField {...props} onChange={setValue} value={value} />;
|
|
27
|
+
};
|
|
28
|
+
|
|
19
29
|
const setDesktop = () => {
|
|
20
30
|
mock.module("./MediaQuery", () => ({
|
|
21
31
|
isNarrowViewport: () => false,
|
|
@@ -460,6 +470,179 @@ describe("DateTimeField", () => {
|
|
|
460
470
|
});
|
|
461
471
|
});
|
|
462
472
|
|
|
473
|
+
describe("onEntryStatusChange", () => {
|
|
474
|
+
it("reports an unfinished date as invalid, a complete one as valid, and a cleared one as empty", async () => {
|
|
475
|
+
const user = userEvent.setup();
|
|
476
|
+
const onEntryStatusChange = mock((_status: string) => {});
|
|
477
|
+
const {getByPlaceholderText} = renderWithTheme(
|
|
478
|
+
<DateTimeField
|
|
479
|
+
onChange={mockOnChange}
|
|
480
|
+
onEntryStatusChange={onEntryStatusChange}
|
|
481
|
+
type="date"
|
|
482
|
+
value=""
|
|
483
|
+
/>
|
|
484
|
+
);
|
|
485
|
+
await user.type(getByPlaceholderText("MM"), "0");
|
|
486
|
+
expect(onEntryStatusChange).toHaveBeenLastCalledWith("invalid");
|
|
487
|
+
|
|
488
|
+
await user.clear(getByPlaceholderText("MM"));
|
|
489
|
+
expect(onEntryStatusChange).toHaveBeenLastCalledWith("empty");
|
|
490
|
+
|
|
491
|
+
await user.type(getByPlaceholderText("MM"), "10");
|
|
492
|
+
await user.type(getByPlaceholderText("DD"), "15");
|
|
493
|
+
await user.type(getByPlaceholderText("YYYY"), "202");
|
|
494
|
+
expect(onEntryStatusChange).toHaveBeenLastCalledWith("invalid");
|
|
495
|
+
await user.type(getByPlaceholderText("YYYY"), "6");
|
|
496
|
+
expect(onEntryStatusChange).toHaveBeenLastCalledWith("valid");
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
it("reports a datetime whose hour is cleared as invalid without throwing", async () => {
|
|
500
|
+
const user = userEvent.setup();
|
|
501
|
+
const onEntryStatusChange = mock((_status: string) => {});
|
|
502
|
+
const {getByPlaceholderText} = renderWithTheme(
|
|
503
|
+
<DateTimeField
|
|
504
|
+
onChange={mockOnChange}
|
|
505
|
+
onEntryStatusChange={onEntryStatusChange}
|
|
506
|
+
timezone="America/New_York"
|
|
507
|
+
type="datetime"
|
|
508
|
+
value="2023-05-15T15:30:00.000Z"
|
|
509
|
+
/>
|
|
510
|
+
);
|
|
511
|
+
await user.clear(getByPlaceholderText("hh"));
|
|
512
|
+
expect(onEntryStatusChange).toHaveBeenLastCalledWith("invalid");
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
it("reports a single-digit hour typed into an empty datetime hour as valid", async () => {
|
|
516
|
+
const user = userEvent.setup();
|
|
517
|
+
const onEntryStatusChange = mock((_status: string) => {});
|
|
518
|
+
const {getByPlaceholderText} = renderWithTheme(
|
|
519
|
+
<DateTimeField
|
|
520
|
+
onChange={mockOnChange}
|
|
521
|
+
onEntryStatusChange={onEntryStatusChange}
|
|
522
|
+
timezone="America/New_York"
|
|
523
|
+
type="datetime"
|
|
524
|
+
value=""
|
|
525
|
+
/>
|
|
526
|
+
);
|
|
527
|
+
await user.type(getByPlaceholderText("MM"), "10");
|
|
528
|
+
await user.type(getByPlaceholderText("DD"), "15");
|
|
529
|
+
await user.type(getByPlaceholderText("YYYY"), "2026");
|
|
530
|
+
await user.type(getByPlaceholderText("mm"), "30");
|
|
531
|
+
act(() => {
|
|
532
|
+
fireEvent.changeText(getByPlaceholderText("hh"), "4");
|
|
533
|
+
});
|
|
534
|
+
expect(onEntryStatusChange).toHaveBeenLastCalledWith("valid");
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
it("reports a time without an hour as invalid", async () => {
|
|
538
|
+
const user = userEvent.setup();
|
|
539
|
+
const onEntryStatusChange = mock((_status: string) => {});
|
|
540
|
+
const {getByPlaceholderText} = renderWithTheme(
|
|
541
|
+
<DateTimeField
|
|
542
|
+
onChange={mockOnChange}
|
|
543
|
+
onEntryStatusChange={onEntryStatusChange}
|
|
544
|
+
timezone="America/New_York"
|
|
545
|
+
type="time"
|
|
546
|
+
value="2023-05-15T15:30:00.000Z"
|
|
547
|
+
/>
|
|
548
|
+
);
|
|
549
|
+
await user.clear(getByPlaceholderText("hh"));
|
|
550
|
+
expect(onEntryStatusChange).toHaveBeenLastCalledWith("invalid");
|
|
551
|
+
await user.type(getByPlaceholderText("hh"), "4");
|
|
552
|
+
expect(onEntryStatusChange).toHaveBeenLastCalledWith("valid");
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
it("reports an on-the-hour time whose hour is cleared as invalid until the minute is cleared too", async () => {
|
|
556
|
+
const user = userEvent.setup();
|
|
557
|
+
const onEntryStatusChange = mock((_status: string) => {});
|
|
558
|
+
const {getByPlaceholderText} = renderWithTheme(
|
|
559
|
+
<DateTimeField
|
|
560
|
+
onChange={mockOnChange}
|
|
561
|
+
onEntryStatusChange={onEntryStatusChange}
|
|
562
|
+
timezone="America/New_York"
|
|
563
|
+
type="time"
|
|
564
|
+
value="2023-05-15T13:00:00.000Z"
|
|
565
|
+
/>
|
|
566
|
+
);
|
|
567
|
+
expect(getByPlaceholderText("mm").props.value).toBe("00");
|
|
568
|
+
await user.clear(getByPlaceholderText("hh"));
|
|
569
|
+
expect(onEntryStatusChange).toHaveBeenLastCalledWith("invalid");
|
|
570
|
+
await user.clear(getByPlaceholderText("mm"));
|
|
571
|
+
expect(onEntryStatusChange).toHaveBeenLastCalledWith("empty");
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
it("reports a noon datetime cleared except for its minute as invalid until the minute is cleared too", async () => {
|
|
575
|
+
const user = userEvent.setup();
|
|
576
|
+
const onEntryStatusChange = mock((_status: string) => {});
|
|
577
|
+
const {getByPlaceholderText} = renderWithTheme(
|
|
578
|
+
<DateTimeField
|
|
579
|
+
onChange={mockOnChange}
|
|
580
|
+
onEntryStatusChange={onEntryStatusChange}
|
|
581
|
+
timezone="America/New_York"
|
|
582
|
+
type="datetime"
|
|
583
|
+
value="2023-05-15T16:00:00.000Z"
|
|
584
|
+
/>
|
|
585
|
+
);
|
|
586
|
+
expect(getByPlaceholderText("hh").props.value).toBe("12");
|
|
587
|
+
for (const placeholder of ["MM", "DD", "YYYY", "hh"]) {
|
|
588
|
+
await user.clear(getByPlaceholderText(placeholder));
|
|
589
|
+
}
|
|
590
|
+
expect(onEntryStatusChange).toHaveBeenLastCalledWith("invalid");
|
|
591
|
+
await user.clear(getByPlaceholderText("mm"));
|
|
592
|
+
expect(onEntryStatusChange).toHaveBeenLastCalledWith("empty");
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
it("reports a controlled time cleared minute first, then hour, as empty", async () => {
|
|
596
|
+
const user = userEvent.setup();
|
|
597
|
+
const onEntryStatusChange = mock((_status: string) => {});
|
|
598
|
+
const {getByPlaceholderText} = renderWithTheme(
|
|
599
|
+
<ControlledDateTimeField
|
|
600
|
+
initialValue="2023-05-15T13:30:00.000Z"
|
|
601
|
+
onEntryStatusChange={onEntryStatusChange}
|
|
602
|
+
timezone="America/New_York"
|
|
603
|
+
type="time"
|
|
604
|
+
/>
|
|
605
|
+
);
|
|
606
|
+
await user.clear(getByPlaceholderText("mm"));
|
|
607
|
+
expect(getByPlaceholderText("mm").props.value).toBe("00");
|
|
608
|
+
expect(onEntryStatusChange).toHaveBeenLastCalledWith("valid");
|
|
609
|
+
await user.clear(getByPlaceholderText("hh"));
|
|
610
|
+
expect(onEntryStatusChange).toHaveBeenLastCalledWith("empty");
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
it("reports a controlled datetime cleared minute first, then the rest, as empty", async () => {
|
|
614
|
+
const user = userEvent.setup();
|
|
615
|
+
const onEntryStatusChange = mock((_status: string) => {});
|
|
616
|
+
const {getByPlaceholderText} = renderWithTheme(
|
|
617
|
+
<ControlledDateTimeField
|
|
618
|
+
initialValue="2026-10-01T13:30:00.000Z"
|
|
619
|
+
onEntryStatusChange={onEntryStatusChange}
|
|
620
|
+
timezone="America/New_York"
|
|
621
|
+
type="datetime"
|
|
622
|
+
/>
|
|
623
|
+
);
|
|
624
|
+
for (const placeholder of ["mm", "MM", "DD", "YYYY", "hh"]) {
|
|
625
|
+
await user.clear(getByPlaceholderText(placeholder));
|
|
626
|
+
}
|
|
627
|
+
expect(onEntryStatusChange).toHaveBeenLastCalledWith("empty");
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
it("emits nothing when the hour of an on-the-hour time is cleared without onEntryStatusChange", async () => {
|
|
631
|
+
const user = userEvent.setup();
|
|
632
|
+
const onChange = mock((_value: string) => {});
|
|
633
|
+
const {getByPlaceholderText} = renderWithTheme(
|
|
634
|
+
<DateTimeField
|
|
635
|
+
onChange={onChange}
|
|
636
|
+
timezone="America/New_York"
|
|
637
|
+
type="time"
|
|
638
|
+
value="2023-05-15T13:00:00.000Z"
|
|
639
|
+
/>
|
|
640
|
+
);
|
|
641
|
+
await user.clear(getByPlaceholderText("hh"));
|
|
642
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
643
|
+
});
|
|
644
|
+
});
|
|
645
|
+
|
|
463
646
|
describe("time type field validation", () => {
|
|
464
647
|
it("should validate hour fields for time type", async () => {
|
|
465
648
|
const user = userEvent.setup();
|