2018-07-16 18:28:36 +03:00
|
|
|
import * as React from 'react';
|
2017-10-12 00:01:37 +03:00
|
|
|
import * as styledComponents from 'styled-components';
|
|
|
|
|
2018-07-16 18:28:36 +03:00
|
|
|
import { ResolvedThemeInterface } from './theme';
|
2017-10-12 00:01:37 +03:00
|
|
|
|
2018-05-16 12:44:36 +03:00
|
|
|
export { ResolvedThemeInterface };
|
|
|
|
|
2018-11-27 12:18:41 +03:00
|
|
|
type WithProps<
|
|
|
|
C extends keyof JSX.IntrinsicElements | React.ComponentType<any>,
|
|
|
|
T extends object
|
|
|
|
> = styledComponents.ThemedStyledFunction<C, ResolvedThemeInterface, T>;
|
2017-10-12 00:01:37 +03:00
|
|
|
|
|
|
|
const {
|
|
|
|
default: styled,
|
|
|
|
css,
|
2018-10-18 11:48:17 +03:00
|
|
|
createGlobalStyle,
|
2017-10-12 00:01:37 +03:00
|
|
|
keyframes,
|
|
|
|
ThemeProvider,
|
2018-05-18 15:10:16 +03:00
|
|
|
} = (styledComponents as any) as styledComponents.ThemedStyledComponentsModule<
|
|
|
|
ResolvedThemeInterface
|
|
|
|
>;
|
2017-10-12 00:01:37 +03:00
|
|
|
|
2018-01-30 16:35:18 +03:00
|
|
|
export const media = {
|
2018-10-05 15:57:12 +03:00
|
|
|
lessThan(breakpoint, print?: boolean) {
|
2018-01-30 16:35:18 +03:00
|
|
|
return (...args) => css`
|
2018-10-05 15:57:12 +03:00
|
|
|
@media ${print ? 'print, ' : ''} screen and (max-width: ${props =>
|
|
|
|
props.theme.breakpoints[breakpoint]}) {
|
2018-01-30 16:35:18 +03:00
|
|
|
${(css as any)(...args)};
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
},
|
|
|
|
|
|
|
|
greaterThan(breakpoint) {
|
|
|
|
return (...args) => css`
|
2018-02-25 13:13:42 +03:00
|
|
|
@media (min-width: ${props => props.theme.breakpoints[breakpoint]}) {
|
2018-01-30 16:35:18 +03:00
|
|
|
${(css as any)(...args)};
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
},
|
|
|
|
|
|
|
|
between(firstBreakpoint, secondBreakpoint) {
|
|
|
|
return (...args) => css`
|
2018-03-16 18:02:31 +03:00
|
|
|
@media (min-width: ${props =>
|
|
|
|
props.theme.breakpoints[firstBreakpoint]}) and (max-width: ${props =>
|
|
|
|
props.theme.breakpoints[secondBreakpoint]}) {
|
2018-01-30 16:35:18 +03:00
|
|
|
${(css as any)(...args)};
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2018-11-27 12:18:41 +03:00
|
|
|
export { css, createGlobalStyle, keyframes, ThemeProvider, WithProps };
|
2017-10-12 00:01:37 +03:00
|
|
|
export default styled;
|
2018-06-29 23:49:53 +03:00
|
|
|
|
|
|
|
export function extensionsHook(styledName: string) {
|
|
|
|
return props => {
|
|
|
|
if (!props.theme.extensionsHook) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return props.theme.extensionsHook(styledName, props);
|
|
|
|
};
|
|
|
|
}
|