diff --git a/.dumirc.ts b/.dumirc.ts index ebd40b0d..50c681a4 100644 --- a/.dumirc.ts +++ b/.dumirc.ts @@ -1,17 +1,19 @@ // more config: https://d.umijs.org/config import { defineConfig } from 'dumi'; +const basePath = process.env.GH_PAGES ? '/menu/' : '/'; +const publicPath = basePath; + export default defineConfig({ themeConfig: { - name: 'rc-menu', + name: 'Menu', logo: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4', - nav: [ - { title: 'Demo', link: '/demo/antd'} - ], + nav: [{ title: 'Demo', link: '/demo/antd' }], }, - favicons: - ['https://avatars0.githubusercontent.com/u/9441414?s=200&v=4'], - outputPath: '.doc', + favicons: ['https://avatars0.githubusercontent.com/u/9441414?s=200&v=4'], + outputPath: 'docs-dist', + base: basePath, + publicPath, exportStatic: {}, mfsu: {}, styles: [ @@ -20,5 +22,5 @@ export default defineConfig({ width: auto !important; } `, - ] + ], }); diff --git a/.fatherrc.ts b/.fatherrc.ts new file mode 100644 index 00000000..96268ae1 --- /dev/null +++ b/.fatherrc.ts @@ -0,0 +1,5 @@ +import { defineConfig } from 'father'; + +export default defineConfig({ + plugins: ['@rc-component/father-plugin'], +}); 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 6745ced9..3b730ef9 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/codeql.yml b/.github/workflows/codeql.yml index 5efca0f4..984e4786 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: "12 22 * * 6" + - cron: '12 22 * * 6' 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/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 5735e2d2..00000000 --- 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 \ No newline at end of file diff --git a/.github/workflows/react-component-ci.yml b/.github/workflows/react-component-ci.yml new file mode 100644 index 00000000..9503b960 --- /dev/null +++ b/.github/workflows/react-component-ci.yml @@ -0,0 +1,8 @@ +name: ✅ test +on: [push, pull_request] +permissions: + contents: read +jobs: + test: + uses: react-component/rc-test/.github/workflows/test-utoo.yml@main + secrets: inherit 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 898129e9..267c6ce6 100644 --- a/.gitignore +++ b/.gitignore @@ -27,6 +27,8 @@ build lib es coverage +.doc +docs-dist/ yarn.lock package-lock.json pnpm-lock.yaml @@ -38,4 +40,5 @@ pnpm-lock.yaml .dumi/tmp-production .env.local -bun.lockb \ No newline at end of file +bun.lockb +.vercel diff --git a/.husky/pre-commit b/.husky/pre-commit index c27d8893..2312dc58 100644 --- 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 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 22d3dce2..ac8052cc 100644 --- a/README.md +++ b/README.md @@ -1,464 +1,184 @@ -# @rc-component/menu - ---- - -React Menu Component. port from https://github.com/kissyteam/menu - -[![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/menu.svg?style=flat-square -[npm-url]: https://npmjs.org/package/@rc-component/menu -[github-actions-image]: https://github.com/react-component/menu/actions/workflows/main.yml/badge.svg -[github-actions-url]: https://github.com/react-component/menu/actions/workflows/main.yml -[circleci-image]: https://img.shields.io/circleci/react-component/menu/master?style=flat-square -[circleci-url]: https://circleci.com/gh/react-component/menu -[codecov-image]: https://img.shields.io/codecov/c/github/react-component/footer/master.svg?style=flat-square -[codecov-url]: https://codecov.io/gh/react-component/footer/branch/master -[coveralls-image]: https://img.shields.io/coveralls/react-component/menu.svg?style=flat-square -[coveralls-url]: https://coveralls.io/r/react-component/menu?branch=master -[david-url]: https://david-dm.org/react-component/menu -[david-image]: https://david-dm.org/react-component/menu/status.svg?style=flat-square -[david-dev-url]: https://david-dm.org/react-component/menu?type=dev -[david-dev-image]: https://david-dm.org/react-component/menu/dev-status.svg?style=flat-square -[download-image]: https://img.shields.io/npm/dm/@rc-component/menu.svg?style=flat-square -[download-url]: https://npmjs.org/package/@rc-component/menu -[bundlephobia-url]: https://bundlephobia.com/result?p=@rc-component/menu -[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/menu -[dumi-url]: https://github.com/umijs/dumi -[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square +
Part of the Ant Design ecosystem.
🧭 Accessible React menu primitives for navigation, command surfaces, and nested item trees.
+ + +English | 简体中文
+ +## Highlights + +- Horizontal, vertical, and inline menu modes. +- Controlled and uncontrolled selection, open keys, and active key state. +- `items` configuration API with legacy children support. +- Sub menus, item groups, dividers, icons, overflow, popup rendering, and keyboard focus helpers. +- TypeScript definitions and semantic `classNames` / `styles` slots. +- Used by Ant Design as the shared menu foundation. ## Install -[](https://npmjs.org/package/@rc-component/menu) +```bash +npm install @rc-component/menu +``` ## Usage -```js -import Menu, { SubMenu, MenuItem } from '@rc-component/menu'; +```tsx | pure +import Menu, { type MenuProps } from '@rc-component/menu'; + +const items: MenuProps['items'] = [ + { key: 'home', label: 'Home' }, + { + key: 'docs', + label: 'Docs', + children: [ + { key: 'quick-start', label: 'Quick start' }, + { key: 'api', label: 'API' }, + ], + }, +]; + +export default () => ( + +); +``` + +```tsx | pure +import Menu, { MenuItem, SubMenu } from '@rc-component/menu'; -ReactDOM.render( +export default () => ( , - container, + ); ``` -## Compatibility +## Examples -| [
](http://godban.github.io/browsers-support-badges/)
](http://godban.github.io/browsers-support-badges/)
](http://godban.github.io/browsers-support-badges/)
](http://godban.github.io/browsers-support-badges/)
](http://godban.github.io/browsers-support-badges/)| name | -type | -default | -description | -
|---|---|---|---|
| ref | -React.HTMLLIElement | -- | get dom node | -
| className | -String | -- | additional css class of root dom node | -
| mode | -String | -vertical | -one of ["horizontal","inline","vertical-left","vertical-right"] | -
| activeKey | -String | -- | initial and current active menu item's key. | -
| defaultActiveFirst | -Boolean | -false | -whether active first menu item when show if activeKey is not set or invalid | -
| multiple | -Boolean | -false | -whether allow multiple select | -
| selectable | -Boolean | -true | -allow selecting menu items | -
| selectedKeys | -String[] | -[] | -selected keys of items | -
| defaultSelectedKeys | -String[] | -[] | -initial selected keys of items | -
| openKeys | -String[] | -[] | -open keys of SubMenuItem | -
| defaultOpenKeys | -String[] | -[] | -initial open keys of SubMenuItem | -
| onSelect | -function({key:String, item:ReactComponent, domEvent:Event, selectedKeys:String[],ItemData:ItemData}) | -- | called when select a menu item | -
| onClick | -function({key:String, item:ReactComponent, domEvent:Event, keyPath: String[], ItemData:ItemData}) | -- | called when click a menu item | -
| onOpenChange | -(openKeys:String[]) => void | -- | called when open/close sub menu | -
| onDeselect | -function({key:String, item:ReactComponent, domEvent:Event, selectedKeys:String[]}) | -- | called when deselect a menu item. only called when allow multiple | -
| triggerSubMenuAction | -Enum { hover, click } | -hover | -which action can trigger submenu open/close | -
| openAnimation | -{enter:function,leave:function}|String | -- | animate when sub menu open or close. see @rc-component/motion for object type. | -
| openTransition | -String | -- | css transitionName when sub menu open or close | -
| subMenuOpenDelay | -Number | -0 | -delay time to show popup sub menu. unit: s | -
| subMenuCloseDelay | -Number | -0.1 | -delay time to hide popup sub menu. unit: s | -
| forceSubMenuRender | -Boolean | -false | -whether to render submenu even if it is not visible | -
| getPopupContainer | -Function(menuDOMNode): HTMLElement | -() => document.body | -Where to render the DOM node of popup menu when the mode is horizontal or vertical | -
| builtinPlacements | -Object of alignConfigs for dom-align | -see placements.ts | -Describes how the popup menus should be positioned | -
| itemIcon | -ReactNode | (props: MenuItemProps) => ReactNode | -- | Specify the menu item icon. | -
| expandIcon | -ReactNode | (props: SubMenuProps & { isSubMenu: boolean }) => ReactNode | -- | Specify the menu item icon. | -
| direction | -String | -- | Layout direction of menu component, it supports RTL direction too. | -
| inlineIndent | -Number | -24 | -Padding level multiplier. Right or left padding depends on param "direction". | -
| name | -type | -default | -description | -
|---|---|---|---|
| className | -String | -- | additional css class of root dom node | -
| disabled | -Boolean | -false | -no effect for click or keydown for this item | -
| extra | -React.ReactNode | -- | Specify menu item extra node. | -
| key | -Object | -- | corresponding to activeKey | -
| onMouseEnter | -Function({eventKey, domEvent}) | -- | - |
| onMouseLeave | -Function({eventKey, domEvent}) | -- | - |
| itemIcon | -ReactNode | (props: MenuItemProps) => ReactNode | -- | Specify the menu item icon. | -
| name | -type | -default | -description | -
|---|---|---|---|
| ref | -React.HTMLLIElement | -- | get dom node | -
| popupClassName | -String | -- | additional css class of root dom node | -
| popupStyle | -CSSProperties | -- | additional css style of root dom node | -
| title | -String/ReactElement | -- | sub menu's content | -
| overflowedIndicator | -String/ReactElement | -··· | -overflow indicator when menu overlows in horizontal mode | -
| key | -Object | -- | corresponding to activeKey | -
| disabled | -Boolean | -false | -no effect for click or keydown for this item | -
| onMouseEnter | -Function({eventKey, domEvent}) | -- | - |
| onMouseLeave | -Function({eventKey, domEvent}) | -- | - |
| onTitleMouseEnter | -Function({eventKey, domEvent}) | -- | - |
| onTitleMouseLeave | -Function({eventKey, domEvent}) | -- | - |
| onTitleClick | -Function({eventKey, domEvent}) | -- | - |
| popupOffset | -Array | -- | The offset of the popup submenu, in an x, y coordinate array. e.g.: `[0,15]` | -
| expandIcon | -ReactNode | (props: SubMenuProps) => ReactNode | -- | Specify the menu item icon. | -
| itemIcon | -ReactNode | (props: SubMenuProps & { isSubMenu: boolean }) => ReactNode | -- | Specify the menu item icon. | -
| name | -type | -default | -description | -
|---|---|---|---|
| ref | -React.HTMLLIElement | -- | get dom node | -
| title | -String|React.Element | -- | title of item group | -
| children | -React.Element[] | -- | MenuItems belonged to this group | -
English | 简体中文
+ +## 特性 + +- 水平、垂直和内联菜单模式。 +- 受控和非受控选择、打开键和活动键状态。 +- `items` 配置 API 具有旧子支持。 +- 子菜单、项目组、分隔线、图标、溢出、弹层渲染和键盘焦点助手。 +- 提供 TypeScript 类型定义和语义化 `classNames` / `styles` 插槽。 +- 被 Ant Design 用作共享的 menu 基础能力。 + +## 安装 + +```bash +npm install @rc-component/menu +``` + +## 使用 + +```tsx | pure +import Menu, { type MenuProps } from '@rc-component/menu'; + +const items: MenuProps['items'] = [ + { key: 'home', label: 'Home' }, + { + key: 'docs', + label: 'Docs', + children: [ + { key: 'quick-start', label: 'Quick start' }, + { key: 'api', label: 'API' }, + ], + }, +]; + +export default () => ( + +); +``` + +```tsx | pure +import Menu, { MenuItem, SubMenu } from '@rc-component/menu'; + +export default () => ( + +); +``` + +## 示例 + +运行本地 dumi 站点: + +```bash +npm install +npm start +``` + +然后打开 `http://localhost:8000`。 + +## API + +### Menu + +| 参数 | 类型 | 默认值 | 说明 | +| --- | --- | --- | --- | +| activeKey | `string` | - | 受控活动项目键。 | +| builtinPlacements | `Record