diff --git a/docs/docs/components/select.mdx b/docs/docs/components/select.mdx
index c89e468..6e13697 100644
--- a/docs/docs/components/select.mdx
+++ b/docs/docs/components/select.mdx
@@ -13,7 +13,7 @@ import { Select } from "@hover-design/react";
### Code Snippets and Examples
import "@hover-design/react/dist/style.css";
-import { Select } from "@hover-design/react";
+import { Select, Loader } from "@hover-design/react";
import { useState } from "react";
##### Select Default
@@ -146,6 +146,67 @@ const options = [
]}
/>
+##### Select Loading
+
+```jsx
+const options = [
+ { label: "First", value: "first" },
+ { label: "Second", value: "second", disabled: true },
+ { label: "Third", value: "third" },
+ { label: "Fourth", value: "fourth" },
+];
+
+
+
+
;
+```
+
+
+
+##### Select with Loading Options
+
+```jsx
+const options = [
+ { label: "First", value: "first" },
+ { label: "Second", value: "second", disabled: true },
+ { label: "Third", value: "third" },
+ { label: "Fourth", value: "fourth" },
+];
+
+const loadingOptions = {
+ loadingContent: "Data is Loading",
+ loader: ,
+ }
+
+
+
+
;
+```
+
+,
+ }}
+ options={[
+ { label: "First", value: "first" },
+ { label: "Second", value: "second", disabled: true },
+ { label: "Third", value: "third" },
+ { label: "Fourth", value: "fourth" },
+ ]}
+/>
+
##### Select Disabled
```jsx
@@ -263,6 +324,8 @@ const options = [
| DropIcon | `JSX Element` | | Yes |
| onDropDownOpen | `()=> void ` | | Yes |
| onDropDownClose | `()=> void ` | | Yes |
+| isLoading | `boolean` | `false` | Yes |
+| loadingOptions | **[Loading Options](#loading-option)** | `false` | Yes |
### Option Object
@@ -273,6 +336,13 @@ const options = [
| disabled | `boolean` | Yes |
| ref | `MutableRefObject` | Yes |
+### Loading Option
+
+| Key | type | Optional ? |
+| :------------- | :---------: | ---------: |
+| loadingContent | `ReactNode` | Yes |
+| loader | `ReactNode` | Yes |
+
### Keyboard Controls
> Keyboard controls will only work when the ** Select ** is focused (selected)
diff --git a/lib/src/components/Select/Select.tsx b/lib/src/components/Select/Select.tsx
index 1b2a954..eb65017 100644
--- a/lib/src/components/Select/Select.tsx
+++ b/lib/src/components/Select/Select.tsx
@@ -27,9 +27,11 @@ import {
noDataFoundStyles,
selectPlaceholderRecipe,
inputRecipe,
+ loadingContentContainer,
} from "./select.css";
import { SelectPropsType, OptionsType } from "./select.types";
import "./select.global.styles.css";
+import { Loader } from "../Loader";
const SelectComponent: ForwardRefRenderFunction<
HTMLDivElement,
@@ -55,6 +57,8 @@ const SelectComponent: ForwardRefRenderFunction<
style,
onDropDownClose = () => {},
onDropDownOpen = () => {},
+ isLoading = false,
+ loadingOptions,
},
ref
) => {
@@ -379,6 +383,52 @@ const SelectComponent: ForwardRefRenderFunction<
isMulti,
});
+ const renderDropDown = () => {
+ return Array.isArray(internalOptions) && internalOptions?.length !== 0 ? (
+ internalOptions.map((option, ind) => {
+ const selectListClass = selectListRecipe({
+ disabled: option.disabled,
+ active:
+ !isMulti &&
+ !Array.isArray(selectValue) &&
+ option.value === selectValue?.value,
+ });
+ return (
+
+ !option.disabled && internalClickHandler(option, event)
+ }
+ onMouseEnter={(event) => {
+ if (!option.disabled) {
+ setCursor(ind);
+ focusElement(ind);
+ }
+ }}
+ onMouseLeave={(event) => {
+ event.currentTarget.setAttribute("data-hover", "false");
+ }}
+ >
+ {option.label}
+
+ );
+ })
+ ) : (
+
+ {checkIfAllValuesSelected()
+ ? "No more Data!"
+ : nothingFoundLabel || "Nothing Found!"}
+
+ );
+ };
+
useClickOutside(
selectRef,
() => {
@@ -462,17 +512,20 @@ const SelectComponent: ForwardRefRenderFunction<
))}
-
-
- {DropIcon
- ? !isClearable && DropIcon
- : !isClearable && }
- {isClearable && }
-
+ {!isLoading ? (
+
+ {DropIcon
+ ? !isClearable && DropIcon
+ : !isClearable && }
+ {isClearable && }
+
+ ) : (
+ loadingOptions?.loader ||
+ )}
{isDropped && (
@@ -482,48 +535,11 @@ const SelectComponent: ForwardRefRenderFunction<
className={`${selectListContainerStyle}`}
role={"listbox"}
>
- {Array.isArray(internalOptions) && internalOptions?.length !== 0 ? (
- internalOptions.map((option, ind) => {
- const selectListClass = selectListRecipe({
- disabled: option.disabled,
- active:
- !isMulti &&
- !Array.isArray(selectValue) &&
- option.value === selectValue?.value,
- });
- return (
-
- !option.disabled && internalClickHandler(option, event)
- }
- onMouseEnter={(event) => {
- if (!option.disabled) {
- setCursor(ind);
- focusElement(ind);
- }
- }}
- onMouseLeave={(event) => {
- event.currentTarget.setAttribute("data-hover", "false");
- }}
- >
- {option.label}
-
- );
- })
+ {!isLoading ? (
+ renderDropDown()
) : (
-
- {checkIfAllValuesSelected()
- ? "No more Data!"
- : nothingFoundLabel || "Nothing Found!"}
+
+ {loadingOptions?.loadingContent || "Loading..."}
)}
diff --git a/lib/src/components/Select/select.css.ts b/lib/src/components/Select/select.css.ts
index f4ad8f8..ec801f2 100644
--- a/lib/src/components/Select/select.css.ts
+++ b/lib/src/components/Select/select.css.ts
@@ -169,3 +169,8 @@ export const inputTextContainer = style({
overflow: "hidden",
height: "100%",
});
+
+export const loadingContentContainer = style({
+ padding: "10px 16px",
+ cursor: "default",
+});
diff --git a/lib/src/components/Select/select.types.ts b/lib/src/components/Select/select.types.ts
index 021d6ca..c54a183 100644
--- a/lib/src/components/Select/select.types.ts
+++ b/lib/src/components/Select/select.types.ts
@@ -1,4 +1,4 @@
-import { KeyboardEvent, MouseEvent, MutableRefObject } from "react";
+import { KeyboardEvent, MouseEvent, MutableRefObject, ReactNode } from "react";
type divType = Omit
;
export type SelectPropsType = divType & {
placeholder?: string;
@@ -24,6 +24,11 @@ export type SelectPropsType = divType & {
error?: boolean | string;
onDropDownClose?: () => void;
onDropDownOpen?: () => void;
+ isLoading?: boolean;
+ loadingOptions?: {
+ loadingContent?: ReactNode;
+ loader?: ReactNode;
+ };
};
export type OptionsType = {