Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(theme-default): improve css variable acquisition (#1322)
- Loading branch information
1 parent
23bdec6
commit eb0d0ea
Showing
6 changed files
with
69 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
ecosystem/theme-default/src/client/composables/useUpdateDeviceStatus.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { onMounted } from 'vue' | ||
import cssVars from '../styles/_variables.module.scss?module' | ||
|
||
export enum DeviceType { | ||
MOBILE = 'mobile', | ||
} | ||
|
||
const DeviceTypeMap = { | ||
[DeviceType.MOBILE]: Number.parseInt(cssVars.mobile?.replace('px', ''), 10), | ||
} | ||
|
||
/** | ||
* add listener to detect screen though device type | ||
*/ | ||
export const useUpdateDeviceStatus = ( | ||
deviceType: DeviceType, | ||
callback: (width: number) => void | ||
): void => { | ||
const width = DeviceTypeMap[deviceType] | ||
if (!Number.isInteger(width)) { | ||
if (__VUEPRESS_DEV__) throw new Error('device width must be a integer') | ||
return | ||
} | ||
|
||
onMounted(() => { | ||
callback(width) | ||
window.addEventListener('resize', () => callback(width), false) | ||
window.addEventListener('orientationchange', () => callback(width), false) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
ecosystem/theme-default/src/client/styles/_variables.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@import '_variables'; | ||
|
||
:export { | ||
mobile: $MQMobile; | ||
} |