Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: long headers values #76

Merged
merged 15 commits into from
Aug 14, 2023
4 changes: 4 additions & 0 deletions src/lib/kit/components/Card/Card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
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;
max-width: 533px;
}

&__note {
Expand Down
23 changes: 19 additions & 4 deletions src/lib/kit/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ 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} from '@gravity-ui/uikit';
import _ from 'lodash';

import {COMMON_POPOVER_PLACEMENT, COMMON_TITLE_MAX_WIDTH} from '../../constants/common';
import {block} from '../../utils';

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

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

const titlePopoverDisabled = (titleRef.current?.offsetWidth || 0) <= COMMON_TITLE_MAX_WIDTH;

const title = React.useMemo(() => {
if (_.isString(propsTitle)) {
return (
<React.Fragment>
<div className={b('title')}>{propsTitle}</div>
<Popover
content={propsTitle}
disabled={titlePopoverDisabled}
placement={COMMON_POPOVER_PLACEMENT}
>
<div ref={titleRef} className={b('title')}>
{propsTitle}
</div>
</Popover>
{description ? (
<div className={b('note')}>
<HelpPopover htmlContent={description} placement={['bottom', 'top']} />
<HelpPopover
htmlContent={description}
placement={COMMON_POPOVER_PLACEMENT}
/>
</div>
) : null}
</React.Fragment>
);
}

return propsTitle;
}, [propsTitle, description]);
}, [propsTitle, titlePopoverDisabled, description]);

React.useEffect(() => {
if (!alwaysOpen && propsOpen !== undefined && propsOpen !== open) {
Expand Down
4 changes: 4 additions & 0 deletions src/lib/kit/components/Layouts/Section/Section.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ $block: '.#{$ns}section';
}

&__title {
max-width: 533px;
font-weight: 500;
margin: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;

&_size_s {
font-size: 13px;
Expand Down
20 changes: 17 additions & 3 deletions src/lib/kit/components/Layouts/Section/Section.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React from 'react';

import {HelpPopover} from '@gravity-ui/components';
import {Popover} from '@gravity-ui/uikit';

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

if (meta) {
Expand Down Expand Up @@ -76,15 +78,27 @@ const SectionBase = <D extends FieldValue, T extends FormValue, S extends Spec>(
}
}

const layoutTitle = spec.viewSpec.layoutTitle;
const layoutTitlePopoverDisabled =
(titleRef.current?.offsetWidth || 0) <= COMMON_TITLE_MAX_WIDTH;

return (
<section className={b()}>
{spec.viewSpec.layoutTitle ? (
{layoutTitle ? (
<div
className={b('header', {
'with-popover': !descriptionAsSubtitle,
})}
>
<h2 className={b('title', {size: titleSize})}>{spec.viewSpec.layoutTitle}</h2>
<Popover
content={layoutTitle}
placement={COMMON_POPOVER_PLACEMENT}
disabled={layoutTitlePopoverDisabled}
>
<h2 className={b('title', {size: titleSize})} ref={titleRef}>
{layoutTitle}
</h2>
</Popover>
{description}
</div>
) : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ $animationDuration: 0.3s;

&-inner {
margin-left: -13px;
max-width: 533px;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import React from 'react';

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

import {COMMON_POPOVER_PLACEMENT} from '../../constants/common';
import {block} from '../../utils';

import './SimpleVerticalAccordeon.scss';
Expand Down Expand Up @@ -34,6 +35,8 @@ interface SimpleVerticalAccordeonState {
isFirstRender: boolean;
}

const TITLE_TEXT_MAX_WIDTH = 485; /** 533px (COMMON_TITLE_MAX_WIDTH) - 48px of padding */

export class SimpleVerticalAccordeon extends React.Component<
SimpleVerticalAccordeonProps,
SimpleVerticalAccordeonState
Expand All @@ -45,6 +48,7 @@ export class SimpleVerticalAccordeon extends React.Component<
};

componentRef = React.createRef<HTMLDivElement>();
titleRef = React.createRef<HTMLElement>();

constructor(props: SimpleVerticalAccordeonProps) {
super(props);
Expand Down Expand Up @@ -97,19 +101,37 @@ export class SimpleVerticalAccordeon extends React.Component<
return null;
}

const title = this.getTitle();
const titlePopoverDisabled =
(this.titleRef.current?.offsetWidth || 0) <= TITLE_TEXT_MAX_WIDTH;

return (
Boolean(React.Children.count(children)) && (
<div className={b({branch: withBranchView, view: viewLayout}, className)}>
<div className={b('header')}>
<Button
view="flat"
className={b('header-inner', buttonClassName)}
onClick={this.handleClick}
qa={`${name}-accordeon-toggler`}
<Popover
content={title}
disabled={titlePopoverDisabled}
placement={COMMON_POPOVER_PLACEMENT}
>
<b className={b('title', {size: titleSize})}>{this.getTitle()}</b>
<Icon data={ChevronDown} className={b('chevron', {open})} size={16} />
</Button>
<Button
view="flat"
className={b('header-inner', buttonClassName)}
onClick={this.handleClick}
qa={`${name}-accordeon-toggler`}
width="auto"
>
<b ref={this.titleRef} className={b('title', {size: titleSize})}>
{title}
</b>
<Icon
data={ChevronDown}
className={b('chevron', {open})}
size={16}
/>
</Button>
</Popover>

{this.getTooltip()}
{headerActionsTemplate ? headerActionsTemplate : null}
</div>
Expand Down
5 changes: 5 additions & 0 deletions src/lib/kit/constants/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type {PopoverProps} from '@gravity-ui/uikit';

export const COMMON_POPOVER_PLACEMENT: PopoverProps['placement'] = ['bottom', 'top'];

export const COMMON_TITLE_MAX_WIDTH = 533;
1 change: 1 addition & 0 deletions src/lib/kit/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './config';
export * from './common';