dees-domtools/ts/domtools.breakpoints.ts
2020-06-03 09:07:31 +00:00

69 lines
1.6 KiB
TypeScript

import { DomTools } from './domtools.classes.domtools';
export const desktop = 1240;
export const tablet = 1024;
export const phablet = 600;
export const phone = 400;
export type TViewport = 'native' | 'desktop' | 'tablet' | 'phablet' | 'phone';
export const getEnvironment = (): TViewport => {
if (globalThis.deesDomTools && globalThis.deesDomTools.domToolsStatePart.getState().virtualViewport) {
return globalThis.deesDomTools.domToolsStatePart.getState().virtualViewport;
} else {
return 'native';
}
};
export const cssForTablet = (contentArg) => {
if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
return `
@media (max-width: ${tablet}px) {
${contentArg}
}
`;
} else if (
getEnvironment() === 'tablet' ||
getEnvironment() === 'phablet' ||
getEnvironment() === 'phone'
) {
return `
@media (min-width: 0px) {
${contentArg}
}
`;
}
};
export const cssForPhablet = (contentArg) => {
if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
return `
@media (max-width: ${phablet}px) {
${contentArg}
}
`;
} else if (getEnvironment() === 'phablet' || getEnvironment() === 'phone') {
return `
@media (min-width: 0px) {
${contentArg}
}
`;
}
};
export const cssForPhone = (contentArg) => {
if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
return `
@media (max-width: ${phone}px) {
${contentArg}
}
`;
} else if (getEnvironment() === 'phone') {
return `
@media (min-width: 0px) {
${contentArg}
}
`;
}
};