From 8eb531f576dbd17841df92f24025a728ca802261 Mon Sep 17 00:00:00 2001 From: Viktor Fedoseev Date: Tue, 8 Aug 2023 14:42:04 +0300 Subject: [PATCH 01/12] fix: long headers values --- src/lib/kit/components/Card/Card.scss | 4 ++++ src/lib/kit/components/Layouts/Section/Section.scss | 4 ++++ .../SimpleVerticalAccordeon/SimpleVerticalAccordeon.scss | 1 + .../SimpleVerticalAccordeon/SimpleVerticalAccordeon.tsx | 1 + 4 files changed, 10 insertions(+) diff --git a/src/lib/kit/components/Card/Card.scss b/src/lib/kit/components/Card/Card.scss index 57161988..06368e8c 100644 --- a/src/lib/kit/components/Card/Card.scss +++ b/src/lib/kit/components/Card/Card.scss @@ -52,6 +52,7 @@ display: flex; align-items: center; flex-grow: 1; + max-width: 543px; } &__header-right { @@ -67,6 +68,9 @@ font-size: var(--yc-text-subheader-2-font-size); font-weight: var(--yc-text-subheader-font-weight); line-height: var(--yc-text-subheader-2-line-height); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; } &__note { diff --git a/src/lib/kit/components/Layouts/Section/Section.scss b/src/lib/kit/components/Layouts/Section/Section.scss index 2f2151f6..48e554a7 100644 --- a/src/lib/kit/components/Layouts/Section/Section.scss +++ b/src/lib/kit/components/Layouts/Section/Section.scss @@ -13,6 +13,7 @@ $block: '.#{$ns}section'; &__header { margin-bottom: $normalOffset; + max-width: 543px; &_with-popover { display: flex; @@ -23,6 +24,9 @@ $block: '.#{$ns}section'; &__title { font-weight: 500; margin: 0; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; &_size_s { font-size: 13px; diff --git a/src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.scss b/src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.scss index f0541afd..562373d3 100644 --- a/src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.scss +++ b/src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.scss @@ -18,6 +18,7 @@ $animationDuration: 0.3s; &__header { display: flex; align-items: center; + max-width: 543px; &-inner { margin-left: -13px; diff --git a/src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.tsx b/src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.tsx index 393e9571..1d4f462f 100644 --- a/src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.tsx +++ b/src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.tsx @@ -103,6 +103,7 @@ export class SimpleVerticalAccordeon extends React.Component<
+ + + + {this.getTooltip()} {headerActionsTemplate ? headerActionsTemplate : null}
diff --git a/src/lib/kit/components/Views/MultiSelectView/MultiSelectView.tsx b/src/lib/kit/components/Views/MultiSelectView/MultiSelectView.tsx index a0495468..d2ce25a2 100644 --- a/src/lib/kit/components/Views/MultiSelectView/MultiSelectView.tsx +++ b/src/lib/kit/components/Views/MultiSelectView/MultiSelectView.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import {Popover} from '@gravity-ui/uikit'; +import {Popover, type PopoverProps} from '@gravity-ui/uikit'; import {ArrayView} from '../../../../core'; import {block} from '../../../utils'; @@ -9,6 +9,8 @@ import './MultiSelectView.scss'; const b = block('multiselect-view'); +const POPOVER_PLACEMENT: PopoverProps['placement'] = ['bottom', 'top']; + export const MultiSelectView: ArrayView = ({spec, value = []}) => { const _value = value as string[]; @@ -21,7 +23,7 @@ export const MultiSelectView: ArrayView = ({spec, value = []}) => { {items.map((item) => ( = ({spec, value}) => { const {initialValue, initialType} = useInitial(value || '', spec, [value]); const {scale} = spec.viewSpec.sizeParams!; @@ -17,7 +19,7 @@ const NumberWithScaleViewBase: React.FC = ({spec, value}) => { return (
Date: Wed, 9 Aug 2023 18:34:45 +0300 Subject: [PATCH 03/12] fix: add long title popover to card & section --- src/lib/kit/components/Card/Card.scss | 2 +- src/lib/kit/components/Card/Card.tsx | 20 +++++++++--- .../components/Layouts/Section/Section.scss | 2 +- .../components/Layouts/Section/Section.tsx | 32 ++++++++++++++----- .../SimpleVerticalAccordeon.tsx | 9 ++++-- 5 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/lib/kit/components/Card/Card.scss b/src/lib/kit/components/Card/Card.scss index 06368e8c..334ea9ed 100644 --- a/src/lib/kit/components/Card/Card.scss +++ b/src/lib/kit/components/Card/Card.scss @@ -52,7 +52,6 @@ display: flex; align-items: center; flex-grow: 1; - max-width: 543px; } &__header-right { @@ -71,6 +70,7 @@ white-space: nowrap; overflow: hidden; text-overflow: ellipsis; + max-width: 533px; } &__note { diff --git a/src/lib/kit/components/Card/Card.tsx b/src/lib/kit/components/Card/Card.tsx index 410b16ba..06906867 100644 --- a/src/lib/kit/components/Card/Card.tsx +++ b/src/lib/kit/components/Card/Card.tsx @@ -2,7 +2,7 @@ import React from 'react'; import {HelpPopover} from '@gravity-ui/components'; import {ChevronDown} from '@gravity-ui/icons'; -import {Button, Card as CardBase, Icon} from '@gravity-ui/uikit'; +import {Button, Card as CardBase, Icon, Popover, type PopoverProps} from '@gravity-ui/uikit'; import _ from 'lodash'; import {block} from '../../utils'; @@ -24,6 +24,9 @@ export interface CardProps { checkEmptyBody?: boolean; } +const POPOVER_PLACEMENT: PopoverProps['placement'] = ['bottom', 'top']; +const MAX_TITLE_WIDTH = 543; + export const Card: React.FC = ({ name, title: propsTitle, @@ -37,6 +40,7 @@ export const Card: React.FC = ({ children, }) => { const containerRef = React.useRef(null); + const titleRef = React.useRef(null); const bodyRef = React.useRef(null); const [open, setOpen] = React.useState(alwaysOpen || propsOpen || false); @@ -66,14 +70,18 @@ export const Card: React.FC = ({ [], ); + const titlePopoverDisabled = (titleRef.current?.offsetWidth || 0) < MAX_TITLE_WIDTH; + const title = React.useMemo(() => { if (_.isString(propsTitle)) { return ( -
{propsTitle}
+ +
{propsTitle}
+
{description ? (
- +
) : null}
@@ -81,7 +89,7 @@ export const Card: React.FC = ({ } return propsTitle; - }, [propsTitle, description]); + }, [propsTitle, titlePopoverDisabled, description]); React.useEffect(() => { if (!alwaysOpen && propsOpen !== undefined && propsOpen !== open) { @@ -112,7 +120,9 @@ export const Card: React.FC = ({ className={b('header', {interactive: Boolean(handleHeaderToggle)})} onClick={handleHeaderToggle} > -
{title}
+
+ {title} +
{actions ?
{actions}
: null} {alwaysOpen ? null : ( diff --git a/src/lib/kit/components/Layouts/Section/Section.scss b/src/lib/kit/components/Layouts/Section/Section.scss index 48e554a7..8653c4bd 100644 --- a/src/lib/kit/components/Layouts/Section/Section.scss +++ b/src/lib/kit/components/Layouts/Section/Section.scss @@ -13,7 +13,6 @@ $block: '.#{$ns}section'; &__header { margin-bottom: $normalOffset; - max-width: 543px; &_with-popover { display: flex; @@ -22,6 +21,7 @@ $block: '.#{$ns}section'; } &__title { + max-width: 533px; font-weight: 500; margin: 0; white-space: nowrap; diff --git a/src/lib/kit/components/Layouts/Section/Section.tsx b/src/lib/kit/components/Layouts/Section/Section.tsx index 0d3fbfdb..751698e5 100644 --- a/src/lib/kit/components/Layouts/Section/Section.tsx +++ b/src/lib/kit/components/Layouts/Section/Section.tsx @@ -1,16 +1,17 @@ import React from 'react'; import {HelpPopover} from '@gravity-ui/components'; +import {Popover, type PopoverProps} from '@gravity-ui/uikit'; import {GroupIndent} from '../../'; import {ErrorWrapper} from '../../../'; import { - FieldRenderProps, - FieldValue, - FormValue, - LayoutProps, - Spec, - ViewLayoutProps, + type FieldRenderProps, + type FieldValue, + type FormValue, + type LayoutProps, + type Spec, + type ViewLayoutProps, isArraySpec, isObjectSpec, } from '../../../../core'; @@ -27,6 +28,9 @@ interface SectionProps { descriptionAsSubtitle?: boolean; } +const POPOVER_PLACEMENT: PopoverProps['placement'] = ['bottom', 'top']; +const MAX_TITLE_WIDTH = 543; + const SectionBase = ({ name, spec, @@ -39,6 +43,7 @@ const SectionBase = ( }: (LayoutProps | ViewLayoutProps) & SectionProps) => { const meta = (restProps as FieldRenderProps).meta as FieldRenderProps['meta'] | undefined; const arrOrObjFlag = isArraySpec(spec) || isObjectSpec(spec); + const titleRef = React.useRef(null); let content = children; if (meta) { @@ -76,15 +81,26 @@ const SectionBase = ( } } + const layoutTitle = spec.viewSpec.layoutTitle; + const layoutTitlePopoverDisabled = (titleRef.current?.offsetWidth || 0) < MAX_TITLE_WIDTH; + return (
- {spec.viewSpec.layoutTitle ? ( + {layoutTitle ? (
-

{spec.viewSpec.layoutTitle}

+ +

+ {layoutTitle} +

+
{description}
) : null} diff --git a/src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.tsx b/src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.tsx index 7401a3cb..f7cd80ad 100644 --- a/src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.tsx +++ b/src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.tsx @@ -2,7 +2,7 @@ import React from 'react'; import {HelpPopover} from '@gravity-ui/components'; import {ChevronDown} from '@gravity-ui/icons'; -import {Button, Icon, Popover} from '@gravity-ui/uikit'; +import {Button, Icon, Popover, type PopoverProps} from '@gravity-ui/uikit'; import {block} from '../../utils'; @@ -35,6 +35,7 @@ interface SimpleVerticalAccordeonState { } const MAX_TITLE_TEXT_WIDTH = 495; /** 543px max-width - 48px of padding */ +const POPOVER_PLACEMENT: PopoverProps['placement'] = ['bottom', 'top']; export class SimpleVerticalAccordeon extends React.Component< SimpleVerticalAccordeonProps, @@ -108,7 +109,11 @@ export class SimpleVerticalAccordeon extends React.Component< Boolean(React.Children.count(children)) && (
- + + + + + {this.getTooltip()} {headerActionsTemplate ? headerActionsTemplate : null}
diff --git a/src/lib/kit/components/Views/MultiSelectView/MultiSelectView.tsx b/src/lib/kit/components/Views/MultiSelectView/MultiSelectView.tsx index a0495468..d2ce25a2 100644 --- a/src/lib/kit/components/Views/MultiSelectView/MultiSelectView.tsx +++ b/src/lib/kit/components/Views/MultiSelectView/MultiSelectView.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import {Popover} from '@gravity-ui/uikit'; +import {Popover, type PopoverProps} from '@gravity-ui/uikit'; import {ArrayView} from '../../../../core'; import {block} from '../../../utils'; @@ -9,6 +9,8 @@ import './MultiSelectView.scss'; const b = block('multiselect-view'); +const POPOVER_PLACEMENT: PopoverProps['placement'] = ['bottom', 'top']; + export const MultiSelectView: ArrayView = ({spec, value = []}) => { const _value = value as string[]; @@ -21,7 +23,7 @@ export const MultiSelectView: ArrayView = ({spec, value = []}) => { {items.map((item) => ( = ({spec, value}) => { const {initialValue, initialType} = useInitial(value || '', spec, [value]); const {scale} = spec.viewSpec.sizeParams!; @@ -17,7 +19,7 @@ const NumberWithScaleViewBase: React.FC = ({spec, value}) => { return (
Date: Wed, 9 Aug 2023 18:34:45 +0300 Subject: [PATCH 08/12] fix: add long title popover to card & section --- src/lib/kit/components/Card/Card.scss | 2 +- src/lib/kit/components/Card/Card.tsx | 20 +++++++++--- .../components/Layouts/Section/Section.scss | 2 +- .../components/Layouts/Section/Section.tsx | 32 ++++++++++++++----- .../SimpleVerticalAccordeon.tsx | 9 ++++-- 5 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/lib/kit/components/Card/Card.scss b/src/lib/kit/components/Card/Card.scss index 06368e8c..334ea9ed 100644 --- a/src/lib/kit/components/Card/Card.scss +++ b/src/lib/kit/components/Card/Card.scss @@ -52,7 +52,6 @@ display: flex; align-items: center; flex-grow: 1; - max-width: 543px; } &__header-right { @@ -71,6 +70,7 @@ white-space: nowrap; overflow: hidden; text-overflow: ellipsis; + max-width: 533px; } &__note { diff --git a/src/lib/kit/components/Card/Card.tsx b/src/lib/kit/components/Card/Card.tsx index 410b16ba..06906867 100644 --- a/src/lib/kit/components/Card/Card.tsx +++ b/src/lib/kit/components/Card/Card.tsx @@ -2,7 +2,7 @@ import React from 'react'; import {HelpPopover} from '@gravity-ui/components'; import {ChevronDown} from '@gravity-ui/icons'; -import {Button, Card as CardBase, Icon} from '@gravity-ui/uikit'; +import {Button, Card as CardBase, Icon, Popover, type PopoverProps} from '@gravity-ui/uikit'; import _ from 'lodash'; import {block} from '../../utils'; @@ -24,6 +24,9 @@ export interface CardProps { checkEmptyBody?: boolean; } +const POPOVER_PLACEMENT: PopoverProps['placement'] = ['bottom', 'top']; +const MAX_TITLE_WIDTH = 543; + export const Card: React.FC = ({ name, title: propsTitle, @@ -37,6 +40,7 @@ export const Card: React.FC = ({ children, }) => { const containerRef = React.useRef(null); + const titleRef = React.useRef(null); const bodyRef = React.useRef(null); const [open, setOpen] = React.useState(alwaysOpen || propsOpen || false); @@ -66,14 +70,18 @@ export const Card: React.FC = ({ [], ); + const titlePopoverDisabled = (titleRef.current?.offsetWidth || 0) < MAX_TITLE_WIDTH; + const title = React.useMemo(() => { if (_.isString(propsTitle)) { return ( -
{propsTitle}
+ +
{propsTitle}
+
{description ? (
- +
) : null}
@@ -81,7 +89,7 @@ export const Card: React.FC = ({ } return propsTitle; - }, [propsTitle, description]); + }, [propsTitle, titlePopoverDisabled, description]); React.useEffect(() => { if (!alwaysOpen && propsOpen !== undefined && propsOpen !== open) { @@ -112,7 +120,9 @@ export const Card: React.FC = ({ className={b('header', {interactive: Boolean(handleHeaderToggle)})} onClick={handleHeaderToggle} > -
{title}
+
+ {title} +
{actions ?
{actions}
: null} {alwaysOpen ? null : ( diff --git a/src/lib/kit/components/Layouts/Section/Section.scss b/src/lib/kit/components/Layouts/Section/Section.scss index 48e554a7..8653c4bd 100644 --- a/src/lib/kit/components/Layouts/Section/Section.scss +++ b/src/lib/kit/components/Layouts/Section/Section.scss @@ -13,7 +13,6 @@ $block: '.#{$ns}section'; &__header { margin-bottom: $normalOffset; - max-width: 543px; &_with-popover { display: flex; @@ -22,6 +21,7 @@ $block: '.#{$ns}section'; } &__title { + max-width: 533px; font-weight: 500; margin: 0; white-space: nowrap; diff --git a/src/lib/kit/components/Layouts/Section/Section.tsx b/src/lib/kit/components/Layouts/Section/Section.tsx index 0d3fbfdb..751698e5 100644 --- a/src/lib/kit/components/Layouts/Section/Section.tsx +++ b/src/lib/kit/components/Layouts/Section/Section.tsx @@ -1,16 +1,17 @@ import React from 'react'; import {HelpPopover} from '@gravity-ui/components'; +import {Popover, type PopoverProps} from '@gravity-ui/uikit'; import {GroupIndent} from '../../'; import {ErrorWrapper} from '../../../'; import { - FieldRenderProps, - FieldValue, - FormValue, - LayoutProps, - Spec, - ViewLayoutProps, + type FieldRenderProps, + type FieldValue, + type FormValue, + type LayoutProps, + type Spec, + type ViewLayoutProps, isArraySpec, isObjectSpec, } from '../../../../core'; @@ -27,6 +28,9 @@ interface SectionProps { descriptionAsSubtitle?: boolean; } +const POPOVER_PLACEMENT: PopoverProps['placement'] = ['bottom', 'top']; +const MAX_TITLE_WIDTH = 543; + const SectionBase = ({ name, spec, @@ -39,6 +43,7 @@ const SectionBase = ( }: (LayoutProps | ViewLayoutProps) & SectionProps) => { const meta = (restProps as FieldRenderProps).meta as FieldRenderProps['meta'] | undefined; const arrOrObjFlag = isArraySpec(spec) || isObjectSpec(spec); + const titleRef = React.useRef(null); let content = children; if (meta) { @@ -76,15 +81,26 @@ const SectionBase = ( } } + const layoutTitle = spec.viewSpec.layoutTitle; + const layoutTitlePopoverDisabled = (titleRef.current?.offsetWidth || 0) < MAX_TITLE_WIDTH; + return (
- {spec.viewSpec.layoutTitle ? ( + {layoutTitle ? (
-

{spec.viewSpec.layoutTitle}

+ +

+ {layoutTitle} +

+
{description}
) : null} diff --git a/src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.tsx b/src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.tsx index 7401a3cb..f7cd80ad 100644 --- a/src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.tsx +++ b/src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.tsx @@ -2,7 +2,7 @@ import React from 'react'; import {HelpPopover} from '@gravity-ui/components'; import {ChevronDown} from '@gravity-ui/icons'; -import {Button, Icon, Popover} from '@gravity-ui/uikit'; +import {Button, Icon, Popover, type PopoverProps} from '@gravity-ui/uikit'; import {block} from '../../utils'; @@ -35,6 +35,7 @@ interface SimpleVerticalAccordeonState { } const MAX_TITLE_TEXT_WIDTH = 495; /** 543px max-width - 48px of padding */ +const POPOVER_PLACEMENT: PopoverProps['placement'] = ['bottom', 'top']; export class SimpleVerticalAccordeon extends React.Component< SimpleVerticalAccordeonProps, @@ -108,7 +109,11 @@ export class SimpleVerticalAccordeon extends React.Component< Boolean(React.Children.count(children)) && (
- +