Skip to content

Commit

Permalink
update eslint-ts
Browse files Browse the repository at this point in the history
  • Loading branch information
z2014 committed Aug 3, 2020
1 parent 883515b commit cc9357a
Show file tree
Hide file tree
Showing 10 changed files with 881 additions and 664 deletions.
86 changes: 16 additions & 70 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,71 +1,17 @@
{
"ecmaFeatures": {
"jsx": true,
"modules": true
},
"env": {
"browser": true,
"node": true
},
"parser": "babel-eslint",
"rules": {
"quotes": [2, "single"],
"strict": [2, "never"],
"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2,
"react/react-in-jsx-scope": 2,
"no-alert": 2,
"no-array-constructor": 2,
"no-caller": 2,
"no-catch-shadow": 2,
"no-labels": 2,
"no-eval": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-implied-eval": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-lone-blocks": 2,
"no-loop-func": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-native-reassign": 2,
"no-new": 2,
"no-new-func": 2,
"no-new-object": 2,
"no-new-wrappers": 2,
"no-octal-escape": 2,
"no-process-exit": 2,
"no-proto": 2,
"no-return-assign": 2,
"no-sequences": 2,
"no-shadow": 2,
"no-shadow-restricted-names": 2,
"no-spaced-func": 2,
"no-trailing-spaces": 2,
"no-undef-init": 2,
"no-unused-expressions": 2,
"no-use-before-define": 2,
"no-with": 2,
"comma-spacing": 2,
"consistent-return": 2,
"no-extra-parens": [2, "functions"],
"eqeqeq": 2,
"key-spacing": [2, { "beforeColon": false, "afterColon": true }],
"new-cap": 2,
"new-parens": 2,
"semi": 2,
"semi-spacing": [2, {"before": false, "after": true}],
"space-infix-ops": 1,
"keyword-spacing": 2,
"space-unary-ops": [2, { "words": true, "nonwords": false }],
"yoda": [2, "never"]
},
"plugins": [
"react"
],
"globals": {
"it": true,
"describe": true
}
}
"extends": [
"alloy",
"alloy/react",
"alloy/typescript"
],
"env": {
"browser": true,
"node": true
},
"rules": {
},
"globals": {
"it": true,
"describe": true
}
}
93 changes: 46 additions & 47 deletions components/button/src/button.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,52 @@
import * as React from "react";
import * as React from 'react';
import {
ButtonProps
} from './interface'
import classNames from "../../utils/classnames";
ButtonProps,
buttonTypes,
buttonSize
} from './interface';
import classNames from '../../utils/classnames';

class Button extends React.Component<ButtonProps> {
static defaultProps = {
disabled: false,
type: 'primary',
size: 'normal',
loading: false
};

click = (e) => {
const { onClick } = this.props;
if (e) {
e.preventDefault();
}
const InternalButton = (props: ButtonProps) => {
const {
size,
type,
children,
className,
loading,
disabled
} = props;
const handleClick = (e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement, MouseEvent>) => {
const { onClick } = props;
if (onClick && typeof onClick === 'function') {
onClick(e);
onClick(e)
}
return false;
}

render() {
const {
size,
type,
children,
className,
loading
} = this.props
const cls = classNames(className, {
'weui-btn': true,
'weui-btn_mini': size === 'small',
'weui-btn_primary': type === 'primary',
'weui-btn_default': type === 'default',
'weui-btn_warn': type === 'warn',
'weui-btn_disabled': this.props.disabled,
'weui-btn_loading': loading
})
return <a
href="#"
onClick={this.click}
className={cls}
>
{ loading ? <i className="weui-loading"></i> : null }
{ children }</a>
}
};
const cls = classNames(className, {
'weui-btn': true,
'weui-btn_mini': size === 'small',
'weui-btn_primary': type === 'primary',
'weui-btn_default': type === 'default',
'weui-btn_warn': type === 'warn',
'weui-btn_disabled': disabled,
'weui-btn_loading': loading
});
return (<a
href='#'
onClick={handleClick}
className={cls}
>
{ loading ? <i className='weui-loading'/> : null }
{ children }
</a>)
}

export default Button
const Button = React.forwardRef(InternalButton);
Button.displayName = 'Button';
Button.defaultProps = {
disabled: false,
type: buttonTypes.primary,
size: buttonSize.normal,
loading: false
};

export default Button;
37 changes: 17 additions & 20 deletions components/button/src/buttonArea.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import * as React from "react";
import classNames from "../../utils/classnames";
import { ButtonAreaProps } from './interface';
import * as React from 'react';
import classNames from '../../utils/classnames';
import { ButtonAreaProps, buttonAreaDirection } from './interface';

class ButtonArea extends React.Component<ButtonAreaProps> {

static defaultProps = {
direction: 'vertical'
};
const InternalButtonArea = (props: ButtonAreaProps) => {
const {direction, children, className} = props;
const cls = classNames(className, {
'weui-btn-area': true,
'weui-btn-area_inline': direction === buttonAreaDirection.horizontal
});
return (<div className={cls}>
{children}
</div>)
}

render() {
const {direction, children, className} = this.props;
const cls = classNames(className, {
'weui-btn-area': true,
'weui-btn-area_inline': direction === 'horizontal'
});

return (
<div className={cls}>
{children}
</div>
);
}
const ButtonArea = React.forwardRef(InternalButtonArea);
ButtonArea.displayName = 'ButtonArea';
ButtonArea.defaultProps = {
direction: buttonAreaDirection.vertical
};

export default ButtonArea;
18 changes: 10 additions & 8 deletions components/button/src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
interface ButtonProps {
export interface ButtonProps {
disabled?: boolean;
type?: buttonTypes;
size?: buttonSize;
className?: String;
loading?: boolean;
children?: React.ReactNode;
onClick?: (e) => void;
}

interface ButtonAreaProps {
export interface ButtonAreaProps {
direction?: String;
className?: String;
children?: React.ReactNode;
}

enum buttonTypes {
export enum buttonTypes {
primary = 'primary',
default = 'default',
warn = 'warn'
}

enum buttonSize {
export enum buttonSize {
small = 'small',
normal = 'normal'
}

export {
ButtonProps,
ButtonAreaProps
}
export enum buttonAreaDirection {
horizontal = 'horizontal',
vertical = 'vertical'
}
22 changes: 10 additions & 12 deletions components/utils/classnames.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
/*!
/*
Copyright (c) 2017 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
with fix with es6 export default
*/

var hasOwn = {}.hasOwnProperty;
const hasOwn = {}.hasOwnProperty;

function classNames(param: any, ...params: any[]): string {
var classes = [];
function classNames(...args: any[]): string {
const classes = [];
for (let arg of args) {
if (!arg) continue;

for (var i = 0; i < arguments.length; i++) {
var arg = arguments[i];
if (!arg) continue;

var argType = typeof arg;
let argType = typeof arg;

if (argType === 'string' || argType === 'number') {
classes.push(arg);
} else if (Array.isArray(arg)) {
classes.push(classNames.apply(null, arg));
} else if (argType === 'object') {
for (var key in arg) {
for (let key in arg) {
if (hasOwn.call(arg, key) && arg[key]) {
classes.push(key);
}
}
}
}
}

return classes.join(' ');
}

export default classNames;
export default classNames;
5 changes: 4 additions & 1 deletion example/pages/button/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class ButtonDemo extends React.Component {
<Button disabled>Disabled</Button>

<ButtonArea>
<Button type="default" >Secondary Normal</Button>
<Button type="default" onClick={(e) => {
console.log('button click');
e.preventDefault();
}}>click me</Button>
<Button type="default" disabled>Secondary Disabled</Button>
</ButtonArea>

Expand Down
19 changes: 12 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
"start": "webpack-dev-server",
"start:doc": "webpack-dev-server --config webpack.config.doc.js --progress --colors --port 8080",
"build": "node scripts/build.js -p",
"lint": "eslint 'src/**/*.js'",
"lint": "./node_modules/.bin/eslint components --ext .ts,.tsx",
"autofix": "./node_modules/.bin/eslint components --ext .ts,.tsx --fix",
"pretest": "npm run lint",
"test": "mocha",
"test:watch": "npm run test -- --watch",
"coverage": "npm run lint & nyc --require babel-core/register mocha && nyc report --reporter=lcov",
"coverage": "npm run lint & nyc --require @babel/register mocha && nyc report --reporter=lcov",
"postpublish": "gh-pages -d ./build/demo"
},
"repository": {
Expand Down Expand Up @@ -45,12 +46,16 @@
"@babel/polyfill": "^7.10.4",
"@babel/preset-env": "^7.10.4",
"@babel/preset-react": "^7.10.4",
"@babel/register": "^7.10.5",
"@babel/runtime": "^7.10.5",
"@rollup/plugin-babel": "^5.1.0",
"@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-node-resolve": "^8.4.0",
"@types/react": "^16.9.43",
"@typescript-eslint/eslint-plugin": "^3.7.1",
"@typescript-eslint/parser": "^3.7.1",
"autoprefixer": "^6.3.5",
"babel-eslint": "^6.0.0",
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-istanbul": "^3.0.0",
Expand All @@ -63,8 +68,9 @@
"css-loader": "^0.28.4",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"eslint": "^3.17.1",
"eslint-plugin-react": "^3.11.3",
"eslint": "^7.6.0",
"eslint-config-alloy": "^3.7.4",
"eslint-plugin-react": "^7.20.5",
"extract-text-webpack-plugin": "^3.0.0",
"fastclick": "^1.0.6",
"file-loader": "^6.0.0",
Expand Down Expand Up @@ -98,10 +104,9 @@
"rimraf": "^2.4.3",
"rollup": "^2.23.0",
"rollup-plugin-less": "0.1.3",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-plugin-progress": "^0.2.1",
"rollup-plugin-replace": "^1.1.1",
"rollup-plugin-uglify": "^1.0.1",
"rollup-plugin-terser": "^6.1.0",
"semver": "^6.3.0",
"sinon": "^1.17.2",
"style-loader": "^0.13.0",
Expand Down
Loading

0 comments on commit cc9357a

Please sign in to comment.