Skip to content
Open
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
125 changes: 122 additions & 3 deletions src/components/DashKit/__stories__/DashKitGroupsShowcase.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import React from 'react';

import {ChartColumn, Copy, Heading, Pin, Sliders, TextAlignLeft, TrashBin} from '@gravity-ui/icons';
import {Button, Icon} from '@gravity-ui/uikit';
import {
ArrowDown,
ArrowUp,
ChartColumn,
ChevronDown,
ChevronUp,
Copy,
Heading,
Pin,
Sliders,
TextAlignLeft,
TrashBin,
} from '@gravity-ui/icons';
import {Button, Disclosure, Icon} from '@gravity-ui/uikit';

import {
ActionPanel,
Expand Down Expand Up @@ -29,12 +41,22 @@
const MAX_ROWS = 2;
const GRID_COLUMNS = 36;

function arrayMove(arr: string[], oldIndex: number, newIndex: number) {
const copy = [...arr];
const item = copy[oldIndex];
copy[oldIndex] = copy[newIndex];
copy[newIndex] = item;

return copy;
}

export const DashKitGroupsShowcase: React.FC = () => {
const [editMode, setEditMode] = React.useState(true);
const [headerInteractions, setHeaderInteractions] = React.useState(true);
const [chartGroups, setChartGroups] = React.useState<string[]>(['1_group', '2_group']);

const onClick = () => {
console.log('click');

Check warning on line 59 in src/components/DashKit/__stories__/DashKitGroupsShowcase.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
};

const items = React.useMemo(
Expand Down Expand Up @@ -96,7 +118,7 @@
);
const [config, setConfig] = React.useState(getConfig(true));

const onChange = React.useCallback(({config}: {config: DashKitProps['config']}) => {

Check warning on line 121 in src/components/DashKit/__stories__/DashKitGroupsShowcase.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

'config' is already declared in the upper scope on line 119 column 12
setConfig(config);
}, []);

Expand Down Expand Up @@ -134,6 +156,91 @@
};
},
},
...chartGroups.map((id) => ({
id,
render: (id: string, children: React.ReactNode, props: DashkitGroupRenderProps) => {

Check warning on line 161 in src/components/DashKit/__stories__/DashKitGroupsShowcase.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

'id' is already declared in the upper scope on line 159 column 33
const itemsLength = props.items.length;
const showPlaceholder = itemsLength === 0 && !props.isDragging;

const isMultipleGroups = chartGroups.length > 1;
const groupIndex = chartGroups.indexOf(id);
const hasNext = isMultipleGroups && groupIndex < chartGroups.length - 1;
const hasPrev = isMultipleGroups && groupIndex > 0;

return (
<Disclosure
className={b('collapse-group')}
key={`key_${id}`}
defaultExpanded={true}
keepMounted={true}
>
<div
key={id}
className={b('collapse-group-grid', {
['edit-mode']: props.editMode,
})}
>
{showPlaceholder ? (
<div className={b('collapse-group-placeholder')}>
Empty group
</div>
) : (
children
)}
</div>

<Disclosure.Summary>
{(props) => (
<div className={b('collapse-group-header')}>
<div className={b('collapse-group-header-action')}>
<Button {...props}>
<Icon
data={props.expanded ? ChevronUp : ChevronDown}
/>
{`${id}: (${itemsLength})`}
</Button>
</div>
<div className={b('collapse-group-header-controls')}>
<Button
onClick={() => {
setChartGroups((groupOrder) => {
return arrayMove(
groupOrder,
groupIndex,
groupIndex - 1,
);
});
}}
disabled={!hasPrev}
view="flat"
size="l"
>
<Icon data={ArrowUp}></Icon>
</Button>
<Button
onClick={() => {
setChartGroups((groupOrder) => {
return arrayMove(
groupOrder,
groupIndex,
groupIndex + 1,
);
});
}}
disabled={!hasNext}
view="flat"
size="l"
>
<Icon data={ArrowDown}></Icon>
</Button>
</div>
</div>
)}
</Disclosure.Summary>
</Disclosure>
);
},
})),
{
id: DEFAULT_GROUP,
gridProperties: (props: ReactGridLayoutProps) => {
Expand All @@ -146,7 +253,7 @@
},
},
],
[headerInteractions],
[headerInteractions, chartGroups],
);

const overlayMenuItems = React.useMemo(() => {
Expand Down Expand Up @@ -321,6 +428,18 @@
? 'Disable header interactions'
: 'Enable header interactions'}
</Button>
<Button
size="m"
className={b('btn-contol')}
onClick={() =>
setChartGroups((current) => [
...current,
`${current.length + 1}_group`,
])
}
>
{'Add group'}
</Button>
</div>
</DemoRow>
<DemoRow title="Component view">
Expand Down
28 changes: 28 additions & 0 deletions src/components/DashKit/__stories__/DashKitShowcase.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,32 @@
flex: 1;
}
}

&__collapse-group {
margin-bottom: 8px;
}

&__collapse-group-placeholder {
flex: 1;
text-align: center;
}

&__collapse-group-header {
display: flex;
}

&__collapse-group-header-action {
flex-grow: 1;
}

&__collapse-group-grid {
min-height: 52px;
display: flex;
flex-direction: column;
margin-top: 8px;

> .react-grid-layout {
flex-grow: 1;
}
}
}
1 change: 1 addition & 0 deletions src/components/GridLayout/GridLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ export default class GridLayout extends React.PureComponent {
items,
layout,
context,
isDragging: this.state.isDragging,
};
return group.render(id, element, groupContext);
}
Expand Down
1 change: 1 addition & 0 deletions src/typings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type AddNewItemOptions = SetItemOptions & {
export interface DashkitGroupRenderProps {
config: Config;
editMode: boolean;
isDragging: boolean;
isMobile: boolean;
items: ConfigItem[];
layout: ConfigLayout[];
Expand Down
Loading