Initial commit: WordPress wp-content (themes, plugins, languages)
- Theme: momentry (custom theme with REST API routes) - Plugins: code-snippets (contains all API proxies) - Languages: zh_TW translations - Excludes: cache, backups, uploads, logs
This commit is contained in:
49
plugins/code-snippets/js/components/common/ConfirmDialog.tsx
Normal file
49
plugins/code-snippets/js/components/common/ConfirmDialog.tsx
Normal file
@@ -0,0 +1,49 @@
|
||||
import React from 'react'
|
||||
import { __ } from '@wordpress/i18n'
|
||||
import { Button, Flex, Modal } from '@wordpress/components'
|
||||
import type { ReactNode } from 'react'
|
||||
|
||||
export interface ConfirmDialogProps {
|
||||
open?: boolean
|
||||
title: string
|
||||
onConfirm?: VoidFunction
|
||||
onCancel: VoidFunction
|
||||
confirmLabel?: string
|
||||
cancelLabel?: string
|
||||
children?: ReactNode,
|
||||
confirmButtonClassName?: string
|
||||
}
|
||||
|
||||
export const ConfirmDialog: React.FC<ConfirmDialogProps> = ({
|
||||
open,
|
||||
title,
|
||||
onConfirm,
|
||||
onCancel,
|
||||
children,
|
||||
confirmLabel = __('OK', 'code-snippets'),
|
||||
cancelLabel = __('Cancel', 'code-snippets'),
|
||||
confirmButtonClassName
|
||||
}) =>
|
||||
open
|
||||
? <Modal
|
||||
title={title}
|
||||
onRequestClose={onCancel}
|
||||
closeButtonLabel={cancelLabel}
|
||||
isDismissible={true}
|
||||
onKeyDown={event => {
|
||||
if ('Enter' === event.key) {
|
||||
onConfirm?.()
|
||||
}
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
<Flex direction="row" justify="flex-end">
|
||||
<Button variant="tertiary" onClick={onCancel}>
|
||||
{cancelLabel}
|
||||
</Button>
|
||||
<Button variant="primary" onClick={onConfirm} className={confirmButtonClassName}>
|
||||
{confirmLabel}
|
||||
</Button>
|
||||
</Flex>
|
||||
</Modal>
|
||||
: null
|
||||
Reference in New Issue
Block a user