dees-domtools/ts/domtools.breakpoints.ts

69 lines
1.6 KiB
TypeScript
Raw Normal View History

2020-05-27 21:15:38 +00:00
import { DomTools } from './domtools.classes.domtools';
2020-05-23 15:00:01 +00:00
export const desktop = 1240;
export const tablet = 700;
export const phablet = 500;
export const phone = 340;
2020-05-27 21:15:38 +00:00
export type TViewport = 'native' | 'desktop' | 'tablet' | 'phablet' | 'phone';
2020-05-23 15:00:01 +00:00
2020-05-27 22:30:03 +00:00
export const getEnvironment = (): TViewport => {
2020-05-27 22:28:52 +00:00
if (globalThis.deesDomTools && globalThis.deesDomTools.domToolsStatePart.getState().virtualViewport) {
return globalThis.deesDomTools.domToolsStatePart.getState().virtualViewport;
} else {
return 'native';
}
2020-05-23 15:00:01 +00:00
};
2020-05-27 22:41:08 +00:00
export const cssForTablet = (contentArg) => {
2020-05-27 22:28:52 +00:00
if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
2020-05-23 15:00:01 +00:00
return `
@media (max-width: ${tablet}px) {
${contentArg}
}
`;
2020-05-27 21:15:38 +00:00
} else if (
2020-05-27 22:28:52 +00:00
getEnvironment() === 'tablet' ||
getEnvironment() === 'phablet' ||
getEnvironment() === 'phone'
2020-05-27 21:15:38 +00:00
) {
2020-05-23 15:00:01 +00:00
return `
@media (min-width: 0px) {
${contentArg}
}
`;
}
};
2020-05-27 22:41:08 +00:00
export const cssForPhablet = (contentArg) => {
2020-05-27 22:28:52 +00:00
if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
2020-05-23 15:00:01 +00:00
return `
@media (max-width: ${phablet}px) {
${contentArg}
}
`;
2020-05-27 22:28:52 +00:00
} else if (getEnvironment() === 'phablet' || getEnvironment() === 'phone') {
2020-05-23 15:00:01 +00:00
return `
@media (min-width: 0px) {
${contentArg}
}
`;
}
};
2020-05-27 22:41:08 +00:00
export const cssForPhone = (contentArg) => {
2020-05-27 22:28:52 +00:00
if (getEnvironment() === 'native' || getEnvironment() === 'desktop') {
2020-05-23 15:00:01 +00:00
return `
@media (max-width: ${phone}px) {
${contentArg}
}
`;
2020-05-27 22:28:52 +00:00
} else if (getEnvironment() === 'phone') {
2020-05-23 15:00:01 +00:00
return `
@media (min-width: 0px) {
${contentArg}
}
`;
}
};