Skip to content

Commit f5a108c

Browse files
committed
Deprecate compoundVariants in favor of compound_variants
1 parent fe9ddbd commit f5a108c

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,4 +1,5 @@
11
## Unreleased
2+
- Deprecate compoundVariants in favor of compound_variants
23

34
## 0.0.7 (2023-12-07)
45
- 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,12 +1,17 @@
11
module ClassVariants
22
class Instance
3-
attr_reader :classes, :variants, :compoundVariants, :defaults
3+
attr_reader :classes, :variants, :compound_variants, :defaults
44

55
# rubocop:disable Naming/VariableName
6-
def initialize(classes = "", variants: {}, compoundVariants: [], defaults: {})
6+
def initialize(classes = "", variants: {}, compoundVariants: [], compound_variants: [], defaults: {})
7+
warn <<~MSG unless compoundVariants.empty?
8+
(ClassVariants) DEPRECATION WARNING: Use of `compoundVariants` keyword argument is deprecated.
9+
Use the `compound_variant` instead.
10+
MSG
11+
712
@classes = classes
813
@variants = expand_boolean_variants(variants)
9-
@compoundVariants = compoundVariants
14+
@compound_variants = compound_variants.empty? ? compoundVariants : compound_variants
1015
@defaults = defaults
1116
end
1217
# rubocop:enable Naming/VariableName
@@ -23,7 +28,7 @@ def render(**overrides)
2328
result << @variants.dig(variant_type, variant)
2429
end
2530

26-
@compoundVariants.each do |compound_variant|
31+
@compound_variants.each do |compound_variant|
2732
if (compound_variant.keys - [:class]).all? { |key| selected[key] == compound_variant[key] }
2833
result << compound_variant[:class]
2934
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 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)