okonomi_ui_kit 0.1.14 → 0.1.16

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: 02d1d3c2bfdf7b4540cb56dba40945e55d15ce78987cd5864ccf1941fbd699b5
4
- data.tar.gz: f7783a14bb40bf95957936061ba560dbb3a64959f5a4084f58927a5edb8359b1
3
+ metadata.gz: 976e4c152c3bcf2e838bcaf51bb68ebc11a3cfd869d0a7fddba785a30f85e7dc
4
+ data.tar.gz: 441f2097aa56fce9a7d481dd75beed270458186fb6707c4fb8dff6d45af95050
5
5
  SHA512:
6
- metadata.gz: 88de14abb1c4ab75fa7a16cab52c5239a62409738e0ae227a13ea552d710fe242418604dd8494ae514fdb01073c80679c8c3b32a3857f3c137f875f26290d63d
7
- data.tar.gz: 1b1c03afe50de99720cb1af0f2238adeeb5d9cc0aaf3da9f7a31eaf2538e1e735b49f751ecf122b6e2fe484260d9fa729e95e55fed2afb15608e874ce1fd6167
6
+ metadata.gz: 4ce34d6df944d6959473f34889240532d3b5e555f261146635620a1e4351f08b1c1384b90f34d1648bdc05856fb6ef8447dee42625db64f34e01b5fa73adae93
7
+ data.tar.gz: d24c7b70a8998ce74385642d6ddf5ac1ae320f55ffb97089d56f3a6d04342cd49460de620e567663fdc5222c476a9180cf76cb2a01d5e79e53edb90e12949c71
@@ -1501,6 +1501,9 @@
1501
1501
  .py-4 {
1502
1502
  padding-block: calc(var(--spacing) * 4);
1503
1503
  }
1504
+ .py-5 {
1505
+ padding-block: calc(var(--spacing) * 5);
1506
+ }
1504
1507
  .py-6 {
1505
1508
  padding-block: calc(var(--spacing) * 6);
1506
1509
  }
@@ -14,6 +14,13 @@ module OkonomiUiKit
14
14
  self.class.name.demodulize.underscore
15
15
  end
16
16
 
17
+ def variant_style(*args)
18
+ tw_merge(
19
+ styles.dig(*([:variants] + [args[1..-1]].flatten)),
20
+ styles.dig(*args)
21
+ )
22
+ end
23
+
17
24
  def style(*args)
18
25
  styles.dig(*args)
19
26
  end
@@ -4,16 +4,12 @@ module OkonomiUiKit
4
4
  def render(options = {}, &block)
5
5
  options = options.with_indifferent_access
6
6
  title = options.delete(:title)
7
+ variant = options.delete(:variant) || :default
7
8
 
8
- classes = tw_merge(
9
- style(:root),
10
- options.delete(:class)
11
- )
12
-
13
- builder = SectionBuilder.new(view, self)
9
+ builder = SectionBuilder.new(view, self, variant)
14
10
  builder.title(title) if title
15
11
 
16
- view.render(template_path, builder: builder, options: options.merge(class: classes), &block)
12
+ view.render(template_path, builder: builder, component: self, variant: variant, &block)
17
13
  end
18
14
 
19
15
  register_styles :default do
@@ -24,10 +20,11 @@ module OkonomiUiKit
24
20
  title: "text-base/7 font-semibold text-gray-900",
25
21
  subtitle: "mt-1 max-w-2xl text-sm/6 text-gray-500",
26
22
  actions: "mt-4 flex md:ml-4 md:mt-0",
27
- attribute_list: "divide-y divide-gray-100",
28
- attribute_row: "py-6 sm:grid sm:grid-cols-3 sm:gap-4",
29
- attribute_label: "text-sm font-medium text-gray-900",
30
- attribute_value: "mt-1 text-sm/6 text-gray-700 sm:col-span-2 sm:mt-0"
23
+ variants: {
24
+ default: {
25
+ body: "px-4 py-5 sm:px-6"
26
+ }
27
+ }
31
28
  }
32
29
  end
33
30
  end
@@ -36,7 +33,9 @@ module OkonomiUiKit
36
33
  include ActionView::Helpers::TagHelper
37
34
  include ActionView::Helpers::CaptureHelper
38
35
 
39
- def initialize(template, component)
36
+ attr_reader :view, :component, :variant
37
+
38
+ def initialize(template, component, variant = :default)
40
39
  @template = template
41
40
  @component = component
42
41
  @title_content = nil
@@ -44,18 +43,19 @@ module OkonomiUiKit
44
43
  @actions_content = nil
45
44
  @body_content = nil
46
45
  @attributes = []
46
+ @variant = variant
47
47
  end
48
48
 
49
49
  def title(text, **options)
50
- @title_content = tag.h3(text, class: @component.style(:title))
50
+ @title_content = tag.h3(text, class: @component.variant_style(variant, :title))
51
51
  end
52
52
 
53
53
  def subtitle(text, **options)
54
- @subtitle_content = tag.p(text, class: @component.style(:subtitle))
54
+ @subtitle_content = tag.p(text, class: @component.variant_style(variant, :subtitle))
55
55
  end
56
56
 
57
57
  def actions(&block)
58
- @actions_content = tag.div(class: @component.style(:actions)) do
58
+ @actions_content = tag.div(class: @component.variant_style(variant, :actions)) do
59
59
  capture(&block) if block_given?
60
60
  end
61
61
  end
@@ -65,47 +65,18 @@ module OkonomiUiKit
65
65
  # Capture the content first to see if attributes were used
66
66
  content = capture { yield(self) }
67
67
 
68
- @body_content = if @attributes.any?
69
- # If attributes were added, wrap them in dl
70
- tag.div do
71
- tag.dl(class: @component.style(:attribute_list)) do
72
- @template.safe_join(@attributes)
73
- end
74
- end
75
- else
76
- # Otherwise, just return the captured content
77
- tag.div do
78
- content
79
- end
68
+ @body_content = tag.div class: @component.variant_style(variant, :body) do
69
+ content
80
70
  end
81
71
  end
82
72
  end
83
73
 
84
- def attribute(label, value = nil, **options, &block)
85
- content = if block_given?
86
- capture(&block)
87
- elsif value.respond_to?(:call)
88
- value.call
89
- else
90
- value
91
- end
92
-
93
- attribute_html = tag.div(class: @component.style(:attribute_row)) do
94
- dt_content = tag.dt(label, class: @component.style(:attribute_label))
95
- dd_content = tag.dd(content, class: @component.style(:attribute_value))
96
-
97
- dt_content + dd_content
98
- end
99
-
100
- @attributes << attribute_html
101
- end
102
-
103
74
  def render_header
104
75
  return nil unless @title_content || @subtitle_content || @actions_content
105
76
 
106
- tag.div(class: @component.style(:header)) do
77
+ tag.div(class: @component.variant_style(variant, :header)) do
107
78
  if @actions_content
108
- tag.div(class: @component.style(:header_with_actions)) do
79
+ tag.div(class: @component.variant_style(variant, :header_with_actions)) do
109
80
  title_section = tag.div do
110
81
  content_parts = []
111
82
  content_parts << @title_content if @title_content
@@ -1,4 +1,4 @@
1
- <div class="<%= options[:class] %>">
1
+ <%= content_tag :div, class: component.variant_style(variant, :root) do %>
2
2
  <% yield(builder) if block_given? %>
3
3
  <%= builder.render_content %>
4
- </div>
4
+ <% end %>
@@ -1,3 +1,3 @@
1
1
  module OkonomiUiKit
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.16"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: okonomi_ui_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Okonomi GmbH