1.0.0 • Published 6 years ago

@home-app/redux-modal.module v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

Homeless Modal

Universal Modal that uses redux state

How to use

  1. Install module:
yarn add @home-app/redux-modal.module
  1. Add redux state:
import { reducer as modalReducer } from '@home-app/redux-modal.module';

rootReducer = combineReducers({
  potato: potatoReducer,
  tomato: tomatoReducer,
  ...
  modal: modalReducer,
})
  1. Create modal config
export const modalIds = {
  EXAMPLE_MODAL: 'EXAMPLE_MODAL',
};

const modalConfig = {
  [modalIds.EXAMPLE_MODAL]: props => <ExampleModal {...props} />,
};
  1. Create ModalComponent and put it somewhere inside react root element
import { modalFactory } from '@home-app/redux-modal.module';

const Modal = modalFactory({
  reduxName: 'modal', // name of reducer from step 1 (default modal)
  config: modalConfig, // modal config from step 2
  appElement: '#root', // selector of react root element 
  classNamePrefix: 'redux-modal', // css classNames prefix (default redux-modal)
});


export default RootComponent = props => <div>
  <OtherStuff />
  <Modal />
</div>
  1. Connect action creators to component from step 3
import { actions } from '@home-app/redux-modal.module';

...

const mapDispatchToProps = dispatch => ({
  openModal: (id, params) => dispatch(actions.modalOpen(id, params),
});

export default connect(null, mapDispatchToProps)(RootComponent));
  1. Add openHandlers wherever you want
...
<input
  type="button"
  onClick={() => this.props.openModal(modalIds.EXAMPLE_MODAL)}
  value="PUSH ME"
/>

second argument for openModal() will be passed to modal component as props

1.0.0

6 years ago

0.1.9

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago