diff --git a/types/react-select/package.json b/types/react-select/package.json new file mode 100644 index 00000000000000..d05e1d429e6465 --- /dev/null +++ b/types/react-select/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "@emotion/serialize": "^1.0.0" + } +} diff --git a/types/react-select/src/components/Control.d.ts b/types/react-select/src/components/Control.d.ts index a59ff84cbeb645..97ff4089e00a07 100644 --- a/types/react-select/src/components/Control.d.ts +++ b/types/react-select/src/components/Control.d.ts @@ -1,4 +1,5 @@ import { ComponentType, ReactNode, Ref as ElementRef } from 'react'; +import { CSSObject } from '@emotion/serialize'; import { borderRadius, colors, spacing } from '../theme'; import { CommonProps, GroupTypeBase, OptionTypeBase, PropsWithStyles } from '../types'; @@ -28,7 +29,7 @@ export type ControlProps< }; }; -export function css(state: State): React.CSSProperties; +export function css(state: State): CSSObject; declare const Control: ComponentType>; diff --git a/types/react-select/src/components/Group.d.ts b/types/react-select/src/components/Group.d.ts index e31eee2fad5601..26c436a412c2c9 100644 --- a/types/react-select/src/components/Group.d.ts +++ b/types/react-select/src/components/Group.d.ts @@ -1,4 +1,5 @@ import { ReactNode, ComponentType } from 'react'; +import { CSSObject } from '@emotion/serialize'; import { spacing } from '../theme'; import { CommonProps, GroupTypeBase, OptionTypeBase } from '../types'; @@ -19,7 +20,7 @@ export type GroupProps< GroupType extends GroupTypeBase = GroupTypeBase > = CommonProps & ComponentProps; -export function groupCSS(): React.CSSProperties; +export function groupCSS(): CSSObject; export const Group: ComponentType>; @@ -29,7 +30,7 @@ export type GroupHeadingProps< GroupType extends GroupTypeBase = GroupTypeBase > = CommonProps & Pick; -export function groupHeadingCSS(): React.CSSProperties; +export function groupHeadingCSS(): CSSObject; export const GroupHeading: ComponentType; diff --git a/types/react-select/src/components/Input.d.ts b/types/react-select/src/components/Input.d.ts index 6b0901c9558bb7..38b10fb6cf06c8 100644 --- a/types/react-select/src/components/Input.d.ts +++ b/types/react-select/src/components/Input.d.ts @@ -1,4 +1,5 @@ import { ComponentType, Ref as ElementRef } from 'react'; +import { CSSObject } from '@emotion/serialize'; import { colors, spacing } from '../theme'; @@ -15,7 +16,7 @@ export type InputProps = PropsWithStyles & { className?: string; }; -export function inputCSS(props: InputProps): React.CSSProperties; +export function inputCSS(props: InputProps): CSSObject; export function inputStyle(isHidden: boolean): React.CSSProperties; export const Input: ComponentType; diff --git a/types/react-select/src/components/Menu.d.ts b/types/react-select/src/components/Menu.d.ts index 3f4d9f8d2d459f..37312f2b83cfc7 100644 --- a/types/react-select/src/components/Menu.d.ts +++ b/types/react-select/src/components/Menu.d.ts @@ -1,5 +1,6 @@ import { Component, ReactElement, Ref as ElementRef, ReactNode, ComponentType } from 'react'; import { createPortal } from 'react-dom'; +import { CSSObject } from '@emotion/serialize'; import { animatedScrollTo, getBoundingClientObj, RectType, getScrollParent, getScrollTop, scrollTo } from '../utils'; import { borderRadius, colors, spacing } from '../theme'; @@ -55,7 +56,7 @@ export type MenuProps< menuShouldScrollIntoView: boolean; }; -export function menuCSS(state: MenuState): React.CSSProperties; +export function menuCSS(state: MenuState): CSSObject; export class Menu< OptionType extends OptionTypeBase, @@ -96,15 +97,15 @@ export type MenuListComponentProps< GroupType extends GroupTypeBase = GroupTypeBase > = CommonProps & MenuListProps & MenuListState; -export function menuListCSS(state: MenuState): React.CSSProperties; +export function menuListCSS(state: MenuState): CSSObject; export const MenuList: ComponentType>; // ============================== // Menu Notices // ============================== -export function noOptionsMessageCSS(): React.CSSProperties; -export function loadingMessageCSS(): React.CSSProperties; +export function noOptionsMessageCSS(): CSSObject; +export function loadingMessageCSS(): CSSObject; export type NoticeProps< OptionType extends OptionTypeBase, @@ -151,7 +152,7 @@ interface PortalStyleArgs { rect: RectType; } -export function menuPortalCSS(args: PortalStyleArgs): React.CSSProperties; +export function menuPortalCSS(args: PortalStyleArgs): CSSObject; export class MenuPortal< OptionType extends OptionTypeBase, diff --git a/types/react-select/src/components/MultiValue.d.ts b/types/react-select/src/components/MultiValue.d.ts index 98f5fd6f0bbff4..9b28121e3e05ba 100644 --- a/types/react-select/src/components/MultiValue.d.ts +++ b/types/react-select/src/components/MultiValue.d.ts @@ -1,4 +1,5 @@ import { ComponentType, Component, ReactNode } from 'react'; +import { CSSObject } from '@emotion/serialize'; import { borderRadius, colors, spacing } from '../theme'; import { CommonProps, GroupTypeBase, OptionTypeBase } from '../types'; @@ -21,9 +22,9 @@ export type MultiValueProps< }; }; -export function multiValueCSS(): React.CSSProperties; -export function multiValueLabelCSS(props: MultiValueProps): React.CSSProperties; -export function multiValueRemoveCSS(props: MultiValueProps): React.CSSProperties; +export function multiValueCSS(): CSSObject; +export function multiValueLabelCSS(props: MultiValueProps): CSSObject; +export function multiValueRemoveCSS(props: MultiValueProps): CSSObject; export interface MultiValueGenericProps { children: ReactNode; diff --git a/types/react-select/src/components/Option.d.ts b/types/react-select/src/components/Option.d.ts index 29b7d079169794..224088f0232486 100644 --- a/types/react-select/src/components/Option.d.ts +++ b/types/react-select/src/components/Option.d.ts @@ -1,4 +1,5 @@ import { ComponentType, ReactNode, MouseEventHandler } from 'react'; +import { CSSObject } from '@emotion/serialize'; import { colors, spacing } from '../theme'; import { CommonProps, PropsWithStyles, InnerRef, OptionTypeBase, GroupTypeBase } from '../types'; @@ -41,7 +42,7 @@ export type OptionProps< data: any; }; -export function optionCSS(state: State): React.CSSProperties; +export function optionCSS(state: State): CSSObject; export const Option: ComponentType>; diff --git a/types/react-select/src/components/Placeholder.d.ts b/types/react-select/src/components/Placeholder.d.ts index 94b8982d9693cc..c5f33119dc1e69 100644 --- a/types/react-select/src/components/Placeholder.d.ts +++ b/types/react-select/src/components/Placeholder.d.ts @@ -1,4 +1,5 @@ import { ComponentType, CSSProperties, ReactNode } from 'react'; +import { CSSObject } from '@emotion/serialize'; import { CommonProps, GroupTypeBase, OptionTypeBase } from '../types'; @@ -15,7 +16,7 @@ export interface PlaceholderProps< innerProps: { style: CSSProperties }; } -export function placeholderCSS(): React.CSSProperties; +export function placeholderCSS(): CSSObject; export const Placeholder: ComponentType>; diff --git a/types/react-select/src/components/SingleValue.d.ts b/types/react-select/src/components/SingleValue.d.ts index 6ac5e57ae576cf..2a86befec8dff5 100644 --- a/types/react-select/src/components/SingleValue.d.ts +++ b/types/react-select/src/components/SingleValue.d.ts @@ -1,4 +1,5 @@ import { ComponentType, ReactNode } from 'react'; +import { CSSObject } from '@emotion/serialize'; import { colors, spacing } from '../theme'; import { CommonProps, GroupTypeBase, OptionTypeBase } from '../types'; @@ -19,7 +20,7 @@ export type SingleValueProps< GroupType extends GroupTypeBase = GroupTypeBase > = CommonProps & ValueProps & State; -export function css(props: SingleValueProps): React.CSSProperties; +export function css(props: SingleValueProps): CSSObject; export const SingleValue: ComponentType>; diff --git a/types/react-select/src/components/containers.d.ts b/types/react-select/src/components/containers.d.ts index b65498873a1dff..7b4ee389eaaa16 100644 --- a/types/react-select/src/components/containers.d.ts +++ b/types/react-select/src/components/containers.d.ts @@ -1,4 +1,5 @@ import { Component, ReactNode, ComponentType } from 'react'; +import { CSSObject } from '@emotion/serialize'; import { spacing } from '../theme'; import { CommonProps, GroupTypeBase, KeyboardEventHandler, OptionTypeBase } from '../types'; @@ -24,7 +25,7 @@ export type ContainerProps< /** Inner props to be passed down to the container. */ innerProps: { onKeyDown: KeyboardEventHandler }; }; -export function containerCSS(state: ContainerState): React.CSSProperties; +export function containerCSS(state: ContainerState): CSSObject; export const SelectContainer: ComponentType>; // ============================== @@ -43,7 +44,7 @@ export type ValueContainerProps< /** The children to be rendered. */ children: ReactNode; }; -export function valueContainerCSS(): React.CSSProperties; +export function valueContainerCSS(): CSSObject; export class ValueContainer extends Component> {} // ============================== @@ -67,5 +68,5 @@ export type IndicatorContainerProps< children: ReactNode; }; -export function indicatorsContainerCSS(): React.CSSProperties; +export function indicatorsContainerCSS(): CSSObject; export const IndicatorsContainer: ComponentType>; diff --git a/types/react-select/src/components/indicators.d.ts b/types/react-select/src/components/indicators.d.ts index 24e3766584b0bf..0f48dadde30a06 100644 --- a/types/react-select/src/components/indicators.d.ts +++ b/types/react-select/src/components/indicators.d.ts @@ -1,4 +1,5 @@ import { ComponentType, ReactElement as ElementType, SVGProps, ReactSVGElement } from 'react'; +import { CSSObject } from '@emotion/serialize'; import { colors, spacing } from '../theme'; import { CommonProps, GroupTypeBase, OptionTypeBase } from '../types'; @@ -31,7 +32,7 @@ export type IndicatorProps< isDisabled: boolean; }; -export type baseCSS = (props: IndicatorProps) => React.CSSProperties; +export type baseCSS = (props: IndicatorProps) => CSSObject; export const dropdownIndicatorCSS: baseCSS; export const DropdownIndicator: ComponentType>; @@ -47,7 +48,7 @@ export interface SeparatorState { isDisabled: boolean; } -export function indicatorSeparatorCSS(state: SeparatorState): React.CSSProperties; +export function indicatorSeparatorCSS(state: SeparatorState): CSSObject; export const IndicatorSeparator: ComponentType>; @@ -55,7 +56,7 @@ export const IndicatorSeparator: ComponentType>; // Loading // ============================== -export function loadingIndicatorCSS(state: { isFocused: boolean; size: number }): React.CSSProperties; +export function loadingIndicatorCSS(state: { isFocused: boolean; size: number }): CSSObject; /** @deprecated Use `LoadingIndicatorProps` instead. */ export type LoadingIconProps< diff --git a/types/react-select/src/styles.d.ts b/types/react-select/src/styles.d.ts index bcc64c8aa6dd1a..553b5478e3bf10 100644 --- a/types/react-select/src/styles.d.ts +++ b/types/react-select/src/styles.d.ts @@ -1,4 +1,4 @@ -import { CSSProperties } from 'react'; +import { CSSObject } from '@emotion/serialize'; import { ContainerProps, IndicatorContainerProps, ValueContainerProps } from './components/containers'; import { ControlProps } from './components/Control'; import { GroupProps, GroupHeadingProps } from './components/Group'; @@ -17,38 +17,35 @@ export interface Props { } /** @deprecated - Unused and will not be exported in next major version */ -export type StylesConfigFunction = (base: CSSProperties, props: Props) => CSSProperties; +export type StylesConfigFunction = (base: CSSObject, props: Props) => CSSObject; export interface Styles< OptionType extends OptionTypeBase, IsMulti extends boolean, GroupType extends GroupTypeBase = GroupTypeBase > { - clearIndicator?(base: CSSProperties, props: IndicatorProps): CSSProperties; - container?(base: CSSProperties, props: ContainerProps): CSSProperties; - control?(base: CSSProperties, props: ControlProps): CSSProperties; - dropdownIndicator?(base: CSSProperties, props: IndicatorProps): CSSProperties; - group?(base: CSSProperties, props: GroupProps): CSSProperties; - groupHeading?(base: CSSProperties, props: GroupHeadingProps): CSSProperties; - indicatorsContainer?( - base: CSSProperties, - props: IndicatorContainerProps, - ): CSSProperties; - indicatorSeparator?(base: CSSProperties, props: IndicatorProps): CSSProperties; - input?: (base: CSSProperties, props: InputProps) => CSSProperties; - loadingIndicator?(base: CSSProperties, props: LoadingIndicatorProps): CSSProperties; - loadingMessage?(base: CSSProperties, props: NoticeProps): CSSProperties; - menu?(base: CSSProperties, props: MenuProps): CSSProperties; - menuList?(base: CSSProperties, props: MenuListComponentProps): CSSProperties; - menuPortal?(base: CSSProperties, props: MenuPortalProps): CSSProperties; - multiValue?(base: CSSProperties, props: MultiValueProps): CSSProperties; - multiValueLabel?(base: CSSProperties, props: MultiValueProps): CSSProperties; - multiValueRemove?(base: CSSProperties, props: MultiValueRemoveProps): CSSProperties; - noOptionsMessage?(base: CSSProperties, props: NoticeProps): CSSProperties; - option?(base: CSSProperties, props: OptionProps): CSSProperties; - placeholder?(base: CSSProperties, props: PlaceholderProps): CSSProperties; - singleValue?(base: CSSProperties, props: SingleValueProps): CSSProperties; - valueContainer?(base: CSSProperties, props: ValueContainerProps): CSSProperties; + clearIndicator?(base: CSSObject, props: IndicatorProps): CSSObject; + container?(base: CSSObject, props: ContainerProps): CSSObject; + control?(base: CSSObject, props: ControlProps): CSSObject; + dropdownIndicator?(base: CSSObject, props: IndicatorProps): CSSObject; + group?(base: CSSObject, props: GroupProps): CSSObject; + groupHeading?(base: CSSObject, props: GroupHeadingProps): CSSObject; + indicatorsContainer?(base: CSSObject, props: IndicatorContainerProps): CSSObject; + indicatorSeparator?(base: CSSObject, props: IndicatorProps): CSSObject; + input?: (base: CSSObject, props: InputProps) => CSSObject; + loadingIndicator?(base: CSSObject, props: LoadingIndicatorProps): CSSObject; + loadingMessage?(base: CSSObject, props: NoticeProps): CSSObject; + menu?(base: CSSObject, props: MenuProps): CSSObject; + menuList?(base: CSSObject, props: MenuListComponentProps): CSSObject; + menuPortal?(base: CSSObject, props: MenuPortalProps): CSSObject; + multiValue?(base: CSSObject, props: MultiValueProps): CSSObject; + multiValueLabel?(base: CSSObject, props: MultiValueProps): CSSObject; + multiValueRemove?(base: CSSObject, props: MultiValueRemoveProps): CSSObject; + noOptionsMessage?(base: CSSObject, props: NoticeProps): CSSObject; + option?(base: CSSObject, props: OptionProps): CSSObject; + placeholder?(base: CSSObject, props: PlaceholderProps): CSSObject; + singleValue?(base: CSSObject, props: SingleValueProps): CSSObject; + valueContainer?(base: CSSObject, props: ValueContainerProps): CSSObject; } export type StylesConfig< @@ -56,7 +53,7 @@ export type StylesConfig< IsMulti extends boolean, GroupType extends GroupTypeBase = GroupTypeBase > = Partial>; -export type GetStyles = (a: string, b: Props) => CSSProperties; +export type GetStyles = (a: string, b: Props) => CSSObject; export const defaultStyles: Styles; diff --git a/types/react-select/test/Header.tsx b/types/react-select/test/Header.tsx index 64157a49fa760f..1a50f76b825962 100644 --- a/types/react-select/test/Header.tsx +++ b/types/react-select/test/Header.tsx @@ -1,9 +1,8 @@ import * as React from 'react'; -import Select from 'react-select'; -import { ControlProps } from 'react-select/src/components/Control'; +import Select, { ControlProps, OptionTypeBase, StylesConfig } from 'react-select'; -const headerSelectStyles = { - control: (base: React.CSSProperties, { isFocused }: ControlProps<{}, boolean>) => ({ +const headerSelectStyles: StylesConfig = { + control: (base, { isFocused }) => ({ ...base, backgroundClip: 'padding-box', borderColor: 'rgba(0,0,0,0.1)', diff --git a/types/react-select/test/examples/StyledMulti.tsx b/types/react-select/test/examples/StyledMulti.tsx index 9fbfbe7c6bccd2..75ef6c3f552bca 100644 --- a/types/react-select/test/examples/StyledMulti.tsx +++ b/types/react-select/test/examples/StyledMulti.tsx @@ -19,6 +19,11 @@ const colourStyles: StylesConfig = { : 'black' : data.color, cursor: isDisabled ? 'not-allowed' : 'default', + + ':active': { + ...styles[':active'], + backgroundColor: !isDisabled && (isSelected ? data.color : color.alpha(0.3).css()), + }, }; }, multiValue: (styles, { data }) => { diff --git a/types/react-select/test/examples/StyledSingle.tsx b/types/react-select/test/examples/StyledSingle.tsx index 6296367a75663a..1a61fa8c7e5054 100644 --- a/types/react-select/test/examples/StyledSingle.tsx +++ b/types/react-select/test/examples/StyledSingle.tsx @@ -1,8 +1,8 @@ import * as React from 'react'; import * as chroma from 'chroma-js'; -import { colourOptions } from '../data'; -import Select from 'react-select'; +import { ColourOption, colourOptions } from '../data'; +import Select, { StylesConfig } from 'react-select'; const dot = (color = '#ccc') => ({ alignItems: 'center', @@ -19,9 +19,9 @@ const dot = (color = '#ccc') => ({ }, }); -const colourStyles = { - control: (styles: any) => ({ ...styles, backgroundColor: 'white' }), - option: (styles: any, { data, isDisabled, isFocused, isSelected }: any) => { +const colourStyles: StylesConfig = { + control: styles => ({ ...styles, backgroundColor: 'white' }), + option: (styles, { data, isDisabled, isFocused, isSelected }) => { const color = chroma(data.color); return { ...styles, @@ -34,11 +34,16 @@ const colourStyles = { : 'black' : data.color, cursor: isDisabled ? 'not-allowed' : 'default', + + ':active': { + ...styles[':active'], + backgroundColor: !isDisabled && (isSelected ? data.color : color.alpha(0.3).css()), + }, }; }, - input: (styles: any) => ({ ...styles, ...dot() }), - placeholder: (styles: any) => ({ ...styles, ...dot() }), - singleValue: (styles: any, { data }: any) => ({ ...styles, ...dot(data.color) }), + input: styles => ({ ...styles, ...dot() }), + placeholder: styles => ({ ...styles, ...dot() }), + singleValue: (styles, { data }) => ({ ...styles, ...dot(data.color) }), }; export default () => (