3.0.4 • Published 1 year ago

react-auto-scroll-time-select v3.0.4

Weekly downloads
23
License
MIT
Repository
github
Last release
1 year ago

react-auto-scroll-time-select

total npm

A select box that supports typescript. You can select options that are separated by time. Automatically scrolls to choices that match the entered value.

Demo Site

Installation

$ yarn add react-auto-scroll-time-select @emotion/css

Usage

import Select, { OptionType } from "react-auto-scroll-time-select";

<Select onChange={setOption} value={option} />;

Export Types

NameType
OptionType{ label: string; value: string; }
InputValueTypestring | null | undefined
StyleConfigType{ key: string: any }

Props

PropDefaultTypeDetail
span30 (minutes)numberChoice time interval
hourLimit24 (hours)numberLimit time
valueOptionType | nullThe time you have selected
onChange(option: OptionType | null) => void;Select change event
findOption(option: OptionType, input: InputValueType) => void;An event that finds options to scroll from input characters
isClearabletruebooleanIf true, display the button to clear
styles{ select, control, ... }See Custom Style
menuPortalTargetElement to add selection menu
defaultScrollOptionValuestringDefault display value
hideOptions[]string[]Specify options to hide
disabledOptions[]string[]Specify options to disabled
startTime00:00stringSpecify the start time

Custom Styles

Examples

<Select
  styles={{
    select: (config: StyleConfigType) => ({
      ...config,
      width: 200,
    }),
    control: () => ({}),
  }}
/>

Styles Props

propsDetail
selectSelect box outline
controlSelect box inner frame
inputForminput field
clearValueClear button
dropDownArrowWrapperDropdown outline
dropDownArrowItemDropdown items
selectOptionsSelection menu outline
optionMenuSelection menu items

Full Custom Example

import React, { useState, useEffect } from "react";
import Select, {
  OptionType,
  InputValueType,
  StyleConfigType,
} from "react-auto-scroll-time-select";

const App = () => {
  const [option, setOption] = useState<OptionType | null>();

  useEffect(() => {
    console.log(option);
  }, [option]);

  return (
    <Select
      onChange={setOption}
      value={option}
      span={15}
      hourLimit={33}
      findOption={(option: OptionType, inputValue: InputValueType) =>
        option.value === inputValue
      }
      isClearable={false}
      styles={{
        select: (config: StyleConfigType) => ({
          ...config,
          width: 500,
        }),
        control: (config: StyleConfigType) => ({
          ...config,
          width: 500,
        }),
        inputForm: (config: StyleConfigType) => ({
          ...config,
          width: "100%",
          backgroundColor: "#d69a9a",
        }),
        clearValue: (config: StyleConfigType) => ({
          ...config,
          width: 30,
          backgroundColor: "#000000",
          color: "white",
        }),
        dropDownArrowWrapper: (config: StyleConfigType) => ({
          ...config,
          width: 50,
          backgroundColor: "#a1a8b7",
          "&:hover > div": {
            borderColor: "rgba(255, 0, 0, 0.5) transparent transparent",
          },
        }),
        dropDownArrowItem: (config: StyleConfigType) => ({
          ...config,
          borderColor: "#a73c3c transparent transparent",
        }),
        selectOptions: (config: StyleConfigType) => ({
          ...config,
          width: 600,
          backgroundColor: "#000000",
        }),
        optionMenu: (config: StyleConfigType) => ({
          ...config,
          color: "green",
        }),
      }}
      menuPortalTarget={document.body}
      defaultScrollOptionValue="09:00"
      hideOptions={["01:30"]}
      disabledOptions={["02:00"]}
      startTime={"01:00"}
    />
  );
};

export default App;

License

MIT

3.0.4

1 year ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.4.1

3 years ago

2.3.0

3 years ago

2.4.0

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.1.0

3 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.5

4 years ago

2.0.6

4 years ago

2.0.3

4 years ago

2.0.4

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago