2.0.1 • Published 8 months ago

@licuido-ui/ui_select v2.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

Selectbox

The Select component is implemented as a custom input element of the InputBase. It extends the text field components sub-components, either the OutlinedInput, Input, or FilledInput, depending on the variant selected. It shares the same styles and many of the same props

Author

Link

Story Book Link Selectbox

PlayGround

Try it have a fun codeBox

Installation

npm i @licuido-ui/ui_select

Import component

import { Select } from '@licuido-ui/ui_select';

Usage

<Select
  componentStylePropSx={{}}
  selectType='default'
  customProps={{
    rootStyleSx: {
      background: '',
    },
    inputRootStyleSx: {
      '& div': {
        background: '',
        color: '',
      },
    },
    selectParentSx: {},
    limitTags: 3,
    multiple: true,
    value: selectedOptions,
    isClearIcon: true,
    onClearTag: () => {
      setSelectedOptions([]);
    },
    islabel: true,
    label: 'select',
    handleChange: handleSelectChange,
    options: [
      { label: 'Option 1', value: 1994 },
      { label: 'Option 2', value: 1972 },
      { label: 'Option 3', value: 1974 },
      { label: 'Option 4', value: 2008 },
      { label: 'Option 5', value: 1957 },
      { label: 'Option 6', value: 1993 },
      { label: 'Option 7', value: 1994 },
    ],
    selectId: 'select',
    dropdownMinHeight: '200px',
    dropdownMaxWidth: '',
    dropdownMinWidth: '',
    dropdownMaxHeight: '',
    inputMinHeight: '',
    inputMaxWidth: '',
    inputMinWidth: '',
    inputMaxHeight: '',
    inputBackgroundColor: 'red',
    inputBorder: '1px solid blue',
    inputBorderRadius: '8px',
    inputPropsSx: {},
    inputStartEndornment: <SearchIcon width={'18px'} color='red' />,
    labelPropsSx: {},
    inputEndEndornment: <ArrowDown width={'18px'} color='red' />,
    checkedIconProp: null,
    unCheckedIconProp: null,
    hoverBgColor: '',
    hoverColor: 'blue',
    background: '',
    borderRadiusChip: '3px',
    inputColor: 'black',
    groupHeadColor: 'grey',
    listItemfontSize: '',
  }}
/>

Image

alt text

Sample Code

import {  Select } from '@licuido-ui/react';
import { useState } from 'react';
import ArrowDown from './assets/arrowDown';
import SearchIcon from './assets/searchIcon';
import GlobeSvg from './assets/globleSvg';

function App() {

   // Selected options state
  const [selectedOptions, setSelectedOptions] = useState<any[]>([]);

  function removeDuplicates(arr: any[]): any[] {
    const objectCounts = new Map();
    arr.forEach((item) => {
      const serializedItem = JSON.stringify(item);
      const count = objectCounts.get(serializedItem) || 0;
      objectCounts.set(serializedItem, count + 1);
    });

    return arr.filter((item) => {
      const serializedItem = JSON.stringify(item);
      const count = objectCounts.get(serializedItem);
      return count === 1;
    });
  }

  // Update the selected options when the user makes a selection
  const handleSelectChange = (event: any, newValue: any) => {
    const deduplicatedArray = removeDuplicates(newValue);
    console.log(deduplicatedArray, 'kkkkkkkk');
    setSelectedOptions(deduplicatedArray);
  };

  return (
    <ThemeProvider theme={muiTheme}>
      <Select
        componentStylePropSx={{}}
        selectType='chip'
        customProps={{
          rootStyleSx: {
            background: '',
          },
          inputRootStyleSx: {
            '& div': {
              background: '',
              color: '',
            },
          },
          selectParentSx: {},
          limitTags: 3,
          multiple: true,
          value: selectedOptions,
          isClearIcon: true,
          onClearTag: () => {
            setSelectedOptions([]);
          },
          islabel: true,
          label: 'select',
          handleChange: handleSelectChange,
          options: [
            { label: 'Option 1', value: 1994 },
            { label: 'Option 2', value: 1972 },
            { label: 'Option 3', value: 1974 },
            { label: 'Option 4', value: 2008 },
            { label: 'Option 5', value: 1957 },
            { label: 'Option 6', value: 1993 },
            { label: 'Option 7', value: 1994 },
          ],,
          selectId: 'select',
          dropdownMinHeight: '200px',
          dropdownMaxWidth: '',
          dropdownMinWidth: '',
          dropdownMaxHeight: '',
          inputMinHeight: '',
          inputMaxWidth: '',
          inputMinWidth: '',
          inputMaxHeight: '',
          inputBackgroundColor: 'red',
          inputBorder: '1px solid blue',
          inputBorderRadius: '8px',
          inputPropsSx: {},
          inputStartEndornment: <SearchIcon width={'18px'} color='red' />,
          labelPropsSx: {},
          inputEndEndornment: <ArrowDown width={'18px'} color='red' />,
          checkedIconProp: null,
          unCheckedIconProp: null,
          hoverBgColor: '',
          hoverColor: 'blue',
          background: '',
          borderRadiusChip: '3px',
          inputColor: 'black',
          groupHeadColor: 'grey',
          listItemfontSize: '',
        }}
      />
  );
}
export default App;

Props

PropTypeDefault ValueDescription
componentStylePropSxObject{}Custom styling for the component.
selectTypeString'default'Type of select component.
customPropsObject{}customProps containing various custom properties:

customProps contain these props ,

PropTypeDefault ValueDescription
rootStyleSxObject{ background: '' }Custom styling for the root element.
inputRootStyleSxObject{ '& div': { background: '', color: '' } }Custom styling for the input root element, including nested elements.
selectParentSxObject{}Custom styling for the select parent element.
limitTagsNumber3Maximum number of tags to display.
multipleBooleantrueAllow multiple selections (true/false).
valueArray[]Selected options.
isClearIconBooleantrueShow clear icon for tags (true/false).
onClearTagFunction() => { setSelectedOptions([]); }Callback function when clearing a tag.
islabelBooleantrueShow label (true/false).
labelString'select'Label text.
handleChangeFunctionhandleSelectChangeCallback function for handling select changes.
optionsArraySee exampleAn array of option objects with label and value.
selectIdString'select'ID for the select element.
dropdownMinHeightString'200px'Minimum height of the dropdown.
dropdownMaxWidthString''Maximum width of the dropdown.
dropdownMinWidthString''Minimum width of the dropdown.
dropdownMaxHeightString''Maximum height of the dropdown.
inputMinHeightString''Minimum height of the input element.
inputMaxWidthString''Maximum width of the input element.
inputMinWidthString''Minimum width of the input element.
inputMaxHeightString''Maximum height of the input element.
inputBackgroundColorString'red'Background color of the input element.
inputBorderString'1px solid blue'Border style of the input element.
inputBorderRadiusString'8px'Border radius of the input element.
inputPropsSxObject{}Custom styling for input props.
inputStartEndornmentJSX Element<SearchIcon width={'18px'} color='red' />Start adornment for the input.
labelPropsSxObject{}Custom styling for label props.
inputEndEndornmentJSX Element<ArrowDown width={'18px'} color='red' />End adornment for the input.
checkedIconPropAnynullCustom icon for checked state.
unCheckedIconPropAnynullCustom icon for unchecked state.
hoverBgColorString''Background color on hover.
hoverColorString'blue'Text color on hover.
backgroundString''Background styling.
borderRadiusChipString'3px'Border radius for chips.
inputColorString'black'Text color of the input.
groupHeadColorString'grey'Color of group headers.
listItemfontSizeString''Font size of list items.