Skip to content

Commit

Permalink
Add custom spinner example
Browse files Browse the repository at this point in the history
  • Loading branch information
csandman committed Dec 4, 2024
1 parent c2a04fb commit c5f73d5
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
52 changes: 50 additions & 2 deletions demo/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ import {
Stack,
Text,
} from "@chakra-ui/react";
import { AsyncSelect, CreatableSelect, Select } from "chakra-react-select";
import {
AsyncSelect,
CreatableSelect,
GroupBase,
LoadingIndicatorProps,
Select,
chakraComponents,
} from "chakra-react-select";
import { useColorModeValue } from "./components/ui/color-mode";
import { Field } from "./components/ui/field";
import {
SelectContent,
Expand All @@ -22,7 +30,7 @@ import {
SelectValueText,
} from "./components/ui/select";
import animeMovies from "./data/anime-movies";
import { colorOptions, groupedOptions } from "./data/options";
import { ColorOption, colorOptions, groupedOptions } from "./data/options";

const mappedColorOptions = colorOptions.map((option) => ({
...option,
Expand All @@ -36,6 +44,35 @@ const tagVariantOptions = [
{ value: "subtle", label: "Subtle", variant: "subtle" },
];

const asyncComponents = {
LoadingIndicator: (
props: LoadingIndicatorProps<ColorOption, true, GroupBase<ColorOption>>
) => {
const { color, trackColor } = useColorModeValue(
{
color: "colorPalette.500",
trackColor: "colors.colorPalette.100",
},
{
color: "colorPalette.300",
trackColor: "colors.colorPalette.800",
}
);

return (
<chakraComponents.LoadingIndicator
colorPalette="blue"
color={color}
trackColor={trackColor}
animationDuration="750ms"
spinnerSize="md"
borderWidth="3px"
{...props}
/>
);
},
};

const App = () => {
return (
<Container as="main" maxWidth="lg" mt={8} mb={16}>
Expand Down Expand Up @@ -134,6 +171,17 @@ const App = () => {
/>
</Field>

<Field label="Async Select with Custom Spinner">
<AsyncSelect
placeholder="Select some colors..."
loadOptions={(_inputValue, callback) => {
setTimeout(() => callback(colorOptions), 10000);
}}
components={asyncComponents}
isLoading
/>
</Field>

<Field label="Select with Creatable Options">
<CreatableSelect
isMulti
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ declare module "react-select" {
* The color of the filled in area of the spinner.
*
* Defaults to your Chakra theme's text color.
*
* @example
* ```jsx
* <Spinner color="blue.600"/>
* ```
* @see {@link https://www.chakra-ui.com/docs/components/spinner#custom-color}
*/
color?: string;
Expand All @@ -223,6 +226,10 @@ declare module "react-select" {
*
* This prop populates the CSS variable `--spinner-track-color`
*
* @example
* ```jsx
* <Spinner trackColor="colors.blue.100"/>
* ```
* @see {@link https://www.chakra-ui.com/docs/components/spinner#track-color}
*/
trackColor?: string;
Expand Down

0 comments on commit c5f73d5

Please sign in to comment.