diff --git a/.dumirc.ts b/.dumirc.ts
index e3235915..66e1a5ef 100644
--- a/.dumirc.ts
+++ b/.dumirc.ts
@@ -2,7 +2,13 @@ import os from 'node:os';
import { defineConfig } from 'dumi';
import path from 'path';
+const basePath = process.env.GH_PAGES ? '/dialog/' : '/';
+const publicPath = basePath;
+
export default defineConfig({
+ outputPath: 'docs-dist',
+ base: basePath,
+ publicPath,
alias: {
'rc-dialog$': path.resolve('src'),
'rc-dialog/es': path.resolve('src'),
@@ -13,4 +19,4 @@ export default defineConfig({
logo: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4',
},
mako: ['Darwin', 'Linux'].includes(os.type()) ? {} : false,
-});;
+});
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
index 33b1999c..758659af 100644
--- a/.github/FUNDING.yml
+++ b/.github/FUNDING.yml
@@ -1,15 +1,2 @@
-# These are supported funding model platforms
-
-github: ant-design # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
-patreon: # Replace with a single Patreon username
-open_collective: ant-design # Replace with a single Open Collective username
-ko_fi: # Replace with a single Ko-fi username
-tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
-community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
-liberapay: # Replace with a single Liberapay username
-issuehunt: # Replace with a single IssueHunt username
-lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
-polar: # Replace with a single Polar username
-buy_me_a_coffee: # Replace with a single Buy Me a Coffee username
-thanks_dev: # Replace with a single thanks.dev username
-custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
+github: ant-design
+open_collective: ant-design
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 05db5d28..3b730ef9 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -1,35 +1,19 @@
version: 2
updates:
-- package-ecosystem: npm
- directory: "/"
- schedule:
- interval: daily
- time: "21:00"
- open-pull-requests-limit: 10
- ignore:
- - dependency-name: rc-select
- versions:
- - 12.1.2
- - 12.1.3
- - 12.1.5
- - 12.1.6
- - 12.1.7
- - 12.1.9
- - dependency-name: "@types/react"
- versions:
- - 17.0.0
- - 17.0.1
- - 17.0.2
- - 17.0.3
- - dependency-name: "@types/react-dom"
- versions:
- - 17.0.0
- - 17.0.1
- - 17.0.2
- - dependency-name: rc-drawer
- versions:
- - 4.2.2
- - 4.3.0
- - dependency-name: less
- versions:
- - 4.1.0
+ - package-ecosystem: npm
+ directory: '/'
+ schedule:
+ interval: weekly
+ day: monday
+ time: '21:00'
+ timezone: Asia/Shanghai
+ open-pull-requests-limit: 10
+
+ - package-ecosystem: github-actions
+ directory: '/'
+ schedule:
+ interval: weekly
+ day: monday
+ time: '21:00'
+ timezone: Asia/Shanghai
+ open-pull-requests-limit: 10
diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml
index 1682c054..f4f38ee2 100644
--- a/.github/workflows/codeql.yml
+++ b/.github/workflows/codeql.yml
@@ -1,12 +1,12 @@
-name: "CodeQL"
+name: 'CodeQL'
on:
push:
- branches: [ "master" ]
+ branches: ['master']
pull_request:
- branches: [ "master" ]
+ branches: ['master']
schedule:
- - cron: "57 7 * * 2"
+ - cron: '57 7 * * 2'
jobs:
analyze:
@@ -20,22 +20,24 @@ jobs:
strategy:
fail-fast: false
matrix:
- language: [ javascript ]
+ language: [javascript]
steps:
- name: Checkout
- uses: actions/checkout@v3
+ uses: actions/checkout@v7
+ with:
+ persist-credentials: false
- name: Initialize CodeQL
- uses: github/codeql-action/init@v2
+ uses: github/codeql-action/init@8aad20d150bbac5944a9f9d289da16a4b0d87c1e
with:
languages: ${{ matrix.language }}
queries: +security-and-quality
- name: Autobuild
- uses: github/codeql-action/autobuild@v2
+ uses: github/codeql-action/autobuild@8aad20d150bbac5944a9f9d289da16a4b0d87c1e
- name: Perform CodeQL Analysis
- uses: github/codeql-action/analyze@v2
+ uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e
with:
- category: "/language:${{ matrix.language }}"
+ category: '/language:${{ matrix.language }}'
diff --git a/.github/workflows/react-component-ci.yml b/.github/workflows/react-component-ci.yml
index 5735e2d2..36dacae4 100644
--- a/.github/workflows/react-component-ci.yml
+++ b/.github/workflows/react-component-ci.yml
@@ -1,6 +1,9 @@
name: ✅ test
on: [push, pull_request]
+permissions:
+ contents: read
jobs:
test:
- uses: react-component/rc-test/.github/workflows/test.yml@main
- secrets: inherit
\ No newline at end of file
+ uses: react-component/rc-test/.github/workflows/test-utoo.yml@main
+ secrets:
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
diff --git a/.github/workflows/react-doctor.yml b/.github/workflows/react-doctor.yml
new file mode 100644
index 00000000..097eb883
--- /dev/null
+++ b/.github/workflows/react-doctor.yml
@@ -0,0 +1,27 @@
+name: React Doctor
+
+on:
+ pull_request:
+ types: [opened, synchronize, reopened, ready_for_review]
+ push:
+ branches: [master]
+
+permissions:
+ contents: read
+ pull-requests: write
+ issues: write
+ statuses: write
+
+concurrency:
+ group: react-doctor-${{ github.event.pull_request.number || github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ react-doctor:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ fetch-depth: 0
+ persist-credentials: false
+ - uses: millionco/react-doctor@0b4f4f4bd248a154e64eb508a48347f71154b3f3
diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml
new file mode 100644
index 00000000..4c2f17ed
--- /dev/null
+++ b/.github/workflows/surge-preview.yml
@@ -0,0 +1,54 @@
+name: Surge Preview
+
+on:
+ pull_request:
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
+ cancel-in-progress: true
+
+permissions:
+ contents: read
+ pull-requests: write
+ checks: write
+
+jobs:
+ preview:
+ runs-on: ubuntu-latest
+ concurrency:
+ group: surge-preview-${{ github.event.pull_request.number }}
+ cancel-in-progress: true
+ env:
+ PREVIEW: true
+ steps:
+ - uses: actions/checkout@v7
+ with:
+ persist-credentials: false
+ - name: Check Surge token
+ id: surge-token
+ env:
+ SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
+ run: |
+ if [ -n "$SURGE_TOKEN" ]; then
+ echo "enabled=true" >> "$GITHUB_OUTPUT"
+ else
+ echo "enabled=false" >> "$GITHUB_OUTPUT"
+ fi
+ - name: Build preview
+ if: ${{ steps.surge-token.outputs.enabled == 'true' }}
+ run: |
+ npm install
+ npm run build
+ - uses: afc163/surge-preview@bf90a5a86111f6311ca42f0a5a0f80fb0fb03cec
+ if: ${{ steps.surge-token.outputs.enabled == 'true' }}
+ env:
+ SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }}
+ with:
+ surge_token: ${{ env.SURGE_TOKEN }}
+ github_token: ${{ secrets.GITHUB_TOKEN }}
+ dist: docs-dist
+ failOnError: false
+ setCommitStatus: false
+ - name: Skip Surge preview
+ if: ${{ steps.surge-token.outputs.enabled != 'true' }}
+ run: echo "SURGE_TOKEN is not configured; skip Surge preview."
diff --git a/.gitignore b/.gitignore
index a43b2cd9..82f1bc92 100644
--- a/.gitignore
+++ b/.gitignore
@@ -48,6 +48,7 @@ pnpm-lock.yaml
# dumi
.dumi/tmp
.dumi/tmp-production
+docs-dist
bun.lockb
.vscode
diff --git a/.husky/pre-commit b/.husky/pre-commit
new file mode 100755
index 00000000..2312dc58
--- /dev/null
+++ b/.husky/pre-commit
@@ -0,0 +1 @@
+npx lint-staged
diff --git a/.prettierignore b/.prettierignore
new file mode 100644
index 00000000..c466d872
--- /dev/null
+++ b/.prettierignore
@@ -0,0 +1,14 @@
+node_modules
+coverage
+docs-dist
+dist
+es
+lib
+.dumi/tmp
+.dumi/tmp-production
+.vercel
+package-lock.json
+pnpm-lock.yaml
+yarn.lock
+bun.lockb
+*.log
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 00000000..bd0a1f72
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,21 @@
+MIT License
+
+Copyright (c) 2019-present react-component
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
index 40920efb..f42a9fee 100644
--- a/README.md
+++ b/README.md
@@ -1,120 +1,116 @@
-# @rc-component/dialog
-
-react dialog component.
-
-[![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url] [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![bundle size][bundlephobia-image]][bundlephobia-url] [![dumi][dumi-image]][dumi-url]
-
-[npm-image]: https://img.shields.io/npm/v/@rc-component/dialog.svg?style=flat-square
-[npm-url]: https://npmjs.org/package/@rc-component/dialog
-[travis-image]: https://img.shields.io/travis/react-component/dialog/master?style=flat-square
-[travis-url]: https://travis-ci.com/react-component/dialog
-[github-actions-image]: https://github.com/react-component/dialog/actions/workflows/react-component-ci.yml/badge.svg
-[github-actions-url]: https://github.com/react-component/dialog/actions/workflows/react-component-ci.yml
-[codecov-image]: https://img.shields.io/codecov/c/github/react-component/dialog/master.svg?style=flat-square
-[codecov-url]: https://app.codecov.io/gh/react-component/dialog
-[david-url]: https://david-dm.org/react-component/dialog
-[david-image]: https://david-dm.org/react-component/dialog/status.svg?style=flat-square
-[david-dev-url]: https://david-dm.org/react-component/dialog?type=dev
-[david-dev-image]: https://david-dm.org/react-component/dialog/dev-status.svg?style=flat-square
-[download-image]: https://img.shields.io/npm/dm/@rc-component/dialog.svg?style=flat-square
-[download-url]: https://npmjs.org/package/@rc-component/dialog
-[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/dialog
-[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/dialog
-[dumi-url]: https://github.com/umijs/dumi
-[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square
-
-
-## Screenshot
-
-
-
-## Example
-
-http://localhost:8007/examples/
-
-online example: https://dialog.react-component.vercel.app/
+
Part of the Ant Design ecosystem.
💬 A composable dialog component for React.
+ + +English | 简体中文
+ +## Highlights + +- Supports controlled visibility, mask, keyboard close, and focus restoration. +- Allows custom title, footer, close icon, container, motion, and modal content rendering. +- Provides semantic `classNames` and `styles` hooks for the dialog structure. +- Ships compiled JavaScript, TypeScript definitions, and CSS assets. ## Install -[](https://npmjs.org/package/@rc-component/dialog) +```bash +npm install @rc-component/dialog +``` ## Usage -```js -var Dialog = require('@rc-component/dialog'); +```tsx | pure +import Dialog from '@rc-component/dialog'; +import '@rc-component/dialog/assets/index.css'; + +export default function App() { + return ( + + ); +} +``` -ReactDOM.render( - -), document.getElementById('t1')); +## Examples -// use dialog +Run the local dumi site: + +```bash +npm install +npm start ``` +Then open `http://localhost:8000`. + ## API -### @rc-component/dialog - -| Name | Type | Default | Description | Version | -| --- | --- | --- | --- | --- | -| prefixCls | String | rc-dialog | The dialog dom node's prefixCls | | -| className | String | | additional className for dialog | | -| classNames | { header?: string; body?: string; footer?: string; mask?: string; content?: string; wrapper?: string; } | | pass className to target area | | -| styles | { header?: CSSProperties; body?: CSSProperties; footer?: CSSProperties; mask?: CSSProperties; content?: CSSProperties; wrapper?: CSSProperties; } | | pass styles to target area | | -| style | Object | {} | Root style for dialog element.Such as width, height | | -| zIndex | Number | | | | -| visible | Boolean | false | current dialog's visible status | | -| animation | String | | part of dialog animation css class name | | -| maskAnimation | String | | part of dialog's mask animation css class name | | -| transitionName | String | | dialog animation css class name | | -| maskTransitionName | String | | mask animation css class name | | -| title | String\|React.Element | | Title of the dialog | | -| footer | React.Element | | footer of the dialog | | -| closable | Boolean \| ({ closeIcon?: React.ReactNode; disabled?: boolean, afterClose:function } & React.AriaAttributes) | true | whether show close button | | -| mask | Boolean | true | whether show mask | | -| maskClosable | Boolean | true | whether click mask to close | | -| keyboard | Boolean | true | whether support press esc to close | | -| mousePosition | {x:number,y:number} | | set pageX and pageY of current mouse(it will cause transform origin to be set). | | -| onClose | function() | | called when click close button or mask | | -| afterClose | function() | | called when close animation end | | -| getContainer | function(): HTMLElement | | to determine where Dialog will be mounted | | -| destroyOnHidden | Boolean | false | to unmount child compenents on onClose | | -| closeIcon | ReactNode | | specific the close icon. | | -| forceRender | Boolean | false | Create dialog dom node before dialog first show | | -| focusTriggerAfterClose | Boolean | true | focus trigger element when dialog closed | | -| scrollLock | Boolean | true | Control whether to lock body scroll when dialog opens | | -| modalRender | (node: ReactNode) => ReactNode | | Custom modal content render | 8.3.0 | +| Property | Description | Type | Default | +| --- | --- | --- | --- | +| afterClose | Callback after close animation ends | `() => void` | - | +| animation | Dialog animation name | string | - | +| className | Additional dialog class name | string | - | +| classNames | Semantic class names | `{ header?: string; body?: string; footer?: string; mask?: string; content?: string; wrapper?: string }` | - | +| closable | Whether to show close button, or close button props | boolean \| object | true | +| closeIcon | Custom close icon | `React.ReactNode` | - | +| destroyOnHidden | Unmount children after dialog closes | boolean | false | +| focusTriggerAfterClose | Focus trigger element after close | boolean | true | +| footer | Dialog footer | `React.ReactNode` | - | +| forceRender | Render dialog before it is first shown | boolean | false | +| getContainer | Container where dialog is mounted | `() => HTMLElement` | - | +| keyboard | Whether pressing Esc closes the dialog | boolean | true | +| mask | Whether to show mask | boolean | true | +| maskAnimation | Mask animation name | string | - | +| maskClosable | Whether clicking mask closes the dialog | boolean | true | +| maskTransitionName | Mask transition class name | string | - | +| modalRender | Custom modal content renderer | `(node: React.ReactNode) => React.ReactNode` | - | +| mousePosition | Mouse position used for transform origin | `{ x: number; y: number }` | - | +| prefixCls | Component class name prefix | string | `rc-dialog` | +| scrollLock | Whether to lock body scroll when open | boolean | true | +| style | Root dialog style | `React.CSSProperties` | - | +| styles | Semantic styles | `{ header?: React.CSSProperties; body?: React.CSSProperties; footer?: React.CSSProperties; mask?: React.CSSProperties; content?: React.CSSProperties; wrapper?: React.CSSProperties }` | - | +| title | Dialog title | `React.ReactNode` | - | +| transitionName | Dialog transition class name | string | - | +| visible | Whether the dialog is visible | boolean | false | +| zIndex | Dialog z-index | number | - | +| onClose | Callback when close button or mask is clicked | `(event: React.SyntheticEvent) => void` | - | ## Development -``` +```bash npm install npm start ``` -## Test Case +The dumi site runs at `http://localhost:8000` by default. -``` +```bash npm test -npm run chrome-test +npm run tsc +npm run lint +npm run compile +npm run build ``` -## Coverage +## Release -``` -npm run coverage +```bash +npm run prepublishOnly ``` -open coverage/ dir +The release flow is handled by `@rc-component/np` through the `rc-np` command after the package build. ## License -@rc-component/dialog is released under the MIT license. - - -## 🤝 Contributing - - -English | 简体中文
+ +## 特性 + +- 支持受控可见性、遮罩、键盘关闭和焦点恢复。 +- 支持自定义标题、页脚、关闭图标、容器、动画和弹窗内容渲染。 +- 为对话框结构提供语义 `classNames` 和 `styles` 挂钩。 +- 提供编译后的 JavaScript、TypeScript 类型定义和 CSS 资源。 + +## 安装 + +```bash +npm install @rc-component/dialog +``` + +## 使用 + +```tsx | pure +import Dialog from '@rc-component/dialog'; +import '@rc-component/dialog/assets/index.css'; + +export default function App() { + return ( + + ); +} +``` + +## 示例 + +运行本地 dumi 站点: + +```bash +npm install +npm start +``` + +然后打开 `http://localhost:8000`。 + +## API + +| 参数 | 说明 | 类型 | 默认值 | +| --- | --- | --- | --- | +| afterClose | 关闭动画结束后回调 | `() => void` | - | +| animation | 对话框动画名称 | string | - | +| className | 附加对话框 className | string | - | +| classNames | 语义 className | `{ header?: string; body?: string; footer?: string; mask?: string; content?: string; wrapper?: string }` | - | +| closable | 是否显示关闭按钮,或关闭按钮属性 | boolean \| object | true | +| closeIcon | 自定义关闭图标 | `React.ReactNode` | - | +| destroyOnHidden | 对话框关闭后卸载子项 | boolean | false | +| focusTriggerAfterClose | 关闭后聚焦触发元素 | boolean | true | +| footer | Dialog footer | `React.ReactNode` | - | +| forceRender | 在首次显示之前渲染对话框 | boolean | false | +| getContainer | 装载对话框的容器 | `() => HTMLElement` | - | +| keyboard | 按 Esc 是否关闭对话框 | boolean | true | +| mask | 是否显示遮罩 | boolean | true | +| maskAnimation | 遮罩动画名称 | string | - | +| maskClosable | 单击遮罩是否关闭对话框 | boolean | true | +| maskTransitionName | 遮罩过渡 className | string | - | +| modalRender | 自定义模态内容渲染器 | `(node: React.ReactNode) => React.ReactNode` | - | +| mousePosition | 用于变换原点的鼠标位置 | `{ x: number; y: number }` | - | +| prefixCls | 组件 className 前缀 | string | `rc-dialog` | +| scrollLock | 打开时是否锁定body滚动 | boolean | true | +| style | 根对话框样式 | `React.CSSProperties` | - | +| styles | 语义化样式 | `{ header?: React.CSSProperties; body?: React.CSSProperties; footer?: React.CSSProperties; mask?: React.CSSProperties; content?: React.CSSProperties; wrapper?: React.CSSProperties }` | - | +| title | 对话框标题 | `React.ReactNode` | - | +| transitionName | 对话框过渡 className | string | - | +| visible | 对话框是否可见 | boolean | false | +| zIndex | 对话框 z-index | number | - | +| onClose | 点击关闭按钮或遮罩时的回调 | `(event: React.SyntheticEvent) => void` | - | + +## 本地开发 + +```bash +npm install +npm start +``` + +dumi 站点默认运行在 `http://localhost:8000`。 + +```bash +npm test +npm run tsc +npm run lint +npm run compile +npm run build +``` + +## 发布 + +```bash +npm run prepublishOnly +``` + +包构建完成后,发布流程由 `@rc-component/np` 通过 `rc-np` 命令处理。 + +## 许可证 + +@rc-component/dialog 基于 [MIT](./LICENSE) 许可证发布。 diff --git a/docs/examples/draggable.tsx b/docs/examples/draggable.tsx index d5a5d2d6..dbfa3889 100644 --- a/docs/examples/draggable.tsx +++ b/docs/examples/draggable.tsx @@ -4,6 +4,10 @@ import Draggable from 'react-draggable'; import Dialog from '@rc-component/dialog'; import '../../assets/index.less'; +const DemoDraggable = Draggable as React.ComponentType< + React.PropsWithChildren<{ disabled?: boolean }> +>; + const MyControl: React.FC = () => { const [visible, setVisible] = React.useState(false); const [disabled, setDisabled] = React.useState(true); @@ -46,7 +50,7 @@ const MyControl: React.FC = () => { modal } - modalRender={(modal) =>