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-switch

v0.3.0

Published

Switch 是一个开关组件,用于在两种状态间切换。

Readme

react-switch

Switch 是一个开关组件,用于在两种状态间切换。

安装

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

基本使用

import { Switch } from "@sea-lion/react-switch";

export default () => (
  <div>
    <Switch />
  </div>
);

受控组件

import { Switch } from "@sea-lion/react-switch";
import { useState } from "react";

export default () => {
  const [checked, setChecked] = useState(false);

  return <Switch checked={checked} onCheckedChange={setChecked} />;
};

默认选中

<Switch defaultChecked />

不同尺寸

Switch 组件提供三种尺寸:

// 尺寸 1(最小)
<Switch size="1" />

// 尺寸 2(默认)
<Switch size="2" />

// 尺寸 3(最大)
<Switch size="3" />

不同变体

Switch 组件支持多种变体样式:

// 经典变体
<Switch variant="classic" />

// 表面变体(默认)
<Switch variant="surface" />

// 柔和变体
<Switch variant="soft" />

自定义颜色

// 蓝色(默认)
<Switch color="blue" />

// 红色
<Switch color="red" />

// 绿色
<Switch color="green" />

高对比度

// 启用高对比度模式
<Switch highContrast />

禁用状态

// 禁用开关
<Switch disabled />

属性

| 参数 | 说明 | 类型 | 默认值 | 版本 | | --------------- | ---------------- | -------------------------------- | --------- | ----- | | size | 开关尺寸 | '1' | '2' | '3' | '2' | 0.2.0 | | variant | 开关变体样式 | 'classic' | 'surface' | 'soft' | 'surface' | 0.2.0 | | color | 开关颜色 | string | 'blue' | 0.2.0 | | radius | 圆角大小 | string | - | 0.2.0 | | highContrast | 是否使用高对比度 | boolean | false | 0.2.0 | | checked | 当前状态(受控) | boolean | - | 0.2.0 | | defaultChecked | 默认选中状态 | boolean | false | 0.2.0 | | onCheckedChange | 状态变化时的回调 | (checked: boolean) => void | - | 0.2.0 | | disabled | 是否禁用 | boolean | false | 0.2.0 |

同时支持所有标准的外边距(margin)属性。 

查看更多

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