diff --git a/changelog.md b/changelog.md index f20e9f4..8603f0f 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,12 @@ on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project ad [comment]: # 'Section Titles: Added/Fixed/Changed/Removed' +## [4.5.0] - 2024-07-22 + +- added support for `size-*` shorthand utility + [(#314)](https://github.com/jaredh159/tailwind-react-native-classnames/issues/314) and + [(#315)](https://github.com/jaredh159/tailwind-react-native-classnames/pull/315) + ## [4.4.0] - 2024-07-09 - added support for arbitrary named colors (eg. `text-[lemonchiffon]`) diff --git a/src/UtilityParser.ts b/src/UtilityParser.ts index bf2192c..692fcb9 100644 --- a/src/UtilityParser.ts +++ b/src/UtilityParser.ts @@ -12,7 +12,7 @@ import { border, borderRadius } from './resolve/borders'; import * as h from './helpers'; import { inset } from './resolve/inset'; import { flexGrowShrink, flexBasis, flex, gap } from './resolve/flex'; -import { widthHeight, minMaxWidthHeight } from './resolve/width-height'; +import { widthHeight, size, minMaxWidthHeight } from './resolve/width-height'; import { letterSpacing } from './resolve/letter-spacing'; import { opacity } from './resolve/opacity'; import { shadowOpacity, shadowOffset } from './resolve/shadow'; @@ -295,6 +295,11 @@ export default class UtilityParser { } } + if (this.consumePeeked(`size-`)) { + style = size(this.rest, this.context, theme); + if (style) return style; + } + h.warn(`\`${this.rest}\` unknown or invalid utility`); return null; } diff --git a/src/__tests__/width-height.spec.ts b/src/__tests__/width-height.spec.ts index 645c780..fb92f7f 100644 --- a/src/__tests__/width-height.spec.ts +++ b/src/__tests__/width-height.spec.ts @@ -38,6 +38,11 @@ describe(`width/height utilities`, () => { // arbitrary [`h-[333px]`, { height: 333 }], + // size-* + [`size-1`, { width: 4, height: 4 }], + [`size-3/4`, { width: `75%`, height: `75%` }], + [`size-[333px]`, { width: 333, height: 333 }], + // not configged, use 0.25rem = 1 as formula [`h-81`, { height: (81 / 4) * 16 }], diff --git a/src/resolve/width-height.ts b/src/resolve/width-height.ts index d611972..b542b3c 100644 --- a/src/resolve/width-height.ts +++ b/src/resolve/width-height.ts @@ -16,6 +16,19 @@ export function widthHeight( return unconfiggedStyle(type, value, context); } +export function size( + value: string, + context: ParseContext = {}, + theme?: TwTheme, +): StyleIR | null { + const width = widthHeight(`width`, value, context, theme?.width); + const height = widthHeight(`height`, value, context, theme?.height); + if (width?.kind !== `complete` || height?.kind !== `complete`) { + return null; + } + return complete({ ...width.style, ...height.style }); +} + export function minMaxWidthHeight( type: 'minWidth' | 'minHeight' | 'maxWidth' | 'maxHeight', value: string,