Skip to content

Commit

Permalink
Fix breakpoint matching, add col-span
Browse files Browse the repository at this point in the history
  • Loading branch information
dabbott committed Jan 10, 2024
1 parent 65a7e83 commit 3c5735a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2432,6 +2432,20 @@ Array [
"grid-flow-row",
"grow",
"grow-0",
"col-auto",
"col-span-1",
"col-span-2",
"col-span-3",
"col-span-4",
"col-span-5",
"col-span-6",
"col-span-7",
"col-span-8",
"col-span-9",
"col-span-10",
"col-span-11",
"col-span-12",
"col-span-full",
"shrink",
"shrink-0",
"flex",
Expand Down
4 changes: 4 additions & 0 deletions packages/noya-tailwind/src/__tests__/tailwind.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ describe('resolves styles', () => {
expect(resolveTailwindClass('auto-cols-max')).toEqual({
gridAutoColumns: 'max-content',
});

expect(resolveTailwindClass('col-span-2')).toEqual({
gridColumn: 'span 2 / span 2',
});
});

it('position', () => {
Expand Down
1 change: 1 addition & 0 deletions packages/noya-tailwind/src/suggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export const suggestionPatterns = [
'grid-flow-row',
'grow',
'grow-0',
'col-{gridColumn}',
'shrink',
'shrink-0',
'flex',
Expand Down
22 changes: 15 additions & 7 deletions packages/noya-tailwind/src/tailwind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export const classGroups = {
autoRows: /^auto-rows/,
gridFlow: /^grid-flow/,
gridCols: /^grid-cols/,
gridColumnSpan: /^col-span-/,
lineHeight: /^leading-/,
tracking: /^tracking-/,
position: /^(absolute|relative|fixed|sticky)/,
Expand Down Expand Up @@ -250,6 +251,7 @@ export const filterTailwindClassesByLastInGroup = memoize(
);

export const breakpoints = [
'none' as const,
'sm' as const,
'md' as const,
'lg' as const,
Expand All @@ -259,15 +261,15 @@ export const breakpoints = [

export const colorSchemes = ['light' as const, 'dark' as const];

export type BreakpointKey = (typeof breakpoints)[number];
export type BreakpointKey = (typeof breakpoints)[number] | 'none';

export function matchBreakpoint(width: number): BreakpointKey {
if (width < 640) return 'sm';
if (width < 768) return 'md';
if (width < 1024) return 'lg';
if (width < 1280) return 'xl';
if (width < 1536) return '2xl';
return '2xl';
if (width >= 1536) return '2xl';
if (width >= 1280) return 'xl';
if (width >= 1024) return 'lg';
if (width >= 768) return 'md';
if (width >= 640) return 'sm';
return 'none';
}

export const extractTailwindClassesByBreakpoint = (
Expand Down Expand Up @@ -781,6 +783,12 @@ export const resolveTailwindClass = memoize(function resolveTailwindClass(
],
};
}
case 'gridColumnSpan': {
const value = className.replace('col-', '');
return {
gridColumn: (config.theme as any).gridColumn[value || 'auto'],
};
}
case 'gradientDirection':
case 'gradientStopFrom':
case 'gradientStopTo': {
Expand Down

0 comments on commit 3c5735a

Please sign in to comment.