Skip to content

Commit 268ce98

Browse files
committed
style: formatted code
1 parent 8068c65 commit 268ce98

File tree

2 files changed

+54
-51
lines changed

2 files changed

+54
-51
lines changed

packages/jacaranda/src/index.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,30 +133,30 @@ describe('sva', () => {
133133
variants: {
134134
disabled: {
135135
true: { opacity: 0.5 },
136-
false: { opacity: 1 }
137-
}
136+
false: { opacity: 1 },
137+
},
138138
},
139139
defaultVariants: {
140-
disabled: false
141-
}
140+
disabled: false,
141+
},
142142
});
143143

144144
// Test with explicit true value
145145
expect(buttonStyles({ disabled: true })).toEqual({
146146
display: 'flex',
147-
opacity: 0.5
147+
opacity: 0.5,
148148
});
149149

150150
// Test with explicit false value
151151
expect(buttonStyles({ disabled: false })).toEqual({
152152
display: 'flex',
153-
opacity: 1
153+
opacity: 1,
154154
});
155155

156156
// Test with default value
157157
expect(buttonStyles()).toEqual({
158158
display: 'flex',
159-
opacity: 1
159+
opacity: 1,
160160
});
161161
});
162162

@@ -167,12 +167,12 @@ describe('sva', () => {
167167
variants: {
168168
disabled: {
169169
true: { opacity: 0.5 },
170-
false: { opacity: 1 }
170+
false: { opacity: 1 },
171171
},
172172
size: {
173173
sm: { padding: 4 },
174174
lg: { padding: 8 },
175-
}
175+
},
176176
},
177177
compoundVariants: [
178178
{
@@ -182,23 +182,23 @@ describe('sva', () => {
182182
],
183183
defaultVariants: {
184184
disabled: false,
185-
size: 'sm'
186-
}
185+
size: 'sm',
186+
},
187187
});
188188

189189
// Test compound variant with boolean true
190190
expect(buttonStyles({ disabled: true, size: 'lg' })).toEqual({
191191
display: 'flex',
192192
opacity: 0.5,
193193
padding: 8,
194-
fontStyle: 'italic'
194+
fontStyle: 'italic',
195195
});
196196

197197
// Test without triggering compound variant
198198
expect(buttonStyles({ disabled: true, size: 'sm' })).toEqual({
199199
display: 'flex',
200200
opacity: 0.5,
201-
padding: 4
201+
padding: 4,
202202
});
203203
});
204204
});

packages/jacaranda/src/index.ts

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,10 @@ function styles<V extends VariantOptions<V>>(config: VariantStyleConfig<V>) {
117117
} as VariantProps;
118118

119119
// Apply variant styles
120-
for (const [propName, value] of Object.entries(mergedProps) as [keyof V, keyof VariantProps[keyof V] | boolean][]) {
120+
for (const [propName, value] of Object.entries(mergedProps) as [
121+
keyof V,
122+
keyof VariantProps[keyof V] | boolean,
123+
][]) {
121124
const variantGroup = config.variants[propName];
122125
if (variantGroup) {
123126
// Handle boolean variants
@@ -146,15 +149,13 @@ function styles<V extends VariantOptions<V>>(config: VariantStyleConfig<V>) {
146149
if (config.compoundVariants) {
147150
for (const compound of config.compoundVariants) {
148151
if (
149-
Object.entries(compound.variants).every(
150-
([propName, value]) => {
151-
// Handle boolean values in compound variants
152-
if (typeof value === 'boolean') {
153-
return mergedProps[propName as keyof V] === value;
154-
}
152+
Object.entries(compound.variants).every(([propName, value]) => {
153+
// Handle boolean values in compound variants
154+
if (typeof value === 'boolean') {
155155
return mergedProps[propName as keyof V] === value;
156156
}
157-
)
157+
return mergedProps[propName as keyof V] === value;
158+
})
158159
) {
159160
styles = {
160161
...styles,
@@ -191,22 +192,25 @@ interface CreateTokensReturn {
191192

192193
// Helper to resolve token references in style objects
193194
function resolveTokens(style: StyleObject, tokens: TokenConfig): StyleObject {
194-
return Object.entries(style).reduce<Record<string, ResolvedStyle[keyof ResolvedStyle]>>((acc, [key, value]) => {
195-
if (typeof value !== 'string' || !value.startsWith('$')) {
196-
acc[key] = value;
197-
return acc;
198-
}
195+
return Object.entries(style).reduce<Record<string, ResolvedStyle[keyof ResolvedStyle]>>(
196+
(acc, [key, value]) => {
197+
if (typeof value !== 'string' || !value.startsWith('$')) {
198+
acc[key] = value;
199+
return acc;
200+
}
199201

200-
const tokenPath = value.slice(1).split('.');
201-
const [category, token] = tokenPath;
202+
const tokenPath = value.slice(1).split('.');
203+
const [category, token] = tokenPath;
202204

203-
const tokenValue = tokens[category as keyof TokenConfig]?.[token];
204-
if (tokenValue !== undefined) {
205-
acc[key] = tokenValue;
206-
}
205+
const tokenValue = tokens[category as keyof TokenConfig]?.[token];
206+
if (tokenValue !== undefined) {
207+
acc[key] = tokenValue;
208+
}
207209

208-
return acc;
209-
}, {}) as StyleObject;
210+
return acc;
211+
},
212+
{},
213+
) as StyleObject;
210214
}
211215

212216
/**
@@ -228,25 +232,24 @@ export function defineTokens<T extends TokenConfig>(tokenConfig: T): CreateToken
228232

229233
// Resolve tokens in variants
230234
const resolvedVariants = config.variants
231-
? Object.entries(config.variants).reduce<Partial<V>>((acc, [key, variantGroup]) => {
235+
? (Object.entries(config.variants).reduce<Partial<V>>((acc, [key, variantGroup]) => {
232236
type VariantGroupType = Record<string, StyleObject>;
233-
234-
const resolvedGroup = Object.entries(variantGroup as VariantGroupType).reduce<Record<string, StyleObject>>(
235-
(groupAcc, [variantKey, variantStyles]) => {
236-
return {
237-
...groupAcc,
238-
[variantKey]: resolveTokens(variantStyles, tokens),
239-
};
240-
},
241-
{}
242-
);
243-
244-
return {
245-
...acc,
246-
[key as keyof V]: resolvedGroup as V[keyof V]
237+
238+
const resolvedGroup = Object.entries(variantGroup as VariantGroupType).reduce<
239+
Record<string, StyleObject>
240+
>((groupAcc, [variantKey, variantStyles]) => {
241+
return {
242+
...groupAcc,
243+
[variantKey]: resolveTokens(variantStyles, tokens),
244+
};
245+
}, {});
246+
247+
return {
248+
...acc,
249+
[key as keyof V]: resolvedGroup as V[keyof V],
247250
};
248-
}, {}) as V
249-
: {} as V;
251+
}, {}) as V)
252+
: ({} as V);
250253

251254
// Resolve tokens in compound variants
252255
const resolvedCompoundVariants = config.compoundVariants?.map((compound) => ({

0 commit comments

Comments
 (0)