0.6.2 • Published 2 years ago

vue-smart-widget v0.6.2

Weekly downloads
286
License
MIT
Repository
github
Last release
2 years ago

vue-smart-widget

Smart widget is a flexible and extensible content container component. It includes header and body part, and widget body includes editboxcontentfooter. If you use with grid, it also have a draggable and resizable grid layout, base on Vue2.5.+ & vue-grid-layout.

Both Support Vue 2/Vue 3

Vue 2 | Vue 3

Installation

Vue 2

npm i vue-smart-widget -S

Vue 3

npm i vue-smart-widget@next -S

Import

Install all the components:

import Vue from 'vue'
import VueSmartWidget from 'vue-smart-widget'

Vue.use(VueSmartWidget)

Use widget only:

import Vue from 'vue'
import { SmartWidget } from 'vue-smart-widget'

Vue.component('SmartWidget', SmartWidget)

Usage

The SmartWidget is heavily base on vue-grid-layout, you can know about vue-grid-layout first, maybe you already use in your project.

Use widget only

Html

<smart-widget title="Default Widget">
  <p>
    It's default widget.
  </p>
</smart-widget>

Use widget with grid

import Vue from 'vue'
import { SmartWidgetGrid } from 'vue-smart-widget'

Vue.component('SmartWidgetGrid', SmartWidgetGrid)

Script

new Vue({
  data () {
    return {
      layout: [
        { x: 0, y: 0, w: 4, h: 4, i: '0' },
        { x: 4, y: 0, w: 4, h: 4, i: '1' },
        { x: 8, y: 0, w: 4, h: 4, i: '2' }
      ]
    }
  }
})

Html

<smart-widget-grid :layout="layout">
  <smart-widget slot="0" simple>
    <div class="layout-center">
      <h3>Simple Widget Without Header</h3>
    </div>
  </smart-widget>
  <smart-widget slot="1" title="Default Widget">
    <div class="layout-center">
      <h3>Default Widget With Header</h3>
    </div>
  </smart-widget>
  <smart-widget slot="2" title="Full Screen" fullscreen>
    <div class="layout-center">
      <h3>Make any widget full screen</h3>
    </div>
  </smart-widget>
</smart-widget-grid>

SmartWidget Props

AttributeDescriptionTypeAccepted valuesDefault
slotWidget slot, the unique identifier of the widget. refer to SmartWidgetGrid PropsString--
titleWidget Header TitleString--
subTitleWidget Header Sub TitleString--
paddingpadding in Widget BodyNumber, Array-[12, 20]
simpleWidget without HeaderBooleantrue or falsefalse
loadingdetermine whether it's loadingBooleantrue or falsefalse
fullscreendetermine whether have fullscreen buttonBooleantrue or falsefalse
collapsedetermine whether have collapse button, only support smart-widgetBooleantrue or falsefalse
refreshdetermine whether have refresh buttonBooleantrue or falsefalse
fixedHeightdetermine whether widget body's height is fixed, only support smart-widgetBooleantrue or falsefalse
shadowwhen to show card shadowsStringalwayshoverneveralways
translateYthe length of vertically transformNumber-0
isActiveddetermine whether widget is activedBooleantrue or falsefalse
activedColorthe actived widget box-shadow color, usually used with isActived attributeStringhex color#0076db
headerHeightWidget Header Height(px)Number-48

SmartWidget Methods

NameDescriptionParameters
moveEvery time an item is being moved and changes position(i, newX, newY)
movedEvery time an item is finished being moved and changes position(i, newX, newY)
resizeEvery time an item is being resized and changes size(i, newH, newW, newHPx, newWPx)
resizedEvery time an item is finished being moved and changes position(i, newH, newW, newHPx, newWPx)
container-resizedEvery time the grid item/layout container changes size (browser window or other)(i, newH, newW, newHPx, newWPx)
on-refreshUsed when the widget need fetching data from ajax methods, usually used with loading attribute-
before-fullscreenUsed when the widget before fullscreen, usually used with fullscreen attributetrue or false
on-fullscreenUsed when the widget is already fullscreen, usually used with fullscreen attributetrue or false

CSS Selector in SmartWidget

NameDescription
.smartwidgetThe main selector in SmartWidget
.is-activedThe state of widget is actived
.vue-grid-item.vue-grid-placeholderThe default css for the placeholder

SmartWidgetGrid Props

It's similar with vue-grid-layout. Care about the attribute layout, The value of layout must be an Array of Object items. Each item must have i, x, y, w and h proprties. especially, the i proprties, it's the unique identifier of the widget item, euqal with widget slot.

AttributeDescriptionTypeAccepted valuesDefault
layoutThis is the initial layout of the grid.Array-required
responsiveLayoutsThis is the initial layouts of the grid per breakpoint if responsive is set to true.Object-{}
colNumSays how many columns the grid has.Number-12
rowHeightSays what is a height of a single row in pixels.Number-48
maxRowsSays what is a maximal number of rows in the grid.Number-Infinity
marginSays what are the margins of elements inside the grid.Array-[10, 10]
draggableSays if the grids items are draggable.Booleantrue or falsetrue
resizableSays if the grids items are resizable.Booleantrue or falsetrue
isMirroredSays if the RTL/LTR should be reversed.Booleantrue or falsefalse
autoSizeSays if the container height should swells and contracts to fit contents.Booleantrue or falsetrue
verticalCompactSays if the layout should be compact vertically.Booleantrue or falsetrue
preventCollisionSays if grid items will move when being dragged over.Booleantrue or falsefalse
responsiveSays if the layout should be responsive to window width.Booleantrue or falsefalse
breakpointsBreakpoints defined for responsive layout. Sets widths on wich column number changes.Object-{ lg: 1200, md: 996, sm: 768, xs: 480, xxs: 0 }
colsDefines number of columns for each breakpoint.Object-{ lg: 12, md: 10, sm: 6, xs: 4, xxs: 2 }
isStaticControl all widgets won't be draggable, resizable or movedBooleantrue or falsefalse

Slot scopes

Each widget in the grid is resizable, slot-scope provide the widget attribute to the children component.

NameDescriptionType
contentHProvide the widget body content(widget-body__content) heightNumber

SmartWidgetGrid Methods

NameDescriptionParameters
layout-createdEmited on the component created lifecycle hooknewLayout
layout-before-mountEmited on the component beforeMount lifecycle hooknewLayout
layout-mountedEmited on the component mounted lifecycle hooknewLayout
layout-readyEmited when all the operations on the mount hook finishnewLayout
layout-updatedEvery time the layout has finished updating and positions of all grid-items are recalculatednewLayout
breakpoint-changedEvery time the breakpoint value changes due to window resize(newBreakpoint, newLayout)

License

MIT @xiaoluoboding

0.6.2

2 years ago

1.0.0-alpha.1

3 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.5

5 years ago

0.5.4

5 years ago

0.5.3

5 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.6

5 years ago

0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago