componeer 0.0.4a → 0.0.7a

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: bf9667e67bbd5867ff0b220fc8e726dd7d38edfeb458b14d4cd9bc14a5884c64
4
- data.tar.gz: 37ede31c7884a7f15aad097f039e63895a459a2c7b1efb1cb080db14eb4aafcb
3
+ metadata.gz: 9fbc69925280e333c8d89044bd85e4e15c4d371eb6acad1d581e832df75cbb9d
4
+ data.tar.gz: 5e6d85cb8b73c1050f8fd277d802e3be1c269908ffd43c8ac5bf99f073863a75
5
5
  SHA512:
6
- metadata.gz: 3342c79bf9a9026842767ad8c735e680c8a2c903cfcc555d7394bc051c153056653364950e08681ba8527d18ef0d14217794cf107ea72ea5e4c7a2d793e8bcd4
7
- data.tar.gz: 4bc158371b0eb9a7e58a349ba41ceab20effa1570167cbeb83ec8aeb7b62899094b892c06906b7515b5333e4a5df50c7b7d23be1d66ef22f013c8feca21869f2
6
+ metadata.gz: 1f5610e4a528847aae3ab4952a2720cf55a8af20e2a07854b0760e47577252392c25d3e83cd2ae77e61bb439fb67c86f69cbb137daeef450735ae9c9a74b862f
7
+ data.tar.gz: 3c48fb148673ca0be5f176f49d8d616354ee004fdbb89c1c5aadcac1469214d5fa0fe9eb72beb6aca1401874c9a1470b6564a24a11f74a039425945117389603
@@ -30,5 +30,15 @@ module Componeer
30
30
  File.exist?(styles_yaml_file) ? YAML.load(ERB.new(File.read(styles_yaml_file)).result) : {}
31
31
  end
32
32
  end
33
+
34
+ def i18n(value, **options)
35
+ I18n.t(value,
36
+ scope: "componeer.#{self.class.to_s.demodulize.underscore.gsub('_component', '')}",
37
+ **options)
38
+ end
39
+
40
+ def to_classes_string(array)
41
+ array.flatten.compact_blank.uniq.join(' ')
42
+ end
33
43
  end
34
44
  end
@@ -1,28 +1,25 @@
1
1
  <div class="flex flex-col py-12 justify-center items-center bg-gray-50 rounded-md">
2
2
  <% if @icon %>
3
- <div><%= inline_svg_tag("#{@icon}.svg", class: 'mx-auto h-12 w-12 text-gray-400') %></div>
3
+ <div>
4
+ <%= inline_svg_tag("#{@icon}.svg", class: 'mx-auto h-12 w-12 text-gray-400') %>
5
+ </div>
4
6
  <% end %>
5
7
 
6
- <h3 class="text-sm font-medium text-gray-900">No <%= @resource_name.pluralize %></h3>
8
+ <h3 class="mt-2 text-sm font-medium text-gray-900">
9
+ <%= i18n('no_resouces', resource_name: @resource_name,
10
+ resource_name_pluralized: @resource_name.pluralize,
11
+ default: 'No %{resource_name_pluralized}') %>
12
+ </h3>
13
+
7
14
  <% if @description %>
8
- <p class="text-sm text-gray-500"><%= @description %></p>
15
+ <p class="text-sm text-gray-500">
16
+ <%= @description %>
17
+ </p>
9
18
  <% end %>
10
- <% if @new_resource_path %>
11
- <div class="flex flex-col items-center space-y-2">
12
- <p class="text-sm text-gray-500">
13
- Get started by creating a new <%= @resource_name %>.
14
- </p>
15
- <div>
16
- <%= componeer.button(size: :small) do %>
17
- <%= link_to @new_resource_path do %>
18
- <div class="flex items-center space-x-2">
19
- <%= inline_svg_tag('plus.svg', class: 'h-5 w-5') %>
20
19
 
21
- <span>New <%= @resource_name %></span>
22
- </div>
23
- <% end %>
24
- <% end %>
25
- </div>
20
+ <% if new_resource_action %>
21
+ <div class="mt-3">
22
+ <%= new_resource_action %>
26
23
  </div>
27
24
  <% end %>
28
25
  </div>
@@ -3,6 +3,8 @@ module Componeer
3
3
  class EmptyStateComponent < BaseComponent
4
4
  register_as :empty_state
5
5
 
6
+ renders_one :new_resource_action
7
+
6
8
  def initialize(resource_name:, icon: :exclamation, new_resource_path: nil, description: nil)
7
9
  @resource_name = resource_name
8
10
  @icon = icon
@@ -0,0 +1,45 @@
1
+ module Componeer
2
+ module Tables
3
+ class ColumnComponent < BaseComponent
4
+ attr_reader :table, :title, :custom_classes, :alignment, :options
5
+ delegate :density, to: :table
6
+
7
+ def initialize(table, title, **options, &block)
8
+ @table = table
9
+ @title = title
10
+ @custom_classes = resolve_classes(options.delete(:class)) || {}
11
+ @alignment = options.delete(:align) || :left
12
+ @options = options
13
+ @block = block
14
+ end
15
+
16
+ def call(record)
17
+ @block.call(record)
18
+ end
19
+
20
+ def th_classes
21
+ attribute_classes(:th, key: :header)
22
+ end
23
+
24
+ def td_classes
25
+ attribute_classes(:td, key: :body)
26
+ end
27
+
28
+ private
29
+
30
+ 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
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,24 @@
1
+ ---
2
+ :header:
3
+ :column:
4
+ :density:
5
+ :default: 'p-3 text-sm font-semibold'
6
+ :compact: 'p-1.5 text-xs font-semibold'
7
+ :alignment:
8
+ :left: 'text-left'
9
+ :right: 'text-right'
10
+ :center: 'text-center'
11
+ :row: 'bg-white border-b border-gray-200'
12
+
13
+ :body:
14
+ :column:
15
+ :density:
16
+ :default: 'p-3 text-sm font-normal'
17
+ :compact: 'p-1.5 text-xs font-normal'
18
+ :alignment:
19
+ :left: 'text-left'
20
+ :right: 'text-right'
21
+ :center: 'text-center'
22
+ :row:
23
+ :default: 'bg-white'
24
+ :striped: 'bg-gray-50'
@@ -0,0 +1,33 @@
1
+ <% if @records.present? %>
2
+ <table class="w-full">
3
+ <thead>
4
+ <tr class="<%= tr_classes(:header) %>">
5
+ <% columns.each do |column| %>
6
+ <th scope="col" class="<%= column.th_classes %>">
7
+ <%= column.title %>
8
+ </th>
9
+ <% end %>
10
+ </tr>
11
+ </thead>
12
+
13
+ <tbody>
14
+ <% @records.each do |record| %>
15
+ <tr
16
+ <% if record.respond_to?(:id) %>
17
+ id="<%= dom_id(record) %>"
18
+ <% end %>
19
+ class="<%= tr_classes %>"
20
+ >
21
+ <% columns.each do |column| %>
22
+ <td class="<%= column.td_classes %>">
23
+ <%= column.call(record) %>
24
+ </td>
25
+ <% end %>
26
+ </tr>
27
+ <% end %>
28
+ </tbody>
29
+ <tfoot><%= footer %></tfoot>
30
+ </table>
31
+ <% else %>
32
+ <%= empty_state %>
33
+ <% end %>
@@ -0,0 +1,38 @@
1
+ module Componeer
2
+ module Tables
3
+ class TableComponent < BaseComponent
4
+ register_as :table
5
+
6
+ renders_many :columns,
7
+ lambda { |title: '', **options, &block|
8
+ ColumnComponent.new(self, title, **options, &block)
9
+ }
10
+
11
+ renders_one :empty_state,
12
+ lambda { |resource_name: nil, icon: :exclamation|
13
+ EmptyStates::EmptyStateComponent.new(resource_name: resource_name ||
14
+ records_resource_name,
15
+ icon:)
16
+ }
17
+
18
+ renders_one :footer
19
+
20
+ attr_reader :records, :density, :striped, :options
21
+
22
+ def initialize(records: nil, **options)
23
+ @records = records
24
+ @striped = options.delete(:striped) || true
25
+ @density = options.delete(:density) || :default
26
+ @options = options
27
+ end
28
+
29
+ def tr_classes(level = :body)
30
+ if level == :body
31
+ styles.dig(level, :row, striped ? cycle(:striped, :default).to_sym : :default)
32
+ else
33
+ styles.dig(level, :row)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,16 @@
1
+ ---
2
+ :size:
3
+ :small: text-xs px-1 p-0.5
4
+ :default: text-sm px-2 py-1
5
+ :large: text-base px-3 py-1.5
6
+ :shape:
7
+ :rounded: rounded rounded-lg
8
+ :flat: rounded-none
9
+ :color:
10
+ :gray: bg-gray-100 text-gray-700
11
+ :brand: bg-brand-100 text-brand-700
12
+ :blue: bg-blue-100 text-blue-700
13
+ :green: bg-green-100 text-green-700
14
+ :red: bg-red-100 text-red-700
15
+ :yellow: bg-yellow-100 text-yellow-700
16
+ :purple: bg-purple-100 text-purple-700
@@ -0,0 +1,3 @@
1
+ <span class="<%= base_classes %>">
2
+ <%= content.presence || text %>
3
+ </span>
@@ -0,0 +1,24 @@
1
+ module Componeer
2
+ module Tags
3
+ class TagComponent < BaseComponent
4
+ register_as :tag
5
+
6
+ attr_reader :text, :type, :size, :color, :shape, :options
7
+
8
+ def initialize(text = nil, **options)
9
+ @text = text
10
+ @type = options.delete(:type) || :default
11
+ @size = options.delete(:size) || :default
12
+ @color = options.delete(:color) || :gray
13
+ @shape = options.delete(:shape) || :rounded
14
+ @options = options
15
+ end
16
+
17
+ def base_classes
18
+ to_classes_string([styles.dig(:size, size),
19
+ styles.dig(:color, color),
20
+ styles.dig(:shape, shape)])
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Componeer
2
- VERSION = '0.0.4a'.freeze
2
+ VERSION = '0.0.7a'.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.4a
4
+ version: 0.0.7a
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-05-27 00:00:00.000000000 Z
13
+ date: 2024-06-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: inline_svg
@@ -78,6 +78,13 @@ files:
78
78
  - app/components/componeer/buttons/styles.yml
79
79
  - app/components/componeer/empty_states/empty_state_component.html.erb
80
80
  - app/components/componeer/empty_states/empty_state_component.rb
81
+ - app/components/componeer/tables/column_component.rb
82
+ - app/components/componeer/tables/styles.yml
83
+ - app/components/componeer/tables/table_component.html.erb
84
+ - app/components/componeer/tables/table_component.rb
85
+ - app/components/componeer/tags/styles.yml
86
+ - app/components/componeer/tags/tag_component.html.erb
87
+ - app/components/componeer/tags/tag_component.rb
81
88
  - app/controllers/application_controller.rb
82
89
  - app/controllers/componeer/application_controller.rb
83
90
  - app/helpers/componeer/application_helper.rb
@@ -91,7 +98,6 @@ files:
91
98
  - lib/componeer/registry.rb
92
99
  - lib/componeer/version.rb
93
100
  - lib/install/componeer.rb
94
- - lib/tasks/componeer_tasks.rake
95
101
  - lib/tasks/install.rake
96
102
  homepage: https://docs.componeer.me
97
103
  licenses:
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :componeer do
3
- # # Task goes here
4
- # end