Skip to content

Commit 7722c75

Browse files
committed
Fix raw styles with falsy conditions.
1 parent 3552085 commit 7722c75

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v1.5.1 (2024-03-13)
4+
5+
### Fixed
6+
7+
- Fix styles application when using raw styles in a `if` block.
8+
39
## v1.5.0 (2024-03-09)
410

511
### Added

src/lib/BuildVariantsBuilder.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,17 @@ export default class BuildVariantsBuilder<
245245
variantsDefinitions: this._allVariantsDefinitions
246246
})
247247

248-
const cssPart = typeof cssOrFn === 'function' ? cssOrFn(builder) : cssOrFn
248+
// pass the builder instance
249+
if (typeof cssOrFn === 'function') {
250+
return this._addCssPart(null, cssOrFn(builder), options)
251+
}
249252

250-
return this._addCssPart(null, cssPart, options)
253+
// pass raw object directly
254+
if (apply) {
255+
return this._addCssPart(null, cssOrFn, options)
256+
}
257+
258+
return this
251259
}
252260

253261
/**

src/tests/BuildVariantsBuilder.test.ts

+22-6
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ describe('BuildVariantsBuilder', () => {
278278
}
279279

280280
const css = testBuildVariants(props)
281+
// should be not applied
281282
.if(false, builder_ => {
282283
return builder_
283284
.css({
@@ -294,6 +295,7 @@ describe('BuildVariantsBuilder', () => {
294295
})
295296
.end()
296297
})
298+
// should be applyed
297299
.if(
298300
() => true,
299301
builder_ => {
@@ -303,24 +305,38 @@ describe('BuildVariantsBuilder', () => {
303305
})
304306
.variant('type', props.type, {
305307
success: {
306-
background: 'lime'
308+
textDecoration: 'underline'
307309
},
308310

309-
error: {
310-
background: 'orange'
311-
}
311+
error: {}
312+
})
313+
.compoundVariant('type', props.type, {
314+
success: builder_ =>
315+
builder_
316+
// should not be applied because defined in a if(false) block
317+
.get('type', 'success')
318+
// should be applied
319+
.css({ fontWeight: 'bold' })
320+
.end(),
321+
error: builder_ => builder_.get('type', 'error').end()
312322
})
313323
.end()
314324
}
315325
)
326+
// should not be applyed
327+
.if(false, {
328+
fontSize: '16px'
329+
})
330+
// should be applyed
316331
.if(true, {
317332
border: '1px solid red'
318333
})
319334
.end()
320335

321336
expect(css).toEqual({
322337
color: 'silver',
323-
background: 'lime',
338+
textDecoration: 'underline',
339+
fontWeight: 'bold',
324340
border: '1px solid red'
325341
})
326342
})
@@ -722,7 +738,7 @@ describe('BuildVariantsBuilder', () => {
722738
describe('css()', () => {
723739
it('should apply css according weight', () => {
724740
const css = testBuildVariants({})
725-
// should be applyied because using a weight
741+
// should be applied because using a weight
726742
.css(
727743
{
728744
color: 'red',

0 commit comments

Comments
 (0)