Skip to content

Commit

Permalink
feat(Alert): 按钮使用 Button 组件
Browse files Browse the repository at this point in the history
  • Loading branch information
shaodahong committed Jan 16, 2019
1 parent 0d3acda commit dd3a57b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 29 deletions.
11 changes: 4 additions & 7 deletions docs/src/mobile/alert/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,17 @@ class A extends React.Component {
name: 'monkey',
onClick: () => {
Toast('monkey')
}
},
{
name: 'kitty',
onClick: () => {
Toast('kitty')
}
},
mini: true
},
{
name: 'world',
className: 'alert-world',
onClick: () => {
Toast('world')
},
mini: true,
type: 'danger',
report: {
name: 'world'
}
Expand Down
58 changes: 37 additions & 21 deletions packages/alert/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@ import { createBrowserHistory } from 'history'
import React, { MouseEventHandler } from 'react'
import { createPortal, render, unmountComponentAtNode } from 'react-dom'

import { Report } from '../utils'
import Button, { ButtonProps } from '../button'

export interface AlertProps {
title?: React.ReactNode
btns?: [
{
name: string;
className?: string;
onClick?: MouseEventHandler<Element>;
[otherProps: string]: any;
}
]
btns?: ButtonProps[]
className?: string
desc?: React.ReactNode
onClose?: MouseEventHandler<Element>
Expand All @@ -33,28 +26,51 @@ class AlertCom extends React.Component<AlertProps, any> {
<div className="x-alert__btns">
{!!btns &&
btns.map((btn, index) => {
const { name, className, onClick, ...otherProps } = btn
let composeClassName
if (index === 0) {
composeClassName = cn('x-alert__btn-y', className)
} else if (index === 1) {
composeClassName = cn('x-alert__btn-n', className)
} else {
composeClassName = cn('x-alert__btn-y', className)
}
const {
name,
onClick,
className,
type = 'primary',
...otherProps
} = btn

const composeClassName = cn('auto-ui-alert__btns-btn', className)

return (
<Report
<Button
className={composeClassName}
{...otherProps}
onClick={e => {
onClick && onClick(e)
onClose && onClose(e)
}}
key={index}
type={type}
{...otherProps}
>
{name}
</Report>
</Button>
)
// let composeClassName
// if (index === 0) {
// composeClassName = cn('x-alert__btn-y', className)
// } else if (index === 1) {
// composeClassName = cn('x-alert__btn-n', className)
// } else {
// composeClassName = cn('x-alert__btn-y', className)
// }
// return (
// <Report
// className={composeClassName}
// {...otherProps}
// onClick={e => {
// onClick && onClick(e)
// onClose && onClose(e)
// }}
// key={index}
// >
// {name}
// </Report>
// )
})}
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions packages/alert/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
&__btns {
display: flex;
padding: 40px;
.auto-ui-alert__btns-btn {
margin-right: 20px;
&:last-child {
margin-right: 0;
}
}

a {
display: block;
Expand Down
2 changes: 1 addition & 1 deletion packages/button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface ButtonProps {
[otherProps: string]: any
}

export default class Button extends Component<ButtonProps, null> {
export default class Button extends Component<ButtonProps, any> {
public render() {
const {
type = 'default',
Expand Down
1 change: 1 addition & 0 deletions packages/button/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
}
&__text {
padding: 0 10px;
white-space: nowrap;
}
&--primary {
background: #00bb55;
Expand Down

0 comments on commit dd3a57b

Please sign in to comment.