@true-engineering/true-react-common-ui-kit 4.0.0-alpha72 → 4.0.0-alpha73

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,4 +1,4 @@
1
- import { Key } from 'react';
1
+ import { HTMLAttributes, Key } from 'react';
2
2
  import { IClickHandlerEvent } from '../../types';
3
3
  import { IIcon } from '../Icon';
4
4
  import { GROUP_PLACEMENTS } from './constants';
@@ -6,9 +6,10 @@ export interface IControlWrapperSizes {
6
6
  }
7
7
  export type IControlWrapperSize = keyof IControlWrapperSizes;
8
8
  export type IGroupPlacement = (typeof GROUP_PLACEMENTS)[number];
9
- export interface IControlWrapperIcon {
9
+ export interface IControlWrapperIcon extends Pick<HTMLAttributes<HTMLDivElement>, 'tabIndex'> {
10
10
  key?: Key;
11
11
  iconComponent: IIcon;
12
12
  onClick?: (event: IClickHandlerEvent) => void;
13
13
  shouldResetSize?: boolean;
14
+ isActiveIcon?: boolean;
14
15
  }
@@ -1,8 +1,9 @@
1
1
  import { FC } from 'react';
2
2
  import { ReactDatePickerCustomHeaderProps as BaseProps } from 'react-datepicker';
3
+ import { Month } from 'date-fns';
3
4
  import { ITweakStylesProps } from '../../../../types';
4
5
  import { IDatePickerHeaderStyles } from './DatePickerHeader.styles';
5
6
  export interface IDatePickerHeaderProps extends BaseProps, ITweakStylesProps<IDatePickerHeaderStyles> {
6
- months?: string[];
7
+ getMonthSelectString: (value: Month) => string;
7
8
  }
8
9
  export declare const DatePickerHeader: FC<IDatePickerHeaderProps>;
@@ -0,0 +1,3 @@
1
+ import { Month } from 'date-fns';
2
+ export declare const MONTH_SELECT_OPTIONS: Month[];
3
+ export declare const YEARS_SELECT_OPTIONS: number[];
@@ -20,7 +20,7 @@ export interface ISelectProps<Value> extends Omit<IReplaceTweakStylesProps<IInpu
20
20
  minSymbolsCountToOpenList?: number;
21
21
  dropdownOptions?: IDropdownWithPopperOptions;
22
22
  /** @default 'chevron-down' */
23
- dropdownIcon?: IIcon;
23
+ dropdownIcon?: IIcon | null;
24
24
  options: Value[] | readonly Value[];
25
25
  value: Value | undefined;
26
26
  /** @default true */
@@ -1,6 +1,6 @@
1
1
  import { createContext, useContext, useMemo, useRef, useEffect, memo, useLayoutEffect, useCallback, useState, Fragment as Fragment$1, forwardRef, PureComponent, createRef, createElement } from "react";
2
2
  import { createUseStyles } from "react-jss";
3
- import { isObject, isString, isNotEmpty, isArrayNotEmpty, mergeStyles, isStringEmpty, isStringNotEmpty, mergeRefs, isFunction, isEmpty, addDataAttributes as addDataAttributes$1, stopPropagation, applyAction, isReactNodeNotEmpty, addClickHandler, getTestId, getSelectKeyHandler, addDataTestId, getArray, isArrayLikeNotEmpty, doNothing, createFilter, merge, getTransition, indexMap, isNumberInteger, isArrayEmpty } from "@true-engineering/true-react-platform-helpers";
3
+ import { isObject, isString, isNotEmpty, isArrayNotEmpty, mergeStyles, isStringEmpty, isStringNotEmpty, mergeRefs, isFunction, isEmpty, addDataAttributes as addDataAttributes$1, stopPropagation, applyAction, isReactNodeNotEmpty, addClickHandler, getTestId, getSelectKeyHandler, addDataTestId, getArray, isArrayLikeNotEmpty, doNothing, createFilter, indexMap, merge, getTransition, isNumberInteger, isArrayEmpty } from "@true-engineering/true-react-platform-helpers";
4
4
  import { jsx, jsxs, Fragment } from "react/jsx-runtime";
5
5
  import { CSSTransition } from "react-transition-group";
6
6
  import clsx from "clsx";
@@ -4142,6 +4142,7 @@ const ControlWrapper = ({
4142
4142
  }) => {
4143
4143
  const classes = useStyles$K({ tweakStyles });
4144
4144
  const [startControlsWidth, setStartControlsWidth] = useState();
4145
+ const [endControlsWidth, setEndControlsWidth] = useState();
4145
4146
  const startIcons = getArray(startIcon).map(convertToControlWrapperIcon);
4146
4147
  const endIcons = getArray(endIcon).map(convertToControlWrapperIcon);
4147
4148
  const hasStartIcons = isArrayNotEmpty(startIcons);
@@ -4156,19 +4157,34 @@ const ControlWrapper = ({
4156
4157
  const startControlsRef = useResizeRef({
4157
4158
  onTargetChange: (target) => setStartControlsWidth(target.clientWidth)
4158
4159
  });
4159
- const renderIconControl = ({ key, iconComponent, onClick, shouldResetSize = false }, iconType, index) => /* @__PURE__ */ jsx(
4160
+ const endControlsRef = useResizeRef({
4161
+ onTargetChange: (target) => setEndControlsWidth(target.clientWidth)
4162
+ });
4163
+ const renderIconControl = ({
4164
+ key,
4165
+ iconComponent,
4166
+ onClick,
4167
+ shouldResetSize = false,
4168
+ isActiveIcon = isNotEmpty(onClick),
4169
+ ...iconContainerProps
4170
+ }, iconType, index) => /* @__PURE__ */ jsx(
4160
4171
  "div",
4161
4172
  {
4162
4173
  className: clsx(classes.icon, classes[`${iconType}Icon`], {
4163
- [classes.activeIcon]: !isDisabled && isNotEmpty(onClick),
4174
+ [classes.activeIcon]: !isDisabled && isActiveIcon,
4164
4175
  [classes.customIcon]: shouldResetSize
4165
4176
  }),
4166
4177
  ...addClickHandler(onClick, !isDisabled),
4167
4178
  ...addDataTestId(testId, `${iconType}-icon`),
4179
+ ...iconContainerProps,
4168
4180
  children: /* @__PURE__ */ jsx("div", { className: classes.iconInner, children: renderIcon(iconComponent) })
4169
4181
  },
4170
4182
  key ?? index
4171
4183
  );
4184
+ const style = {
4185
+ "--start-controls-width": hasStartIcons ? `${startControlsWidth}px` : void 0,
4186
+ "--end-controls-width": hasEndControls ? `${endControlsWidth}px` : void 0
4187
+ };
4172
4188
  return /* @__PURE__ */ jsxs(
4173
4189
  "div",
4174
4190
  {
@@ -4186,7 +4202,7 @@ const ControlWrapper = ({
4186
4202
  [classes.withStartControls]: hasStartIcons
4187
4203
  }
4188
4204
  ),
4189
- style: hasStartIcons ? { "--start-controls-width": `${startControlsWidth}px` } : void 0,
4205
+ style,
4190
4206
  ...addDataAttributes$1(data, testId),
4191
4207
  children: [
4192
4208
  isReactNodeNotEmpty(label) && /* @__PURE__ */ jsx(
@@ -4203,7 +4219,7 @@ const ControlWrapper = ({
4203
4219
  /* @__PURE__ */ jsxs("div", { className: classes.wrapper, children: [
4204
4220
  hasStartIcons && /* @__PURE__ */ jsx("div", { className: clsx(classes.controls, classes.startControls), ref: startControlsRef, children: startIcons.map((iconProps, index) => renderIconControl(iconProps, "start", index)) }),
4205
4221
  children,
4206
- hasEndControls && /* @__PURE__ */ jsxs("div", { className: classes.controls, children: [
4222
+ hasEndControls && /* @__PURE__ */ jsxs("div", { className: classes.controls, ref: endControlsRef, children: [
4207
4223
  hasClearButton && renderIconControl({ iconComponent: "close", onClick: onClear }, "clear"),
4208
4224
  hasEndIcons && endIcons.map((iconProps, index) => renderIconControl(iconProps, "end", index)),
4209
4225
  isLoading && /* @__PURE__ */ jsx(
@@ -5335,26 +5351,23 @@ function Select(props) {
5335
5351
  isLoading: areOptionsLoading,
5336
5352
  tweakStyles: tweakInputStyles,
5337
5353
  testId,
5338
- icon: [
5354
+ endIcon: [
5339
5355
  isMultiSelect && shouldShowMultiSelectCounter ? {
5340
5356
  key: "counter",
5341
5357
  iconComponent: /* @__PURE__ */ jsxs("div", { className: classes.counter, children: [
5342
5358
  "(+",
5343
5359
  value.length - 1,
5344
5360
  ")"
5345
- ] }, "counter"),
5361
+ ] }),
5346
5362
  shouldResetSize: true
5347
5363
  } : void 0,
5348
5364
  ...getArray(endIcon),
5349
- /* @__PURE__ */ jsx(
5350
- "div",
5351
- {
5352
- className: clsx(classes.arrow, isOpen && classes.activeArrow),
5353
- onClick: onArrowClick,
5354
- children: renderIcon(dropdownIcon)
5355
- },
5356
- "arrow"
5357
- )
5365
+ isNotEmpty(dropdownIcon) ? {
5366
+ key: "arrow",
5367
+ onClick: onArrowClick,
5368
+ tabIndex: void 0,
5369
+ iconComponent: /* @__PURE__ */ jsx("div", { className: clsx(classes.arrow, { [classes.activeArrow]: isOpen }), children: renderIcon(dropdownIcon) })
5370
+ } : void 0
5358
5371
  ].filter(isNotEmpty),
5359
5372
  ...inputProps
5360
5373
  }
@@ -5366,6 +5379,8 @@ function Select(props) {
5366
5379
  }
5367
5380
  );
5368
5381
  }
5382
+ const MONTH_SELECT_OPTIONS = indexMap(12, (idx) => idx);
5383
+ const YEARS_SELECT_OPTIONS = indexMap(41, (idx) => getYear(/* @__PURE__ */ new Date()) - 30 + idx);
5369
5384
  const useStyles$F = createThemedStyles("DatePickerHeader", {
5370
5385
  btn: {
5371
5386
  width: 36,
@@ -5409,7 +5424,7 @@ const selectStyles$1 = {
5409
5424
  };
5410
5425
  const DatePickerHeader = ({
5411
5426
  date,
5412
- months = [],
5427
+ getMonthSelectString,
5413
5428
  tweakStyles,
5414
5429
  prevMonthButtonDisabled,
5415
5430
  nextMonthButtonDisabled,
@@ -5425,31 +5440,28 @@ const DatePickerHeader = ({
5425
5440
  className: "tweakSelect",
5426
5441
  currentComponentName: "DatePickerHeader"
5427
5442
  });
5428
- const years = useMemo(
5429
- () => Array.from(Array(41)).map((_, i) => getYear(/* @__PURE__ */ new Date()) - 30 + i),
5430
- []
5431
- );
5432
5443
  return /* @__PURE__ */ jsxs("div", { className: classes.header, children: [
5433
5444
  /* @__PURE__ */ jsx(
5434
5445
  Select,
5435
5446
  {
5436
- value: months[getMonth(date)],
5437
- options: months,
5447
+ value: getMonth(date),
5448
+ options: MONTH_SELECT_OPTIONS,
5449
+ convertValueToString: getMonthSelectString,
5438
5450
  dropdownIcon: "chevron-down-small",
5439
5451
  isAutoSized: true,
5440
5452
  tweakStyles: tweakSelectStyles,
5441
- onChange: (value) => changeMonth(months.indexOf(value))
5453
+ onChange: (value) => isNotEmpty(value) && changeMonth(value)
5442
5454
  }
5443
5455
  ),
5444
5456
  /* @__PURE__ */ jsx(
5445
5457
  Select,
5446
5458
  {
5447
5459
  value: getYear(date),
5448
- options: years,
5460
+ options: YEARS_SELECT_OPTIONS,
5449
5461
  dropdownIcon: "chevron-down-small",
5450
5462
  isAutoSized: true,
5451
5463
  tweakStyles: tweakSelectStyles,
5452
- onChange: (value) => changeYear(value)
5464
+ onChange: (value) => isNotEmpty(value) && changeYear(value)
5453
5465
  }
5454
5466
  ),
5455
5467
  /* @__PURE__ */ jsxs("div", { className: classes.buttons, children: [
@@ -5584,13 +5596,14 @@ const DatePicker = forwardRef(function DatePicker2({
5584
5596
  const [end, setEnd] = useState(endDate);
5585
5597
  const [endDateValue, setEndDateValue] = useState(formatDate(endDate));
5586
5598
  const hasDateInputValue = isRange ? isStringNotEmpty(startDateValue) || isStringNotEmpty(endDateValue) : isStringNotEmpty(dateValue);
5599
+ const endIcon = isClearable && hasDateInputValue ? inputProps.endIcon : getArray(inputProps.endIcon).concat("calendar");
5587
5600
  const dateInputProps = {
5588
5601
  ...inputProps,
5589
5602
  isRange,
5590
5603
  isDisabled,
5591
5604
  isClearable,
5592
5605
  isActive: isOpen,
5593
- icon: isClearable && hasDateInputValue ? void 0 : "calendar",
5606
+ endIcon,
5594
5607
  tweakStyles: tweakDateInputStyles,
5595
5608
  ...isRange ? { startDate: startDateValue, endDate: endDateValue } : { date: dateValue }
5596
5609
  };
@@ -5669,13 +5682,24 @@ const DatePicker = forwardRef(function DatePicker2({
5669
5682
  (event) => datePickerRef.current?.handleClickOutside(event),
5670
5683
  OUTSIDE_CLICK_IGNORE_CLASS
5671
5684
  );
5685
+ const resolvedLocale = isString(locale) ? LocalesMap[locale] : locale;
5686
+ const getLocalizedMonth = useCallback(
5687
+ (month) => {
5688
+ if (isNotEmpty(months?.[month])) {
5689
+ return months[month];
5690
+ }
5691
+ const localizedMonth = resolvedLocale.localize.month(month);
5692
+ return localizedMonth.charAt(0).toUpperCase().concat(localizedMonth.slice(1));
5693
+ },
5694
+ [resolvedLocale, months]
5695
+ );
5672
5696
  return /* @__PURE__ */ jsx("div", { className: classes.root, ...addDataAttributes$1(data), children: /* @__PURE__ */ jsx(
5673
5697
  DatePickerBase,
5674
5698
  {
5675
5699
  ref: componentRef,
5676
5700
  minDate,
5677
5701
  maxDate,
5678
- locale: isString(locale) ? LocalesMap[locale] : locale,
5702
+ locale: resolvedLocale,
5679
5703
  dateFormat,
5680
5704
  placeholderText: placeholder,
5681
5705
  calendarStartDay,
@@ -5701,7 +5725,7 @@ const DatePicker = forwardRef(function DatePicker2({
5701
5725
  customInputRef,
5702
5726
  customInput: /* @__PURE__ */ jsx(CustomInput, { ...dateInputProps }),
5703
5727
  renderDayContents: (day) => /* @__PURE__ */ jsx("div", { className: classes.dayInner, children: day }),
5704
- renderCustomHeader: renderCustomHeader ?? ((baseProps) => /* @__PURE__ */ jsx(DatePickerHeader, { ...baseProps, months })),
5728
+ renderCustomHeader: renderCustomHeader ?? ((baseProps) => /* @__PURE__ */ jsx(DatePickerHeader, { ...baseProps, getMonthSelectString: getLocalizedMonth })),
5705
5729
  todayButton,
5706
5730
  highlightDates,
5707
5731
  calendarContainer,