Skip to content

Commit f9e87a0

Browse files
authored
feat: Change selectedOptionColorPalette values pulled from the theme (#364)
* Change selectedOptionColorPalette selected values * Add consistent-type-imports eslint rule
1 parent 9dc874b commit f9e87a0

File tree

14 files changed

+106
-57
lines changed

14 files changed

+106
-57
lines changed
36.1 KB
Loading
38.7 KB
Loading

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,13 @@ If you choose to stick with the default `selectedOptionStyle="color"`, you have
344344
one additional styling option. If you do not like the default of blue for the
345345
highlight color, you can pass the `selectedOptionColorPalette` prop to change
346346
it. This prop will accept any named color from your theme's color palette, and
347-
it will use the `500` value in light mode or the `300` value in dark mode.
347+
it will use `colorPalette.solid` for the background, and `colorPalette.contrast`
348+
for the text.
349+
350+
If you'd like to use a custom color palette for this prop, ensure that you have
351+
properly set up the custom color, including the `solid` and `contrast` semantic
352+
tokens, accoring to
353+
[the official guide](https://www.chakra-ui.com/guides/theming-custom-colors).
348354

349355
> [!NOTE]
350356
>

demo/eslint.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ const eslintConfig = tseslint.config(
2525
...react.configs.recommended.rules,
2626
...react.configs["jsx-runtime"].rules,
2727
...reactHooks.configs.recommended.rules,
28+
"@typescript-eslint/consistent-type-imports": [
29+
"warn",
30+
{
31+
prefer: "type-imports",
32+
disallowTypeAnnotations: true,
33+
},
34+
],
2835
"react/prop-types": "off",
2936
"react-refresh/only-export-components": [
3037
"warn",

demo/src/app.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import {
1010
Stack,
1111
Text,
1212
} from "@chakra-ui/react";
13+
import type { GroupBase, LoadingIndicatorProps } from "chakra-react-select";
1314
import {
1415
AsyncSelect,
1516
CreatableSelect,
16-
GroupBase,
17-
LoadingIndicatorProps,
1817
Select,
1918
chakraComponents,
2019
} from "chakra-react-select";
2120
import ConnectedSelectMenuExample from "./components/advanced-examples/connected-select-menu-example";
2221
import CustomIndicatorIconsExample from "./components/advanced-examples/custom-indicator-icons-example";
22+
import DynamicSelectedOptionColorExample from "./components/advanced-examples/dynamic-selected-option-color-example";
2323
import MenuPortalTargetExample from "./components/advanced-examples/menu-portal-target-example";
2424
import OptionsWithIconsExample from "./components/advanced-examples/options-with-icons-example";
2525
import SelectPopoverExample from "./components/advanced-examples/select-popover-example";
@@ -35,7 +35,8 @@ import {
3535
SelectValueText,
3636
} from "./components/ui/select";
3737
import animeMovies from "./data/anime-movies";
38-
import { ColorOption, colorOptions, groupedOptions } from "./data/options";
38+
import type { ColorOption } from "./data/options";
39+
import { colorOptions, groupedOptions } from "./data/options";
3940

4041
const mappedColorOptions = colorOptions.map((option) => ({
4142
...option,
@@ -354,6 +355,16 @@ const App = () => {
354355
/>
355356
</Field>
356357

358+
<Field
359+
label={
360+
<Span>
361+
Single Select with dynamic <Code>selectedOptionColorPalette</Code>
362+
</Span>
363+
}
364+
>
365+
<DynamicSelectedOptionColorExample />
366+
</Field>
367+
357368
<Field
358369
label={
359370
<Span>

demo/src/components/advanced-examples/custom-indicator-icons-example.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
import {
2-
GroupBase,
3-
Select,
4-
SelectComponentsConfig,
5-
chakraComponents,
6-
} from "chakra-react-select";
1+
import type { GroupBase, SelectComponentsConfig } from "chakra-react-select";
2+
import { Select, chakraComponents } from "chakra-react-select";
73
import { LuArrowDown, LuCircleX } from "react-icons/lu";
84
import { groupedOptions } from "../../data/options";
95

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { useState } from "react";
2+
import { Select } from "chakra-react-select";
3+
import type { ColorOption } from "../../data/options";
4+
import { colorOptions } from "../../data/options";
5+
6+
const DynamicSelectedOptionColorExample = () => {
7+
const [selectedOptionColorPalette, setSelectedOptionColorPalette] =
8+
useState<ColorOption | null>(colorOptions[0]);
9+
10+
return (
11+
<Select
12+
name="colors"
13+
options={colorOptions}
14+
placeholder="Select a color..."
15+
closeMenuOnSelect={false}
16+
value={selectedOptionColorPalette}
17+
onChange={setSelectedOptionColorPalette}
18+
selectedOptionColorPalette={selectedOptionColorPalette?.value}
19+
/>
20+
);
21+
};
22+
23+
export default DynamicSelectedOptionColorExample;

demo/src/components/advanced-examples/menu-portal-target-example.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useState } from "react";
22
import { Stack } from "@chakra-ui/react";
3-
import { Select, Props as SelectProps } from "chakra-react-select";
3+
import type { Props as SelectProps } from "chakra-react-select";
4+
import { Select } from "chakra-react-select";
45
import { colorOptions } from "../../data/options";
56
import { Button } from "../ui/button";
67
import {

demo/src/components/advanced-examples/select-popover-example.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { useRef, useState } from "react";
22
import { Icon } from "@chakra-ui/react";
3-
import {
3+
import type {
44
ChakraStylesConfig,
5-
Select,
65
SelectInstance,
76
SingleValue,
87
} from "chakra-react-select";
8+
import { Select } from "chakra-react-select";
99
import { LuChevronDown, LuSearch } from "react-icons/lu";
10-
import { StateOption, stateOptions } from "../../data/options";
10+
import type { StateOption } from "../../data/options";
11+
import { stateOptions } from "../../data/options";
1112
import { Button } from "../ui/button";
1213
import {
1314
PopoverBody,

demo/src/data/countries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { GroupBase, OptionBase } from "chakra-react-select";
1+
import type { GroupBase, OptionBase } from "chakra-react-select";
22

33
export interface CountryOption extends OptionBase {
44
label: string;

0 commit comments

Comments
 (0)