4.1.2 • Published 7 days ago

@availity/select v4.1.2

Weekly downloads
125
License
MIT
Repository
github
Last release
7 days ago

@availity/select

Wrapper for react-select-async-paginate to work with formik

Installation

npm install @availity/select @availity/api-axios @availity/api-core @availity/form formik react reactstrap --save

Validation

See yup and @availity/yup

Select (Default Export)

Select dropdown without a Label or Feedback

Select Usage

import React from 'react';
import { Form } from '@availity/form';
import Select from '@availity/select';
import * as yup from 'yup';
import '@availity/yup';

// ...
const schema = yup.object().shape({
  justTheInput: yup.string().required('This field is required.'),
});

const options = [
  {label: "Option 1", value: 1},
  {label: "Option 2", value: 2},
  {label: "Option 3", value: 3},
];

return (
  <Form
    initialValues={{
      justTheInput: undefined,
    }}
    onSubmit={values => apiResource.submit(values)}
    validationSchema={schema}
  >
    <Select
      id="justTheInput"
      name="justTheInput"
      isMulti={false}
      options={options}
    />

    <Button color="primary" type="submit">
      Submit
    </Button>
  </Form>
);

Select Props

See react-select-async-paginate for additional props

  • name: String. Required. The name of the field. Will be the key of the selected option(s) that come through in the values of the onSubmit callback.
  • raw: Boolean. Optional. Default: false. If true, the entire object of the selected value will be returned as the value instead of the value for the valueKey within the object.
  • valueKey: String. Optional. The key of the value you want returned when selected. Default: value
  • labelKey: String. Optional. The key for the label you want to appear in the dropdown for the user to see. Default label
  • maxLength: Number. Optional. The maximum number of options that can be selected (when isMulti is true)
  • selectRef: Function or Node. Optional. Ref passed to react-select-async-paginate component
  • className: Additional styles to be added to the <Select />

SelectField

The same as Select but with a Label that appears above the input and a Feedback that appears below the input.

SelectField Usage

import React from 'react';
import { Form } from '@availity/form';
import { SelectField } from '@availity/select';
import * as yup from 'yup';
import '@availity/yup';

// ...
const schema = yup.object().shape({
  justTheInput: yup
    .array()
    .of(yup.string())
    .min(min, 'Must select at least 2 options')
    .max(max, 'Cannot select more than 4 options')
    .required('This field is required.'),
});

const options = [
  {label: "Option 1", value: 1},
  {label: "Option 2", value: 2},
  {label: "Option 3", value: 3},
];

return (
  <Form
    initialValues={{
      selectWithLabel: undefined,
    }}
    onSubmit={values => apiResource.submit(values)}
    validationSchema={schema}
  >
    <SelectField
      label="Select a value"
      id="selectWithLabel"
      name="selectWithLabel"
      isMulti
      options={options}
    />

    <Button color="primary" type="submit">
      Submit
    </Button>
  </Form>
);

SelectField Props

Same as Select, with the following additional props:

  • label: Node. Optional. The label to render above the Select input
  • labelHidden: Boolean. Optional. Whether the label should be hidden
  • labelClass: String. Optional. classNames to pass to the Label
  • feedbackClass: String. Optional. classNames to pass to the Feedback
  • groupClass: String. Optional. classNames to pass to the FormGroup

ResourceSelect

A select list which automatically loads and pages through a resource when the user scrolls down.

ResourceSelect Usage

import React from 'react';
import { Form } from '@availity/form';
import { ResourceSelect } from '@availity/select';
import * as yup from 'yup';
import '@availity/yup';

// ...
const schema = yup.object().shape({
  resourceSelect: yup.string().required('This field is required.'),
});

const avCustomResource = new AvApi({ name: 'my-custom-resource' });

return (
  <Form
    initialValues={{
      resourceSelect: '',
    }}
    onSubmit={values => apiResource.submit(values)}
    validationSchema={schema}
  >
    <ResourceSelect
      id="resourceSelect"
      name="resourceSelect"
      resource={avCustomResource}
      isMulti={false}
    />

    <Button color="primary" type="submit">
      Submit
    </Button>
  </Form>
);

ResourceSelect Props

See react-select-async-paginate for additional props

  • raw: Boolean. Optional. Default: true. If true, the entire object of the selected value will be returned as the value instead of the value for the valueKey within the object.
  • valueKey: String. Optional. The key of the value you want returned when selected. Default: value
  • labelKey: String. Optional. The key for the label you want to appear in the dropdown for the user to see. Default label
  • label: String. Optional. If provided, the rendered component will mimic SelectField instead of Select (it will create a group with a label and feedback).
  • requestConfig: Object. Optional. Configuration object which will be used with the query method on the resource. Useful for defining headers to be sent with the request.
  • parameters: Object. Optional. Object which will be used to create querystring parameters in the request.
  • customerId: String. Optional. The value of the customer ID which will be sent in the parameters. Useful for restricting the loaded options to be related to the organization the user has in context.
  • requiredParams: Array of strings. Optional. If present, the network request will not be made until all of the required parameters specified in the array have a truthy value.
  • cacheUniq: Any. Optional. When this prop changes, all cache options are cleared. (see react-select-async-paginate)
  • watchParams: Array of strings. Optional. If present, the options will reset when any of the parameters specified in the array change value. This is useful for when a customerId changes and you need to load a new list of options for the user to choose from. Used to derive cacheUniq if cacheUniq prop is not provided.
  • resource: Availity API resource (see @availity/api-core and @availity/api-axios). Required.
  • getResult: String or Function. Optional. When a function, the function will be called with the API response body/payload and is expected to return an array containing the list of items for the page. When a string, the string is expected to be a simple key used to get the value from the response ("simple" meaning not handling dot-notation for nested objects, if you need that provide a function.)
  • debounceTimeout: Number. default: 350. The amount of time (in milliseconds) to wait after the user has stopped typing before making the network request (debounced input).
  • delay: Number. Default: 350. Set to debounceTimeout if debounceTimeout is not provided. (see react-select-async-paginate)
  • itemsPerPage: Number. Optional. Default: 50. The number of items to fetched be displayed per page when the usr scrolls down.
  • onPageChange: Function. Optional. A callback function to inform you that the user has scrolled to the bottom of the list and more items are loaded. The current input value and the page the user wants to go to will be provided as arguments to the callback function.
  • hasMore: Boolean or Function. Optional. If true, ResourceSelect will attempt to retrieve the next page of results. response.data from axios response is passed as the only argument to hasMore when hasMore is a function. Defaults to: ({ totalCount, limit, offset }) => totalCount > offset + limit;
  • additional: Object. Optional. Additional properties to pass to AsyncPaginate (see react-select-async-paginate).

Pre-made Resource Selects

The follow components exist and can be imported by name from @availity/select/resources

  • AvProviderSelect
  • AvOrganizationSelect
  • AvRegionSelect
  • AvPermissionSelect
  • AvNavigationSelect
  • AvUserSelect

These components are ResourceSelect with pre-configured resource, valueKey, and labelKey to make it easy to use. All of the props for ResourceSelect can be provided to override the defaults of these pre-made components. For some of the components you will want to provide the customerId prop.

Pre-made Resource Selects Example Usage
import React from 'react';
import AvApi from '@availity/api-axios';
import { Form } from '@availity/form';
import {
  AvProviderSelect,
  AvOrganizationSelect,
  AvRegionSelect,
  AvPermissionSelect,
  AvNavigationSelect,
  AvUserSelect,
} from '@availity/select/resources';

const schema = yup.object().shape({
  AvProviderSelect: yup.string().required('This field is required.'),
  AvOrganizationSelect: yup.string().required('This field is required.'),
  AvRegionSelect: yup.string().required('This field is required.'),
  AvPermissionSelect: yup.string().required('This field is required.'),
  AvNavigationSelect: yup.string().required('This field is required.'),
  AvUserSelect: yup.string().required('This field is required.'),
});

// ...
<Form
  initialValues={{
    AvProviderSelect: null,
    AvOrganizationSelect: null,
    AvRegionSelect: null,
    AvPermissionSelect: null,
    AvNavigationSelect: null,
    AvUserSelect: null,
  }}
  onSubmit={values => apiResource.submit(values)}
  validationSchema={schema}
>
    <AvProviderSelect
        name="provider"
        customerId="1234"
        requiredParams={['customerId']}
        watchParams={['customerId']}
        label="Select a provider"
        customerId={customerId}
        required
    />
    <AvOrganizationSelect
        name="organization"
        label="Select a Organization"
        required
    />
    <AvRegionSelect
        name="region"
        label="Select a Region"
        required
    />
    <AvPermissionSelect
        name="permissions"
        label="Select a provider"
        customerId={customerId}
        isMulti
        required
    />
    <AvNavigationSelect
        name="payerSpace"
        label="Select a Payer Space"
        customerId={customerId}
        required
    />
    <AvUserSelect
        name="user"
        label="Select a User"
        customerId={customerId}
    />
</Form>;
4.1.2

7 days ago

4.1.1

2 months ago

4.1.0

5 months ago

4.0.1

6 months ago

4.0.2

6 months ago

4.0.0

7 months ago

3.5.1

8 months ago

3.5.0

1 year ago

3.4.2-alpha.0

1 year ago

3.4.1

1 year ago

3.4.0

1 year ago

3.3.3-alpha.0

1 year ago

3.2.0

2 years ago

3.1.2

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

3.3.1

2 years ago

3.3.0

2 years ago

3.3.2

2 years ago

2.10.0

2 years ago

2.9.1

2 years ago

2.9.0

2 years ago

2.4.0

2 years ago

2.8.0

2 years ago

2.3.2

2 years ago

2.3.1

2 years ago

2.7.0

2 years ago

2.4.1-alpha.5

2 years ago

2.7.1

2 years ago

2.6.1

2 years ago

2.6.0

2 years ago

2.6.3

2 years ago

2.6.2

2 years ago

2.5.0

2 years ago

2.6.5

2 years ago

2.6.4

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.0

2 years ago

2.3.0

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

1.0.6-ts.11

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

1.0.2

3 years ago

1.0.6

2 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

0.20.1

3 years ago

0.20.0

3 years ago

0.18.4

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

0.19.0

3 years ago

0.20.4

3 years ago

0.20.3

3 years ago

0.20.2

3 years ago

0.18.3

3 years ago

0.18.2

3 years ago

0.18.1

3 years ago

0.17.12

3 years ago

0.18.0

3 years ago

0.17.11

3 years ago

0.17.10

3 years ago

0.17.9

3 years ago

0.17.8

3 years ago

0.17.7

3 years ago

0.17.6

3 years ago

0.17.5

3 years ago

0.17.4

3 years ago

0.17.3

3 years ago

0.17.2

3 years ago

0.17.1

3 years ago

0.17.0

3 years ago

0.16.3

4 years ago

0.16.2

4 years ago

0.16.1

4 years ago

0.16.0

4 years ago

0.6.2-alpha.54

4 years ago

0.6.2-alpha.50

4 years ago

0.6.2-alpha.51

4 years ago

0.15.0

4 years ago

0.14.0

4 years ago

0.6.2-alpha.48

4 years ago

0.6.2-alpha.46

4 years ago

0.6.2-alpha.43

4 years ago

0.13.6

4 years ago

0.6.2-alpha.40

4 years ago

0.13.5

4 years ago

0.13.4

4 years ago

0.13.3

4 years ago

0.13.2

4 years ago

0.13.1

4 years ago

0.13.0

4 years ago

0.12.0

4 years ago

0.12.0-alpha.7

4 years ago

0.11.1

4 years ago

0.11.0

4 years ago

0.10.0

4 years ago

0.9.28

4 years ago

0.9.27

4 years ago

0.9.26

4 years ago

0.9.25

4 years ago

0.9.24

4 years ago

0.9.23

4 years ago

0.9.21

4 years ago

0.9.22

4 years ago

0.9.19

4 years ago

0.9.20

4 years ago

0.9.16

4 years ago

0.9.17

4 years ago

0.9.18

4 years ago

0.9.15

4 years ago

0.9.14

4 years ago

0.9.13

4 years ago

0.9.12

4 years ago

0.9.11

4 years ago

0.9.10

4 years ago

0.9.9

4 years ago

0.9.8

4 years ago

0.9.7

4 years ago

0.9.6

4 years ago

0.9.5

4 years ago

0.9.4

4 years ago

0.9.3

4 years ago

0.9.2

4 years ago

0.9.1

4 years ago

1.0.0-alpha.29

4 years ago

0.8.7

4 years ago

0.9.0

4 years ago

0.8.6

4 years ago

0.8.5

4 years ago

0.8.4

4 years ago

0.8.3

4 years ago

0.8.2

4 years ago

0.8.1

4 years ago

0.8.0

4 years ago

0.7.0

4 years ago

0.6.2

4 years ago

0.6.2-alpha.13

4 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.15

5 years ago

0.4.14

5 years ago

0.4.13

5 years ago

0.4.12

5 years ago

0.4.11

5 years ago

0.4.10

5 years ago

0.4.9

5 years ago

0.4.8

5 years ago

0.4.7

5 years ago

0.4.6

5 years ago

0.4.5

5 years ago

0.4.4

5 years ago

0.4.3

5 years ago

0.4.2

5 years ago

0.4.1

5 years ago

0.4.0

5 years ago

0.3.5

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.2

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.1-alpha.572

5 years ago

0.1.1-alpha.571

5 years ago

0.1.1-alpha.548

5 years ago