Skip to content

Commit

Permalink
fix: Fixed confirm onClose (#64)
Browse files Browse the repository at this point in the history
* feat: Add `modal` component

* feat: Update control params

* feat: Update avatar type

* feat: Update confirm

* docs: Update modal docs

* docs: Update confirm modal docs

* fix: Fixed import path

* feat: Update title and button name

* feat: Add `onClose`

* feat: Add `confirm` component

* feat: Update control params

* feat: Update avatar type

* feat: Update confirm

* docs: Update modal docs

* feat: Add `onClose`

* fix: Fixed merge an extra line
  • Loading branch information
Vibes-INS authored Oct 18, 2021
1 parent 7ec5c63 commit 6a482a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions libs/mibao-ui/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './index.scss'

export * from './lib/confirm/confirm'
export * from './lib/select/select'
export * from './lib/pagination/pagination'
export * from './lib/alert/alert'
Expand Down
13 changes: 7 additions & 6 deletions libs/mibao-ui/src/lib/confirm/confirm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import './confirm.module.scss'
import React, { ReactNode, createContext, useState, useContext } from 'react'
import React, { ReactNode, createContext, useState, useContext, useCallback } from 'react'
import {
Modal,
ModalBody,
Expand Down Expand Up @@ -37,8 +37,12 @@ const ConfirmModal: React.FC<{
onClose: () => void
}> = (props) => {
const context = useContext(ConfirmContext)
const onClose = useCallback(() => {
context.props?.onCancel?.()
props.onClose?.()
}, [context.props, props])

return <Modal isOpen={props.isOpen} onClose={props.onClose}>
return <Modal isOpen={props.isOpen} onClose={onClose}>
<ModalOverlay />
<ModalContent>
<ModalHeader>{context.props?.title}</ModalHeader>
Expand All @@ -57,10 +61,7 @@ const ConfirmModal: React.FC<{
</Button>

{
context.props?.onCancel && <Button isFullWidth onClick={() => {
context.props?.onCancel?.()
props.onClose?.()
}}>
context.props?.onCancel && <Button isFullWidth onClick={onClose}>
{ context.props?.cancelText ?? 'Cancel' }
</Button>
}
Expand Down

1 comment on commit 6a482a0

@vercel
Copy link

@vercel vercel bot commented on 6a482a0 Oct 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.