tramway 1.0.0.1 → 1.0.1

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: 4ae5cf80f64299d99f74c529026b79d86560dc9de06ef48b5e2034e0cf586781
4
- data.tar.gz: 8c7a9206caca2076a929c6f1d5f54680e7efb637f615a9513be2d2d720eaaf2a
3
+ metadata.gz: e80ee744d6bfbcc4a55b9cbccc19b9d2c755830c8641009198d86553961cc0ed
4
+ data.tar.gz: 58f0e9d547c6d209800c02e9ac6774b910366ead27c3f2306c5cc5bf379e7f38
5
5
  SHA512:
6
- metadata.gz: 8e74f1aa07fe82961906725383afbe2ca3b2ee307c0aecb04687f4e49db726aec9796a9bab6fd9dac9b61801a91ddf31f4d746591ac725cdf0e158beddc10c67
7
- data.tar.gz: 3b0fc24f6e0f5f24540b85ec151af179b4bedd292713e8035932c11346e12d2ba685382d12a86e5deb97a5dd3e85ef5a8ff2e7c5a3aba9b6f676897a1adfc2a2
6
+ metadata.gz: 37b4d134de11d33b1dbbf1dd08818934a02c1d4de126d07bd15ad9b763fb8ec7b355ec9f05913e72a2b2133e2ef0679651b620ea29bb658cb8859e999bd35f66
7
+ data.tar.gz: 4537dd751d10550a4cf9176b969195200caeabc2f74556a96dc72afd73e5c9d8b3238b71c48c59d751550d2ae9faddac98991a95222db19114d1f93b7d624ace
data/README.md CHANGED
@@ -248,6 +248,56 @@ class UserDecorator < Tramway::BaseDecorator
248
248
  end
249
249
  ```
250
250
 
251
+ #### Add header content to index pages
252
+
253
+ You can inject custom content above an entity's index table by defining an
254
+ `index_header_content` lambda on its decorator. The lambda receives the
255
+ collection of decorated records and can render any component you need.
256
+
257
+ *config/initializers/tramway.rb*
258
+ ```ruby
259
+ Tramway.configure do |config|
260
+ config.entities = [
261
+ {
262
+ name: :project,
263
+ pages: [
264
+ { action: :index }
265
+ ]
266
+ }
267
+ ]
268
+ end
269
+ ```
270
+
271
+ *app/decorators/project_decorator.rb*
272
+ ```ruby
273
+ class ProjectDecorator < Tramway::BaseDecorator
274
+ class << self
275
+ def index_header_content
276
+ lambda do |_collection|
277
+ component "projects/index_header"
278
+ end
279
+ end
280
+ end
281
+ end
282
+ ```
283
+
284
+ *app/components/projects/index_header_component.html.haml*
285
+ ```haml
286
+ .mb-2
287
+ = tramway_button path: Rails.application.routes.url_helpers.new_project_path,
288
+ text: 'Create',
289
+ type: :hope
290
+ ```
291
+
292
+ *app/components/projects/index_header_component.rb*
293
+ ```ruby
294
+ class Projects::IndexHeaderComponent < Tramway::BaseComponent
295
+ end
296
+ ```
297
+
298
+ With this configuration in place, the index page will render the `Create`
299
+ button component above the table of projects.
300
+
251
301
  #### Decorate a single object
252
302
 
253
303
  You can use the same method to decorate a single object either
@@ -770,7 +820,7 @@ Available form helpers:
770
820
 
771
821
  *app/views/devise/sessions/new.html.erb*
772
822
  ```erb
773
- <%= tramway_form_for(resource, as: resource_name, url: session_path(resource_name), class: 'bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4') do |f| %>
823
+ <%= tramway_form_for(resource, as: resource_name, url: session_path(resource_name), html: { class: 'bg-white shadow-md rounded px-8 pt-6 pb-8 mb-4') } do |f| %>
774
824
  <%= component 'forms/errors', record: resource %>
775
825
 
776
826
  <%= f.text_field :email, placeholder: 'Your email' %>
@@ -0,0 +1,2 @@
1
+ %span{ class: classes }
2
+ = text
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Tailwinds
4
+ # Default Tramway badge
5
+ #
6
+ class BadgeComponent < Tailwinds::BaseComponent
7
+ option :text
8
+ option :type, optional: true
9
+ option :color, optional: true
10
+
11
+ def classes
12
+ [
13
+ 'flex', 'px-3', 'py-1', 'text-sm', 'font-semibold', 'text-white', "bg-#{resolved_color}-500",
14
+ "dark:bg-#{resolved_color}-600", 'rounded-full', 'w-fit'
15
+ ]
16
+ end
17
+ end
18
+ end
@@ -3,5 +3,41 @@
3
3
  module Tailwinds
4
4
  # Shared base component for Tailwinds components
5
5
  class BaseComponent < Tramway::BaseComponent
6
+ TYPE_COLOR_MAP = {
7
+ default: :gray,
8
+ life: :gray,
9
+ primary: :blue,
10
+ hope: :blue,
11
+ secondary: :zinc,
12
+ success: :green,
13
+ will: :green,
14
+ warning: :orange,
15
+ greed: :orange,
16
+ danger: :red,
17
+ rage: :red,
18
+ love: :violet,
19
+ compassion: :indigo,
20
+ compassio: :indigo,
21
+ fear: :yellow,
22
+ submit: :green
23
+ }.freeze
24
+
25
+ def resolved_color
26
+ (color || type_color).to_s
27
+ end
28
+
29
+ def type_color
30
+ TYPE_COLOR_MAP.fetch(normalized_type, TYPE_COLOR_MAP[:default]).to_sym
31
+ end
32
+
33
+ def normalized_type
34
+ value = type
35
+ value = nil if value.respond_to?(:empty?) && value.empty?
36
+ value ||= :default
37
+ value = value.downcase if value.respond_to?(:downcase)
38
+ value = value.to_sym if value.respond_to?(:to_sym)
39
+
40
+ TYPE_COLOR_MAP.key?(value) ? value : :default
41
+ end
6
42
  end
7
43
  end
@@ -21,25 +21,6 @@ module Tailwinds
21
21
  }[size]
22
22
  end
23
23
 
24
- TYPE_COLOR_MAP = {
25
- default: :gray,
26
- life: :gray,
27
- primary: :blue,
28
- hope: :blue,
29
- secondary: :zinc,
30
- success: :green,
31
- will: :green,
32
- warning: :orange,
33
- greed: :orange,
34
- danger: :red,
35
- rage: :red,
36
- love: :violet,
37
- compassion: :indigo,
38
- compassio: :indigo,
39
- fear: :yellow,
40
- submit: :green
41
- }.freeze
42
-
43
24
  def classes
44
25
  (default_classes +
45
26
  light_mode_classes +
@@ -69,25 +50,5 @@ module Tailwinds
69
50
  'dark:text-gray-300'
70
51
  ]
71
52
  end
72
-
73
- private
74
-
75
- def resolved_color
76
- (color || type_color).to_s
77
- end
78
-
79
- def type_color
80
- TYPE_COLOR_MAP.fetch(normalized_type, TYPE_COLOR_MAP[:default]).to_sym
81
- end
82
-
83
- def normalized_type
84
- value = type
85
- value = nil if value.respond_to?(:empty?) && value.empty?
86
- value ||= :default
87
- value = value.downcase if value.respond_to?(:downcase)
88
- value = value.to_sym if value.respond_to?(:to_sym)
89
-
90
- TYPE_COLOR_MAP.key?(value) ? value : :default
91
- end
92
53
  end
93
54
  end
@@ -2,7 +2,7 @@
2
2
  - if @label
3
3
  = component('tailwinds/form/label', for: @for) do
4
4
  = @label
5
- - base_classes = 'bg-white border border-gray-300 text-gray-700 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 '
5
+ - base_classes = 'w-full bg-white border border-gray-300 text-gray-700 rounded focus:outline-none focus:ring-2 focus:ring-blue-500 '
6
6
  - base_classes += 'focus:border-transparent disabled:bg-gray-100 disabled:text-gray-400 disabled:cursor-not-allowed '
7
7
  - base_classes += 'dark:bg-gray-800 dark:border-gray-600 dark:text-gray-100 dark:focus:ring-red-400 dark:disabled:bg-gray-800 dark:disabled:text-gray-500'
8
8
  - classes = "#{size_class(:select_input)} #{base_classes}"
@@ -59,6 +59,13 @@ module Tramway
59
59
  component 'tailwinds/containers/narrow', &
60
60
  end
61
61
  end
62
+
63
+ def tramway_badge(text:, type: nil, color: nil)
64
+ component 'tailwinds/badge',
65
+ text:,
66
+ type:,
67
+ color:
68
+ end
62
69
  end
63
70
  end
64
71
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tramway
4
- VERSION = '1.0.0.1'
4
+ VERSION = '1.0.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tramway
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.1
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - kalashnikovisme
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2025-11-01 00:00:00.000000000 Z
12
+ date: 2025-11-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: anyway_config
@@ -145,6 +145,8 @@ files:
145
145
  - app/components/tailwind_component.rb
146
146
  - app/components/tailwinds/back_button_component.html.haml
147
147
  - app/components/tailwinds/back_button_component.rb
148
+ - app/components/tailwinds/badge_component.html.haml
149
+ - app/components/tailwinds/badge_component.rb
148
150
  - app/components/tailwinds/base_component.rb
149
151
  - app/components/tailwinds/button_component.html.haml
150
152
  - app/components/tailwinds/button_component.rb