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

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";
@@ -3073,12 +3073,13 @@ const WithPopup = ({
3073
3073
  onClick: stopPropagation
3074
3074
  }
3075
3075
  });
3076
+ const triggerData = { popupOpen: isActive, ...data };
3076
3077
  const triggerElement = applyAction(trigger, {
3077
3078
  referenceProps: !isTriggerWrapped ? referenceProps : void 0,
3078
3079
  triggerProps: {
3079
3080
  isActive,
3080
3081
  isDisabled,
3081
- ...!isTriggerWrapped && { data, testId, ...referenceProps }
3082
+ ...!isTriggerWrapped && { data: triggerData, testId, ...referenceProps }
3082
3083
  }
3083
3084
  });
3084
3085
  return /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -3091,7 +3092,7 @@ const WithPopup = ({
3091
3092
  [classes.active]: isActive
3092
3093
  }),
3093
3094
  ...referenceProps,
3094
- ...addDataAttributes$1(data, testId),
3095
+ ...addDataAttributes$1(triggerData, testId),
3095
3096
  children: triggerElement
3096
3097
  }
3097
3098
  ) : triggerElement,
@@ -4142,6 +4143,7 @@ const ControlWrapper = ({
4142
4143
  }) => {
4143
4144
  const classes = useStyles$K({ tweakStyles });
4144
4145
  const [startControlsWidth, setStartControlsWidth] = useState();
4146
+ const [endControlsWidth, setEndControlsWidth] = useState();
4145
4147
  const startIcons = getArray(startIcon).map(convertToControlWrapperIcon);
4146
4148
  const endIcons = getArray(endIcon).map(convertToControlWrapperIcon);
4147
4149
  const hasStartIcons = isArrayNotEmpty(startIcons);
@@ -4156,19 +4158,34 @@ const ControlWrapper = ({
4156
4158
  const startControlsRef = useResizeRef({
4157
4159
  onTargetChange: (target) => setStartControlsWidth(target.clientWidth)
4158
4160
  });
4159
- const renderIconControl = ({ key, iconComponent, onClick, shouldResetSize = false }, iconType, index) => /* @__PURE__ */ jsx(
4161
+ const endControlsRef = useResizeRef({
4162
+ onTargetChange: (target) => setEndControlsWidth(target.clientWidth)
4163
+ });
4164
+ const renderIconControl = ({
4165
+ key,
4166
+ iconComponent,
4167
+ onClick,
4168
+ shouldResetSize = false,
4169
+ isActiveIcon = isNotEmpty(onClick),
4170
+ ...iconContainerProps
4171
+ }, iconType, index) => /* @__PURE__ */ jsx(
4160
4172
  "div",
4161
4173
  {
4162
4174
  className: clsx(classes.icon, classes[`${iconType}Icon`], {
4163
- [classes.activeIcon]: !isDisabled && isNotEmpty(onClick),
4175
+ [classes.activeIcon]: !isDisabled && isActiveIcon,
4164
4176
  [classes.customIcon]: shouldResetSize
4165
4177
  }),
4166
4178
  ...addClickHandler(onClick, !isDisabled),
4167
4179
  ...addDataTestId(testId, `${iconType}-icon`),
4180
+ ...iconContainerProps,
4168
4181
  children: /* @__PURE__ */ jsx("div", { className: classes.iconInner, children: renderIcon(iconComponent) })
4169
4182
  },
4170
4183
  key ?? index
4171
4184
  );
4185
+ const style = {
4186
+ "--start-controls-width": hasStartIcons ? `${startControlsWidth}px` : void 0,
4187
+ "--end-controls-width": hasEndControls ? `${endControlsWidth}px` : void 0
4188
+ };
4172
4189
  return /* @__PURE__ */ jsxs(
4173
4190
  "div",
4174
4191
  {
@@ -4186,7 +4203,7 @@ const ControlWrapper = ({
4186
4203
  [classes.withStartControls]: hasStartIcons
4187
4204
  }
4188
4205
  ),
4189
- style: hasStartIcons ? { "--start-controls-width": `${startControlsWidth}px` } : void 0,
4206
+ style,
4190
4207
  ...addDataAttributes$1(data, testId),
4191
4208
  children: [
4192
4209
  isReactNodeNotEmpty(label) && /* @__PURE__ */ jsx(
@@ -4203,7 +4220,7 @@ const ControlWrapper = ({
4203
4220
  /* @__PURE__ */ jsxs("div", { className: classes.wrapper, children: [
4204
4221
  hasStartIcons && /* @__PURE__ */ jsx("div", { className: clsx(classes.controls, classes.startControls), ref: startControlsRef, children: startIcons.map((iconProps, index) => renderIconControl(iconProps, "start", index)) }),
4205
4222
  children,
4206
- hasEndControls && /* @__PURE__ */ jsxs("div", { className: classes.controls, children: [
4223
+ hasEndControls && /* @__PURE__ */ jsxs("div", { className: classes.controls, ref: endControlsRef, children: [
4207
4224
  hasClearButton && renderIconControl({ iconComponent: "close", onClick: onClear }, "clear"),
4208
4225
  hasEndIcons && endIcons.map((iconProps, index) => renderIconControl(iconProps, "end", index)),
4209
4226
  isLoading && /* @__PURE__ */ jsx(
@@ -5335,26 +5352,23 @@ function Select(props) {
5335
5352
  isLoading: areOptionsLoading,
5336
5353
  tweakStyles: tweakInputStyles,
5337
5354
  testId,
5338
- icon: [
5355
+ endIcon: [
5339
5356
  isMultiSelect && shouldShowMultiSelectCounter ? {
5340
5357
  key: "counter",
5341
5358
  iconComponent: /* @__PURE__ */ jsxs("div", { className: classes.counter, children: [
5342
5359
  "(+",
5343
5360
  value.length - 1,
5344
5361
  ")"
5345
- ] }, "counter"),
5362
+ ] }),
5346
5363
  shouldResetSize: true
5347
5364
  } : void 0,
5348
5365
  ...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
- )
5366
+ isNotEmpty(dropdownIcon) ? {
5367
+ key: "arrow",
5368
+ onClick: onArrowClick,
5369
+ tabIndex: void 0,
5370
+ iconComponent: /* @__PURE__ */ jsx("div", { className: clsx(classes.arrow, { [classes.activeArrow]: isOpen }), children: renderIcon(dropdownIcon) })
5371
+ } : void 0
5358
5372
  ].filter(isNotEmpty),
5359
5373
  ...inputProps
5360
5374
  }
@@ -5366,6 +5380,8 @@ function Select(props) {
5366
5380
  }
5367
5381
  );
5368
5382
  }
5383
+ const MONTH_SELECT_OPTIONS = indexMap(12, (idx) => idx);
5384
+ const YEARS_SELECT_OPTIONS = indexMap(41, (idx) => getYear(/* @__PURE__ */ new Date()) - 30 + idx);
5369
5385
  const useStyles$F = createThemedStyles("DatePickerHeader", {
5370
5386
  btn: {
5371
5387
  width: 36,
@@ -5409,7 +5425,7 @@ const selectStyles$1 = {
5409
5425
  };
5410
5426
  const DatePickerHeader = ({
5411
5427
  date,
5412
- months = [],
5428
+ getMonthSelectString,
5413
5429
  tweakStyles,
5414
5430
  prevMonthButtonDisabled,
5415
5431
  nextMonthButtonDisabled,
@@ -5425,31 +5441,28 @@ const DatePickerHeader = ({
5425
5441
  className: "tweakSelect",
5426
5442
  currentComponentName: "DatePickerHeader"
5427
5443
  });
5428
- const years = useMemo(
5429
- () => Array.from(Array(41)).map((_, i) => getYear(/* @__PURE__ */ new Date()) - 30 + i),
5430
- []
5431
- );
5432
5444
  return /* @__PURE__ */ jsxs("div", { className: classes.header, children: [
5433
5445
  /* @__PURE__ */ jsx(
5434
5446
  Select,
5435
5447
  {
5436
- value: months[getMonth(date)],
5437
- options: months,
5448
+ value: getMonth(date),
5449
+ options: MONTH_SELECT_OPTIONS,
5450
+ convertValueToString: getMonthSelectString,
5438
5451
  dropdownIcon: "chevron-down-small",
5439
5452
  isAutoSized: true,
5440
5453
  tweakStyles: tweakSelectStyles,
5441
- onChange: (value) => changeMonth(months.indexOf(value))
5454
+ onChange: (value) => isNotEmpty(value) && changeMonth(value)
5442
5455
  }
5443
5456
  ),
5444
5457
  /* @__PURE__ */ jsx(
5445
5458
  Select,
5446
5459
  {
5447
5460
  value: getYear(date),
5448
- options: years,
5461
+ options: YEARS_SELECT_OPTIONS,
5449
5462
  dropdownIcon: "chevron-down-small",
5450
5463
  isAutoSized: true,
5451
5464
  tweakStyles: tweakSelectStyles,
5452
- onChange: (value) => changeYear(value)
5465
+ onChange: (value) => isNotEmpty(value) && changeYear(value)
5453
5466
  }
5454
5467
  ),
5455
5468
  /* @__PURE__ */ jsxs("div", { className: classes.buttons, children: [
@@ -5584,13 +5597,14 @@ const DatePicker = forwardRef(function DatePicker2({
5584
5597
  const [end, setEnd] = useState(endDate);
5585
5598
  const [endDateValue, setEndDateValue] = useState(formatDate(endDate));
5586
5599
  const hasDateInputValue = isRange ? isStringNotEmpty(startDateValue) || isStringNotEmpty(endDateValue) : isStringNotEmpty(dateValue);
5600
+ const endIcon = isClearable && hasDateInputValue ? inputProps.endIcon : getArray(inputProps.endIcon).concat("calendar");
5587
5601
  const dateInputProps = {
5588
5602
  ...inputProps,
5589
5603
  isRange,
5590
5604
  isDisabled,
5591
5605
  isClearable,
5592
5606
  isActive: isOpen,
5593
- icon: isClearable && hasDateInputValue ? void 0 : "calendar",
5607
+ endIcon,
5594
5608
  tweakStyles: tweakDateInputStyles,
5595
5609
  ...isRange ? { startDate: startDateValue, endDate: endDateValue } : { date: dateValue }
5596
5610
  };
@@ -5669,13 +5683,24 @@ const DatePicker = forwardRef(function DatePicker2({
5669
5683
  (event) => datePickerRef.current?.handleClickOutside(event),
5670
5684
  OUTSIDE_CLICK_IGNORE_CLASS
5671
5685
  );
5686
+ const resolvedLocale = isString(locale) ? LocalesMap[locale] : locale;
5687
+ const getLocalizedMonth = useCallback(
5688
+ (month) => {
5689
+ if (isNotEmpty(months?.[month])) {
5690
+ return months[month];
5691
+ }
5692
+ const localizedMonth = resolvedLocale.localize.month(month);
5693
+ return localizedMonth.charAt(0).toUpperCase().concat(localizedMonth.slice(1));
5694
+ },
5695
+ [resolvedLocale, months]
5696
+ );
5672
5697
  return /* @__PURE__ */ jsx("div", { className: classes.root, ...addDataAttributes$1(data), children: /* @__PURE__ */ jsx(
5673
5698
  DatePickerBase,
5674
5699
  {
5675
5700
  ref: componentRef,
5676
5701
  minDate,
5677
5702
  maxDate,
5678
- locale: isString(locale) ? LocalesMap[locale] : locale,
5703
+ locale: resolvedLocale,
5679
5704
  dateFormat,
5680
5705
  placeholderText: placeholder,
5681
5706
  calendarStartDay,
@@ -5701,7 +5726,7 @@ const DatePicker = forwardRef(function DatePicker2({
5701
5726
  customInputRef,
5702
5727
  customInput: /* @__PURE__ */ jsx(CustomInput, { ...dateInputProps }),
5703
5728
  renderDayContents: (day) => /* @__PURE__ */ jsx("div", { className: classes.dayInner, children: day }),
5704
- renderCustomHeader: renderCustomHeader ?? ((baseProps) => /* @__PURE__ */ jsx(DatePickerHeader, { ...baseProps, months })),
5729
+ renderCustomHeader: renderCustomHeader ?? ((baseProps) => /* @__PURE__ */ jsx(DatePickerHeader, { ...baseProps, getMonthSelectString: getLocalizedMonth })),
5705
5730
  todayButton,
5706
5731
  highlightDates,
5707
5732
  calendarContainer,