dees-domtools/ts/domtools.breakpoints.ts
2020-05-27 21:15:38 +00:00

66 lines
1.7 KiB
TypeScript

import { DomTools } from './domtools.classes.domtools';
export const desktop = 1240;
export const tablet = 700;
export const phablet = 500;
export const phone = 340;
export type TViewport = 'native' | 'desktop' | 'tablet' | 'phablet' | 'phone';
export const getEnvironment = async (): Promise<TViewport> => {
const domToolsInstance = await DomTools.setupDomTools();
return domToolsInstance.domToolsStatePart.getState().virtualViewport;
};
export const cssForTablet = async contentArg => {
if ((await getEnvironment()) === 'native' || (await getEnvironment()) === 'desktop') {
return `
@media (max-width: ${tablet}px) {
${contentArg}
}
`;
} else if (
(await getEnvironment()) === 'tablet' ||
(await getEnvironment()) === 'phablet' ||
(await getEnvironment()) === 'phone'
) {
return `
@media (min-width: 0px) {
${contentArg}
}
`;
}
};
export const cssForPhablet = async contentArg => {
if ((await getEnvironment()) === 'native' || (await getEnvironment()) === 'desktop') {
return `
@media (max-width: ${phablet}px) {
${contentArg}
}
`;
} else if ((await getEnvironment()) === 'phablet' || (await getEnvironment()) === 'phone') {
return `
@media (min-width: 0px) {
${contentArg}
}
`;
}
};
export const cssForPhone = async contentArg => {
if ((await getEnvironment()) === 'native' || (await getEnvironment()) === 'desktop') {
return `
@media (max-width: ${phone}px) {
${contentArg}
}
`;
} else if ((await getEnvironment()) === 'phone') {
return `
@media (min-width: 0px) {
${contentArg}
}
`;
}
};