Skip to content

Commit 28cdad5

Browse files
committed
feat(ui): add modal component
close #41
1 parent 962451b commit 28cdad5

22 files changed

Lines changed: 837 additions & 20 deletions

File tree

packages/site/src/app/styles/_app.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ h3 {
195195
section[id^='Button'],
196196
section[id^='Dropdown'],
197197
section[id^='Notification'],
198-
section[id^='Toast'] {
198+
section[id^='Toast'],
199+
section[id^='Modal'] {
199200
.d-button {
200201
margin-right: 8px;
201202
margin-bottom: 12px;

packages/ui/src/components/drawer/Drawer.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { usePrefixConfig, useComponentConfig, useElement, useLockScroll, useMaxI
1212
import { registerComponentMate, getClassName, toPx } from '../../utils';
1313
import { DMask } from '../_mask';
1414
import { DTransition } from '../_transition';
15+
import { DDrawerHeader } from './DrawerHeader';
1516

1617
export interface DDrawerProps extends React.HTMLAttributes<HTMLDivElement> {
1718
dVisible: [boolean, DUpdater<boolean>?];
@@ -23,7 +24,7 @@ export interface DDrawerProps extends React.HTMLAttributes<HTMLDivElement> {
2324
dMask?: boolean;
2425
dMaskClosable?: boolean;
2526
dEscClosable?: boolean;
26-
dHeader?: React.ReactElement<DDrawerHeaderProps>;
27+
dHeader?: React.ReactElement<DDrawerHeaderProps> | string;
2728
dFooter?: React.ReactElement<DDrawerFooterProps>;
2829
dChildDrawer?: React.ReactElement<DDrawerProps>;
2930
onClose?: () => void;
@@ -205,6 +206,17 @@ export function DDrawer(props: DDrawerProps): JSX.Element | null {
205206
return null;
206207
})();
207208

209+
const headerNode = (() => {
210+
if (dHeader) {
211+
const node = isString(dHeader) ? <DDrawerHeader>{dHeader}</DDrawerHeader> : dHeader;
212+
return React.cloneElement<DDrawerHeaderPropsWithPrivate>(node, {
213+
...node.props,
214+
__id: headerId,
215+
__onClose: closeDrawer,
216+
});
217+
}
218+
})();
219+
208220
const drawerNode = (
209221
<>
210222
<DTransition
@@ -231,7 +243,7 @@ export function DDrawer(props: DDrawerProps): JSX.Element | null {
231243
}}
232244
role="dialog"
233245
aria-modal="true"
234-
aria-labelledby={dHeader ? headerId : undefined}
246+
aria-labelledby={headerNode ? headerId : undefined}
235247
aria-describedby={contentId}
236248
>
237249
{dMask && (
@@ -260,12 +272,7 @@ export function DDrawer(props: DDrawerProps): JSX.Element | null {
260272
}
261273
}}
262274
>
263-
{dHeader &&
264-
React.cloneElement<DDrawerHeaderPropsWithPrivate>(dHeader, {
265-
...dHeader.props,
266-
__id: headerId,
267-
__onClose: closeDrawer,
268-
})}
275+
{headerNode}
269276
<div className={`${dPrefix}drawer__body`}>{children}</div>
270277
{dFooter &&
271278
React.cloneElement<DDrawerFooterPropsWithPrivate>(dFooter, {

packages/ui/src/components/drawer/demos/2.Placement.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Set the pop-up position through `dPlacement`.
1515
```tsx
1616
import { useState } from 'react';
1717

18-
import { DDrawer, DDrawerHeader, DButton } from '@react-devui/ui';
18+
import { DDrawer, DButton } from '@react-devui/ui';
1919

2020
export default function Demo() {
2121
const [visible, setVisible] = useState(false);
@@ -44,7 +44,7 @@ export default function Demo() {
4444
<DButton onClick={() => handleClick('bottom')}>B</DButton>
4545
</div>
4646
</div>
47-
<DDrawer dVisible={[visible, setVisible]} dPlacement={placement} dHeader={<DDrawerHeader>Placement Drawer</DDrawerHeader>}>
47+
<DDrawer dVisible={[visible, setVisible]} dPlacement={placement} dHeader="Placement Drawer">
4848
<p>Some contents...</p>
4949
<p>Some contents...</p>
5050
<p>Some contents...</p>

packages/ui/src/components/drawer/demos/4.Nested.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Nesting drawers through `dChildDrawer`.
1515
```tsx
1616
import { useState } from 'react';
1717

18-
import { DDrawer, DDrawerHeader, DButton } from '@react-devui/ui';
18+
import { DDrawer, DButton } from '@react-devui/ui';
1919

2020
export default function Demo() {
2121
const [visible1, setVisible1] = useState(false);
@@ -32,9 +32,9 @@ export default function Demo() {
3232
</DButton>
3333
<DDrawer
3434
dVisible={[visible1, setVisible1]}
35-
dHeader={<DDrawerHeader>Drawer1</DDrawerHeader>}
35+
dHeader="Drawer1"
3636
dChildDrawer={
37-
<DDrawer dVisible={[visible2, setVisible2]} dHeader={<DDrawerHeader>Drawer2</DDrawerHeader>}>
37+
<DDrawer dVisible={[visible2, setVisible2]} dHeader="Drawer2">
3838
<p>Some contents...</p>
3939
<p>Some contents...</p>
4040
<p>Some contents...</p>

packages/ui/src/components/drawer/demos/5.Footer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Realize complex footer operations through the `DDrawerFooter` component.
1515
```tsx
1616
import { useState } from 'react';
1717

18-
import { DDrawer, DDrawerHeader, DDrawerFooter, DButton } from '@react-devui/ui';
18+
import { DDrawer, DDrawerFooter, DButton } from '@react-devui/ui';
1919
import { useAsync } from '@react-devui/ui/hooks';
2020

2121
export default function Demo() {
@@ -34,7 +34,7 @@ export default function Demo() {
3434
</DButton>
3535
<DDrawer
3636
dVisible={[visible, setVisible]}
37-
dHeader={<DDrawerHeader>Custom Footer</DDrawerHeader>}
37+
dHeader="Custom Footer"
3838
dFooter={
3939
<DDrawerFooter
4040
dAlign="center"

packages/ui/src/components/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ export { DInput } from './input';
3737
export type { DMenuProps } from './menu';
3838
export { DMenu } from './menu';
3939

40+
export type { DModalProps, DModalHeaderProps, DModalFooterProps } from './modal';
41+
export { DModal, DModalHeader, DModalFooter } from './modal';
42+
4043
export type { DNotificationProps } from './notification';
4144
export { NotificationService } from './notification';
4245

0 commit comments

Comments
 (0)