diff --git a/.dumirc.ts b/.dumirc.ts index deac20b5a..9f5e28324 100644 --- a/.dumirc.ts +++ b/.dumirc.ts @@ -1,10 +1,15 @@ import { defineConfig } from 'dumi'; +const basePath = process.env.GH_PAGES ? '/select/' : '/'; +const publicPath = basePath; + export default defineConfig({ favicons: ['https://avatars0.githubusercontent.com/u/9441414?s=200&v=4'], themeConfig: { name: 'Select', logo: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4', }, - outputPath: '.doc', + outputPath: 'docs-dist', + base: basePath, + publicPath, }); diff --git a/.fatherrc.ts b/.fatherrc.ts new file mode 100644 index 000000000..96268ae1e --- /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 33b1999c7..758659af3 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 2cbed3ee2..3b730ef99 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,29 +3,17 @@ updates: - package-ecosystem: npm directory: '/' schedule: - interval: daily + 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 - ignore: - - 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: '@types/react-dom' - versions: - - 17.0.0 - - 17.0.1 - - 17.0.2 - - dependency-name: typescript - versions: - - 4.1.3 - - 4.1.4 - - 4.1.5 - - 4.2.2 diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 8598a777c..a3d6e349f 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -24,18 +24,20 @@ jobs: 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 }}' diff --git a/.github/workflows/react-doctor.yml b/.github/workflows/react-doctor.yml new file mode 100644 index 000000000..29d6f76bd --- /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 000000000..394f2b02e --- /dev/null +++ b/.github/workflows/surge-preview.yml @@ -0,0 +1,48 @@ +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: 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/.github/workflows/test.yml b/.github/workflows/test.yml index f860ff107..36dacae47 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.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 + uses: react-component/rc-test/.github/workflows/test-utoo.yml@main + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index 88a192abe..7cbbac945 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,5 @@ tsconfig.test.json .dumi/tmp .dumi/tmp-test .dumi/tmp-production -.history \ No newline at end of file +docs-dist +.history diff --git a/.husky/pre-commit b/.husky/pre-commit index d0a778429..2312dc587 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1 +1 @@ -npx lint-staged \ No newline at end of file +npx lint-staged diff --git a/.prettierignore b/.prettierignore index 214377229..f6166fa09 100644 --- a/.prettierignore +++ b/.prettierignore @@ -9,3 +9,15 @@ package.json .umi .umi-production .umi-test +node_modules +coverage +docs-dist +dist +.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 000000000..bd0a1f722 --- /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 8c23dd44f..e48b94edc 100644 --- a/README.md +++ b/README.md @@ -1,195 +1,168 @@ -# @rc-component/select - ---- - -React Select 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/select.svg?style=flat-square -[npm-url]: http://npmjs.org/package/@rc-component/select -[github-actions-image]: https://github.com/react-component/select/actions/workflows/test.yml/badge.svg -[github-actions-url]: https://github.com/react-component/select/actions/workflows/test.yml -[codecov-image]: https://img.shields.io/codecov/c/github/react-component/select/master.svg?style=flat-square -[codecov-url]: https://app.codecov.io/gh/react-component/select -[david-url]: https://david-dm.org/react-component/select -[david-image]: https://david-dm.org/react-component/select/status.svg?style=flat-square -[david-dev-url]: https://david-dm.org/react-component/select?type=dev -[david-dev-image]: https://david-dm.org/react-component/select/dev-status.svg?style=flat-square -[download-image]: https://img.shields.io/npm/dm/@rc-component/select.svg?style=flat-square -[download-url]: https://npmjs.org/package/@rc-component/select -[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/select -[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/select -[dumi-url]: https://github.com/umijs/dumi -[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square - -## Screenshots - - - -## Feature - -- support IE11+,Chrome,Firefox,Safari - -### Keyboard - -- Open select (focus input || focus and click) -- KeyDown/KeyUp/Enter to navigate menu - -## install - -[![@rc-component/select](https://nodei.co/npm/@rc-component/select.png)](https://npmjs.org/package/@rc-component/select) +
+

@rc-component/select

+

Ant Design Part of the Ant Design ecosystem.

+

🎯 Composable Select component for React, with search, async-friendly option data, custom rendering, and virtual scrolling.

+ +

+ NPM version + npm downloads + build status + Codecov + bundle size + dumi +

+
+ +

English | 简体中文

+ +## Highlights + +| Area | Support | +| --------- | ---------------------------------------------------------- | +| Data | `options` data, legacy `Option` children, grouped options | +| Modes | Single select, `multiple`, `tags`, and `combobox` | +| Search | Controlled search, custom filter, custom sort | +| Rendering | Custom option, label, selected item, clear, and menu icons | +| Scale | Virtual scrolling with configurable item height | + +## Install + +```bash +npm install @rc-component/select +``` ## Usage -### basic use - -```jsx | pure -import Select, { Option } from '@rc-component/select'; +```tsx | pure +import Select from '@rc-component/select'; import '@rc-component/select/assets/index.css'; export default () => ( - + +); +``` + +## 示例 + +运行本地 dumi 站点: + +```bash +npm install +npm start +``` + +然后打开 `http://localhost:8000`。 + +## API + +### Select + +Select 还接受来自 `BaseSelect` 的公共属性,但由 Select 重新定义的 `showSearch` 除外。 + +| 名称 | 说明 | 类型 | 默认值 | +| --- | --- | --- | --- | +| autoClearSearchValue | 已弃用。请改用 `showSearch.autoClearSearchValue`。 | boolean | true | +| backfill | 将活动选项回填到输入中。仅适用于 `combobox` 模式。 | boolean | false | +| children | 旧版选项子节点。新代码推荐使用 `options`。 | ReactNode | - | +| classNames | 语义 className。 | `Partial>` | - | +| defaultActiveFirstOption | 默认情况下第一个选项是否处于活动状态。 | boolean | true | +| defaultValue | 初始选中值。 | `ValueType` \| null | - | +| direction | 下拉方向。 | `ltr` \| `rtl` | `ltr` | +| fieldNames | 自定义选项字段名称。 | `FieldNames` | - | +| filterOption | 已弃用。请改用 `showSearch.filterOption`。 | boolean \| `FilterFunc` | - | +| filterSort | 已弃用。请改用 `showSearch.filterSort`。 | `(optionA, optionB, info) => number` | - | +| labelInValue | 返回标记值对象而不是原始值。 | boolean | false | +| labelRender | 自定义选定的标签渲染。 | `(props: LabelInValueType) => ReactNode` | - | +| listHeight | 弹层列表高度。 | number | 200 | +| listItemHeight | 弹层列表项的高度。 | number | 20 | +| maxCount | 最大选定项目数。 | number | - | +| menuItemSelectedIcon | 自定义选定的选项图标。 | `RenderNode` | - | +| mode | 选择模式。 | `combobox` \| `multiple` \| `tags` | - | +| onActive | 当活动值改变时调用。 | `(value: ValueType) => void` | - | +| onChange | 当选定值更改时调用。 | `(value: ValueType, option?: OptionType \| OptionType[]) => void` | - | +| onDeselect | 当取消选择某个值时调用。 | `(value, option) => void` | - | +| onSearch | 已弃用。请改用 `showSearch.onSearch`。 | `(value: string) => void` | - | +| onSelect | 选择值时调用。 | `(value, option) => void` | - | +| optionFilterProp | 已废弃。请使用 `showSearch.optionFilterProp`。 | string \| string[] | - | +| optionLabelProp | 用作所选标签的选项道具。 | string | - | +| optionRender | 自定义选项渲染器。 | `(oriOption, info: { index: number }) => ReactNode` | - | +| options | 选项数据。 | `OptionType[]` | - | +| searchValue | 已弃用。请改用 `showSearch.searchValue`。 | string | - | +| showSearch | 启用搜索或配置搜索行为。 | boolean \| `SearchConfig` | - | +| styles | 语义化样式。 | `Partial>` | - | +| value | 受控选中值。 | `ValueType` \| null | - | +| virtual | 设置为 `false` 时禁用虚拟滚动。 | boolean | true | + +### 方法 + +| 名称 | 说明 | 参数 | +| ----- | ------------ | ---- | +| blur | 移除焦点。 | - | +| focus | 聚焦选择器。 | - | + +### SearchConfig + +| 名称 | 说明 | 类型 | 默认值 | +| --- | --- | --- | --- | +| autoClearSearchValue | 在多种模式下选择或取消选择后清除搜索输入。 | boolean | true | +| filterOption | 按搜索输入过滤选项。 | boolean \| `FilterFunc` | - | +| filterSort | 对过滤的选项进行排序。 | `(optionA, optionB, info: { searchValue: string }) => number` | - | +| onSearch | 当搜索输入更改时调用。 | `(value: string) => void` | - | +| optionFilterProp | 启用 `filterOption` 时用于过滤的选项属性。 | string \| string[] | - | +| searchValue | 受控搜索输入值。 | string | - | + +### Option + +`Option` 是一个旧的占位符组件。对于新用途,更喜欢 `options` 属性。 + +| 名称 | 说明 | 类型 | 默认值 | +| --------- | ---------------- | ------------------------ | ------ | +| children | 选项标签。 | ReactNode | - | +| className | 选项 className。 | string | - | +| disabled | 禁用该选项。 | boolean | false | +| title | 选项标题。 | string | - | +| value | 选项值。 | string \| number \| null | - | + +### OptGroup + +`OptGroup` 是一个旧的占位符组件。优选嵌套 `options` 数据以供新用途。 + +| 名称 | 说明 | 类型 | 默认值 | +| --------- | ---------------- | --------- | ------ | +| children | 组选项。 | ReactNode | - | +| className | 分组 className。 | string | - | +| disabled | 禁用该组。 | boolean | false | +| label | Group label. | ReactNode | - | +| title | Group title. | string | - | + +## 本地开发 + +```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/select 基于 [MIT](./LICENSE) 许可证发布。 diff --git a/docs/examples/getPopupContainer.tsx b/docs/examples/getPopupContainer.tsx index 5b32af2fd..4399ccc4e 100644 --- a/docs/examples/getPopupContainer.tsx +++ b/docs/examples/getPopupContainer.tsx @@ -1,7 +1,7 @@ -import 'rc-dialog/assets/index.css'; +import '@rc-component/dialog/assets/index.css'; import '../../assets/index.less'; -import Dialog from 'rc-dialog'; +import Dialog from '@rc-component/dialog'; import Select, { type SelectProps } from '@rc-component/select'; import React from 'react'; diff --git a/package.json b/package.json index cd4592e91..f72b5d9c4 100644 --- a/package.json +++ b/package.json @@ -13,20 +13,20 @@ ], "main": "./lib/index", "module": "./es/index", - "types": "./lib/index.d.ts", + "types": "./es/index.d.ts", "files": [ "assets/*.css", "assets/*.less", "es", "lib" ], - "homepage": "http://github.com/react-component/select", + "homepage": "https://react-component.github.io/select", "repository": { "type": "git", - "url": "git@github.com:react-component/select.git" + "url": "https://github.com/react-component/select.git" }, "bugs": { - "url": "http://github.com/react-component/select/issues" + "url": "https://github.com/react-component/select/issues" }, "license": "MIT", "scripts": { @@ -38,8 +38,7 @@ "prettier": "prettier --write --ignore-unknown .", "lint": "eslint src/ docs/ tests/ --ext .tsx,.ts,.jsx,.js", "test": "rc-test", - "tsc": "tsc --noEmit", - "now-build": "npm run build" + "tsc": "tsc --noEmit" }, "lint-staged": { "*": "prettier --write --ignore-unknown" @@ -56,29 +55,32 @@ "clsx": "^2.1.1" }, "devDependencies": { + "@rc-component/dialog": "^1.10.0", "@rc-component/father-plugin": "^2.2.0", - "@rc-component/np": "^1.0.0", - "@testing-library/jest-dom": "^6.4.5", - "@testing-library/react": "^15.0.6", - "@types/jest": "^29.5.12", - "@types/node": "^24.5.2", - "@types/react": "^18.3.0", - "@types/react-dom": "^18.3.0", + "@rc-component/np": "^1.0.4", + "@testing-library/jest-dom": "^6.9.1", + "@testing-library/react": "^15.0.7", + "@types/jest": "^29.5.14", + "@types/node": "^26.0.1", + "@types/react": "^18.3.31", + "@types/react-dom": "^18.3.7", "@umijs/fabric": "^4.0.1", - "babel-jest": "^29.6.1", - "dumi": "^2.2.13", - "eslint": "^8.55.0", - "father": "^4.0.0", - "husky": "^9.1.5", + "babel-jest": "^29.7.0", + "dumi": "^2.4.35", + "eslint": "^8.57.1", + "father": "^4.6.23", + "husky": "^9.1.7", "jsonp": "^0.2.1", - "less": "^4.2.0", - "lint-staged": "^15.2.9", - "prettier": "^3.1.1", + "less": "^4.6.7", + "lint-staged": "^16.4.0", + "prettier": "^3.9.0", "querystring": "^0.2.1", - "rc-dialog": "^9.0.0", - "rc-test": "^7.1.2", - "react": "^18.2.0", - "react-dom": "^18.2.0", - "typescript": "^5.2.2" + "rc-test": "^7.1.3", + "react": "^18.3.1", + "react-dom": "^18.3.1", + "typescript": "^5.9.3" + }, + "publishConfig": { + "access": "public" } } diff --git a/tsconfig.json b/tsconfig.json index 9e18b113f..eec0a112f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,6 +11,8 @@ "@/*": ["src/*"], "@@/*": [".dumi/tmp/*"], "@rc-component/select": ["src/index.ts"] - } - } + }, + "ignoreDeprecations": "5.0" + }, + "include": [".dumirc.ts", ".fatherrc.ts", "src", "tests", "docs"] } diff --git a/vercel.json b/vercel.json index cc12e4054..5f9139ef4 100644 --- a/vercel.json +++ b/vercel.json @@ -1,3 +1,6 @@ { - "framework": "umijs" + "framework": "umijs", + "installCommand": "npm install", + "buildCommand": "npm run build", + "outputDirectory": "docs-dist" }