Skip to content

Commit

Permalink
fix: border side prefix match (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
hannoeru committed Oct 28, 2021
1 parent 8d9ed6a commit 42e5590
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/lib/utilities/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ function border(utility: Utility, plugin: PluginUtils, dir = '*', real?: Utility
?.updateMeta('utilities', 'borderOpacity', pluginOrder.borderOpacity, 1, true)

// handle border side
|| dir === '*' && handler.catchPrefix(/^border-[tlbr]/, true)
|| dir === '*' && handler.catchPrefix(/^(border-[tlbr])-/, true, 1)
?.then(() => border(utility.clone('border' + utility.raw.slice(8)), plugin, expandDirection(handler.prefix?.slice(-1) as string, false)?.[0], utility))

// handle border color
Expand Down
6 changes: 3 additions & 3 deletions src/lib/utilities/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type Handler = {
_prefix_expr?: string
opacity?: string | undefined
color?: colorCallback
catchPrefix: (regex: RegExp, match?: boolean) => Handler | undefined,
catchPrefix: (regex: RegExp, match?: boolean, matchIndex?: number) => Handler | undefined,
isStatic: (map: { [key: string]: string | string[] }, amount?: string) => boolean,
isTime: (start: number, end: number, type: 'int' | 'float') => boolean,
isNumber: (start: number, end: number, type: 'int' | 'float') => boolean,
Expand Down Expand Up @@ -111,13 +111,13 @@ export function createHandler(handlers: Handlers = { static: true }): HandlerCre
_amount: utility.amount,
_slices: utility.slices,

catchPrefix: (regex, match = false) => {
catchPrefix: (regex, match = false, matchIndex = 0) => {
handler._prefix_expr = regex.source;

if (match) {
const matched = utility.raw.match(regex);
if (!matched) return;
handler.prefix = matched[0];
handler.prefix = matched[matchIndex];
}
return handler;
},
Expand Down
4 changes: 4 additions & 0 deletions test/processor/__snapshots__/utilities.test.ts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,10 @@ Tools / border top/left/bottom/right color / css / 0: |-
--tw-border-opacity: 1;
border-color: rgba(167, 243, 208, var(--tw-border-opacity));
}
.border-true-gray-300 {
--tw-border-opacity: 1;
border-color: rgba(212, 212, 212, var(--tw-border-opacity));
}
.border-green-200\/50 {
--tw-border-opacity: 0.5;
border-color: rgba(167, 243, 208, var(--tw-border-opacity));
Expand Down
2 changes: 1 addition & 1 deletion test/processor/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ describe('Utilities', () => {
});

it('border top/left/bottom/right color', () => {
expect(processor.interpret('border-t-green-200 border-t-green-200/50 border-b-green-200 border-green-200 border-green-200/50').styleSheet.build()).toMatchSnapshot('css');
expect(processor.interpret('border-t-green-200 border-t-green-200/50 border-b-green-200 border-green-200 border-true-gray-300 border-green-200/50').styleSheet.build()).toMatchSnapshot('css');
});

it('gradient colors', () => {
Expand Down

0 comments on commit 42e5590

Please sign in to comment.