diff --git a/.eslintrc.js b/.eslintrc.js
deleted file mode 100644
index 59511d8..0000000
--- a/.eslintrc.js
+++ /dev/null
@@ -1,11 +0,0 @@
-const config = {
- extends: [require.resolve('@umijs/fabric/dist/eslint')],
- rules: {
- 'react/no-did-update-set-state': 0,
- 'react/no-find-dom-node': 0,
- 'import/no-extraneous-dependencies': 0,
- 'react/sort-comp': 0,
- },
-};
-
-module.exports = config;
\ No newline at end of file
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000..758659a
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1,2 @@
+github: ant-design
+open_collective: ant-design
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index 5990d9c..5e6c7fa 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -1,11 +1,27 @@
-# To get started with Dependabot version updates, you'll need to specify which
-# package ecosystems to update and where the package manifests are located.
-# Please see the documentation for all configuration options:
-# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
-
version: 2
updates:
- - package-ecosystem: "" # See documentation for possible values
- directory: "/" # Location of package manifests
+ - package-ecosystem: npm
+ directory: '/'
+ schedule:
+ interval: weekly
+ day: monday
+ time: '21:00'
+ timezone: Asia/Shanghai
+ open-pull-requests-limit: 10
+ groups:
+ npm-dependencies:
+ patterns:
+ - '*'
+
+ - package-ecosystem: github-actions
+ directory: '/'
schedule:
- interval: "weekly"
+ interval: weekly
+ day: monday
+ time: '21:00'
+ timezone: Asia/Shanghai
+ open-pull-requests-limit: 10
+ groups:
+ github-actions:
+ patterns:
+ - '*'
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
deleted file mode 100644
index f860ff1..0000000
--- a/.github/workflows/main.yml
+++ /dev/null
@@ -1,6 +0,0 @@
-name: ✅ test
-on: [push, pull_request]
-jobs:
- test:
- uses: react-component/rc-test/.github/workflows/test.yml@main
- secrets: inherit
diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml
deleted file mode 100644
index d02059a..0000000
--- a/.github/workflows/preview.yml
+++ /dev/null
@@ -1,20 +0,0 @@
-name: 🔂 Surge PR Preview
-
-on: [pull_request]
-
-jobs:
- preview:
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - uses: afc163/surge-preview@v1
- id: preview_step
- with:
- surge_token: ${{ secrets.SURGE_TOKEN }}
- github_token: ${{ secrets.GITHUB_TOKEN }}
- dist: .doc
- build: |
- npm install
- npm run docs:build
- - name: Get the preview_url
- run: echo "url => ${{ steps.preview_step.outputs.preview_url }}"
diff --git a/.github/workflows/react-doctor.yml b/.github/workflows/react-doctor.yml
new file mode 100644
index 0000000..29d6f76
--- /dev/null
+++ b/.github/workflows/react-doctor.yml
@@ -0,0 +1,22 @@
+name: React Doctor
+
+on:
+ pull_request:
+ push:
+ branches: [master]
+
+permissions:
+ contents: read
+ pull-requests: write
+ issues: write
+ statuses: write
+
+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 0000000..18227e7
--- /dev/null
+++ b/.github/workflows/surge-preview.yml
@@ -0,0 +1,52 @@
+name: Surge Preview
+
+on:
+ pull_request:
+
+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
+ 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: Setup utoo
+ if: ${{ steps.surge-token.outputs.enabled == 'true' }}
+ uses: utooland/setup-utoo@v1
+
+ - name: Build preview
+ if: ${{ steps.surge-token.outputs.enabled == 'true' }}
+ run: |
+ ut 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: .doc
+ 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/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..10c0ebb
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,16 @@
+name: ✅ test
+
+on:
+ push:
+ branches: [master]
+ pull_request:
+ branches: [master]
+
+permissions:
+ contents: read
+
+jobs:
+ test:
+ uses: react-component/rc-test/.github/workflows/test-utoo.yml@main
+ secrets:
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
diff --git a/README.md b/README.md
index 4a57694..c302c04 100644
--- a/README.md
+++ b/README.md
@@ -1,54 +1,71 @@
-# rc-portal
+
+
@rc-component/portal
+
Part of the Ant Design ecosystem.
+
🌀 React portal primitive with lifecycle-friendly container handling.
+
+
+
+
+
+
+
+
+
+
+
+English | 简体中文
+
+## Highlights
+
+| Area | Support |
+| ------- | ------------------------------------------------------------------ |
+| Purpose | React portal primitive with lifecycle-friendly container handling. |
+| Package | `@rc-component/portal` |
+| Release | `@rc-component/np` / `rc-np` |
-React 18 supported Portal Component.
+## Install
-[![NPM version][npm-image]][npm-url] [](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![npm download][download-image]][download-url]
+```bash
+npm install @rc-component/portal
+```
-[npm-image]: http://img.shields.io/npm/v/rc-portal.svg?style=flat-square
-[npm-url]: http://npmjs.org/package/rc-portal
-[github-actions-image]: https://github.com/react-component/portal/workflows/CI/badge.svg
-[github-actions-url]: https://github.com/react-component/portal/actions
-[codecov-image]: https://img.shields.io/codecov/c/github/react-component/portal/master.svg?style=flat-square
-[codecov-url]: https://app.codecov.io/gh/react-component/portal
-[download-image]: https://img.shields.io/npm/dm/rc-portal.svg?style=flat-square
-[download-url]: https://npmjs.org/package/rc-portal
+## Usage
-## Development
+```tsx | pure
+import Portal from '@rc-component/portal';
-```bash
-npm install
-npm start
-open http://localhost:8000
+export default () => Hello World;
```
-## Feature
-
-- React life cycle support portal component
+## API
-## Install
+| Prop | Description | Type | Default |
+| --- | --- | --- | --- |
+| `getContainer` | Customize portal container. | `Element \| () => Element \| string \| false` | `document.body` |
+| `open` | Whether to render portal content. | `boolean` | `false` |
+| `autoLock` | Lock page scroll when the portal is open. | `boolean` | `false` |
-[](https://npmjs.org/package/rc-portal)
+## Development
-## Usage
+```bash
+npm install
+npm start
+npm test
+npm run lint
+npm run tsc
+npm run compile
+```
-```js | pure
-import Portal from '@rc-component/portal';
+The dumi site runs at `http://localhost:8000`.
-const Demo = () => {
- return Hello World;
-};
+## Release
-export default Demo;
+```bash
+npm run prepublishOnly
```
-## 🔥 API
-
-We use typescript to create the Type definition. You can view directly in IDE. But you can still check the type definition [here](https://github.com/react-component/portal/blob/master/src/interface.ts).
+The release flow is handled by `@rc-component/np` through the `rc-np` command when the package uses the shared release flow.
-### Portal
+## License
-| Prop | Description | Type | Default |
-| ------------ | ---------------------------------- | ------------------------ | ------------- |
-| getContainer | Customize portal container element | Element \| () => Element | document.body |
-| open | Show the portal | boolean | false |
-| autoLock | Lock screen scroll when open | boolean | false |
+@rc-component/portal is released under the [MIT](./LICENSE) license.
diff --git a/README.zh-CN.md b/README.zh-CN.md
new file mode 100644
index 0000000..4a74594
--- /dev/null
+++ b/README.zh-CN.md
@@ -0,0 +1,71 @@
+
+
@rc-component/portal
+
Ant Design 生态的一部分。
+
🌀 支持生命周期与容器管理的 React Portal 基础组件。
+
+
+
+
+
+
+
+
+
+
+
+English | 简体中文
+
+## 亮点
+
+| 方向 | 支持 |
+| ---- | ------------------------------------------------ |
+| 定位 | 支持生命周期与容器管理的 React Portal 基础组件。 |
+| 包名 | `@rc-component/portal` |
+| 发布 | `@rc-component/np` / `rc-np` |
+
+## 安装
+
+```bash
+npm install @rc-component/portal
+```
+
+## 用法
+
+```tsx | pure
+import Portal from '@rc-component/portal';
+
+export default () => Hello World;
+```
+
+## API
+
+| 名称 | 说明 | 类型 | 默认值 |
+| --- | --- | --- | --- |
+| `getContainer` | 自定义 Portal 容器。 | `Element \| () => Element \| string \| false` | `document.body` |
+| `open` | 是否渲染 Portal 内容。 | `boolean` | `false` |
+| `autoLock` | Portal 打开时锁定页面滚动。 | `boolean` | `false` |
+
+## 本地开发
+
+```bash
+npm install
+npm start
+npm test
+npm run lint
+npm run tsc
+npm run compile
+```
+
+本地 dumi 站点默认运行在 `http://localhost:8000`.
+
+## 发布
+
+```bash
+npm run prepublishOnly
+```
+
+发布流程通过 `@rc-component/np` 提供的 `rc-np` 命令处理。
+
+## 许可证
+
+@rc-component/portal 基于 [MIT](./LICENSE) 协议发布。
diff --git a/docs/examples/getContainer.tsx b/docs/examples/getContainer.tsx
index 1cf2c0b..03b3f22 100644
--- a/docs/examples/getContainer.tsx
+++ b/docs/examples/getContainer.tsx
@@ -10,7 +10,7 @@ const Content = (): React.ReactElement => {
};
export default () => {
- const divRef = React.useRef();
+ const divRef = React.useRef(null);
return (
{
{
- return divRef.current;
+ return divRef.current!;
}}
>
diff --git a/eslint.config.mjs b/eslint.config.mjs
new file mode 100644
index 0000000..40f08ec
--- /dev/null
+++ b/eslint.config.mjs
@@ -0,0 +1,115 @@
+import js from '@eslint/js';
+import { defineConfig } from 'eslint/config';
+import { dirname } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import prettier from 'eslint-config-prettier';
+import jest from 'eslint-plugin-jest';
+import react from 'eslint-plugin-react';
+import reactHooks from 'eslint-plugin-react-hooks';
+import globals from 'globals';
+import tseslint from 'typescript-eslint';
+
+const tsconfigRootDir = dirname(fileURLToPath(import.meta.url));
+
+export default defineConfig([
+ {
+ plugins: {
+ '@typescript-eslint': tseslint.plugin,
+ },
+ },
+ {
+ linterOptions: {
+ reportUnusedDisableDirectives: 'warn',
+ },
+ },
+ {
+ ignores: [
+ 'node_modules/',
+ 'coverage/',
+ 'es/',
+ 'lib/',
+ 'dist/',
+ 'docs-dist/',
+ '.docs-dist/',
+ '.dumi/',
+ '.doc/',
+ '.vercel/',
+ ],
+ },
+ {
+ files: ['**/*.{js,jsx,ts,tsx}'],
+ extends: [
+ js.configs.recommended,
+ react.configs.flat.recommended,
+ react.configs.flat['jsx-runtime'],
+ prettier,
+ ],
+ plugins: {
+ 'react-hooks': reactHooks,
+ },
+ languageOptions: {
+ globals: {
+ ...globals.browser,
+ ...globals.node,
+ },
+ },
+ settings: {
+ react: {
+ version: 'detect',
+ },
+ },
+ rules: {
+ 'no-async-promise-executor': 'off',
+ 'no-empty-pattern': 'off',
+ 'no-irregular-whitespace': 'off',
+ 'no-prototype-builtins': 'off',
+ 'no-useless-escape': 'off',
+ 'no-extra-boolean-cast': 'off',
+ 'no-undef': 'off',
+ 'no-unused-vars': 'off',
+ 'react/no-find-dom-node': 'off',
+ 'react/display-name': 'off',
+ 'react/no-unknown-property': 'off',
+ 'react/prop-types': 'off',
+ 'react-hooks/exhaustive-deps': 'warn',
+ 'react-hooks/rules-of-hooks': 'error',
+ },
+ },
+ {
+ files: ['**/*.{ts,tsx}'],
+ extends: [...tseslint.configs.recommended],
+ rules: {
+ '@typescript-eslint/ban-ts-comment': 'off',
+ '@typescript-eslint/no-empty-object-type': 'off',
+ '@typescript-eslint/no-explicit-any': 'off',
+ '@typescript-eslint/no-unsafe-function-type': 'off',
+ '@typescript-eslint/no-unnecessary-type-constraint': 'off',
+ '@typescript-eslint/no-unused-vars': 'off',
+ },
+ },
+ {
+ files: ['src/**/*.{ts,tsx}'],
+ languageOptions: {
+ parserOptions: {
+ projectService: true,
+ tsconfigRootDir,
+ },
+ },
+ },
+ {
+ files: ['tests/**/*.{js,jsx,ts,tsx}', '**/*.{test,spec}.{js,jsx,ts,tsx}'],
+ extends: [jest.configs['flat/recommended']],
+ rules: {
+ 'jest/no-disabled-tests': 'off',
+ 'jest/no-done-callback': 'off',
+ 'jest/no-identical-title': 'off',
+ 'jest/expect-expect': 'off',
+ 'jest/no-alias-methods': 'off',
+ 'jest/no-conditional-expect': 'off',
+ 'jest/no-export': 'off',
+ 'jest/no-standalone-expect': 'off',
+ 'jest/valid-expect': 'off',
+ 'jest/valid-title': 'off',
+ },
+ },
+]);
diff --git a/global.d.ts b/global.d.ts
new file mode 100644
index 0000000..1ea3960
--- /dev/null
+++ b/global.d.ts
@@ -0,0 +1 @@
+declare module '*.less';
diff --git a/package.json b/package.json
index e1842ca..6016806 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "@rc-component/portal",
"version": "2.2.1",
- "description": "React Portal Component",
+ "description": "🌀 React portal primitive with lifecycle-friendly container handling.",
"keywords": [
"react",
"react-component",
@@ -26,13 +26,13 @@
"dist"
],
"scripts": {
+ "build": "dumi build",
"compile": "father build",
"deploy": "npm run docs:build && npm run docs:deploy",
"docs:build": "dumi build",
"docs:deploy": "gh-pages -d docs-dist",
"lint": "eslint src/ --ext .tsx,.ts",
"lint:tsc": "tsc -p tsconfig.json --noEmit",
- "now-build": "npm run docs:build",
"prepare": "dumi setup",
"prepublishOnly": "npm run compile && rc-np",
"prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
@@ -41,6 +41,7 @@
"test:client": "rc-test --testPathIgnorePatterns=ssr.test.tsx --testPathIgnorePatterns=ssr.test.tsx",
"test:coverage": "npm run test:client -- --coverage",
"test:server": "rc-test --env=node -- tests/ssr.test.tsx",
+ "tsc": "tsc -p tsconfig.json --noEmit",
"watch": "father dev"
},
"dependencies": {
@@ -48,26 +49,32 @@
"clsx": "^2.1.1"
},
"devDependencies": {
+ "@eslint/js": "^9.39.4",
"@rc-component/father-plugin": "^2.2.0",
- "@rc-component/np": "^1.0.3",
+ "@rc-component/np": "^1.0.4",
"@testing-library/dom": "^10.4.1",
- "@testing-library/jest-dom": "^6.9.0",
+ "@testing-library/jest-dom": "^6.9.1",
"@testing-library/react": "^16.3.2",
- "@types/jest": "^26.0.20",
- "@types/node": "^20.9.0",
- "@types/react": "^18.0.0",
- "@types/react-dom": "^18.0.0",
- "@umijs/fabric": "^4.0.0",
- "dumi": "^2.0.0",
- "eslint": "^8.0.0",
- "father": "^4.0.0",
+ "@types/jest": "^30.0.0",
+ "@types/node": "^26.0.1",
+ "@types/react": "^19.2.17",
+ "@types/react-dom": "^19.2.3",
+ "dumi": "^2.4.38",
+ "eslint": "^9.39.4",
+ "eslint-config-prettier": "^10.1.8",
+ "eslint-plugin-jest": "^29.15.4",
+ "eslint-plugin-react": "^7.37.5",
+ "eslint-plugin-react-hooks": "^7.1.1",
+ "father": "^4.6.24",
"gh-pages": "^6.1.1",
"glob": "^10.0.0",
- "prettier": "^2.1.2",
- "rc-test": "^7.1.2",
- "react": "^19.0.0",
- "react-dom": "^19.0.0",
- "typescript": "^5.0.0"
+ "globals": "^17.7.0",
+ "prettier": "^3.9.4",
+ "rc-test": "^7.1.3",
+ "react": "^19.2.7",
+ "react-dom": "^19.2.7",
+ "typescript": "^6.0.3",
+ "typescript-eslint": "^8.62.1"
},
"peerDependencies": {
"react": ">=18.0.0",
diff --git a/src/index.tsx b/src/index.tsx
index 34fa676..718a514 100644
--- a/src/index.tsx
+++ b/src/index.tsx
@@ -1,3 +1,5 @@
+/* eslint @typescript-eslint/consistent-type-exports: off */
+
import Portal from './Portal';
import type { PortalProps } from './Portal';
import { inlineMock } from './mock';
diff --git a/tests/__snapshots__/index.test.tsx.snap b/tests/__snapshots__/index.test.tsx.snap
index f12cba8..013fa15 100644
--- a/tests/__snapshots__/index.test.tsx.snap
+++ b/tests/__snapshots__/index.test.tsx.snap
@@ -1,4 +1,4 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
+// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`Portal getContainer customize in same level 1`] = `
diff --git a/tests/__snapshots__/testEnv.test.tsx.snap b/tests/__snapshots__/testEnv.test.tsx.snap
index 91bdcb4..470d11d 100644
--- a/tests/__snapshots__/testEnv.test.tsx.snap
+++ b/tests/__snapshots__/testEnv.test.tsx.snap
@@ -1,4 +1,4 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
+// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`Test Env inlineMock 1`] = `
diff --git a/tests/index.test.tsx b/tests/index.test.tsx
index 942509b..5b81aa8 100644
--- a/tests/index.test.tsx
+++ b/tests/index.test.tsx
@@ -78,11 +78,11 @@ describe('Portal', () => {
};
const Demo = () => {
- const divRef = React.useRef();
+ const divRef = React.useRef
(null);
return (
-
divRef.current}>
+ divRef.current!}>
@@ -91,7 +91,7 @@ describe('Portal', () => {
const { container } = render();
expect(container).toMatchSnapshot();
- expect(renderTimes).toEqual(1);
+ expect(renderTimes).toEqual(2);
});
});
@@ -239,7 +239,7 @@ describe('Portal', () => {
let checked = false;
const Demo = ({ open }: { open?: boolean }) => {
- const pRef = React.useRef();
+ const pRef = React.useRef(null);
React.useEffect(() => {
if (open) {
diff --git a/tsconfig.json b/tsconfig.json
index 6e12177..67ceb8c 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,16 +1,19 @@
{
"compilerOptions": {
"target": "esnext",
- "moduleResolution": "node",
- "baseUrl": "./",
+ "strict": false,
+ "types": ["node", "jest"],
+ "moduleResolution": "bundler",
"jsx": "preserve",
"declaration": true,
"skipLibCheck": true,
"esModuleInterop": true,
"paths": {
- "@/*": ["src/*"],
- "@@/*": [".dumi/tmp/*"],
- "@rc-component/portal": ["src/Portal.tsx"]
+ "@/*": ["./src/*"],
+ "@@/*": ["./.dumi/tmp/*"],
+ "@rc-component/portal": ["./src/Portal.tsx"]
}
- }
+ },
+ "include": ["**/*.ts", "**/*.tsx", ".dumirc.ts"],
+ "exclude": ["node_modules", "es", "lib", "dist", "docs-dist", ".doc", ".dumi/tmp", "coverage"]
}
diff --git a/vercel.json b/vercel.json
new file mode 100644
index 0000000..fe70e76
--- /dev/null
+++ b/vercel.json
@@ -0,0 +1,6 @@
+{
+ "framework": "umijs",
+ "installCommand": "npm install",
+ "buildCommand": "npm run build",
+ "outputDirectory": ".doc"
+}