Skip to content

Commit

Permalink
fix: flex property should convert considering the default values for …
Browse files Browse the repository at this point in the history
…flexShrink and flexBasis
  • Loading branch information
Jackardios committed Feb 11, 2023
1 parent 0bf17d5 commit e417b51
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
31 changes: 27 additions & 4 deletions src/constants/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,10 +839,33 @@ export const TAILWIND_DECLARATION_CONVERTERS: TailwindDeclarationConverters = {
return classes;
},

flex: (declaration, config) =>
config.tailwindConfig.corePlugins.flex
? convertDeclarationValue(declaration.value, config.mapping.flex, 'flex')
: [],
flex: (declaration, config) => {
if (!config.tailwindConfig.corePlugins.flex) {
return [];
}

let classes = convertDeclarationValue(
declaration.value,
config.mapping.flex,
'flex',
''
);

if (classes.length) {
return classes;
}

const [flexGrow, flexShrink = '1', flexBasis = '0%'] = declaration.value
.trim()
.split(/\s+/m);

return convertDeclarationValue(
`${flexGrow} ${flexShrink} ${flexBasis}`,
config.mapping.flex,
'flex',
declaration.value
);
},

'flex-basis': (declaration, config) =>
config.tailwindConfig.corePlugins.flexBasis
Expand Down
3 changes: 3 additions & 0 deletions test/TailwindConverter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ describe('TailwindConverter', () => {
'after:border-r-8',
'after:border-dashed',
'after:border-t-[some-invalid-value]',
'after:flex-1',
'after:rounded-tl-none',
'after:rounded-tr-[0.25%]',
'after:border-t-[current]',
Expand All @@ -455,6 +456,8 @@ describe('TailwindConverter', () => {
'break-inside-avoid-column',
'caret-[color:var(--cyan)]',
'h-9',
'flex-1',
'xl:flex-[1_0]',
'xl:clear-both',
'xl:text-lime-200',
'xl:gap-x-48',
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/TailwindConverter.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ exports[`TailwindConverter should convert the complex CSS 1`] = `
@apply border pl-[25%] pr-[1.5em] pt-0 pb-px bottom-full;
}
.bar {
@apply backdrop-brightness-90 backdrop-sepia-[25%] backdrop-blur-none animate-[some-animation_2s_linear_infinite] origin-[12%_25.5%] ease-[cubic-bezier(0.23,0,0.25,1)] lg:backdrop-brightness-75 lg:backdrop-sepia lg:bg-local lg:bg-blend-difference lg:bg-clip-padding lg:bg-[hsl(30,51%,22%)] lg:disabled:bg-gradient-to-tr lg:disabled:bg-origin-padding lg:disabled:bg-left-bottom lg:disabled:bg-no-repeat lg:disabled:bg-contain lg:disabled:border-b-2 after:border-spacing-[5%] after:rounded-full after:border-l-[3px] after:border-l-transparent after:border-l-[1rem] after:border-r-2 after:border-r-[aqua] after:border-r-8 after:border-dashed after:border-t-[some-invalid-value] after:rounded-tl-none after:rounded-tr-[0.25%] after:border-t-[current] after:border-t-[100vh] after:border-dotted after:border-0 after:bottom-[100vw] box-decoration-slice shadow box-border break-after-all break-before-page break-inside-avoid-column caret-[color:var(--cyan)] h-9 xl:clear-both xl:text-lime-200 xl:gap-x-48 xl:columns-3 xl:content-none xl:cursor-pointer xl:hidden xl:fill-sky-800 xl:blur-sm xl:brightness-50 xl:sepia xl:contrast-100 xl:hue-rotate-30 xl:invert-0 xl:opacity-5 xl:saturate-150 xl:flex-auto xl:basis-3 xl:flex-col-reverse xl:grow xl:shrink-0 xl:flex-wrap-reverse xl:float-right xl:text-2xl xl:antialiased xl:italic xl:ordinal xl:font-semibold;
@apply backdrop-brightness-90 backdrop-sepia-[25%] backdrop-blur-none animate-[some-animation_2s_linear_infinite] origin-[12%_25.5%] ease-[cubic-bezier(0.23,0,0.25,1)] lg:backdrop-brightness-75 lg:backdrop-sepia lg:bg-local lg:bg-blend-difference lg:bg-clip-padding lg:bg-[hsl(30,51%,22%)] lg:disabled:bg-gradient-to-tr lg:disabled:bg-origin-padding lg:disabled:bg-left-bottom lg:disabled:bg-no-repeat lg:disabled:bg-contain lg:disabled:border-b-2 after:border-spacing-[5%] after:rounded-full after:border-l-[3px] after:border-l-transparent after:border-l-[1rem] after:border-r-2 after:border-r-[aqua] after:border-r-8 after:border-dashed after:border-t-[some-invalid-value] after:flex-1 after:rounded-tl-none after:rounded-tr-[0.25%] after:border-t-[current] after:border-t-[100vh] after:border-dotted after:border-0 after:bottom-[100vw] box-decoration-slice shadow box-border break-after-all break-before-page break-inside-avoid-column caret-[color:var(--cyan)] h-9 flex-1 xl:flex-[1_0] xl:clear-both xl:text-lime-200 xl:gap-x-48 xl:columns-3 xl:content-none xl:cursor-pointer xl:hidden xl:fill-sky-800 xl:blur-sm xl:brightness-50 xl:sepia xl:contrast-100 xl:hue-rotate-30 xl:invert-0 xl:opacity-5 xl:saturate-150 xl:flex-auto xl:basis-3 xl:flex-col-reverse xl:grow xl:shrink-0 xl:flex-wrap-reverse xl:float-right xl:text-2xl xl:antialiased xl:italic xl:ordinal xl:font-semibold;
/* arbitary value */
animation-delay: 200ms;
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/input.css
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@
border-top-width: 100vh;
border-width: 0px;
bottom: 100vw;
flex: 1;
}
}

Expand All @@ -173,8 +174,10 @@
break-inside: avoid-column;
caret-color: var(--cyan);
height: 2.25rem;
flex: 1 1;

@media (min-width: 1280px) {
flex: 1 0;
clear: both;
color: #d9f99d;
column-gap: 12rem;
Expand Down

0 comments on commit e417b51

Please sign in to comment.