dees-domtools/ts/domtools.breakpoints.ts

72 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;
2020-06-03 09:07:31 +00:00
export const tablet = 1024;
export const phablet = 600;
2020-06-01 12:30:21 +00:00
export const phone = 400;
2020-05-23 15:00:01 +00:00
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-06-28 15:49:46 +00:00
if (
globalThis.deesDomTools &&
globalThis.deesDomTools.domToolsStatePart.getState().virtualViewport
) {
2020-05-27 22:28:52 +00:00
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}
}
`;
}
};