-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: adhere more closely to the react lifecycle for modals * feat: reduce boilerplate with a modal container * feat: README * chore: renames
- Loading branch information
1 parent
dc7adae
commit e3441f7
Showing
11 changed files
with
171 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
import Intercom from './Intercom' | ||
|
||
export default Intercom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { connect } from 'react-redux' | ||
import { RouterAction } from 'react-router-redux' | ||
|
||
import Modal from './Modal' | ||
import { ModalProps, MapStateProps, MapDispatchProps } from './Modal.types' | ||
import { RootDispatch } from '../../types' | ||
import { closeModal } from '../../modules/modal/actions' | ||
|
||
const mapState = (_: any): MapStateProps => ({}) | ||
|
||
const mapDispatch = ( | ||
dispatch: RootDispatch<RouterAction> | ||
): MapDispatchProps => ({ | ||
onCloseModal: (name: string) => dispatch(closeModal(name)) | ||
}) | ||
|
||
const mergeProps = ( | ||
stateProps: MapStateProps, | ||
dispatchProps: MapDispatchProps, | ||
ownProps: ModalProps | ||
): ModalProps => ({ | ||
...stateProps, | ||
...dispatchProps, | ||
...ownProps | ||
}) | ||
|
||
export default connect( | ||
mapState, | ||
mapDispatch, | ||
mergeProps | ||
)(Modal) as any |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as React from 'react' | ||
import { Modal as ModalComponent } from 'decentraland-ui' | ||
|
||
import { ModalProps } from './Modal.types' | ||
|
||
export default class Modal extends React.PureComponent<ModalProps> { | ||
handleClose = () => { | ||
const { name, onCloseModal } = this.props | ||
onCloseModal(name) | ||
} | ||
|
||
render() { | ||
const { name, ...modalProps } = this.props | ||
|
||
return ( | ||
<ModalComponent | ||
open={true} | ||
className={name} | ||
size="small" | ||
onClose={this.handleClose} | ||
{...modalProps} | ||
/> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as React from 'react' | ||
import { | ||
ModalProps as ModalComponentProps, | ||
ModalActions, | ||
ModalContent, | ||
ModalDescription, | ||
ModalHeader | ||
} from 'decentraland-ui' | ||
|
||
import { closeModal } from '../../modules/modal/actions' | ||
|
||
export type ModalProps = ModalComponentProps & { | ||
name: string | ||
onCloseModal: typeof closeModal | ||
} | ||
|
||
export interface ModalComponent extends React.PureComponent<ModalProps> { | ||
Actions: typeof ModalActions | ||
Content: typeof ModalContent | ||
Description: typeof ModalDescription | ||
Header: typeof ModalHeader | ||
} | ||
|
||
export type MapStateProps = {} | ||
export type MapDispatchProps = Pick<ModalProps, 'onCloseModal'> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Modal as ModalComponent } from 'decentraland-ui' | ||
import Modal from './Modal.container' | ||
|
||
Modal.Actions = ModalComponent.Actions | ||
Modal.Content = ModalComponent.Content | ||
Modal.Description = ModalComponent.Description | ||
Modal.Header = ModalComponent.Header | ||
|
||
export default Modal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,3 @@ export type Modal = { | |
name: string | ||
metadata: any | ||
} | ||
|
||
export type ModalProps = { | ||
modal: Modal | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
import { ModalState } from '../../modules/modal/reducer' | ||
import { ModalProps } from '../../modules/modal/types' | ||
import { closeModal } from '../../modules/modal/actions' | ||
|
||
export type ModalProps = { | ||
name: string | ||
metadata?: any | ||
onClose: () => ReturnType<typeof closeModal> | ||
} | ||
export type ModalComponent = React.ComponentType<ModalProps> | ||
|
||
export type DefaultProps = { | ||
children: React.ReactNode | null | ||
} | ||
|
||
export type Props = DefaultProps & { | ||
components: Record<string, React.ComponentType<ModalProps>> | ||
components: Record<string, ModalComponent> | ||
modals: ModalState | ||
onClose: typeof closeModal | ||
} | ||
|
||
export type MapStateProps = Pick<Props, 'modals'> | ||
export type MapDispatchProps = {} | ||
export type MapDispatchProps = Pick<Props, 'onClose'> |