|
1 | 1 | import {useCallback, useEffect, useMemo, useRef} from 'react'; |
2 | 2 | import type {Theme} from '@emotion/react'; |
| 3 | +import {useTheme} from '@emotion/react'; |
3 | 4 | import styled from '@emotion/styled'; |
4 | 5 | import debounce from 'lodash/debounce'; |
5 | 6 |
|
@@ -60,43 +61,34 @@ const filterOption = (canditate: any, input: any) => |
60 | 61 | const getOptionValue = (option: TeamOption) => option.value; |
61 | 62 |
|
62 | 63 | // Ensures that the svg icon is white when selected |
63 | | -const unassignedSelectStyles: StylesConfig = { |
64 | | - option: (provided, state) => { |
65 | | - // XXX: The `state.theme` is an emotion theme object, but it is not typed |
66 | | - // as the emotion theme object in react-select |
67 | | - const theme = state.theme as unknown as Theme; |
68 | | - |
69 | | - return {...provided, svg: {color: state.isSelected ? theme.white : undefined}}; |
70 | | - }, |
71 | | -}; |
| 64 | +const getUnassignedSelectStyles = (theme: Theme): StylesConfig => ({ |
| 65 | + option: (provided, state) => ({ |
| 66 | + ...provided, |
| 67 | + svg: {color: state.isSelected ? theme.white : undefined}, |
| 68 | + }), |
| 69 | +}); |
72 | 70 |
|
73 | | -const placeholderSelectStyles: StylesConfig = { |
74 | | - input: (provided, state) => { |
75 | | - // XXX: The `state.theme` is an emotion theme object, but it is not typed |
76 | | - // as the emotion theme object in react-select |
77 | | - const theme = state.theme as unknown as Theme; |
78 | | - |
79 | | - return { |
80 | | - ...provided, |
81 | | - display: 'grid', |
82 | | - gridTemplateColumns: 'max-content 1fr', |
83 | | - alignItems: 'center', |
84 | | - gridGap: space(1), |
85 | | - ':before': { |
86 | | - backgroundColor: theme.backgroundSecondary, |
87 | | - height: 24, |
88 | | - width: 24, |
89 | | - borderRadius: 3, |
90 | | - content: '""', |
91 | | - display: 'block', |
92 | | - }, |
93 | | - }; |
94 | | - }, |
| 71 | +const getPlaceholderSelectStyles = (theme: Theme): StylesConfig => ({ |
| 72 | + input: provided => ({ |
| 73 | + ...provided, |
| 74 | + display: 'grid', |
| 75 | + gridTemplateColumns: 'max-content 1fr', |
| 76 | + alignItems: 'center', |
| 77 | + gridGap: space(1), |
| 78 | + ':before': { |
| 79 | + backgroundColor: theme.tokens.background.secondary, |
| 80 | + height: 24, |
| 81 | + width: 24, |
| 82 | + borderRadius: 3, |
| 83 | + content: '""', |
| 84 | + display: 'block', |
| 85 | + }, |
| 86 | + }), |
95 | 87 | placeholder: provided => ({ |
96 | 88 | ...provided, |
97 | 89 | paddingLeft: 32, |
98 | 90 | }), |
99 | | -}; |
| 91 | +}); |
100 | 92 |
|
101 | 93 | interface Props extends ControlProps { |
102 | 94 | onChange: (value: any) => any; |
@@ -139,6 +131,7 @@ export interface TeamOption extends GeneralSelectValue { |
139 | 131 | } |
140 | 132 |
|
141 | 133 | export function TeamSelector(props: Props) { |
| 134 | + const theme = useTheme(); |
142 | 135 | const organization = useOrganization(); |
143 | 136 | const { |
144 | 137 | allowCreate, |
@@ -361,11 +354,11 @@ export function TeamSelector(props: Props) { |
361 | 354 |
|
362 | 355 | const styles = useMemo( |
363 | 356 | () => ({ |
364 | | - ...(includeUnassigned ? unassignedSelectStyles : {}), |
365 | | - ...(multiple ? {} : placeholderSelectStyles), |
| 357 | + ...(includeUnassigned ? getUnassignedSelectStyles(theme) : {}), |
| 358 | + ...(multiple ? {} : getPlaceholderSelectStyles(theme)), |
366 | 359 | ...stylesProp, |
367 | 360 | }), |
368 | | - [includeUnassigned, multiple, stylesProp] |
| 361 | + [includeUnassigned, multiple, stylesProp, theme] |
369 | 362 | ); |
370 | 363 |
|
371 | 364 | useEffect(() => { |
|
0 commit comments