@true-engineering/true-react-common-ui-kit 4.0.0-alpha66 → 4.0.0-alpha67

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,9 +1,3 @@
1
- import { CSSProperties } from 'react';
2
1
  import { ITweakStyles } from '../../theme';
3
- export declare const SELECTOR_GAP: number;
4
- export declare const getSelectorLineStyle: (activeElementData?: {
5
- clientWidth: number;
6
- offsetLeft: number;
7
- }) => CSSProperties | undefined;
8
- export declare const useStyles: import('../../theme').IUseStyles<"option" | "s" | "line" | "invalid" | "root" | "active" | "disabled" | "m" | "l" | "iconFromRight" | "required" | "optionWrapper" | "optionIcon" | "optionText" | "selector" | "autoWidth">;
2
+ export declare const useStyles: import('../../theme').IUseStyles<"option" | "s" | "invalid" | "active" | "disabled" | "m" | "l" | "iconFromRight" | "required" | "selector" | "autoWidth" | "optionIcon" | "optionText">;
9
3
  export type ISelectorStyles = ITweakStyles<typeof useStyles>;
@@ -1,8 +1,8 @@
1
1
  import { RefCallback } from 'react';
2
- export interface IResizeRefOptions {
2
+ export interface IResizeRefOptions<T extends Element> {
3
3
  /** @default false */
4
4
  isDisabled?: boolean;
5
5
  onChange?: (entry: ResizeObserverEntry) => void;
6
- onTargetChange?: (target: Element) => void;
6
+ onTargetChange?: (target: T) => void;
7
7
  }
8
- export declare const useResizeRef: (options: IResizeRefOptions) => RefCallback<Element>;
8
+ export declare const useResizeRef: <T extends Element>(options: IResizeRefOptions<T>) => RefCallback<T>;
@@ -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, hasDuplicates, 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, merge, getTransition, indexMap, 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";
@@ -10835,131 +10835,49 @@ function RadioButton({
10835
10835
  }
10836
10836
  );
10837
10837
  }
10838
- const SELECTOR_TOTAL_GAP = 4;
10839
- const SELECTOR_BORDER_WIDTH = 1;
10840
- const SELECTOR_GAP = SELECTOR_TOTAL_GAP - SELECTOR_BORDER_WIDTH;
10841
- const getSelectorLineStyle = (activeElementData) => isNotEmpty(activeElementData) ? {
10842
- width: activeElementData.clientWidth - SELECTOR_GAP * 2,
10843
- transform: `translateX(${activeElementData.offsetLeft}px)`
10844
- } : void 0;
10845
10838
  const useStyles$7 = createThemedStyles("Selector", {
10846
- root: {
10847
- display: "flex",
10848
- alignItems: "center",
10849
- listStyle: "none",
10850
- position: "relative"
10851
- },
10852
- required: {
10853
- "&::before": {
10854
- top: "50%",
10855
- left: -12,
10856
- width: 6,
10857
- height: 6,
10839
+ selector: {
10840
+ display: "grid",
10841
+ gridAutoFlow: "column",
10842
+ gridAutoColumns: "auto",
10843
+ boxSizing: "border-box",
10844
+ position: "relative",
10845
+ "&:has($active)::before": {
10858
10846
  content: '""',
10859
10847
  position: "absolute",
10860
- transform: "translate(0, -50%)",
10861
- borderRadius: "50%",
10862
- backgroundColor: colors.ORANGE_FOCUS
10848
+ transition: animations.defaultTransition,
10849
+ transitionProperty: "left, width",
10850
+ width: "var(--active-element-width)",
10851
+ height: "var(--active-element-height)",
10852
+ top: "var(--active-element-top)",
10853
+ left: "var(--active-element-left)"
10863
10854
  }
10864
10855
  },
10865
- invalid: {},
10866
- optionWrapper: {
10867
- height: "100%"
10856
+ autoWidth: {
10857
+ gridAutoColumns: "1fr"
10868
10858
  },
10859
+ required: {},
10860
+ invalid: {},
10869
10861
  option: {
10862
+ appearance: "none",
10863
+ background: "none",
10864
+ border: "none",
10870
10865
  display: "flex",
10871
10866
  alignItems: "center",
10872
10867
  justifyContent: "center",
10873
- appearance: "none",
10874
- borderRadius: 0,
10875
- padding: 0,
10876
- border: "none",
10877
- cursor: "pointer",
10878
- width: "100%"
10879
- },
10880
- active: {
10881
- cursor: "default"
10882
- },
10883
- disabled: {
10884
- cursor: "default",
10885
- "& $optionText": {
10886
- color: colors.FONT_LABEL
10887
- }
10888
- },
10889
- optionIcon: {
10890
- width: 20,
10891
- height: 20
10892
- },
10893
- optionText: {},
10894
- iconFromRight: {
10895
- "& $option": {
10868
+ zIndex: 1,
10869
+ "$iconFromRight &": {
10896
10870
  flexDirection: "row-reverse"
10897
10871
  }
10898
10872
  },
10873
+ active: {},
10874
+ disabled: {},
10875
+ optionIcon: {},
10876
+ optionText: {},
10877
+ iconFromRight: {},
10899
10878
  s: {},
10900
10879
  m: {},
10901
- l: {},
10902
- line: {},
10903
- selector: {
10904
- display: "grid",
10905
- gridAutoFlow: "column",
10906
- gridAutoColumns: "1fr",
10907
- borderRadius: dimensions.BORDER_RADIUS_SMALL,
10908
- backgroundColor: colors.BORDER_LIGHT,
10909
- width: "fit-content",
10910
- position: "relative",
10911
- border: ["solid", SELECTOR_BORDER_WIDTH, "transparent"],
10912
- "& $line": {
10913
- content: '""',
10914
- position: "absolute",
10915
- left: SELECTOR_GAP,
10916
- height: `calc(100% - ${SELECTOR_GAP * 2}px)`,
10917
- backgroundColor: colors.CLASSIC_WHITE,
10918
- borderRadius: dimensions.BORDER_RADIUS_SMALL,
10919
- transition: animations.defaultTransition,
10920
- transitionProperty: "transform, width"
10921
- },
10922
- "&$invalid": {
10923
- borderColor: colors.RED_WARNING
10924
- },
10925
- "& $option": {
10926
- gap: 6,
10927
- position: "relative",
10928
- zIndex: 1,
10929
- height: "100%",
10930
- color: colors.FONT_MEDIUM,
10931
- fontSize: 16,
10932
- transition: animations.defaultTransition,
10933
- transitionProperty: "color",
10934
- background: "none",
10935
- "&$s": {
10936
- padding: [4, 8],
10937
- fontSize: 10,
10938
- lineHeight: "14px"
10939
- },
10940
- "&$m": {
10941
- padding: [14, 18]
10942
- },
10943
- "&$l": {
10944
- padding: [16, 24]
10945
- },
10946
- "&:hover, &:focus": {
10947
- color: colors.FONT_MAIN
10948
- },
10949
- "&$active": {
10950
- color: colors.FONT_MAIN
10951
- }
10952
- }
10953
- },
10954
- autoWidth: {
10955
- "&$selector": {
10956
- gridAutoColumns: "auto",
10957
- "& $line": {
10958
- width: "unset",
10959
- transform: "unset"
10960
- }
10961
- }
10962
- }
10880
+ l: {}
10963
10881
  });
10964
10882
  function Selector({
10965
10883
  options,
@@ -10975,57 +10893,53 @@ function Selector({
10975
10893
  tweakStyles,
10976
10894
  onChange
10977
10895
  }) {
10978
- const classes = useStyles$7({ theme: tweakStyles });
10979
- const optionsValues = options.map((opt) => opt.value);
10980
- const [elementsData, setElementsData] = useState([]);
10981
- const listRef = useRef(null);
10982
- if (hasDuplicates(optionsValues)) {
10983
- console.error("Selector: Значения options.value должны быть уникальными");
10984
- }
10985
- useEffect(() => {
10986
- const listEl = listRef.current;
10987
- if (listEl === null) {
10988
- return;
10896
+ const classes = useStyles$7({ tweakStyles });
10897
+ const updateVariables = (active) => {
10898
+ if (isNotEmpty(active?.parentElement)) {
10899
+ active.parentElement.style.setProperty("--active-element-width", `${active.clientWidth}px`);
10900
+ active.parentElement.style.setProperty("--active-element-height", `${active.clientHeight}px`);
10901
+ active.parentElement.style.setProperty("--active-element-left", `${active.offsetLeft}px`);
10902
+ active.parentElement.style.setProperty("--active-element-top", `${active.offsetTop}px`);
10989
10903
  }
10990
- setElementsData([...listEl.querySelectorAll(`.${classes.optionWrapper}`)]);
10991
- }, [options, size2]);
10992
- const activeElementData = isNotEmpty(value) ? elementsData[optionsValues.indexOf(value)] : void 0;
10993
- return /* @__PURE__ */ jsxs(
10904
+ };
10905
+ const resizeRef = useResizeRef({
10906
+ onTargetChange: (target) => updateVariables(target.querySelector(`.${classes.active}`))
10907
+ });
10908
+ return /* @__PURE__ */ jsx(
10994
10909
  "div",
10995
10910
  {
10996
- className: clsx(classes.root, classes.selector, {
10911
+ ref: resizeRef,
10912
+ className: clsx(classes.selector, classes[size2], {
10997
10913
  [classes.iconFromRight]: iconPosition === "right",
10998
10914
  [classes.invalid]: isInvalid,
10999
10915
  [classes.required]: isRequired,
11000
10916
  [classes.autoWidth]: hasSameOptionsWidth
11001
10917
  }),
11002
- ref: listRef,
11003
10918
  ...addDataAttributes$1(data, testId),
11004
- children: [
11005
- isNotEmpty(activeElementData) && /* @__PURE__ */ jsx("div", { className: classes.line, style: getSelectorLineStyle(activeElementData) }),
11006
- options.map((option) => {
11007
- const optionId = option.value.toString();
11008
- const isDisabledOption = option.isDisabled ?? isDisabled;
11009
- const isActiveOption = option.value === value;
11010
- return /* @__PURE__ */ jsx("div", { className: classes.optionWrapper, children: /* @__PURE__ */ jsxs(
11011
- "button",
11012
- {
11013
- type: "button",
11014
- className: clsx(classes.option, classes[size2], {
11015
- [classes.active]: isActiveOption,
11016
- [classes.disabled]: isDisabledOption
11017
- }),
11018
- disabled: isDisabledOption,
11019
- onClick: !isDisabledOption ? () => onChange(option.value) : void 0,
11020
- ...addDataTestId(testId, optionId),
11021
- children: [
11022
- isReactNodeNotEmpty(option.icon) && /* @__PURE__ */ jsx("div", { className: classes.optionIcon, children: renderIcon(option.icon) }),
11023
- /* @__PURE__ */ jsx("div", { className: classes.optionText, children: option.label })
11024
- ]
11025
- }
11026
- ) }, optionId);
11027
- })
11028
- ]
10919
+ children: options.map((option) => {
10920
+ const optionId = String(option.value);
10921
+ const isDisabledOption = option.isDisabled || isDisabled;
10922
+ const isActiveOption = option.value === value;
10923
+ return /* @__PURE__ */ jsxs(
10924
+ "button",
10925
+ {
10926
+ ref: isActiveOption ? updateVariables : void 0,
10927
+ type: "button",
10928
+ className: clsx(classes.option, {
10929
+ [classes.active]: isActiveOption,
10930
+ [classes.disabled]: isDisabledOption
10931
+ }),
10932
+ disabled: isDisabledOption,
10933
+ onClick: !isDisabledOption ? () => onChange(option.value) : void 0,
10934
+ ...addDataTestId(testId, optionId),
10935
+ children: [
10936
+ isReactNodeNotEmpty(option.icon) && /* @__PURE__ */ jsx("div", { className: classes.optionIcon, children: renderIcon(option.icon) }),
10937
+ /* @__PURE__ */ jsx("div", { className: classes.optionText, children: option.label })
10938
+ ]
10939
+ },
10940
+ optionId
10941
+ );
10942
+ })
11029
10943
  }
11030
10944
  );
11031
10945
  }