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/.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/workflows/codeql.yml b/.github/workflows/codeql.yml index 8598a777c..585a5e837 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@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + 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..07884617c --- /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@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + 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..50782cc0a --- /dev/null +++ b/.github/workflows/surge-preview.yml @@ -0,0 +1,45 @@ +name: Surge Preview + +on: + pull_request: + +permissions: + contents: read + pull-requests: write + checks: write + +jobs: + preview: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + 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..f8482b632 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,5 +2,5 @@ name: ✅ test on: [push, pull_request] jobs: test: - uses: react-component/rc-test/.github/workflows/test.yml@main + uses: react-component/rc-test/.github/workflows/test-utoo.yml@main secrets: inherit diff --git a/README.md b/README.md index 8c23dd44f..4ea5aeea3 100644 --- a/README.md +++ b/README.md @@ -1,195 +1,167 @@ -# @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 | Dropdown 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` | - | +| 选项 | 选项数据。 | `OptionType[]` | - | +| searchValue | 已弃用。请改用 `showSearch.searchValue`。 | string | - | +| showSearch | 启用搜索或配置搜索行为。 | boolean \| `SearchConfig` | - | +| styles | 语义化样式。 | `Partial>` | - | +| 价值 | 受控选中值。 | `ValueType` \| null | - | +| virtual | 设置为 `false` 时禁用虚拟滚动。 | boolean | true | + +### 方法 + +| 名称 | 说明 | 参数 | +| ----- | ------------------- | ---------- | +| 模糊 | 移除焦点。 | - | +| 重点 | 聚焦选择器。 | - | + +### 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 | - | +| 价值 | 选项值。 | 字符串\|数字\|无效的 | - | + +### 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 +``` + +## 发布 + +```bash +npm run prepublishOnly +``` + +包构建完成后,发布流程由 `@rc-component/np` 通过 `rc-np` 命令处理。 + +## 许可证 + +@rc-component/select 基于 [MIT](./LICENSE.md) 许可证发布。 diff --git a/package.json b/package.json index cd4592e91..60bbc1a4b 100644 --- a/package.json +++ b/package.json @@ -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" @@ -57,28 +56,28 @@ }, "devDependencies": { "@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" } } diff --git a/tsconfig.json b/tsconfig.json index 9e18b113f..bff2fed5e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,9 +8,22 @@ "skipLibCheck": true, "esModuleInterop": true, "paths": { - "@/*": ["src/*"], - "@@/*": [".dumi/tmp/*"], - "@rc-component/select": ["src/index.ts"] - } - } + "@/*": [ + "src/*" + ], + "@@/*": [ + ".dumi/tmp/*" + ], + "@rc-component/select": [ + "src/index.ts" + ] + }, + "ignoreDeprecations": "5.0" + }, + "include": [ + ".dumirc.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" }