Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/lib/kit/components/Layouts/Accordeon/Accordeon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import {ArrayLayoutProps, ObjectLayoutProps} from '../../../../core';
import {ArrayLayoutProps, ObjectLayoutProps, isArrayItem} from '../../../../core';
import {ErrorWrapper} from '../../../components';
import {useErrorChecker} from '../../../hooks';
import {RemoveButton} from '../../RemoveButton';
Expand All @@ -21,7 +21,7 @@ export const Accordeon = <T extends ArrayLayoutProps | ObjectLayoutProps>({
}, [input.onDrop, setOpen]);

const removeButton = React.useMemo(() => {
if (spec.required || !input.value) {
if (!isArrayItem(name) && (spec.required || !input.value)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import {ArrayLayoutProps, ObjectLayoutProps} from '../../../../core';
import {ArrayLayoutProps, ObjectLayoutProps, isArrayItem} from '../../../../core';
import {useErrorChecker} from '../../../hooks';
import {block} from '../../../utils';
import {AccordeonCard} from '../../AccordeonCard';
Expand All @@ -26,7 +26,7 @@ export const AccordeonCardForm = <T extends ArrayLayoutProps | ObjectLayoutProps
}, [input.onDrop, setOpen]);

const removeButton = React.useMemo(() => {
if (spec.required || !input.value) {
if (!isArrayItem(name) && (spec.required || !input.value)) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/kit/components/Layouts/CardAccordeon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import {FieldValue, LayoutProps, Spec} from '../../../core';
import {FieldValue, LayoutProps, Spec, isArrayItem} from '../../../core';
import {Card, ErrorWrapper} from '../../components';
import {useErrorChecker} from '../../hooks';
import {RemoveButton} from '../RemoveButton';
Expand All @@ -22,7 +22,7 @@ export const CardAccordeon = <T extends FieldValue, S extends Spec>({
}, [input.onDrop, setOpen]);

const removeButton = React.useMemo(() => {
if (spec.required || !input.value) {
if (!isArrayItem(name) && (spec.required || !input.value)) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/kit/components/Layouts/CardSection.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import {FieldValue, LayoutProps, Spec} from '../../../core';
import {FieldValue, LayoutProps, Spec, isArrayItem} from '../../../core';
import {Card, ErrorWrapper} from '../../components';
import {RemoveButton} from '../RemoveButton';

Expand All @@ -12,7 +12,7 @@ export const CardSection = <T extends FieldValue, S extends Spec>({
children,
}: LayoutProps<T, undefined, undefined, S>) => {
const removeButton = React.useMemo(() => {
if (spec.required || !input.value) {
if (!isArrayItem(name) && (spec.required || !input.value)) {
return null;
}

Expand Down
30 changes: 18 additions & 12 deletions src/lib/kit/components/Layouts/Section/Section.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,29 @@ $block: '.#{$ns}section';
}

&__header {
display: flex;
align-items: center;
margin-bottom: $normalOffset;

&_with-popover {
display: flex;
&_size_s {
height: 18px;
}

&_size_m {
height: 20px;
}
}

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

&_size_s {
font-size: 13px;
}
&__title-popover {
display: flex;
align-items: center;

&_size_m {
font-size: 15px;
.g-popover__handler {
display: flex;
}
}

Expand All @@ -51,4 +53,8 @@ $block: '.#{$ns}section';
&__description {
margin-top: 4px;
}

&__remove-button {
margin-left: 5px;
}
}
31 changes: 29 additions & 2 deletions src/lib/kit/components/Layouts/Section/Section.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {HelpPopover} from '@gravity-ui/components';
import {Popover, Text} from '@gravity-ui/uikit';

import {GroupIndent} from '../../';
import {RemoveButton} from '../../RemoveButton';
import {COMMON_POPOVER_PLACEMENT, COMMON_TITLE_MAX_WIDTH, ErrorWrapper} from '../../../';
import {
FieldRenderProps,
Expand All @@ -12,6 +13,7 @@ import {
LayoutProps,
Spec,
ViewLayoutProps,
isArrayItem,
isArraySpec,
isObjectSpec,
} from '../../../../core';
Expand All @@ -38,11 +40,28 @@ const SectionBase = <D extends FieldValue, T extends FormValue, S extends Spec>(
children,
...restProps
}: (LayoutProps<D, undefined, undefined, S> | ViewLayoutProps<T, S>) & SectionProps) => {
const input = (restProps as FieldRenderProps<D>).input as
| FieldRenderProps<D>['input']
| undefined;
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;

const removeButton = React.useMemo(() => {
if (input?.value && input?.onDrop && isArrayItem(name)) {
return (
<RemoveButton
name={name}
onDrop={input.onDrop}
switcherClassName={b('remove-button')}
/>
);
}

return null;
}, [input?.value, input?.onDrop, name]);

if (meta) {
content = (
<ErrorWrapper name={name} meta={meta} withoutChildErrorStyles={arrOrObjFlag}>
Expand Down Expand Up @@ -88,18 +107,26 @@ const SectionBase = <D extends FieldValue, T extends FormValue, S extends Spec>(
<div
className={b('header', {
'with-popover': !descriptionAsSubtitle,
size: titleSize,
})}
>
<Popover
className={b('title-popover')}
content={layoutTitle}
placement={COMMON_POPOVER_PLACEMENT}
disabled={layoutTitlePopoverDisabled}
>
<h2 className={b('title', {size: titleSize})} ref={titleRef}>
<Text
className={b('title')}
variant={titleSize === 'm' ? 'body-2' : 'body-1'}
ref={titleRef}
ellipsis
>
{layoutTitle}
</h2>
</Text>
</Popover>
{description}
{removeButton}
</div>
) : null}
<div className={b('content')}>{content}</div>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions src/lib/kit/components/RemoveButton/RemoveButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ import i18n from '../../i18n';
export interface RemoveButtonProps {
name: string;
onDrop: () => void;
switcherClassName?: string;
}

export const RemoveButton: React.FC<RemoveButtonProps> = ({name, onDrop}) => {
export const RemoveButton: React.FC<RemoveButtonProps> = ({name, onDrop, switcherClassName}) => {
const items: DropdownMenuItemMixed<any>[] = React.useMemo(
() => [{text: i18n('label_delete'), action: onDrop, theme: 'danger'}],
[onDrop],
);

const switcher = React.useMemo(
() => (
<Button view="flat" qa={`${name}-drop-item`}>
<Button className={switcherClassName} view="flat" qa={`${name}-drop-item`}>
<Icon data={Ellipsis} size={16} />
</Button>
),
[],
[switcherClassName],
);

return <DropdownMenu switcher={switcher} items={items} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@ $animationDuration: 0.3s;
margin-left: -13px;
max-width: 533px;
}

.g-popover__handler {
display: flex;
}
}

&__tooltip {
margin: 0px 5px;

.g-help-popover {
display: flex;

& > span {
display: flex;
}
}
}

&__chevron {
Expand Down