npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@sea-lion/react-segmented-control

v0.3.0

Published

SegmentedControl 是一个分段控制器组件,用于在一组相关选项中进行单选。它提供了一个可视化的指示器,显示当前选中的选项。

Readme

react-segmented-control

SegmentedControl 是一个分段控制器组件,用于在一组相关选项中进行单选。它提供了一个可视化的指示器,显示当前选中的选项。

安装

$ yarn add @sea-lion/react-segmented-control
# 或者
$ npm install @sea-lion/react-segmented-control

基本使用

import * as SegmentedControl from "@sea-lion/react-segmented-control";

export default () => {
  return (
    <SegmentedControl.Root defaultValue="daily">
      <SegmentedControl.Item value="daily">每日</SegmentedControl.Item>
      <SegmentedControl.Item value="weekly">每周</SegmentedControl.Item>
      <SegmentedControl.Item value="monthly">每月</SegmentedControl.Item>
    </SegmentedControl.Root>
  );
};

尺寸

SegmentedControl 组件支持三种尺寸,控制控件的大小:

// 小尺寸
<SegmentedControl.Root size="1">
  {/* 子项 */}
</SegmentedControl.Root>

// 中等尺寸(默认)
<SegmentedControl.Root size="2">
  {/* 子项 */}
</SegmentedControl.Root>

// 大尺寸
<SegmentedControl.Root size="3">
  {/* 子项 */}
</SegmentedControl.Root>

变体

SegmentedControl 组件提供两种视觉变体:

// Surface 变体(默认)
<SegmentedControl.Root variant="surface">
  {/* 子项 */}
</SegmentedControl.Root>

// Classic 变体
<SegmentedControl.Root variant="classic">
  {/* 子项 */}
</SegmentedControl.Root>

圆角

使用 radius 属性控制组件的圆角程度:

<SegmentedControl.Root radius="none">
  {/* 子项 */}
</SegmentedControl.Root>

<SegmentedControl.Root radius="small">
  {/* 子项 */}
</SegmentedControl.Root>

<SegmentedControl.Root radius="medium">
  {/* 子项 */}
</SegmentedControl.Root>

<SegmentedControl.Root radius="large">
  {/* 子项 */}
</SegmentedControl.Root>

<SegmentedControl.Root radius="full">
  {/* 子项 */}
</SegmentedControl.Root>

受控模式

SegmentedControl 可以作为受控组件使用,通过 valueonValueChange 属性:

import * as SegmentedControl from "@sea-lion/react-segmented-control";
import { useState } from "react";

export default () => {
  const [value, setValue] = useState("daily");

  return (
    <SegmentedControl.Root value={value} onValueChange={setValue}>
      <SegmentedControl.Item value="daily">每日</SegmentedControl.Item>
      <SegmentedControl.Item value="weekly">每周</SegmentedControl.Item>
      <SegmentedControl.Item value="monthly">每月</SegmentedControl.Item>
    </SegmentedControl.Root>
  );
};

属性

Root 属性

| 参数 | 说明 | 类型 | 默认值 | 版本 | | ------------- | -------------- | -------------------------------------------------- | --------- | ----- | | size | 控件大小 | '1' | '2' | '3' | '2' | 0.2.0 | | variant | 视觉变体 | 'surface' | 'classic' | 'surface' | 0.2.0 | | radius | 圆角大小 | 'none' | 'small' | 'medium' | 'large' | 'full' | - | 0.2.0 | | value | 当前选中值 | string | - | 0.2.0 | | defaultValue | 默认选中值 | string | - | 0.2.0 | | onValueChange | 值变化回调函数 | (value: string) => void | - | 0.2.0 |

Item 属性

| 参数 | 说明 | 类型 | 默认值 | 版本 | | ----- | -------- | ------ | ------ | ----- | | value | 选项的值 | string | - | 0.2.0 | 

查看更多

参考 Radix UI 官方文档 获取完整 API 与设计规范。