Skip to content

Commit

Permalink
update resizable grid item logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita-Polyakov committed Mar 21, 2024
1 parent ee1a4c0 commit 8971c01
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/components/shared/Widget/Base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@
import isEqual from 'lodash/fp/isEqual';
import { Component, Prop, Vue, Ref } from 'vue-property-decorator';
import type { Size } from '@/types/layout';
import { debouncedInputHandler } from '@/utils';
type Size = Pick<DOMRect, 'width' | 'height'>;
@Component
export default class BaseWidget extends Vue {
/**
Expand Down
22 changes: 19 additions & 3 deletions src/components/shared/Widget/Grid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@layout-updated="updateLayout"
>
<div v-if="lines" class="grid-lines" :style="gridLinesStyle" />
<grid-item v-for="widget in layout" :key="widget.i" v-bind="widget">
<grid-item v-for="widget in layout" :key="widget.i" :is-resizable="isResizable(widget)" v-bind="widget">
<slot
:name="widget.i"
v-bind="{
Expand All @@ -41,7 +41,14 @@ import { GridLayout, GridItem } from 'vue-grid-layout';
import { Component, Emit, Prop, Vue, Watch } from 'vue-property-decorator';
import { Breakpoint, BreakpointKey } from '@/consts/layout';
import type { Layout, LayoutConfig, ResponsiveLayouts, LayoutWidget, WidgetsVisibilityModel } from '@/types/layout';
import type {
Layout,
LayoutConfig,
ResponsiveLayouts,
LayoutWidget,
WidgetsVisibilityModel,
Size,
} from '@/types/layout';
import { layoutsStorage } from '@/utils/storage';
const DEFAULT_BREAKPOINTS: LayoutConfig = {
Expand Down Expand Up @@ -209,11 +216,20 @@ export default class WidgetsGrid extends Vue {
this.checkLayoutUpdate();
}
isResizable(widget: LayoutWidget): boolean {
if (!this.resizable) return false;
const { maxW, maxH, minW, minH } = widget;
const fixed = maxW === minW && maxH === minH;
return !fixed;
}
/**
* Calculate widget layout height
* Occurs after widget emits resize event with new own rect coordinates
*/
onResize(widgetId: string, rect: DOMRect): void {
onResize(widgetId: string, rect: Size): void {
const layout = cloneDeep(this.layout);
const widget = findWidgetInLayout(layout, widgetId);
Expand Down
2 changes: 2 additions & 0 deletions src/types/layout.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { BreakpointKey } from '@/consts/layout';

export type Size = Pick<DOMRect, 'width' | 'height'>;

export type WidgetSize = {
w: number;
h: number;
Expand Down
2 changes: 1 addition & 1 deletion src/views/Swap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class Swap extends Mixins(mixins.LoadingMixin, TranslationMixin,
{ x: 0, y: 0, w: 6, h: 20, minW: 4, minH: 20, i: SwapWidgets.Form },
{ x: 0, y: 20, w: 6, h: 4, minW: 4, minH: 4, i: SwapWidgets.Distribution },
{ x: 6, y: 0, w: 9, h: 20, minW: 4, minH: 20, i: SwapWidgets.Chart },
{ x: 6, y: 20, w: 6, h: 4, minW: 4, minH: 4, i: SwapWidgets.Customise },
{ x: 6, y: 20, w: 4, h: 4, minW: 4, minH: 4, i: SwapWidgets.Customise },
{ x: 15, y: 0, w: 9, h: 24, minW: 4, minH: 24, i: SwapWidgets.Transactions },
],
md: [
Expand Down

0 comments on commit 8971c01

Please sign in to comment.