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: add groups grid properties #152

Merged
merged 1 commit into from
Jul 4, 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
ActionPanel,
DashKit,
DashKitDnDWrapper,
DashKitGroup,
DashKitProps,
DashkitGroupRenderProps,
ReactGridLayoutProps,
} from '../../..';
import {DEFAULT_GROUP, MenuItems} from '../../../helpers';
import {i18n} from '../../../i18n';
Expand Down Expand Up @@ -46,7 +48,7 @@
}, []);

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

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

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

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

Expand Down Expand Up @@ -153,7 +155,7 @@
[config],
);

const groups = React.useMemo(
const groups = React.useMemo<DashKitGroup[]>(
() => [
{
id: fixedGroup,
Expand Down Expand Up @@ -185,6 +187,9 @@
</div>
);
},
gridProperties: (props: ReactGridLayoutProps) => {
return {...props, compactType: 'horizontal'};
},
},
{
id: DEFAULT_GROUP,
Expand All @@ -196,10 +201,10 @@
return (
<DashKitDnDWrapper
onDragStart={() => {
console.log('dragStarted');

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

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
}}
onDragEnd={() => {
console.log('dragEnded');

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

View workflow job for this annotation

GitHub Actions / Verify Files

Unexpected console statement
}}
>
<Demo title="Groups">
Expand Down
14 changes: 10 additions & 4 deletions src/components/GridLayout/GridLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export default class GridLayout extends React.PureComponent {
);
}

renderGroup(group, renderLayout, renderItems, offset = 0) {
renderGroup(group, renderLayout, renderItems, offset = 0, groupGridProperties) {
const {
registerManager,
editMode,
Expand All @@ -213,11 +213,17 @@ export default class GridLayout extends React.PureComponent {
outerDnDEnable,
} = this.context;

const properties = groupGridProperties
? groupGridProperties({
...registerManager.gridLayout,
})
: registerManager.gridLayout;

return (
<Layout
{...registerManager.gridLayout}
key={`group_${group}`}
{...properties}
layout={renderLayout}
key={`group_${group}`}
isDraggable={editMode}
isResizable={editMode}
onDragStart={this._onStart}
Expand Down Expand Up @@ -314,7 +320,7 @@ export default class GridLayout extends React.PureComponent {
items = itemsByGroup[id] || [];
}

const element = this.renderGroup(id, layout, items, offset);
const element = this.renderGroup(id, layout, items, offset, group.gridProperties);
offset += items.length;

if (group.render) {
Expand Down
20 changes: 20 additions & 0 deletions src/typings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,31 @@ export interface DashkitGroupRenderProps {
layout: ConfigLayout[];
}

export type ReactGridLayoutProps = Omit<
ReactGridLayout.ReactGridLayoutProps,
| 'children'
| 'innerRef'
| 'key'
| 'layout'
| 'isDraggable'
| 'isResizable'
| 'onDragStart'
| 'onDragStop'
| 'onResizeStart'
| 'onResizeStop'
| 'draggableHandle'
| 'isDroppable'
| 'onDropDragOver'
| 'onDrop'
| 'draggableCancel'
>;

export interface DashKitGroup {
id?: string;
render?: (
id: string,
children: React.ReactNode,
props: DashkitGroupRenderProps,
) => React.ReactNode;
gridProperties?: (props: ReactGridLayoutProps) => ReactGridLayoutProps;
}
Loading