Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4331968
chore: standardize repository config
afc163 Jun 26, 2026
771799e
fix: make preview build generate styles
afc163 Jun 26, 2026
bed5b58
fix: address review feedback
afc163 Jun 26, 2026
4f5736b
fix: keep rc-test secrets inheritance
afc163 Jun 26, 2026
fbeb616
fix: align test workflow triggers
afc163 Jun 26, 2026
7336b16
chore: address AI review feedback
afc163 Jun 26, 2026
9038793
docs: standardize README release details
afc163 Jun 26, 2026
fb6afc2
ci: make surge preview non-blocking
afc163 Jun 26, 2026
a491ac0
ci: keep surge preview as fallback
afc163 Jun 26, 2026
941413f
docs: refine README usage and ecosystem note
afc163 Jun 27, 2026
75577f2
ci: isolate surge preview token
afc163 Jun 27, 2026
8252c5b
docs: add Chinese README
afc163 Jun 27, 2026
ba9acc9
docs: add Ant Design logo to README
afc163 Jun 27, 2026
11a0aea
docs: refine bilingual README branding
afc163 Jun 27, 2026
0b2914f
chore: standardize rc tooling and docs
afc163 Jun 27, 2026
7533087
chore: address standardization review comments
afc163 Jun 27, 2026
54638a9
chore: include father config in type checks
afc163 Jun 27, 2026
8f132fe
docs: add license file
afc163 Jun 28, 2026
fe3bf79
ci: use actions checkout v7
afc163 Jun 28, 2026
a0320ec
chore: standardize package metadata
afc163 Jun 28, 2026
25efc32
ci: standardize dependabot updates
afc163 Jun 28, 2026
d31e137
docs: fix Chinese README API names
afc163 Jun 28, 2026
28dcc11
chore: refine preview workflow ignores
afc163 Jun 28, 2026
d6eb2c5
docs: polish Chinese README wording
afc163 Jun 28, 2026
42523cb
chore: align tooling ignores and typescript
afc163 Jun 28, 2026
bb3401c
docs: polish Chinese README wording
afc163 Jun 28, 2026
6207ea4
docs: document dumi dev server port
afc163 Jun 28, 2026
07de675
chore: standardize husky configuration
afc163 Jun 28, 2026
433c7f8
docs: normalize readme badges
afc163 Jun 28, 2026
8822e57
ci: limit reusable workflow secrets
afc163 Jun 28, 2026
35cd254
ci: restore reusable workflow compatibility
afc163 Jun 28, 2026
c217523
docs: polish zh-CN readme wording
afc163 Jun 28, 2026
35e1c11
ci: narrow surge preview permissions
afc163 Jun 28, 2026
b9b0bb4
chore: limit reusable workflow secrets
afc163 Jun 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ 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'],
themeConfig: {
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'),
},
});
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: ant-design
open_collective: ant-design
13 changes: 12 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 0 additions & 6 deletions .github/workflows/main.yml

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/preview.yml

This file was deleted.

13 changes: 13 additions & 0 deletions .github/workflows/react-component-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: ✅ test
on:
push:
branches: [master]
pull_request:
branches: [master]
permissions:
contents: read
jobs:
test:
uses: react-component/rc-test/.github/workflows/test-utoo.yml@main
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
27 changes: 27 additions & 0 deletions .github/workflows/react-doctor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: React Doctor

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
push:
branches: [master]
Comment thread
coderabbitai[bot] marked this conversation as resolved.

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
54 changes: 54 additions & 0 deletions .github/workflows/surge-preview.yml
Original file line number Diff line number Diff line change
@@ -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."
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ package-lock.json
pnpm-lock.yaml
coverage/
.doc
docs-dist
.vercel

# umi
.umi
Expand Down
5 changes: 1 addition & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx pretty-quick --staged
npx lint-staged
10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
142 changes: 91 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,119 @@
# @rc-component/segmented
<div align="center">
<h1>@rc-component/segmented</h1>
<p><sub><img alt="Ant Design" height="14" src="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg" style="vertical-align: -0.125em;" /> Part of the Ant Design ecosystem.</sub></p>
<p>🧩 React segmented control for switching between compact options.</p>

[![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]
<p>
<a href="https://npmjs.org/package/@rc-component/segmented"><img alt="NPM version" src="https://img.shields.io/npm/v/@rc-component/segmented.svg?style=flat-square"></a>
<a href="https://npmjs.org/package/@rc-component/segmented"><img alt="npm downloads" src="https://img.shields.io/npm/dm/@rc-component/segmented.svg?style=flat-square"></a>
<a href="https://github.com/react-component/segmented/actions/workflows/react-component-ci.yml"><img alt="build status" src="https://github.com/react-component/segmented/actions/workflows/react-component-ci.yml/badge.svg"></a>
<a href="https://app.codecov.io/gh/react-component/segmented"><img alt="Codecov" src="https://img.shields.io/codecov/c/github/react-component/segmented/master.svg?style=flat-square"></a>
<a href="https://bundlephobia.com/package/@rc-component/segmented"><img alt="bundle size" src="https://img.shields.io/bundlephobia/minzip/@rc-component/segmented?style=flat-square"></a>
<a href="https://github.com/umijs/dumi"><img alt="dumi" src="https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square"></a>
</p>
</div>

[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
<p align="center">English | <a href="./README.zh-CN.md">简体中文</a></p>

React Segmented Control.

![](https://gw.alipayobjects.com/mdn/rms_50855f/afts/img/A*bmGGQpnWs0oAAAAAAAAAAAAAARQnAQ)
## Highlights

## Live Demo

https://react-component.github.io/segmented/
- 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 () => (
<Segmented
options={['Antd', 'Antv', 'Egg.js']}
onChange={(value) => handleValueChange(value)}
/>,
mountNode,
options={['Daily', 'Weekly', 'Monthly']}
defaultValue="Weekly"
onChange={(value) => {
console.log(value);
}}
/>
);
```

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

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<string \| number \| [SegmentedOption](#SegmentedOption)> | [] | 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<Record<'item' \| 'label', string>> | - | 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<string \| number \| SegmentedLabeledOption> | - | Available options. Required. |
| `prefixCls` | string | `'rc-segmented'` | Prefix class name. |
Comment thread
coderabbitai[bot] marked this conversation as resolved.
| `style` | React.CSSProperties | - | Root style. |
| `styles` | Partial<Record<'item' \| 'label', React.CSSProperties>> | - | 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
```

The dumi site runs at `http://localhost:8000` by default.

## Release

```bash
npm run prepublishOnly
```

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) license.
Loading
Loading