From 5eb49f411293fb9a07c0ff94e42efbe1faeb63a3 Mon Sep 17 00:00:00 2001 From: Markus Unger <38430185+markusunger@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:35:26 +0200 Subject: [PATCH] feat: add support for multiple default options (#263) * feat: add support for multiple default options * docs: add usage example * docs: update prop list * docs: update v2 changelog * chore: add changeset --- .changeset/loud-comics-learn.md | 5 ++ apps/expo/src/constants/routes.ts | 5 ++ .../multiselect-with-default-options.tsx | 13 +++++ .../get-default-selection-index.test.ts | 44 ++++++++++++++++ .../helpers/get-default-selection-index.ts | 24 +++++++++ .../src/helpers/index.ts | 1 + .../src/state/reducer.ts | 34 +++++++------ .../src/state/types.ts | 2 +- .../src/types/types.ts | 4 +- website/docs/api/select.mdx | 40 +++++++-------- website/docs/usage.md | 50 +++++++++++++++++++ website/docs/v2.mdx | 2 + 12 files changed, 187 insertions(+), 37 deletions(-) create mode 100644 .changeset/loud-comics-learn.md create mode 100644 apps/expo/src/examples/multiselect-with-default-options.tsx create mode 100644 packages/react-native-select-pro/src/helpers/__tests__/get-default-selection-index.test.ts create mode 100644 packages/react-native-select-pro/src/helpers/get-default-selection-index.ts diff --git a/.changeset/loud-comics-learn.md b/.changeset/loud-comics-learn.md new file mode 100644 index 00000000..6a79e72b --- /dev/null +++ b/.changeset/loud-comics-learn.md @@ -0,0 +1,5 @@ +--- +'@mobile-reality/react-native-select-pro': minor +--- + +Added support for multiple defaultOption objects diff --git a/apps/expo/src/constants/routes.ts b/apps/expo/src/constants/routes.ts index 131b9722..ba8fecf9 100644 --- a/apps/expo/src/constants/routes.ts +++ b/apps/expo/src/constants/routes.ts @@ -8,6 +8,7 @@ import { CustomStyles } from '../examples/custom-styles'; import { ModalExample } from '../examples/modal-example'; import { MultiSelect } from '../examples/multiselect'; import { MultiSelectSearchableWithSeparatedOptions } from '../examples/multiselect-searchable-with-separated-options'; +import { MultiSelectWithDefaultOptions } from '../examples/multiselect-with-default-options'; import { MultiSelectWithHiddenOptions } from '../examples/multiselect-with-hidden-options'; import { MultiSelectWithSearchable } from '../examples/multiselect-with-searchable'; import { MultiSelectWithSeparatedOptions } from '../examples/multiselect-with-separated-options'; @@ -115,6 +116,10 @@ export const ROUTES = [ name: 'MultiSelect with Hidden Options', screen: MultiSelectWithHiddenOptions, }, + { + name: 'MultiSelect with Default Options', + screen: MultiSelectWithDefaultOptions, + }, { name: 'TextInputProps', screen: TextInputProps, diff --git a/apps/expo/src/examples/multiselect-with-default-options.tsx b/apps/expo/src/examples/multiselect-with-default-options.tsx new file mode 100644 index 00000000..7d3608ec --- /dev/null +++ b/apps/expo/src/examples/multiselect-with-default-options.tsx @@ -0,0 +1,13 @@ +import React from 'react'; +import { Select } from '@mobile-reality/react-native-select-pro'; + +import { SafeAreaViewWrapper } from '../components/safe-area-view-wrapper'; +import { DATA } from '../constants/data'; + +export const MultiSelectWithDefaultOptions = () => { + return ( + + +