3.0.0 • Published 4 years ago

@opuscapita/react-async-select v3.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
4 years ago

react-async-select

Description

This component is a combination of a combobox with asynchronous fetching of results and a modal search dialog for more filtering possibilities.

Installation

npm install @opuscapita/react-async-select

Demo

View the DEMO

Builds

UMD

The default build with compiled styles in the .js file. Also minified version available in the lib/umd directory.

CommonJS/ES Module

You need to configure your module loader to use cjs or es fields of the package.json to use these module types. Also you need to configure sass loader, since all the styles are in sass format.

API

Prop nameTypeDefaultDescription
valueanyThe initially selected value
onSelectfunction() => {}Selection callback function
loadOptionsfunction() => Promise.resolve([])Function for fetching options for the combobox
isDisabledbooleanfalseDisables the component from user interaction
localizationTextsobjectA dictionary with translated texts as values
localizationTexts."searchBy"stringUI text prefix for the first search field
localizationTexts."by"stringUI text prefix for other search fields
localizationTexts."close"stringUI text for the Close-button
localizationTexts."select"stringUI text for the Select-button
localizationTexts."field.XYZ"stringLabel for the search field with name "XYZ"
localizationTexts."column.XYZ"stringHeader for the column with name "XYZ"
localizationTexts."loading"string'Loading...'Loading placeholder text
localizationTexts."noItems"string'--'Empty result set text for the dropdown
localizationTexts."noData"string'No rows found'Empty result set text for the modal
localizationTexts."previous"string'Previous'Paging text
localizationTexts."next"string'Next'Paging text
localizationTexts."page"string'Page'Paging text
localizationTexts."of"string'of'Paging text
localizationTexts."rows"string'rows'Paging text
localizationTexts."pageJump"string'jump to page'Paging text
localizationTexts."rowsSelector"string'rows per page'Paging text
modalobjectModal dialog specific props
modal.titlestring''Localized title of the modal
modal.fieldsstring[]List of fields to show as columns
modal.loadOptionsfunction() => Promise.resolve({ data: [], totalCount: 0 })Function for fetching entries to the table
modal.componentsobject{}A collection of custom components
modal.components.LeftPanelelementnullCustom component for left side panel
modal.components.RightPanelelementnullCustom component for right side panel
setReffunction() => {}Allows access to select component ref from outside
onKeyDownfunction() => {}Allows handling of keydown events from outside

Code example

import React, { useState } from 'react';
import { Dropdown } from '@opuscapita/react-component-example';

export default class ReactView extends React.Component {
  const [value, setValue] = useState(null);

  render() {
    return (
      <Dropdown
        localizationTexts={{
          searchBy: 'Search by',
          by: 'By',
          close: 'Close',
          select: 'Select',
          "field.fieldName1": 'my field',
          "field.fieldName2": 'another field'
          "column.fieldName1": 'My field',
          "column.fieldName2": 'Another field',
          "previous": "PREV",
          "next": "NEXT",
          "loading": "LOADING",
          "noData": "NODATA",
          "page": "PAGE",
          "of": "OF",
          "rows": "ROWS",
          "pageJump": "JUMP",
          "rowsSelector": "RPP",
        }}
        isDisabled={false}
        value={value}
        loadOptions={
          () => Promise.resolve([
            { label: 'a_DisplayValue', value: 'a' }
            { label: 'b_DisplayValue', value: 'b' }
          ])
        }
        onSelect={value => setValue(value)}
        modal={{
          title: 'Search entries',
          fields: [
            'fieldName1',
            'fieldName2',
          ],
          loadOptions: () => Promise.resolve({
            data: [
              {
                fieldName1: 'a_DisplayValue',
                fieldName2: 'a_AnotherDisplayValue'
                value: 'a'
              },
              {
                fieldName1: 'b_DisplayValue',
                fieldName2: 'b_AnotherDisplayValue'
                value: 'b'
              },
            ],
            totalCount: 0
          }),
          components: {
            LeftPanel: ({ selectedRow }) => (<div></div>),
            RightPanel: ({ selectedRow }) => (<div></div>),
          }
        }}
      />
    );
  }
}
3.0.0

4 years ago

2.6.0

5 years ago

2.5.2

5 years ago

2.5.1

5 years ago

2.5.0

5 years ago

2.4.3

5 years ago

2.4.2

5 years ago

2.4.1

5 years ago

2.4.0

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.0

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.1

6 years ago