@true-engineering/true-react-common-ui-kit 4.0.0-alpha71 → 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.
- package/dist/components/ControlWrapper/types.d.ts +3 -2
- package/dist/components/DatePicker/components/DatePickerHeader/DatePickerHeader.d.ts +2 -1
- package/dist/components/DatePicker/components/DatePickerHeader/constants.d.ts +3 -0
- package/dist/components/FiltersPane/types.d.ts +7 -1
- package/dist/components/Select/Select.d.ts +1 -1
- package/dist/true-react-common-ui-kit.js +53 -29
- package/dist/true-react-common-ui-kit.js.map +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs +1 -1
- package/dist/true-react-common-ui-kit.umd.cjs.map +1 -1
- package/package.json +1 -1
- package/src/components/ControlWrapper/ControlWrapper.tsx +22 -8
- package/src/components/ControlWrapper/types.ts +3 -2
- package/src/components/DatePicker/DatePicker.stories.tsx +7 -18
- package/src/components/DatePicker/DatePicker.tsx +27 -4
- package/src/components/DatePicker/components/DatePickerHeader/DatePickerHeader.tsx +12 -14
- package/src/components/DatePicker/components/DatePickerHeader/constants.ts +5 -0
- package/src/components/FiltersPane/types.ts +8 -0
- package/src/components/Select/Select.stories.tsx +5 -0
- package/src/components/Select/Select.tsx +18 -16
|
@@ -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
|
-
|
|
7
|
+
getMonthSelectString: (value: Month) => string;
|
|
7
8
|
}
|
|
8
9
|
export declare const DatePickerHeader: FC<IDatePickerHeaderProps>;
|
|
@@ -78,6 +78,12 @@ export interface ICustomRangeConfigItem<Value> extends IConfigItemBasicBase<Valu
|
|
|
78
78
|
component: CustomComponent<Value>;
|
|
79
79
|
valueViewType?: 'range';
|
|
80
80
|
}
|
|
81
|
+
export interface ICustomSingularConfigItem<Value> extends IConfigItemBasicBase<Value> {
|
|
82
|
+
[key: string & {}]: any;
|
|
83
|
+
type: 'custom';
|
|
84
|
+
component: CustomComponent<Value>;
|
|
85
|
+
getSelectedValue?: (v: Value) => ReactNode;
|
|
86
|
+
}
|
|
81
87
|
export interface ICustomMultipleConfigItem<Value> extends IConfigItemBasicBase<Value> {
|
|
82
88
|
[key: string & {}]: any;
|
|
83
89
|
type: 'custom';
|
|
@@ -85,7 +91,7 @@ export interface ICustomMultipleConfigItem<Value> extends IConfigItemBasicBase<V
|
|
|
85
91
|
valueViewType?: 'multiple';
|
|
86
92
|
getSelectedValue?: (v: ICustomValue<Value>) => ReactNode;
|
|
87
93
|
}
|
|
88
|
-
export type ICustomConfigItem<Value> = ICustomRangeConfigItem<Value> | ICustomMultipleConfigItem<Value>;
|
|
94
|
+
export type ICustomConfigItem<Value> = ICustomRangeConfigItem<Value> | ICustomSingularConfigItem<Value> | ICustomMultipleConfigItem<Value>;
|
|
89
95
|
export type ConfigItem<Value> = ISelectConfigItem<Value> | IMultiSelectConfigItem<Value> | ICustomConfigItem<Value> | IDateRangeWithoutPeriodConfigItem<Value> | IDateRangeConfigItem<Value> | IDatePickerSingleConfigItem<Value> | IIntervalConfigItem<Value> | IBooleanConfigItem<Value>;
|
|
90
96
|
export type ConfigType<Values> = {
|
|
91
97
|
[K in keyof Values]: ConfigItem<Values[K]>;
|
|
@@ -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,
|
|
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
|
|
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 &&
|
|
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
|
|
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
|
-
|
|
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
|
-
] }
|
|
5361
|
+
] }),
|
|
5346
5362
|
shouldResetSize: true
|
|
5347
5363
|
} : void 0,
|
|
5348
5364
|
...getArray(endIcon),
|
|
5349
|
-
|
|
5350
|
-
"
|
|
5351
|
-
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
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
|
-
|
|
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:
|
|
5437
|
-
options:
|
|
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(
|
|
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:
|
|
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
|
-
|
|
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:
|
|
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,
|
|
5728
|
+
renderCustomHeader: renderCustomHeader ?? ((baseProps) => /* @__PURE__ */ jsx(DatePickerHeader, { ...baseProps, getMonthSelectString: getLocalizedMonth })),
|
|
5705
5729
|
todayButton,
|
|
5706
5730
|
highlightDates,
|
|
5707
5731
|
calendarContainer,
|