@appbaseio/rheostat

中文文档
1.0.0-alpha.15发布于 2023/01/24MITCommonJS近 30 天下载 1.2万

Rheostat is a www, mobile, and accessible slider component built with React

原始使用文档
文档目录4 节
  1. Install
  2. Props
  3. Usage
  4. Live Playground

Rheostat

A mobile, tablet, desktop, and accessible slider for the web.

Rheostat demo

Install

npm install rheostat

Props

The algorithm, by default linear, the slider will use. Feel free to write your own as long as it conforms to the shape.

  algorithm: PropTypes.shape({
    getValue: PropTypes.func,
    getPosition: PropTypes.func,
  })

Custom class name that will be applied to the root of Rheostat.

  className: PropTypes.string

Custom React component overrides for both the handles, and the "progress" bar.

  handle: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
  progressBar: PropTypes.oneOfType([PropTypes.func, PropTypes.string])

The maximum and minimum possible values, by default 0 - 100.

  max: PropTypes.number
  min: PropTypes.number

pitComponent is a custom React component for rendering "pits" across the bar. pitPoints is the set of points at which it will render a pit. Points are an array of values on the slider.

  pitComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
  pitPoints: PropTypes.arrayOf(PropTypes.number)

NOTE: onChange is called whenever the value is changed and committed. This happens at the end of a drag, keypress, or click event. onChange is recommended when you wish to persist the values.

onValuesUpdated is a convenience event that is triggered while the value is being actively changed. This includes dragging, click, or keypress. onValuesUpdated is recommended if you need to work with the values before they're committed.

  onChange: PropTypes.func
  onClick: PropTypes.func
  onKeyPress: PropTypes.func
  onSliderDragEnd: PropTypes.func
  onSliderDragMove: PropTypes.func
  onSliderDragStart: PropTypes.func
  onValuesUpdated: PropTypes.func

snap is a boolean which controls the slider's snapping behavior. snapPoints is an array of values on the slider where the slider should snap to.

If snap is set to true and no snapPoints are set then the slider is snapped into an absolute position. For example, on a scale of 1-10 if the slider is let go at the 54% mark it'll pick the value 5 and snap to 50%.

  snap: PropTypes.bool
  snapPoints: PropTypes.arrayOf(PropTypes.number)

The values, by default 0 and 100.

  values: PropTypes.arrayOf(PropTypes.number)

You can disable the slider to prevent the user from moving it.

  disabled: PropTypes.bool

Usage

Important: Make sure to include the css file or feel free to create your own.

  • Simple.
import Rheostat from 'rheostat';

ReactDOM.render(<Rheostat />, document.getElementById('slider-root'));
  • A slider with a multiple handles.
import Rheostat from 'rheostat';

ReactDOM.render((
  <Rheostat
    min={1}
    max={100}
    values={[1, 100]}
  />
), document.getElementById('slider-root'));

Live Playground

For more examples you can check out the storybook.

  • Clone this repo on your machine.
  • npm install
  • npm run storybook
  • Visit http://localhost:9001/.

版本与发布记录

@appbaseio/rheostat 共发布 16 个版本,首次发布于 2022/10/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.0-alpha.15latest2023/01/243 年前
1.0.0-alpha.142023/01/243 年前
1.0.0-alpha.132023/01/243 年前
1.0.0-alpha.122023/01/233 年前
1.0.0-alpha.112023/01/183 年前
1.0.0-alpha.102023/01/183 年前

关于 @appbaseio/rheostat 的常见问题

@appbaseio/rheostat 是什么?

Rheostat is a www, mobile, and accessible slider component built with React

如何安装 @appbaseio/rheostat?

在项目目录运行 npm install @appbaseio/rheostat,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=0.13.x)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@appbaseio/rheostat 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/appbaseio__rheostat 是否存在。

@appbaseio/rheostat 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@appbaseio/rheostat 可以商用吗?

@appbaseio/rheostat 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@appbaseio/rheostat 的下载量有多少?

根据 npm 官方下载统计,@appbaseio/rheostat 在 2026/10/07 – 2026/11/05 这 30 天内被下载 12,160 次,日均约 405 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@appbaseio/rheostat 还在维护吗?

最新版本 1.0.0-alpha.15 发布于 2023/01/24(3 年前);至今共发布 16 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/10/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。