New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

chakra-ui-simple-autocomplete

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chakra-ui-simple-autocomplete

A simple autocomplete input built with Chakra UI

  • 2.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
717
decreased by-34.52%
Maintainers
1
Weekly downloads
 
Created
Source

Chakra UI Simple Autocomplete

A simple autocomplete input built with Chakra UI

NPM version Build Status Downloads

Demo

demo

Storybook

Typescript CodeSandbox

Install

npm install chakra-ui-simple-autocomplete

Usage

  • Usage Example with TSX/Typescript
import { Autocomplete, Option } from 'chakra-ui-simple-autocomplete';

const options = [
  { value: 'javascript', label: 'Javascript' },
  { value: 'chakra', label: 'Chakra' },
  { value: 'react', label: 'React' },
  { value: 'css', label: 'CSS' },
];

const AutocompleteWrapper = () => {
  const [result, setResult] = React.useState<Option[]>([]);

  return (
      <Box maxW="md">
        <Autocomplete
          options={options}
          result={result}
          setResult={(options: Option[]) => setResult(options)}
          placeholder="Autocomplete"
        />
      </Box>
  );
};
  • Usage Example with TSX and Formik + Yup
import { Autocomplete, Option } from 'chakra-ui-simple-autocomplete';
import { Badge, Box } from '@chakra-ui/react';

const options = [
  { value: 'javascript', label: 'Javascript' },
  { value: 'chakra', label: 'Chakra' },
  { value: 'react', label: 'React' },
  { value: 'css', label: 'CSS' },
];

const autocompleteSchema = Yup.object().shape({
  tags: Yup.array()
    .of(
      Yup.object().shape({
        value: Yup.string(),
        label: Yup.string(),
      }),
    )
    .min(1),
});

const AutocompleteWrapper = () => {
  const [result, setResult] = React.useState<Option[]>([]);

  return (
    <Formik
      validationSchema={autocompleteSchema}
      initialValues={{ tags: [] }}
      onSubmit={(values) => {
        console.log(values)
      }}>
      {(props) => (
        <Box maxW="md">
          <Field name="tags">
            {({ field, form }: FieldProps) => (
              <Autocomplete
                options={options}
                result={result}
                setResult={(options: Option[]) => {
                  form.setFieldValue('tags', options);
                  setResult(options);
                }}
                placeholder="Autocomplete"
              />
            )}
          </Field>
        </Box>
      )}
    </Formik>
  );
};

Props

PropertyTypeRequiredDescription
optionsOption[]YesAn array of Option to render on the autocomplete
resultOption[]YesState where the selected options are going to be stored
setResult(options: Option[]) => voidYesCallback to be triggered everytime the we add/remove an option from the result
renderBadge(option: Option) => React.ReactNodeNoRenders each selected option
renderCheckIcon(option: Option) => React.ReactNodeNoCustom check icon
renderCreateIcon() => React.ReactNodeNoCustom create icon
placeholderStringNoPlaceholder for the input
colorSchemeStringNoColor scheme to be applied on the input
bgHoverColorStringNoBackground color when hovering the options
allowCreationBooleanNoShow the create new tag option. Default true
notFoundTextStringNo"Not found" text to be displayed if allowCreation is false.
disableRenderBadgeBooleanNoOptional prop for turning off the renderBadge function.

:hammer_and_wrench: Support

Please open an issue for support.

:memo: Contributing

Please contribute using Github Flow. Create a branch, add commits, and open a pull request.

:scroll: License

License: MIT

Keywords

FAQs

Package last updated on 29 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc