GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - react-widget/switch: https://react-widget.github.io/switch/

BranchesTags
Open more actions menu

Latest commit

 

History

2 Commits
2 Commits

Folders and files

NameName
Last commit message
Last commit date
docs
docs
 
 
examples
examples
 
 
src
src
 
 
style
style
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
.prettierignore
.prettierignore
 
 
.prettierrc
.prettierrc
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
babel.config.js
babel.config.js
 
 
jest.config.js
jest.config.js
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
packez.config.js
packez.config.js
 
 
transform-es.config.js
transform-es.config.js
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

Switch

Switch组件

安装

npm install --save react-widget-switch

使用

Edit rw-widget-switch

import React from "react";
import Switch from "react-widget-switch";
import "react-widget-switch/style";

export default function App() {
  return (
    <div
      className="App"
      style={{
        padding: 100
      }}
    >
      <Switch />
    </div>
  );
}

Interfaces

import React from "react";
export interface SwitchProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange" | "onClick"> {
    /** 组件样式前缀名 */
    prefixCls?: string;
    /** 类名称 */
    className?: string;
    /** 组件自动获取焦点 */
    autoFocus: boolean;
    /** 是否选中(受控) */
    checked: boolean;
    /** 初始是否选中 */
    defaultChecked: boolean;
    /** 开关大小,可选值:default small */
    size?: "small" | "default";
    /** 是否禁用 */
    disabled: boolean;
    /** 选中时的内容 */
    checkedChildren: React.ReactNode;
    /** 非选中时的内容 */
    unCheckedChildren: React.ReactNode;
    /** 改变时触发 */
    onChange: (checked: boolean, e: React.SyntheticEvent) => void;
    onKeyDown: (e: React.KeyboardEvent) => void;
    onClick: (checked: boolean, e: React.MouseEvent) => void;
}
export interface SwitchState {
    checked: boolean;
}
export declare class Switch extends React.Component<SwitchProps, SwitchState> {
    static defaultProps: {
        prefixCls: string;
        tabIndex: number;
        defaultChecked: boolean;
    };
    static getDerivedStateFromProps(nextProps: SwitchProps, state: SwitchState): {
        checked: boolean;
    };
    nodeRef: React.RefObject<HTMLDivElement>;
    constructor(props: SwitchProps);
    fireChange(checked: boolean, e: React.SyntheticEvent): void;
    protected handleClick: (e: React.MouseEvent) => void;
    protected handleKeyDown: (e: React.KeyboardEvent) => void;
    componentDidMount(): void;
    render(): JSX.Element;
}
export default Switch;

defaultProps

{
	prefixCls: "rw-switch",
}

基础样式

.rw-switch {
    position: relative;
    display: inline-block;
    min-width: 44px;
    height: 22px;
    line-height: 22px;
    vertical-align: middle;
    border-radius: 20px 20px;
    background-color: #bfcbd9;
    cursor: pointer;
    user-select: none;
    transition: all 0.3s;
}

.rw-switch-checked {
    background-color: #20a0ff;
}

.rw-switch-disabled {
    cursor: not-allowed;
    opacity: 0.4;
    outline: none;
}

.rw-switch-small {
    min-width: 28px;
    height: 16px;
    line-height: 16px;
}

.rw-switch-handler {
    position: absolute;
    width: 18px;
    height: 18px;
    left: 2px;
    top: 2px;
    transition: all 0.3s;
}

.rw-switch-handler:after {
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    border-radius: 50% 50%;
    content: " ";
    background: #fff;
}

.rw-switch-small .rw-switch-handler {
    width: 12px;
    height: 12px;
}

.rw-switch-checked .rw-switch-handler {
    left: calc(100% - 18px - 2px);
}

.rw-switch-small.rw-switch-checked .rw-switch-handler {
    left: calc(100% - 12px - 2px);
}

.rw-switch-inner {
    color: #fff;
    font-size: 12px;
    display: block;
    margin: 0 7px 0 25px;
    transition: all 0.3s;
}

.rw-switch-checked .rw-switch-inner {
    margin: 0 25px 0 7px;
}

.rw-switch-small .rw-switch-inner {
    margin: 0 5px 0 18px;
}

.rw-switch-checked.rw-switch-small .rw-switch-inner {
    margin: 0 18px 0 5px;
}

About

https://react-widget.github.io/switch/

Resources

Readme
MIT license
Activity
Custom properties

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.