0.1.5 • Published 4 years ago

q-layout v0.1.5

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

q-layout

npm.io npm.io npm.io npm.io npm.io

CHANGELOG

中文文档

Download

yarn

yarn add q-layout

npm

npm install q-layout

cnpm

cpm install q-layout

Import

import q-layout in the entry file

import Vue from 'vue';
import QLayout from 'q-layout';
import 'q-layout/dist/q-layout.css';
Vue.use(QLayout);

And then you can use the layout component which call q-row anywhere

<q-row>template</q-row>

Why q-layout exists

In the usual development, we build the layout of a webpage by html css or a littile bit javascript, javascript will only be using more in some logics of codes but not the layout

During coding the layout of a webpage, we will code html first and name a className for an element, just like <div class="test"></div>, or naming it by an id, but whatever you should define a sign for an element.

And there is a rule in naming the className for elements which call bem, but if you are using vue, it will be not necessary because vue has a scoped css concept

But you can check that some vue ui components also use the bem naming rule, because it will be much more standard. But actually in the business code,it would be not much standard,the naming in the ui components is for the user who will change the style of the component conventionally,but it is not much more sense to use it in the business code

This is the first problem, Don't you find there is troublesome to name an element in business codes ? If you naming it easy you'd find it is not suitable,if naming it complexly you'd find it is trouble

But the proble can be resolved,we check it later

After you define a sign for an element, you need to code css for it, code css in vue is easy too.

just like this

<style scoped>
.test {
  color: blue;
}
</style>

But when the page's business is complex, there will be a a lot of elements and a lot of classeNames

Usualy we checked the layout of the page will not direct check the code, we will check it by using chrome's tool, and then if we may change the style we should find the sign of the element first and then can change css of the element

It will be not necessary, Image that, if you code css in html, Won't you cut down a step to change css

for example

There is an element which height is 100px

The usual way to code it is like this

<template>
  <div class="element">test</div>
</template>

<script>
export default {};
</script>

<style scoped>
.element {
  height: 100px;
}
</style>

We take full advantage of vue's feature, you can write css by using props

<template>
  <q-row h="100">test</q-row>
</template>

<script>
export default {};
</script>

It will be translated the same as the usual way

<div style="height:100.000px">test</div>

No Style and no Classnames, you don't need to cudgele your brains to think the naming of the className, and you don't need to find the position to change css,you will only need to find the element

And we provide many props to code the layout not only h

Props

We separate css properties by w3c standard classification

Options Explanation

The following documentation just like this

propsTypeRawDefaultTranslateType
bkColorStringbackgroundColor''pure

before we check the documentation for props we need know some explanations

props

the same as vue props

type

the same as vue prop's type

raw

the original css property

default

the same as vue prop's default value

translateType

different properties have different translatable result

  • default

to translate property by using the settings's unit and ratio

The default unit is px and the default ratio is 1

you can change that by the config.

for example

<q-row maxh="100">test</q-row>

the result is

<div style="maxHeight:100.000px">test</div>
  • pure

To direct translating property

for example

<q-row color="#000">test</q-row>

the result is

<div style="color:#000">test</div>
  • class

Translate property by setting classNames not styles

for example

<q-row dir="top">test</q-row>

the result is

<div class="q-layout-flexDirection-top">test</div>

and we have built-in class

.q-layout-flexDirection-top {
  flex-direction: column;
}
  • classPure

If property is a boolean will enable class if not will enable pure

for example

if property is a boolean

<q-row border></q-row>

The above generative result will be <div class="q-layout-border"></div>

if property is a string

<q-row border="1px solid #666"></q-row>

The above generative result will be border:1px solid #666 and will not set a className

The following are built-in props

Background

propsTypeRawDefaultTranslateType
backgroundStringbackground''pure
bkColorStringbackgroundColor''pure
bkPositionStringbackgroundPosition''pure
bkRepeatStringbackgroundRepeat''pure
bkSizeStringbackgroundSize''pure

Border

propsTypeRawDefaultTranslateType
borderTopString BooleanborderTop''classPure
borderRightString BooleanborderRight''classPure
borderBottomString BooleanborderBottom''classPure
borderLeftString BooleanborderLeft''classPure
borderString Booleanborder''classPure
radiusNumber StringborderRadius''default

Box

propsTypeRawDefaultTranslateType
overflowStringoverflow''pure
overflowXStringoverflowX''pure
overflowYStringoverflowY''pure

Color

propsTypeRawDefaultTranslateType
opacityString Numberopacity''pure

Dimension

propsTypeRawDefaultTranslateType
hString Numberheight''default
maxhString NumbermaxHeight''default
minhString NumberminHeight''default
wString Numberwidth''default
maxwString NumbermaxWidth''default
minwString NumberminWidth''default

Flex

propsTypeRawDefaultTranslateTypeDescription
dirStringflexDirection''classtop right bottom left
justifyStringjustifyContent''classflex-start flex-end center space-between space-around
alignStringalignItems''classflex-start flex-end center baseline stretch
flexStringflex''class1-10
centerBoolean''''classjustify=center & align=center

FontSize

propsTypeRawDefaultTranslateType
fontSizeStringfontSize''default
fontWeightStringfontWeight''pure

Margin

propsTypeRawDefaultTranslateType
marginString Numbermargin''default
mtString NumbermarginTop''default
mrString NumbermarginRight''default
mbString NumbermarginBottom''default
mlString NumbermarginLeft''default

Padding

propsTypeRawDefaultTranslateType
paddingString Numberpadding''default
ptString NumberpaddingTop''default
prString NumberpaddingRight''default
pbString NumberpaddingBottom''default
plString NumberpaddingLeft''default

Position

propsTypeRawDefaultTranslateType
positionStringposition''pure
tString Numbertop''default
rString Numberright''default
bString Numberbottom''default
lString Numberleft''default
displayStringdisplay''pure
floatStringfloat''pure
cursorStringcursor''pure
vaStringverticalAlign''pure
zIndexStringzIndex''pure
visibilityStringvisibility''pure

Text

propsTypeRawDefaultTranslateType
colorStringcolor''pure
lhStringlineHeight''default
indentStringtextIndent''default
letterSpacingStringletterSpacing''default
wordSpacingStringwordSpacing''default
textAlignStringtextAlign''pure
whiteSpaceStringwhiteSpace''pure
wordBreakStringwordBreak''pure

User

propsTypeRawDefaultTranslateType
boxStringboxSizing''pure

InstallOptions

OptionsTypeRequiredDefaultDescription
unitStringfalsepxcss unit
ratioStringfalse1css ratio
decimalsStringfalse3reserved decimal places
collectionsObjectfalse{}custom css property
  • unit

css unit which can be px rem vw or more, default value is px

import Vue from 'vue';
import QLayout from 'q-layout';
Vue.use(QLayout, {
  unit: 'vw'
});
<q-row h="100"></q-row>

The above generative result will be

<div style="height:100.000vw"></div>
  • ratio

The ratio between the practical value and the setting value, default value is 1

import Vue from 'vue';
import QLayout from 'q-layout';
Vue.use(QLayout, {
  unit: 'vw',
  ratio: 7.5
});
<q-row h="100"></q-row>

The above generative result will be

<div style="height:13.333vw"></div>

because 100/7.5 = 13.333

  • decimals

The computing value's reserved decimal, default value is 3

import Vue from 'vue';
import QLayout from 'q-layout';
Vue.use(QLayout, {
  unit: 'vw',
  ratio: 7.5,
  decimals: 2
});
<q-row h="100"></q-row>

The above generative result will be

<div style="height:13.33vw"></div>
  • collections

We provide many props that can satisfy many demands, but if you want to add some custom css property or change default css property you can use collections

collections has some configurations

Keep Original Property

The following configurations can change property based on the original property

alias

you can set an alias name for a property which is existing

import Vue from 'vue';
import QLayout from 'q-layout';
Vue.use(QLayout, {
  collections: {
    h: {
      alias: 'height'
    }
  }
});
<q-row height="100"></q-row>

so h and height can both translate to

<div style="height:100.000px"></div>

coverage

if you don't need the original property you can use this to coverage the old property

import Vue from 'vue';
import QLayout from 'q-layout';
Vue.use(QLayout, {
  collections: {
    h: {
      coverage: 'height'
    }
  }
});
<q-row height="100"></q-row>

now only height can be translated, the property h has been removed

<div style="height:100.000px"></div>

New Property

If you need to configurate some custom properties you can use following configurations raw type default pure class classPure

raw

The original css property, which is required

type

The property's type

The same as the prop's type in vue, which is required

default

The property's default value

The same as the prop's default value in vue, which is required

raw&type&default

The same as default of translateType

wo have collections maxh for maxHeight, we only give an example here

import Vue from 'vue';
import QLayout from 'q-layout';
Vue.use(QLayout, {
  collections: {
    maxh: {
      raw: 'maxHeight',
      type: [String, Number],
      default: ''
    }
  }
});
<q-row maxh="100"></q-row>

The above generative result will be

<div style="max-height:100.000px"></div>

And if maxh is a number,it will translate into percent

<q-row :maxh="10"></q-row>

The above generative result will be

<div style="max-height:10%"></div>

pure

The same as pure of translateType

import Vue from 'vue';
import QLayout from 'q-layout';
Vue.use(QLayout, {
  collections: {
    family: {
      raw: 'fontFamily',
      type: String,
      default: '',
      pure: ture
    }
  }
});
<q-row family="monospace"></q-row>

The above generative result will be

<div style="font-family:monospace"></div>

class

The same as class of translateType

import Vue from 'vue';
import QLayout from 'q-layout';
Vue.use(QLayout, {
  collections: {
    diyClass: {
      raw: 'rawDiyClass',
      type: String,
      default: '',
      class: ture
    }
  }
});
<q-row diyClass="test"></q-row>

The above generative result will be

<div class="q-layout-rawDiyClass-test"></div>

classPure

The same as classPure of translateType

wo have collections border for border, we only give an example here

import Vue from 'vue';
import QLayout from 'q-layout';
Vue.use(QLayout, {
  collections: {
    border: {
      raw: 'border',
      type: [Boolean, String],
      default: '',
      pureClass: ture
    }
  }
});

if property is a boolean

<q-row border></q-row>

The above generative result will be

<div class="q-layout-border"></div>

if property is a string

<q-row border="1px solid #666"></q-row>

The above generative result will be

<div style="border:1px solid #666"></div>

and will not set a className

Code Hints

We using vetur to provide code hints. The above props are all including in the configuration.

If you have set custom property by using alias coverage or custom property you may need add custom attributes, click here to see vetur's docs,click here to see our default attributes

0.1.5

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago