Created
January 12, 2024 08:08
-
-
Save chalkygames123/9b36d2bf15faa3a915fb8ac6dbac313b to your computer and use it in GitHub Desktop.
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
import plugin from 'tailwindcss/plugin'; | |
/** | |
* 参照: https://piccalil.li/tutorial/create-a-responsive-grid-layout-with-no-media-queries-using-css-grid/ | |
*/ | |
const autoGrid = plugin( | |
({ addComponents, matchComponents, theme }) => { | |
matchComponents( | |
{ | |
'auto-grid': (value) => ({ | |
display: 'grid', | |
'grid-template-columns': `repeat(auto-fill, minmax(min(${value}, 100%), 1fr))`, | |
}), | |
}, | |
{ | |
values: theme('autoGrid'), | |
}, | |
); | |
addComponents({ | |
'.auto-grid-none': { | |
display: 'revert', | |
'grid-template-columns': 'revert', | |
}, | |
}); | |
}, | |
{ | |
theme: { | |
// @ts-ignore | |
autoGrid: ({ theme }) => ({ | |
...theme('flexBasis'), | |
}), | |
}, | |
}, | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment