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 🙏

© 2024 – Pkg Stats / Ryan Hefner

zent-slider

v1.0.0

Published

Slider组件

Downloads

6

Readme

Slider 滑动输入条

通过拖动、点击 Slider 组件选择数值

使用指南

  • 可设置单滑块或者双滑块
  • 可与 Input 输入框配合使用

代码演示

:::demo 基础用法

import { Slider } from 'zent';

class Test extends React.Component {
  state = {
    value: 0
  }

  onChange = value => {
    this.setState({ value });
  }

  render() {
    const { value } = this.state;
    return (<Slider value={value} onChange={this.onChange} />);
  }
}

ReactDOM.render(
    <Test />
    , mountNode
);

:::

:::demo 双滑块选择范围

import { Slider } from 'zent';

class Test extends React.Component {
  state = {
    value: [30, 100]
  }

  onChange = value => {
    this.setState({ value });
  }

  render() {
    const { value } = this.state;
    return (<Slider range value={value} onChange={this.onChange} />);
  }
}

ReactDOM.render(
    <Test />
    , mountNode
);

:::

:::demo 设置最大值,最小值,间隔

import { Slider } from 'zent';

class Test extends React.Component {
  state = {
    value: 1.3
  }

  onChange = value => {
    this.setState({ value });
  }

  render() {
    const { value } = this.state;
    return (<Slider max={2} min={1} step={0.1} value={value} onChange={this.onChange} />);
  }
}

ReactDOM.render(
    <Test />
    , mountNode
);

:::

:::demo 标签值

import { Slider } from 'zent';

const marks = {
  0: '0°C',
  100: '100°C'
};

class Test extends React.Component {
  state = {
    value: [30, 100]
  }

  onChange = value => {
    this.setState({ value });
  }

  render() {
    const { value } = this.state;
    return (<Slider range marks={marks} value={value} onChange={this.onChange} />);
  }
}

ReactDOM.render(
    <Test />
    , mountNode
);

:::

:::demo 只能选择标签值,此时无输入框

import { Slider } from 'zent';

const marks = {
  0: '0°C',
  25: '25°C',
  50: '50°C',
  75: '75°C',
  100: '100°C'
};

class Test extends React.Component {
  state = {
    value: [0, 50]
  }

  onChange = value => {
    this.setState({ value });
  }

  render() {
    const { value } = this.state;
    return (<Slider range dots marks={marks} value={value} onChange={this.onChange} />);
  }
}

ReactDOM.render(
    <Test />
    , mountNode
);

:::

:::demo disabled

import { Slider } from 'zent';

ReactDOM.render(
    <Slider value={[30, 100]} range disabled />
    , mountNode
);

:::

API

| 参数 | 说明 | 类型 | 默认值 | 备选值 | 是否必填 | | ------------ | --------------- | ------------- | -------- | ----------------------- | ---- | | value | 输入值 | [number,array] | 0 | [0,0] | 是 | | onChange | change 事件 | func(e:Event) | | | 否 | | range | 是否选择范围 | bool | false | | 否 | | max | 最大范围 | number | 100 | 50 | 否 | | min | 最小范围 | number | 0 | -100 | 否 | | step | 间隔 | number | 1 | | 否 | | withInput | 是否带输入框 | bool | true | | 否 | | dots | 是否只能在标签值中选择 | bool | true | | 否 | | marks | 标签值 | object | | | 否 | | disabled | 是否禁用 | bool | false | | 否 | | className | 自定义额外类名 | string | '' | | 否 | | prefix | 自定义类前缀 | string | 'zent' | | 否 |

range 属性设置了必须给一个 value 值,且一定为一个长度为2的数组,数组项必须为数字。dots 属性配合 marks 属性使用。