shared.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import type { AdminLayoutProps, LayoutCssVars, LayoutCssVarsProps } from '../../types';
  2. /** The id of the scroll element of the layout */
  3. export const LAYOUT_SCROLL_EL_ID = '__SCROLL_EL_ID__';
  4. /** The max z-index of the layout */
  5. export const LAYOUT_MAX_Z_INDEX = 100;
  6. /**
  7. * Create layout css vars by css vars props
  8. *
  9. * @param props Css vars props
  10. */
  11. function createLayoutCssVarsByCssVarsProps(props: LayoutCssVarsProps) {
  12. const cssVars: LayoutCssVars = {
  13. '--soy-header-height': `${props.headerHeight}px`,
  14. '--soy-header-z-index': props.headerZIndex,
  15. '--soy-tab-height': `${props.tabHeight}px`,
  16. '--soy-tab-z-index': props.tabZIndex,
  17. '--soy-sider-width': `${props.siderWidth}px`,
  18. '--soy-sider-collapsed-width': `${props.siderCollapsedWidth}px`,
  19. '--soy-sider-z-index': props.siderZIndex,
  20. '--soy-mobile-sider-z-index': props.mobileSiderZIndex,
  21. '--soy-footer-height': `${props.footerHeight}px`,
  22. '--soy-footer-z-index': props.footerZIndex
  23. };
  24. return cssVars;
  25. }
  26. /**
  27. * Create layout css vars
  28. *
  29. * @param props
  30. */
  31. export function createLayoutCssVars(props: AdminLayoutProps) {
  32. const {
  33. mode,
  34. isMobile,
  35. maxZIndex = LAYOUT_MAX_Z_INDEX,
  36. headerHeight,
  37. tabHeight,
  38. siderWidth,
  39. siderCollapsedWidth,
  40. footerHeight
  41. } = props;
  42. const headerZIndex = maxZIndex - 3;
  43. const tabZIndex = maxZIndex - 5;
  44. const siderZIndex = mode === 'vertical' || isMobile ? maxZIndex - 1 : maxZIndex - 4;
  45. const mobileSiderZIndex = isMobile ? maxZIndex - 2 : 0;
  46. const footerZIndex = maxZIndex - 5;
  47. const cssProps: LayoutCssVarsProps = {
  48. headerHeight,
  49. headerZIndex,
  50. tabHeight,
  51. tabZIndex,
  52. siderWidth,
  53. siderZIndex,
  54. mobileSiderZIndex,
  55. siderCollapsedWidth,
  56. footerHeight,
  57. footerZIndex
  58. };
  59. return createLayoutCssVarsByCssVarsProps(cssProps);
  60. }