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 support for mobile layout #227

Merged
merged 6 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
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 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 @@
ItemDropProps,
ItemsStateAndParams,
} from '../../shared';
import {
import type {
AddConfigItem,
AddNewItemOptions,
ContextProps,
Expand All @@ -31,10 +31,9 @@
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 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 All @@ -90,7 +93,7 @@
defaultProps: defaultGridProps,
groups: groups.reduce<Record<string, GridReflowOptions>>((memo, g) => {
const groupId = g.id || DEFAULT_GROUP;
memo[groupId] = g.gridProperties

Check warning on line 96 in src/components/DashKit/DashKit.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

Assignment to property of function parameter 'memo'

Check warning on line 96 in src/components/DashKit/DashKit.tsx

View workflow job for this annotation

GitHub Actions / build

Assignment to property of function parameter 'memo'
? getReflowProps(g.gridProperties(defaultGridProps))
: defaultGridProps;

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 @@ -731,6 +731,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
Loading