Skip to content

Commit

Permalink
support arbitrary named colors
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredh159 committed Jul 9, 2024
1 parent 8011d31 commit c8398f9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.4.0] - 2024-07-09

- added support for arbitrary named colors (eg. `text-[lemonchiffon]`)
[(#282)](https://github.com/jaredh159/tailwind-react-native-classnames/issues/306) and
[(#293)](https://github.com/jaredh159/tailwind-react-native-classnames/pull/309)

## [4.3.0] - 2024-06-18

- added support for line-height shorthand with font-size (eg. `text-sm/6`)
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/borders.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe(`borders`, () => {
[`border-white`, { borderColor: `#fff` }],
[`border-t-white`, { borderTopColor: `#fff` }],
[`border-t-[#e9c46a]`, { borderTopColor: `#e9c46a` }],
[`border-t-[steelblue]`, { borderTopColor: `steelblue` }],
[`border-blue-200`, { borderColor: `#bfdbfe` }],
[`border-black border-opacity-50`, { borderColor: `rgba(0, 0, 0, 0.5)` }],
[`border-dashed`, { borderStyle: `dashed` }],
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/colors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ describe(`colors`, () => {

test(`arbitrary color values`, () => {
expect(tw`bg-[#012]`).toEqual({ backgroundColor: `#012` });
expect(tw`bg-[rebeccapurple]`).toEqual({ backgroundColor: `rebeccapurple` });
expect(tw`bg-[rgba(3,4,5,0.1)]`).toEqual({
backgroundColor: `rgba(3,4,5,0.1)`,
});
Expand Down
7 changes: 4 additions & 3 deletions src/resolve/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ export function color(

let color = ``;

// for arbitrary support: `bg-[#eaeaea]`, `text-[rgba(1, 1, 1, 0.5)]`
// arbitrary hex/rgb(a) support: `bg-[#eaeaea]`, `text-[rgba(1, 1, 1, 0.5)]`
if (value.startsWith(`[#`) || value.startsWith(`[rgb`)) {
color = value.slice(1, -1);

// search for color in config
// arbitrary named colors: `bg-[lemonchiffon]`
} else if (value.startsWith(`[`) && value.slice(1, -1).match(/^[a-z]{3,}$/)) {
color = value.slice(1, -1);
} else {
color = configColor(value, config) ?? ``;
}
Expand Down

0 comments on commit c8398f9

Please sign in to comment.