@pikas-ui/select

This package contains a select component that can be used to select an option from a list of options.

This library is based on Radix Ui.

Change Log

Requirements

To use this package, you must install the @pikas-ui/styles package.

Installation

You can install this package using npm, yarn, or pnpm.

npm install @pikas-ui/select
yarn add @pikas-ui/select
pnpm add @pikas-ui/select

Usage

Select

This component is used to select an option from a list of options.

import { Select } from '@pikas-ui/select';

const Example: React.FC = () => {
  return (
    <Select
      defaultValue="option-1-1"
      data={[
        {
          name: 'Option 1',
          items: [
            {
              label: 'Option 1.1',
              value: 'option-1-1',
            },
            {
              label: 'Option 1.2',
              value: 'option-1-2',
            },
          ],
        },
        {
          name: 'Option 2',
          items: [
            {
              label: 'Option 2.1',
              value: 'option-2-1',
            },
            {
              label: 'Option 2.2',
              value: 'option-2-2',
            },
          ],
        },
      ]}
    />
  );
};

Props

PropDescriptionTypeDefault
descriptionThe description of the select.string-
cssCustom css for the component.SelectCSS-
labelThe label of the select.string or ReactNode-
idThe id of the select.string-
valueThe value of the select.string-
hasSearchIf the select has a search.booleanfalse
searchPlaceholderThe placeholder of the search.string-
onChangeThe callback when the select changes.(value: string) => void-
onOpenChangeThe callback when the select opens or closes.(open: boolean) => void-
defaultOpenIf the select is open by default.booleanfalse
directionThe direction of the select.SelectDirections-
textErrorThe error of the select.string-
ariaLabelThe aria-label of the select.string-
outlineIf the select has an outline.booleantrue
backgroundColorNameThe background color of the select.string-
boxShadowThe box shadow of the select.string-
borderRadiusThe border radius of the select.string-
borderColorNameThe border color of the select.string-
borderWidthThe border width of the select.number-
fontSizeThe font size of the select.string-
paddingThe padding of the select.SelectPadding-
dataThe data of the select.SelectData-
widthThe width of the select.string or number"100%"
maxWidthThe max width of the select.string or number"100%"
minWidthThe min width of the select.string or number-
requiredThe required of the select.booleanfalse
infoAdd a info icon with a tooltip.string-
disabledIf the select is disabled.booleanfalse
placeholderThe placeholder of the select.string-

Reference

You can use the ref prop to get the select reference.

import type { SelectRef } from '@pikas-ui/select';
import { Select } from '@pikas-ui/select';
import { useRef } from 'react';
import { Button } from '@pikas-ui/button';

const Example: React.FC = () => {
  const selectRef = useRef<SelectRef>(null);

  return (
    <>
      <Select
        ref={selectRef}
        defaultValue="option-1"
        data={[
          {
            items: [
              {
                label: 'Option 1',
                value: 'option-1',
              },
              {
                label: 'Option 2',
                value: 'option-2',
              },
            ],
          },
        ]}
      />
      <Button
        onClick={(): void => {
          selectRef.current?.setValue('option-1');
        }}
      >
        Set Option 1
      </Button>
      <Button
        onClick={(): void => {
          selectRef.current?.setValue('option-2');
        }}
      >
        Set Option 2
      </Button>
    </>
  );
};
RefDescriptionTypeDefault
setValueSet the value of the select.(value: string) => void-

Contributing

This documentation can be edited on GitHub here