Layout scaffolding for Web apps.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

145 lines
3.5 KiB

  1. import tailwindPlugin from 'tailwindcss/plugin';
  2. export interface ViewfinderPluginOptions {
  3. baseWidth?: number;
  4. topbarHeight?: string;
  5. sizeMenu?: string;
  6. colorTopbar?: string;
  7. colorSidebar?: string;
  8. colorSidebarMenu?: string;
  9. }
  10. export const plugin = tailwindPlugin.withOptions<ViewfinderPluginOptions | undefined>(
  11. ({
  12. baseWidth = 360 as const,
  13. topbarHeight = '4rem' as const,
  14. sizeMenu = topbarHeight,
  15. colorTopbar = '255 255 255' as const,
  16. colorSidebarMenu = '255 255 255' as const,
  17. colorSidebar = '255 255 255' as const,
  18. } = {} as ViewfinderPluginOptions) => ({
  19. addBase,
  20. addComponents,
  21. addUtilities,
  22. }) => {
  23. addBase({
  24. ':root': {
  25. '--base-width': `${baseWidth}px`,
  26. '--height-topbar': topbarHeight,
  27. '--size-menu': sizeMenu,
  28. '--color-topbar': colorTopbar,
  29. '--color-sidebar': colorSidebar,
  30. '--color-sidebar-menu': colorSidebarMenu,
  31. },
  32. });
  33. addBase({
  34. ':root': {
  35. 'background-color': 'rgb(var(--color-background))',
  36. },
  37. });
  38. addComponents({
  39. '.topbar': {
  40. height: 'var(--height-topbar, 4rem)',
  41. '& ~ *': {
  42. 'padding-top': 'var(--height-topbar, 4rem)',
  43. },
  44. '& ~ [data-viewfinder="main"] ~ *': {
  45. 'padding-top': '0',
  46. },
  47. '& [data-viewfinder="menu"] > *': {
  48. 'width': '100%',
  49. 'height': '100%',
  50. 'position': 'relative',
  51. },
  52. '& [data-viewfinder="user"] > *': {
  53. 'width': '100%',
  54. 'height': '100%',
  55. 'position': 'relative',
  56. },
  57. [`@media (min-width: ${baseWidth * 3}px)`]: {
  58. '& ~ [data-viewfinder="main"] ~ *': {
  59. 'padding-top': 'var(--height-topbar, 4rem)',
  60. },
  61. '& [data-viewfinder="menu"] > *': {
  62. 'position': 'absolute',
  63. 'left': '-999999px',
  64. },
  65. '& [data-viewfinder="menu"] > *:focus': {
  66. 'position': 'static',
  67. },
  68. },
  69. },
  70. });
  71. addUtilities({
  72. '.scrollbar-hidden': {
  73. 'scrollbar-width': 'none',
  74. '&::-webkit-scrollbar': {
  75. 'display': 'none',
  76. },
  77. },
  78. });
  79. addComponents({
  80. '.left-sidebar-with-menu-base': {
  81. '& [data-viewfinder="menu-item"] > *': {
  82. 'height': '100%',
  83. 'display': 'flex',
  84. 'align-items': 'center',
  85. 'text-decoration': 'none',
  86. 'width': '100%',
  87. },
  88. [`@media (min-width: ${baseWidth * 3}px)`]: {
  89. '& [data-viewfinder="menu-item"]': {
  90. 'width': 'auto !important',
  91. },
  92. '& [data-viewfinder="menu-item"] > *': {
  93. 'height': 'auto',
  94. },
  95. },
  96. },
  97. });
  98. },
  99. ({
  100. baseWidth = 360 as const,
  101. } = {} as ViewfinderPluginOptions) => ({
  102. theme: {
  103. screens: {
  104. '3xs': `${baseWidth}px`,
  105. '2xs': `${baseWidth * 1.5}px`,
  106. xs: `${baseWidth * 2}px`,
  107. sm: `${baseWidth * 2.5}px`,
  108. md: `${baseWidth * 3}px`,
  109. lg: `${baseWidth * 4}px`,
  110. xl: `${baseWidth * 5}px`,
  111. '2xl': `${baseWidth * 6}px`,
  112. '3xl': `${baseWidth * 7}px`,
  113. },
  114. extend: {
  115. colors: {
  116. topbar: 'rgb(var(--color-topbar))',
  117. sidebar: 'rgb(var(--color-sidebar))',
  118. 'sidebar-menu': 'rgb(var(--color-sidebar-menu))',
  119. },
  120. spacing: {
  121. topbar: 'var(--height-topbar, 4rem)',
  122. menu: 'var(--size-menu, var(--height-topbar, 4rem))',
  123. inherit: 'inherit',
  124. },
  125. maxWidth: {
  126. 'screen-3xs': `${baseWidth}px`,
  127. 'screen-2xs': `${baseWidth * 1.5}px`,
  128. 'screen-xs': `${baseWidth * 2}px`,
  129. 'screen-sm': `${baseWidth * 2.5}px`,
  130. 'screen-md': `${baseWidth * 3}px`,
  131. 'screen-lg': `${baseWidth * 4}px`,
  132. 'screen-xl': `${baseWidth * 5}px`,
  133. 'screen-2xl': `${baseWidth * 6}px`,
  134. 'screen-3xl': `${baseWidth * 7}px`,
  135. },
  136. minWidth: {
  137. 32: '8rem',
  138. },
  139. },
  140. },
  141. }),
  142. );