Skip to content

Instantly share code, notes, and snippets.

@chalkygames123
Created January 12, 2024 08:08
Show Gist options
  • Save chalkygames123/9b36d2bf15faa3a915fb8ac6dbac313b to your computer and use it in GitHub Desktop.
Save chalkygames123/9b36d2bf15faa3a915fb8ac6dbac313b to your computer and use it in GitHub Desktop.
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