Skip to content

Commit

Permalink
feat: group properties (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
flops authored Jul 4, 2024
1 parent e3a919d commit ac39f67
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/components/DashKit/__stories__/DashKitGroupsShowcase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import {
ActionPanel,
DashKit,
DashKitDnDWrapper,
DashKitGroup,
DashKitProps,
DashkitGroupRenderProps,
ReactGridLayoutProps,
} from '../../..';
import {DEFAULT_GROUP, MenuItems} from '../../../helpers';
import {i18n} from '../../../i18n';
Expand Down Expand Up @@ -153,7 +155,7 @@ export const DashKitGroupsShowcase: React.FC = () => {
[config],
);

const groups = React.useMemo(
const groups = React.useMemo<DashKitGroup[]>(
() => [
{
id: fixedGroup,
Expand Down Expand Up @@ -185,6 +187,9 @@ export const DashKitGroupsShowcase: React.FC = () => {
</div>
);
},
gridProperties: (props: ReactGridLayoutProps) => {
return {...props, compactType: 'horizontal'};
},
},
{
id: DEFAULT_GROUP,
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;
}

0 comments on commit ac39f67

Please sign in to comment.