Skip to content

Commit

Permalink
feat(Calendar): 编译组件库到 dist 目录下,并上传 dist 到 repo 内
Browse files Browse the repository at this point in the history
  • Loading branch information
zhgqthomas committed Apr 14, 2019
1 parent da46998 commit 71b77b9
Show file tree
Hide file tree
Showing 206 changed files with 31,395 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
dist/
node_modules/

yarn.lock
Expand Down
35 changes: 35 additions & 0 deletions dist/h5/common/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Taro from '@tarojs/taro-h5';
import { Component } from "@tarojs/taro-h5";
import Nerv from "nervjs";

const objectToString = style => {
if (style && typeof style === 'object') {
let styleStr = '';
Object.keys(style).forEach(key => {
const lowerCaseKey = key.replace(/([A-Z])/g, '-$1').toLowerCase();
styleStr += `${lowerCaseKey}:${style[key]};`;
});
return styleStr;
} else if (style && typeof style === 'string') {
return style;
}
return '';
};

export default class AtComponent extends Component {
static options = {
addGlobalClass: true

/**
* 合并 style
* @param {Object|String} style1
* @param {Object|String} style2
* @returns {String}
*/
};mergeStyle(style1, style2) {
if (style1 && typeof style1 === 'object' && style2 && typeof style2 === 'object') {
return Object.assign({}, style1, style2);
}
return objectToString(style1) + objectToString(style2);
}
}
168 changes: 168 additions & 0 deletions dist/h5/common/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import Taro from '@tarojs/taro-h5';
import Nerv from "nervjs";
const ENV = Taro.getEnv();
function delay(delayTime = 500) {
return new Promise(resolve => {
if ([Taro.ENV_TYPE.WEB, Taro.ENV_TYPE.SWAN].includes(ENV)) {
setTimeout(() => {
resolve();
}, delayTime);
return;
}
resolve();
});
}
function delayQuerySelector(self, selectorStr, delayTime = 500) {
const $scope = ENV === Taro.ENV_TYPE.WEB ? self : self.$scope;
const selector = Taro.createSelectorQuery().in($scope);
return new Promise(resolve => {
delay(delayTime).then(() => {
selector.select(selectorStr).boundingClientRect().exec(res => {
resolve(res);
});
});
});
}
function delayGetScrollOffset({ delayTime = 500 }) {
return new Promise(resolve => {
delay(delayTime).then(() => {
Taro.createSelectorQuery().selectViewport().scrollOffset().exec(res => {
resolve(res);
});
});
});
}
function delayGetClientRect({ self, selectorStr, delayTime = 500 }) {
const $scope = ENV === Taro.ENV_TYPE.WEB || ENV === Taro.ENV_TYPE.SWAN ? self : self.$scope;
const selector = Taro.createSelectorQuery().in($scope);
return new Promise(resolve => {
delay(delayTime).then(() => {
selector.select(selectorStr).boundingClientRect().exec(res => {
resolve(res);
});
});
});
}
function uuid(len = 8, radix = 16) {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
const value = [];
let i = 0;
radix = radix || chars.length;
if (len) {
// Compact form
for (i = 0; i < len; i++) value[i] = chars[0 | Math.random() * radix];
} else {
// rfc4122, version 4 form
let r;
// rfc4122 requires these characters
/* eslint-disable-next-line */
value[8] = value[13] = value[18] = value[23] = '-';
value[14] = '4';
// Fill in random data. At i==19 set the high bits of clock sequence as
// per rfc4122, sec. 4.1.5
for (i = 0; i < 36; i++) {
if (!value[i]) {
r = 0 | Math.random() * 16;
value[i] = chars[i === 19 ? r & 0x3 | 0x8 : r];
}
}
}
return value.join('');
}
function getEventDetail(event) {
let detail;
switch (ENV) {
case Taro.ENV_TYPE.WEB:
detail = {
pageX: event.pageX,
pageY: event.pageY,
clientX: event.clientX,
clientY: event.clientY,
offsetX: event.offsetX,
offsetY: event.offsetY,
x: event.x,
y: event.y
};
break;
case Taro.ENV_TYPE.WEAPP:
detail = {
pageX: event.target.pageX,
pageY: event.target.pageY,
clientX: event.touches[0].clientX,
clientY: event.touches[0].clientY,
offsetX: event.target.offsetLeft,
offsetY: event.target.offsetTop,
x: event.target.x,
y: event.target.y
};
break;
case Taro.ENV_TYPE.ALIPAY:
detail = {
pageX: event.target.pageX,
pageY: event.target.pageY,
clientX: event.target.clientX,
clientY: event.target.clientY,
offsetX: event.target.offsetLeft,
offsetY: event.target.offsetTop,
x: event.target.x,
y: event.target.y
};
break;
case Taro.ENV_TYPE.SWAN:
detail = {
pageX: event.changedTouches[0].pageX,
pageY: event.changedTouches[0].pageY,
clientX: event.target.clientX,
clientY: event.target.clientY,
offsetX: event.target.offsetLeft,
offsetY: event.target.offsetTop,
x: event.detail.x,
y: event.detail.y
};
break;
default:
detail = {
pageX: 0,
pageY: 0,
clientX: 0,
clientY: 0,
offsetX: 0,
offsetY: 0,
x: 0,
y: 0
};
console.warn('getEventDetail暂未支持该环境');
break;
}
return detail;
}
function initTestEnv() {
if (process.env.NODE_ENV === 'test') {
Taro.initPxTransform({ designWidth: 750 });
}
}
function isTest() {
return process.env.NODE_ENV === 'test';
}
let scrollTop = 0;
function handleTouchScroll(flag) {
if (ENV !== Taro.ENV_TYPE.WEB) {
return;
}
if (flag) {
scrollTop = document.documentElement.scrollTop;
// 使body脱离文档流
document.body.classList.add('at-frozen');
// 把脱离文档流的body拉上去!否则页面会回到顶部!
document.body.style.top = `${-scrollTop}px`;
} else {
document.body.style.top = null;
document.body.classList.remove('at-frozen');
document.documentElement.scrollTop = scrollTop;
}
}
function pxTransform(size) {
if (!size) return '';
return Taro.pxTransform(size);
}
export { delay, delayQuerySelector, uuid, getEventDetail, initTestEnv, isTest, pxTransform, handleTouchScroll, delayGetClientRect, delayGetScrollOffset };
137 changes: 137 additions & 0 deletions dist/h5/components/accordion/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import Taro from '@tarojs/taro-h5';
import Nerv from "nervjs";
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { View, Text } from '@tarojs/components';
import AtComponent from "../../common/component";
import { delayQuerySelector, initTestEnv } from "../../common/utils";

initTestEnv();

// 文档
export default class AtAccordion extends AtComponent {
constructor() {
super(...arguments);
this.isCompleted = true;
this.startOpen = false;
this.state = {
wrapperHeight: ''
};
}

handleClick = event => {
const { open } = this.props;
if (!this.isCompleted) return;

this.props.onClick(!open, event);
};

toggleWithAnimation() {
const { open, isAnimation } = this.props;
if (!this.isCompleted || !isAnimation) return;

this.isCompleted = false;
delayQuerySelector(this, '.at-accordion__body', 0).then(rect => {
const height = parseInt(rect[0].height);
const startHeight = open ? height : 0;
const endHeight = open ? 0 : height;
this.startOpen = false;
this.setState({
wrapperHeight: startHeight
}, () => {
setTimeout(() => {
this.setState({
wrapperHeight: endHeight
}, () => {
setTimeout(() => {
this.isCompleted = true;
this.setState({});
}, 700);
});
}, 100);
});
});
}

componentWillReceiveProps(nextProps) {
if (nextProps.open !== this.props.open) {
this.startOpen = nextProps.open && nextProps.isAnimation;
this.toggleWithAnimation();
}
}

render() {
const {
customStyle,
className,
title,
icon,
hasBorder,
open
} = this.props;
const { wrapperHeight } = this.state;

const rootCls = classNames('at-accordion', className);
const iconCls = classNames({
'at-icon': true,
[`at-icon-${icon && icon.value}`]: icon && icon.value,
'at-accordion__icon': true
});
const headerCls = classNames('at-accordion__header', {
'at-accordion__header--noborder': !hasBorder
});
const arrowCls = classNames('at-accordion__arrow', {
'at-accordion__arrow--folded': !!open
});
const contentCls = classNames('at-accordion__content', {
'at-accordion__content--inactive': !open && this.isCompleted || this.startOpen
});
const iconStyle = {
color: icon && icon.color || '',
fontSize: icon && `${icon.size}px` || ''
};
const contentStyle = { height: `${wrapperHeight}px` };

if (this.isCompleted) {
contentStyle.height = '';
}

return <View className={rootCls} style={customStyle}>
<View className={headerCls} onClick={this.handleClick}>
{icon && icon.value && <Text className={iconCls} style={iconStyle}></Text>}
<View className="at-accordion__title">{title}</View>
<View className={arrowCls}>
<Text className="at-icon at-icon-chevron-down"></Text>
</View>
</View>
<View style={contentStyle} className={contentCls}>
<View className="at-accordion__body">
{this.props.children}
</View>

</View>
</View>;
}
}

AtAccordion.defaultProps = {
open: false,
customStyle: '',
className: '',
title: '',
icon: {},
hasBorder: true,
isAnimation: true,
onClick: () => {}
};

AtAccordion.propTypes = {
customStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
className: PropTypes.oneOfType([PropTypes.array, PropTypes.string]),
open: PropTypes.bool,
isAnimation: PropTypes.bool,
title: PropTypes.string,
icon: PropTypes.object,
hasBorder: PropTypes.bool,
onClick: PropTypes.func
};
13 changes: 13 additions & 0 deletions dist/h5/components/action-sheet/body/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Taro from '@tarojs/taro-h5';
import Nerv from "nervjs";
import classNames from 'classnames';
import { View } from '@tarojs/components';

import AtComponent from "../../../common/component";

export default class AtActionSheetBody extends AtComponent {
render() {
const rootClass = classNames('at-action-sheet__body', this.props.className);
return <View className={rootClass}>{this.props.children}</View>;
}
}
27 changes: 27 additions & 0 deletions dist/h5/components/action-sheet/body/item/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import Taro from '@tarojs/taro-h5';
import Nerv from "nervjs";
import classNames from 'classnames';
import { View } from '@tarojs/components';
import PropTypes from 'prop-types';
import _isFunction from 'lodash/isFunction';
import AtComponent from "../../../../common/component";

export default class AtActionSheetItem extends AtComponent {
handleClick = (...args) => {
if (_isFunction(this.props.onClick)) {
this.props.onClick(...args);
}
};

render() {
const rootClass = classNames('at-action-sheet__item', this.props.className);

return <View className={rootClass} onClick={this.handleClick}>
{this.props.children}
</View>;
}
}

AtActionSheetItem.propTypes = {
onClick: PropTypes.func
};

0 comments on commit 71b77b9

Please sign in to comment.