Skip to content

Commit 37f3c6e

Browse files
authored
fix: long headers values (#76)
1 parent e1bbbec commit 37f3c6e

File tree

8 files changed

+82
-16
lines changed

8 files changed

+82
-16
lines changed

src/lib/kit/components/Card/Card.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@
6767
font-size: var(--yc-text-subheader-2-font-size);
6868
font-weight: var(--yc-text-subheader-font-weight);
6969
line-height: var(--yc-text-subheader-2-line-height);
70+
white-space: nowrap;
71+
overflow: hidden;
72+
text-overflow: ellipsis;
73+
max-width: 533px;
7074
}
7175

7276
&__note {

src/lib/kit/components/Card/Card.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import React from 'react';
22

33
import {HelpPopover} from '@gravity-ui/components';
44
import {ChevronDown} from '@gravity-ui/icons';
5-
import {Button, Card as CardBase, Icon} from '@gravity-ui/uikit';
5+
import {Button, Card as CardBase, Icon, Popover} from '@gravity-ui/uikit';
66
import _ from 'lodash';
77

8+
import {COMMON_POPOVER_PLACEMENT, COMMON_TITLE_MAX_WIDTH} from '../../constants/common';
89
import {block} from '../../utils';
910

1011
import './Card.scss';
@@ -37,6 +38,7 @@ export const Card: React.FC<CardProps> = ({
3738
children,
3839
}) => {
3940
const containerRef = React.useRef<HTMLDivElement>(null);
41+
const titleRef = React.useRef<HTMLDivElement>(null);
4042
const bodyRef = React.useRef<HTMLDivElement>(null);
4143
const [open, setOpen] = React.useState(alwaysOpen || propsOpen || false);
4244

@@ -66,22 +68,35 @@ export const Card: React.FC<CardProps> = ({
6668
[],
6769
);
6870

71+
const titlePopoverDisabled = (titleRef.current?.offsetWidth || 0) <= COMMON_TITLE_MAX_WIDTH;
72+
6973
const title = React.useMemo(() => {
7074
if (_.isString(propsTitle)) {
7175
return (
7276
<React.Fragment>
73-
<div className={b('title')}>{propsTitle}</div>
77+
<Popover
78+
content={propsTitle}
79+
disabled={titlePopoverDisabled}
80+
placement={COMMON_POPOVER_PLACEMENT}
81+
>
82+
<div ref={titleRef} className={b('title')}>
83+
{propsTitle}
84+
</div>
85+
</Popover>
7486
{description ? (
7587
<div className={b('note')}>
76-
<HelpPopover htmlContent={description} placement={['bottom', 'top']} />
88+
<HelpPopover
89+
htmlContent={description}
90+
placement={COMMON_POPOVER_PLACEMENT}
91+
/>
7792
</div>
7893
) : null}
7994
</React.Fragment>
8095
);
8196
}
8297

8398
return propsTitle;
84-
}, [propsTitle, description]);
99+
}, [propsTitle, titlePopoverDisabled, description]);
85100

86101
React.useEffect(() => {
87102
if (!alwaysOpen && propsOpen !== undefined && propsOpen !== open) {

src/lib/kit/components/Layouts/Section/Section.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ $block: '.#{$ns}section';
2121
}
2222

2323
&__title {
24+
max-width: 533px;
2425
font-weight: 500;
2526
margin: 0;
27+
white-space: nowrap;
28+
overflow: hidden;
29+
text-overflow: ellipsis;
2630

2731
&_size_s {
2832
font-size: 13px;

src/lib/kit/components/Layouts/Section/Section.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
22

33
import {HelpPopover} from '@gravity-ui/components';
4+
import {Popover} from '@gravity-ui/uikit';
45

56
import {GroupIndent} from '../../';
6-
import {ErrorWrapper} from '../../../';
7+
import {COMMON_POPOVER_PLACEMENT, COMMON_TITLE_MAX_WIDTH, ErrorWrapper} from '../../../';
78
import {
89
FieldRenderProps,
910
FieldValue,
@@ -39,6 +40,7 @@ const SectionBase = <D extends FieldValue, T extends FormValue, S extends Spec>(
3940
}: (LayoutProps<D, S> | ViewLayoutProps<T, S>) & SectionProps) => {
4041
const meta = (restProps as FieldRenderProps<D>).meta as FieldRenderProps<D>['meta'] | undefined;
4142
const arrOrObjFlag = isArraySpec(spec) || isObjectSpec(spec);
43+
const titleRef = React.useRef<HTMLHeadingElement>(null);
4244
let content = children;
4345

4446
if (meta) {
@@ -76,15 +78,27 @@ const SectionBase = <D extends FieldValue, T extends FormValue, S extends Spec>(
7678
}
7779
}
7880

81+
const layoutTitle = spec.viewSpec.layoutTitle;
82+
const layoutTitlePopoverDisabled =
83+
(titleRef.current?.offsetWidth || 0) <= COMMON_TITLE_MAX_WIDTH;
84+
7985
return (
8086
<section className={b()}>
81-
{spec.viewSpec.layoutTitle ? (
87+
{layoutTitle ? (
8288
<div
8389
className={b('header', {
8490
'with-popover': !descriptionAsSubtitle,
8591
})}
8692
>
87-
<h2 className={b('title', {size: titleSize})}>{spec.viewSpec.layoutTitle}</h2>
93+
<Popover
94+
content={layoutTitle}
95+
placement={COMMON_POPOVER_PLACEMENT}
96+
disabled={layoutTitlePopoverDisabled}
97+
>
98+
<h2 className={b('title', {size: titleSize})} ref={titleRef}>
99+
{layoutTitle}
100+
</h2>
101+
</Popover>
88102
{description}
89103
</div>
90104
) : null}

src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ $animationDuration: 0.3s;
2121

2222
&-inner {
2323
margin-left: -13px;
24+
max-width: 533px;
2425
}
2526
}
2627

src/lib/kit/components/SimpleVerticalAccordeon/SimpleVerticalAccordeon.tsx

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import React from 'react';
22

33
import {HelpPopover} from '@gravity-ui/components';
44
import {ChevronDown} from '@gravity-ui/icons';
5-
import {Button, Icon} from '@gravity-ui/uikit';
5+
import {Button, Icon, Popover} from '@gravity-ui/uikit';
66

7+
import {COMMON_POPOVER_PLACEMENT} from '../../constants/common';
78
import {block} from '../../utils';
89

910
import './SimpleVerticalAccordeon.scss';
@@ -34,6 +35,8 @@ interface SimpleVerticalAccordeonState {
3435
isFirstRender: boolean;
3536
}
3637

38+
const TITLE_TEXT_MAX_WIDTH = 485; /** 533px (COMMON_TITLE_MAX_WIDTH) - 48px of padding */
39+
3740
export class SimpleVerticalAccordeon extends React.Component<
3841
SimpleVerticalAccordeonProps,
3942
SimpleVerticalAccordeonState
@@ -45,6 +48,7 @@ export class SimpleVerticalAccordeon extends React.Component<
4548
};
4649

4750
componentRef = React.createRef<HTMLDivElement>();
51+
titleRef = React.createRef<HTMLElement>();
4852

4953
constructor(props: SimpleVerticalAccordeonProps) {
5054
super(props);
@@ -97,19 +101,37 @@ export class SimpleVerticalAccordeon extends React.Component<
97101
return null;
98102
}
99103

104+
const title = this.getTitle();
105+
const titlePopoverDisabled =
106+
(this.titleRef.current?.offsetWidth || 0) <= TITLE_TEXT_MAX_WIDTH;
107+
100108
return (
101109
Boolean(React.Children.count(children)) && (
102110
<div className={b({branch: withBranchView, view: viewLayout}, className)}>
103111
<div className={b('header')}>
104-
<Button
105-
view="flat"
106-
className={b('header-inner', buttonClassName)}
107-
onClick={this.handleClick}
108-
qa={`${name}-accordeon-toggler`}
112+
<Popover
113+
content={title}
114+
disabled={titlePopoverDisabled}
115+
placement={COMMON_POPOVER_PLACEMENT}
109116
>
110-
<b className={b('title', {size: titleSize})}>{this.getTitle()}</b>
111-
<Icon data={ChevronDown} className={b('chevron', {open})} size={16} />
112-
</Button>
117+
<Button
118+
view="flat"
119+
className={b('header-inner', buttonClassName)}
120+
onClick={this.handleClick}
121+
qa={`${name}-accordeon-toggler`}
122+
width="auto"
123+
>
124+
<b ref={this.titleRef} className={b('title', {size: titleSize})}>
125+
{title}
126+
</b>
127+
<Icon
128+
data={ChevronDown}
129+
className={b('chevron', {open})}
130+
size={16}
131+
/>
132+
</Button>
133+
</Popover>
134+
113135
{this.getTooltip()}
114136
{headerActionsTemplate ? headerActionsTemplate : null}
115137
</div>

src/lib/kit/constants/common.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type {PopoverProps} from '@gravity-ui/uikit';
2+
3+
export const COMMON_POPOVER_PLACEMENT: PopoverProps['placement'] = ['bottom', 'top'];
4+
5+
export const COMMON_TITLE_MAX_WIDTH = 533;

src/lib/kit/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './config';
2+
export * from './common';

0 commit comments

Comments
 (0)