diff --git a/.dumirc.ts b/.dumirc.ts index 95ecbc3..f31cdc8 100644 --- a/.dumirc.ts +++ b/.dumirc.ts @@ -2,10 +2,11 @@ import { defineConfig } from 'dumi'; import path from 'path'; -const basePath = process.env.GITHUB_ACTIONS ? '/collapse/' : '/'; -const publicPath = process.env.GITHUB_ACTIONS ? '/collapse/' : '/'; +const basePath = process.env.GH_PAGES ? '/collapse/' : '/'; +const publicPath = basePath; export default defineConfig({ + outputPath: 'docs-dist', alias: { 'rc-collapse$': path.resolve('src'), 'rc-collapse/es': path.resolve('src'), 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 6745ced..3b730ef 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,28 +1,19 @@ version: 2 updates: -- package-ecosystem: npm - directory: "/" - schedule: - interval: daily - time: "21:00" - open-pull-requests-limit: 10 - ignore: - - dependency-name: "@types/react-dom" - versions: - - 17.0.0 - - 17.0.1 - - 17.0.2 - - dependency-name: "@types/react" - versions: - - 17.0.0 - - 17.0.1 - - 17.0.2 - - 17.0.3 - - dependency-name: np - versions: - - 7.2.0 - - 7.3.0 - - 7.4.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/react-component-ci.yml b/.github/workflows/react-component-ci.yml index 5735e2d..36dacae 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 0000000..097eb88 --- /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/site-deploy.yml b/.github/workflows/site-deploy.yml index 8f12507..c5de830 100644 --- a/.github/workflows/site-deploy.yml +++ b/.github/workflows/site-deploy.yml @@ -13,12 +13,14 @@ jobs: runs-on: ubuntu-latest steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v7 + with: + persist-credentials: false - name: setup node - uses: actions/setup-node@v1 + uses: actions/setup-node@v6 with: - node-version: 14 + node-version: 20 - name: create package-lock.json run: npm i --package-lock-only --ignore-scripts @@ -30,10 +32,10 @@ jobs: run: npm run build - name: Deploy to GitHub Pages - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@329bcc8f12caed2cefe5a5b80781499a6f3b361b with: github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./dist + publish_dir: ./docs-dist force_orphan: true user_name: 'github-actions[bot]' user_email: 'github-actions[bot]@users.noreply.github.com' diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml new file mode 100644 index 0000000..cffac6c --- /dev/null +++ b/.github/workflows/surge-preview.yml @@ -0,0 +1,50 @@ +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 + 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 e1c3a36..f01a997 100644 --- a/.gitignore +++ b/.gitignore @@ -36,7 +36,8 @@ pnpm-lock.yaml .dumi/tmp .dumi/tmp-production .dumi/tmp-test +docs-dist .env.local src/.umi -bun.lockb \ No newline at end of file +bun.lockb diff --git a/.husky/pre-commit b/.husky/pre-commit index c27d889..2312dc5 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1 @@ -lint-staged +npx lint-staged diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..c466d87 --- /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 0000000..bd0a1f7 --- /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 96ceda1..57f91a1 100644 --- a/README.md +++ b/README.md @@ -1,250 +1,114 @@ -# rc-collapse - -rc-collapse ui component for react - -[![NPM version][npm-image]][npm-url] [![build status][github-actions-image]][github-actions-url] [![Test coverage][codecov-image]][codecov-url] [![npm download][download-image]][download-url] - -[npm-image]: http://img.shields.io/npm/v/rc-collapse.svg?style=flat-square -[npm-url]: http://npmjs.org/package/rc-collapse -[github-actions-image]: https://github.com/react-component/collapse/workflows/CI/badge.svg -[github-actions-url]: https://github.com/react-component/collapse/actions -[codecov-image]: https://img.shields.io/codecov/c/github/react-component/collapse/master.svg?style=flat-square -[codecov-url]: https://app.codecov.io/gh/react-component/collapse -[download-image]: https://img.shields.io/npm/dm/rc-collapse.svg?style=flat-square -[download-url]: https://npmjs.org/package/rc-collapse - -## Live Demo - -https://collapse-react-component.vercel.app +
Part of the Ant Design ecosystem.
🪗 A flexible collapse and accordion component for React.
+ + +English | 简体中文
+ +## Highlights + +- Supports accordion and multi-panel collapse modes. +- Prefer the `items` API for declarative panel configuration. +- Keeps `Collapse.Panel` for compatibility. It is deprecated and will be removed in v4. +- Supports custom expand icons, semantic class names, semantic styles, and motion. ## Install -[](https://npmjs.org/package/rc-collapse) +```bash +npm install @rc-component/collapse +``` ## Usage -```js -var Collapse = require('rc-collapse'); -var Panel = Collapse.Panel; -var React = require('react'); -var ReactDOM = require('react-dom'); -require('rc-collapse/assets/index.css'); - -var App = ( -| name | -type | -default | -description | -
|---|---|---|---|
| activeKey | -String|Array |
- The first panel key | -current active Panel key | -
| className | -String or object | -- | custom className to apply | -
| defaultActiveKey | -String|Array |
- null | -default active key | -
| destroyOnHidden | -Boolean | -false | -If destroy the panel which not active, default false. | -
| accordion | -Boolean | -false | -accordion mode, default is null, is collapse mode | -
| onChange | -Function(key) | -noop | -called when collapse Panel is changed | -
| expandIcon | -(props: PanelProps) => ReactNode | -- | specific the custom expand icon. | -
| collapsible | -'header' | 'icon' | 'disabled' | -- | -specify whether the panel of children is collapsible or the area of collapsible. | -
| items | -- interface.ts#ItemType - | -- | -collapse items content | -
| name | -type | -default | -description | -
|---|---|---|---|
| header | -String or node | -- | header content of Panel | -
| headerClass | -String | -' ' | -custom className to apply to header | -
| showArrow | -boolean | -true | -show arrow beside header | -
| className | -String or object | -- | custom className to apply | -
| classNames | -{ header?: string, body?: string } | -- | Semantic structure className | -
| style | -object | -- | custom style | -
| styles | -{ header?: React.CSSProperties, body?: React.CSSProperties } | -- | Semantic structure styles | -
| openMotion | -object | -- | set the animation of open behavior, [more](https://github.com/react-component/motion). Different with v2, closed pane use a `rc-collapse-content-hidden` class to set `display: none` for hidden. | -
| forceRender | -boolean | -false | -forced render of content in panel, not lazy render after clicking on header | -
| extra | -String | ReactNode | -- | Content to render in the right of the panel header | -
| collapsible | -'header' | 'icon' | 'disabled' | -- | -specify whether the panel be collapsible or the area of collapsible. | -
English | 简体中文
+ +## 特性 + +- 支持手风琴和多面板折叠模式。 +- 推荐使用 `items` API 声明式配置面板。 +- 保留 `Collapse.Panel` 以实现兼容性。它已被弃用,并将在 v4 中删除。 +- 支持自定义展开图标、语义化类名、语义样式和动画。 + +## 安装 + +```bash +npm install @rc-component/collapse +``` + +## 使用 + +```tsx | pure +import Collapse from '@rc-component/collapse'; +import '@rc-component/collapse/assets/index.css'; + +export default function App() { + return ( +