d2coreui 23.0.43 → 23.0.45

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.
@@ -2,6 +2,8 @@ import React, { HTMLAttributes } from "react";
2
2
  import { Dayjs } from "dayjs";
3
3
  import { TooltipPlacement } from "antd/es/tooltip";
4
4
  import { SizeType } from "antd/lib/config-provider/SizeContext";
5
+ import { InputStatus } from "antd/es/_util/statusUtils";
6
+ import { Variant } from "antd/es/config-provider";
5
7
  export declare enum DateRangeInputMode {
6
8
  SIMPLE = 0,
7
9
  ADVANCED = 1
@@ -20,6 +22,8 @@ export interface DateRangeInputProps extends Omit<HTMLAttributes<HTMLDivElement>
20
22
  [rangeName: string]: () => [Dayjs, Dayjs];
21
23
  };
22
24
  size?: SizeType;
25
+ status?: InputStatus;
26
+ variant?: Variant;
23
27
  compact?: boolean;
24
28
  hidePopup?: boolean;
25
29
  renderAsCalendar?: boolean;
@@ -21,71 +21,335 @@ import DateRangeInputAdvancedPanel, { TimeShiftDirection } from "./dateRangeInpu
21
21
  import WithCss from "../style/withCss";
22
22
  import { createStyles } from "antd-style";
23
23
  const useStyles = createStyles(({ token, css }, props) => {
24
- const { size = 'middle' } = props;
24
+ const { size, variant } = props;
25
25
  const heightMap = {
26
26
  small: token.controlHeightSM,
27
27
  middle: token.controlHeight,
28
28
  large: token.controlHeightLG,
29
29
  };
30
+ const paddingInlineMap = {
31
+ small: token.controlPaddingHorizontalSM - token.lineWidth,
32
+ middle: token.paddingSM - token.lineWidth,
33
+ large: token.controlPaddingHorizontal - token.lineWidth,
34
+ };
35
+ const outlined = css `
36
+ background-color: ${token.colorBgContainer};
37
+ border: ${token.lineWidth}px ${token.lineType} ${token.colorBorder};
38
+ border-radius: ${token.borderRadius}px;
39
+
40
+ &:hover {
41
+ border-color: ${token.colorPrimaryHover};
42
+ background-color: ${token.colorBgContainer};
43
+ }
44
+
45
+ &:focus-within, &.focused {
46
+ border-color: ${token.colorPrimary};
47
+ box-shadow: 0 0 0 ${token.controlOutlineWidth}px ${token.controlOutline};
48
+ background-color: ${token.colorBgContainer};
49
+ }
50
+
51
+ &.disabled {
52
+ background-color: ${token.colorBgContainerDisabled};
53
+ border-color: ${token.colorBorder};
54
+
55
+ &:hover, &:focus-within {
56
+ border-color: ${token.colorBorder};
57
+ background-color: ${token.colorBgContainerDisabled};
58
+ }
59
+ }
60
+
61
+ /* status must stay after .disabled - in antd a status border wins over the disabled one */
62
+ &.status-error {
63
+ border-color: ${token.colorError};
64
+
65
+ &:hover {
66
+ border-color: ${token.colorErrorBorderHover};
67
+ }
68
+
69
+ &:focus-within, &.focused {
70
+ border-color: ${token.colorError};
71
+ box-shadow: 0 0 0 ${token.controlOutlineWidth}px ${token.colorErrorOutline};
72
+ }
73
+
74
+ &.disabled, &.disabled:hover {
75
+ border-color: ${token.colorError};
76
+ }
77
+ }
78
+
79
+ &.status-warning {
80
+ border-color: ${token.colorWarning};
81
+
82
+ &:hover {
83
+ border-color: ${token.colorWarningBorderHover};
84
+ }
85
+
86
+ &:focus-within, &.focused {
87
+ border-color: ${token.colorWarning};
88
+ box-shadow: 0 0 0 ${token.controlOutlineWidth}px ${token.colorWarningOutline};
89
+ }
90
+
91
+ &.disabled, &.disabled:hover {
92
+ border-color: ${token.colorWarning};
93
+ }
94
+ }
95
+ `;
96
+ const underlined = css `
97
+ background-color: ${token.colorBgContainer};
98
+ border-width: ${token.lineWidth}px 0;
99
+ border-style: ${token.lineType} none;
100
+ border-color: transparent transparent ${token.colorBorder} transparent;
101
+ border-radius: 0;
102
+
103
+ &:hover {
104
+ border-color: transparent transparent ${token.colorPrimaryHover} transparent;
105
+ background-color: ${token.colorBgContainer};
106
+ }
107
+
108
+ &:focus-within, &.focused {
109
+ border-color: transparent transparent ${token.colorPrimary} transparent;
110
+ background-color: ${token.colorBgContainer};
111
+ }
112
+
113
+ &.disabled {
114
+ border-color: transparent transparent ${token.colorBorder} transparent;
115
+
116
+ &:hover, &:focus-within {
117
+ border-color: transparent transparent ${token.colorBorder} transparent;
118
+ }
119
+ }
120
+
121
+ &.status-error {
122
+ border-color: transparent transparent ${token.colorError} transparent;
123
+
124
+ &:hover {
125
+ border-color: transparent transparent ${token.colorErrorBorderHover} transparent;
126
+ }
127
+
128
+ &:focus-within, &.focused, &.disabled, &.disabled:hover {
129
+ border-color: transparent transparent ${token.colorError} transparent;
130
+ }
131
+ }
132
+
133
+ &.status-warning {
134
+ border-color: transparent transparent ${token.colorWarning} transparent;
135
+
136
+ &:hover {
137
+ border-color: transparent transparent ${token.colorWarningBorderHover} transparent;
138
+ }
139
+
140
+ &:focus-within, &.focused, &.disabled, &.disabled:hover {
141
+ border-color: transparent transparent ${token.colorWarning} transparent;
142
+ }
143
+ }
144
+ `;
145
+ const filled = css `
146
+ background: ${token.colorFillTertiary};
147
+ border: ${token.lineWidth}px ${token.lineType} transparent;
148
+ border-radius: ${token.borderRadius}px;
149
+
150
+ &:hover {
151
+ background: ${token.colorFillSecondary};
152
+ }
153
+
154
+ &:focus-within, &.focused {
155
+ border-color: ${token.colorPrimary};
156
+ background-color: ${token.colorBgContainer};
157
+ }
158
+
159
+ &.disabled {
160
+ background-color: ${token.colorBgContainerDisabled};
161
+ border-color: ${token.colorBorder};
162
+
163
+ &:hover, &:focus-within {
164
+ border-color: ${token.colorBorder};
165
+ background-color: ${token.colorBgContainerDisabled};
166
+ }
167
+ }
168
+
169
+ /* antd guards the filled status style with :not(-disabled), so a disabled input keeps
170
+ the plain disabled background instead of the tinted one */
171
+ &.status-error:not(.disabled) {
172
+ background: ${token.colorErrorBg};
173
+ border-color: transparent;
174
+
175
+ && input {
176
+ color: ${token.colorErrorText};
177
+ }
178
+
179
+ &:hover {
180
+ background: ${token.colorErrorBgHover};
181
+ }
182
+
183
+ &:focus-within, &.focused {
184
+ border-color: ${token.colorError};
185
+ background-color: ${token.colorBgContainer};
186
+ }
187
+ }
188
+
189
+ &.status-warning:not(.disabled) {
190
+ background: ${token.colorWarningBg};
191
+ border-color: transparent;
192
+
193
+ && input {
194
+ color: ${token.colorWarningText};
195
+ }
196
+
197
+ &:hover {
198
+ background: ${token.colorWarningBgHover};
199
+ }
200
+
201
+ &:focus-within, &.focused {
202
+ border-color: ${token.colorWarning};
203
+ background-color: ${token.colorBgContainer};
204
+ }
205
+ }
206
+ `;
207
+ const borderless = css `
208
+ background: transparent;
209
+ border: none;
210
+ border-radius: ${token.borderRadius}px;
211
+
212
+ &:focus-within, &.focused {
213
+ outline: none;
214
+ }
215
+
216
+ /* the value lives in the nested inputs, so the colour has to reach them;
217
+ disabled wins over status, the same way antd pickers behave */
218
+ &.status-error:not(.disabled) {
219
+ color: ${token.colorError};
220
+
221
+ && input {
222
+ color: ${token.colorError};
223
+ }
224
+ }
225
+
226
+ &.status-warning:not(.disabled) {
227
+ color: ${token.colorWarning};
228
+
229
+ && input {
230
+ color: ${token.colorWarning};
231
+ }
232
+ }
233
+ `;
234
+ const variantStyles = { outlined, underlined, filled, borderless }[variant];
235
+ const hasRadius = variant !== "underlined";
236
+ const height = heightMap[size] - (variant === "borderless" ? 2 * token.lineWidth : 0);
237
+ const statusAffix = variant !== "borderless";
30
238
  return {
31
239
  baseLayout: css `
32
240
  display: inline-block;
33
241
  position: relative;
34
242
  width: 100%;
35
- height: ${heightMap[size]}px;
36
- padding: 0;
243
+ height: ${height}px;
244
+ padding: 0 ${paddingInlineMap[size]}px 0 0;
37
245
  color: ${token.colorText};
38
246
  font-size: ${token.fontSize}px;
39
247
  line-height: ${token.lineHeight};
40
- background-color: ${token.colorBgContainer};
41
- border: 1px solid ${token.colorBorder};
42
- border-radius: ${token.borderRadius}px;
43
- transition: all ${token.motionDurationMid};
44
-
45
- .ant-space-compact & {
46
- border-radius: 0;
248
+ transition: border ${token.motionDurationMid}, box-shadow ${token.motionDurationMid}, background ${token.motionDurationMid};
249
+
250
+ ${variantStyles}
251
+
252
+ &:hover, &:focus-within, &.focused {
253
+ z-index: 3;
47
254
  }
48
255
 
49
- .ant-space-compact > *:not(:last-child) & {
50
- width: calc(100% + 1px);
256
+ &:focus-within, &.focused {
257
+ outline: 0;
51
258
  }
52
259
 
53
- .ant-space-compact > *:first-child & {
54
- border-start-start-radius: ${token.borderRadius}px;
55
- border-end-start-radius: ${token.borderRadius}px;
56
- border-inline-end-width: 1px;
260
+ /* inputs are disabled while the popup is open, but the value must stay readable */
261
+ &.focused input[disabled] {
262
+ color: ${token.colorText};
263
+ -webkit-text-fill-color: ${token.colorText};
264
+ cursor: default;
57
265
  }
58
266
 
59
- .ant-space-compact > *:last-child & {
60
- border-start-end-radius: ${token.borderRadius}px;
61
- border-end-end-radius: ${token.borderRadius}px;
267
+ &.disabled {
268
+ color: ${token.colorTextDisabled};
269
+ box-shadow: none;
270
+ opacity: 1;
271
+ cursor: not-allowed;
272
+
273
+ &:hover, &:focus-within {
274
+ box-shadow: none;
275
+ }
62
276
  }
63
277
 
64
- .ant-space-compact > *:first-child:last-child & {
65
- border-radius: ${token.borderRadius}px;
278
+ .ant-space-compact & {
279
+ border-radius: 0;
66
280
  }
67
-
68
- &:focus-within {
69
- border-color: ${token.colorPrimaryHover};
70
- z-index: 3;
281
+
282
+ .ant-space-compact > *:not(:last-child) & {
283
+ width: calc(100% + ${token.lineWidth}px);
71
284
  }
72
285
 
73
- &:hover {
74
- border-color: ${token.colorPrimaryHover};
75
- z-index: 3;
286
+ ${hasRadius ? css `
287
+ .ant-space-compact > *:first-child & {
288
+ border-start-start-radius: ${token.borderRadius}px;
289
+ border-end-start-radius: ${token.borderRadius}px;
290
+ border-inline-end-width: ${token.lineWidth}px;
291
+ }
292
+
293
+ .ant-space-compact > *:last-child & {
294
+ border-start-end-radius: ${token.borderRadius}px;
295
+ border-end-end-radius: ${token.borderRadius}px;
296
+ }
297
+
298
+ .ant-space-compact > *:first-child:last-child & {
299
+ border-radius: ${token.borderRadius}px;
300
+ }
301
+ ` : ""}
302
+ `,
303
+ rangeSeparator: css `
304
+ align-self: center;
305
+ color: ${token.colorTextQuaternary};
306
+ /* antd fixes the separator at fontSizeLG for every size */
307
+ font-size: ${token.fontSizeLG}px;
308
+ line-height: 1;
309
+ cursor: default;
310
+
311
+ .focused & {
312
+ color: ${token.colorIcon};
76
313
  }
77
314
 
78
- &.disabled {
315
+ .disabled & {
79
316
  color: ${token.colorTextDisabled};
80
- background-color: ${token.colorBgContainerDisabled};
81
- border-color: ${token.colorBorder};
82
317
  cursor: not-allowed;
318
+ }
319
+ `,
320
+ suffixIcon: css `
321
+ align-self: center;
322
+ margin-inline-start: ${token.paddingXS / 2}px;
323
+ color: ${token.colorTextQuaternary};
324
+ line-height: 1;
83
325
 
84
- &:hover {
85
- border-color: ${token.colorBorder};
326
+ ${statusAffix ? css `
327
+ .status-error & {
328
+ color: ${token.colorError};
86
329
  }
330
+
331
+ .status-warning & {
332
+ color: ${token.colorWarning};
333
+ }
334
+ ` : ""}
335
+
336
+ .disabled & {
337
+ color: ${token.colorTextDisabled};
87
338
  }
88
- `
339
+ `,
340
+ };
341
+ });
342
+ const usePopupStyles = createStyles(({ token, css }) => {
343
+ return {
344
+ presetsBar: css `
345
+ border-top: ${token.lineWidth}px ${token.lineType} ${token.colorSplit};
346
+ padding-top: 6px;
347
+ `,
348
+ advancedSeparator: css `
349
+ margin: 4px;
350
+ color: ${token.colorTextSecondary};
351
+ text-align: center;
352
+ `,
89
353
  };
90
354
  });
91
355
  export var DateRangeInputMode;
@@ -145,7 +409,7 @@ export default class DateRangeInput extends React.Component {
145
409
  renderSimplePart() {
146
410
  const _a = this.props, { fromValue, toValue, onChange, style, allowClear, renderAsCalendar, hidePopup, align, defaultMode, onModeChange, confirmButtonsRenderer, onPopupVisibleChange } = _a, props = __rest(_a, ["fromValue", "toValue", "onChange", "style", "allowClear", "renderAsCalendar", "hidePopup", "align", "defaultMode", "onModeChange", "confirmButtonsRenderer", "onPopupVisibleChange"]);
147
411
  const markedDateInterval = this.props.fromValue && this.props.toValue ? [this.props.fromValue, this.props.toValue] : undefined;
148
- return (React.createElement("div", null,
412
+ return (React.createElement(WithCss, { useStyles: usePopupStyles }, (context) => React.createElement("div", null,
149
413
  React.createElement("div", { style: { display: "flex" } },
150
414
  React.createElement(DateTimeInput, Object.assign({ value: fromValue }, props, { allowClear: allowClear, renderAsCalendar: true, style: { width: "100%" }, onChange: (date) => {
151
415
  var _a, _b;
@@ -214,7 +478,7 @@ export default class DateRangeInput extends React.Component {
214
478
  }, onDateItemMouseUp: (_date) => {
215
479
  this.setState({ selectionStartDate: null });
216
480
  }, ignoreKeyStrokes: true }))),
217
- React.createElement("div", { style: { borderTop: "1px solid #ddd", paddingTop: 6 } }, this.props.ranges && Object.keys(this.props.ranges).map((rangeName, index) => {
481
+ React.createElement("div", { className: context.styles.presetsBar }, this.props.ranges && Object.keys(this.props.ranges).map((rangeName, index) => {
218
482
  return (React.createElement(Tag, { style: { userSelect: "none", cursor: "pointer" }, color: "blue", key: `range-${index}`, onClick: () => {
219
483
  var _a, _b, _c;
220
484
  const rangeFunction = (_a = this.props.ranges) === null || _a === void 0 ? void 0 : _a[rangeName];
@@ -223,18 +487,18 @@ export default class DateRangeInput extends React.Component {
223
487
  (_c = (_b = this.props).onChange) === null || _c === void 0 ? void 0 : _c.call(_b, range[0], range[1]);
224
488
  }
225
489
  } }, rangeName));
226
- }))));
490
+ })))));
227
491
  }
228
492
  renderAdvancedPart() {
229
493
  const _a = this.props, { fromValue, toValue, onChange, style, allowClear, renderAsCalendar, hidePopup, align, defaultMode, compact, onModeChange, confirmButtonsRenderer, onPopupVisibleChange } = _a, props = __rest(_a, ["fromValue", "toValue", "onChange", "style", "allowClear", "renderAsCalendar", "hidePopup", "align", "defaultMode", "compact", "onModeChange", "confirmButtonsRenderer", "onPopupVisibleChange"]);
230
- return (React.createElement("div", null,
494
+ return (React.createElement(WithCss, { useStyles: usePopupStyles }, (context) => React.createElement("div", null,
231
495
  React.createElement("div", { style: { display: "flex", gap: 8 } },
232
496
  React.createElement(DateTimeInput, Object.assign({}, props, { style: { flexGrow: 1 }, value: fromValue, onChange: (value) => {
233
497
  var _a, _b;
234
498
  (_b = (_a = this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, value, this.props.toValue);
235
499
  } })),
236
500
  !compact &&
237
- React.createElement("span", { style: { margin: 4, color: "rgba(0, 0, 0, 0.65)", textAlign: "center" } }, "\u27F7"),
501
+ React.createElement("span", { className: context.styles.advancedSeparator }, "\u27F7"),
238
502
  React.createElement(DateTimeInput, Object.assign({}, props, { style: { flexGrow: 1 }, value: toValue, onChange: (value) => {
239
503
  var _a, _b;
240
504
  (_b = (_a = this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.fromValue, value);
@@ -285,7 +549,7 @@ export default class DateRangeInput extends React.Component {
285
549
  to = dayjs().startOf(unit).subtract(1, "millisecond");
286
550
  }
287
551
  this.onChange(this.props.fromValue, to);
288
- } })));
552
+ } }))));
289
553
  }
290
554
  renderPopup() {
291
555
  var _a, _b;
@@ -304,20 +568,25 @@ export default class DateRangeInput extends React.Component {
304
568
  _b.call(_a))));
305
569
  }
306
570
  renderInput() {
307
- const _a = this.props, { className, fromValue, toValue, onChange, style, allowClear, renderAsCalendar, hidePopup, align, disabled, defaultMode, onModeChange, confirmButtonsRenderer, onPopupVisibleChange, size } = _a, props = __rest(_a, ["className", "fromValue", "toValue", "onChange", "style", "allowClear", "renderAsCalendar", "hidePopup", "align", "disabled", "defaultMode", "onModeChange", "confirmButtonsRenderer", "onPopupVisibleChange", "size"]);
571
+ const _a = this.props, { className, fromValue, toValue, onChange, style, allowClear, renderAsCalendar, hidePopup, align, disabled, defaultMode, onModeChange, confirmButtonsRenderer, onPopupVisibleChange, size, status, variant } = _a, props = __rest(_a, ["className", "fromValue", "toValue", "onChange", "style", "allowClear", "renderAsCalendar", "hidePopup", "align", "disabled", "defaultMode", "onModeChange", "confirmButtonsRenderer", "onPopupVisibleChange", "size", "status", "variant"]);
308
572
  return (React.createElement("div", { style: Object.assign(Object.assign({}, style), { padding: 0, position: "relative" }), className: className, onFocus: this.props.onFocus, onBlur: this.props.onBlur },
309
- React.createElement(WithCss, { useStyles: useStyles, props: { size } }, (context) => React.createElement("div", { style: { display: "flex", justifyContent: "space-between", paddingRight: 8 }, className: context.styles.baseLayout + (disabled || this.state.popupVisible ? " disabled" : "") },
573
+ React.createElement(WithCss, { useStyles: useStyles, props: { size, variant } }, (context) => React.createElement("div", { style: { display: "flex", justifyContent: "space-between" }, className: context.cx(context.styles.baseLayout, {
574
+ disabled: !!disabled,
575
+ focused: !disabled && this.state.popupVisible,
576
+ "status-error": status === "error",
577
+ "status-warning": status === "warning",
578
+ }) },
310
579
  React.createElement(DateTimeInput, Object.assign({ value: fromValue }, props, { disabled: disabled, inputDisabled: this.state.popupVisible, allowClear: allowClear, variant: "borderless", hidePopup: true, size: size, style: { width: "auto" }, inputStyle: { paddingRight: 2 }, onChange: (value) => {
311
580
  var _a, _b;
312
581
  (_b = (_a = this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, value, this.props.toValue);
313
582
  } })),
314
- React.createElement("span", { style: { alignSelf: "center" } }, "\u27F7"),
583
+ React.createElement("span", { className: context.styles.rangeSeparator }, "\u27F7"),
315
584
  React.createElement(DateTimeInput, Object.assign({ value: toValue }, props, { disabled: disabled, inputDisabled: this.state.popupVisible, allowClear: allowClear, variant: "borderless", hidePopup: true, size: size, style: { width: "auto" }, inputStyle: { paddingLeft: 2 }, onChange: (value) => {
316
585
  var _a, _b;
317
586
  (_b = (_a = this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, this.props.fromValue, value);
318
587
  } })),
319
588
  !hidePopup && !renderAsCalendar &&
320
- React.createElement(CalendarOutlined, { style: { cursor: (disabled || this.state.popupVisible) ? "not-allowed" : "pointer" }, onClick: (event) => {
589
+ React.createElement(CalendarOutlined, { className: context.styles.suffixIcon, style: { cursor: (disabled || this.state.popupVisible) ? "not-allowed" : "pointer" }, onClick: (event) => {
321
590
  var _a, _b;
322
591
  if (!disabled && document.createEvent) {
323
592
  if (this.state.popupVisible) {
@@ -340,7 +609,7 @@ export default class DateRangeInput extends React.Component {
340
609
  return this.renderInput();
341
610
  }
342
611
  else {
343
- return (React.createElement(Tooltip, { color: "white", key: "date-range-popup-" + this.state.popupKeyIndex, trigger: this.props.disabled ? [] : ["contextMenu"], align: this.props.align, placement: this.props.placement, styles: { body: { width: "fit-content" } }, onOpenChange: (visible) => {
612
+ return (React.createElement(WithCss, { useStyles: usePopupStyles }, ({ theme }) => React.createElement(Tooltip, { color: theme.colorBgElevated, key: "date-range-popup-" + this.state.popupKeyIndex, trigger: this.props.disabled ? [] : ["contextMenu"], align: this.props.align, placement: this.props.placement, styles: { body: { width: "fit-content" } }, onOpenChange: (visible) => {
344
613
  var _a, _b, _c, _d;
345
614
  if (visible) {
346
615
  (_b = (_a = this.props).onFocus) === null || _b === void 0 ? void 0 : _b.call(_a);
@@ -349,7 +618,7 @@ export default class DateRangeInput extends React.Component {
349
618
  (_d = (_c = this.props).onBlur) === null || _d === void 0 ? void 0 : _d.call(_c);
350
619
  }
351
620
  this.setState({ popupVisible: visible });
352
- }, title: this.renderPopup() }, this.renderInput()));
621
+ }, title: this.renderPopup() }, this.renderInput())));
353
622
  }
354
623
  }
355
624
  }