redoc/src/styled-components.ts

54 lines
1.4 KiB
TypeScript
Raw Normal View History

2017-10-12 00:01:37 +03:00
import * as styledComponents from 'styled-components';
import { ThemeInterface } from './theme';
2017-10-12 00:01:37 +03:00
2017-11-19 22:27:44 +03:00
export type StyledFunction<T> = styledComponents.ThemedStyledFunction<T, ThemeInterface>;
2017-10-12 00:01:37 +03:00
function withProps<T, U extends HTMLElement = HTMLElement>(
styledFunction: StyledFunction<React.HTMLProps<U>>,
): StyledFunction<T & React.HTMLProps<U>> {
return styledFunction;
}
const {
default: styled,
css,
injectGlobal,
keyframes,
ThemeProvider,
withTheme,
2018-01-22 21:30:53 +03:00
} = (styledComponents as styledComponents.ThemedStyledComponentsModule<
any
>) as styledComponents.ThemedStyledComponentsModule<ThemeInterface>;
2017-10-12 00:01:37 +03:00
2018-01-30 16:35:18 +03:00
export const media = {
lessThan(breakpoint) {
return (...args) => css`
@media (max-width: ${props => props.theme.breakpoints[breakpoint]}) {
2018-01-30 16:35:18 +03:00
${(css as any)(...args)};
}
`;
},
greaterThan(breakpoint) {
return (...args) => css`
@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`
@media (min-width: ${props => props.theme.breakpoints[firstBreakpoint]}) and (max-width: ${props => props.theme.breakpoints[
2018-01-30 16:35:18 +03:00
secondBreakpoint
]}) {
${(css as any)(...args)};
}
`;
},
};
2017-10-12 00:01:37 +03:00
export { css, injectGlobal, keyframes, ThemeProvider, withTheme, withProps };
export default styled;