1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | 'use strict'
|
7 |
|
8 | import React, {PropTypes as types} from 'react'
|
9 | import classnames from 'classnames'
|
10 | import {ApTouchable} from 'apeman-react-touchable'
|
11 | import ApDialog from './ap_dialog'
|
12 |
|
13 |
|
14 | let ApYesnoDialog = React.createClass({
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | propTypes: {
|
21 | present: types.bool.isRequired,
|
22 |
|
23 | onYes: types.func,
|
24 |
|
25 | onNo: types.func,
|
26 |
|
27 | title: types.string,
|
28 |
|
29 | yesText: types.string,
|
30 |
|
31 | noText: types.string
|
32 | },
|
33 |
|
34 | mixins: [],
|
35 |
|
36 | statics: {},
|
37 |
|
38 | getInitialState () {
|
39 | return {}
|
40 | },
|
41 |
|
42 | getDefaultProps () {
|
43 | return {
|
44 | present: false,
|
45 | onYes: null,
|
46 | onNo: null,
|
47 | title: null,
|
48 | yesText: 'Yes',
|
49 | noText: 'No'
|
50 | }
|
51 | },
|
52 |
|
53 | render () {
|
54 | const s = this
|
55 | let { props } = s
|
56 | if (!props.present) {
|
57 | return null;
|
58 | }
|
59 | return (
|
60 | <ApDialog className={ classnames('ap-yesno-dialog', props.className) }
|
61 | style={ Object.assign({}, props.style) }
|
62 | { ...props }
|
63 | >
|
64 | <div>{ props.children }</div>
|
65 | <div className="ap-yesno-dialog-control">
|
66 | { s._renderYesnoButton(props.noText, s.handleNo) }
|
67 | { s._renderYesnoButton(props.yesText, s.handleYes) }
|
68 | </div>
|
69 | </ApDialog>
|
70 | )
|
71 | },
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | handleYes(e) {
|
78 | const s = this,
|
79 | {props} = s
|
80 | if (props.onYes) {
|
81 | props.onYes(e)
|
82 | }
|
83 | },
|
84 |
|
85 | handleNo(e) {
|
86 | const s = this,
|
87 | {props} = s
|
88 | if (props.onNo) {
|
89 | props.onNo(e)
|
90 | }
|
91 | },
|
92 |
|
93 |
|
94 |
|
95 |
|
96 | _renderYesnoButton(text, callback) {
|
97 | const s = this
|
98 | return (
|
99 | <a className="ap-yesno-dialog-button">
|
100 | <ApTouchable onTap={ callback }>
|
101 | <span className="ap-yesno-dialog-button-text">{ text }</span>
|
102 | </ApTouchable>
|
103 | </a>
|
104 | )
|
105 | }
|
106 |
|
107 | })
|
108 |
|
109 | export default ApYesnoDialog; |
\ | No newline at end of file |