2
私は確認ダイアログを表示し、ユーザーの操作(確認/キャンセル)を表示し、より少ない試行でどのコンポーネントでも再利用できるサービスを作成しようとしています。ReactJsの再利用可能なモード
私は(私のダイアログを注入するReact gateway
を使用して)これまでに試した何
私のようなサービスを作成します。私のコンポーネントに続いて
var createConfirm = function(options, onConfirm, onCancel) {
options = options || {};
var actions = [
<FlatButton
label="Cancel"
primary={true}
onClick={onCancel}
/>,
<RaisedButton
label="OK"
primary={true}
onClick={onConfirm}
/>,
];
return (
<Gateway into="confirm-modal">
<Dialog
title={options.title || 'Confirmation'}
actions={actions}
modal={true}
open={true}
>
{options.content || 'Are you sure?'}
</Dialog>
</Gateway>
)
}
export default createConfirm;
を、私はrender()
機能にこれを注入:
...
{
_this.state.isOpen && _this.confirmable
}
モーダル確認を表示する必要がある場合は、
this.confirmable = createConfirm({
title: 'CONFIRM',
content: 'Are you sure to do that'
}, function() {
console.log('user confirm')
_this.setState({
isOpen: false
});
}, function() {
console.log('user cancel')
_this.setState({
isOpen: false
})
});
this.setState({isOpen: true});
それはレンダリングされませんので、私の問題
は、私はあなたが見ることができるよう、その確認ダイアログを閉じるには、何、false
へisOpen
状態に設定されています。これはちょっとチートで、Dialogを閉じるためのネイティブな方法ではないようです(アニメーションを残して失われて、変わって見える...)。
私はダイアログを完全に制御できるサービスをどのように実装できますか?
ありがとうございました!
ダイアログ/モーダルに閉鎖する方法:
wrapper.remove();
でもある私のアプローチが好き、それは実際にそれを閉じないで、DOMノードからのモーダルを削除しています。私が尋ねたいのは、モーダルを完全にコントロールするアプローチです。 – dzuncoi