loon-bulma-react 2022.3.19 → 2022.3.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -94,6 +94,7 @@ export { FileInput } from './components/Form/File/FileInput';
94
94
  export type { FileInputProps } from './components/Form/File/FileInput';
95
95
  export { NotifierProvider, useNotifier } from './contexts/Notifier/NotifierProvider';
96
96
  export type { NotifierItemProps } from './contexts/Notifier/NotifierProps';
97
+ export { ConfirmProvider, useConfirm } from './contexts/Confirm/ConfirmContextProvider';
97
98
  export { Calendar } from './components/Calendar';
98
99
  export type { BaseEventProps, CalendarOptions } from './components/Calendar/Props';
99
100
  export type { MonthViewProps } from './components/Calendar';
package/dist/index.js CHANGED
@@ -4935,6 +4935,116 @@ function useNotifier() {
4935
4935
  return notifierHelpers;
4936
4936
  }
4937
4937
 
4938
+ var resolveCallback;
4939
+ var ConfirmContext = React__default.createContext(null);
4940
+ ConfirmContext.displayName = 'ConfirmContext';
4941
+ function ConfirmProvider(_ref) {
4942
+ var children = _ref.children;
4943
+ var _React$useReducer = React__default.useReducer(confirmReducer, initialState),
4944
+ state = _React$useReducer[0],
4945
+ setState = _React$useReducer[1];
4946
+ return React__default.createElement(ConfirmContext.Provider, {
4947
+ value: {
4948
+ state: state,
4949
+ setState: setState
4950
+ }
4951
+ }, React__default.createElement(ConfirmDialog, null), children);
4952
+ }
4953
+ var initialState = {
4954
+ show: false,
4955
+ content: '',
4956
+ ok: 'Ok',
4957
+ cancel: 'Annuleren',
4958
+ others: undefined
4959
+ };
4960
+ function confirmReducer(state, action) {
4961
+ var _action$payload, _action$ok, _action$cancel;
4962
+ if (state === void 0) {
4963
+ state = initialState;
4964
+ }
4965
+ switch (action.type) {
4966
+ case 'SHOW':
4967
+ return _extends({}, state, {
4968
+ show: true,
4969
+ content: (_action$payload = action.payload) === null || _action$payload === void 0 ? void 0 : _action$payload.content,
4970
+ ok: (_action$ok = action.ok) != null ? _action$ok : 'Ok',
4971
+ cancel: (_action$cancel = action.cancel) != null ? _action$cancel : 'Annuleren',
4972
+ others: action.others
4973
+ });
4974
+ case 'HIDE':
4975
+ return initialState;
4976
+ default:
4977
+ return initialState;
4978
+ }
4979
+ }
4980
+ function useConfirm(ok, cancel, others) {
4981
+ if (ok === void 0) {
4982
+ ok = 'OK';
4983
+ }
4984
+ if (cancel === void 0) {
4985
+ cancel = 'Annuleren';
4986
+ }
4987
+ if (others === void 0) {
4988
+ others = undefined;
4989
+ }
4990
+ var confirmContext = React__default.useContext(ConfirmContext);
4991
+ if (!confirmContext) throw new Error('useConfirm must be used inside a ConfirmProvider');
4992
+ var onConfirm = function onConfirm() {
4993
+ closeConfirm();
4994
+ resolveCallback(true);
4995
+ };
4996
+ var onCancel = function onCancel() {
4997
+ closeConfirm();
4998
+ resolveCallback(false);
4999
+ };
5000
+ var confirm = function confirm(content) {
5001
+ confirmContext.setState(_extends({}, confirmContext.state, {
5002
+ type: 'SHOW',
5003
+ payload: {
5004
+ content: content
5005
+ },
5006
+ ok: ok,
5007
+ cancel: cancel,
5008
+ others: others
5009
+ }));
5010
+ return new Promise(function (resolve) {
5011
+ resolveCallback = resolve;
5012
+ });
5013
+ };
5014
+ var closeConfirm = function closeConfirm() {
5015
+ confirmContext.setState({
5016
+ type: 'HIDE',
5017
+ payload: undefined
5018
+ });
5019
+ };
5020
+ return {
5021
+ confirm: confirm,
5022
+ onConfirm: onConfirm,
5023
+ onCancel: onCancel,
5024
+ confirmState: confirmContext.state
5025
+ };
5026
+ }
5027
+ function ConfirmDialog() {
5028
+ var _useConfirm = useConfirm(),
5029
+ onConfirm = _useConfirm.onConfirm,
5030
+ onCancel = _useConfirm.onCancel,
5031
+ confirmState = _useConfirm.confirmState;
5032
+ return confirmState.show ? React__default.createElement("div", {
5033
+ className: "modal is-active"
5034
+ }, React__default.createElement("div", {
5035
+ className: "modal-background"
5036
+ }), React__default.createElement("div", {
5037
+ className: "modal-content"
5038
+ }, React__default.createElement(Box, null, typeof confirmState.content === 'string' && React__default.createElement("p", null, confirmState === null || confirmState === void 0 ? void 0 : confirmState.content), typeof confirmState.content !== 'string' && (confirmState === null || confirmState === void 0 ? void 0 : confirmState.content), React__default.createElement(ButtonGroup, {
5039
+ alignment: "c",
5040
+ className: "mt-6"
5041
+ }, React__default.createElement(Button.Success, {
5042
+ onClick: onConfirm
5043
+ }, confirmState.ok), React__default.createElement(Button.Danger, {
5044
+ onClick: onCancel
5045
+ }, confirmState.cancel), confirmState.others)))) : null;
5046
+ }
5047
+
4938
5048
  var JSDateTime = /*#__PURE__*/function () {
4939
5049
  function JSDateTime(date, locale, formatOptions) {
4940
5050
  if (formatOptions === void 0) {
@@ -6672,6 +6782,7 @@ exports.CheckBox = CheckBox;
6672
6782
  exports.ColorInput = ColorInput;
6673
6783
  exports.Column = Column;
6674
6784
  exports.Columns = Columns;
6785
+ exports.ConfirmProvider = ConfirmProvider;
6675
6786
  exports.Container = Container;
6676
6787
  exports.Content = Content;
6677
6788
  exports.DataTable = DataTable;
@@ -6728,6 +6839,7 @@ exports.getHotkeyHandler = getHotkeyHandler;
6728
6839
  exports.serializeJSON = serializeJSON;
6729
6840
  exports.useBoolToggle = useBoolToggle;
6730
6841
  exports.useClipboard = useClipboard;
6842
+ exports.useConfirm = useConfirm;
6731
6843
  exports.useDebouncedValue = useDebouncedValue;
6732
6844
  exports.useHotkeys = useHotkeys;
6733
6845
  exports.useLocalStoredState = useLocalStoredState;