tramway 0.6.0.3 → 0.6.1.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: bf2ab80ae30a9e91fbae5ec778765d2b188111dcc73b7345ca1e4fd2191a68ac
4
- data.tar.gz: 8913fd30d94589d60498e68edc4b24c7f130f2463c5a874cab87c8cc2eb645d2
3
+ metadata.gz: 7fffab981c47137351c1b55fb952713cf8ee9f1b4ba963ca60e2349d8e836d2e
4
+ data.tar.gz: e858d3b6377eb934c5ae15bccee505a65f1a4abdb4d7088340f7271ba923c8f8
5
5
  SHA512:
6
- metadata.gz: ce7b37bd2c408441f4409a20d96883604fea9077e5d884f820ad6ebf218f5d6a6680195ed21d0f305d19b3ace0b01ebcd6f1439c8efa3b87dd0bbba49d1d7652
7
- data.tar.gz: 9e28805788ce2ce3b7e82ed9ef09f463942e5ac0fe43617783235c48fcc4809b5fd7ed47d56c8238842ebb268ea805e543c150b5129fa6ba87bcf2f73c3ed0a9
6
+ metadata.gz: 82dede0fafef9b81bf1e2bf12da749d14a7bf508d7855d57497ccecefb5f2bcb779c89460fdda9f4bdb71bdd6af6df224cb7c0036b457dba0f6d44e703f61cd5
7
+ data.tar.gz: 37b31c109c429c1d5979a8bbbff3c5ef171653b2abbadc8b2a41c979096af9cf22b0302ede6496539fb8755c4fb83766f01cfe1f98d3e4761a27bb1b89b6903b
data/README.md CHANGED
@@ -642,8 +642,43 @@ component applies.
642
642
 
643
643
  Tramway ships with helpers for common UI patterns built on top of Tailwind components.
644
644
 
645
- * `tramway_button` renders a button-styled link and accepts `path`, optional `text`, HTTP `method`, and styling options such as
646
- `color`, `type`, and `size`. All additional keyword arguments are forwarded to the underlying component as HTML attributes.
645
+ * `tramway_button` renders a button-styled form submit by default and accepts `path`, optional `text`, HTTP `method`, and styling
646
+ options such as `color`, `type`, and `size`. Pass `link: true` to render a button-styled link instead. All additional keyword
647
+ arguments are forwarded to the underlying component as HTML attributes.
648
+
649
+ The `type` option maps semantic intent to Tailwind color families. The full set of supported values is:
650
+
651
+ | Type | Color |
652
+ | ---- | ----- |
653
+ | `default`, `life` | Gray |
654
+ | `primary`, `hope` | Blue |
655
+ | `secondary` | Zinc |
656
+ | `success`, `will` | Green |
657
+ | `warning`, `greed` | Orange |
658
+ | `danger`, `rage` | Red |
659
+ | `love` | Violet |
660
+ | `compassion` | Indigo |
661
+ | `fear` | Yellow |
662
+
663
+ If none of the predefined semantic types fit your needs, you can supply a Tailwind color family directly using the `color`
664
+ option—for example: `color: :gray`. When you pass a custom color ensure the corresponding utility classes exist in your
665
+ Tailwind configuration. Add the following safelist entries (adjusting the color name as needed) to `config/tailwind.config.js`:
666
+
667
+ ```js
668
+ // config/tailwind.config.js
669
+ module.exports = {
670
+ // ...
671
+ safelist: [
672
+ // existing entries …
673
+ {
674
+ pattern: /(bg|hover:bg|dark:bg|dark:hover:bg)-gray-(500|600|700|800)/,
675
+ },
676
+ ],
677
+ }
678
+ ```
679
+
680
+ Tailwind will then emit the `bg-gray-500`, `hover:bg-gray-700`, `dark:bg-gray-600`, and `dark:hover:bg-gray-800` classes that
681
+ Tramway buttons expect when you opt into a custom color.
647
682
 
648
683
  ```erb
649
684
  <%= tramway_button path: user_path(user), text: 'View profile', color: :emerald, data: { turbo: false } %>
@@ -1,10 +1,10 @@
1
1
  - if text.present?
2
- - if method == :get
2
+ - if link
3
3
  = link_to text, path, class: classes, **options.except(:class)
4
4
  - else
5
5
  = button_to text, path, method:, class: classes, **options.except(:class)
6
6
  - else
7
- - if method == :get
7
+ - if link
8
8
  = link_to path, class: classes, **options.except(:class) do
9
9
  = content
10
10
  - else
@@ -6,26 +6,45 @@ module Tailwinds
6
6
  class ButtonComponent < BaseComponent
7
7
  option :text, optional: true, default: -> {}
8
8
  option :path
9
- option :color, default: -> { :blue }
10
- option :type, default: -> { :default }
9
+ option :color, optional: true
10
+ option :type, optional: true
11
11
  option :size, default: -> { :middle }
12
12
  option :method, optional: true, default: -> { :get }
13
+ option :link, optional: true, default: -> { false }
13
14
  option :options, optional: true, default: -> { {} }
14
15
 
15
16
  def size_classes
16
17
  case size
17
18
  when :small
18
- 'text-sm py-1 px-1'
19
+ 'text-sm py-1 px-2 rounded' # small button
19
20
  when :middle
20
- 'py-2 px-4'
21
+ 'py-2 px-4' # middle button
21
22
  end
22
23
  end
23
24
 
25
+ TYPE_COLOR_MAP = {
26
+ default: :gray,
27
+ life: :gray,
28
+ primary: :blue,
29
+ hope: :blue,
30
+ secondary: :zinc,
31
+ success: :green,
32
+ will: :green,
33
+ warning: :orange,
34
+ greed: :orange,
35
+ danger: :red,
36
+ rage: :red,
37
+ love: :violet,
38
+ compassion: :indigo,
39
+ compassio: :indigo,
40
+ fear: :yellow
41
+ }.freeze
42
+
24
43
  def classes
25
44
  (default_classes +
26
45
  light_mode_classes +
27
46
  dark_mode_classes +
28
- (method == :get ? %w[px-1 h-fit] : ['cursor-pointer'])).compact.join(' ')
47
+ (link ? %w[px-1 h-fit] : ['cursor-pointer'])).compact.join(' ')
29
48
  end
30
49
 
31
50
  def default_classes
@@ -43,18 +62,38 @@ module Tailwinds
43
62
 
44
63
  def light_mode_classes
45
64
  [
46
- "bg-#{color}-500",
47
- "hover:bg-#{color}-700",
65
+ "bg-#{resolved_color}-500",
66
+ "hover:bg-#{resolved_color}-700",
48
67
  'text-white'
49
68
  ]
50
69
  end
51
70
 
52
71
  def dark_mode_classes
53
72
  [
54
- "dark:bg-#{color}-600",
55
- "dark:hover:bg-#{color}-800",
73
+ "dark:bg-#{resolved_color}-600",
74
+ "dark:hover:bg-#{resolved_color}-800",
56
75
  'dark:text-gray-300'
57
76
  ]
58
77
  end
78
+
79
+ private
80
+
81
+ def resolved_color
82
+ (color || type_color).to_s
83
+ end
84
+
85
+ def type_color
86
+ TYPE_COLOR_MAP.fetch(normalized_type, TYPE_COLOR_MAP[:default]).to_sym
87
+ end
88
+
89
+ def normalized_type
90
+ value = type
91
+ value = nil if value.respond_to?(:empty?) && value.empty?
92
+ value ||= :default
93
+ value = value.downcase if value.respond_to?(:downcase)
94
+ value = value.to_sym if value.respond_to?(:to_sym)
95
+
96
+ TYPE_COLOR_MAP.key?(value) ? value : :default
97
+ end
59
98
  end
60
99
  end
@@ -1,3 +1,3 @@
1
1
  .container.p-4.flex.align-center.justify-center.w-full.mx-auto.bg-gray-100.dark:bg-gray-900.text-gray-900.dark:text-white{ id: }
2
- .flex.flex-col.justify-center.w-full.py-8.dark:text-white
2
+ .flex.flex-col.justify-center.w-full.dark:text-white
3
3
  = content
@@ -66,9 +66,11 @@ module.exports = {
66
66
  'px-6',
67
67
  'px-4',
68
68
  'px-3',
69
+ 'px-2',
69
70
  'py-8',
70
71
  'py-4',
71
72
  'py-2',
73
+ 'py-1',
72
74
  'mb-2',
73
75
  'mt-8',
74
76
  'mt-2',
@@ -100,6 +102,44 @@ module.exports = {
100
102
  'font-normal',
101
103
  'text-xs',
102
104
 
105
+ // === Button color presets ===
106
+ 'bg-gray-500',
107
+ 'hover:bg-gray-700',
108
+ 'dark:bg-gray-600',
109
+ 'dark:hover:bg-gray-800',
110
+ 'bg-blue-500',
111
+ 'hover:bg-blue-700',
112
+ 'dark:bg-blue-600',
113
+ 'dark:hover:bg-blue-800',
114
+ 'bg-zinc-500',
115
+ 'hover:bg-zinc-700',
116
+ 'dark:bg-zinc-600',
117
+ 'dark:hover:bg-zinc-800',
118
+ 'bg-green-500',
119
+ 'hover:bg-green-700',
120
+ 'dark:bg-green-600',
121
+ 'dark:hover:bg-green-800',
122
+ 'bg-orange-500',
123
+ 'hover:bg-orange-700',
124
+ 'dark:bg-orange-600',
125
+ 'dark:hover:bg-orange-800',
126
+ 'bg-red-500',
127
+ 'hover:bg-red-700',
128
+ 'dark:bg-red-600',
129
+ 'dark:hover:bg-red-800',
130
+ 'bg-violet-500',
131
+ 'hover:bg-violet-700',
132
+ 'dark:bg-violet-600',
133
+ 'dark:hover:bg-violet-800',
134
+ 'bg-indigo-500',
135
+ 'hover:bg-indigo-700',
136
+ 'dark:bg-indigo-600',
137
+ 'dark:hover:bg-indigo-800',
138
+ 'bg-yellow-500',
139
+ 'hover:bg-yellow-700',
140
+ 'dark:bg-yellow-600',
141
+ 'dark:hover:bg-yellow-800',
142
+
103
143
  // === Form state helpers ===
104
144
  'disabled:bg-gray-100',
105
145
  'disabled:text-gray-400',
@@ -36,11 +36,12 @@ module Tramway
36
36
  component 'tailwinds/table/cell', &
37
37
  end
38
38
 
39
- def tramway_button(path:, text: nil, method: :get, **options)
39
+ def tramway_button(path:, text: nil, method: :get, link: false, **options)
40
40
  component 'tailwinds/button',
41
41
  text:,
42
42
  path:,
43
43
  method:,
44
+ link:,
44
45
  color: options.delete(:color),
45
46
  type: options.delete(:type),
46
47
  size: options.delete(:size),
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tramway
4
- VERSION = '0.6.0.3'
4
+ VERSION = '0.6.1.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: 0.6.0.3
4
+ version: 0.6.1.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-10-27 00:00:00.000000000 Z
12
+ date: 2025-10-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: anyway_config