Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(example app): add modals page example 204 #250

Merged
merged 11 commits into from
Jun 15, 2020
44 changes: 13 additions & 31 deletions example/src/pages/Modals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import { AppState, ModalState } from './../redux/types'

/** Example of Modal Component Using Redux */
eamahanna marked this conversation as resolved.
Show resolved Hide resolved
interface TestModalProps extends ConnectedModalProps {
modalKey: string
modalKey?: string
children: React.ReactNode
}

const TestModal = ({ onClose }: TestModalProps): React.ReactElement => (
const TestModal = ({ onClose, children }: TestModalProps): React.ReactElement => (
<Modal
title={<h2>Test Modal</h2>}
actions={
Expand All @@ -29,7 +30,7 @@ const TestModal = ({ onClose }: TestModalProps): React.ReactElement => (
</Button>
</>
}>
<p>This is a test modal that uses redux!</p>
{ children }
</Modal>
)

Expand All @@ -54,29 +55,8 @@ const ExamplePage = ({
closeModalAction,
}: ConnectedProps<typeof connector>): React.ReactElement => {

/** Example of Modal Component Using Hooks */
const { isOpen, openModal, closeModal } = useModal()

const HookTestModal = (): React.ReactElement => (
<Modal
title={<h2>Test Modal</h2>}
actions={
<>
<Button type="button" outline onClick={closeModal}>
Cancel
</Button>
<Button type="button" onClick={closeModal}>
Close
</Button>
</>
}>
<p>This is a test modal that uses hooks!</p>
</Modal>
)

const ConnectedHookTestModal = connectModal(HookTestModal)
/** End of Example of Modal Component Using Hooks */

return (
<section>
<h1>Modals</h1>
Expand All @@ -90,25 +70,27 @@ const ExamplePage = ({
<Button type="button" onClick={() => openModalAction('testModal')}>
Click me!
</Button>
{/* Example of modal using redux for state management */}
<ConnectedTestModal
eamahanna marked this conversation as resolved.
Show resolved Hide resolved
modalKey="testModal"
isOpen={'testModal' === openModalKey}
onClose={() => closeModalAction('testModal')}
/>
onClose={() => closeModalAction('testModal')}>
<p>This is a modal that uses redux!</p>
</ConnectedTestModal>
</div>
<div style={{ margin: '8px'}}>
<Button type="button" onClick={openModal}>
Click me!
</Button>
<ConnectedHookTestModal isOpen={isOpen} onClose={closeModal} />
{/* Example of modal using hooks for state management */}
<ConnectedTestModal isOpen={isOpen} onClose={closeModal} >
<p>This is a modal that uses hooks!</p>
</ConnectedTestModal>
</div>
</section>
)
}

const ConnectedExamplePage = connect(
mapStateToProps,
mapDispatchToProps
)(ExamplePage)
const ConnectedExamplePage = connector(ExamplePage)

export default ConnectedExamplePage
2 changes: 1 addition & 1 deletion example/src/redux/reducer.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { initialState, rootReducer } from './reducers'
import { OpenModalAction, CloseModalAction, AppState } from './types'

describe('flashReducer', () => {
describe('rootReducer', () => {
it('should set the openModalKey state', () => {
const openModalAction: OpenModalAction = {
type: 'OPEN_MODAL',
Expand Down
2 changes: 0 additions & 2 deletions example/src/redux/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ export interface CloseModalAction {

export type ModalActionTypes = OpenModalAction | CloseModalAction;

/** this represents what the state object will look like */
/** Assume each modal has a unique key, open modals is an array of keys for modals, or have a single one open at a time */
export interface AppState {
modalState: ModalState
}