From 4331968dd2109b9d672ef7ec11df1a8dbb0efa8e Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 26 Jun 2026 16:25:49 +0800 Subject: [PATCH 01/34] chore: standardize repository config --- .dumirc.ts | 6 +- .github/FUNDING.yml | 2 + .github/workflows/codeql.yml | 43 +++++++ .github/workflows/main.yml | 6 - .github/workflows/preview.yml | 20 ---- .github/workflows/react-component-ci.yml | 8 ++ .github/workflows/react-doctor.yml | 27 +++++ .github/workflows/surge-preview.yml | 39 +++++++ .gitignore | 2 + README.md | 137 ++++++++++++++--------- docs/demo/basic.tsx | 2 +- docs/demo/controlled.tsx | 6 +- docs/demo/custom-render.tsx | 4 +- docs/demo/dynamic.tsx | 4 +- docs/demo/html-title.tsx | 4 +- docs/demo/name.tsx | 2 +- docs/demo/refs.tsx | 4 +- docs/demo/rtl.tsx | 4 +- docs/index.md | 2 +- package.json | 8 +- tsconfig.json | 5 +- vercel.json | 6 + 22 files changed, 237 insertions(+), 104 deletions(-) create mode 100644 .github/FUNDING.yml create mode 100644 .github/workflows/codeql.yml delete mode 100644 .github/workflows/main.yml delete mode 100644 .github/workflows/preview.yml create mode 100644 .github/workflows/react-component-ci.yml create mode 100644 .github/workflows/react-doctor.yml create mode 100644 .github/workflows/surge-preview.yml create mode 100644 vercel.json diff --git a/.dumirc.ts b/.dumirc.ts index 8b56eeb..9ebb64f 100644 --- a/.dumirc.ts +++ b/.dumirc.ts @@ -10,11 +10,13 @@ export default defineConfig({ name: 'Segmented', logo: 'https://avatars0.githubusercontent.com/u/9441414?s=200&v=4', }, - outputPath: '.doc', + outputPath: 'docs-dist', exportStatic: {}, base: basePath, publicPath, alias: { - 'rc-segmented': path.resolve(__dirname, 'src/index.tsx'), + '@rc-component/segmented$': path.resolve(__dirname, 'src/index.tsx'), + '@rc-component/segmented/es': path.resolve(__dirname, 'src'), + '@rc-component/segmented/assets': path.resolve(__dirname, 'assets'), }, }); 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/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..abe88da --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,43 @@ +name: 'CodeQL' + +on: + push: + branches: ['master'] + pull_request: + branches: ['master'] + schedule: + - cron: '31 3 * * 0' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [javascript] + + steps: + - name: Checkout + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + with: + persist-credentials: false + + - name: Initialize CodeQL + uses: github/codeql-action/init@8aad20d150bbac5944a9f9d289da16a4b0d87c1e + with: + languages: ${{ matrix.language }} + queries: +security-and-quality + + - name: Autobuild + uses: github/codeql-action/autobuild@8aad20d150bbac5944a9f9d289da16a4b0d87c1e + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e + with: + category: '/language:${{ matrix.language }}' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index f860ff1..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 diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml deleted file mode 100644 index d02059a..0000000 --- a/.github/workflows/preview.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: 🔂 Surge PR Preview - -on: [pull_request] - -jobs: - preview: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: afc163/surge-preview@v1 - id: preview_step - with: - surge_token: ${{ secrets.SURGE_TOKEN }} - github_token: ${{ secrets.GITHUB_TOKEN }} - dist: .doc - build: | - npm install - npm run docs:build - - name: Get the preview_url - run: echo "url => ${{ steps.preview_step.outputs.preview_url }}" 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..f68281c --- /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@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 0000000..1b29a17 --- /dev/null +++ b/.github/workflows/surge-preview.yml @@ -0,0 +1,39 @@ +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 + statuses: write + +jobs: + preview: + runs-on: ubuntu-latest + env: + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} + PREVIEW: true + steps: + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + with: + persist-credentials: false + - uses: afc163/surge-preview@bf90a5a86111f6311ca42f0a5a0f80fb0fb03cec + if: ${{ env.SURGE_TOKEN != '' }} + with: + surge_token: ${{ env.SURGE_TOKEN }} + github_token: ${{ secrets.GITHUB_TOKEN }} + dist: docs-dist + failOnError: true + setCommitStatus: true + build: | + npm install + npm run build + - name: Skip Surge preview + if: ${{ env.SURGE_TOKEN == '' }} + run: echo "SURGE_TOKEN is not configured; skip Surge preview." diff --git a/.gitignore b/.gitignore index e65506a..14aa70a 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,8 @@ package-lock.json pnpm-lock.yaml coverage/ .doc +docs-dist +.vercel # umi .umi diff --git a/README.md b/README.md index 6972128..05c0c5e 100644 --- a/README.md +++ b/README.md @@ -1,79 +1,106 @@ -# @rc-component/segmented - -[![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![bundle size][bundlephobia-image]][bundlephobia-url] - -[npm-image]: http://img.shields.io/npm/v/@rc-component/segmented.svg?style=flat-square -[npm-url]: http://npmjs.org/package/@rc-component/segmented -[github-actions-image]: https://github.com/react-component/segmented/actions/workflows/main.yml/badge.svg -[github-actions-url]: https://github.com/react-component/segmented/actions/workflows/main.yml -[codecov-image]: https://codecov.io/gh/react-component/segmented/branch/master/graph/badge.svg -[codecov-url]: https://codecov.io/gh/react-component/segmented/branch/master -[download-image]: https://img.shields.io/npm/dm/@rc-component/segmented.svg?style=flat-square -[download-url]: https://npmjs.org/package/@rc-component/segmented -[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/segmented -[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/segmented - -React Segmented Control. - -![](https://gw.alipayobjects.com/mdn/rms_50855f/afts/img/A*bmGGQpnWs0oAAAAAAAAAAAAAARQnAQ) - -## Live Demo - -https://react-component.github.io/segmented/ +
+

@rc-component/segmented

+

🧩 React segmented control for switching between compact options.

+

+ Ant Design +

+

Part of the Ant Design ecosystem.

+ +

+ npm version + npm downloads + CI + Codecov + bundle size + dumi +

+
+ +## Highlights + +- Supports string, number, and labeled option records. +- Provides controlled and uncontrolled value flows. +- Includes keyboard navigation, RTL, vertical layout, and disabled options. +- Exposes semantic `classNames` and `styles` slots for item and label customization. ## Install -[![@rc-component/segmented](https://nodei.co/npm/@rc-component/segmented.png)](https://npmjs.org/package/@rc-component/segmented) +```bash +npm install @rc-component/segmented +``` ## Usage -```js +```tsx pure import Segmented from '@rc-component/segmented'; -import '@rc-component/segmented/assets/index.css'; // import '@rc-component/segmented/assets/index.less'; -import { render } from 'react-dom'; +import '@rc-component/segmented/assets/index.css'; -render( +export default () => ( handleValueChange(value)} - />, - mountNode, + options={['Daily', 'Weekly', 'Monthly']} + defaultValue="Weekly" + onChange={(value) => { + console.log(value); + }} + /> ); ``` +Online preview: https://segmented.react-component.vercel.app/ + ## API -Please note that **onChange** API - changed on v2.0.0+ - -| Property | Type | Default | Description | -| --------- | --------- | --------- | --------- | -| prefixCls | string | `rc-segmented` | prefixCls of this component | -| className | string | '' | additional class name of segmented | -| style | React.CSSProperties | | style properties of segmented | -| options | Array | [] | options for choices | -| value | string \| number | | value of segmented | -| defaultValue | string \| number | | defaultValue of segmented | -| value | string \| number | | currently selected value of segmented | -| onChange | (value: string \| number) => void | | defaultValue of segmented | -| disabled | boolean | false | disabled status of segmented | - -### SegmentedOption - -| Property | Type | Default | Description | -| --------- | --------- | --------- | --------- | -| label | ReactNode | | label of segmented option | -| value | string \| number | | value of segmented option | -| className | string | '' | additional class name of segmented option | -| disabled | boolean | false | disabled status of segmented option | +### Segmented + +| Name | Type | Default | Description | +| --- | --- | --- | --- | +| `className` | string | `''` | Additional class name. | +| `classNames` | Partial> | - | Semantic class names for internal slots. | +| `defaultValue` | string \| number | first option value | Initial selected value. | +| `direction` | `'ltr'` \| `'rtl'` | - | Layout direction. | +| `disabled` | boolean | false | Disable all options. | +| `itemRender` | `(node: ReactNode, info: { item: SegmentedLabeledOption }) => ReactNode` | identity | Custom option item renderer. | +| `motionName` | string | `'thumb-motion'` | Motion class name for the active thumb. | +| `name` | string | - | Radio group name. | +| `onChange` | `(value: string \| number) => void` | - | Triggered when the selected value changes. | +| `options` | Array | [] | Available options. | +| `prefixCls` | string | `'rc-segmented'` | Prefix class name. | +| `style` | React.CSSProperties | - | Root style. | +| `styles` | Partial> | - | Semantic styles for internal slots. | +| `value` | string \| number | - | Controlled selected value. | +| `vertical` | boolean | false | Render options vertically. | + +Additional valid `div` props are passed to the root element. + +### SegmentedLabeledOption + +| Name | Type | Default | Description | +| --- | --- | --- | --- | +| `className` | string | - | Option class name. | +| `disabled` | boolean | false | Disable this option. | +| `label` | ReactNode | - | Displayed option content. | +| `title` | string | derived from label | Native title for the label. | +| `value` | string \| number | - | Option value. | ## Development -``` +```bash npm install npm start +npm test +npm run tsc +npm run compile +npm run build +``` + +## Release + +```bash +npm run prepublishOnly ``` +`prepublishOnly` builds the package with Father and publishes through `rc-np`. Run `npm run gh-pages` to deploy the dumi site. + ## License @rc-component/segmented is released under the MIT license. diff --git a/docs/demo/basic.tsx b/docs/demo/basic.tsx index db4d63d..712276d 100644 --- a/docs/demo/basic.tsx +++ b/docs/demo/basic.tsx @@ -1,4 +1,4 @@ -import Segmented from 'rc-segmented'; +import Segmented from '@rc-component/segmented'; import React from 'react'; import '../../assets/style.less'; diff --git a/docs/demo/controlled.tsx b/docs/demo/controlled.tsx index 2546819..b3890a2 100644 --- a/docs/demo/controlled.tsx +++ b/docs/demo/controlled.tsx @@ -1,7 +1,7 @@ -import '../../assets/style.less'; +import type { SegmentedValue } from '@rc-component/segmented'; +import Segmented from '@rc-component/segmented'; import React from 'react'; -import Segmented from 'rc-segmented'; -import type { SegmentedValue } from 'rc-segmented'; +import '../../assets/style.less'; export default class Demo extends React.Component< unknown, diff --git a/docs/demo/custom-render.tsx b/docs/demo/custom-render.tsx index fd39b23..eb41dcb 100644 --- a/docs/demo/custom-render.tsx +++ b/docs/demo/custom-render.tsx @@ -1,6 +1,6 @@ -import '../../assets/style.less'; +import Segmented from '@rc-component/segmented'; import * as React from 'react'; -import Segmented from 'rc-segmented'; +import '../../assets/style.less'; const options = [ { diff --git a/docs/demo/dynamic.tsx b/docs/demo/dynamic.tsx index c350d9f..3cfe13c 100644 --- a/docs/demo/dynamic.tsx +++ b/docs/demo/dynamic.tsx @@ -1,6 +1,6 @@ -import '../../assets/style.less'; +import Segmented from '@rc-component/segmented'; import * as React from 'react'; -import Segmented from 'rc-segmented'; +import '../../assets/style.less'; const defaultOptions1 = ['iOS', 'Android', 'Web']; const defaultOptions2 = [ diff --git a/docs/demo/html-title.tsx b/docs/demo/html-title.tsx index 394141d..6feb647 100644 --- a/docs/demo/html-title.tsx +++ b/docs/demo/html-title.tsx @@ -1,6 +1,6 @@ -import '../../assets/style.less'; +import Segmented from '@rc-component/segmented'; import React from 'react'; -import Segmented from 'rc-segmented'; +import '../../assets/style.less'; export default function App() { return ( diff --git a/docs/demo/name.tsx b/docs/demo/name.tsx index d62fe30..260be39 100644 --- a/docs/demo/name.tsx +++ b/docs/demo/name.tsx @@ -1,4 +1,4 @@ -import Segmented from 'rc-segmented'; +import Segmented from '@rc-component/segmented'; import React from 'react'; import '../../assets/style.less'; diff --git a/docs/demo/refs.tsx b/docs/demo/refs.tsx index 5a7e345..45e5e22 100644 --- a/docs/demo/refs.tsx +++ b/docs/demo/refs.tsx @@ -1,6 +1,6 @@ -import '../../assets/style.less'; +import Segmented from '@rc-component/segmented'; import React from 'react'; -import Segmented from 'rc-segmented'; +import '../../assets/style.less'; class ClassComponentWithStringRef extends React.Component { componentDidMount() { diff --git a/docs/demo/rtl.tsx b/docs/demo/rtl.tsx index 91c3761..12fd8b4 100644 --- a/docs/demo/rtl.tsx +++ b/docs/demo/rtl.tsx @@ -1,6 +1,6 @@ -import '../../assets/style.less'; +import Segmented from '@rc-component/segmented'; import React, { useState } from 'react'; -import Segmented from 'rc-segmented'; +import '../../assets/style.less'; export default function App() { const [direction, setDirection] = useState<'rtl' | 'ltr'>('rtl'); diff --git a/docs/index.md b/docs/index.md index e718ed5..afdba56 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,6 +1,6 @@ --- hero: - title: rc-segmented + title: '@rc-component/segmented' description: React segmented controls used in ant.design --- diff --git a/package.json b/package.json index 688930d..c41d099 100644 --- a/package.json +++ b/package.json @@ -32,14 +32,16 @@ "license": "MIT", "scripts": { "start": "dumi dev", + "build": "npm run docs:build", + "tsc": "tsc --noEmit", "type:check": "tsc --noEmit", "docs:build": "dumi build", - "docs:deploy": "gh-pages -d .doc", + "docs:deploy": "gh-pages -d docs-dist", "compile": "father build && lessc assets/index.less assets/index.css", "gh-pages": "GH_PAGES=1 npm run docs:build && npm run docs:deploy", "prepublishOnly": "npm run compile && rc-np", "lint": "eslint src/ --ext .ts,.tsx,.jsx,.js,.md", - "prettier": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\"", + "prettier": "prettier --write --ignore-unknown .", "pretty-quick": "pretty-quick", "test": "jest", "coverage": "jest --coverage", @@ -66,7 +68,7 @@ "dumi": "^2.1.2", "eslint": "^7.0.0", "father": "^4.1.1", - "gh-pages": "^3.1.0", + "gh-pages": "^6.1.0", "husky": "^8.0.0", "jest": "^29.3.1", "jest-environment-jsdom": "^29.3.1", diff --git a/tsconfig.json b/tsconfig.json index 1cbc5ac..cbb0ca4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,8 +16,9 @@ "paths": { "@/*": ["src/*"], "@@/*": [".dumi/tmp/*"], - "rc-segmented": ["src/index.tsx"] + "@rc-component/segmented": ["src/index.tsx"] } }, - "include": [".dumi/**/*", ".dumirc.ts", "src", "tests", "docs/demo"] + "include": [".dumirc.ts", "src", "tests", "docs/demo"], + "exclude": ["docs-dist", "lib", "es"] } diff --git a/vercel.json b/vercel.json new file mode 100644 index 0000000..5f9139e --- /dev/null +++ b/vercel.json @@ -0,0 +1,6 @@ +{ + "framework": "umijs", + "installCommand": "npm install", + "buildCommand": "npm run build", + "outputDirectory": "docs-dist" +} From 771799ea718c6a9c035080098de7cdc9bcceecdc Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 26 Jun 2026 16:30:19 +0800 Subject: [PATCH 02/34] fix: make preview build generate styles --- .github/workflows/codeql.yml | 43 ------------------------------------ package.json | 4 ++-- 2 files changed, 2 insertions(+), 45 deletions(-) delete mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml deleted file mode 100644 index abe88da..0000000 --- a/.github/workflows/codeql.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: 'CodeQL' - -on: - push: - branches: ['master'] - pull_request: - branches: ['master'] - schedule: - - cron: '31 3 * * 0' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [javascript] - - steps: - - name: Checkout - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 - with: - persist-credentials: false - - - name: Initialize CodeQL - uses: github/codeql-action/init@8aad20d150bbac5944a9f9d289da16a4b0d87c1e - with: - languages: ${{ matrix.language }} - queries: +security-and-quality - - - name: Autobuild - uses: github/codeql-action/autobuild@8aad20d150bbac5944a9f9d289da16a4b0d87c1e - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@8aad20d150bbac5944a9f9d289da16a4b0d87c1e - with: - category: '/language:${{ matrix.language }}' diff --git a/package.json b/package.json index c41d099..658d2f3 100644 --- a/package.json +++ b/package.json @@ -32,13 +32,13 @@ "license": "MIT", "scripts": { "start": "dumi dev", - "build": "npm run docs:build", + "build": "npm run compile && npm run docs:build", "tsc": "tsc --noEmit", "type:check": "tsc --noEmit", "docs:build": "dumi build", "docs:deploy": "gh-pages -d docs-dist", "compile": "father build && lessc assets/index.less assets/index.css", - "gh-pages": "GH_PAGES=1 npm run docs:build && npm run docs:deploy", + "gh-pages": "GH_PAGES=1 npm run compile && npm run docs:build && npm run docs:deploy", "prepublishOnly": "npm run compile && rc-np", "lint": "eslint src/ --ext .ts,.tsx,.jsx,.js,.md", "prettier": "prettier --write --ignore-unknown .", From bed5b588b098aa930d9508f59a72c486f0b2455a Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 26 Jun 2026 16:41:00 +0800 Subject: [PATCH 03/34] fix: address review feedback --- .github/workflows/react-component-ci.yml | 3 ++- README.md | 2 +- tsconfig.json | 5 ++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/react-component-ci.yml b/.github/workflows/react-component-ci.yml index 9503b96..36dacae 100644 --- a/.github/workflows/react-component-ci.yml +++ b/.github/workflows/react-component-ci.yml @@ -5,4 +5,5 @@ permissions: jobs: test: uses: react-component/rc-test/.github/workflows/test-utoo.yml@main - secrets: inherit + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} diff --git a/README.md b/README.md index 05c0c5e..ce3c627 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Online preview: https://segmented.react-component.vercel.app/ | `motionName` | string | `'thumb-motion'` | Motion class name for the active thumb. | | `name` | string | - | Radio group name. | | `onChange` | `(value: string \| number) => void` | - | Triggered when the selected value changes. | -| `options` | Array | [] | Available options. | +| `options` | Array | - | Available options. Required. | | `prefixCls` | string | `'rc-segmented'` | Prefix class name. | | `style` | React.CSSProperties | - | Root style. | | `styles` | Partial> | - | Semantic styles for internal slots. | diff --git a/tsconfig.json b/tsconfig.json index cbb0ca4..b7f0d77 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,7 +16,10 @@ "paths": { "@/*": ["src/*"], "@@/*": [".dumi/tmp/*"], - "@rc-component/segmented": ["src/index.tsx"] + "@rc-component/segmented": ["src/index.tsx"], + "@rc-component/segmented/es": ["src"], + "@rc-component/segmented/es/*": ["src/*"], + "@rc-component/segmented/assets/*": ["assets/*"] } }, "include": [".dumirc.ts", "src", "tests", "docs/demo"], From 4f5736b553b962b614858072a1328e499e2ba2ec Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 26 Jun 2026 16:44:38 +0800 Subject: [PATCH 04/34] fix: keep rc-test secrets inheritance --- .github/workflows/react-component-ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/react-component-ci.yml b/.github/workflows/react-component-ci.yml index 36dacae..9503b96 100644 --- a/.github/workflows/react-component-ci.yml +++ b/.github/workflows/react-component-ci.yml @@ -5,5 +5,4 @@ permissions: jobs: test: uses: react-component/rc-test/.github/workflows/test-utoo.yml@main - secrets: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + secrets: inherit From fbeb616c75142ed4443bd6edb311e2543869f52e Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 26 Jun 2026 16:46:36 +0800 Subject: [PATCH 05/34] fix: align test workflow triggers --- .github/workflows/react-component-ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/react-component-ci.yml b/.github/workflows/react-component-ci.yml index 9503b96..1ed6420 100644 --- a/.github/workflows/react-component-ci.yml +++ b/.github/workflows/react-component-ci.yml @@ -1,5 +1,9 @@ name: ✅ test -on: [push, pull_request] +on: + push: + branches: [master] + pull_request: + branches: [master] permissions: contents: read jobs: From 7336b1636c1cfb413f4f7ccf15ff0ba899983a1b Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 01:27:31 +0800 Subject: [PATCH 06/34] chore: address AI review feedback --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 658d2f3..d0c6dca 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "docs:build": "dumi build", "docs:deploy": "gh-pages -d docs-dist", "compile": "father build && lessc assets/index.less assets/index.css", - "gh-pages": "GH_PAGES=1 npm run compile && npm run docs:build && npm run docs:deploy", + "gh-pages": "npm run compile && cross-env GH_PAGES=1 npm run docs:build && npm run docs:deploy", "prepublishOnly": "npm run compile && rc-np", "lint": "eslint src/ --ext .ts,.tsx,.jsx,.js,.md", "prettier": "prettier --write --ignore-unknown .", @@ -65,6 +65,7 @@ "@types/react-dom": "^18.3.1", "@umijs/fabric": "^3.0.0", "@umijs/test": "^4.0.36", + "cross-env": "^7.0.0", "dumi": "^2.1.2", "eslint": "^7.0.0", "father": "^4.1.1", From 9038793d474ce34ca804e90e577d481a4f6e3fec Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 01:56:49 +0800 Subject: [PATCH 07/34] docs: standardize README release details --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ce3c627..16593ee 100644 --- a/README.md +++ b/README.md @@ -99,8 +99,8 @@ npm run build npm run prepublishOnly ``` -`prepublishOnly` builds the package with Father and publishes through `rc-np`. Run `npm run gh-pages` to deploy the dumi site. +The release flow is handled by `@rc-component/np` through the `rc-np` command after the package build. ## License -@rc-component/segmented is released under the MIT license. +@rc-component/segmented is released under the [MIT](./LICENSE.md) license. From fb6afc22eba51379affb7a38ce3522b2eb573b50 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 02:13:58 +0800 Subject: [PATCH 08/34] ci: make surge preview non-blocking --- .github/workflows/surge-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml index 1b29a17..ad8683d 100644 --- a/.github/workflows/surge-preview.yml +++ b/.github/workflows/surge-preview.yml @@ -29,7 +29,7 @@ jobs: surge_token: ${{ env.SURGE_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }} dist: docs-dist - failOnError: true + failOnError: false setCommitStatus: true build: | npm install From a491ac0e52bb81fc3bbd243a927e87bec342c7eb Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 02:25:42 +0800 Subject: [PATCH 09/34] ci: keep surge preview as fallback --- .github/workflows/surge-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml index ad8683d..70768bf 100644 --- a/.github/workflows/surge-preview.yml +++ b/.github/workflows/surge-preview.yml @@ -30,7 +30,7 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} dist: docs-dist failOnError: false - setCommitStatus: true + setCommitStatus: false build: | npm install npm run build From 941413f5677d5270435c65778eb22323119dcd0f Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 13:04:02 +0800 Subject: [PATCH 10/34] docs: refine README usage and ecosystem note --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 16593ee..7c8dbda 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,7 @@

@rc-component/segmented

+

Part of the Ant Design ecosystem.

🧩 React segmented control for switching between compact options.

-

- Ant Design -

-

Part of the Ant Design ecosystem.

npm version @@ -16,6 +13,7 @@

+ ## Highlights - Supports string, number, and labeled option records. From 75577f280f7c92faa0c67f2bd04d85a5128ec7da Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 13:22:17 +0800 Subject: [PATCH 11/34] ci: isolate surge preview token --- .github/workflows/surge-preview.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml index 70768bf..faf6b8b 100644 --- a/.github/workflows/surge-preview.yml +++ b/.github/workflows/surge-preview.yml @@ -17,23 +17,26 @@ jobs: preview: runs-on: ubuntu-latest env: - SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} PREVIEW: true steps: - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 with: persist-credentials: false + - name: Build preview + if: ${{ secrets.SURGE_TOKEN != '' }} + run: | + npm install + npm run build - uses: afc163/surge-preview@bf90a5a86111f6311ca42f0a5a0f80fb0fb03cec - if: ${{ env.SURGE_TOKEN != '' }} + if: ${{ secrets.SURGE_TOKEN != '' }} + env: + SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} with: surge_token: ${{ env.SURGE_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }} dist: docs-dist failOnError: false setCommitStatus: false - build: | - npm install - npm run build - name: Skip Surge preview - if: ${{ env.SURGE_TOKEN == '' }} + if: ${{ secrets.SURGE_TOKEN == '' }} run: echo "SURGE_TOKEN is not configured; skip Surge preview." From 8252c5b2255a447cb62a8bdde0242693fdf4f185 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 22:20:04 +0800 Subject: [PATCH 12/34] docs: add Chinese README --- README.md | 2 + README.zh-CN.md | 106 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 README.zh-CN.md diff --git a/README.md b/README.md index 7c8dbda..cd47f08 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@

+

English | 简体中文

+ ## Highlights diff --git a/README.zh-CN.md b/README.zh-CN.md new file mode 100644 index 0000000..eacd829 --- /dev/null +++ b/README.zh-CN.md @@ -0,0 +1,106 @@ +
+

@rc-component/segmented

+

Ant Design 生态的一部分。

+

🔘 React 分段控制器组件。

+ +

+ npm version + npm downloads + CI + Codecov + bundle size + dumi +

+
+ +

English | 简体中文

+ + +## 特性 + +- 支持 string, number, and labeled option records. +- 提供 controlled and uncontrolled value flows. +- Includes keyboard navigation, RTL, vertical layout, and disabled options. +- 暴露 semantic `classNames` and `styles` slots for item and label customization. + +## 安装 + +```bash +npm install @rc-component/segmented +``` + +## 使用 + +```tsx pure +import Segmented from '@rc-component/segmented'; +import '@rc-component/segmented/assets/index.css'; + +export default () => ( + { + console.log(value); + }} + /> +); +``` + +Online preview: https://segmented.react-component.vercel.app/ + +## API + +### Segmented + +| 名称 | 类型 | 默认值 | 说明 | +| --- | --- | --- | --- | +| `className` | string | `''` | Additional class name. | +| `classNames` | Partial> | - | Semantic class names for internal slots. | +| `defaultValue` | string \| number | first option value | Initial selected value. | +| `direction` | `'ltr'` \| `'rtl'` | - | Layout direction. | +| `disabled` | boolean | false | Disable all options. | +| `itemRender` | `(node: ReactNode, info: { item: SegmentedLabeledOption }) => ReactNode` | identity | Custom option item renderer. | +| `motionName` | string | `'thumb-motion'` | Motion class name for the active thumb. | +| `name` | string | - | Radio group name. | +| `onChange` | `(value: string \| number) => void` | - | Triggered when the selected value changes. | +| `options` | Array | - | Available options. Required. | +| `prefixCls` | string | `'rc-segmented'` | Prefix class name. | +| `style` | React.CSSProperties | - | Root style. | +| `styles` | Partial> | - | Semantic styles for internal slots. | +| `value` | string \| number | - | Controlled selected value. | +| `vertical` | boolean | false | Render options vertically. | + +Additional valid `div` props are passed to the root element. + +### SegmentedLabeledOption + +| 名称 | 类型 | 默认值 | 说明 | +| --- | --- | --- | --- | +| `className` | string | - | Option class name. | +| `disabled` | boolean | false | Disable this option. | +| `label` | ReactNode | - | Displayed option content. | +| `title` | string | derived from label | Native title for the label. | +| `value` | string \| number | - | Option value. | + +## 本地开发 + +```bash +npm install +npm start +npm test +npm run tsc +npm run compile +npm run build +``` + +## 发布 + +```bash +npm run prepublishOnly +``` + +The release flow is handled by `@rc-component/np` through the `rc-np` command after the package build. + +## 许可证 + +@rc-component/segmented is released under the [MIT](./LICENSE.md) license. From ba9acc91b829620746b475707ba67e66cd4aa400 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 22:34:52 +0800 Subject: [PATCH 13/34] docs: add Ant Design logo to README --- README.md | 1 + README.zh-CN.md | 1 + 2 files changed, 2 insertions(+) diff --git a/README.md b/README.md index cd47f08..67f2169 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@

@rc-component/segmented

Part of the Ant Design ecosystem.

+ Ant Design

🧩 React segmented control for switching between compact options.

diff --git a/README.zh-CN.md b/README.zh-CN.md index eacd829..64dd00b 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -1,6 +1,7 @@

@rc-component/segmented

Ant Design 生态的一部分。

+ Ant Design

🔘 React 分段控制器组件。

From 11a0aeaecbfab6ba052c0a5221a98cc0b3df1637 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sat, 27 Jun 2026 23:03:44 +0800 Subject: [PATCH 14/34] docs: refine bilingual README branding --- README.md | 3 +-- README.zh-CN.md | 57 ++++++++++++++++++++++++------------------------- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 67f2169..0afb943 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@

@rc-component/segmented

-

Part of the Ant Design ecosystem.

- Ant Design +

Ant Design Part of the Ant Design ecosystem.

🧩 React segmented control for switching between compact options.

diff --git a/README.zh-CN.md b/README.zh-CN.md index 64dd00b..939473a 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -1,8 +1,7 @@

@rc-component/segmented

-

Ant Design 生态的一部分。

- Ant Design -

🔘 React 分段控制器组件。

+

Ant Design Ant Design 生态的一部分。

+

🧩 React 分段控制器组件。

npm version @@ -19,10 +18,10 @@ ## 特性 -- 支持 string, number, and labeled option records. -- 提供 controlled and uncontrolled value flows. -- Includes keyboard navigation, RTL, vertical layout, and disabled options. -- 暴露 semantic `classNames` and `styles` slots for item and label customization. +- 支持字符串、数字和带标签的选项记录。 +- 提供受控和不受控的价值流。 +- 包括键盘导航、RTL、垂直布局和禁用选项。 +- 引入用于项目和标签定制的语义 `classNames` 和 `styles` 插槽。 ## 安装 @@ -47,7 +46,7 @@ export default () => ( ); ``` -Online preview: https://segmented.react-component.vercel.app/ +在线预览:https://segmented.react-component.vercel.app/ ## API @@ -55,33 +54,33 @@ Online preview: https://segmented.react-component.vercel.app/ | 名称 | 类型 | 默认值 | 说明 | | --- | --- | --- | --- | -| `className` | string | `''` | Additional class name. | -| `classNames` | Partial> | - | Semantic class names for internal slots. | -| `defaultValue` | string \| number | first option value | Initial selected value. | +| `className` | string | `''` | 附加className。 | +| `classNames` | 部分<记录<'项目'\| '标签',字符串>> | - | 内部插槽的语义化 className。 | +| `defaultValue` | string \| number | 第一个选项值 | 初始选中值。 | | `direction` | `'ltr'` \| `'rtl'` | - | Layout direction. | -| `disabled` | boolean | false | Disable all options. | -| `itemRender` | `(node: ReactNode, info: { item: SegmentedLabeledOption }) => ReactNode` | identity | Custom option item renderer. | -| `motionName` | string | `'thumb-motion'` | Motion class name for the active thumb. | +| `disabled` | boolean | false | 禁用所有选项。 | +| `itemRender` | `(node: ReactNode, info: { item: SegmentedLabeledOption }) => ReactNode` | identity | 自定义选项项渲染器。 | +| `motionName` | string | `'thumb-motion'` | 活动拇指的运动className称。 | | `name` | string | - | Radio group name. | -| `onChange` | `(value: string \| number) => void` | - | Triggered when the selected value changes. | -| `options` | Array | - | Available options. Required. | -| `prefixCls` | string | `'rc-segmented'` | Prefix class name. | -| `style` | React.CSSProperties | - | Root style. | -| `styles` | Partial> | - | Semantic styles for internal slots. | -| `value` | string \| number | - | Controlled selected value. | -| `vertical` | boolean | false | Render options vertically. | +| `onChange` | `(value: string \| number) => void` | - | 当所选值更改时触发。 | +| `options` | Array | - | 可用选项,必填。 | +| `prefixCls` | string | `'rc-segmented'` | 前缀className。 | +| `style` | React.CSSProperties | - | 根样式。 | +| `styles` | 部分<记录<'项目'\| '标签',React.CSSProperties>> | - | 内部插槽的语义化样式。 | +| `value` | string \| number | - | 受控选中值。 | +| `vertical` | boolean | false | 垂直渲染选项。 | -Additional valid `div` props are passed to the root element. +其他合法的 `div` 属性会透传给根元素。 ### SegmentedLabeledOption | 名称 | 类型 | 默认值 | 说明 | | --- | --- | --- | --- | -| `className` | string | - | Option class name. | -| `disabled` | boolean | false | Disable this option. | -| `label` | ReactNode | - | Displayed option content. | -| `title` | string | derived from label | Native title for the label. | -| `value` | string \| number | - | Option value. | +| `className` | string | - | 选项className称。 | +| `disabled` | boolean | false | 禁用此选项。 | +| `label` | ReactNode | - | 展示的选项内容。 | +| `title` | string | 源自标签 | 标签的原生标题。 | +| `value` | string \| number | - | 选项值。 | ## 本地开发 @@ -100,8 +99,8 @@ npm run build npm run prepublishOnly ``` -The release flow is handled by `@rc-component/np` through the `rc-np` command after the package build. +包构建完成后,发布流程由 `@rc-component/np` 通过 `rc-np` 命令处理。 ## 许可证 -@rc-component/segmented is released under the [MIT](./LICENSE.md) license. +@rc-component/segmented 基于 [MIT](./LICENSE.md) 许可证发布。 From 0b2914f9e15159376f1722871044a7669f783211 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 01:28:43 +0800 Subject: [PATCH 15/34] chore: standardize rc tooling and docs --- .dumirc.ts | 2 +- README.md | 11 +++++++++++ README.zh-CN.md | 11 +++++++++++ package.json | 46 ++++++++++++++++++++++---------------------- tsconfig.json | 51 ++++++++++++++++++++++++++++++++++++++----------- 5 files changed, 86 insertions(+), 35 deletions(-) diff --git a/.dumirc.ts b/.dumirc.ts index 9ebb64f..0b34af3 100644 --- a/.dumirc.ts +++ b/.dumirc.ts @@ -2,7 +2,7 @@ import { defineConfig } from 'dumi'; import path from 'path'; const basePath = process.env.GH_PAGES ? '/segmented/' : '/'; -const publicPath = process.env.GH_PAGES ? '/segmented/' : '/'; +const publicPath = basePath; export default defineConfig({ favicons: ['https://avatars0.githubusercontent.com/u/9441414?s=200&v=4'], diff --git a/README.md b/README.md index 0afb943..6a2c176 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,17 @@ export default () => ( Online preview: https://segmented.react-component.vercel.app/ +## Examples + +Run the local dumi site: + +```bash +npm install +npm start +``` + +Then open `http://localhost:8000`. + ## API ### Segmented diff --git a/README.zh-CN.md b/README.zh-CN.md index 939473a..a645b2e 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -48,6 +48,17 @@ export default () => ( 在线预览:https://segmented.react-component.vercel.app/ +## 示例 + +运行本地 dumi 站点: + +```bash +npm install +npm start +``` + +然后打开 `http://localhost:8000`。 + ## API ### Segmented diff --git a/package.json b/package.json index d0c6dca..1462897 100644 --- a/package.json +++ b/package.json @@ -55,31 +55,31 @@ }, "devDependencies": { "@rc-component/father-plugin": "^2.2.0", - "@rc-component/np": "^1.0.0", + "@rc-component/np": "^1.0.4", "@testing-library/jest-dom": "^6.9.1", - "@testing-library/react": "^14.2.1", - "@testing-library/user-event": "^14.5.2", - "@types/jest": "^29.2.4", - "@types/node": "^24.5.2", - "@types/react": "^18.3.11", - "@types/react-dom": "^18.3.1", - "@umijs/fabric": "^3.0.0", - "@umijs/test": "^4.0.36", - "cross-env": "^7.0.0", - "dumi": "^2.1.2", - "eslint": "^7.0.0", - "father": "^4.1.1", - "gh-pages": "^6.1.0", - "husky": "^8.0.0", - "jest": "^29.3.1", - "jest-environment-jsdom": "^29.3.1", - "less": "^3.10.3", - "prettier": "^2.0.5", - "pretty-quick": "^3.0.0", - "react": "^18.0.0", - "react-dom": "^18.0.0", + "@testing-library/react": "^15.0.7", + "@testing-library/user-event": "14.5.2", + "@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", + "@umijs/test": "^4.6.68", + "cross-env": "^10.1.0", + "dumi": "^2.4.35", + "eslint": "^8.57.1", + "father": "^4.6.23", + "gh-pages": "^6.3.0", + "husky": "^9.1.7", + "jest": "^29.7.0", + "jest-environment-jsdom": "^29.7.0", + "less": "^4.6.7", + "prettier": "^3.9.0", + "pretty-quick": "^4.2.2", + "react": "^18.3.1", + "react-dom": "^18.3.1", "ts-node": "^10.9.1", - "typescript": "^5.3.0" + "typescript": "^5.9.3" }, "peerDependencies": { "react": ">=16.0.0", diff --git a/tsconfig.json b/tsconfig.json index b7f0d77..d0168be 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,10 @@ "module": "ESNext", "moduleResolution": "node", "baseUrl": "./", - "lib": ["dom", "es2017"], + "lib": [ + "dom", + "es2017" + ], "jsx": "react", "strict": true, "esModuleInterop": true, @@ -12,16 +15,42 @@ "emitDecoratorMetadata": true, "skipLibCheck": true, "declaration": true, - "types": ["jest", "node", "@testing-library/jest-dom"], + "types": [ + "jest", + "node", + "@testing-library/jest-dom" + ], "paths": { - "@/*": ["src/*"], - "@@/*": [".dumi/tmp/*"], - "@rc-component/segmented": ["src/index.tsx"], - "@rc-component/segmented/es": ["src"], - "@rc-component/segmented/es/*": ["src/*"], - "@rc-component/segmented/assets/*": ["assets/*"] - } + "@/*": [ + "src/*" + ], + "@@/*": [ + ".dumi/tmp/*" + ], + "@rc-component/segmented": [ + "src/index.tsx" + ], + "@rc-component/segmented/es": [ + "src" + ], + "@rc-component/segmented/es/*": [ + "src/*" + ], + "@rc-component/segmented/assets/*": [ + "assets/*" + ] + }, + "ignoreDeprecations": "5.0" }, - "include": [".dumirc.ts", "src", "tests", "docs/demo"], - "exclude": ["docs-dist", "lib", "es"] + "include": [ + ".dumirc.ts", + "src", + "tests", + "docs/demo" + ], + "exclude": [ + "docs-dist", + "lib", + "es" + ] } From 75330879ca319147cf8a312b791af445ab0896f1 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 02:01:07 +0800 Subject: [PATCH 16/34] chore: address standardization review comments --- .github/workflows/surge-preview.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml index faf6b8b..cb6c8c4 100644 --- a/.github/workflows/surge-preview.yml +++ b/.github/workflows/surge-preview.yml @@ -22,13 +22,23 @@ jobs: - 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: ${{ secrets.SURGE_TOKEN != '' }} + if: ${{ steps.surge-token.outputs.enabled == 'true' }} run: | npm install npm run build - uses: afc163/surge-preview@bf90a5a86111f6311ca42f0a5a0f80fb0fb03cec - if: ${{ secrets.SURGE_TOKEN != '' }} + if: ${{ steps.surge-token.outputs.enabled == 'true' }} env: SURGE_TOKEN: ${{ secrets.SURGE_TOKEN }} with: @@ -38,5 +48,5 @@ jobs: failOnError: false setCommitStatus: false - name: Skip Surge preview - if: ${{ secrets.SURGE_TOKEN == '' }} + if: ${{ steps.surge-token.outputs.enabled != 'true' }} run: echo "SURGE_TOKEN is not configured; skip Surge preview." From 54638a9210e71bd70a6dac37d7955c8741760f33 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 02:10:34 +0800 Subject: [PATCH 17/34] chore: include father config in type checks --- tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tsconfig.json b/tsconfig.json index d0168be..9d43c37 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -43,6 +43,7 @@ "ignoreDeprecations": "5.0" }, "include": [ + ".fatherrc.ts", ".dumirc.ts", "src", "tests", From 8f132fe950e70fb58f9ab7692a7849cdb065f8ee Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 13:27:54 +0800 Subject: [PATCH 18/34] docs: add license file --- LICENSE | 21 +++++++++++++++++++++ README.md | 2 +- README.zh-CN.md | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 LICENSE 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 6a2c176..c1c4901 100644 --- a/README.md +++ b/README.md @@ -114,4 +114,4 @@ The release flow is handled by `@rc-component/np` through the `rc-np` command af ## License -@rc-component/segmented is released under the [MIT](./LICENSE.md) license. +@rc-component/segmented is released under the [MIT](./LICENSE) license. diff --git a/README.zh-CN.md b/README.zh-CN.md index a645b2e..86e038e 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -114,4 +114,4 @@ npm run prepublishOnly ## 许可证 -@rc-component/segmented 基于 [MIT](./LICENSE.md) 许可证发布。 +@rc-component/segmented 基于 [MIT](./LICENSE) 许可证发布。 From fe3bf79a21488e3f19d68f2d5c99769076c9f06d Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 14:01:11 +0800 Subject: [PATCH 19/34] ci: use actions checkout v7 --- .github/workflows/react-doctor.yml | 2 +- .github/workflows/surge-preview.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/react-doctor.yml b/.github/workflows/react-doctor.yml index f68281c..097eb88 100644 --- a/.github/workflows/react-doctor.yml +++ b/.github/workflows/react-doctor.yml @@ -20,7 +20,7 @@ jobs: react-doctor: runs-on: ubuntu-latest steps: - - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + - uses: actions/checkout@v7 with: fetch-depth: 0 persist-credentials: false diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml index cb6c8c4..ebfecd5 100644 --- a/.github/workflows/surge-preview.yml +++ b/.github/workflows/surge-preview.yml @@ -19,7 +19,7 @@ jobs: env: PREVIEW: true steps: - - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 + - uses: actions/checkout@v7 with: persist-credentials: false - name: Check Surge token From a0320ec8af3f51a2830e11379bd8b200f18ff95a Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 14:31:59 +0800 Subject: [PATCH 20/34] chore: standardize package metadata --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1462897..14284f3 100644 --- a/package.json +++ b/package.json @@ -24,10 +24,10 @@ "homepage": "https://react-component.github.io/segmented", "repository": { "type": "git", - "url": "git@github.com:react-component/segmented.git" + "url": "https://github.com/react-component/segmented.git" }, "bugs": { - "url": "http://github.com/react-component/segmented/issues" + "url": "https://github.com/react-component/segmented/issues" }, "license": "MIT", "scripts": { From 25efc324cc2583c2936c56bbfe772553f4b21a8e Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 14:38:13 +0800 Subject: [PATCH 21/34] ci: standardize dependabot updates --- .github/dependabot.yml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 07575c0..3b730ef 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,6 +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 From d31e137a9232e4c868099602bead26773de2ed81 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 16:27:35 +0800 Subject: [PATCH 22/34] docs: fix Chinese README API names --- README.zh-CN.md | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/README.zh-CN.md b/README.zh-CN.md index 86e038e..2b044e6 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -15,7 +15,6 @@

English | 简体中文

- ## 特性 - 支持字符串、数字和带标签的选项记录。 @@ -63,35 +62,35 @@ npm start ### Segmented -| 名称 | 类型 | 默认值 | 说明 | -| --- | --- | --- | --- | -| `className` | string | `''` | 附加className。 | -| `classNames` | 部分<记录<'项目'\| '标签',字符串>> | - | 内部插槽的语义化 className。 | -| `defaultValue` | string \| number | 第一个选项值 | 初始选中值。 | -| `direction` | `'ltr'` \| `'rtl'` | - | Layout direction. | -| `disabled` | boolean | false | 禁用所有选项。 | -| `itemRender` | `(node: ReactNode, info: { item: SegmentedLabeledOption }) => ReactNode` | identity | 自定义选项项渲染器。 | -| `motionName` | string | `'thumb-motion'` | 活动拇指的运动className称。 | -| `name` | string | - | Radio group name. | -| `onChange` | `(value: string \| number) => void` | - | 当所选值更改时触发。 | -| `options` | Array | - | 可用选项,必填。 | -| `prefixCls` | string | `'rc-segmented'` | 前缀className。 | -| `style` | React.CSSProperties | - | 根样式。 | -| `styles` | 部分<记录<'项目'\| '标签',React.CSSProperties>> | - | 内部插槽的语义化样式。 | -| `value` | string \| number | - | 受控选中值。 | -| `vertical` | boolean | false | 垂直渲染选项。 | +| 名称 | 类型 | 默认值 | 说明 | +| -------------- | ------------------------------------------------------------------------ | ---------------- | ---------------------------- | +| `className` | string | `''` | 附加className。 | +| `classNames` | Partial> | - | 内部插槽的语义化 className。 | +| `defaultValue` | string \| number | 第一个选项值 | 初始选中值。 | +| `direction` | `'ltr'` \| `'rtl'` | - | Layout direction. | +| `disabled` | boolean | false | 禁用所有选项。 | +| `itemRender` | `(node: ReactNode, info: { item: SegmentedLabeledOption }) => ReactNode` | identity | 自定义选项项渲染器。 | +| `motionName` | string | `'thumb-motion'` | 活动拇指的运动className称。 | +| `name` | string | - | Radio group name. | +| `onChange` | `(value: string \| number) => void` | - | 当所选值更改时触发。 | +| `options` | Array | - | 可用选项,必填。 | +| `prefixCls` | string | `'rc-segmented'` | 前缀className。 | +| `style` | React.CSSProperties | - | 根样式。 | +| `styles` | Partial> | - | 内部插槽的语义化样式。 | +| `value` | string \| number | - | 受控选中值。 | +| `vertical` | boolean | false | 垂直渲染选项。 | 其他合法的 `div` 属性会透传给根元素。 ### SegmentedLabeledOption -| 名称 | 类型 | 默认值 | 说明 | -| --- | --- | --- | --- | -| `className` | string | - | 选项className称。 | -| `disabled` | boolean | false | 禁用此选项。 | -| `label` | ReactNode | - | 展示的选项内容。 | -| `title` | string | 源自标签 | 标签的原生标题。 | -| `value` | string \| number | - | 选项值。 | +| 名称 | 类型 | 默认值 | 说明 | +| ----------- | ---------------- | -------- | ----------------- | +| `className` | string | - | 选项className称。 | +| `disabled` | boolean | false | 禁用此选项。 | +| `label` | ReactNode | - | 展示的选项内容。 | +| `title` | string | 源自标签 | 标签的原生标题。 | +| `value` | string \| number | - | 选项值。 | ## 本地开发 From 28dcc11e69c29aa59119b92c8a1e1bf7e4d601d7 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 17:15:59 +0800 Subject: [PATCH 23/34] chore: refine preview workflow ignores --- .github/workflows/surge-preview.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml index ebfecd5..eaff160 100644 --- a/.github/workflows/surge-preview.yml +++ b/.github/workflows/surge-preview.yml @@ -16,6 +16,9 @@ permissions: jobs: preview: runs-on: ubuntu-latest + concurrency: + group: surge-preview-${{ github.event.pull_request.number }} + cancel-in-progress: true env: PREVIEW: true steps: From d6eb2c5875413d51b6393adfef015b2d474fa741 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 17:36:36 +0800 Subject: [PATCH 24/34] docs: polish Chinese README wording --- README.zh-CN.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.zh-CN.md b/README.zh-CN.md index 2b044e6..a29e577 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -64,17 +64,17 @@ npm start | 名称 | 类型 | 默认值 | 说明 | | -------------- | ------------------------------------------------------------------------ | ---------------- | ---------------------------- | -| `className` | string | `''` | 附加className。 | +| `className` | string | `''` | 附加 className。 | | `classNames` | Partial> | - | 内部插槽的语义化 className。 | | `defaultValue` | string \| number | 第一个选项值 | 初始选中值。 | | `direction` | `'ltr'` \| `'rtl'` | - | Layout direction. | | `disabled` | boolean | false | 禁用所有选项。 | | `itemRender` | `(node: ReactNode, info: { item: SegmentedLabeledOption }) => ReactNode` | identity | 自定义选项项渲染器。 | -| `motionName` | string | `'thumb-motion'` | 活动拇指的运动className称。 | +| `motionName` | string | `'thumb-motion'` | 活动拇指的动画 className。 | | `name` | string | - | Radio group name. | | `onChange` | `(value: string \| number) => void` | - | 当所选值更改时触发。 | | `options` | Array | - | 可用选项,必填。 | -| `prefixCls` | string | `'rc-segmented'` | 前缀className。 | +| `prefixCls` | string | `'rc-segmented'` | className 前缀。 | | `style` | React.CSSProperties | - | 根样式。 | | `styles` | Partial> | - | 内部插槽的语义化样式。 | | `value` | string \| number | - | 受控选中值。 | @@ -84,13 +84,13 @@ npm start ### SegmentedLabeledOption -| 名称 | 类型 | 默认值 | 说明 | -| ----------- | ---------------- | -------- | ----------------- | -| `className` | string | - | 选项className称。 | -| `disabled` | boolean | false | 禁用此选项。 | -| `label` | ReactNode | - | 展示的选项内容。 | -| `title` | string | 源自标签 | 标签的原生标题。 | -| `value` | string \| number | - | 选项值。 | +| 名称 | 类型 | 默认值 | 说明 | +| ----------- | ---------------- | -------- | ---------------- | +| `className` | string | - | 选项 className。 | +| `disabled` | boolean | false | 禁用此选项。 | +| `label` | ReactNode | - | 展示的选项内容。 | +| `title` | string | 源自标签 | 标签的原生标题。 | +| `value` | string \| number | - | 选项值。 | ## 本地开发 From 42523cbc9600d9c4acae832fb3b601045390d209 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 17:48:17 +0800 Subject: [PATCH 25/34] chore: align tooling ignores and typescript --- .prettierignore | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.prettierignore b/.prettierignore index 32cb484..e0de014 100644 --- a/.prettierignore +++ b/.prettierignore @@ -11,3 +11,13 @@ _site .umi .doc README.md +coverage +docs-dist +dist +.dumi/tmp +.dumi/tmp-production +.vercel +pnpm-lock.yaml +yarn.lock +bun.lockb +*.log From bb3401c9a4c55756b04b8dc5d56619da227e9655 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 19:13:54 +0800 Subject: [PATCH 26/34] docs: polish Chinese README wording --- README.zh-CN.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.zh-CN.md b/README.zh-CN.md index a29e577..b545a12 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -67,11 +67,11 @@ npm start | `className` | string | `''` | 附加 className。 | | `classNames` | Partial> | - | 内部插槽的语义化 className。 | | `defaultValue` | string \| number | 第一个选项值 | 初始选中值。 | -| `direction` | `'ltr'` \| `'rtl'` | - | Layout direction. | +| `direction` | `'ltr'` \| `'rtl'` | - | 布局方向。 | | `disabled` | boolean | false | 禁用所有选项。 | | `itemRender` | `(node: ReactNode, info: { item: SegmentedLabeledOption }) => ReactNode` | identity | 自定义选项项渲染器。 | | `motionName` | string | `'thumb-motion'` | 活动拇指的动画 className。 | -| `name` | string | - | Radio group name. | +| `name` | string | - | 单选组名称。 | | `onChange` | `(value: string \| number) => void` | - | 当所选值更改时触发。 | | `options` | Array | - | 可用选项,必填。 | | `prefixCls` | string | `'rc-segmented'` | className 前缀。 | From 6207ea4967aee3acb20777c53be656315b6fcf70 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 19:39:07 +0800 Subject: [PATCH 27/34] docs: document dumi dev server port --- README.md | 2 ++ README.zh-CN.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index c1c4901..4089504 100644 --- a/README.md +++ b/README.md @@ -104,6 +104,8 @@ npm run compile npm run build ``` +The dumi site runs at `http://localhost:8000` by default. + ## Release ```bash diff --git a/README.zh-CN.md b/README.zh-CN.md index b545a12..e47d266 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -103,6 +103,8 @@ npm run compile npm run build ``` +dumi 站点默认运行在 `http://localhost:8000`。 + ## 发布 ```bash From 07de675dc12af4bb928022dabfc39333b5e11a55 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 19:58:31 +0800 Subject: [PATCH 28/34] chore: standardize husky configuration --- .husky/pre-commit | 5 +---- package.json | 10 ++++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 0da96d6..2312dc5 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1 @@ -#!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" - -npx pretty-quick --staged +npx lint-staged diff --git a/package.json b/package.json index 14284f3..fce0965 100644 --- a/package.json +++ b/package.json @@ -42,10 +42,9 @@ "prepublishOnly": "npm run compile && rc-np", "lint": "eslint src/ --ext .ts,.tsx,.jsx,.js,.md", "prettier": "prettier --write --ignore-unknown .", - "pretty-quick": "pretty-quick", "test": "jest", "coverage": "jest --coverage", - "prepare": "husky install" + "prepare": "husky" }, "dependencies": { "@babel/runtime": "^7.11.1", @@ -75,11 +74,11 @@ "jest-environment-jsdom": "^29.7.0", "less": "^4.6.7", "prettier": "^3.9.0", - "pretty-quick": "^4.2.2", "react": "^18.3.1", "react-dom": "^18.3.1", "ts-node": "^10.9.1", - "typescript": "^5.9.3" + "typescript": "^5.9.3", + "lint-staged": "^16.4.0" }, "peerDependencies": { "react": ">=16.0.0", @@ -93,5 +92,8 @@ }, "tnpm": { "mode": "npm" + }, + "lint-staged": { + "*": "prettier --write --ignore-unknown" } } From 433c7f87d5a07d749f6f6aa68a105556982723e3 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 21:01:09 +0800 Subject: [PATCH 29/34] docs: normalize readme badges --- README.md | 12 ++++++------ README.zh-CN.md | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4089504..921d2c5 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,12 @@

🧩 React segmented control for switching between compact options.

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

diff --git a/README.zh-CN.md b/README.zh-CN.md index e47d266..a5d53bc 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -4,12 +4,12 @@

🧩 React 分段控制器组件。

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

From 8822e5729c74ec28556b13e69f0b59491739a456 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 21:20:58 +0800 Subject: [PATCH 30/34] ci: limit reusable workflow secrets --- .github/workflows/react-component-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/react-component-ci.yml b/.github/workflows/react-component-ci.yml index 1ed6420..bb86720 100644 --- a/.github/workflows/react-component-ci.yml +++ b/.github/workflows/react-component-ci.yml @@ -9,4 +9,5 @@ permissions: jobs: test: uses: react-component/rc-test/.github/workflows/test-utoo.yml@main - secrets: inherit + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} From 35cd2546655d0b3c6ca2afa3b029f5e5b0bc9612 Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 21:33:24 +0800 Subject: [PATCH 31/34] ci: restore reusable workflow compatibility --- .github/workflows/react-component-ci.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/react-component-ci.yml b/.github/workflows/react-component-ci.yml index bb86720..1ed6420 100644 --- a/.github/workflows/react-component-ci.yml +++ b/.github/workflows/react-component-ci.yml @@ -9,5 +9,4 @@ permissions: jobs: test: uses: react-component/rc-test/.github/workflows/test-utoo.yml@main - secrets: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + secrets: inherit From c217523c669fbdc26c38ffbc7e86066ffc19877d Mon Sep 17 00:00:00 2001 From: afc163 Date: Sun, 28 Jun 2026 21:52:46 +0800 Subject: [PATCH 32/34] docs: polish zh-CN readme wording --- README.zh-CN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.zh-CN.md b/README.zh-CN.md index a5d53bc..940adc2 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -18,7 +18,7 @@ ## 特性 - 支持字符串、数字和带标签的选项记录。 -- 提供受控和不受控的价值流。 +- 支持受控和非受控的取值流程。 - 包括键盘导航、RTL、垂直布局和禁用选项。 - 引入用于项目和标签定制的语义 `classNames` 和 `styles` 插槽。 From 35e1c11e6da445810f7611fac9fa0bc986bb0735 Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 29 Jun 2026 01:08:19 +0800 Subject: [PATCH 33/34] ci: narrow surge preview permissions --- .github/workflows/surge-preview.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/surge-preview.yml b/.github/workflows/surge-preview.yml index eaff160..4c2f17e 100644 --- a/.github/workflows/surge-preview.yml +++ b/.github/workflows/surge-preview.yml @@ -11,7 +11,6 @@ permissions: contents: read pull-requests: write checks: write - statuses: write jobs: preview: From b9b0bb4200310e305c768763112be7897c4562c5 Mon Sep 17 00:00:00 2001 From: afc163 Date: Mon, 29 Jun 2026 14:26:12 +0800 Subject: [PATCH 34/34] chore: limit reusable workflow secrets --- .github/workflows/react-component-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/react-component-ci.yml b/.github/workflows/react-component-ci.yml index 1ed6420..bb86720 100644 --- a/.github/workflows/react-component-ci.yml +++ b/.github/workflows/react-component-ci.yml @@ -9,4 +9,5 @@ permissions: jobs: test: uses: react-component/rc-test/.github/workflows/test-utoo.yml@main - secrets: inherit + secrets: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}