Skip to content

Commit

Permalink
chore: update aspect-ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
hunghg255 committed Sep 12, 2023
1 parent c51ac8e commit fe10b08
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
20 changes: 20 additions & 0 deletions __TEST__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,23 @@ test('CSS to tailwindcss with variable', () => {
],
});
});

test('CSS Aspect Ratio', () => {
const cssCode1 = `body {
aspect-ratio: auto;
aspect-ratio: 1 / 1;
aspect-ratio: 16 / 9;
aspect-ratio: 3 / 4;
}`;

expect(CssToTailwind(cssCode1)).toEqual({
code: 'OK',
data: [
{
resultVal: 'aspect-auto aspect-square aspect-video [aspect-ratio:3_/_4]',
selectorName: 'body',
},
],
});
});

10 changes: 8 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CssCodeParse, CustomSelect, CustomTheme, ResultCode, TranslatorConfig } from "./types";
import { getBorderRadiusDefaultVal, getCustomVal, getFilterDefaultVal, getFontSizeDefaultVal, getRemDefaultVal, getUnitMetacharactersVal, hasNegative, isColor, isUnit } from "./utils";
import { getBorderRadiusDefaultVal, getCustomVal, getFilterDefaultVal, getFontSizeDefaultVal, getRemDefaultVal, getUnitMetacharactersVal, hasNegative, isColor, isUnit, removeSpace } from "./utils";

const specialAttribute = ['@charset', '@font-face', '@import', '@keyframes'];

Expand Down Expand Up @@ -83,7 +83,13 @@ const propertyMap: Map<
(val) =>
({ none: 'appearance-none' }[val] ?? `[appearance:${getCustomVal(val)}]`),
],
['aspect-ratio', (val) => `[aspect-ratio:${getCustomVal(val)}]`],
['aspect-ratio', (val) => {
return {
auto: 'aspect-auto',
'1/1': 'aspect-square',
'16/9': 'aspect-video',
}[removeSpace(val)] ?? `[aspect-ratio:${getCustomVal(val)}]`;
}],
[
'backdrop-filter',
(val) => {
Expand Down
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,7 @@ export const getFontSizeDefaultVal = (val: string) => {

return fontSize[val] ?? `text-[${val}]`;
};

export const removeSpace = (str: string) => {
return str.replace(/\s/g, '');
}

0 comments on commit fe10b08

Please sign in to comment.