Skip to content

Commit

Permalink
add Row and Col component
Browse files Browse the repository at this point in the history
  • Loading branch information
icarusion committed May 15, 2018
1 parent e738d26 commit 97cd37b
Show file tree
Hide file tree
Showing 21 changed files with 121 additions and 29 deletions.
38 changes: 38 additions & 0 deletions build/build-dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const gulp = require('gulp');
const less = require('gulp-less');
const cssmin = require('gulp-clean-css');
const rename = require('gulp-rename');

gulp.task('compile-css', () => {
return gulp.src(['../src/**/*.less', '!../src/**/_*.less'])
.pipe(less())
.pipe(cssmin())
.pipe(rename((path) => {
path.extname = '.wxss';
}))
.pipe(gulp.dest('../examples/dist/'));
});

gulp.task('compile-js', () => {
return gulp.src(['../src/**/*.js'])
.pipe(gulp.dest('../examples/dist/'));
});

gulp.task('compile-json', () => {
return gulp.src(['../src/**/*.json'])
.pipe(gulp.dest('../examples/dist/'));
});

gulp.task('compile-wxml', () => {
return gulp.src(['../src/**/*.wxml'])
.pipe(gulp.dest('../examples/dist/'));
});

gulp.task('auto', () => {
gulp.watch('../src/**/*.less', ['compile-css']);
gulp.watch('../src/**/*.js', ['compile-js']);
gulp.watch('../src/**/*.json', ['compile-json']);
gulp.watch('../src/**/*.wxml', ['compile-wxml']);
});

gulp.task('default', ['compile-css', 'compile-js', 'compile-json', 'compile-wxml', 'auto']);
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"pages":[
"pages/list/index"
"pages/layout/index"
],
"window": {
"navigationBarBackgroundColor": "#FAFAFA",
Expand Down
6 changes: 0 additions & 6 deletions examples/pages/grid/index.json

This file was deleted.

Empty file removed examples/pages/grid/index.wxml
Empty file.
Empty file removed examples/pages/grid/index.wxss
Empty file.
File renamed without changes.
7 changes: 7 additions & 0 deletions examples/pages/layout/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"navigationBarTitleText": "Grid 栅格",
"usingComponents": {
"i-row": "../../dist/row/index",
"i-col": "../../dist/col/index"
}
}
14 changes: 14 additions & 0 deletions examples/pages/layout/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<i-row i-class="row-class">
<i-col span="8" i-class="col-class">col-8</i-col>
<i-col span="8" i-class="col-class light">col-8</i-col>
<i-col span="8" i-class="col-class">col-8</i-col>
</i-row>

<i-row i-class="row-class">
<i-col span="4" i-class="col-class">col-4</i-col>
<i-col span="10" offset="4" i-class="col-class">col-10 offset-4</i-col>
</i-row>

<i-row i-class="row-class">
<i-col span="12" offset="12" i-class="col-class">col-12 offset-12</i-col>
</i-row>
14 changes: 14 additions & 0 deletions examples/pages/layout/index.wxss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.row-class{
background: #fff;
}
.col-class{
height: 32px;
line-height: 32px;
color: #fff;
text-align: center;
background: #2d8cf0;
font-size: 12px;
}
.col-class.light{
background: #5cadff;
}
3 changes: 0 additions & 3 deletions examples/pages/list/index.js

This file was deleted.

6 changes: 0 additions & 6 deletions examples/pages/list/index.json

This file was deleted.

Empty file removed examples/pages/list/index.wxml
Empty file.
Empty file removed examples/pages/list/index.wxss
Empty file.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"example": "example"
},
"scripts": {
"build": "gulp --gulpfile build/build.js"
"dev": "gulp --gulpfile build/build-dev.js",
"build": "gulp --gulpfile build/build-prod.js"
},
"repository": {
"type": "git",
Expand Down
21 changes: 19 additions & 2 deletions src/col/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
Page({
Component({
externalClasses: ['i-class'],

});
relations: {
'../row/index': {
type: 'parent'
}
},

properties: {
span: {
value: 0,
type: Number
},
offset: {
value: 0,
type: Number
}
}
});
7 changes: 2 additions & 5 deletions src/col/index.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
{
"navigationBarTitleText": "List 列表",
"usingComponents": {

}
}
"component": true
}
24 changes: 21 additions & 3 deletions src/col/index.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
.i-col{
color: red;
}
@grid-columns: 24;

.i-col {
float: left;
box-sizing: border-box;
width: 0;
}

.generate-columns(@grid-columns, @index: 1) when (@index =< @grid-columns) {
.i-col-span-@{index} {
display: block;
width: percentage((@index / @grid-columns));
}
.i-col-offset-@{index} {
margin-left: percentage((@index / @grid-columns));;
}

.generate-columns(@grid-columns, (@index + 1));
}

.generate-columns(@grid-columns);
1 change: 1 addition & 0 deletions src/col/index.wxml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<view class="i-class i-col {{ span ? 'i-col-span-' + span : '' }} {{ offset ? 'i-col-offset-' + offset : '' }}"><slot></slot></view>
2 changes: 1 addition & 1 deletion src/row/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Component({
externalClasses: ['row-class'],
externalClasses: ['i-class'],

relations: {
'../col/index': {
Expand Down
2 changes: 1 addition & 1 deletion src/row/index.wxml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<view class="row-class i-row"><slot></slot></view>
<view class="i-class i-row"><slot></slot></view>

0 comments on commit 97cd37b

Please sign in to comment.