componeer 0.0.7b → 0.0.11a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f497c0538b1d0dadcb6e0784b88b9d649ef2670e7c62f37127e12d19dcdcb38
4
- data.tar.gz: d362b552e3a1daf1b6a5e5bf439cc1dc9457ad969ec099b5ad02835768cbd542
3
+ metadata.gz: fea358fca5011fbf1cc657f027aaad0cc072b909c011c06f01944148653aa4f5
4
+ data.tar.gz: dbc3edcf000d827c5a08d1826b333bdcd91204f59ad684d916de37d77273f93e
5
5
  SHA512:
6
- metadata.gz: e8a0678a20adeb1b42e62d4e4933095031047b7989e4d062564f9a2b8654637538c3a25540a83f99cbe59e554c8c23faa2c698ad712835e1a24e308b51982c29
7
- data.tar.gz: ec3cd5cab6ced503afe8b739e42e68adb850a3fef1984720b0c6b935af5e720689ecc9ea8fa4a882444e0f917aa5292f03ff043710694f51fb51921dcb9b046e
6
+ metadata.gz: 5c37119eaa82dd6c26540e2baec5ba4372504de9bb1d7551ed3c01209d15150857676d08d37ae6476f6beafe3aaefb3b92a841232f7d6871efb6ae8bdb67782b
7
+ data.tar.gz: 73918f9a74b589e5067e02713730e3afdaea3eea368e2a8ebca00629859f11036467efeb5a29313034ca3d4d061777058af44286d910390ad4329ff7a2c34244
@@ -1,3 +1,5 @@
1
+ require 'tailwind_merge'
2
+
1
3
  module Componeer
2
4
  class BaseComponent < ViewComponent::Base
3
5
  include Componeer::Helpers
@@ -37,8 +39,12 @@ module Componeer
37
39
  **options)
38
40
  end
39
41
 
42
+ def merge_tailwind_classes(*classes)
43
+ TailwindMerge::Merger.new.merge(to_classes_string(classes))
44
+ end
45
+
40
46
  def to_classes_string(array)
41
- array.flatten.compact_blank.uniq.join(' ')
47
+ flattenize(array).join(' ')
42
48
  end
43
49
 
44
50
  private
@@ -53,5 +59,19 @@ module Componeer
53
59
 
54
60
  @options = opts
55
61
  end
62
+
63
+ def resolve_custom_classes(string_or_hash)
64
+ return {} unless string_or_hash
65
+
66
+ if string_or_hash.is_a?(String)
67
+ self.class::CUSTOM_CLASS_KEYS.index_with { |_key| string_or_hash }
68
+ else
69
+ string_or_hash
70
+ end
71
+ end
72
+
73
+ def flattenize(array)
74
+ [array].flatten.compact_blank.uniq
75
+ end
56
76
  end
57
77
  end
@@ -0,0 +1,11 @@
1
+ <div>
2
+ <% if header? %>
3
+ <div class="<%= header_styles %>">
4
+ <%= header_text || header %>
5
+ </div>
6
+ <% end %>
7
+
8
+ <div class="<%= body_styles %>">
9
+ <%= body_text || body %>
10
+ </div>
11
+ </div>
@@ -0,0 +1,54 @@
1
+ module Componeer
2
+ module Cards
3
+ class CardComponent < BaseComponent
4
+ register_as :card
5
+
6
+ renders_one :header
7
+ renders_one :body
8
+
9
+ attr_reader :mode, :header_text, :body_text, :size, :color, :shape, :custom_classes
10
+
11
+ CUSTOM_CLASS_KEYS = %i[header body].freeze
12
+ DEFAULT_OPTIONS = { mode: :primary, header_text: nil, body_text: nil, size: :default,
13
+ color: :default }.freeze
14
+
15
+ def initialize(**options)
16
+ @custom_classes = resolve_custom_classes(options.delete(:class))
17
+ build_options(options)
18
+ end
19
+
20
+ def header?
21
+ (header_text || header).present?
22
+ end
23
+
24
+ def primary?
25
+ mode == :primary
26
+ end
27
+
28
+ def header_styles
29
+ merge_tailwind_classes([common_styles, styles[:header], border_for(:header),
30
+ shape_for(:header), custom_classes[:header]&.to_s&.split])
31
+ end
32
+
33
+ def body_styles
34
+ merge_tailwind_classes([common_styles, styles[:body], border_for(:body), shape_for(:body),
35
+ custom_classes[:body]&.to_s&.split])
36
+ end
37
+
38
+ private
39
+
40
+ def common_styles
41
+ [styles.dig(:base, :size, size), styles.dig(:base, :color, mode, color)]
42
+ end
43
+
44
+ def border_for(element)
45
+ { header: primary? ? 'border-b' : 'border',
46
+ body: primary? ? '' : "border #{(header? && 'border-t-0').presence}" }.fetch(element)
47
+ end
48
+
49
+ def shape_for(element)
50
+ { header: 'rounded-t-lg', body: header? ? 'rounded-b-lg' : 'rounded-lg' }.fetch(element)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,20 @@
1
+ ---
2
+ :base:
3
+ :size:
4
+ :small: text-xs px-2 py-1
5
+ :default: text-sm px-3 py-2
6
+ :color:
7
+ :outline:
8
+ :default: bg-white text-gray-800 border-gray-300
9
+ :brand: bg-white text-brand-800 border-brand-300
10
+ :info: bg-white text-cyan-800 border-cyan-300
11
+ :warning: bg-white text-amber-800 border-amber-300
12
+ :danger: bg-white text-red-800 border-red-300
13
+ :primary:
14
+ :default: bg-gray-50 text-gray-800 border-gray-300
15
+ :brand: bg-brand-50 text-brand-800 border-brand-300
16
+ :info: bg-cyan-50 text-cyan-800 border-cyan-300
17
+ :warning: bg-amber-50 text-amber-800 border-amber-300
18
+ :danger: bg-red-50 text-red-800 border-red-300
19
+ :header: font-semibold
20
+ :body: font-normal
@@ -1,16 +1,18 @@
1
1
  module Componeer
2
2
  module Tables
3
3
  class ColumnComponent < BaseComponent
4
- attr_reader :table, :title, :custom_classes, :alignment, :options
4
+ attr_reader :table, :title, :custom_classes, :align, :options
5
5
  delegate :density, to: :table
6
6
 
7
+ CUSTOM_CLASS_KEYS = %i[th td].freeze
8
+ DEFAULT_OPTIONS = { align: :left }.freeze
9
+
7
10
  def initialize(table, title, **options, &block)
8
11
  @table = table
9
12
  @title = title
10
- @custom_classes = resolve_classes(options.delete(:class)) || {}
11
- @alignment = options.delete(:align) || :left
12
- @options = options
13
+ @custom_classes = resolve_custom_classes(options.delete(:class))
13
14
  @block = block
15
+ build_options(options)
14
16
  end
15
17
 
16
18
  def call(record)
@@ -28,17 +30,9 @@ module Componeer
28
30
  private
29
31
 
30
32
  def attribute_classes(attr, key:)
31
- to_classes_string([styles.dig(key, :column, :density, density),
32
- styles.dig(key, :column, :alignment, alignment),
33
- custom_classes[attr].to_s.split])
34
- end
35
-
36
- def resolve_classes(hash_or_string)
37
- if hash_or_string.is_a?(String)
38
- { th: hash_or_string, td: hash_or_string }
39
- else
40
- hash_or_string
41
- end
33
+ merge_tailwind_classes([styles.dig(key, :column, :density, density),
34
+ styles.dig(key, :column, :alignment, align),
35
+ custom_classes[attr].to_s.split])
42
36
  end
43
37
  end
44
38
  end
@@ -1,11 +1,12 @@
1
1
  ---
2
2
  :size:
3
- :small: text-xs px-1 p-0.5
3
+ :small: text-xs px-1.5 p-0.5
4
4
  :default: text-sm px-2 py-1
5
5
  :large: text-base px-3 py-1.5
6
6
  :shape:
7
- :rounded: rounded rounded-lg
7
+ :rounded: rounded-lg
8
8
  :flat: rounded-none
9
+ :circle: :rounded-full
9
10
  :color:
10
11
  :gray: bg-gray-100 text-gray-700
11
12
  :brand: bg-brand-100 text-brand-700
@@ -3,19 +3,21 @@ module Componeer
3
3
  class TagComponent < BaseComponent
4
4
  register_as :tag
5
5
 
6
- attr_reader :text, :type, :size, :color, :shape, :options
6
+ attr_reader :text, :type, :size, :color, :shape, :custom_classes, :options
7
7
 
8
8
  DEFAULT_OPTIONS = { type: :default, size: :default, color: :gray, shape: :rounded }.freeze
9
9
 
10
10
  def initialize(text = nil, **options)
11
11
  @text = text
12
+ @custom_classes = options.delete(:class)
12
13
  build_options(options)
13
14
  end
14
15
 
15
16
  def base_classes
16
- to_classes_string([styles.dig(:size, size),
17
- styles.dig(:color, color),
18
- styles.dig(:shape, shape)])
17
+ merge_tailwind_classes([styles.dig(:size, size),
18
+ styles.dig(:color, color),
19
+ styles.dig(:shape, shape),
20
+ custom_classes])
19
21
  end
20
22
  end
21
23
  end
@@ -1,3 +1,5 @@
1
+ require 'inline_svg'
2
+
1
3
  InlineSvg.configure do |config|
2
4
  config.asset_file = InlineSvg::CachedAssetFile.new(
3
5
  paths: ["#{__dir__}/../../app/assets/images/icons/"],
@@ -1,3 +1,3 @@
1
1
  module Componeer
2
- VERSION = '0.0.7b'.freeze
2
+ VERSION = '0.0.11a'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: componeer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7b
4
+ version: 0.0.11a
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andre Rodrigues
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-06-04 00:00:00.000000000 Z
13
+ date: 2024-09-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: inline_svg
@@ -32,6 +32,20 @@ dependencies:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: 1.9.0
35
+ - !ruby/object:Gem::Dependency
36
+ name: tailwind_merge
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 0.12.0
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: 0.12.0
35
49
  - !ruby/object:Gem::Dependency
36
50
  name: view_component
37
51
  requirement: !ruby/object:Gem::Requirement
@@ -76,6 +90,9 @@ files:
76
90
  - app/components/componeer/buttons/button_component.html.erb
77
91
  - app/components/componeer/buttons/button_component.rb
78
92
  - app/components/componeer/buttons/styles.yml
93
+ - app/components/componeer/cards/card_component.html.erb
94
+ - app/components/componeer/cards/card_component.rb
95
+ - app/components/componeer/cards/styles.yml
79
96
  - app/components/componeer/empty_states/empty_state_component.html.erb
80
97
  - app/components/componeer/empty_states/empty_state_component.rb
81
98
  - app/components/componeer/tables/column_component.rb