diff --git a/packages/checkbox/index.wxs b/packages/checkbox/index.wxs
index 927eb55d..eb9c7726 100644
--- a/packages/checkbox/index.wxs
+++ b/packages/checkbox/index.wxs
@@ -1,20 +1,20 @@
/* eslint-disable */
-var utils = require('../wxs/utils.wxs');
+var style = require('../wxs/style.wxs');
+var addUnit = require('../wxs/add-unit.wxs');
function iconStyle(checkedColor, value, disabled, parentDisabled, iconSize) {
- var styles = [['font-size', utils.addUnit(iconSize)]];
+ var styles = {
+ 'font-size': addUnit(iconSize),
+ };
+
if (checkedColor && value && !disabled && !parentDisabled) {
- styles.push(['border-color', checkedColor]);
- styles.push(['background-color', checkedColor]);
+ styles['border-color'] = checkedColor;
+ styles['background-color'] = checkedColor;
}
- return styles
- .map(function(item) {
- return item.join(':');
- })
- .join(';');
+ return style(styles);
}
module.exports = {
- iconStyle: iconStyle
+ iconStyle: iconStyle,
};
diff --git a/packages/grid-item/index.ts b/packages/grid-item/index.ts
index db112b47..4754b18b 100644
--- a/packages/grid-item/index.ts
+++ b/packages/grid-item/index.ts
@@ -1,6 +1,5 @@
import { link } from '../mixins/link';
import { VantComponent } from '../common/component';
-import { addUnit } from '../common/utils';
VantComponent({
relation: {
@@ -48,40 +47,8 @@ VantComponent({
direction,
iconSize,
} = data;
- const width = `${100 / columnNum}%`;
-
- const styleWrapper: string[] = [];
- styleWrapper.push(`width: ${width}`);
-
- if (square) {
- styleWrapper.push(`padding-top: ${width}`);
- }
-
- if (gutter) {
- const gutterValue = addUnit(gutter);
- styleWrapper.push(`padding-right: ${gutterValue}`);
-
- const index = children.indexOf(this);
- if (index >= columnNum && !square) {
- styleWrapper.push(`margin-top: ${gutterValue}`);
- }
- }
-
- let contentStyle = '';
-
- if (square && gutter) {
- const gutterValue = addUnit(gutter);
-
- contentStyle = `
- right: ${gutterValue};
- bottom: ${gutterValue};
- height: auto;
- `;
- }
this.setData({
- viewStyle: styleWrapper.join('; '),
- contentStyle,
center,
border,
square,
@@ -89,6 +56,8 @@ VantComponent({
clickable,
direction,
iconSize,
+ index: children.indexOf(this),
+ columnNum,
});
},
diff --git a/packages/grid-item/index.wxml b/packages/grid-item/index.wxml
index ede970ca..0070a2bb 100644
--- a/packages/grid-item/index.wxml
+++ b/packages/grid-item/index.wxml
@@ -1,9 +1,14 @@
+
-
+
diff --git a/packages/grid-item/index.wxs b/packages/grid-item/index.wxs
new file mode 100644
index 00000000..2cfe37d0
--- /dev/null
+++ b/packages/grid-item/index.wxs
@@ -0,0 +1,32 @@
+/* eslint-disable */
+var style = require('../wxs/style.wxs');
+var addUnit = require('../wxs/add-unit.wxs');
+
+function wrapperStyle(data) {
+ var width = 100 / data.columnNum + '%';
+
+ return style({
+ width: width,
+ 'padding-top': data.square ? width : null,
+ 'padding-right': addUnit(data.gutter),
+ 'margin-top':
+ data.index >= data.columnNum && !data.square
+ ? addUnit(data.gutter)
+ : null,
+ });
+}
+
+function contentStyle(data) {
+ return data.square
+ ? style({
+ right: addUnit(data.gutter),
+ bottom: addUnit(data.gutter),
+ height: 'auto',
+ })
+ : '';
+}
+
+module.exports = {
+ wrapperStyle: wrapperStyle,
+ contentStyle: contentStyle,
+};
diff --git a/packages/grid/index.ts b/packages/grid/index.ts
index d81436c4..4c898f02 100644
--- a/packages/grid/index.ts
+++ b/packages/grid/index.ts
@@ -1,5 +1,4 @@
import { VantComponent } from '../common/component';
-import { addUnit } from '../common/utils';
VantComponent({
relation: {
@@ -47,19 +46,6 @@ VantComponent({
},
},
- data: {
- viewStyle: '',
- },
-
- created() {
- const { gutter } = this.data;
- if (gutter) {
- this.setData({
- viewStyle: `padding-left: ${addUnit(gutter)}`,
- });
- }
- },
-
methods: {
updateChildren() {
this.children.forEach(
diff --git a/packages/grid/index.wxml b/packages/grid/index.wxml
index c5a545f5..2e4118f3 100644
--- a/packages/grid/index.wxml
+++ b/packages/grid/index.wxml
@@ -1,3 +1,8 @@
-
+
+
+
diff --git a/packages/grid/index.wxs b/packages/grid/index.wxs
new file mode 100644
index 00000000..cd3b1bd5
--- /dev/null
+++ b/packages/grid/index.wxs
@@ -0,0 +1,13 @@
+/* eslint-disable */
+var style = require('../wxs/style.wxs');
+var addUnit = require('../wxs/add-unit.wxs');
+
+function rootStyle(data) {
+ return style({
+ 'padding-left': addUnit(data.gutter),
+ });
+}
+
+module.exports = {
+ rootStyle: rootStyle,
+};
diff --git a/packages/icon/index.wxml b/packages/icon/index.wxml
index 62eff360..3c701745 100644
--- a/packages/icon/index.wxml
+++ b/packages/icon/index.wxml
@@ -1,10 +1,9 @@
-
-
+
+