UNPKG

pzl-react-reusable-components

Version:
43 lines 1.65 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; import React, { useState } from 'react'; import { ConfirmDialog } from './ConfirmDialog'; /** * Confirm action using a `Dialog` from `@fluentui/react`. Specify `Dialog` properties like `title` and `subText` along * with a `responses` array and get back a JSX element with the dialog and a response callback function. */ export function useConfirmationDialog() { var _a = useState({}), state = _a[0], setState = _a[1]; var reset = function () { return setState({ props: null, onResponse: null }); }; var element = state.props && (React.createElement(ConfirmDialog, __assign({}, state.props, { onResponse: state.onResponse }))); /** * Get response from user in Dialog * * @param {IDialogContentProps} props Dialog content props */ function getResponse(props) { return new Promise(function (resolve) { setState({ props: props, onResponse: function (value, comment) { reset(); resolve({ response: value, comment: comment }); } }); }); } return [element, getResponse]; } //# sourceMappingURL=useConfirmationDialog.js.map