x-ui-design 0.5.74 → 0.5.76

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.
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
2
  import { TRangePickerProps } from '../../../types/datepicker';
3
3
  import './style.css';
4
- declare const RangePicker: ({ prefixCls, value, onChange, placeholder, disabled, error, format, prefix, allowClear, inputReadOnly, size, picker, locale, disabledDate, onCalendarChange, style, className, separator, defaultValue, bordered }: TRangePickerProps) => React.JSX.Element;
4
+ declare const RangePicker: ({ prefixCls, value, onChange, placeholder, disabled, error, format, prefix, allowClear, inputReadOnly, size, picker, locale, disabledDate, onOpenChange, onCalendarChange, style, className, separator, defaultValue, bordered, ref, }: TRangePickerProps) => React.JSX.Element;
5
5
  export default RangePicker;
@@ -1,4 +1,4 @@
1
- import { FocusEvent, ReactNode } from 'react';
1
+ import { FocusEvent, ForwardedRef, ReactNode } from 'react';
2
2
  import { DefaultProps, RuleType, SizeType } from '.';
3
3
  export interface BaseInfo {
4
4
  range?: 'start' | 'end';
@@ -33,6 +33,7 @@ export type TDatePickerProps = DefaultProps & {
33
33
  };
34
34
  onChange?: (date: RuleType | RuleType[], dateString: string | string[]) => void;
35
35
  onCalendarChange?: (date: RuleType | RuleType[], dateString: string | string[], info: BaseInfo) => void;
36
+ onOpenChange?: (open: boolean) => void;
36
37
  getPopupContainer?: (node: HTMLElement) => HTMLElement;
37
38
  showToday?: boolean;
38
39
  inputReadOnly?: boolean;
@@ -44,6 +45,7 @@ export type TRangePickerProps = Omit<TDatePickerProps, 'placeholder' | 'value' |
44
45
  value?: Date[];
45
46
  defaultValue?: Date[];
46
47
  separator?: ReactNode;
48
+ ref?: ForwardedRef<HTMLDivElement> | undefined;
47
49
  };
48
50
  export type Locale = {
49
51
  locale: string;
package/dist/index.esm.js CHANGED
@@ -2029,7 +2029,11 @@ const DatePicker = ({
2029
2029
  [`${prefixCls}-disabled`]: disabled
2030
2030
  }]),
2031
2031
  disabled: disabled,
2032
- onClick: () => setIsOpen(!isOpen)
2032
+ onClick: e => {
2033
+ e.preventDefault();
2034
+ e.stopPropagation();
2035
+ setIsOpen(!isOpen);
2036
+ }
2033
2037
  }, prefix || null, /*#__PURE__*/React.createElement("input", {
2034
2038
  size: INPUT_SIZE$1,
2035
2039
  disabled: disabled,
@@ -2060,25 +2064,49 @@ const DatePicker = ({
2060
2064
  }, /*#__PURE__*/React.createElement("div", {
2061
2065
  className: `${prefixCls}-nav-buttons`
2062
2066
  }, /*#__PURE__*/React.createElement("button", {
2063
- onClick: () => setCurrentYear(y => y - 1)
2067
+ onClick: e => {
2068
+ e.preventDefault();
2069
+ e.stopPropagation();
2070
+ setCurrentYear(y => y - 1);
2071
+ }
2064
2072
  }, "\xAB"), /*#__PURE__*/React.createElement("button", {
2065
- onClick: () => setCurrentMonth(m => m === 0 ? (setCurrentYear(y => y - 1), MONTH_LENGTH) : m - 1)
2073
+ onClick: e => {
2074
+ e.preventDefault();
2075
+ e.stopPropagation();
2076
+ setCurrentMonth(m => m === 0 ? (setCurrentYear(y => y - 1), MONTH_LENGTH) : m - 1);
2077
+ }
2066
2078
  }, "\u2039")), /*#__PURE__*/React.createElement("div", {
2067
2079
  className: `${prefixCls}-dropdown-selects`
2068
2080
  }, /*#__PURE__*/React.createElement("button", {
2069
2081
  type: "button",
2070
2082
  className: `${prefixCls}-select`,
2071
- onClick: () => setViewMode('year')
2083
+ onClick: e => {
2084
+ e.preventDefault();
2085
+ e.stopPropagation();
2086
+ setViewMode('year');
2087
+ }
2072
2088
  }, currentYear), /*#__PURE__*/React.createElement("button", {
2073
2089
  type: "button",
2074
2090
  className: `${prefixCls}-select`,
2075
- onClick: () => setViewMode('month')
2091
+ onClick: e => {
2092
+ e.preventDefault();
2093
+ e.stopPropagation();
2094
+ setViewMode('month');
2095
+ }
2076
2096
  }, localeMonths[currentMonth])), /*#__PURE__*/React.createElement("div", {
2077
2097
  className: `${prefixCls}-nav-buttons`
2078
2098
  }, /*#__PURE__*/React.createElement("button", {
2079
- onClick: () => setCurrentMonth(m => m === MONTH_LENGTH ? (setCurrentYear(y => y + 1), 0) : m + 1)
2099
+ onClick: e => {
2100
+ e.preventDefault();
2101
+ e.stopPropagation();
2102
+ setCurrentMonth(m => m === MONTH_LENGTH ? (setCurrentYear(y => y + 1), 0) : m + 1);
2103
+ }
2080
2104
  }, "\u203A"), /*#__PURE__*/React.createElement("button", {
2081
- onClick: () => setCurrentYear(y => y + 1)
2105
+ onClick: e => {
2106
+ e.preventDefault();
2107
+ e.stopPropagation();
2108
+ setCurrentYear(y => y + 1);
2109
+ }
2082
2110
  }, "\xBB"))), viewMode === 'day' && /*#__PURE__*/React.createElement("div", {
2083
2111
  className: `${prefixCls}-grid day`
2084
2112
  }, localeWeekdays.map(day => /*#__PURE__*/React.createElement("div", {
@@ -2097,7 +2125,11 @@ const DatePicker = ({
2097
2125
  [`${prefixCls}-selected`]: isSelected,
2098
2126
  [`${prefixCls}-other-month`]: !current
2099
2127
  }]),
2100
- onClick: () => handleSelect(day, month, year),
2128
+ onClick: e => {
2129
+ e.preventDefault();
2130
+ e.stopPropagation();
2131
+ handleSelect(day, month, year);
2132
+ },
2101
2133
  disabled: disabledDate?.(new Date(year, month, day), {
2102
2134
  from: undefined,
2103
2135
  to: undefined
@@ -2108,7 +2140,9 @@ const DatePicker = ({
2108
2140
  }, localeMonths.map((m, i) => /*#__PURE__*/React.createElement("button", {
2109
2141
  key: i,
2110
2142
  className: `${prefixCls}-month`,
2111
- onClick: () => {
2143
+ onClick: e => {
2144
+ e.preventDefault();
2145
+ e.stopPropagation();
2112
2146
  setCurrentMonth(i);
2113
2147
  setViewMode('day');
2114
2148
  },
@@ -2123,7 +2157,9 @@ const DatePicker = ({
2123
2157
  key: year,
2124
2158
  className: `${prefixCls}-year`,
2125
2159
  disabled: isYearDisabled(year),
2126
- onClick: () => {
2160
+ onClick: e => {
2161
+ e.preventDefault();
2162
+ e.stopPropagation();
2127
2163
  setCurrentYear(year);
2128
2164
  setViewMode('month');
2129
2165
  }
@@ -2139,7 +2175,9 @@ const DatePicker = ({
2139
2175
  from: undefined,
2140
2176
  to: undefined
2141
2177
  }),
2142
- onClick: () => {
2178
+ onClick: e => {
2179
+ e.preventDefault();
2180
+ e.stopPropagation();
2143
2181
  handleSelect(DateNow.getDate(), DateNow.getMonth(), DateNow.getFullYear());
2144
2182
  }
2145
2183
  }, locale?.today || 'Today')))));
@@ -2171,12 +2209,14 @@ const RangePicker = ({
2171
2209
  picker = 'date',
2172
2210
  locale,
2173
2211
  disabledDate,
2212
+ onOpenChange,
2174
2213
  onCalendarChange,
2175
2214
  style = {},
2176
2215
  className = '',
2177
2216
  separator,
2178
2217
  defaultValue,
2179
- bordered = true
2218
+ bordered = true,
2219
+ ref
2180
2220
  }) => {
2181
2221
  const containerRef = useRef(null);
2182
2222
  const [isOpen, setIsOpen] = useState(false);
@@ -2191,10 +2231,19 @@ const RangePicker = ({
2191
2231
  month: 'short'
2192
2232
  }));
2193
2233
  const localeWeekdays = locale?.shortWeekDays || ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'];
2234
+ useImperativeHandle(ref, () => ({
2235
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2236
+ // @ts-expect-error
2237
+ focus: containerRef.current?.focus,
2238
+ input: containerRef.current,
2239
+ blur: containerRef.current.blur,
2240
+ nativeElement: containerRef.current
2241
+ }));
2194
2242
  useEffect(() => {
2195
2243
  const handleClickOutside = event => {
2196
2244
  if (containerRef.current && !containerRef.current.contains(event.target)) {
2197
2245
  setIsOpen(false);
2246
+ onOpenChange?.(false);
2198
2247
  }
2199
2248
  };
2200
2249
  document.addEventListener('mousedown', handleClickOutside);
@@ -2212,6 +2261,7 @@ const RangePicker = ({
2212
2261
  onChange?.([begin.toUTCString(), end.toUTCString()], [formatDate(begin), formatDate(end)]);
2213
2262
  onCalendarChange?.([begin.toUTCString(), end.toUTCString()], [formatDate(begin), formatDate(end)], {});
2214
2263
  setIsOpen(false);
2264
+ onOpenChange?.(false);
2215
2265
  }
2216
2266
  };
2217
2267
  const isMonthDisabled = month => {
@@ -2246,25 +2296,49 @@ const RangePicker = ({
2246
2296
  }, all || !monthOffset ? /*#__PURE__*/React.createElement("div", {
2247
2297
  className: `${prefixCls}-nav-buttons`
2248
2298
  }, /*#__PURE__*/React.createElement("button", {
2249
- onClick: () => setCurrentYear(y => y - 1)
2299
+ onClick: e => {
2300
+ e.preventDefault();
2301
+ e.stopPropagation();
2302
+ setCurrentYear(y => y - 1);
2303
+ }
2250
2304
  }, "\xAB"), /*#__PURE__*/React.createElement("button", {
2251
- onClick: () => setCurrentMonth(m => m === 0 ? (setCurrentYear(y => y - 1), MONTH_LENGTH) : m - 1)
2305
+ onClick: e => {
2306
+ e.preventDefault();
2307
+ e.stopPropagation();
2308
+ setCurrentMonth(m => m === 0 ? (setCurrentYear(y => y - 1), MONTH_LENGTH) : m - 1);
2309
+ }
2252
2310
  }, "\u2039")) : /*#__PURE__*/React.createElement("span", null), /*#__PURE__*/React.createElement("div", {
2253
2311
  className: `${prefixCls}-dropdown-selects`
2254
2312
  }, /*#__PURE__*/React.createElement("button", {
2255
2313
  type: "button",
2256
2314
  className: `${prefixCls}-select`,
2257
- onClick: () => setViewMode('year')
2315
+ onClick: e => {
2316
+ e.preventDefault();
2317
+ e.stopPropagation();
2318
+ setViewMode('year');
2319
+ }
2258
2320
  }, baseYear), /*#__PURE__*/React.createElement("button", {
2259
2321
  type: "button",
2260
2322
  className: `${prefixCls}-select`,
2261
- onClick: () => setViewMode('month')
2323
+ onClick: e => {
2324
+ e.preventDefault();
2325
+ e.stopPropagation();
2326
+ setViewMode('month');
2327
+ }
2262
2328
  }, localeMonths[baseMonth])), all || monthOffset ? /*#__PURE__*/React.createElement("div", {
2263
2329
  className: `${prefixCls}-nav-buttons`
2264
2330
  }, /*#__PURE__*/React.createElement("button", {
2265
- onClick: () => setCurrentMonth(m => m === MONTH_LENGTH ? (setCurrentYear(y => y + 1), 0) : m + 1)
2331
+ onClick: e => {
2332
+ e.preventDefault();
2333
+ e.stopPropagation();
2334
+ setCurrentMonth(m => m === MONTH_LENGTH ? (setCurrentYear(y => y + 1), 0) : m + 1);
2335
+ }
2266
2336
  }, "\u203A"), /*#__PURE__*/React.createElement("button", {
2267
- onClick: () => setCurrentYear(y => y + 1)
2337
+ onClick: e => {
2338
+ e.preventDefault();
2339
+ e.stopPropagation();
2340
+ setCurrentYear(y => y + 1);
2341
+ }
2268
2342
  }, "\xBB")) : /*#__PURE__*/React.createElement("span", null));
2269
2343
  };
2270
2344
  const renderCalendar = (monthOffset = 0, all) => {
@@ -2308,8 +2382,16 @@ const RangePicker = ({
2308
2382
  from: undefined,
2309
2383
  to: undefined
2310
2384
  }),
2311
- onClick: () => day && handleSelect(day),
2312
- onMouseEnter: () => day && setHoveredDate(day),
2385
+ onClick: e => {
2386
+ e.preventDefault();
2387
+ e.stopPropagation();
2388
+ day && handleSelect(day);
2389
+ },
2390
+ onMouseEnter: e => {
2391
+ e.preventDefault();
2392
+ e.stopPropagation();
2393
+ day && setHoveredDate(day);
2394
+ },
2313
2395
  className: clsx([`${prefixCls}-day`, {
2314
2396
  [`${prefixCls}-selected`]: isSelected,
2315
2397
  [`${prefixCls}-in-range`]: inRange,
@@ -2322,7 +2404,9 @@ const RangePicker = ({
2322
2404
  }, localeMonths.map((m, i) => /*#__PURE__*/React.createElement("button", {
2323
2405
  key: i,
2324
2406
  className: `${prefixCls}-month`,
2325
- onClick: () => {
2407
+ onClick: e => {
2408
+ e.preventDefault();
2409
+ e.stopPropagation();
2326
2410
  setCurrentMonth(i);
2327
2411
  setViewMode('day');
2328
2412
  },
@@ -2337,7 +2421,9 @@ const RangePicker = ({
2337
2421
  key: year,
2338
2422
  className: `${prefixCls}-year`,
2339
2423
  disabled: isYearDisabled(year),
2340
- onClick: () => {
2424
+ onClick: e => {
2425
+ e.preventDefault();
2426
+ e.stopPropagation();
2341
2427
  setCurrentYear(year);
2342
2428
  setViewMode('month');
2343
2429
  }
@@ -2365,19 +2451,24 @@ const RangePicker = ({
2365
2451
  [`${prefixCls}-disabled`]: disabled
2366
2452
  }]),
2367
2453
  disabled: disabled,
2368
- onClick: () => setIsOpen(!isOpen)
2454
+ onClick: e => {
2455
+ e.preventDefault();
2456
+ e.stopPropagation();
2457
+ setIsOpen(!isOpen);
2458
+ onOpenChange?.(!isOpen);
2459
+ }
2369
2460
  }, prefix, /*#__PURE__*/React.createElement("input", {
2370
2461
  readOnly: inputReadOnly,
2371
2462
  className: `${prefixCls}-selected-date`,
2372
2463
  placeholder: placeholder[0],
2373
- value: selectedDates[0] ? formatDate(selectedDates[0]) : ''
2464
+ [inputReadOnly ? 'value' : 'defaultValue']: selectedDates[0] ? formatDate(selectedDates[0]) : ''
2374
2465
  }), /*#__PURE__*/React.createElement("span", {
2375
2466
  className: `${prefixCls}-range-separator`
2376
2467
  }, separator || /*#__PURE__*/React.createElement(DateDistanceIcon, null)), /*#__PURE__*/React.createElement("input", {
2377
2468
  readOnly: inputReadOnly,
2378
2469
  className: `${prefixCls}-selected-date`,
2379
2470
  placeholder: placeholder[1],
2380
- value: selectedDates[1] ? formatDate(selectedDates[1]) : ''
2471
+ [inputReadOnly ? 'value' : 'defaultValue']: selectedDates[1] ? formatDate(selectedDates[1]) : ''
2381
2472
  }), /*#__PURE__*/React.createElement("span", {
2382
2473
  className: `${prefixCls}-icon`
2383
2474
  }, allowClear && (selectedDates[0] || selectedDates[1]) ? /*#__PURE__*/React.createElement("span", {