// @flow
/** @jsx jsx */
import { type Node } from 'react';
import { jsx, keyframes } from '@emotion/react';
import type { CommonProps, Theme } from '../types';
// ==============================
// Dropdown & Clear Icons
// ==============================
const Svg = ({ size, ...props }: { size: number }) => (
);
export const CrossIcon = (props: any) => (
);
export const DownChevron = (props: any) => (
);
// ==============================
// Dropdown & Clear Buttons
// ==============================
export type IndicatorProps = CommonProps & {
/** The children to be rendered inside the indicator. */
children: Node,
/** Props that will be passed on to the children. */
innerProps: any,
/** The focused state of the select. */
isFocused: boolean,
/** Whether the text is right to left */
isRtl: boolean,
};
const baseCSS = ({
isFocused,
theme: {
spacing: { baseUnit },
colors,
},
}: IndicatorProps) => ({
label: 'indicatorContainer',
color: isFocused ? colors.neutral60 : colors.neutral20,
display: 'flex',
padding: baseUnit * 2,
transition: 'color 150ms',
':hover': {
color: isFocused ? colors.neutral80 : colors.neutral40,
},
});
export const dropdownIndicatorCSS = baseCSS;
export const DropdownIndicator = (props: IndicatorProps) => {
const { children, className, cx, getStyles, innerProps } = props;
return (
{children || }
);
};
export const clearIndicatorCSS = baseCSS;
export const ClearIndicator = (props: IndicatorProps) => {
const { children, className, cx, getStyles, innerProps } = props;
return (
{children || }
);
};
// ==============================
// Separator
// ==============================
type SeparatorState = { isDisabled: boolean };
export const indicatorSeparatorCSS = ({
isDisabled,
theme: {
spacing: { baseUnit },
colors,
},
}: CommonProps & SeparatorState) => ({
label: 'indicatorSeparator',
alignSelf: 'stretch',
backgroundColor: isDisabled ? colors.neutral10 : colors.neutral20,
marginBottom: baseUnit * 2,
marginTop: baseUnit * 2,
width: 1,
});
export const IndicatorSeparator = (props: IndicatorProps) => {
const { className, cx, getStyles, innerProps } = props;
return (
);
};
// ==============================
// Loading
// ==============================
const loadingDotAnimations = keyframes`
0%, 80%, 100% { opacity: 0; }
40% { opacity: 1; }
`;
export const loadingIndicatorCSS = ({
isFocused,
size,
theme: {
colors,
spacing: { baseUnit },
},
}: {
isFocused: boolean,
size: number,
theme: Theme,
}) => ({
label: 'loadingIndicator',
color: isFocused ? colors.neutral60 : colors.neutral20,
display: 'flex',
padding: baseUnit * 2,
transition: 'color 150ms',
alignSelf: 'center',
fontSize: size,
lineHeight: 1,
marginRight: size,
textAlign: 'center',
verticalAlign: 'middle',
});
type DotProps = { delay: number, offset: boolean };
const LoadingDot = ({ delay, offset }: DotProps) => (
);
export type LoadingIconProps = {
/** Props that will be passed on to the children. */
innerProps: any,
/** The focused state of the select. */
isFocused: boolean,
/** Whether the text is right to left */
isRtl: boolean,
} & CommonProps & {
/** Set size of the container. */
size: number,
};
export const LoadingIndicator = (props: LoadingIconProps) => {
const { className, cx, getStyles, innerProps, isRtl } = props;
return (
);
};
LoadingIndicator.defaultProps = { size: 4 };