Skip to content

Commit

Permalink
feat: add groups support for mobile layout (#227)
Browse files Browse the repository at this point in the history
* feat: add groups support for mobile layout

* chore: reworked contexts js files into ts

* feat: mobile layout render groups

* fix: adjust widget layout method

* fix: render empty mobile group
  • Loading branch information
flops authored Dec 18, 2024
1 parent 5cc5f1f commit c43b6b7
Show file tree
Hide file tree
Showing 20 changed files with 348 additions and 204 deletions.
12 changes: 6 additions & 6 deletions .storybook/decorators/withMobile.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';
import type {Decorator} from '@storybook/react';
import {MobileProvider} from '@gravity-ui/uikit';
import {DashKit} from '../../src/components/DashKit/DashKit';

export const withMobile: Decorator = (Story, context) => {
const platform = context.globals.platform;

return (
<MobileProvider mobile={platform === 'mobile'} platform={platform}>
<Story key={platform} {...context} />
</MobileProvider>
);
DashKit.setSettings({
isMobile: platform === 'mobile',
});

return <Story key={platform} {...context} />;
};
31 changes: 17 additions & 14 deletions src/components/DashKit/DashKit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import noop from 'lodash/noop';
import pick from 'lodash/pick';

import {DEFAULT_GROUP, DEFAULT_NAMESPACE} from '../../constants';
import {DashKitDnDContext} from '../../context/DashKitContext';
import {DashKitDnDContext} from '../../context';
import type {
Config,
ConfigItem,
Expand All @@ -13,7 +13,7 @@ import type {
ItemDropProps,
ItemsStateAndParams,
} from '../../shared';
import {
import type {
AddConfigItem,
AddNewItemOptions,
ContextProps,
Expand All @@ -31,10 +31,9 @@ import {RegisterManager, UpdateManager, reflowLayout} from '../../utils';
import {DashKitDnDWrapper} from '../DashKitDnDWrapper/DashKitDnDWrapper';
import DashKitView from '../DashKitView/DashKitView';
import GridLayout from '../GridLayout/GridLayout';
import {OverlayControlItem, OverlayControlsCtxShape} from '../OverlayControls/OverlayControls';
import type {OverlayControlItem, PreparedCopyItemOptions} from '../OverlayControls/OverlayControls';

interface DashKitGeneralProps
extends Pick<OverlayControlsCtxShape, 'getPreparedCopyItemOptions' | 'onCopyFulfill'> {
interface DashKitGeneralProps {
config: Config;
editMode: boolean;
draggableHandleClassName?: string;
Expand All @@ -43,32 +42,36 @@ interface DashKitGeneralProps
}

interface DashKitDefaultProps {
defaultGlobalParams: GlobalParams;
globalParams: GlobalParams;
itemsStateAndParams: ItemsStateAndParams;
settings: SettingsProps;
context: ContextProps;
noOverlay: boolean;
focusable?: boolean;
groups?: DashKitGroup[];

onItemEdit: (item: ConfigItem) => void;
onChange: (data: {
config: Config;
itemsStateAndParams: ItemsStateAndParams;
groups?: DashKitGroup[];
}) => void;

onDrop?: (dropProps: ItemDropProps) => void;

onItemMountChange?: (item: ConfigItem, state: {isAsync: boolean; isMounted: boolean}) => void;
onItemRender?: (item: ConfigItem) => void;

getPreparedCopyItemOptions?: (options: PreparedCopyItemOptions) => PreparedCopyItemOptions;
onCopyFulfill?: (error: null | Error, data?: PreparedCopyItemOptions) => void;

onDragStart?: ItemManipulationCallback;
onDrag?: ItemManipulationCallback;
onDragStop?: ItemManipulationCallback;
onResizeStart?: ItemManipulationCallback;
onResize?: ItemManipulationCallback;
onResizeStop?: ItemManipulationCallback;

defaultGlobalParams: GlobalParams;
globalParams: GlobalParams;
itemsStateAndParams: ItemsStateAndParams;
settings: SettingsProps;
context: ContextProps;
noOverlay: boolean;
focusable?: boolean;
groups?: DashKitGroup[];
}

export interface DashKitProps extends DashKitGeneralProps, Partial<DashKitDefaultProps> {}
Expand Down
2 changes: 1 addition & 1 deletion src/components/DashKitDnDWrapper/DashKitDnDWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

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

type DashKitDnDWrapperProps = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/DashKitView/DashKitView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import {DashKitContext} from '../../context/DashKitContext';
import {DashKitContext} from '../../context';
import {withContext} from '../../hocs/withContext';
import {useCalcPropsLayout} from '../../hooks/useCalcLayout';
import type {RegisterManager} from '../../utils';
Expand Down
2 changes: 1 addition & 1 deletion src/components/GridItem/GridItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import PropTypes from 'prop-types';

import {FOCUSED_CLASS_NAME} from '../../constants';
import {DashKitContext} from '../../context/DashKitContext';
import {DashKitContext} from '../../context';
import {cn} from '../../utils/cn';
import Item from '../Item/Item';
import OverlayControls from '../OverlayControls/OverlayControls';
Expand Down
3 changes: 2 additions & 1 deletion src/components/GridLayout/GridLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
DRAGGABLE_CANCEL_CLASS_NAME,
TEMPORARY_ITEM_ID,
} from '../../constants';
import {DashKitContext} from '../../context/DashKitContext';
import {DashKitContext} from '../../context';
import {resolveLayoutGroup} from '../../utils';
import GridItem from '../GridItem/GridItem';

Expand Down Expand Up @@ -742,6 +742,7 @@ export default class GridLayout extends React.PureComponent {

if (group.render) {
const groupContext = {
isMobile: false,
config,
editMode,
items,
Expand Down
123 changes: 0 additions & 123 deletions src/components/MobileLayout/MobileLayout.js

This file was deleted.

Loading

0 comments on commit c43b6b7

Please sign in to comment.