diff --git a/.dumirc.ts b/.dumirc.ts index 498e3b6..e578592 100644 --- a/.dumirc.ts +++ b/.dumirc.ts @@ -1,7 +1,7 @@ import { defineConfig } from 'dumi'; const basePath = process.env.GH_PAGES ? '/input/' : '/'; -const publicPath = process.env.GH_PAGES ? '/input/' : '/'; +const publicPath = basePath; export default defineConfig({ mfsu: false, @@ -10,7 +10,7 @@ export default defineConfig({ name: 'Input', 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 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 5f0889c..3b730ef 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,11 +1,19 @@ -# 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: "npm" # 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 + + - package-ecosystem: github-actions + directory: '/' schedule: - interval: "weekly" + 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 bc73d6d..3be35a8 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: "13 6 * * 2" + - cron: '13 6 * * 2' 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 5735e2d..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 \ 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 0000000..9503b96 --- /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 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/surge-preview.yml b/.github/workflows/surge-preview.yml new file mode 100644 index 0000000..4c2f17e --- /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 cda3eae..e155f32 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ pnpm-lock.yaml coverage/ .doc dist/ +docs-dist/ # umi .umi @@ -43,3 +44,4 @@ dist/ .dumi/tmp-production .node bun.lockb +.vercel diff --git a/.prettierignore b/.prettierignore index e1497d5..4b2b6ce 100644 --- a/.prettierignore +++ b/.prettierignore @@ -10,3 +10,13 @@ public _site .umi .doc +coverage +docs-dist +dist +.dumi/tmp +.dumi/tmp-production +.vercel +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 036b692..7a817b6 100644 --- a/README.md +++ b/README.md @@ -1,148 +1,151 @@ -# @rc-component/input ⌨️ - -[![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]: http://img.shields.io/npm/v/@rc-component/input.svg?style=flat-square -[npm-url]: http://npmjs.org/package/@rc-component/input -[travis-image]: https://img.shields.io/travis/react-component/input/master?style=flat-square -[travis-url]: https://travis-ci.com/react-component/input -[github-actions-image]: https://github.com/react-component/input/actions/workflows/main.yml/badge.svg -[github-actions-url]: https://github.com/react-component/input/actions/workflows/main.yml -[codecov-image]: https://img.shields.io/codecov/c/github/react-component/input/master.svg?style=flat-square -[codecov-url]: https://app.codecov.io/gh/react-component/input -[david-url]: https://david-dm.org/react-component/input -[david-image]: https://david-dm.org/react-component/input/status.svg?style=flat-square -[david-dev-url]: https://david-dm.org/react-component/input?type=dev -[david-dev-image]: https://david-dm.org/react-component/input/dev-status.svg?style=flat-square -[download-image]: https://img.shields.io/npm/dm/@rc-component/input.svg?style=flat-square -[download-url]: https://npmjs.org/package/@rc-component/input -[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/input -[bundlephobia-image]: https://img.shields.io/bundlephobia/minzip/@rc-component/input?style=flat-square -[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.
📦 ⌨️ Low-level React input primitives for building polished text fields and textareas.
+ + +English | 简体中文
+ +## Highlights + +- Composable `Input`, `TextArea`, and `BaseInput` primitives. +- Affix, addon, clear icon, prefix, suffix, and character count support. +- Autosizing textarea with resize callbacks and imperative refs. +- TypeScript definitions and semantic `classNames` / `styles` slots. +- Used by Ant Design as the shared input foundation. ## Install -[](https://npmjs.org/package/@rc-component/input) +```bash +npm install @rc-component/input +``` ## Usage -```js +```tsx | pure import Input from '@rc-component/input'; -import { render } from 'react-dom'; -render(, mountNode); +export default () => ; ``` -```js +```tsx | pure import { TextArea } from '@rc-component/input'; -import { render } from 'react-dom'; -render(, mountNode); +export default () => ; ``` -## API +## Examples -| Property | Type | Default | Description | -| --------------------- | ------------------------------------------------------------------------------------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | -| prefixCls | string | rc-input | | -| className | string | '' | additional class name of input | -| style | React.CSSProperties | | style properties of input | -| affixWrapperClassName | string | - | className with '@rc-component/input-affix-wrapper' | -| groupClassName | string | - | className with '@rc-component/input-group-wrapper' | -| wrapperClassName | string | - | className with '@rc-component/input-wrapper' | -| addonAfter | ReactNode | - | The label text displayed after (on the right side of) the input field | -| addonBefore | ReactNode | - | The label text displayed before (on the left side of) the input field | -| allowClear | boolean | { clearIcon: ReactNode } | false | If allow to remove input content with clear icon | -| bordered | boolean | true | Whether has border style | -| defaultValue | string | - | The initial input content | -| disabled | boolean | false | Whether the input is disabled | -| id | string | - | The ID for input | -| maxLength | number | - | The max length | -| showCount | boolean | { formatter: ({ value: string, count: number, maxLength?: number }) => ReactNode } | false | Whether show text count | -| prefix | ReactNode | - | The prefix icon for the Input | -| suffix | ReactNode | - | The suffix icon for the Input | -| type | string | `text` | The type of input, see: [MDN](https://developer.mozilla.org/docs/Web/HTML/Element/input#Form_%3Cinput%3E_types) (use the named `TextArea` export instead of `type="textarea"`) | -| value | string | - | The input content value | -| onChange | function(e) | - | Callback when user input | -| onPressEnter | function(e) | - | The callback function that is triggered when Enter key is pressed | - -## TextArea - -`rc-textarea` has been migrated into `@rc-component/input`. Use the named `TextArea` export for all textarea-related features. - -```js -import { TextArea } from '@rc-component/input'; +Run the local dumi site: -; -; +```bash +npm install +npm start ``` -| Property | Type | Default | Description | -| ------------ | --------------------------- | ----------- | ---------------------------------------------------------------------------------------------- | -| prefixCls | string | rc-textarea | | -| className | string | '' | additional class name of textarea | -| style | React.CSSProperties | - | style properties of textarea | -| autoSize | boolean \| object | - | Height autosize feature, can be set to `true\|false` or an object `{ minRows: 2, maxRows: 6 }` | -| allowClear | boolean \| { clearIcon } | false | If allow to remove textarea content with clear icon | -| showCount | boolean \| { formatter } | false | Whether show text count | -| count | CountConfig | - | Custom count strategy / max / exceed formatter | -| onPressEnter | function(e) | - | The callback function that is triggered when Enter key is pressed | -| onResize | function({ width, height }) | - | The callback function that is triggered when resize | - -## inputRef - -```tsx | pure -const inputRef = useRef(null); - -useEffect(() => { - inputRef.current.focus(); // the input will get focus - inputRef.current.blur(); // the input will lose focus - console.log(inputRef.current.input); // The origin input element -}, []); -// .... -; -``` +Then open `http://localhost:8000`. -| Property | Type | Description | -| -------- | --------------------------------------- | --------------------------------- | -| focus | `(options?: InputFocusOptions) => void` | The input get focus when called | -| blur | `() => void` | The input loses focus when called | -| input | `HTMLInputElement \| null` | The origin input element | +## API -## textareaRef +### Input + +| Property | Type | Default | Description | +| ------------ | ---------------------------------------------------------- | ---------- | --------------------------------------------------------------- | +| addonAfter | `ReactNode` | - | Element displayed after the input. | +| addonBefore | `ReactNode` | - | Element displayed before the input. | +| allowClear | `boolean \| { disabled?: boolean; clearIcon?: ReactNode }` | `false` | Show a clear button for the current value. | +| className | `string` | - | Class name for the input element. | +| classNames | `InputProps['classNames']` | - | Semantic class names for input slots. | +| count | `CountConfig` | - | Custom count strategy, limit, visibility, and exceed formatter. | +| defaultValue | `string \| number \| readonly string[] \| bigint` | - | Initial input value. | +| disabled | `boolean` | `false` | Disable the input. | +| htmlSize | `number` | - | Native input `size` attribute. | +| maxLength | `number` | - | Native input `maxLength` attribute. | +| prefix | `ReactNode` | - | Prefix content inside the input wrapper. | +| prefixCls | `string` | `rc-input` | Class name prefix. | +| showCount | `boolean \| { formatter: ShowCountFormatter }` | `false` | Show character count. Prefer `count.show` for new code. | +| styles | `InputProps['styles']` | - | Semantic styles for input slots. | +| suffix | `ReactNode` | - | Suffix content inside the input wrapper. | +| type | `InputProps['type']` | `text` | Native input type. Use `TextArea` for textarea behavior. | +| value | `string \| number \| readonly string[] \| bigint` | - | Controlled input value. | +| onChange | `React.ChangeEventHandler Ant Design 生态的一部分。
📦 ⌨️ React 输入框基础组件,支持前后缀、清除按钮、计数和组合输入。
+ + +English | 简体中文
+ +## 特性 + +- 提供可组合的 `Input`、`TextArea` 和 `BaseInput` 基础组件。 +- 支持前后缀、附加内容、清除图标和字符计数。 +- `TextArea` 支持自适应高度、尺寸变化回调和命令式 ref。 +- 提供 TypeScript 类型定义和语义化 `classNames` / `styles` 插槽。 +- 被 Ant Design 用作共享的 input 基础能力。 + +## 安装 + +```bash +npm install @rc-component/input +``` + +## 使用 + +```tsx | pure +import Input from '@rc-component/input'; + +export default () => ; +``` + +```tsx | pure +import { TextArea } from '@rc-component/input'; + +export default () => ; +``` + +## 示例 + +运行本地 dumi 站点: + +```bash +npm install +npm start +``` + +然后打开 `http://localhost:8000`。 + +## API + +### Input + +| 参数 | 类型 | 默认值 | 说明 | +| ------------ | ---------------------------------------------------------- | ---------- | ---------------------------------------------------- | +| addonAfter | `ReactNode` | - | 输入后显示的元素。 | +| addonBefore | `ReactNode` | - | 输入之前显示的元素。 | +| allowClear | `boolean \| { disabled?: boolean; clearIcon?: ReactNode }` | `false` | 显示当前值的清除按钮。 | +| className | `string` | - | 输入元素的 className。 | +| classNames | `InputProps['classNames']` | - | 输入槽的语义 className。 | +| count | `CountConfig` | - | 自定义计数策略、限制、可见性和超出格式化程序。 | +| defaultValue | `string \| number \| readonly string[] \| bigint` | - | 初始输入值。 | +| disabled | `boolean` | `false` | 禁用输入。 | +| htmlSize | `number` | - | 原生 input `size` 属性。 | +| maxLength | `number` | - | 原生 input `maxLength` 属性。 | +| prefix | `ReactNode` | - | 输入包装器内的前缀内容。 | +| prefixCls | `string` | `rc-input` | className 前缀。 | +| showCount | `boolean \| { formatter: ShowCountFormatter }` | `false` | 显示字符数。新代码首选 `count.show`。 | +| styles | `InputProps['styles']` | - | 输入槽的语义样式。 | +| suffix | `ReactNode` | - | 输入包装器内的后缀内容。 | +| type | `InputProps['type']` | `text` | 原生 input 类型。需要文本域行为时请使用 `TextArea`。 | +| value | `string \| number \| readonly string[] \| bigint` | - | 受控输入值。 | +| onChange | `React.ChangeEventHandler