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.
 
 
 

139 lines
3.3 KiB

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