Skip to content

Commit 36ee0d6

Browse files
authored
Merge pull request avo-hq#20 from javierav/feature/deprecate-compound-variants
Deprecate compoundVariants in favor of compound_variants
2 parents b8ca92c + 9329c4f commit 36ee0d6

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Unreleased
22
- Deprecate usage of positional arguments ([#12](https://github.com/avo-hq/class_variants/pull/12))
3+
- Deprecate compoundVariants in favor of compound_variants ([#20](https://github.com/avo-hq/class_variants/pull/20))
34

45
## 0.0.7 (2023-12-07)
56
- Add support for compound variants ([#8](https://github.com/avo-hq/class_variants/pull/8))

lib/class_variants/instance.rb

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
module ClassVariants
22
class Instance
3-
attr_reader :base, :variants, :compoundVariants, :defaults
3+
attr_reader :base, :variants, :compound_variants, :defaults
44

55
# rubocop:disable Naming/VariableName
6-
def initialize(classes = nil, base: nil, variants: {}, compoundVariants: [], defaults: {})
6+
def initialize(classes = nil, base: nil, variants: {}, compoundVariants: [], compound_variants: [], defaults: {})
77
warn <<~MSG if classes
88
(ClassVariants) DEPRECATION WARNING: Use of positional argument for default classes is deprecated
99
and will be removed in the next version. Use the `base` keyword argument instead.
1010
MSG
1111

12+
warn <<~MSG unless compoundVariants.empty?
13+
(ClassVariants) DEPRECATION WARNING: Use of `compoundVariants` keyword argument is deprecated
14+
and will be removed in the next version. Use the `compound_variant` instead.
15+
MSG
16+
1217
@base = base || classes
1318
@variants = expand_boolean_variants(variants)
14-
@compoundVariants = compoundVariants
19+
@compound_variants = compound_variants.empty? ? compoundVariants : compound_variants
1520
@defaults = defaults
1621
end
1722
# rubocop:enable Naming/VariableName
@@ -28,7 +33,7 @@ def render(**overrides)
2833
result << @variants.dig(variant_type, variant)
2934
end
3035

31-
@compoundVariants.each do |compound_variant|
36+
@compound_variants.each do |compound_variant|
3237
if (compound_variant.keys - [:class]).all? { |key| selected[key] == compound_variant[key] }
3338
result << compound_variant[:class]
3439
end

readme.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ We create an object from the class or helper where we define the configuration u
3535

3636
1. The `base` keyword argument with default classes that should be applied to each variant.
3737
1. The `variants` keyword argument where we declare the variants with their option and classes.
38-
1. The `compoundVariants` keyword argument where we declare the compound variants with their conditions and classes.
38+
1. The `compound_variants` keyword argument where we declare the compound variants with their conditions and classes
3939
1. The `defaults` keyword argument (optional) where we declare the default value for each variant.
4040

4141
## Example
@@ -90,7 +90,7 @@ button_classes = ClassVariants.build(
9090
},
9191
border: "border"
9292
},
93-
compoundVariants: [
93+
compound_variants: [
9494
{ color: :red, border: true, class: "border-red-800" },
9595
{ color: :blue, border: true, class: "border-blue-800" }
9696
]

test/class_variants_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def setup
1717
visible: "inline-block",
1818
"!visible": "hidden"
1919
},
20-
compoundVariants: [
20+
compound_variants: [
2121
{ring: true, color: :red, class: "focus:ring-red-600"},
2222
{ring: true, color: :green, class: "focus:ring-green-600"}
2323
],

0 commit comments

Comments
 (0)