diff --git a/.dumirc.ts b/.dumirc.ts index 01854c1..7d2614c 100644 --- a/.dumirc.ts +++ b/.dumirc.ts @@ -1,6 +1,12 @@ import { defineConfig } from 'dumi'; +const basePath = process.env.GH_PAGES ? '/checkbox/' : '/'; +const publicPath = basePath; + export default defineConfig({ + outputPath: 'docs-dist', + base: basePath, + publicPath, themeConfig: { name: 'Checkbox', }, 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 1372add..3b730ef 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,20 +1,19 @@ version: 2 updates: -- package-ecosystem: npm - directory: "/" - schedule: - interval: daily - time: "21:00" - open-pull-requests-limit: 10 - ignore: - - dependency-name: react-dom - versions: - - 17.0.1 - - 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 1bc4e70..e9fe2fd 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: "8 20 * * 1" + - cron: '8 20 * * 1' 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 index 5735e2d..36dacae 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.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/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 be4e312..16145ad 100644 --- a/.gitignore +++ b/.gitignore @@ -39,7 +39,8 @@ package-lock.json .umi-production .umi-test .docs +docs-dist pnpm-lock.yaml -bun.lockb \ No newline at end of file +bun.lockb diff --git a/.husky/pre-commit b/.husky/pre-commit index 759436f..2312dc5 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1 @@ -#!/bin/sh -. "$(dirname "$0")/_/husky.sh" - -npx --no-install lint-staged --quiet +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 0a64f69..ed95df8 100644 --- a/README.md +++ b/README.md @@ -1,112 +1,115 @@ -# rc-checkbox - ---- - -Checkbox ui component for react. - -[![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-checkbox.svg?style=flat-square -[npm-url]: http://npmjs.org/package/rc-checkbox -[travis-image]: https://img.shields.io/travis/react-component/checkbox/master?style=flat-square -[travis-url]: https://travis-ci.com/react-component/checkbox -[github-actions-image]: https://github.com/react-component/checkbox/workflows/CI/badge.svg -[github-actions-url]: https://github.com/react-component/checkbox/actions -[codecov-image]: https://img.shields.io/codecov/c/github/react-component/checkbox/master.svg?style=flat-square -[codecov-url]: https://app.codecov.io/gh/react-component/checkbox -[david-url]: https://david-dm.org/react-component/checkbox -[david-image]: https://david-dm.org/react-component/checkbox/status.svg?style=flat-square -[david-dev-url]: https://david-dm.org/react-component/checkbox?type=dev -[david-dev-image]: https://david-dm.org/react-component/checkbox/dev-status.svg?style=flat-square -[download-image]: https://img.shields.io/npm/dm/rc-checkbox.svg?style=flat-square -[download-url]: https://npmjs.org/package/rc-checkbox -[bundlephobia-url]: https://bundlephobia.com/package/rc-checkbox -[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-checkbox -[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.
☑️ A small, accessible checkbox primitive for React.
+ + +English | 简体中文
+ +## Highlights + +- Works as a controlled or uncontrolled checkbox. +- Exposes an imperative ref for focus, blur, and DOM access. +- Keeps native input attributes available while normalizing the change event. +- Ships compiled JavaScript, TypeScript definitions, and a standalone CSS asset. ## Install -[](https://npmjs.org/package/rc-checkbox) +```bash +npm install @rc-component/checkbox +``` ## Usage -```js -import checkbox from '@rc-component/checkbox'; - -export default () =>
](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 | -
|---|---|---|---|
| prefixCls | -String | -rc-checkbox | -- |
| className | -String | -'' | -additional class name of root node | -
| name | -String | -- | same with native input checkbox | -
| checked | -enum: 0,1,2 | -- | - |
| defaultChecked | -enum: 0,1,2 | -0 | -same with native input checkbox | -
| onChange | -Function(e:Event, checked:Number) | -- | called when checkbox is changed. e is native event, checked is original checked state. | -
English | 简体中文
+ +## 特性 + +- 可作为受控或非受控复选框。 +- 引入用于焦点、模糊和 DOM 访问的命令式引用。 +- 在规范化变更事件时保留可用的原生 input 属性。 +- 提供编译后的 JavaScript、TypeScript 类型定义和独立 CSS 资源。 + +## 安装 + +```bash +npm install @rc-component/checkbox +``` + +## 使用 + +```tsx +import Checkbox from '@rc-component/checkbox'; +import '@rc-component/checkbox/assets/index.css'; + +export default function App() { + return ( +