protos 0.2.3 → 0.4.0

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.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -5
  3. data/CHANGELOG.md +11 -0
  4. data/README.md +82 -67
  5. data/benchmarks/.keep +0 -0
  6. data/benchmarks/table.txt +12 -0
  7. data/examples/list.rb +3 -1
  8. data/examples/navbar.rb +1 -1
  9. data/lib/protos/accordion/item.rb +7 -8
  10. data/lib/protos/accordion.rb +6 -10
  11. data/lib/protos/alert/actions.rb +2 -2
  12. data/lib/protos/alert/icon.rb +2 -2
  13. data/lib/protos/alert.rb +4 -8
  14. data/lib/protos/attributes.rb +7 -8
  15. data/lib/protos/avatar.rb +1 -1
  16. data/lib/protos/breadcrumbs/crumb.rb +2 -2
  17. data/lib/protos/breadcrumbs.rb +2 -4
  18. data/lib/protos/card/actions.rb +2 -2
  19. data/lib/protos/card/body.rb +2 -2
  20. data/lib/protos/card/image.rb +2 -2
  21. data/lib/protos/card/title.rb +2 -2
  22. data/lib/protos/card.rb +6 -14
  23. data/lib/protos/carousel/actions.rb +2 -2
  24. data/lib/protos/carousel/item.rb +2 -2
  25. data/lib/protos/carousel.rb +4 -8
  26. data/lib/protos/chat_bubble/content.rb +2 -2
  27. data/lib/protos/chat_bubble/footer.rb +2 -2
  28. data/lib/protos/chat_bubble/header.rb +2 -2
  29. data/lib/protos/chat_bubble/image.rb +2 -2
  30. data/lib/protos/chat_bubble.rb +6 -14
  31. data/lib/protos/collapse/content.rb +2 -2
  32. data/lib/protos/collapse/title.rb +3 -3
  33. data/lib/protos/collapse.rb +4 -8
  34. data/lib/protos/combobox.rb +8 -24
  35. data/lib/protos/command/dialog.rb +1 -1
  36. data/lib/protos/command/empty.rb +2 -2
  37. data/lib/protos/command/group.rb +1 -1
  38. data/lib/protos/command/input.rb +3 -2
  39. data/lib/protos/command/item.rb +2 -2
  40. data/lib/protos/command/list.rb +2 -2
  41. data/lib/protos/command/title.rb +2 -2
  42. data/lib/protos/command/trigger.rb +2 -2
  43. data/lib/protos/command.rb +10 -26
  44. data/lib/protos/component.rb +21 -30
  45. data/lib/protos/drawer/content.rb +2 -2
  46. data/lib/protos/drawer/side.rb +1 -1
  47. data/lib/protos/drawer/trigger.rb +2 -2
  48. data/lib/protos/drawer.rb +5 -11
  49. data/lib/protos/dropdown/item.rb +2 -2
  50. data/lib/protos/dropdown/menu.rb +1 -1
  51. data/lib/protos/dropdown.rb +3 -9
  52. data/lib/protos/hero/content.rb +2 -2
  53. data/lib/protos/hero/overlay.rb +2 -2
  54. data/lib/protos/hero.rb +4 -8
  55. data/lib/protos/list/item.rb +2 -2
  56. data/lib/protos/list.rb +3 -5
  57. data/lib/protos/modal/close_button.rb +1 -1
  58. data/lib/protos/modal/dialog.rb +1 -1
  59. data/lib/protos/modal/trigger.rb +2 -2
  60. data/lib/protos/modal.rb +5 -11
  61. data/lib/protos/popover/content.rb +3 -1
  62. data/lib/protos/popover/trigger.rb +2 -2
  63. data/lib/protos/popover.rb +4 -8
  64. data/lib/protos/stats/actions.rb +2 -2
  65. data/lib/protos/stats/description.rb +2 -2
  66. data/lib/protos/stats/figure.rb +2 -2
  67. data/lib/protos/stats/stat.rb +2 -2
  68. data/lib/protos/stats/title.rb +2 -2
  69. data/lib/protos/stats/value.rb +2 -2
  70. data/lib/protos/stats.rb +8 -20
  71. data/lib/protos/swap/off.rb +2 -2
  72. data/lib/protos/swap/on.rb +2 -2
  73. data/lib/protos/swap.rb +5 -10
  74. data/lib/protos/table/body.rb +2 -2
  75. data/lib/protos/table/caption.rb +3 -3
  76. data/lib/protos/table/cell.rb +2 -2
  77. data/lib/protos/table/footer.rb +2 -2
  78. data/lib/protos/table/head.rb +2 -2
  79. data/lib/protos/table/header.rb +2 -2
  80. data/lib/protos/table/row.rb +2 -2
  81. data/lib/protos/table.rb +8 -22
  82. data/lib/protos/tabs/tab.rb +5 -4
  83. data/lib/protos/tabs.rb +3 -5
  84. data/lib/protos/theme.rb +34 -45
  85. data/lib/protos/timeline/center.rb +2 -2
  86. data/lib/protos/timeline/item.rb +2 -2
  87. data/lib/protos/timeline/left.rb +2 -2
  88. data/lib/protos/timeline/right.rb +2 -2
  89. data/lib/protos/timeline.rb +6 -14
  90. data/lib/protos/toast/close_button.rb +2 -1
  91. data/lib/protos/toast.rb +3 -5
  92. data/lib/protos/token_list.rb +18 -31
  93. data/lib/protos/typography/heading.rb +2 -2
  94. data/lib/protos/typography/inline_link.rb +3 -3
  95. data/lib/protos/typography/paragraph.rb +2 -2
  96. data/lib/protos/typography.rb +12 -12
  97. data/lib/protos/version.rb +1 -1
  98. data/protos.gemspec +15 -3
  99. metadata +8 -6
@@ -80,17 +80,13 @@ module Protos
80
80
  reader: false,
81
81
  type: TriggerTypes | Types::Array.of(TriggerTypes)
82
82
 
83
- def template(&block)
84
- div(**attrs, &block)
83
+ def view_template(&)
84
+ div(**attrs, &)
85
85
  end
86
86
 
87
- def content(...)
88
- Content.new(...)
89
- end
87
+ def content(...) = render Content.new(...)
90
88
 
91
- def trigger(...)
92
- Trigger.new(...)
93
- end
89
+ def trigger(...) = render Trigger.new(...)
94
90
 
95
91
  private
96
92
 
@@ -5,8 +5,8 @@ module Protos
5
5
  class Actions < Component
6
6
  # DOCS: A container for the actions (e.g. buttons) for a group of stats
7
7
 
8
- def template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
12
  private
@@ -5,8 +5,8 @@ module Protos
5
5
  class Description < Component
6
6
  # DOCS: A description for a group of stats
7
7
 
8
- def template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
12
  private
@@ -5,8 +5,8 @@ module Protos
5
5
  class Figure < Component
6
6
  # DOCS: A figure for a single stat
7
7
 
8
- def template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
12
  private
@@ -5,8 +5,8 @@ module Protos
5
5
  class Stat < Component
6
6
  # DOCS: A single stat container
7
7
 
8
- def template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
12
  private
@@ -5,8 +5,8 @@ module Protos
5
5
  class Title < Component
6
6
  # DOCS: A title for a group of stats
7
7
 
8
- def template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
12
  private
@@ -5,8 +5,8 @@ module Protos
5
5
  class Value < Component
6
6
  # DOCS: A value for a single stat
7
7
 
8
- def template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
12
  private
data/lib/protos/stats.rb CHANGED
@@ -5,33 +5,21 @@ module Protos
5
5
  # DOCS: Stats component that contains a collection of stats
6
6
  # https://daisyui.com/components/stat/
7
7
 
8
- def template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
- def actions(...)
13
- Actions.new(...)
14
- end
12
+ def actions(...) = render Actions.new(...)
15
13
 
16
- def description(...)
17
- Description.new(...)
18
- end
14
+ def description(...) = render Description.new(...)
19
15
 
20
- def figure(...)
21
- Figure.new(...)
22
- end
16
+ def figure(...) = render Figure.new(...)
23
17
 
24
- def stat(...)
25
- Stat.new(...)
26
- end
18
+ def stat(...) = render Stat.new(...)
27
19
 
28
- def title(...)
29
- Title.new(...)
30
- end
20
+ def title(...) = render Title.new(...)
31
21
 
32
- def value(...)
33
- Value.new(...)
34
- end
22
+ def value(...) = render Value.new(...)
35
23
 
36
24
  private
37
25
 
@@ -5,8 +5,8 @@ module Protos
5
5
  class Off < Component
6
6
  # DOCS: The off state for a swap component. This is the default state.
7
7
 
8
- def template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
12
  private
@@ -5,8 +5,8 @@ module Protos
5
5
  class On < Component
6
6
  # DOCS: The on state for a swap component. This is the active state.
7
7
 
8
- def template(&block)
9
- div(**attrs, &block)
8
+ def view_template(&)
9
+ div(**attrs, &)
10
10
  end
11
11
 
12
12
  private
data/lib/protos/swap.rb CHANGED
@@ -6,27 +6,22 @@ module Protos
6
6
  # display different content.
7
7
  # https://daisyui.com/components/swap/
8
8
 
9
- def template
9
+ def view_template
10
10
  label(**attrs) do
11
- input(type: :checkbox, class: css[:input])
11
+ input(type: :checkbox, class: css[:input], autocomplete: :off)
12
12
  yield if block_given?
13
13
  end
14
14
  end
15
15
 
16
- def on(...)
17
- On.new(...)
18
- end
16
+ def on(...) = render On.new(...)
19
17
 
20
- def off(...)
21
- Off.new(...)
22
- end
18
+ def off(...) = render Off.new(...)
23
19
 
24
20
  private
25
21
 
26
22
  def theme
27
23
  {
28
- container: tokens("swap"),
29
- input: tokens("hidden")
24
+ container: tokens("swap")
30
25
  }
31
26
  end
32
27
  end
@@ -5,8 +5,8 @@ module Protos
5
5
  class Body < Component
6
6
  # DOCS: The body of a table
7
7
 
8
- def template(&block)
9
- tbody(**attrs, &block)
8
+ def view_template(&)
9
+ tbody(**attrs, &)
10
10
  end
11
11
  end
12
12
  end
@@ -5,15 +5,15 @@ module Protos
5
5
  class Caption < Component
6
6
  # DOCS: The caption of a table
7
7
 
8
- def template(&block)
9
- caption(**attrs, &block)
8
+ def view_template(&)
9
+ caption(**attrs, &)
10
10
  end
11
11
 
12
12
  private
13
13
 
14
14
  def theme
15
15
  {
16
- container: tokens("caption-bottom", "p-sm")
16
+ container: tokens("caption-bottom")
17
17
  }
18
18
  end
19
19
  end
@@ -11,8 +11,8 @@ module Protos
11
11
  :left
12
12
  }
13
13
 
14
- def template(&block)
15
- td(**attrs, &block)
14
+ def view_template(&)
15
+ td(**attrs, &)
16
16
  end
17
17
 
18
18
  private
@@ -5,8 +5,8 @@ module Protos
5
5
  class Footer < Component
6
6
  # DOCS: The footer of a table
7
7
 
8
- def template(&block)
9
- tfoot(**attrs, &block)
8
+ def view_template(&)
9
+ tfoot(**attrs, &)
10
10
  end
11
11
  end
12
12
  end
@@ -11,8 +11,8 @@ module Protos
11
11
  :left
12
12
  }
13
13
 
14
- def template(&block)
15
- th(**attrs, &block)
14
+ def view_template(&)
15
+ th(**attrs, &)
16
16
  end
17
17
 
18
18
  private
@@ -6,8 +6,8 @@ module Protos
6
6
  # DOCS: The header of a table that contains many Protos::Table::Head
7
7
  # components
8
8
 
9
- def template(&block)
10
- thead(**attrs, &block)
9
+ def view_template(&)
10
+ thead(**attrs, &)
11
11
  end
12
12
  end
13
13
  end
@@ -5,8 +5,8 @@ module Protos
5
5
  class Row < Component
6
6
  # DOCS: The row of a table
7
7
 
8
- def template(&block)
9
- tr(**attrs, &block)
8
+ def view_template(&)
9
+ tr(**attrs, &)
10
10
  end
11
11
  end
12
12
  end
data/lib/protos/table.rb CHANGED
@@ -18,39 +18,25 @@ module Protos
18
18
  :lg
19
19
  )
20
20
 
21
- def template(&block)
21
+ def view_template(&block)
22
22
  div(**attrs) do
23
23
  table(class: css[:table], &block)
24
24
  end
25
25
  end
26
26
 
27
- def body(...)
28
- Body.new(...)
29
- end
27
+ def body(...) = render Body.new(...)
30
28
 
31
- def caption(...)
32
- Caption.new(...)
33
- end
29
+ def caption(...) = render Caption.new(...)
34
30
 
35
- def cell(...)
36
- Cell.new(...)
37
- end
31
+ def cell(...) = render Cell.new(...)
38
32
 
39
- def footer(...)
40
- Footer.new(...)
41
- end
33
+ def footer(...) = render Footer.new(...)
42
34
 
43
- def head(...)
44
- Head.new(...)
45
- end
35
+ def head(...) = render Head.new(...)
46
36
 
47
- def header(...)
48
- Header.new(...)
49
- end
37
+ def header(...) = render Header.new(...)
50
38
 
51
- def row(...)
52
- Row.new(...)
53
- end
39
+ def row(...) = render Row.new(...)
54
40
 
55
41
  private
56
42
 
@@ -5,20 +5,21 @@ module Protos
5
5
  class Tab < Component
6
6
  # DOCS: A single tab in a tabs component
7
7
 
8
- param :id
8
+ option :id
9
9
  option :label
10
10
  option :active, default: -> { false }
11
11
  option :disabled, default: -> { false }
12
12
 
13
- def template(&block)
13
+ def view_template(&)
14
14
  input(
15
15
  type: :radio,
16
16
  class: css[:input],
17
17
  name: id,
18
18
  role: :tab,
19
- aria_label: label
19
+ aria_label: label,
20
+ autocomplete: :off
20
21
  )
21
- div(**attrs, &block)
22
+ div(**attrs, &)
22
23
  end
23
24
 
24
25
  private
data/lib/protos/tabs.rb CHANGED
@@ -24,13 +24,11 @@ module Protos
24
24
  :lg
25
25
  )
26
26
 
27
- def template(&block)
28
- div(**attrs, &block)
27
+ def view_template(&)
28
+ div(**attrs, &)
29
29
  end
30
30
 
31
- def tab(...)
32
- Tab.new(...)
33
- end
31
+ def tab(...) = render Tab.new(...)
34
32
 
35
33
  private
36
34
 
data/lib/protos/theme.rb CHANGED
@@ -13,13 +13,24 @@ module Protos
13
13
  end
14
14
  end
15
15
 
16
- def initialize(theme = {}, **kwargs)
17
- @theme = theme.merge(kwargs)
16
+ def initialize(theme = {}, tailwind_merge: true, **kwargs)
17
+ @tailwind_merge = tailwind_merge
18
+
19
+ @theme = Hash.new do |hash, key|
20
+ hash[key] = TokenList.new
21
+ end
22
+
23
+ theme.merge!(kwargs).each do |key, value|
24
+ @theme[key].add(value)
25
+ end
18
26
  end
19
27
 
20
28
  def [](key)
21
- value = @theme[key]
22
- return value unless value.is_a?(String)
29
+ return nil unless key?(key)
30
+
31
+ value = @theme[key].to_s
32
+ return nil if value.empty?
33
+ return value unless @tailwind_merge
23
34
 
24
35
  self.class.merger.merge(value)
25
36
  end
@@ -29,66 +40,44 @@ module Protos
29
40
  end
30
41
 
31
42
  def add(key, value)
32
- TokenList.new
33
- .add(@theme.fetch(key, ""))
34
- .add(value)
35
- .to_s
36
- .tap do |tokens|
37
- @theme[key] = tokens
38
- end
43
+ @theme[key].add(value)
39
44
  end
40
45
 
41
46
  def remove(key, value)
42
- TokenList.new
43
- .add(@theme.fetch(key, ""))
44
- .remove(value)
45
- .to_s
46
- .tap do |tokens|
47
- @theme[key] = tokens
48
- end
47
+ @theme[key].remove(value)
48
+ @theme.delete(key) if @theme[key].empty?
49
49
  end
50
50
 
51
51
  def set(key, value)
52
- if value.is_a?(Hash)
53
- @theme[key] = value
54
- else
55
- TokenList
56
- .parse(value)
57
- .to_s
58
- .tap do |tokens|
59
- @theme[key] = tokens
60
- end
61
- end
52
+ @theme[key].clear.add(value)
62
53
  end
63
54
 
64
55
  def merge(hash)
65
- hash ||= {}
66
-
67
- tap do
68
- hash.each_key do |key|
69
- if key?(key)
70
- add(key, hash[key])
71
- elsif negation?(key)
72
- no_bang = key.to_s[1..].to_sym
73
- remove(no_bang, hash[key])
74
- elsif override?(key)
75
- no_bang = key.to_s.chomp("!").to_sym
76
- set(no_bang, hash[key])
77
- else
78
- set(key, hash[key])
79
- end
56
+ return self unless hash
57
+
58
+ hash.each do |key, value|
59
+ if key?(key)
60
+ add(key, value)
61
+ elsif negation?(key)
62
+ remove(key[1..].to_sym, value)
63
+ elsif override?(key)
64
+ set(key[..-2].to_sym, value)
65
+ else
66
+ set(key, value)
80
67
  end
81
68
  end
69
+
70
+ self
82
71
  end
83
72
 
84
73
  private
85
74
 
86
75
  def negation?(key)
87
- key.to_s.start_with?("!")
76
+ key.start_with?("!")
88
77
  end
89
78
 
90
79
  def override?(key)
91
- key.to_s.end_with?("!")
80
+ key.end_with?("!")
92
81
  end
93
82
  end
94
83
  end
@@ -6,8 +6,8 @@ module Protos
6
6
  # DOCS: The center of a timeline. This would usually be an icon or
7
7
  # something small that shows a point on the timeline.
8
8
 
9
- def template(&block)
10
- div(**attrs, &block)
9
+ def view_template(&)
10
+ div(**attrs, &)
11
11
  end
12
12
 
13
13
  private
@@ -7,8 +7,8 @@ module Protos
7
7
  # right and depending on its position in the list, an hr at the beginning
8
8
  # or end.
9
9
 
10
- def template(&block)
11
- li(**attrs, &block)
10
+ def view_template(&)
11
+ li(**attrs, &)
12
12
  end
13
13
  end
14
14
  end
@@ -6,8 +6,8 @@ module Protos
6
6
  # DOCS: Content on the left (on daisyui "start") side of a timeline.
7
7
  # We chose not to use start/end because of the keywork conflict with ruby.
8
8
 
9
- def template(&block)
10
- div(**attrs, &block)
9
+ def view_template(&)
10
+ div(**attrs, &)
11
11
  end
12
12
 
13
13
  private
@@ -6,8 +6,8 @@ module Protos
6
6
  # DOCS: Content on the right (on daisyui "end") side of a timeline.
7
7
  # We chose not to use start/end because of the keywork conflict with ruby.
8
8
 
9
- def template(&block)
10
- div(**attrs, &block)
9
+ def view_template(&)
10
+ div(**attrs, &)
11
11
  end
12
12
 
13
13
  private
@@ -7,25 +7,17 @@ module Protos
7
7
 
8
8
  option :vertical, type: Types::Bool, default: -> { false }
9
9
 
10
- def template(&block)
11
- ul(**attrs, &block)
10
+ def view_template(&)
11
+ ul(**attrs, &)
12
12
  end
13
13
 
14
- def item(...)
15
- Item.new(...)
16
- end
14
+ def item(...) = render Item.new(...)
17
15
 
18
- def left(...)
19
- Left.new(...)
20
- end
16
+ def left(...) = render Left.new(...)
21
17
 
22
- def center(...)
23
- Center.new(...)
24
- end
18
+ def center(...) = render Center.new(...)
25
19
 
26
- def right(...)
27
- Right.new(...)
28
- end
20
+ def right(...) = render Right.new(...)
29
21
 
30
22
  private
31
23
 
@@ -5,11 +5,12 @@ module Protos
5
5
  class CloseButton < Component
6
6
  # DOCS: A close button for a toast
7
7
 
8
- def template(&block)
8
+ def view_template(&block)
9
9
  form(method: :dialog, class: css[:form]) do
10
10
  button(
11
11
  autofocus: true,
12
12
  formmethod: :dialog,
13
+ formnovalidate: true,
13
14
  **attrs,
14
15
  &block
15
16
  )
data/lib/protos/toast.rb CHANGED
@@ -23,13 +23,11 @@ module Protos
23
23
  default: -> { :bottom_end },
24
24
  reader: false
25
25
 
26
- def template(&block)
27
- dialog(**attrs, &block)
26
+ def view_template(&)
27
+ dialog(**attrs, &)
28
28
  end
29
29
 
30
- def close_button(...)
31
- CloseButton.new(...)
32
- end
30
+ def close_button(...) = render CloseButton.new(...)
33
31
 
34
32
  private
35
33