d2coreui 23.0.55 → 23.0.56
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/CHANGELOG.md +18 -0
- package/components/date/dateRangeInput.js +5 -5
- package/components/date/dateRangeInput.js.map +1 -1
- package/components/date/dateRangeInputAdvancedPanel.js +15 -4
- package/components/date/dateRangeInputAdvancedPanel.js.map +1 -1
- package/components/date/dateRangeInputConfirm.js +16 -13
- package/components/date/dateRangeInputConfirm.js.map +1 -1
- package/components/date/dateTimeInput.js +38 -28
- package/components/date/dateTimeInput.js.map +1 -1
- package/components/style/withCss.d.ts +9 -4
- package/components/style/withCss.js +7 -3
- package/components/style/withCss.js.map +1 -1
- package/package.json +1 -1
|
@@ -22,13 +22,13 @@ import WithCss from "../style/withCss";
|
|
|
22
22
|
const useStyles = createStyles(({ token, css }) => {
|
|
23
23
|
return {
|
|
24
24
|
// the confirm buttons float above the page on a transparent tooltip, so they need their own surface
|
|
25
|
-
buttonsSurface: css `
|
|
26
|
-
background: ${token.colorBgElevated};
|
|
25
|
+
buttonsSurface: css `
|
|
26
|
+
background: ${token.colorBgElevated};
|
|
27
27
|
`,
|
|
28
28
|
// ghost button is transparent by default - give it the same opaque surface
|
|
29
|
-
revertButton: css `
|
|
30
|
-
background: ${token.colorBgElevated};
|
|
31
|
-
border-right-width: 2px;
|
|
29
|
+
revertButton: css `
|
|
30
|
+
background: ${token.colorBgElevated};
|
|
31
|
+
border-right-width: 2px;
|
|
32
32
|
`,
|
|
33
33
|
};
|
|
34
34
|
});
|
|
@@ -99,15 +99,18 @@ export default class DateRangeInputConfirm extends React.Component {
|
|
|
99
99
|
});
|
|
100
100
|
(_c = this.dateRangeInput) === null || _c === void 0 ? void 0 : _c.closePopup();
|
|
101
101
|
}
|
|
102
|
-
renderConfirmButtons(size
|
|
102
|
+
renderConfirmButtons(size) {
|
|
103
103
|
const validInterval = this.props.allowClear ?
|
|
104
104
|
(!this.state.currentFromValue || this.state.currentFromValue.isValid()) && (!this.state.currentToValue || this.state.currentToValue.isValid()) :
|
|
105
105
|
this.state.currentFromValue && this.state.currentFromValue.isValid() && this.state.currentToValue && this.state.currentToValue.isValid();
|
|
106
|
-
return (React.createElement(WithCss, { useStyles: useStyles }, ({ styles }
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
return (React.createElement(WithCss, { useStyles: useStyles, props: { size } }, ({ styles }, { size: mergedSize }) => {
|
|
107
|
+
const buttonWidth = mergedSize === "small" ? 48 : undefined;
|
|
108
|
+
return (React.createElement(Space.Compact, { className: styles.buttonsSurface },
|
|
109
|
+
React.createElement(Button, { className: styles.revertButton, style: { width: buttonWidth }, size: size, title: i18n("Revert"), key: "revert", danger: true, ghost: true, onClick: this.onRevert },
|
|
110
|
+
React.createElement(UndoIcon, null)),
|
|
111
|
+
React.createElement(Button, { style: { width: buttonWidth }, title: i18n("Apply"), key: "apply-button", size: size, type: "primary", disabled: !validInterval || this.state.invalidDatesPresent, onClick: this.onConfirm },
|
|
112
|
+
React.createElement(CheckOutlined, null))));
|
|
113
|
+
}));
|
|
111
114
|
}
|
|
112
115
|
confirmButtonsVisible() {
|
|
113
116
|
const { originalFromValue, originalToValue, currentFromValue, currentToValue } = this.state;
|
|
@@ -129,7 +132,7 @@ export default class DateRangeInputConfirm extends React.Component {
|
|
|
129
132
|
align = { points: ["tr", "br"], offset: [0, -6] };
|
|
130
133
|
}
|
|
131
134
|
return (React.createElement("span", { onKeyDown: this.onKeyDown, ref: this.parentRef },
|
|
132
|
-
React.createElement(Tooltip, { color: "transparent", styles: { body: { boxShadow: "none" } }, open: this.confirmButtonsVisible() && !this.state.popupVisible, align: align, title: this.renderConfirmButtons(rest.size
|
|
135
|
+
React.createElement(Tooltip, { color: "transparent", styles: { body: { boxShadow: "none" } }, open: this.confirmButtonsVisible() && !this.state.popupVisible, align: align, title: this.renderConfirmButtons(rest.size), getPopupContainer: () => {
|
|
133
136
|
var _a, _b;
|
|
134
137
|
// very nasty trick how remove error of ResizeObservers infinite cycling - because popover (with dynamic size) is placed in resizable panel
|
|
135
138
|
const parentNode = ((_b = (_a = this.parentRef.current) === null || _a === void 0 ? void 0 : _a.parentNode) !== null && _b !== void 0 ? _b : document.body);
|
|
@@ -145,7 +148,7 @@ export default class DateRangeInputConfirm extends React.Component {
|
|
|
145
148
|
});
|
|
146
149
|
}, confirmButtonsRenderer: () => {
|
|
147
150
|
if (this.confirmButtonsVisible()) {
|
|
148
|
-
return this.renderConfirmButtons("small"
|
|
151
|
+
return this.renderConfirmButtons("small");
|
|
149
152
|
}
|
|
150
153
|
return undefined;
|
|
151
154
|
}, onPopupVisibleChange: visible => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dateRangeInputConfirm.js","sourceRoot":"","sources":["../../../../components/date/dateRangeInputConfirm.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAC,MAAM,MAAM,CAAC;AAC5C,OAAO,EAAC,aAAa,EAAC,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAC,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAChD,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,cAAc,EAAE,EAAC,kBAAkB,EAAsB,MAAM,kBAAkB,CAAC;AAGzF,OAAO,EAAC,QAAQ,EAAC,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAC,GAAG,EAAC,MAAM,aAAa,CAAC;AAChC,OAAO,EAAC,YAAY,EAAC,MAAM,YAAY,CAAC;AACxC,OAAO,OAAO,MAAM,kBAAkB,CAAC;AAEvC,MAAM,SAAS,GAAG,YAAY,CAAC,CAAC,EAAC,KAAK,EAAE,GAAG,EAAC,EAAE,EAAE;IAC5C,OAAO;QACH,oGAAoG;QACpG,cAAc,EAAE,GAAG,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,EACtB,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE;wBAClB,IAAI,CAAC,QAAQ,CAAC,EAAC,mBAAmB,EAAE,IAAI,EAAC,CAAC,CAAC;oBAC/C,CAAC,EACD,QAAQ,EAAE,CAAC,SAAuB,EAAE,OAAqB,EAAE,EAAE;wBACzD,IAAI,CAAC,QAAQ,CAAC;4BACV,gBAAgB,EAAE,SAAS;4BAC3B,cAAc,EAAE,OAAO;4BACvB,mBAAmB,EAAE,KAAK;yBAC7B,CAAC,CAAA;oBACN,CAAC,EACD,sBAAsB,EAAE,GAAG,EAAE;wBACzB,IAAI,IAAI,CAAC,qBAAqB,EAAE,EAAE,CAAC;4BAC/B,OAAO,IAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;wBAClD,CAAC;wBACD,OAAO,SAAS,CAAC;oBACrB,CAAC,EACD,oBAAoB,EAAE,OAAO,CAAC,EAAE;wBAC5B,IAAI,CAAC,QAAQ,CAAC,EAAC,YAAY,EAAE,OAAO,EAAC,CAAC,CAAC;oBAC3C,CAAC,EACD,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAC5B,YAAY,EAAE,IAAI,CAAC,EAAE;wBACjB,IAAI,CAAC,QAAQ,CAAC,EAAC,IAAI,EAAE,IAAI,EAAC,CAAC,CAAC;oBAChC,CAAC,IACG,IAAI,EACV,CACI,CACP,CACV,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React, {createRef} from \"react\";\r\nimport {Dayjs} from \"dayjs\";\r\nimport {Button, Space, Tooltip} from \"antd\";\r\nimport {DateTimeUtils} from \"d2core/utils/dateTimeUtils\";\r\nimport {CheckOutlined} from \"@ant-design/icons\";\r\nimport i18n from \"d2core/i18n/i18n\";\r\nimport DateRangeInput, {DateRangeInputMode, DateRangeInputProps} from \"./dateRangeInput\";\r\nimport {TooltipPlacement} from \"antd/es/tooltip\";\r\nimport {AlignType} from \"@rc-component/trigger/lib/interface\";\r\nimport {UndoIcon} from \"../icons/undoIcon\";\r\nimport {SizeType} from \"antd/lib/config-provider/SizeContext\";\r\nimport {Key} from \"ts-key-enum\";\r\nimport {createStyles} from \"antd-style\";\r\nimport WithCss from \"../style/withCss\";\r\n\r\nconst useStyles = createStyles(({token, css}) => {\r\n return {\r\n // the confirm buttons float above the page on a transparent tooltip, so they need their own surface\r\n buttonsSurface: css`\r\n background: ${token.colorBgElevated};\r\n `,\r\n // ghost button is transparent by default - give it the same opaque surface\r\n revertButton: css`\r\n background: ${token.colorBgElevated};\r\n border-right-width: 2px;\r\n `,\r\n }\r\n});\r\n\r\n/**\r\n * Props of {@link DateRangeInputConfirm} - those of {@link DateRangeInput}, except that `onChange` is called only\r\n * on confirmation. `onInvalidValue`, `onPopupVisibleChange`, `onModeChange`, `defaultMode` and\r\n * `confirmButtonsRenderer` are used internally and passing them overrides the confirm behaviour.\r\n */\r\ninterface DateRangeInputConfirmProps extends DateRangeInputProps {\r\n /** Shows the confirm buttons from the start, even before anything is changed, until the first confirmation. */\r\n requireConfirmationAtStart?: boolean\r\n /**\r\n * Where the floating confirm buttons are shown next to the input: `\"right\"`, `\"topRight\"`; any other value\r\n * (or none) means below the right edge.\r\n */\r\n confirmPlacement?: TooltipPlacement\r\n}\r\n\r\ninterface DateRangeInputConfirmState {\r\n originalFromValue: Dayjs | null\r\n originalToValue: Dayjs | null\r\n currentFromValue: Dayjs | null\r\n currentToValue: Dayjs | null\r\n invalidDatesPresent: boolean\r\n requireConfirmation: boolean\r\n\r\n popupVisible: boolean\r\n mode: DateRangeInputMode\r\n}\r\n\r\n/**\r\n * {@link DateRangeInput} that buffers edits and reports them through `onChange` only when confirmed with the\r\n * Apply button or Enter; the Revert button or Escape restores the last value from props. The Revert/Apply buttons\r\n * float next to the input (and appear in the popup footer) while the range differs from the props, contains an\r\n * invalid text or {@link DateRangeInputConfirmProps.requireConfirmationAtStart} is pending. A change of\r\n * `fromValue`/`toValue` from props discards the buffered edit.\r\n */\r\nexport default class DateRangeInputConfirm extends React.Component<DateRangeInputConfirmProps, DateRangeInputConfirmState> {\r\n private dateRangeInput: DateRangeInput | null = null;\r\n private parentRef: React.RefObject<HTMLSpanElement> = createRef();\r\n\r\n constructor(props: Readonly<DateRangeInputConfirmProps>) {\r\n super(props);\r\n this.state = {\r\n originalFromValue: props.fromValue ?? null,\r\n originalToValue: props.toValue ?? null,\r\n currentFromValue: props.fromValue ?? null,\r\n currentToValue: props.toValue ?? null,\r\n invalidDatesPresent: false,\r\n requireConfirmation: !!props.requireConfirmationAtStart,\r\n\r\n popupVisible: false,\r\n mode: props.defaultMode ?? DateRangeInputMode.SIMPLE,\r\n };\r\n\r\n this.onKeyDown = this.onKeyDown.bind(this);\r\n this.onConfirm = this.onConfirm.bind(this);\r\n this.onRevert = this.onRevert.bind(this);\r\n }\r\n\r\n /** Confirms on Enter and reverts on Escape; attached to the wrapping element. */\r\n onKeyDown(event: React.KeyboardEvent) {\r\n if (event.key === Key.Enter) {\r\n this.onConfirm();\r\n } else if (event.key === Key.Escape) {\r\n this.onRevert();\r\n }\r\n }\r\n\r\n componentDidUpdate(prevProps: Readonly<DateRangeInputProps>) {\r\n const preFromValueUnixTime = DateTimeUtils.toUnixTime(prevProps.fromValue);\r\n const currentFromValueUnixTime = DateTimeUtils.toUnixTime(this.props.fromValue);\r\n const prevToValueUnixTime = DateTimeUtils.toUnixTime(prevProps.toValue);\r\n const currentToValueUnixTime = DateTimeUtils.toUnixTime(this.props.toValue);\r\n if (preFromValueUnixTime !== currentFromValueUnixTime ||\r\n prevToValueUnixTime !== currentToValueUnixTime) {\r\n this.setState({\r\n originalFromValue: this.props.fromValue ?? null,\r\n originalToValue: this.props.toValue ?? null,\r\n currentFromValue: this.props.fromValue ?? null,\r\n currentToValue: this.props.toValue ?? null\r\n })\r\n }\r\n }\r\n\r\n private onConfirm() {\r\n this.setState({requireConfirmation: false});\r\n this.props.onChange?.(this.state.currentFromValue, this.state.currentToValue);\r\n this.dateRangeInput?.closePopup();\r\n }\r\n\r\n private onRevert() {\r\n this.setState({\r\n currentFromValue: this.state.originalFromValue ?? null,\r\n currentToValue: this.state.originalToValue ?? null,\r\n invalidDatesPresent: false,\r\n });\r\n this.dateRangeInput?.closePopup();\r\n }\r\n\r\n private renderConfirmButtons(size?: SizeType, buttonWidth?: number) {\r\n const validInterval = this.props.allowClear ?\r\n (!this.state.currentFromValue || this.state.currentFromValue.isValid()) && (!this.state.currentToValue || this.state.currentToValue.isValid()) :\r\n this.state.currentFromValue && this.state.currentFromValue.isValid() && this.state.currentToValue && this.state.currentToValue.isValid();\r\n\r\n return (\r\n <WithCss useStyles={useStyles}>{({styles}) =>\r\n <Space.Compact className={styles.buttonsSurface}>\r\n <Button\r\n className={styles.revertButton}\r\n style={{width: buttonWidth}}\r\n size={size}\r\n title={i18n(\"Revert\")}\r\n key=\"revert\"\r\n danger\r\n ghost\r\n onClick={this.onRevert}\r\n >\r\n <UndoIcon/>\r\n </Button>\r\n <Button\r\n style={{width: buttonWidth}}\r\n title={i18n(\"Apply\")} key=\"apply-button\"\r\n size={size}\r\n type=\"primary\"\r\n disabled={!validInterval || this.state.invalidDatesPresent}\r\n onClick={this.onConfirm}\r\n >\r\n <CheckOutlined/>\r\n </Button>\r\n </Space.Compact>\r\n }</WithCss>\r\n );\r\n }\r\n\r\n private confirmButtonsVisible() {\r\n const {originalFromValue, originalToValue, currentFromValue, currentToValue} = this.state;\r\n const valueChanged = DateTimeUtils.toUnixTime(currentFromValue) !== DateTimeUtils.toUnixTime(originalFromValue) ||\r\n DateTimeUtils.toUnixTime(currentToValue) !== DateTimeUtils.toUnixTime(originalToValue);\r\n\r\n return valueChanged || this.state.invalidDatesPresent || this.state.requireConfirmation;\r\n }\r\n\r\n render(): any {\r\n const {\r\n fromValue,\r\n toValue,\r\n onChange,\r\n allowClear,\r\n requireConfirmationAtStart,\r\n confirmPlacement,\r\n compact,\r\n ...rest\r\n } = this.props;\r\n let align: AlignType;\r\n if (confirmPlacement === \"right\") {\r\n align = {points: [\"tl\", \"tr\"], offset: [-8, 0]};\r\n } else if (confirmPlacement === \"topRight\") {\r\n align = {points: [\"br\", \"tr\"], offset: [0, 8]};\r\n } else {\r\n // default bottomRight\r\n align = {points: [\"tr\", \"br\"], offset: [0, -6]};\r\n }\r\n return (\r\n <span onKeyDown={this.onKeyDown} ref={this.parentRef}>\r\n <Tooltip\r\n color={\"transparent\"}\r\n styles={{body: {boxShadow: \"none\"}}}\r\n open={this.confirmButtonsVisible() && !this.state.popupVisible}\r\n align={align}\r\n title={this.renderConfirmButtons(rest.size, rest.size === \"small\" ? 48 : undefined)}\r\n getPopupContainer={() => {\r\n // very nasty trick how remove error of ResizeObservers infinite cycling - because popover (with dynamic size) is placed in resizable panel\r\n const parentNode = (this.parentRef.current?.parentNode ?? document.body) as HTMLElement;\r\n return parentNode;\r\n }}\r\n >\r\n <DateRangeInput\r\n ref={component => this.dateRangeInput = component}\r\n fromValue={this.state.currentFromValue}\r\n toValue={this.state.currentToValue}\r\n allowClear={allowClear}\r\n compact={compact}\r\n onInvalidValue={(_) => {\r\n this.setState({invalidDatesPresent: true});\r\n }}\r\n onChange={(fromValue: Dayjs | null, toValue: Dayjs | null) => {\r\n this.setState({\r\n currentFromValue: fromValue,\r\n currentToValue: toValue,\r\n invalidDatesPresent: false,\r\n })\r\n }}\r\n confirmButtonsRenderer={() => {\r\n if (this.confirmButtonsVisible()) {\r\n return this.renderConfirmButtons(\"small\", 48);\r\n }\r\n return undefined;\r\n }}\r\n onPopupVisibleChange={visible => {\r\n this.setState({popupVisible: visible});\r\n }}\r\n defaultMode={this.state.mode}\r\n onModeChange={mode => {\r\n this.setState({mode: mode});\r\n }}\r\n {...rest}\r\n />\r\n </Tooltip>\r\n </span>\r\n );\r\n }\r\n}"]}
|
|
1
|
+
{"version":3,"file":"dateRangeInputConfirm.js","sourceRoot":"","sources":["../../../../components/date/dateRangeInputConfirm.tsx"],"names":[],"mappings":";;;;;;;;;;;AAAA,OA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C,oBAAoB,CAAC,OAAO,CAAC,CAAC;wBAC9C,CAAC;wBACD,OAAO,SAAS,CAAC;oBACrB,CAAC,EACD,oBAAoB,EAAE,OAAO,CAAC,EAAE;wBAC5B,IAAI,CAAC,QAAQ,CAAC,EAAC,YAAY,EAAE,OAAO,EAAC,CAAC,CAAC;oBAC3C,CAAC,EACD,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,EAC5B,YAAY,EAAE,IAAI,CAAC,EAAE;wBACjB,IAAI,CAAC,QAAQ,CAAC,EAAC,IAAI,EAAE,IAAI,EAAC,CAAC,CAAC;oBAChC,CAAC,IACG,IAAI,EACV,CACI,CACP,CACV,CAAC;IACN,CAAC;CACJ","sourcesContent":["import React, {createRef} from \"react\";\nimport {Dayjs} from \"dayjs\";\nimport {Button, Space, Tooltip} from \"antd\";\nimport {DateTimeUtils} from \"d2core/utils/dateTimeUtils\";\nimport {CheckOutlined} from \"@ant-design/icons\";\nimport i18n from \"d2core/i18n/i18n\";\nimport DateRangeInput, {DateRangeInputMode, DateRangeInputProps} from \"./dateRangeInput\";\nimport {TooltipPlacement} from \"antd/es/tooltip\";\nimport {AlignType} from \"@rc-component/trigger/lib/interface\";\nimport {UndoIcon} from \"../icons/undoIcon\";\nimport {SizeType} from \"antd/lib/config-provider/SizeContext\";\nimport {Key} from \"ts-key-enum\";\nimport {createStyles} from \"antd-style\";\nimport WithCss from \"../style/withCss\";\n\nconst useStyles = createStyles(({token, css}) => {\n return {\n // the confirm buttons float above the page on a transparent tooltip, so they need their own surface\n buttonsSurface: css`\n background: ${token.colorBgElevated};\n `,\n // ghost button is transparent by default - give it the same opaque surface\n revertButton: css`\n background: ${token.colorBgElevated};\n border-right-width: 2px;\n `,\n }\n});\n\n/**\n * Props of {@link DateRangeInputConfirm} - those of {@link DateRangeInput}, except that `onChange` is called only\n * on confirmation. `onInvalidValue`, `onPopupVisibleChange`, `onModeChange`, `defaultMode` and\n * `confirmButtonsRenderer` are used internally and passing them overrides the confirm behaviour.\n */\ninterface DateRangeInputConfirmProps extends DateRangeInputProps {\n /** Shows the confirm buttons from the start, even before anything is changed, until the first confirmation. */\n requireConfirmationAtStart?: boolean\n /**\n * Where the floating confirm buttons are shown next to the input: `\"right\"`, `\"topRight\"`; any other value\n * (or none) means below the right edge.\n */\n confirmPlacement?: TooltipPlacement\n}\n\ninterface DateRangeInputConfirmState {\n originalFromValue: Dayjs | null\n originalToValue: Dayjs | null\n currentFromValue: Dayjs | null\n currentToValue: Dayjs | null\n invalidDatesPresent: boolean\n requireConfirmation: boolean\n\n popupVisible: boolean\n mode: DateRangeInputMode\n}\n\n/**\n * {@link DateRangeInput} that buffers edits and reports them through `onChange` only when confirmed with the\n * Apply button or Enter; the Revert button or Escape restores the last value from props. The Revert/Apply buttons\n * float next to the input (and appear in the popup footer) while the range differs from the props, contains an\n * invalid text or {@link DateRangeInputConfirmProps.requireConfirmationAtStart} is pending. A change of\n * `fromValue`/`toValue` from props discards the buffered edit.\n */\nexport default class DateRangeInputConfirm extends React.Component<DateRangeInputConfirmProps, DateRangeInputConfirmState> {\n private dateRangeInput: DateRangeInput | null = null;\n private parentRef: React.RefObject<HTMLSpanElement> = createRef();\n\n constructor(props: Readonly<DateRangeInputConfirmProps>) {\n super(props);\n this.state = {\n originalFromValue: props.fromValue ?? null,\n originalToValue: props.toValue ?? null,\n currentFromValue: props.fromValue ?? null,\n currentToValue: props.toValue ?? null,\n invalidDatesPresent: false,\n requireConfirmation: !!props.requireConfirmationAtStart,\n\n popupVisible: false,\n mode: props.defaultMode ?? DateRangeInputMode.SIMPLE,\n };\n\n this.onKeyDown = this.onKeyDown.bind(this);\n this.onConfirm = this.onConfirm.bind(this);\n this.onRevert = this.onRevert.bind(this);\n }\n\n /** Confirms on Enter and reverts on Escape; attached to the wrapping element. */\n onKeyDown(event: React.KeyboardEvent) {\n if (event.key === Key.Enter) {\n this.onConfirm();\n } else if (event.key === Key.Escape) {\n this.onRevert();\n }\n }\n\n componentDidUpdate(prevProps: Readonly<DateRangeInputProps>) {\n const preFromValueUnixTime = DateTimeUtils.toUnixTime(prevProps.fromValue);\n const currentFromValueUnixTime = DateTimeUtils.toUnixTime(this.props.fromValue);\n const prevToValueUnixTime = DateTimeUtils.toUnixTime(prevProps.toValue);\n const currentToValueUnixTime = DateTimeUtils.toUnixTime(this.props.toValue);\n if (preFromValueUnixTime !== currentFromValueUnixTime ||\n prevToValueUnixTime !== currentToValueUnixTime) {\n this.setState({\n originalFromValue: this.props.fromValue ?? null,\n originalToValue: this.props.toValue ?? null,\n currentFromValue: this.props.fromValue ?? null,\n currentToValue: this.props.toValue ?? null\n })\n }\n }\n\n private onConfirm() {\n this.setState({requireConfirmation: false});\n this.props.onChange?.(this.state.currentFromValue, this.state.currentToValue);\n this.dateRangeInput?.closePopup();\n }\n\n private onRevert() {\n this.setState({\n currentFromValue: this.state.originalFromValue ?? null,\n currentToValue: this.state.originalToValue ?? null,\n invalidDatesPresent: false,\n });\n this.dateRangeInput?.closePopup();\n }\n\n private renderConfirmButtons(size?: SizeType) {\n const validInterval = this.props.allowClear ?\n (!this.state.currentFromValue || this.state.currentFromValue.isValid()) && (!this.state.currentToValue || this.state.currentToValue.isValid()) :\n this.state.currentFromValue && this.state.currentFromValue.isValid() && this.state.currentToValue && this.state.currentToValue.isValid();\n\n return (\n <WithCss useStyles={useStyles} props={{size}}>{({styles}, {size: mergedSize}) => {\n const buttonWidth = mergedSize === \"small\" ? 48 : undefined;\n return (\n <Space.Compact className={styles.buttonsSurface}>\n <Button\n className={styles.revertButton}\n style={{width: buttonWidth}}\n size={size}\n title={i18n(\"Revert\")}\n key=\"revert\"\n danger\n ghost\n onClick={this.onRevert}\n >\n <UndoIcon/>\n </Button>\n <Button\n style={{width: buttonWidth}}\n title={i18n(\"Apply\")} key=\"apply-button\"\n size={size}\n type=\"primary\"\n disabled={!validInterval || this.state.invalidDatesPresent}\n onClick={this.onConfirm}\n >\n <CheckOutlined/>\n </Button>\n </Space.Compact>\n );\n }}</WithCss>\n );\n }\n\n private confirmButtonsVisible() {\n const {originalFromValue, originalToValue, currentFromValue, currentToValue} = this.state;\n const valueChanged = DateTimeUtils.toUnixTime(currentFromValue) !== DateTimeUtils.toUnixTime(originalFromValue) ||\n DateTimeUtils.toUnixTime(currentToValue) !== DateTimeUtils.toUnixTime(originalToValue);\n\n return valueChanged || this.state.invalidDatesPresent || this.state.requireConfirmation;\n }\n\n render(): any {\n const {\n fromValue,\n toValue,\n onChange,\n allowClear,\n requireConfirmationAtStart,\n confirmPlacement,\n compact,\n ...rest\n } = this.props;\n let align: AlignType;\n if (confirmPlacement === \"right\") {\n align = {points: [\"tl\", \"tr\"], offset: [-8, 0]};\n } else if (confirmPlacement === \"topRight\") {\n align = {points: [\"br\", \"tr\"], offset: [0, 8]};\n } else {\n // default bottomRight\n align = {points: [\"tr\", \"br\"], offset: [0, -6]};\n }\n return (\n <span onKeyDown={this.onKeyDown} ref={this.parentRef}>\n <Tooltip\n color={\"transparent\"}\n styles={{body: {boxShadow: \"none\"}}}\n open={this.confirmButtonsVisible() && !this.state.popupVisible}\n align={align}\n title={this.renderConfirmButtons(rest.size)}\n getPopupContainer={() => {\n // very nasty trick how remove error of ResizeObservers infinite cycling - because popover (with dynamic size) is placed in resizable panel\n const parentNode = (this.parentRef.current?.parentNode ?? document.body) as HTMLElement;\n return parentNode;\n }}\n >\n <DateRangeInput\n ref={component => this.dateRangeInput = component}\n fromValue={this.state.currentFromValue}\n toValue={this.state.currentToValue}\n allowClear={allowClear}\n compact={compact}\n onInvalidValue={(_) => {\n this.setState({invalidDatesPresent: true});\n }}\n onChange={(fromValue: Dayjs | null, toValue: Dayjs | null) => {\n this.setState({\n currentFromValue: fromValue,\n currentToValue: toValue,\n invalidDatesPresent: false,\n })\n }}\n confirmButtonsRenderer={() => {\n if (this.confirmButtonsVisible()) {\n return this.renderConfirmButtons(\"small\");\n }\n return undefined;\n }}\n onPopupVisibleChange={visible => {\n this.setState({popupVisible: visible});\n }}\n defaultMode={this.state.mode}\n onModeChange={mode => {\n this.setState({mode: mode});\n }}\n {...rest}\n />\n </Tooltip>\n </span>\n );\n }\n}"]}
|
|
@@ -69,10 +69,19 @@ const useStyles = createStyles(({ token, css }, props) => {
|
|
|
69
69
|
padding-bottom: 0 !important;
|
|
70
70
|
}
|
|
71
71
|
`,
|
|
72
|
+
// the calendar icon is centred on this wrapper, not on the root, which a flex parent may stretch; as a block
|
|
73
|
+
// it would put the inline-block antd input on a line box and grow by the descender gap
|
|
74
|
+
inputWrapper: css `
|
|
75
|
+
display: flex;
|
|
76
|
+
position: relative;
|
|
77
|
+
`,
|
|
78
|
+
suffixIconHost: css `
|
|
79
|
+
display: flex;
|
|
80
|
+
align-items: center;
|
|
81
|
+
justify-content: center;
|
|
82
|
+
`,
|
|
72
83
|
suffixIcon: css `
|
|
73
84
|
color: ${token.colorTextQuaternary};
|
|
74
|
-
vertical-align: middle;
|
|
75
|
-
height: 100%;
|
|
76
85
|
`,
|
|
77
86
|
// antd colours the affix by status - see `genOutlinedStatusStyle.affixColor`
|
|
78
87
|
suffixIconError: css `
|
|
@@ -494,20 +503,22 @@ export default class DateTimeInput extends React.Component {
|
|
|
494
503
|
// the root has to stay a plain DOM element - Tooltip in render() clones it to inject
|
|
495
504
|
// its trigger handlers, and a WithCss root would swallow them
|
|
496
505
|
return (React.createElement("div", Object.assign({ style: Object.assign(Object.assign(Object.assign({}, (autoWidth ? { width: "fit-content" } : {})), style), { position: "relative" }) }, props, { className: className }),
|
|
497
|
-
React.createElement(WithCss, { useStyles: useStyles, props: { variant } }, ({ styles, cx, theme }) => {
|
|
506
|
+
React.createElement(WithCss, { useStyles: useStyles, props: { variant, size } }, ({ styles, cx, theme }, { size: mergedSize }) => {
|
|
498
507
|
var _a;
|
|
499
508
|
const maskedInputStyle = !this.state.valid ? { color: theme.colorError } : {};
|
|
500
509
|
if (autoWidth) {
|
|
501
510
|
Object.assign(maskedInputStyle, {
|
|
511
|
+
// the measured width is the minimum - the input still fills a root stretched by the caller
|
|
512
|
+
flexGrow: 1,
|
|
502
513
|
boxSizing: "content-box",
|
|
503
|
-
width: this.getInputTextWidth(theme.fontFamily,
|
|
514
|
+
width: this.getInputTextWidth(theme.fontFamily, mergedSize === "large" ? theme.fontSizeLG : theme.fontSize),
|
|
504
515
|
}, !hidePopup && { paddingRight: CALENDAR_ICON_WIDTH });
|
|
505
516
|
}
|
|
506
517
|
if (inputStyle) {
|
|
507
518
|
Object.assign(maskedInputStyle, inputStyle);
|
|
508
519
|
}
|
|
509
520
|
return (React.createElement(React.Fragment, null,
|
|
510
|
-
React.createElement("div", { className: cx({ [styles.disabledText]: !!disabled }), onKeyDown: (event) => {
|
|
521
|
+
React.createElement("div", { className: cx(styles.inputWrapper, { [styles.disabledText]: !!disabled }), onKeyDown: (event) => {
|
|
511
522
|
if (event.code === "ArrowUp") { // up
|
|
512
523
|
this.increment();
|
|
513
524
|
event.preventDefault();
|
|
@@ -541,29 +552,28 @@ export default class DateTimeInput extends React.Component {
|
|
|
541
552
|
valid: valid,
|
|
542
553
|
currentInfo: value
|
|
543
554
|
});
|
|
544
|
-
} })
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
}) }))));
|
|
555
|
+
} }),
|
|
556
|
+
!hidePopup && !renderAsCalendar && React.createElement("div", { className: styles.suffixIconHost, style: {
|
|
557
|
+
width: CALENDAR_ICON_WIDTH,
|
|
558
|
+
opacity: 1,
|
|
559
|
+
height: "100%",
|
|
560
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
561
|
+
background: "transparent",
|
|
562
|
+
position: "absolute",
|
|
563
|
+
top: 0,
|
|
564
|
+
right: 0,
|
|
565
|
+
}, onClick: (event) => {
|
|
566
|
+
if (document.createEvent) {
|
|
567
|
+
var ev = document.createEvent('HTMLEvents');
|
|
568
|
+
ev.initEvent('contextmenu', true, false);
|
|
569
|
+
event.target.dispatchEvent(ev);
|
|
570
|
+
}
|
|
571
|
+
} },
|
|
572
|
+
React.createElement(CalendarOutlined, { className: cx(styles.suffixIcon, {
|
|
573
|
+
[styles.suffixIconError]: !disabled && mergedStatus === "error",
|
|
574
|
+
[styles.suffixIconWarning]: !disabled && mergedStatus === "warning",
|
|
575
|
+
[styles.suffixIconDisabled]: !!disabled,
|
|
576
|
+
}) })))));
|
|
567
577
|
})));
|
|
568
578
|
}
|
|
569
579
|
render() {
|