d2coreui 23.0.54 → 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 +65 -40
- package/README.md +154 -154
- package/components/date/dateRangeInput.d.ts +5 -0
- package/components/date/dateRangeInput.js +20 -11
- 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.d.ts +12 -0
- package/components/date/dateTimeInput.js +72 -30
- package/components/date/dateTimeInput.js.map +1 -1
- package/components/grid/dataGrid.js +3 -3
- package/components/grid/dataGrid.js.map +1 -1
- package/components/grid/export/worker/pdfExport.js.map +1 -1
- package/components/grid/extendedDataGrid.js +8 -8
- package/components/grid/extendedDataGrid.js.map +1 -1
- package/components/modal/impl/draggableModalStyles.js +126 -126
- package/components/modal/impl/draggableModalStyles.js.map +1 -1
- package/components/modal/impl/resizeHandle.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
- package/style/index.less +240 -240
|
@@ -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,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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,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,CAAA;0BACD,KAAK,CAAC,eAAe;SACtC;QACD,2EAA2E;QAC3E,YAAY,EAAE,GAAG,CAAA;0BACC,KAAK,CAAC,eAAe;;SAEtC;KACJ,CAAA;AACL,CAAC,CAAC,CAAC;AA6BH;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAA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AAC,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,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}"]}
|
|
@@ -58,6 +58,11 @@ interface DateTimeInputProps extends Omit<HTMLAttributes<HTMLDivElement>, "onCha
|
|
|
58
58
|
placement?: TooltipPlacement;
|
|
59
59
|
/** antd control size. */
|
|
60
60
|
size?: SizeType;
|
|
61
|
+
/**
|
|
62
|
+
* Sizes the component to the rendered {@link DateTimeInputProps.mask} instead of filling the parent: the input
|
|
63
|
+
* is as wide as the formatted value. A `width` in `style` or `inputStyle` still wins.
|
|
64
|
+
*/
|
|
65
|
+
autoWidth?: boolean;
|
|
61
66
|
/** Day whose month the calendar shows initially and whenever the popup opens, instead of the value's month. */
|
|
62
67
|
defaultSelectedDate?: Dayjs;
|
|
63
68
|
/** Inclusive range of days highlighted in the calendar as selected. Intended for range pickers. */
|
|
@@ -182,6 +187,13 @@ export default class DateTimeInput extends React.Component<DateTimeInputProps, D
|
|
|
182
187
|
private renderCalendarNavigation;
|
|
183
188
|
/** Renders the calendar panel - the popup content, or the whole component with {@link DateTimeInputProps.renderAsCalendar}. */
|
|
184
189
|
renderCalendar(): React.ReactElement;
|
|
190
|
+
/**
|
|
191
|
+
* Width of the formatted {@link DateTimeInputProps.mask} in the font antd gives the input (`fontSizeLG` for
|
|
192
|
+
* `large`, `fontSize` otherwise). Computed from the theme rather than read from the DOM, so it is right in the
|
|
193
|
+
* very first render - a later correction would be animated by the input's `transition`.
|
|
194
|
+
* `tabular-nums` must stay off - in Segoe UI it widens the digits past the measured "0" and the value overflows.
|
|
195
|
+
*/
|
|
196
|
+
private getInputTextWidth;
|
|
185
197
|
/** Renders the masked input with its calendar icon, without the popup. */
|
|
186
198
|
renderInput(): React.JSX.Element;
|
|
187
199
|
render(): any;
|
|
@@ -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 `
|
|
@@ -193,6 +202,16 @@ function buildMaskLayout(mask) {
|
|
|
193
202
|
}
|
|
194
203
|
return { pattern, segments };
|
|
195
204
|
}
|
|
205
|
+
const CALENDAR_ICON_WIDTH = 28;
|
|
206
|
+
let measureContext = null;
|
|
207
|
+
function measureTextWidth(text, font) {
|
|
208
|
+
measureContext !== null && measureContext !== void 0 ? measureContext : (measureContext = document.createElement("canvas").getContext("2d"));
|
|
209
|
+
if (!measureContext) {
|
|
210
|
+
return 0;
|
|
211
|
+
}
|
|
212
|
+
measureContext.font = font;
|
|
213
|
+
return measureContext.measureText(text).width;
|
|
214
|
+
}
|
|
196
215
|
/**
|
|
197
216
|
* Masked date-time input with a calendar popup - a controlled replacement for antd `DatePicker`.
|
|
198
217
|
* The value is typed field by field according to {@link DateTimeInputProps.mask}; ArrowUp/ArrowDown and the
|
|
@@ -248,10 +267,15 @@ export default class DateTimeInput extends React.Component {
|
|
|
248
267
|
this.onItemMouseOver = debounce(this.onItemMouseOver.bind(this), 100, { maxWait: 100 });
|
|
249
268
|
}
|
|
250
269
|
componentDidMount() {
|
|
251
|
-
var _a;
|
|
270
|
+
var _a, _b;
|
|
252
271
|
// React registers `wheel` as a passive listener, so preventDefault() from an onWheel
|
|
253
272
|
// prop is ignored and the page scrolls along with the value - hence a native listener
|
|
254
273
|
(_a = this.input) === null || _a === void 0 ? void 0 : _a.addEventListener("wheel", this.onWheel, { passive: false });
|
|
274
|
+
(_b = document.fonts) === null || _b === void 0 ? void 0 : _b.ready.then(() => {
|
|
275
|
+
if (this.props.autoWidth) {
|
|
276
|
+
this.forceUpdate();
|
|
277
|
+
}
|
|
278
|
+
});
|
|
255
279
|
}
|
|
256
280
|
componentWillUnmount() {
|
|
257
281
|
var _a;
|
|
@@ -459,23 +483,42 @@ export default class DateTimeInput extends React.Component {
|
|
|
459
483
|
this.setState({ popupCalendarVisible: false });
|
|
460
484
|
} }, i18n("Today")))));
|
|
461
485
|
}
|
|
486
|
+
/**
|
|
487
|
+
* Width of the formatted {@link DateTimeInputProps.mask} in the font antd gives the input (`fontSizeLG` for
|
|
488
|
+
* `large`, `fontSize` otherwise). Computed from the theme rather than read from the DOM, so it is right in the
|
|
489
|
+
* very first render - a later correction would be animated by the input's `transition`.
|
|
490
|
+
* `tabular-nums` must stay off - in Segoe UI it widens the digits past the measured "0" and the value overflows.
|
|
491
|
+
*/
|
|
492
|
+
getInputTextWidth(fontFamily, fontSize) {
|
|
493
|
+
// all digits as "0" so that the width holds for any value, not just today's
|
|
494
|
+
const sample = dayjs().locale("locale.d2000").format(this.props.mask).replace(/\d/g, "0");
|
|
495
|
+
return Math.ceil(measureTextWidth(sample, `${fontSize}px ${fontFamily}`));
|
|
496
|
+
}
|
|
462
497
|
/** Renders the masked input with its calendar icon, without the popup. */
|
|
463
498
|
renderInput() {
|
|
464
|
-
const _a = this.props, { mask, value, onChange, onInvalidValue, style, disabled, inputDisabled, variant, hidePopup, renderAsCalendar, allowClear, minDateTime, maxDateTime, onDateItemMouseDown, onDateItemMouseOver, onDateItemMouseUp, markedDateInterval, inputStyle, getPopupContainer, autoFocus, className, size, status } = _a, props = __rest(_a, ["mask", "value", "onChange", "onInvalidValue", "style", "disabled", "inputDisabled", "variant", "hidePopup", "renderAsCalendar", "allowClear", "minDateTime", "maxDateTime", "onDateItemMouseDown", "onDateItemMouseOver", "onDateItemMouseUp", "markedDateInterval", "inputStyle", "getPopupContainer", "autoFocus", "className", "size", "status"]);
|
|
499
|
+
const _a = this.props, { mask, value, onChange, onInvalidValue, style, disabled, inputDisabled, variant, hidePopup, renderAsCalendar, allowClear, minDateTime, maxDateTime, onDateItemMouseDown, onDateItemMouseOver, onDateItemMouseUp, markedDateInterval, inputStyle, getPopupContainer, autoFocus, className, size, status, autoWidth } = _a, props = __rest(_a, ["mask", "value", "onChange", "onInvalidValue", "style", "disabled", "inputDisabled", "variant", "hidePopup", "renderAsCalendar", "allowClear", "minDateTime", "maxDateTime", "onDateItemMouseDown", "onDateItemMouseOver", "onDateItemMouseUp", "markedDateInterval", "inputStyle", "getPopupContainer", "autoFocus", "className", "size", "status", "autoWidth"]);
|
|
465
500
|
const unix = value === null || value === void 0 ? void 0 : value.valueOf();
|
|
466
501
|
// an unparseable input is an error even when the caller reports no status
|
|
467
502
|
const mergedStatus = status || (!this.state.valid ? "error" : "");
|
|
468
503
|
// the root has to stay a plain DOM element - Tooltip in render() clones it to inject
|
|
469
504
|
// its trigger handlers, and a WithCss root would swallow them
|
|
470
|
-
return (React.createElement("div", Object.assign({ style: Object.assign(Object.assign({}, style), { position: "relative" }) }, props, { className: className }),
|
|
471
|
-
React.createElement(WithCss, { useStyles: useStyles, props: { variant } }, ({ styles, cx, theme }) => {
|
|
505
|
+
return (React.createElement("div", Object.assign({ style: Object.assign(Object.assign(Object.assign({}, (autoWidth ? { width: "fit-content" } : {})), style), { position: "relative" }) }, props, { className: className }),
|
|
506
|
+
React.createElement(WithCss, { useStyles: useStyles, props: { variant, size } }, ({ styles, cx, theme }, { size: mergedSize }) => {
|
|
472
507
|
var _a;
|
|
473
508
|
const maskedInputStyle = !this.state.valid ? { color: theme.colorError } : {};
|
|
509
|
+
if (autoWidth) {
|
|
510
|
+
Object.assign(maskedInputStyle, {
|
|
511
|
+
// the measured width is the minimum - the input still fills a root stretched by the caller
|
|
512
|
+
flexGrow: 1,
|
|
513
|
+
boxSizing: "content-box",
|
|
514
|
+
width: this.getInputTextWidth(theme.fontFamily, mergedSize === "large" ? theme.fontSizeLG : theme.fontSize),
|
|
515
|
+
}, !hidePopup && { paddingRight: CALENDAR_ICON_WIDTH });
|
|
516
|
+
}
|
|
474
517
|
if (inputStyle) {
|
|
475
518
|
Object.assign(maskedInputStyle, inputStyle);
|
|
476
519
|
}
|
|
477
520
|
return (React.createElement(React.Fragment, null,
|
|
478
|
-
React.createElement("div", { className: cx({ [styles.disabledText]: !!disabled }), onKeyDown: (event) => {
|
|
521
|
+
React.createElement("div", { className: cx(styles.inputWrapper, { [styles.disabledText]: !!disabled }), onKeyDown: (event) => {
|
|
479
522
|
if (event.code === "ArrowUp") { // up
|
|
480
523
|
this.increment();
|
|
481
524
|
event.preventDefault();
|
|
@@ -509,29 +552,28 @@ export default class DateTimeInput extends React.Component {
|
|
|
509
552
|
valid: valid,
|
|
510
553
|
currentInfo: value
|
|
511
554
|
});
|
|
512
|
-
} })
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
}) }))));
|
|
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
|
+
}) })))));
|
|
535
577
|
})));
|
|
536
578
|
}
|
|
537
579
|
render() {
|