windi.config.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. const primaryColor = '#0960bd';
  2. export default {
  3. darkMode: 'class',
  4. plugins: [createEnterPlugin()],
  5. theme: {
  6. extend: {
  7. zIndex: {
  8. '-1': '-1',
  9. },
  10. colors: {
  11. primary: primaryColor,
  12. },
  13. screens: {
  14. sm: '576px',
  15. md: '768px',
  16. lg: '992px',
  17. xl: '1200px',
  18. '2xl': '1600px',
  19. },
  20. },
  21. },
  22. };
  23. /**
  24. * Used for animation when the element is displayed.
  25. * @param maxOutput The larger the maxOutput output, the larger the generated css volume.
  26. */
  27. function createEnterPlugin(maxOutput = 6) {
  28. const createCss = (index: number, d = 'x') => {
  29. const upd = d.toUpperCase();
  30. return {
  31. [`*> .enter-${d}:nth-child(${index})`]: {
  32. transform: `translate${upd}(50px)`,
  33. },
  34. [`*> .-enter-${d}:nth-child(${index})`]: {
  35. transform: `translate${upd}(-50px)`,
  36. },
  37. [`* > .enter-${d}:nth-child(${index}),* > .-enter-${d}:nth-child(${index})`]: {
  38. 'z-index': `${10 - index}`,
  39. opacity: '0',
  40. animation: `enter-${d}-animation 0.4s ease-in-out 0.3s`,
  41. 'animation-fill-mode': 'forwards',
  42. 'animation-delay': `${(index * 1) / 10}s`,
  43. },
  44. };
  45. };
  46. const handler = ({ addBase }) => {
  47. const addRawCss = {};
  48. for (let index = 1; index < maxOutput; index++) {
  49. Object.assign(addRawCss, {
  50. ...createCss(index, 'x'),
  51. ...createCss(index, 'y'),
  52. });
  53. }
  54. addBase({
  55. ...addRawCss,
  56. [`@keyframes enter-x-animation`]: {
  57. to: {
  58. opacity: '1',
  59. transform: 'translateX(0)',
  60. },
  61. },
  62. [`@keyframes enter-y-animation`]: {
  63. to: {
  64. opacity: '1',
  65. transform: 'translateY(0)',
  66. },
  67. },
  68. });
  69. };
  70. return { handler };
  71. }