@astral/ui 1.52.0 → 1.53.0

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,7 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { UseClickAwayListenerOptions } from '../hooks';
3
- export type ClickAwayListenerProps = Omit<UseClickAwayListenerOptions, 'ref'> & {
3
+ export type ClickAwayListenerProps = Omit<UseClickAwayListenerOptions, 'ref' | 'isActive'> & {
4
4
  children: JSX.Element;
5
+ isActive?: boolean;
5
6
  };
6
7
  /**
7
8
  * @description компонент предоставляющий обертку для работы с хуком useClickAwayEffect
@@ -6,7 +6,7 @@ const hooks_1 = require("../hooks");
6
6
  /**
7
7
  * @description компонент предоставляющий обертку для работы с хуком useClickAwayEffect
8
8
  */
9
- const ClickAwayListener = ({ onClickAway, preventBubbling, isActive, children, }) => {
9
+ const ClickAwayListener = ({ onClickAway, preventBubbling, isActive = true, children, }) => {
10
10
  const ref = (0, react_1.useRef)(null);
11
11
  (0, hooks_1.useClickAwayEffect)({ ref, onClickAway, preventBubbling, isActive });
12
12
  return react_1.Children.only((0, react_1.cloneElement)(children, { ref }));
@@ -23,7 +23,7 @@ exports.OverflowTypography = (0, react_1.forwardRef)((_a, forwardedRef) => {
23
23
  const { ref, isOverflowed } = (0, useOverflowed_1.useOverflowed)(forwardedRef);
24
24
  const typographyProps = Object.assign(Object.assign({}, props), { ref,
25
25
  children,
26
- rowsCount });
26
+ rowsCount, hasMultipleRows: rowsCount > exports.DEFAULT_ROWS_COUNT });
27
27
  if (children && isOverflowed) {
28
28
  return ((0, jsx_runtime_1.jsx)(Tooltip_1.Tooltip, Object.assign({ title: children, disableInteractive: true }, tooltipProps, { children: (0, jsx_runtime_1.jsx)(styles_1.OverflowTypographyWrapper, Object.assign({}, typographyProps)) })));
29
29
  }
@@ -9,7 +9,17 @@ const useOverflowed = (forwardedRef) => {
9
9
  ? forwardedRef
10
10
  : localRef;
11
11
  const [isOverflowed, setOverflow] = (0, react_1.useState)(false);
12
- const handleResize = (0, react_1.useCallback)((0, lodash_es_1.debounce)(([{ target, contentRect }]) => setOverflow(contentRect.height < target.scrollHeight), 500), []);
12
+ const handleResize = (0, react_1.useCallback)((0, lodash_es_1.debounce)(([{ target, contentRect }]) => {
13
+ /**
14
+ * @description сверка высоты дом ноды и высоты скролл контейнера, если скролл больше, то значит компонент переполнен контентом
15
+ */
16
+ const isScrollHeightBigger = contentRect.height < target.scrollHeight;
17
+ /**
18
+ * @description сверка ширины дом ноды и ширины скролл контейнера, если скролл больше, то значит компонент переполнен контентом
19
+ */
20
+ const isScrollWidthBigger = target.scrollWidth > contentRect.width;
21
+ setOverflow(isScrollHeightBigger || isScrollWidthBigger);
22
+ }, 500), []);
13
23
  const resizeObserver = (0, react_1.useMemo)(() => new ResizeObserver(handleResize), []);
14
24
  (0, react_1.useLayoutEffect)(() => {
15
25
  if (ref === null || ref === void 0 ? void 0 : ref.current) {
@@ -2,4 +2,6 @@
2
2
  import { OverflowedProps } from './OverflowTypography';
3
3
  export declare const OverflowTypographyWrapper: import("@emotion/styled").StyledComponent<Pick<import("react").PropsWithChildren<import("../Typography").TypographyProps>, string | number | symbol> & import("react").RefAttributes<HTMLElement> & {
4
4
  theme?: import("@emotion/react").Theme | undefined;
5
+ } & {
6
+ hasMultipleRows: boolean;
5
7
  } & Required<OverflowedProps>, {}, {}>;
@@ -3,16 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OverflowTypographyWrapper = void 0;
4
4
  const styles_1 = require("../styles");
5
5
  const Typography_1 = require("../Typography");
6
+ // проверки на rowsCount в стилях нужны для того, чтобы элементы в одну строку обрезались бы по буквенно
7
+ // но если нужно обрезание по нескольким строчкам, тогда элементы будут обрезаться по словам
6
8
  exports.OverflowTypographyWrapper = (0, styles_1.styled)(Typography_1.Typography, {
7
- shouldForwardProp: (name) => name !== 'rowsCount',
9
+ shouldForwardProp: (name) => name !== 'rowsCount' && name !== 'hasMultipleRows',
8
10
  }) `
9
11
  /* stylelint-disable-next-line */
10
- display: -webkit-box;
12
+ display: ${({ hasMultipleRows }) => (hasMultipleRows ? '-webkit-box' : '')};
11
13
  max-width: 100%;
12
14
  overflow: hidden;
13
15
 
14
- white-space: initial;
16
+ white-space: ${({ hasMultipleRows }) => hasMultipleRows ? 'initial' : 'nowrap'};
15
17
  text-overflow: ellipsis;
16
18
  -webkit-line-clamp: ${({ rowsCount }) => rowsCount};
17
- -webkit-box-orient: vertical;
19
+ -webkit-box-orient: ${({ hasMultipleRows }) => hasMultipleRows ? 'vertical' : ''};
18
20
  `;
@@ -1,7 +1,8 @@
1
1
  /// <reference types="react" />
2
2
  import { UseClickAwayListenerOptions } from '../hooks';
3
- export type ClickAwayListenerProps = Omit<UseClickAwayListenerOptions, 'ref'> & {
3
+ export type ClickAwayListenerProps = Omit<UseClickAwayListenerOptions, 'ref' | 'isActive'> & {
4
4
  children: JSX.Element;
5
+ isActive?: boolean;
5
6
  };
6
7
  /**
7
8
  * @description компонент предоставляющий обертку для работы с хуком useClickAwayEffect
@@ -3,7 +3,7 @@ import { useClickAwayEffect } from '../hooks';
3
3
  /**
4
4
  * @description компонент предоставляющий обертку для работы с хуком useClickAwayEffect
5
5
  */
6
- export const ClickAwayListener = ({ onClickAway, preventBubbling, isActive, children, }) => {
6
+ export const ClickAwayListener = ({ onClickAway, preventBubbling, isActive = true, children, }) => {
7
7
  const ref = useRef(null);
8
8
  useClickAwayEffect({ ref, onClickAway, preventBubbling, isActive });
9
9
  return Children.only(cloneElement(children, { ref }));
@@ -20,7 +20,7 @@ export const OverflowTypography = forwardRef((_a, forwardedRef) => {
20
20
  const { ref, isOverflowed } = useOverflowed(forwardedRef);
21
21
  const typographyProps = Object.assign(Object.assign({}, props), { ref,
22
22
  children,
23
- rowsCount });
23
+ rowsCount, hasMultipleRows: rowsCount > DEFAULT_ROWS_COUNT });
24
24
  if (children && isOverflowed) {
25
25
  return (_jsx(Tooltip, Object.assign({ title: children, disableInteractive: true }, tooltipProps, { children: _jsx(OverflowTypographyWrapper, Object.assign({}, typographyProps)) })));
26
26
  }
@@ -6,7 +6,17 @@ export const useOverflowed = (forwardedRef) => {
6
6
  ? forwardedRef
7
7
  : localRef;
8
8
  const [isOverflowed, setOverflow] = useState(false);
9
- const handleResize = useCallback(debounce(([{ target, contentRect }]) => setOverflow(contentRect.height < target.scrollHeight), 500), []);
9
+ const handleResize = useCallback(debounce(([{ target, contentRect }]) => {
10
+ /**
11
+ * @description сверка высоты дом ноды и высоты скролл контейнера, если скролл больше, то значит компонент переполнен контентом
12
+ */
13
+ const isScrollHeightBigger = contentRect.height < target.scrollHeight;
14
+ /**
15
+ * @description сверка ширины дом ноды и ширины скролл контейнера, если скролл больше, то значит компонент переполнен контентом
16
+ */
17
+ const isScrollWidthBigger = target.scrollWidth > contentRect.width;
18
+ setOverflow(isScrollHeightBigger || isScrollWidthBigger);
19
+ }, 500), []);
10
20
  const resizeObserver = useMemo(() => new ResizeObserver(handleResize), []);
11
21
  useLayoutEffect(() => {
12
22
  if (ref === null || ref === void 0 ? void 0 : ref.current) {
@@ -2,4 +2,6 @@
2
2
  import { OverflowedProps } from './OverflowTypography';
3
3
  export declare const OverflowTypographyWrapper: import("@emotion/styled").StyledComponent<Pick<import("react").PropsWithChildren<import("../Typography").TypographyProps>, string | number | symbol> & import("react").RefAttributes<HTMLElement> & {
4
4
  theme?: import("@emotion/react").Theme | undefined;
5
+ } & {
6
+ hasMultipleRows: boolean;
5
7
  } & Required<OverflowedProps>, {}, {}>;
@@ -1,15 +1,17 @@
1
1
  import { styled } from '../styles';
2
2
  import { Typography } from '../Typography';
3
+ // проверки на rowsCount в стилях нужны для того, чтобы элементы в одну строку обрезались бы по буквенно
4
+ // но если нужно обрезание по нескольким строчкам, тогда элементы будут обрезаться по словам
3
5
  export const OverflowTypographyWrapper = styled(Typography, {
4
- shouldForwardProp: (name) => name !== 'rowsCount',
6
+ shouldForwardProp: (name) => name !== 'rowsCount' && name !== 'hasMultipleRows',
5
7
  }) `
6
8
  /* stylelint-disable-next-line */
7
- display: -webkit-box;
9
+ display: ${({ hasMultipleRows }) => (hasMultipleRows ? '-webkit-box' : '')};
8
10
  max-width: 100%;
9
11
  overflow: hidden;
10
12
 
11
- white-space: initial;
13
+ white-space: ${({ hasMultipleRows }) => hasMultipleRows ? 'initial' : 'nowrap'};
12
14
  text-overflow: ellipsis;
13
15
  -webkit-line-clamp: ${({ rowsCount }) => rowsCount};
14
- -webkit-box-orient: vertical;
16
+ -webkit-box-orient: ${({ hasMultipleRows }) => hasMultipleRows ? 'vertical' : ''};
15
17
  `;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@astral/ui",
3
- "version": "1.52.0",
3
+ "version": "1.53.0",
4
4
  "browser": "./esm/index.js",
5
5
  "main": "./index.js",
6
6
  "dependencies": {
7
- "@astral/icons": "^1.52.0",
7
+ "@astral/icons": "^1.53.0",
8
8
  "@emotion/cache": "11.7.1",
9
9
  "@emotion/react": "11.9.0",
10
10
  "@emotion/server": "11.4.0",