Skip to content

Commit 3552085

Browse files
authored
Merge pull request #13 from productive-codebases/feat/accept-styles-directly
Accept styles directly on conditions.
2 parents 8ae71e4 + b3ffe06 commit 3552085

5 files changed

+18
-6
lines changed

CHANGELOG.md

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

3+
## v1.5.0 (2024-03-09)
4+
5+
### Added
6+
7+
- Accept styles directly as the second argument on conditions.
8+
39
## v1.4.0 (2023-07-24)
410

511
### Added

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@productive-codebases/build-variants",
3-
"version": "1.4.0",
3+
"version": "1.5.0",
44
"description": "Declare and compose styles variants with ease.",
55
"author": "Alexis MINEAUD",
66
"license": "MIT",

src/lib/BuildVariantsBuilder.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export default class BuildVariantsBuilder<
235235
*/
236236
if(
237237
apply: boolean | (() => boolean),
238-
fn: BuildVariantsBuilderFn<TProps, TCSSObject>,
238+
cssOrFn: TCSSObject | BuildVariantsBuilderFn<TProps, TCSSObject>,
239239
options?: BuildVariantsMergerCssPartsOptionsPublic
240240
): this {
241241
const applyValue = typeof apply === 'function' ? apply() : apply
@@ -245,7 +245,9 @@ export default class BuildVariantsBuilder<
245245
variantsDefinitions: this._allVariantsDefinitions
246246
})
247247

248-
return this._addCssPart(null, fn(builder), options)
248+
const cssPart = typeof cssOrFn === 'function' ? cssOrFn(builder) : cssOrFn
249+
250+
return this._addCssPart(null, cssPart, options)
249251
}
250252

251253
/**

src/tests/BuildVariantsBuilder.test.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,15 @@ describe('BuildVariantsBuilder', () => {
313313
.end()
314314
}
315315
)
316+
.if(true, {
317+
border: '1px solid red'
318+
})
316319
.end()
317320

318321
expect(css).toEqual({
319322
color: 'silver',
320-
background: 'lime'
323+
background: 'lime',
324+
border: '1px solid red'
321325
})
322326
})
323327
})

0 commit comments

Comments
 (0)