-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
881 additions
and
664 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.