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

feat: extend grid properties #212

Merged
merged 10 commits into from
Oct 30, 2024
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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,19 @@ DashKit.setSettings({menu: [] as Array<MenuItem>});
#### DashKitDnDWrapper

```ts
type DraggedOverItem = {
h: number;
w: number;
type: string;
parent: string;
i?: number;
};

interface DashKitDnDWrapperProps {
dragImageSrc?: string;
onDragStart?: (dragProps: ItemDragProps) => void;
onDragEnd?: () => void;
onDropDragOver?: (draggedItem: DraggedOverItem, sharedItem: DraggedOverItem | null) => void | boolean;
}
```

Expand Down
57 changes: 47 additions & 10 deletions src/components/DashKit/__stories__/DashKitGroupsShowcase.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';

import {cn} from '@bem-react/classname';
import {ChartColumn, Copy, Heading, Pin, Sliders, TextAlignLeft, TrashBin} from '@gravity-ui/icons';
import {Button, Icon} from '@gravity-ui/uikit';

Expand All @@ -18,20 +17,24 @@
} from '../../..';
import {DEFAULT_GROUP, MenuItems} from '../../../helpers';
import {i18n} from '../../../i18n';
import {cn} from '../../../utils/cn';

import {Demo, DemoRow} from './Demo';
import {fixedGroup, getConfig} from './utils';

const b = cn('dashkit-demo');
import './DashKitShowcase.scss';

const b = cn('stories-dashkit-showcase');

const MAX_ROWS = 2;
const GRID_COLUMNS = 36;

export const DashKitGroupsShowcase: React.FC = () => {
const [editMode, setEditMode] = React.useState(true);
const [headerInteractions, setHeaderInteractions] = React.useState(true);

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

Check warning on line 37 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 @@ -93,7 +96,7 @@
);
const [config, setConfig] = React.useState(getConfig(true));

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

Check warning on line 99 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 97 column 12
setConfig(config);
}, []);

Expand All @@ -112,29 +115,43 @@
);
},
gridProperties: (props: ReactGridLayoutProps) => {
return {...props, compactType: 'horizontal-nowrap', maxRows: MAX_ROWS};
const overrideProps: ReactGridLayoutProps = {
...props,
compactType: 'horizontal-nowrap',
maxRows: MAX_ROWS,
};

if (headerInteractions) {
return overrideProps;
}

return {
...overrideProps,
noOverlay: true,
isResizable: false,
isDraggable: false,
resizeHandles: [],
};
},
},
{
id: DEFAULT_GROUP,
gridProperties: (props: ReactGridLayoutProps) => {
const copy = {...props};

return {
...copy,
...props,
compactType: null,
allowOverlap: true,
resizeHandles: ['s', 'w', 'e', 'n', 'sw', 'nw', 'se', 'ne'],
};
},
},
],
[],
[headerInteractions],
);

const overlayMenuItems = React.useMemo(() => {
const layoutById = config.layout.reduce<Record<string, ConfigLayout>>((memo, item) => {
memo[item.i] = item;

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

View workflow job for this annotation

GitHub Actions / Verify Files

Assignment to property of function parameter 'memo'
return memo;
}, {});
const maxOffset = config.layout
Expand Down Expand Up @@ -275,12 +292,31 @@
onDragEnd={() => {
console.log('dragEnded');
}}
onDropDragOver={(item) => headerInteractions || item.parent !== fixedGroup}
>
<Demo title="Groups">
<DemoRow title="Controls">
<Button view="action" size="m" onClick={() => setEditMode(!editMode)}>
{editMode ? 'Disable editMode' : 'Enable editMode'}
</Button>
<div className={b('controls-line')}>
<Button
view="action"
size="m"
className={b('btn-contol')}
onClick={() => setEditMode(!editMode)}
>
{editMode ? 'Disable editMode' : 'Enable editMode'}
</Button>
<Button
view="action"
size="m"
className={b('btn-contol')}
onClick={() => setHeaderInteractions(!headerInteractions)}
disabled={!editMode}
>
{headerInteractions
? 'Disable header interactions'
: 'Enable header interactions'}
</Button>
</div>
</DemoRow>
<DemoRow title="Component view">
<DashKit
Expand All @@ -292,6 +328,7 @@
overlayMenuItems={overlayMenuItems}
onDragStart={updateConfigOrder}
onResizeStart={updateConfigOrder}
context={{editModeHeader: headerInteractions}}
/>
<ActionPanel items={items} />
</DemoRow>
Expand Down
21 changes: 21 additions & 0 deletions src/components/DashKit/__stories__/DashKitShowcase.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,25 @@
margin-bottom: 10px;
margin-right: 10px;
}

&__inline-group {
background-color: var(--g-color-base-generic-ultralight);
position: sticky;
overflow: auto;
top: 0;
z-index: 3;
min-height: 52px;
display: flex;
flex-direction: column;
margin-bottom: 8px;

&_edit-mode {
position: static;
overflow: visible;
}

> .react-grid-layout {
flex: 1;
}
}
}
21 changes: 0 additions & 21 deletions src/components/DashKit/__stories__/Demo.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,6 @@
}
}

&-inline-group {
background-color: var(--g-color-base-generic-ultralight);
position: sticky;
overflow: auto;
top: 0;
z-index: 3;
min-height: 44px;
display: flex;
flex-direction: column;
margin-bottom: 8px;

&_edit-mode {
position: static;
overflow: visible;
}

> .react-grid-layout {
flex: 1;
}
}

.dashkit_focused {
outline: 1px dashed var(--g-color-text-danger);
}
Expand Down
19 changes: 13 additions & 6 deletions src/components/DashKitDnDWrapper/DashKitDnDWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React from 'react';

import {DashKitDnDContext} from '../../context/DashKitContext';
import type {ItemDragProps} from '../../shared';
import type {DraggedOverItem, ItemDragProps} from '../../shared';

type DashKitDnDWrapperProps = {
dragImageSrc?: string;
onDropDragOver?: (
draggedItem: DraggedOverItem,
sharedItem: DraggedOverItem | null,
) => void | boolean;
onDragStart?: (dragProps: ItemDragProps) => void;
onDragEnd?: () => void;
children: React.ReactElement;
Expand All @@ -22,20 +26,22 @@ export const DashKitDnDWrapper: React.FC<DashKitDnDWrapperProps> = (props) => {
return img;
}, [props.dragImageSrc]);

const onDragStartProp = props.onDragStart;
const onDragStart = React.useCallback(
(_: React.DragEvent<Element>, itemDragProps: ItemDragProps) => {
setDragProps(itemDragProps);
props.onDragStart?.(itemDragProps);
onDragStartProp?.(itemDragProps);
},
[setDragProps, props.onDragStart],
[setDragProps, onDragStartProp],
);

const onDragEndProp = props.onDragEnd;
const onDragEnd = React.useCallback(
(_: React.DragEvent<Element>) => {
setDragProps(null);
props.onDragEnd?.();
onDragEndProp?.();
},
[setDragProps, props.onDragEnd],
[setDragProps, onDragEndProp],
);

const contextValue = React.useMemo(() => {
Expand All @@ -44,8 +50,9 @@ export const DashKitDnDWrapper: React.FC<DashKitDnDWrapperProps> = (props) => {
dragImagePreview,
onDragStart,
onDragEnd,
onDropDragOver: props.onDropDragOver,
};
}, [dragProps, dragImagePreview, onDragStart, onDragEnd]);
}, [dragProps, dragImagePreview, onDragStart, onDragEnd, props.onDropDragOver]);

return (
<DashKitDnDContext.Provider value={contextValue}>
Expand Down
6 changes: 6 additions & 0 deletions src/components/GridItem/GridItem.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
}
}

.react-grid-item.dropping {
// Disable evety mouse event for dropping element placeholder
user-select: none;
pointer-events: none;
}

.react-grid-layout {
position: relative;
transition: height 200ms ease;
Expand Down
Loading
Loading