-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b2b35ba
commit 72cd96b
Showing
14 changed files
with
188 additions
and
5 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,3 @@ | ||
# `Confirm` | ||
|
||
TBD |
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,63 @@ | ||
// @ts-nocheck (for now) | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
// eslint-disable-next-line no-restricted-imports | ||
import type { Ref } from 'react'; | ||
import { confirmable } from 'react-confirm'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Button from '../button'; | ||
import type { OwnProps } from './types'; | ||
import { Card, CardHeader, CardFooter } from '../card'; | ||
import { Heading } from '../heading'; | ||
import { contextConnect, PolymorphicComponentProps } from '../ui/context'; | ||
import { useConfirm } from './hook'; | ||
|
||
// @todo deal with overlay click event, close dialog | ||
// @todo add type declarations for the react-confirm functions | ||
function Confirm( | ||
props: PolymorphicComponentProps< OwnProps, 'div', false >, | ||
forwardedRef: Ref< any > | ||
) { | ||
const { | ||
role, | ||
wrapperClassName, | ||
show, | ||
proceed, | ||
confirmation, | ||
...otherProps | ||
} = useConfirm( props ); | ||
|
||
return ( | ||
<div | ||
{ ...otherProps } | ||
role={ role } | ||
className={ wrapperClassName } | ||
ref={ forwardedRef } | ||
style={ { visibility: show ? 'visible' : 'hidden' } } | ||
> | ||
<Card> | ||
<CardHeader> | ||
<Heading level="4">{ confirmation }</Heading> | ||
</CardHeader> | ||
<CardFooter justify="center"> | ||
<Button | ||
variant="secondary" | ||
onClick={ () => proceed( false ) } | ||
> | ||
Cancel | ||
</Button> | ||
<Button variant="primary" onClick={ () => proceed( true ) }> | ||
OK | ||
</Button> | ||
</CardFooter> | ||
</Card> | ||
</div> | ||
); | ||
} | ||
|
||
export default confirmable( contextConnect( Confirm, 'Confirm' ) ); |
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,32 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useContextSystem, PolymorphicComponentProps } from '../ui/context'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import * as styles from './styles'; | ||
import { useCx } from '../utils/hooks/use-cx'; | ||
import type { OwnProps } from './types'; | ||
|
||
export function useConfirm( | ||
props: PolymorphicComponentProps< OwnProps, 'div' > | ||
) { | ||
const { className, ...otherProps } = useContextSystem( props, 'Confirm' ); | ||
|
||
const cx = useCx(); | ||
|
||
const classes = cx( className ); | ||
const wrapperClassName = cx( styles.overlayWrapper ); | ||
const dialogWrapperClassName = cx( styles.dialogWrapper ); | ||
|
||
console.log( otherProps ); | ||
|
||
return { | ||
className: classes, | ||
wrapperClassName, | ||
dialogWrapperClassName, | ||
...otherProps, | ||
}; | ||
} |
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,15 @@ | ||
//@ts-nocheck | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { createConfirmation } from 'react-confirm'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Confirm from './component'; | ||
|
||
const confirm = createConfirmation( Confirm ); | ||
|
||
export { Confirm, confirm }; |
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,18 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { Confirm } from '..'; | ||
|
||
export default { | ||
component: Confirm, | ||
title: 'Components (Experimental)/Confirm', | ||
}; | ||
|
||
export const _default = () => { | ||
return <Confirm />; | ||
}; |
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,24 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { css } from '@emotion/react'; | ||
|
||
export const overlayWrapper = css` | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
z-index: 99; | ||
background: rgba( 0, 0, 0, 0.5 ); | ||
display: -webkit-flex; | ||
display: -moz-flex; | ||
display: -ms-flex; | ||
display: -o-flex; | ||
display: flex; | ||
justify-content: center; | ||
-ms-align-items: center; | ||
align-items: center; | ||
`; | ||
|
||
export const dialogWrapper = css``; |
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 @@ | ||
// TBD |
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,10 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
|
||
// TBD | ||
export interface OwnProps { | ||
show: boolean; | ||
proceed: Function; | ||
confirmation: string; | ||
} |
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