componeer 0.0.7a → 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 +4 -4
- data/app/components/componeer/base_component.rb +34 -1
- data/app/components/componeer/cards/card_component.html.erb +11 -0
- data/app/components/componeer/cards/card_component.rb +54 -0
- data/app/components/componeer/cards/styles.yml +20 -0
- data/app/components/componeer/empty_states/empty_state_component.rb +4 -4
- data/app/components/componeer/tables/column_component.rb +9 -15
- data/app/components/componeer/tables/table_component.rb +3 -3
- data/app/components/componeer/tags/styles.yml +3 -2
- data/app/components/componeer/tags/tag_component.rb +9 -9
- data/config/initializers/inline_svg.rb +2 -0
- data/lib/componeer/version.rb +1 -1
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fea358fca5011fbf1cc657f027aaad0cc072b909c011c06f01944148653aa4f5
|
4
|
+
data.tar.gz: dbc3edcf000d827c5a08d1826b333bdcd91204f59ad684d916de37d77273f93e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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,39 @@ 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.
|
47
|
+
flattenize(array).join(' ')
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def build_options(opts)
|
53
|
+
opts = opts.reverse_merge(self.class::DEFAULT_OPTIONS)
|
54
|
+
|
55
|
+
opts.each do |k, v|
|
56
|
+
instance_variable_set("@#{k}", v)
|
57
|
+
opts.delete(k)
|
58
|
+
end
|
59
|
+
|
60
|
+
@options = opts
|
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
|
42
75
|
end
|
43
76
|
end
|
44
77
|
end
|
@@ -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
|
@@ -5,11 +5,11 @@ module Componeer
|
|
5
5
|
|
6
6
|
renders_one :new_resource_action
|
7
7
|
|
8
|
-
|
8
|
+
DEFAULT_OPTIONS = { icon: :exclamation, new_resource_path: nil, description: nil }.freeze
|
9
|
+
|
10
|
+
def initialize(resource_name:, **options)
|
9
11
|
@resource_name = resource_name
|
10
|
-
|
11
|
-
@new_resource_path = new_resource_path
|
12
|
-
@description = description
|
12
|
+
build_options(options)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -1,16 +1,18 @@
|
|
1
1
|
module Componeer
|
2
2
|
module Tables
|
3
3
|
class ColumnComponent < BaseComponent
|
4
|
-
attr_reader :table, :title, :custom_classes, :
|
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 =
|
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
|
-
|
32
|
-
|
33
|
-
|
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
|
@@ -19,11 +19,11 @@ module Componeer
|
|
19
19
|
|
20
20
|
attr_reader :records, :density, :striped, :options
|
21
21
|
|
22
|
+
DEFAULT_OPTIONS = { striped: true, density: :default }.freeze
|
23
|
+
|
22
24
|
def initialize(records: nil, **options)
|
23
25
|
@records = records
|
24
|
-
|
25
|
-
@density = options.delete(:density) || :default
|
26
|
-
@options = options
|
26
|
+
build_options(options)
|
27
27
|
end
|
28
28
|
|
29
29
|
def tr_classes(level = :body)
|
@@ -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
|
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,21 +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
|
+
|
8
|
+
DEFAULT_OPTIONS = { type: :default, size: :default, color: :gray, shape: :rounded }.freeze
|
7
9
|
|
8
10
|
def initialize(text = nil, **options)
|
9
11
|
@text = text
|
10
|
-
@
|
11
|
-
|
12
|
-
@color = options.delete(:color) || :gray
|
13
|
-
@shape = options.delete(:shape) || :rounded
|
14
|
-
@options = options
|
12
|
+
@custom_classes = options.delete(:class)
|
13
|
+
build_options(options)
|
15
14
|
end
|
16
15
|
|
17
16
|
def base_classes
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
merge_tailwind_classes([styles.dig(:size, size),
|
18
|
+
styles.dig(:color, color),
|
19
|
+
styles.dig(:shape, shape),
|
20
|
+
custom_classes])
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/componeer/version.rb
CHANGED
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.
|
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-
|
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
|