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

react-widget-listbox

v2.0.1

Published

rw-widget-listbox

Downloads

95

Readme

ListBox

ListBox组件

安装

npm install --save react-widget-listbox

使用

Edit react-widget-listbox

import React from "react";
import Trigger from "react-widget-listbox";
import "react-widget-listbox/style";

export default function App() {
  return (
    <div
      className="App"
      style={{
        padding: 100
      }}
    >
      <ListBox
        data={[
            {
                value: 'Banana',
                label: 'Banana'
            }, {
                value: 'Orange',
                label: 'Orange'
            }, {
                value: 'Apple',
                label: 'Apple'
            }, {
                value: 'Mango',
                label: 'Mango'
            }, 
        ]}  
      />
    </div>
  );
}

Interfaces

export declare type ItemData = Record<string | number, any>;
export declare type ValueType = number | string;
export declare type Item = {
    value: any;
    label: React.ReactNode;
    disabled: boolean;
    children?: Item[];
    data: ItemData;
    ref: React.RefObject<ListItem>;
};
export interface ListBoxProps {
    /** 样式前缀 */
    prefixCls?: string;
    /** 样式名 */
    className?: string;
    /** 样式属性 */
    style?: React.CSSProperties;
    /** tabIndex值 */
    tabIndex?: number;
    /** 支持多选,开启多选后,defaultValue/value为数组 */
    multiple?: boolean;
    /** 默认选中值 */
    defaultValue?: ValueType | ValueType[];
    /** 选中值(受控) */
    value?: ValueType | ValueType[];
    /** 禁用 */
    disabled?: boolean;
    /** 只读 */
    readOnly?: boolean;
    /** 自动获取焦点 */
    autoFocus?: boolean;
    /** 数据集 */
    data?: ItemData[];
    /** 设置data数据的值字段 */
    valueField?: string;
    /** 设置data数据的显示字段 */
    labelField?: string;
    /** 设置data数据的禁用字段 */
    disabledField?: string;
    /** 设置data数据的子节点字段 */
    childrenField?: string;
    /** 设置renderHeader后CSS属性 */
    headerStyle?: React.CSSProperties;
    /** 设置renderFooter后CSS属性 */
    footerStyle?: React.CSSProperties;
    /** 设置列表容器CSS属性 */
    bodyStyle?: React.CSSProperties;
    /** 无数据时显示内容 */
    emptyLabel?: React.ReactNode;
    /** 获取列表项属性 */
    getItemProps?: (data: ItemData) => React.HTMLAttributes<HTMLElement>;
    /** 获取分组标题项属性 */
    getGroupTitleProps?: (data: ItemData) => React.HTMLAttributes<HTMLElement>;
    /** 自定义渲染分组标题 */
    renderGroupTitle?: (data: ItemData) => React.ReactNode;
    /** 自定义渲染列表项内容 */
    renderItem?: (data: ItemData, item: Item) => React.ReactNode;
    /** 自定义渲染器 */
    renderer?: (listBody: React.ReactNode) => React.ReactNode;
    fixListBodyHeightOnIE?: boolean;
    onSelect?: (value: string | number, data: ItemData) => void;
    onDeselect?: (value: ValueType, data: ItemData) => void;
    onChange?: (value: ValueType | ValueType[], data: ItemData[] | ItemData) => void;
    onFocus?: (e: React.FocusEvent) => void;
    onBlur?: (e: React.FocusEvent) => void;
    onKeyDown?: (e: React.KeyboardEvent) => void;
    onMouseLeave?: (e: React.MouseEvent) => void;
    wrapperComponent: React.ElementType;
    bodyWrapperComponent: React.ElementType;
}

defaultProps

{
	prefixCls: "rw-listbox",
	valueField: "value",
	labelField: "label",
	disabledField: "disabled",
	childrenField: "children",
	tabIndex: 0,
	emptyLabel: "Not Found",
	fixListBodyHeightOnIE: true,
	data: [],
	wrapperComponent: "div",
	bodyWrapperComponent: "div",
}

基础样式

.rw-listbox {
	border-radius: 3px;
	position: relative;
	background: #fff;
	display: flex;
	flex-direction: column;
	border: 1px solid #10161a26;
	padding: 5px;
}

.rw-listbox-body {
	flex: 1;
	overflow: auto;
	overflow-x: hidden;
}

.rw-listbox-item-group .rw-listbox-item {
	padding-left: 23px;
}

.rw-listbox-group-title {
	display: flex;
	padding: 5px 7px;
	line-height: 20px;
	user-select: none;
	color: rgb(24, 32, 38);
}

.rw-listbox-item {
	display: flex;
	border-radius: 2px;
	padding: 5px 7px;
	line-height: 20px;
	cursor: pointer;
	user-select: none;
	color: rgb(24, 32, 38);
}

.rw-listbox-item-active {
	background-color: rgba(167, 182, 194, 0.3);
}

.rw-listbox-item:active {
	background-color: rgba(115, 134, 148, 0.3);
}

.rw-listbox-item.rw-listbox-item-selected {
	color: #fff;
	background-color: #137cbd;
}
.rw-listbox-disabled .rw-listbox-item,
.rw-listbox-item.rw-listbox-item-disabled {
	background-color: inherit;
	color: rgba(167, 182, 194, 0.6);
	cursor: default;
}

.rw-listbox-group-title {
	font-weight: 400;
}
.rw-listbox-group-list .rw-listbox-item {
	padding-left: 24px;
}