Skip to content

Commit 1611b50

Browse files
saalto-itcsandman
andauthored
fix: update type definitions to use ConditionalValue for color palette props (#362)
* fix: update type definitions to use ConditionalValue for color palette props * Fix the new color palette prop typing --------- Co-authored-by: Chris Sandvik <[email protected]>
1 parent 870c8ff commit 1611b50

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

src/chakra-components/multi-value.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import type { ColorPalette, SystemStyleObject } from "@chakra-ui/react";
1+
import type { SystemStyleObject } from "@chakra-ui/react";
22
import { Span, useChakraContext, useSlotRecipe } from "@chakra-ui/react";
33
import type {
44
GroupBase,
55
MultiValueGenericProps,
66
MultiValueProps,
77
MultiValueRemoveProps,
88
} from "react-select";
9-
import type { TagVariant } from "../types";
9+
import type { ColorPaletteProp, TagVariant } from "../types";
1010
import { CloseIcon } from "./icons";
1111

1212
const hasColorPalette = (
1313
option: unknown
14-
): option is { colorPalette: ColorPalette } =>
14+
): option is { colorPalette: ColorPaletteProp } =>
1515
typeof option === "object" &&
1616
option !== null &&
1717
"colorPalette" in option &&
@@ -52,7 +52,7 @@ export const MultiValue = <
5252
const { colorPalette: themeTagColorPalette, variant: defaultTagVariant } =
5353
chakraContext.getSlotRecipe("tag").defaultVariants ?? {};
5454

55-
let optionColorPalette: ColorPalette | undefined = themeTagColorPalette;
55+
let optionColorPalette: ColorPaletteProp = themeTagColorPalette;
5656
if (hasColorPalette(data)) {
5757
optionColorPalette = data.colorPalette;
5858
} else if (tagColorPalette) {

src/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
2-
import type {
3-
ColorPalette,
4-
SpinnerProps,
5-
SystemStyleObject,
6-
} from "@chakra-ui/react";
2+
import type { SpinnerProps, SystemStyleObject } from "@chakra-ui/react";
73
import type { GroupBase, StylesConfig, ThemeConfig } from "react-select";
84
import type {
95
ChakraStylesConfig,
6+
ColorPaletteProp,
107
SelectedOptionStyle,
118
SizeProp,
129
TagVariant,
@@ -86,8 +83,9 @@ declare module "react-select/base" {
8683
* @see {@link https://github.com/csandman/chakra-react-select#colorscheme}
8784
* @see {@link https://www.chakra-ui.com/docs/components/tag#colors}
8885
* @see {@link https://www.chakra-ui.com/docs/styling/virtual-color}
86+
* @see {@link https://github.com/chakra-ui/chakra-ui/blob/9ecae5c/packages/react/src/styled-system/generated/system.gen.ts#L688}
8987
*/
90-
tagColorPalette?: ColorPalette;
88+
tagColorPalette?: ColorPaletteProp;
9189

9290
/**
9391
* The `variant` prop that will be forwarded to your `MultiValue` component
@@ -122,8 +120,9 @@ declare module "react-select/base" {
122120
* @defaultValue `blue`
123121
* @see {@link https://github.com/csandman/chakra-react-select#selectedoptioncolorpalette--default-blue}
124122
* @see {@link https://www.chakra-ui.com/docs/theming/customization/colors}
123+
* @see {@link https://github.com/chakra-ui/chakra-ui/blob/9ecae5c/packages/react/src/styled-system/generated/system.gen.ts#L688}
125124
*/
126-
selectedOptionColorPalette?: ColorPalette;
125+
selectedOptionColorPalette?: ColorPaletteProp;
127126

128127
/**
129128
* The color value to style the border of the `Control` with when the
@@ -207,8 +206,9 @@ declare module "react-select" {
207206
* The color palette of the filled in area of the spinner.
208207
*
209208
* @see {@link https://www.chakra-ui.com/docs/components/spinner#colors}
209+
* @see {@link https://github.com/chakra-ui/chakra-ui/blob/9ecae5c/packages/react/src/styled-system/generated/system.gen.ts#L688}
210210
*/
211-
colorPalette?: ColorPalette;
211+
colorPalette?: ColorPaletteProp;
212212

213213
/**
214214
* The color of the filled in area of the spinner.

src/types.ts

+10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type {
2+
ColorPalette,
3+
ConditionalValue,
24
SelectRootProps,
35
SystemStyleObject,
46
TagRootProps,
@@ -26,6 +28,14 @@ import type {
2628
ValueContainerProps,
2729
} from "react-select";
2830

31+
export type CssVars = `var(--${string})`;
32+
33+
export type AnyString = string & {};
34+
35+
export type ColorPaletteProp = ConditionalValue<
36+
ColorPalette | CssVars | AnyString
37+
>;
38+
2939
export interface SizeProps<PropType extends string | number = string | number> {
3040
sm: PropType;
3141
md: PropType;

src/use-chakra-select-props.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import type { ColorPalette } from "@chakra-ui/react";
21
import { useFieldContext } from "@chakra-ui/react";
32
import type { GroupBase, Props } from "react-select";
43
import chakraComponents from "./chakra-components";
5-
import type { SelectedOptionStyle, UseFieldReturn } from "./types";
4+
import type {
5+
ColorPaletteProp,
6+
SelectedOptionStyle,
7+
UseFieldReturn,
8+
} from "./types";
69

710
const useChakraSelectProps = <
811
Option,
@@ -42,7 +45,7 @@ const useChakraSelectProps = <
4245
}
4346

4447
// Ensure that the color used for the selected options is a string
45-
let realSelectedOptionColorPalette: ColorPalette =
48+
let realSelectedOptionColorPalette: ColorPaletteProp =
4649
selectedOptionColorPalette || "blue";
4750
if (typeof realSelectedOptionColorPalette !== "string") {
4851
realSelectedOptionColorPalette = "blue";

0 commit comments

Comments
 (0)