-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc64135
commit 54d6aa7
Showing
5 changed files
with
139 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<template> | ||
<widgets-grid :layouts="layouts" @update="updateLayouts"> | ||
<template v-for="(_, scopedSlotName) in $scopedSlots" v-slot:[scopedSlotName]="slotData"> | ||
<slot :name="scopedSlotName" v-bind="slotData" /> | ||
</template> | ||
</widgets-grid> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { mixins } from '@soramitsu/soraneo-wallet-web'; | ||
import cloneDeep from 'lodash/fp/cloneDeep'; | ||
import isEqual from 'lodash/fp/isEqual'; | ||
import { Component, Mixins, Prop, ModelSync } from 'vue-property-decorator'; | ||
import { Components } from '@/consts'; | ||
import { lazyComponent } from '@/router'; | ||
import type { ResponsiveLayouts } from '@/types/layout'; | ||
@Component({ | ||
components: { | ||
WidgetsGrid: lazyComponent(Components.WidgetsGrid), | ||
}, | ||
}) | ||
export default class Swap extends Mixins(mixins.LoadingMixin) { | ||
/** | ||
* Layout ID to sync it with storage | ||
*/ | ||
@Prop({ default: '', type: String }) readonly id!: string; | ||
/** | ||
* Layout widgets IDs | ||
*/ | ||
@Prop({ default: () => [], type: Array }) readonly widgets!: string[]; | ||
/** | ||
* Default layouts | ||
*/ | ||
@Prop({ default: () => ({}), type: Object }) readonly defaultLayouts!: ResponsiveLayouts; | ||
/** | ||
* Layout Widgets visibility by widget ID | ||
*/ | ||
@ModelSync('visibility', 'update:visibility', { type: Object }) | ||
widgetsVisibility!: Record<string, boolean>; | ||
layouts!: ResponsiveLayouts; | ||
created(): void { | ||
if (this.id) { | ||
// load layouts from storage | ||
} | ||
// or use default | ||
this.saveLayouts(this.defaultLayouts); | ||
} | ||
updateLayouts(updated: ResponsiveLayouts): void { | ||
if (!isEqual(this.layouts, updated)) { | ||
this.saveLayouts({ ...this.layouts, ...updated }); | ||
} | ||
} | ||
saveLayouts(layouts: ResponsiveLayouts) { | ||
this.layouts = cloneDeep(layouts); | ||
} | ||
toggleWidget(widgetId: string, isVisible: boolean): void { | ||
const layouts = cloneDeep(this.layouts); | ||
Object.keys(layouts).forEach((key) => { | ||
if (isVisible) { | ||
const widget = this.defaultLayouts[key].find((widget) => widget.i === widgetId); | ||
if (widget) { | ||
layouts[key] = [...layouts[key], { ...widget }]; | ||
} | ||
} else { | ||
layouts[key] = layouts[key].filter((widget) => widget.i !== widgetId); | ||
} | ||
}); | ||
this.saveLayouts(layouts); | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
import type { BreakpointKey } from '@/consts/layout'; | ||
|
||
export type WidgetRect = { | ||
export type WidgetSize = { | ||
w: number; | ||
h: number; | ||
minW?: number; | ||
minH?: number; | ||
maxW?: number; | ||
maxH?: number; | ||
}; | ||
|
||
export type LayoutWidgetConfig = WidgetRect & { | ||
i: string; | ||
export type WidgetPosition = { | ||
x: number; | ||
y: number; | ||
}; | ||
|
||
export type BreakpointConfig<T> = Record<BreakpointKey, T>; | ||
export type LayoutWidget = WidgetSize & | ||
WidgetPosition & { | ||
i: string; | ||
}; | ||
|
||
export type LayoutWidget = Required<LayoutWidgetConfig>; | ||
export type BreakpointConfig<T> = Record<BreakpointKey, T>; | ||
|
||
export type LayoutConfig = BreakpointConfig<number>; | ||
|
||
export type Layout<T extends LayoutWidgetConfig> = T[]; | ||
export type Layout = LayoutWidget[]; | ||
|
||
export type ResponsiveLayouts<T extends LayoutWidgetConfig> = Partial<BreakpointConfig<Layout<T>>>; | ||
export type ResponsiveLayouts = Partial<BreakpointConfig<Layout>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters