0.2.3 • Published 6 years ago

modalo v0.2.3

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

Modalo

React, component for displaying modals. Uses plain React component or connected to redux store.

React Component

createModal(types, [renderer])

Returns React component, and then we select modal to render passing string id as a component prop.

argumenttypedescription
typesobjectpairs of modal id and modal React component
rendererReact componentcustom renderer

Use custom renderer when have different requirements which default one haven't meet props:

proptypedesscription
componentstringkey of the modal to render
onOverlayClickfunctionoverlay click handler
import { createModal } from 'modalo';
import { render } from 'react-dom';

const Modal = createModal({
  'modal-one': ModalOne,
  'modal-two': ModalTwo
});

render(<Modal component="modal-one" />, document.body);

Styles

Load default renderer styles:

import 'modalo/dist/Renderer/Renderer.css';

Redux connected React component

createReduxModal(types, [renderer])

Creates connected React component.

createReducer([customReducer])

'modal' state branch is only supported.

const rootReducer = combineReducers({
  modal: createReducer()
});
argumenttypedescription
customReducerfunctionlet you change state on custom actions. You are free to change state as you need, however only openModal, closeModal helper reducers are recommended to not malform state

Custom reducer

import { createReducer, openModal, closeModal } from 'modalo';
const customReducer = (state, action) => {
  switch (action.type) {
    case 'USER_NEEDS_TO_CONFIRM_ACTION': {
      return openModal(state, 'confirm-modal');
    }
    case 'USER_CONFIRMED': {
      return closeModal(state);
    }
    defautl: {
      return state;
    }
  }
};
const reducer = createReducer(customReducer);
import { combineReducers } from 'redux';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import { render } from 'react-dom';
import { createReduxModal, createReducer } from 'modalo';

const Modal = createReduxModal({
  'confirm-modal': ConfirmModal
});
const rootReducer = combineReducers({
  modal: createReducer()
});
const store = createStore(rootReducer, {});

render(
  (
    <Provider store={store}>
      <Modal />
    </Provider>
  ),
  document.body);

TODO:

  • add simple renderer (without animations)
0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.8

6 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago