Skip to content

Commit 0ef8977

Browse files
committed
create select styles context in a different file for better bundle generation
1 parent 18b97ac commit 0ef8977

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

src/components/Select/context.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { createStylesContext, type SystemStyleObject } from "@chakra-ui/react"
2+
3+
import { reactSelectAnatomyKeys } from "./innerComponents"
4+
5+
const [ReactSelectStylesProvider, useReactSelectStyles] =
6+
createStylesContext("ReactSelect")
7+
8+
export const SelectStylesProvider = ReactSelectStylesProvider
9+
10+
export const useSelectStyles = useReactSelectStyles as () => Record<
11+
(typeof reactSelectAnatomyKeys)[number],
12+
SystemStyleObject
13+
>

src/components/Select/index.tsx

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
11
import ReactSelect, { ActionMeta, GroupBase, Props } from "react-select"
2-
import {
3-
createStylesContext,
4-
type SystemStyleObject,
5-
ThemingProps,
6-
useMultiStyleConfig,
7-
} from "@chakra-ui/react"
2+
import { ThemingProps, useMultiStyleConfig } from "@chakra-ui/react"
83

9-
import { components, reactSelectAnatomyKeys } from "./innerComponents"
10-
11-
const [ReactSelectStylesProvider, useReactSelectStyles] =
12-
createStylesContext("ReactSelect")
13-
14-
export const useSelectStyles = useReactSelectStyles as () => Record<
15-
(typeof reactSelectAnatomyKeys)[number],
16-
SystemStyleObject
17-
>
4+
import { SelectStylesProvider } from "./context"
5+
import { components } from "./innerComponents"
186

197
/**
208
* Type for onChange handler in the `Select` component
@@ -60,7 +48,7 @@ const Select = <
6048
variant,
6149
})
6250
return (
63-
<ReactSelectStylesProvider value={styles}>
51+
<SelectStylesProvider value={styles}>
6452
<ReactSelect
6553
components={components}
6654
styles={{
@@ -75,7 +63,7 @@ const Select = <
7563
unstyled
7664
menuPlacement="bottom"
7765
/>
78-
</ReactSelectStylesProvider>
66+
</SelectStylesProvider>
7967
)
8068
}
8169

src/components/Select/innerComponents.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
} from "react-select"
1212
import { Box, Center, HStack, Icon } from "@chakra-ui/react"
1313

14-
import { useSelectStyles } from "."
14+
import { useSelectStyles } from "./context"
1515

1616
export const reactSelectAnatomyKeys = [
1717
"container",

0 commit comments

Comments
 (0)