Skip to content

Commit

Permalink
Merge pull request #334 from csandman/feat/use-default-tag-theme-props
Browse files Browse the repository at this point in the history
  • Loading branch information
csandman committed Sep 19, 2024
2 parents 59c02a6 + a271d18 commit af4dd7b
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/use-chakra-select-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ const useChakraSelectProps = <
// eslint-disable-next-line deprecation/deprecation
theme,
size,
tagColorScheme = "gray",
isDisabled,
isInvalid,
isReadOnly,
required,
isRequired,
inputId,
tagVariant,
selectedOptionStyle = "color",
selectedOptionColorScheme = "blue",
variant,
tagColorScheme,
tagVariant,
focusBorderColor,
errorBorderColor,
chakraStyles = {},
Expand All @@ -33,7 +33,12 @@ const useChakraSelectProps = <
...props
}: Props<Option, IsMulti, Group>): Props<Option, IsMulti, Group> => {
const chakraTheme = useTheme();
const { variant: defaultVariant } = chakraTheme.components.Input.defaultProps;
const { variant: defaultVariant = "outline" } =
chakraTheme?.components?.Input?.defaultProps ?? {};
const {
colorScheme: defaultTagColorScheme = "gray",
variant: defaultTagVariant = "subtle",
} = chakraTheme?.components?.Tag?.defaultProps ?? {};

// Combine the props passed into the component with the props that can be set
// on a surrounding form control to get the values of `isDisabled` and
Expand Down Expand Up @@ -65,19 +70,19 @@ const useChakraSelectProps = <
realSelectedOptionColorScheme = "blue";
}

const select: Props<Option, IsMulti, Group> = {
const selectProps: Props<Option, IsMulti, Group> = {
// Allow overriding of custom components
components: {
...chakraComponents,
...components,
},
// Custom select props
tagColorScheme,
size,
tagVariant,
selectedOptionStyle: realSelectedOptionStyle,
selectedOptionColorScheme: realSelectedOptionColorScheme,
variant: variant ?? defaultVariant,
tagColorScheme: tagColorScheme ?? defaultTagColorScheme,
tagVariant: tagVariant ?? defaultTagVariant,
chakraStyles,
focusBorderColor,
errorBorderColor,
Expand All @@ -96,7 +101,7 @@ const useChakraSelectProps = <
"aria-invalid": props["aria-invalid"] ?? inputProps["aria-invalid"],
};

return select;
return selectProps;
};

export default useChakraSelectProps;

0 comments on commit af4dd7b

Please sign in to comment.