ariadne_view_components 0.0.4 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/app/assets/javascripts/ariadne-form-with.d.ts +20 -0
  4. data/app/assets/javascripts/ariadne-form.d.ts +22 -0
  5. data/app/assets/javascripts/ariadne.d.ts +1 -0
  6. data/app/assets/javascripts/ariadne_view_components.js +7 -1
  7. data/app/assets/javascripts/ariadne_view_components.js.map +1 -1
  8. data/app/assets/javascripts/clipboard-copy-component.d.ts +4 -0
  9. data/app/assets/javascripts/comment-component.d.ts +13 -0
  10. data/app/assets/javascripts/rich-text-area-component.d.ts +4 -0
  11. data/app/assets/javascripts/slideover-component.d.ts +9 -0
  12. data/app/assets/javascripts/time-ago-component.d.ts +1 -0
  13. data/app/assets/javascripts/time_ago_component.d.ts +1 -0
  14. data/app/assets/javascripts/tooltip-component.d.ts +24 -0
  15. data/app/assets/stylesheets/application.ariadne_view_components.css +6 -3
  16. data/app/assets/stylesheets/prosemirror.css +323 -0
  17. data/app/assets/stylesheets/tooltip-component.css +37 -0
  18. data/app/components/ariadne/ariadne-form.ts +96 -0
  19. data/app/components/ariadne/ariadne.ts +11 -1
  20. data/app/components/ariadne/base_button.rb +12 -12
  21. data/app/components/ariadne/base_component.rb +13 -131
  22. data/app/components/ariadne/blankslate_component.html.erb +5 -5
  23. data/app/components/ariadne/blankslate_component.rb +5 -10
  24. data/app/components/ariadne/body_component.rb +30 -0
  25. data/app/components/ariadne/button_component.rb +12 -16
  26. data/app/components/ariadne/clipboard_copy_component.html.erb +5 -4
  27. data/app/components/ariadne/clipboard_copy_component.rb +41 -3
  28. data/app/components/ariadne/comment-component.ts +55 -0
  29. data/app/components/ariadne/comment_component.html.erb +22 -0
  30. data/app/components/ariadne/comment_component.rb +57 -0
  31. data/app/components/ariadne/component.rb +4 -3
  32. data/app/components/ariadne/container_component.rb +1 -1
  33. data/app/components/ariadne/counter_component.rb +4 -4
  34. data/app/components/ariadne/flash_component.html.erb +12 -12
  35. data/app/components/ariadne/flash_component.rb +17 -17
  36. data/app/components/ariadne/flex_component.rb +49 -0
  37. data/app/components/ariadne/footer_component.html.erb +1 -1
  38. data/app/components/ariadne/footer_component.rb +1 -1
  39. data/app/components/ariadne/grid_component.html.erb +13 -4
  40. data/app/components/ariadne/grid_component.rb +22 -11
  41. data/app/components/ariadne/header_component.html.erb +7 -7
  42. data/app/components/ariadne/header_component.rb +8 -8
  43. data/app/components/ariadne/heading_component.rb +3 -3
  44. data/app/components/ariadne/heroicon_component.html.erb +4 -6
  45. data/app/components/ariadne/heroicon_component.rb +21 -10
  46. data/app/components/ariadne/inline_flex_component.rb +14 -12
  47. data/app/components/ariadne/link_component.rb +13 -8
  48. data/app/components/ariadne/list_component.html.erb +5 -7
  49. data/app/components/ariadne/list_component.rb +9 -38
  50. data/app/components/ariadne/main_component.rb +32 -0
  51. data/app/components/ariadne/narrow_container_component.html.erb +3 -0
  52. data/app/components/ariadne/narrow_container_component.rb +30 -0
  53. data/app/components/ariadne/panel_bar_component.html.erb +20 -0
  54. data/app/components/ariadne/panel_bar_component.rb +79 -0
  55. data/app/components/ariadne/pill_component.rb +2 -2
  56. data/app/components/ariadne/rich-text-area-component.ts +32 -0
  57. data/app/components/ariadne/rich_text_area_component.html.erb +6 -0
  58. data/app/components/ariadne/rich_text_area_component.rb +35 -0
  59. data/app/components/ariadne/slideover-component.ts +3 -3
  60. data/app/components/ariadne/slideover_component.html.erb +3 -6
  61. data/app/components/ariadne/slideover_component.rb +19 -15
  62. data/app/components/ariadne/tab_bar_component.html.erb +3 -0
  63. data/app/components/ariadne/tab_bar_component.rb +45 -0
  64. data/app/components/ariadne/tab_component.html.erb +7 -0
  65. data/app/components/ariadne/tab_component.rb +43 -0
  66. data/app/components/ariadne/{time_ago_component.ts → time-ago-component.ts} +0 -0
  67. data/app/components/ariadne/time_ago_component.rb +2 -2
  68. data/app/components/ariadne/timeline_component.html.erb +6 -6
  69. data/app/components/ariadne/tooltip-component.ts +57 -0
  70. data/app/components/ariadne/tooltip_component.html.erb +4 -0
  71. data/app/components/ariadne/tooltip_component.rb +34 -31
  72. data/app/lib/ariadne/action_view_extensions/form_helper.rb +4 -1
  73. data/app/lib/ariadne/fetch_or_fallback_helper.rb +3 -1
  74. data/app/lib/ariadne/form_builder.rb +22 -22
  75. data/app/lib/ariadne/icon_helper.rb +1 -1
  76. data/lib/ariadne/view_components/engine.rb +171 -3
  77. data/lib/ariadne/view_components/version.rb +1 -1
  78. data/lib/ariadne/view_components.rb +31 -30
  79. data/lib/rubocop/config/default.yml +0 -6
  80. data/lib/rubocop/cop/ariadne/no_tag_memoize.rb +1 -0
  81. data/lib/tasks/docs.rake +9 -0
  82. data/static/arguments.yml +186 -15
  83. data/static/audited_at.json +12 -2
  84. data/static/classes.yml +200 -154
  85. data/static/constants.json +168 -146
  86. data/static/statuses.json +12 -2
  87. metadata +65 -13
  88. data/lib/ariadne/classify/utilities.rb +0 -199
  89. data/lib/ariadne/classify/utilities.yml +0 -1817
  90. data/lib/ariadne/classify/validation.rb +0 -18
  91. data/lib/ariadne/classify.rb +0 -218
  92. data/lib/rubocop/cop/ariadne/ariadne_heroicon.rb +0 -252
  93. data/lib/rubocop/cop/ariadne/component_name_migration.rb +0 -35
  94. data/lib/rubocop/cop/ariadne/system_argument_instead_of_class.rb +0 -57
  95. data/lib/tasks/utilities.rake +0 -121
@@ -1,155 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "ariadne/classify"
4
-
5
3
  module Ariadne
6
4
  # All Ariadne ViewComponents accept a standard set of options: classes, which match Tailwind CSS classes, and attributes, which match HTML attributes..
7
5
  #
8
- # Under the hood, classes are [mapped](https://github.com/ariadne/view_components/blob/main/lib/ariadne/classify.rb) to Tailwind CSS classes, with any unconsumed attributes passed to Rails' [`content_tag`](https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag).
6
+ # Under the hood, any-non class attributes is passed to Rails' [`tag`](https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-tag)
7
+ # (for self-closing tags) or [`content_tag`](https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag).
9
8
  class BaseComponent < Ariadne::Component
10
9
  SELF_CLOSING_TAGS = [:area, :base, :br, :col, :embed, :hr, :img, :input, :link, :meta, :param, :source, :track, :wbr].freeze
11
10
 
12
- # ## HTML attributes
13
- #
14
- # System arguments include most HTML attributes. For example:
15
- #
16
- # | Name | Type | Description |
17
- # | :- | :- | :- |
18
- # | `aria` | `Hash` | Aria attributes: `aria: { label: "foo" }` renders `aria-label='foo'`. |
19
- # | `data` | `Hash` | Data attributes: `data: { foo: :bar }` renders `data-foo='bar'`. |
20
- # | `height` | `Integer` | The height. |
21
- # | `hidden` | `Boolean` | Whether to assign the `hidden` attribute. |
22
- # | `style` | `String` | Inline styles. |
23
- # | `title` | `String` | The `title` attribute. |
24
- # | `width` | `Integer` | The width. |
25
- #
26
- # ## Animation
27
- #
28
- # | Name | Type | Description |
29
- # | :- | :- | :- |
30
- # | `animation` | Symbol | <%= one_of(Ariadne::Classify::Utilities.mappings(:animation)) %> |
31
- #
32
- # ## Border
33
- #
34
- # | Name | Type | Description |
35
- # | :- | :- | :- |
36
- # | `border_bottom` | Integer | Set to `0` to remove the bottom border. |
37
- # | `border_left` | Integer | Set to `0` to remove the left border. |
38
- # | `border_radius` | Integer | <%= one_of([0, 1, 2, 3]) %> |
39
- # | `border_right` | Integer | Set to `0` to remove the right border. |
40
- # | `border_top` | Integer | Set to `0` to remove the top border. |
41
- # | `border` | Symbol | <%= one_of([:left, :top, :bottom, :right, :y, :x, true]) %> |
42
- # | `box_shadow` | Boolean, Symbol | Box shadow. <%= one_of([true, :medium, :large, :extra_large, :none]) %> |
43
- #
44
- # ## Color
45
- #
46
- # | Name | Type | Description |
47
- # | :- | :- | :- |
48
- # | `bg` | Symbol | Background color. <%= one_of(Ariadne::Classify::Utilities.mappings(:bg)) %> |
49
- # | `border_color` | Symbol | Border color. <%= one_of(Ariadne::Classify::Utilities.mappings(:border_color)) %> |
50
- # | `color` | Symbol | Text color. <%= one_of(Ariadne::Classify::Utilities.mappings(:color)) %> |
51
- #
52
- # ## Flex
53
- #
54
- # | Name | Type | Description |
55
- # | :- | :- | :- |
56
- # | `align_items` | Symbol | <%= one_of(Ariadne::Classify::FLEX_ALIGN_ITEMS_VALUES) %> |
57
- # | `align_self` | Symbol | <%= one_of(Ariadne::Classify::FLEX_ALIGN_SELF_VALUES) %> |
58
- # | `direction` | Symbol | <%= one_of(Ariadne::Classify::FLEX_DIRECTION_VALUES) %> |
59
- # | `flex` | Integer, Symbol | <%= one_of(Ariadne::Classify::FLEX_VALUES) %> |
60
- # | `flex_grow` | Integer | To enable, set to `0`. |
61
- # | `flex_shrink` | Integer | To enable, set to `0`. |
62
- # | `flex_wrap` | Symbol | <%= one_of(Ariadne::Classify::FLEX_WRAP_MAPPINGS.keys) %> |
63
- # | `justify_content` | Symbol | <%= one_of(Ariadne::Classify::FLEX_JUSTIFY_CONTENT_VALUES) %> |
64
- #
65
- # ## Grid
66
- #
67
- # | Name | Type | Description |
68
- # | :- | :- | :- |
69
- # | `clearfix` | Boolean | Whether to assign the `clearfix` class. |
70
- # | `col` | Integer | Number of columns. <%= one_of(Ariadne::Classify::Utilities.mappings(:col)) %> |
71
- # | `container` | Symbol | Size of the container. <%= one_of(Ariadne::Classify::Utilities.mappings(:container)) %> |
72
- #
73
- # ## Layout
74
- #
75
- # | Name | Type | Description |
76
- # | :- | :- | :- |
77
- # | `display` | Symbol | <%= one_of(Ariadne::Classify::Utilities.mappings(:display)) %> |
78
- # | `w` | Symbol | <%= one_of(Ariadne::Classify::Utilities.mappings(:w)) %> |
79
- # | `h` | Symbol | <%= one_of(Ariadne::Classify::Utilities.mappings(:h)) %> |
80
- # | `hide` | Symbol | Hide the element at a specific breakpoint. <%= one_of(Ariadne::Classify::Utilities.mappings(:hide)) %> |
81
- # | `visibility` | Symbol | Visibility. <%= one_of(Ariadne::Classify::Utilities.mappings(:visibility)) %> |
82
- # | `vertical_align` | Symbol | <%= one_of(Ariadne::Classify::Utilities.mappings(:vertical_align)) %> |
83
- #
84
- # ## Position
85
- #
86
- # | Name | Type | Description |
87
- # | :- | :- | :- |
88
- # | `bottom` | Boolean | If `false`, sets `bottom: 0`. |
89
- # | `float` | Symbol | <%= one_of(Ariadne::Classify::Utilities.mappings(:float)) %> |
90
- # | `left` | Boolean | If `false`, sets `left: 0`. |
91
- # | `position` | Symbol | <%= one_of(Ariadne::Classify::Utilities.mappings(:position)) %> |
92
- # | `right` | Boolean | If `false`, sets `right: 0`. |
93
- # | `top` | Boolean | If `false`, sets `top: 0`. |
94
- #
95
- # ## Spacing
96
- #
97
- # | Name | Type | Description |
98
- # | :- | :- | :- |
99
- # | `m` | Integer | Margin. <%= one_of(Ariadne::Classify::Utilities.mappings(:m)) %> |
100
- # | `mb` | Integer | Margin bottom. <%= one_of(Ariadne::Classify::Utilities.mappings(:mb)) %> |
101
- # | `ml` | Integer | Margin left. <%= one_of(Ariadne::Classify::Utilities.mappings(:ml)) %> |
102
- # | `mr` | Integer | Margin right. <%= one_of(Ariadne::Classify::Utilities.mappings(:mr)) %> |
103
- # | `mt` | Integer | Margin top. <%= one_of(Ariadne::Classify::Utilities.mappings(:mt)) %> |
104
- # | `mx` | Integer | Horizontal margins. <%= one_of(Ariadne::Classify::Utilities.mappings(:mx)) %> |
105
- # | `my` | Integer | Vertical margins. <%= one_of(Ariadne::Classify::Utilities.mappings(:my)) %> |
106
- # | `p` | Integer | Padding. <%= one_of(Ariadne::Classify::Utilities.mappings(:p)) %> |
107
- # | `pb` | Integer | Padding bottom. <%= one_of(Ariadne::Classify::Utilities.mappings(:pb)) %> |
108
- # | `pl` | Integer | Padding left. <%= one_of(Ariadne::Classify::Utilities.mappings(:pl)) %> |
109
- # | `pr` | Integer | Padding right. <%= one_of(Ariadne::Classify::Utilities.mappings(:pr)) %> |
110
- # | `pt` | Integer | Padding left. <%= one_of(Ariadne::Classify::Utilities.mappings(:pt)) %> |
111
- # | `px` | Integer | Horizontal padding. <%= one_of(Ariadne::Classify::Utilities.mappings(:px)) %> |
112
- # | `py` | Integer | Vertical padding. <%= one_of(Ariadne::Classify::Utilities.mappings(:py)) %> |
113
- #
114
- # ## Typography
115
- #
116
- # | Name | Type | Description |
117
- # | :- | :- | :- |
118
- # | `font_family` | Symbol | Font weight. <%= one_of([:mono]) %> |
119
- # | `font_size` | String, Integer, Symbol | <%= one_of(["00", 0, 1, 2, 3, 4, 5, 6, :small, :normal]) %> |
120
- # | `font_style` | Symbol | Font weight. <%= one_of([:italic]) %> |
121
- # | `font_weight` | Symbol | Font weight. <%= one_of([:light, :normal, :bold, :emphasized]) %> |
122
- # | `text_align` | Symbol | Text alignment. <%= one_of([:left, :right, :center]) %> |
123
- # | `text_transform` | Symbol | Text alignment. <%= one_of([:uppercase]) %> |
124
- # | `underline` | Boolean | Whether text should be underlined. |
125
- # | `word_break` | Symbol | Whether to break words on line breaks. <%= one_of(Ariadne::Classify::Utilities.mappings(:word_break)) %> |
126
- #
127
- # ## Other
128
- #
129
- # | Name | Type | Description |
130
- # | :- | :- | :- |
131
- # | classes | String | CSS class name value to be concatenated with generated Tailwind CSS classes. |
132
- # | test_selector | String | Adds `data-test-selector='given value'` in non-Production environments for testing purposes. |
133
11
  def initialize(tag:, classes: "", attributes: {})
134
12
  @tag = tag
135
13
 
136
- @attributes = validate_attributes(tag: tag, attributes: attributes)
14
+ @attributes = validate_attributes(tag: tag, attributes: attributes) || {}
137
15
  @attributes[:"data-ariadne-view-component"] = true
138
16
 
139
- classes = classes.present? ? @attributes.merge(classes: classes) : @attributes.fetch(:classes, "")
140
- @classes = Ariadne::Classify.call(classes)
141
-
142
- # Filter out Ariadne keys so they don't get assigned as HTML attributes
143
- @content_tag_args = add_test_selector(@attributes).except(*Ariadne::Classify::Utilities::UTILITIES.keys)
17
+ classes = @attributes.fetch(:classes, "") if classes.blank?
18
+ @classes = validate_class_names(classes) || {}
19
+ @content_tag_args = {}
144
20
  end
145
21
 
146
22
  def call
147
- options = @content_tag_args.merge(@classes)
23
+ options = @attributes.merge(@classes)
148
24
  if SELF_CLOSING_TAGS.include?(@tag)
149
25
  tag(@tag, options)
150
26
  else
151
27
  content_tag(@tag, content, options)
152
28
  end
153
29
  end
30
+
31
+ private def validate_class_names(classes)
32
+ return if classes.blank?
33
+
34
+ { class: Ariadne::ViewComponents.tailwind_merger.merge(classes) }
35
+ end
154
36
  end
155
37
  end
@@ -1,4 +1,4 @@
1
- <div class="bg-white">
1
+ <%= render Ariadne::NarrowContainerComponent.new do %>
2
2
  <%= render Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes) do %>
3
3
  <% if icon.present? %>
4
4
  <%= icon %>
@@ -10,17 +10,17 @@
10
10
  <%= description %>
11
11
  <% end %>
12
12
  <%= content %>
13
- <div class="mt-8 flex justify-center">
13
+ <div class="ariadne-mt-8 ariadne-flex ariadne-justify-center">
14
14
  <% if primary_action.present? %>
15
- <div class="inline-flex rounded-md shadow">
15
+ <div class="ariadne-inline-flex ariadne-rounded-md shadow">
16
16
  <%= primary_action %>
17
17
  </div>
18
18
  <% end %>
19
19
  <% if secondary_action.present? %>
20
- <div class="ml-3 inline-flex">
20
+ <div class="ariadne-ml-3 ariadne-inline-flex">
21
21
  <%= secondary_action %>
22
22
  </div>
23
23
  <% end %>
24
24
  </div>
25
25
  <% end %>
26
- </div>
26
+ <% end %>
@@ -12,14 +12,14 @@ module Ariadne
12
12
  DEFAULT_TAG = :div
13
13
  TAG_OPTIONS = [DEFAULT_TAG].freeze
14
14
 
15
- DEFAULT_CLASSES = "max-w-7xl mx-auto text-center py-12 px-4 sm:px-6 lg:py-16 lg:px-8"
15
+ DEFAULT_CLASSES = "ariadne-text-center"
16
16
 
17
17
  # Optional visual that renders an <%= link_to_component(Ariadne::HeroiconComponent) %>.
18
18
  #
19
19
  # @param tag [Symbol, String] The rendered tag name
20
20
  # @param icon [String] Name of <%= link_to_heroicons %> to use.
21
21
  # @param size [Symbol] <%= one_of(Ariadne::HeroiconComponent::SIZE_MAPPINGS, sort: false) %>
22
- # @param variant [String] <%= one_of(HeroiconsHelper::Icon::VARIANTS, sort: false) %>
22
+ # @param variant [String] <%= one_of(HeroiconsHelper::Icon::VALID_VARIANTS, sort: false) %>
23
23
  # @param classes [String] <%= link_to_classes_docs %>
24
24
  # @param attributes [Hash] Same arguments as <%= link_to_component(Ariadne::HeroiconComponent) %>.
25
25
  renders_one :icon, lambda { |tag: :svg, icon:, size: Ariadne::HeroiconComponent::SIZE_DEFAULT, variant: HeroiconsHelper::Icon::VARIANT_SOLID, classes: "", attributes: {}|
@@ -79,7 +79,7 @@ module Ariadne
79
79
  # @param href [String] URL to be used for the primary action.
80
80
  # @param classes [String] <%= link_to_classes_docs %>
81
81
  # @param attributes [Hash] Same arguments as <%= link_to_component(Ariadne::HeroiconComponent) %>.
82
- renders_one :primary_action, lambda { |href: nil, tag: :a, method: nil, size: :m, scheme: :default, classes: "", attributes: {}|
82
+ renders_one :primary_action, lambda { |href: nil, tag: :a, method: nil, size: :md, scheme: :default, classes: "", attributes: {}|
83
83
  attributes[:href] = href
84
84
  attributes[:method] = method
85
85
 
@@ -113,10 +113,10 @@ module Ariadne
113
113
  #
114
114
  # @example Icon
115
115
  # @description
116
- # Add an `icon` to give additional context. Refer to the [Octicons](https://primer.style/octicons/) documentation to choose an icon.
116
+ # Add an `icon` to give additional context. Refer to the [Heroicons](https://heroicons.com) documentation to choose an icon.
117
117
  # @code
118
118
  # <%= render Ariadne::BlankslateComponent.new do |c| %>
119
- # <% c.icon(icon: :globe) %>
119
+ # <% c.icon(icon: :"globe-europe-africa") %>
120
120
  # <% c.heading(tag: :h2).with_content("heading") %>
121
121
  # <% c.description { "Description"} %>
122
122
  # <% end %>
@@ -142,10 +142,5 @@ module Ariadne
142
142
  def render?
143
143
  heading.present?
144
144
  end
145
-
146
- def wrapper
147
- yield
148
- nil # returning `yield` causes a double render
149
- end
150
145
  end
151
146
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ariadne
4
+ # Add a general description of component here
5
+ # Add additional usage considerations or best practices that may aid the user to use the component correctly.
6
+ # @accessibility Add any accessibility considerations
7
+ class BodyComponent < Ariadne::Component
8
+ DEFAULT_CLASSES = "ariadne-flex ariadne-flex-col ariadne-min-h-screen"
9
+
10
+ # @example Default
11
+ #
12
+ # <%= render(Ariadne::BodyComponent.new) { "Example" } %>
13
+ #
14
+ # @param classes [String] <%= link_to_classes_docs %>
15
+ # @param attributes [Hash] <%= link_to_attributes_docs %>
16
+ def initialize(classes: "", attributes: {})
17
+ @tag = :body
18
+ @classes = class_names(
19
+ DEFAULT_CLASSES,
20
+ classes
21
+ )
22
+
23
+ @attributes = attributes
24
+ end
25
+
26
+ def call
27
+ render(Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes)) { content }
28
+ end
29
+ end
30
+ end
@@ -9,11 +9,12 @@ module Ariadne
9
9
  LINK_SCHEME = :link
10
10
 
11
11
  SCHEME_CLASS_MAPPINGS = {
12
- default: "text-purple-800 bg-purple-50 hover:bg-purple-100 border-purple-300 focus:ring-offset-purple-50 focus:ring-purple-600",
13
- info: "text-blue-800 bg-blue-50 hover:bg-blue-100 border-blue-300 focus:ring-offset-blue-50 focus:ring-blue-600",
14
- success: "text-green-800 bg-green-50 hover:bg-green-100 border-green-300 focus:ring-offset-green-50 focus:ring-green-600",
15
- warning: "text-yellow-800 bg-yellow-50 hover:bg-yellow-100 border-yellow-300 focus:ring-offset-yellow-50 focus:ring-yellow-600",
16
- danger: "text-red-800 bg-red-50 hover:bg-red-100 border-red-300 focus:ring-offset-red-50 focus:ring-red-600",
12
+ none: "",
13
+ default: "ariadne-text-purple-800 ariadne-bg-purple-50 hover:ariadne-bg-purple-100 ariadne-border-purple-300 focus:ariadne-ring-offset-purple-50 focus:ariadne-ring-purple-600",
14
+ info: "ariadne-text-blue-800 ariadne-bg-blue-50 hover:ariadne-bg-blue-100 ariadne-border-blue-300 focus:ariadne-ring-offset-blue-50 focus:ariadne-ring-blue-600",
15
+ success: "ariadne-text-green-800 ariadne-bg-green-50 hover:ariadne-bg-green-100 ariadne-border-green-300 focus:ariadne-ring-offset-green-50 focus:ariadne-ring-green-600",
16
+ warning: "ariadne-text-yellow-800 ariadne-bg-yellow-50 hover:ariadne-bg-yellow-100 ariadne-border-yellow-300 focus:ariadne-ring-offset-yellow-50 focus:ariadne-ring-yellow-600",
17
+ danger: "ariadne-text-red-800 ariadne-bg-red-50 hover:ariadne-bg-red-100 ariadne-border-red-300 focus:ariadne-ring-offset-red-50 focus:ariadne-ring-red-600",
17
18
  }.freeze
18
19
  VALID_SCHEMES = SCHEME_CLASS_MAPPINGS.keys.freeze
19
20
 
@@ -26,7 +27,7 @@ module Ariadne
26
27
  # @param tag [Symbol, String] The rendered tag name
27
28
  # @param classes [String] <%= link_to_classes_docs %>
28
29
  # @param icon [String] Name of <%= link_to_heroicons %> to use.
29
- # @param variant [String] <%= one_of(HeroiconsHelper::Icon::VARIANTS, sort: false) %>
30
+ # @param variant [String] <%= one_of(HeroiconsHelper::Icon::VALID_VARIANTS, sort: false) %>
30
31
  # @param attributes [Hash] Same arguments as <%= link_to_component(Ariadne::HeroiconComponent) %>.
31
32
  renders_one :icon, lambda { |tag: :svg, icon:, variant:, classes: "", attributes: {}|
32
33
  @icon = icon
@@ -58,18 +59,13 @@ module Ariadne
58
59
  #
59
60
  # @param tag [Symbol, String] The rendered tag name
60
61
  # @param text [String] The text content of the tooltip. This should be brief and no longer than a sentence.
61
- # @param direction [Symbol] <%= one_of(Ariadne::TooltipComponent::DIRECTION_OPTIONS) %>
62
+ # @param direction [Symbol] <%= one_of(Ariadne::TooltipComponent::VALID_PLACEMENTS) %>
62
63
  # @param classes [String] <%= link_to_classes_docs %>
63
64
  # @param attributes [Hash] Same arguments as <%= link_to_component(Ariadne::TooltipComponent) %>.
64
- renders_one :tooltip, lambda { |tag: :"tool-tip", text:, direction: Ariadne::TooltipComponent::DIRECTION_DEFAULT, type: Ariadne::TooltipComponent::TYPE_DEFAULT, classes: "", attributes: {}|
65
+ renders_one :tooltip, lambda { |tag: Ariadne::TooltipComponent::DEFAULT_TAG, text:, direction: Ariadne::TooltipComponent::DEFAULT_PLACEMENT, type: Ariadne::TooltipComponent::TYPE_DEFAULT, classes: "", attributes: {}|
65
66
  raise ArgumentError, "Buttons with a tooltip must have a unique `id` set on the `Button`." if @id.blank?
66
67
 
67
- # TODO: test this
68
- tag = check_incoming_tag(:"tool-tip", tag)
69
- attributes[:for] = @id
70
- attributes[:type] = check_incoming_attribute(:description, attributes[:type])
71
-
72
- Ariadne::TooltipComponent.new(tag: tag, text: text, direction: direction, type: type, classes: classes, attributes: attributes)
68
+ Ariadne::TooltipComponent.new(for_id: @id, tag: tag, text: text, direction: direction, type: type, classes: classes, attributes: attributes)
73
69
  }
74
70
 
75
71
  # @example Schemes
@@ -81,8 +77,8 @@ module Ariadne
81
77
  # <%= render(Ariadne::ButtonComponent.new(scheme: :danger)) { "Danger" } %>
82
78
  #
83
79
  # @example Sizes
84
- # <%= render(Ariadne::ButtonComponent.new(size: :s)) { "Small" } %>
85
- # <%= render(Ariadne::ButtonComponent.new(size: :m)) { "Medium" } %>
80
+ # <%= render(Ariadne::ButtonComponent.new(size: :sm)) { "Small" } %>
81
+ # <%= render(Ariadne::ButtonComponent.new(size: :md)) { "Medium" } %>
86
82
  #
87
83
  # @example With leading visual
88
84
  # <%= render(Ariadne::ButtonComponent.new) do |c| %>
@@ -1,8 +1,9 @@
1
- <%= render Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes.merge(:"data-controller" => DATA_CONTROLLER, :"data-action" => DATA_ACTION)) do %>
1
+ <%= render Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes.merge(controller_data)) do %>
2
2
  <% if content.present? %>
3
- <%= content %>
3
+ <%= content.to_s + tooltip.to_s %>
4
4
  <% else %>
5
- <%= render Ariadne::HeroiconComponent.new(icon: :duplicate, variant: HeroiconsHelper::Icon::VARIANT_OUTLINE) %>
6
- <%= render Ariadne::HeroiconComponent.new(icon: :check, variant: HeroiconsHelper::Icon::VARIANT_OUTLINE, attributes: { color: :success, style: "display: none;" }) %>
5
+ <%= render Ariadne::HeroiconComponent.new(icon: :"document-duplicate", variant: HeroiconsHelper::Icon::VARIANT_OUTLINE) %>
6
+ <!-- TODO: fix, check should replace on click -->
7
+ <%= render Ariadne::HeroiconComponent.new(icon: :check, variant: HeroiconsHelper::Icon::VARIANT_OUTLINE, classes: "ariadne-text-green-600", attributes: { style: "display: none;" }) %>
7
8
  <% end %>
8
9
  <% end %>
@@ -8,11 +8,28 @@ module Ariadne
8
8
  class ClipboardCopyComponent < Ariadne::Component
9
9
  DEFAULT_TAG = :"clipboard-copy"
10
10
 
11
- DEFAULT_CLASSES = "cursor-pointer"
11
+ DEFAULT_CLASSES = LinkComponent::DEFAULT_ACTIONABLE_CLASSES
12
12
 
13
13
  DATA_CONTROLLER = "clipboard-copy-component"
14
14
  DATA_ACTION = "click->clipboard-copy-component#copy"
15
15
 
16
+ # `Tooltip` that appears on mouse hover or keyboard focus over the button. Use tooltips sparingly and as a last resort.
17
+ # **Important:** This tooltip defaults to `type: :description`. In a few scenarios, `type: :label` may be more appropriate.
18
+ # Consult the <%= link_to_component(Ariadne::TooltipComponent) %> documentation for more information.
19
+ #
20
+ # @param tag [Symbol, String] The rendered tag name
21
+ # @param text [String] The text content of the tooltip. This should be brief and no longer than a sentence.
22
+ # @param direction [Symbol] <%= one_of(Ariadne::TooltipComponent::VALID_PLACEMENTS) %>
23
+ # @param classes [String] <%= link_to_classes_docs %>
24
+ # @param attributes [Hash] Same arguments as <%= link_to_component(Ariadne::TooltipComponent) %>.
25
+ renders_one :tooltip, lambda { |tag: Ariadne::TooltipComponent::DEFAULT_TAG, text:, direction: Ariadne::TooltipComponent::DEFAULT_PLACEMENT, type: Ariadne::TooltipComponent::TYPE_DEFAULT, classes: "", attributes: {}|
26
+ raise ArgumentError, "CopyClipboardComponents with a tooltip must have a unique `id` set on the `CopyClipboardComponent`." if @id.blank?
27
+
28
+ @data_tooltip_direction = { "data-tooltip-component-direction": direction }
29
+
30
+ Ariadne::TooltipComponent.new(tag: tag, for_id: @id, text: text, direction: direction, type: type, classes: classes, attributes: attributes)
31
+ }
32
+
16
33
  # @example Default
17
34
  # <%= render(Ariadne::ClipboardCopyComponent.new(value: "Text to copy", aria_label: "Copy text to the system clipboard" )) %>
18
35
  #
@@ -22,19 +39,22 @@ module Ariadne
22
39
  # <% end %>
23
40
  #
24
41
  # @example Copying from an element
25
- # <%= render(Ariadne::ClipboardCopyComponent.new(attributes: { for: "blob-path"}, aria_label: "Copy text to the system clipboard" )) %>
42
+ # <%= render(Ariadne::ClipboardCopyComponent.new(for_id: "blob-path", aria_label: "Copy text to the system clipboard" )) %>
26
43
  # <div id="blob-path">src/index.js</div>
27
44
  #
28
45
  # @param tag [Symbol, String] The rendered tag name
29
46
  # @param classes [String] <%= link_to_classes_docs %>
30
47
  # @param value [String] Text to copy into the users clipboard when they click the component.
48
+ # @param for_id [String] If `value` is not provided, the element with this id will be copied.
31
49
  # @param aria_label [String] Text for accessibility. Can also be passed in as part of `attributes`, but it must be present.
32
50
  # @param attributes [Hash] <%= link_to_attributes_docs %>
33
- def initialize(tag: DEFAULT_TAG, value: "", aria_label: "", classes: "", attributes: {})
51
+ def initialize(tag: DEFAULT_TAG, value: "", for_id: nil, aria_label: "", classes: "", attributes: {})
34
52
  @attributes = attributes
35
53
  @value = value
36
54
 
37
55
  @attributes[:"aria-label"] = aria_label
56
+ @attributes[:for] ||= for_id
57
+ @id = @attributes[:id]
38
58
 
39
59
  validate!
40
60
 
@@ -48,5 +68,23 @@ module Ariadne
48
68
  raise ArgumentError, "Must provide either `value` or `for`" if @value.blank? && @attributes[:for].blank?
49
69
  raise ArgumentError, "Must provide only `value` or `for`, not both" if @value.present? && @attributes[:for].present?
50
70
  end
71
+
72
+ DATA_CONTROLLERS_WITH_TOOLTIPS = {
73
+ "data-controller": "#{DATA_CONTROLLER} #{Ariadne::TooltipComponent::DATA_CONTROLLER}",
74
+ "data-action": "#{DATA_ACTION} #{Ariadne::TooltipComponent::DATA_ACTION}",
75
+ "data-tooltip-component-target": "trigger",
76
+ }
77
+
78
+ DATA_CONTROLLERS =
79
+ {
80
+ "data-controller": DATA_CONTROLLER.to_s,
81
+ "data-action": DATA_ACTION,
82
+ }
83
+
84
+ def controller_data
85
+ return DATA_CONTROLLERS_WITH_TOOLTIPS if tooltip.present?
86
+
87
+ DATA_CONTROLLERS
88
+ end
51
89
  end
52
90
  end
@@ -0,0 +1,55 @@
1
+ import {Controller} from '@hotwired/stimulus'
2
+
3
+ export default class CommentComponent extends Controller {
4
+ static targets = ['tab', 'tabBarComponent']
5
+
6
+ declare readonly commentComponentTarget: HTMLDivElement
7
+ declare readonly tabBarComponentTarget: HTMLElement // technically a `nav but typescript can't find it?
8
+ declare readonly tabTargets: [HTMLButtonElement]
9
+
10
+ SELECTED_TAB_CLASSES = ['ariadne-border-indigo-500', 'ariadne-text-indigo-600']
11
+ PUBLIC_BACKGROUND_COLOR = 'ariadne-bg-white'
12
+ INTERNAL_BACKGROUND_COLOR = 'ariadne-bg-internal-message'
13
+
14
+ connect() {
15
+ for (const tab of this.tabTargets) {
16
+ if (tab.hasAttribute('selected')) {
17
+ tab.classList.add(...this.SELECTED_TAB_CLASSES)
18
+ }
19
+ }
20
+ }
21
+
22
+ toggleTab() {
23
+ for (const tab of this.tabTargets) {
24
+ if (tab.hasAttribute('selected')) {
25
+ tab.removeAttribute('selected')
26
+ tab.classList.remove(...this.SELECTED_TAB_CLASSES)
27
+ this.toggleBackgrounds(tab)
28
+ } else {
29
+ tab.setAttribute('selected', 'true')
30
+ tab.classList.add(...this.SELECTED_TAB_CLASSES)
31
+ this.toggleBackgrounds(tab)
32
+ if (tab.hasAttribute('data-public')) {
33
+ document.getElementById('message_public')?.setAttribute('value', 'true')
34
+ } else {
35
+ document.getElementById('message_public')?.setAttribute('value', 'false')
36
+ }
37
+ }
38
+ }
39
+ }
40
+ toggleBackgrounds(tab: HTMLButtonElement) {
41
+ if (tab.hasAttribute('selected')) {
42
+ if (tab.hasAttribute('data-public')) {
43
+ // this.commentComponentTarget.classList.add(this.PUBLIC_BACKGROUND_COLOR)
44
+ // this.commentComponentTarget.classList.remove(this.INTERNAL_BACKGROUND_COLOR)
45
+ this.tabBarComponentTarget.classList.add(this.PUBLIC_BACKGROUND_COLOR)
46
+ this.tabBarComponentTarget.classList.remove(this.INTERNAL_BACKGROUND_COLOR)
47
+ } else {
48
+ // this.commentComponentTarget.classList.remove(this.PUBLIC_BACKGROUND_COLOR)
49
+ // this.commentComponentTarget.classList.add(this.INTERNAL_BACKGROUND_COLOR)
50
+ this.tabBarComponentTarget.classList.remove(this.PUBLIC_BACKGROUND_COLOR)
51
+ this.tabBarComponentTarget.classList.add(this.INTERNAL_BACKGROUND_COLOR)
52
+ }
53
+ }
54
+ }
55
+ }
@@ -0,0 +1,22 @@
1
+ <%= render(Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes)) do %>
2
+ <div class="ariadne-bg-white" data-comment-component-target="commentComponent">
3
+ <div class="ariadne-hidden sm:ariadne-block">
4
+ <div class="ariadne-border-b ariadne-border-gray-200">
5
+ <%= render(Ariadne::TabBarComponent.new(sr_label: @sr_label, attributes: { :"data-comment-component-target" => "tabBarComponent" })) do |tab_bar| %>
6
+ <%= public_tab %>
7
+ <%= internal_tab %>
8
+ <% end %>
9
+ </div>
10
+ </div>
11
+ <%= ariadne_form_with(url: @url, method: @method, classes: @classes, attributes: @attributes) do |comment_box| %>
12
+ <div class="ariadne-overflow-hidden ariadne-border-x ariadne-border-b ariadne-border-gray-300 ariadne-shadow-sm focus-within:ariadne-border-indigo-500 focus-within:ariadne-ring-1 focus-within:ariadne-ring-indigo-500">
13
+ <%= hidden_field_tag 'message_public', true %>
14
+ <%= render(Ariadne::RichTextAreaComponent.new(name: :bodytext, sr_label: "Select reply type", attributes: { required: true})) %>
15
+ <% comment_box.submit { @submit } %>
16
+ </div>
17
+ <div class="ariadne-mt-2 ariadne-flex ariadne-justify-end">
18
+ <%= submit %>
19
+ </div>
20
+ <% end %>
21
+ </div>
22
+ <% end %>
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ariadne
4
+ # Defines a submittable form for adding comments to a conversation.
5
+ # @accessibility This component requires you to pass in a `sr_label`
6
+ # attribute, which will be used to label the tabs for screen readers.
7
+ class CommentComponent < Ariadne::Component
8
+ DEFAULT_TAG = :div
9
+ TAG_OPTIONS = [DEFAULT_TAG].freeze
10
+
11
+ DEFAULT_CLASSES = "ariadne-bg-white ariadne-border-gray-300 ariadne-border ariadne-shadow ariadne-py-5 ariadne-px-5 ariadne-rounded-md "
12
+
13
+ renders_one :public_tab, lambda { |selected: false, text:, classes: "", attributes: {}|
14
+ attributes[:"data-comment-component-target"] ||= "tab"
15
+ attributes[:"data-action"] ||= "click->comment-component#toggleTab"
16
+ attributes[:"data-public"] = true
17
+ @tab_idx += 1
18
+ render(Ariadne::TabComponent.new(selected: selected, classes: classes, attributes: attributes)) { text }
19
+ }
20
+
21
+ renders_one :internal_tab, lambda { |selected: false, text:, classes: "", attributes: {}|
22
+ attributes[:"data-comment-component-target"] ||= "tab"
23
+ attributes[:"data-action"] ||= "click->comment-component#toggleTab"
24
+ @tab_idx += 1
25
+ render(Ariadne::TabComponent.new(selected: selected, classes: classes, attributes: attributes)) { text }
26
+ }
27
+
28
+ renders_one :submit, lambda { |classes: "", attributes: {}|
29
+ Ariadne::ButtonComponent.new(type: Ariadne::BaseButton::TYPE_SUBMIT, scheme: Ariadne::ButtonComponent::DEFAULT_SCHEME, classes: classes, attributes: attributes)
30
+ }
31
+
32
+ # @example Default
33
+ #
34
+ # <%= render(Ariadne::CommentComponent.new(url: "/messages", method: :post, sr_label: "Select delivery time")) { "Example" } %>
35
+ #
36
+ # @param url [String] The URL to take action against.
37
+ # @param method [String] The method to use when submitting the form.
38
+ # @param sr_label [String] A label to introduce these tabs for screen readers.
39
+ # @param classes [String] <%= link_to_classes_docs %>
40
+ # @param attributes [Hash] <%= link_to_attributes_docs %>
41
+ def initialize(url:, method:, sr_label:, classes: "", attributes: {})
42
+ @tag = DEFAULT_TAG
43
+ @classes = class_names(
44
+ DEFAULT_CLASSES,
45
+ classes
46
+ )
47
+ @url = url
48
+ @method = method
49
+ @sr_label = sr_label
50
+
51
+ @tab_idx = -1
52
+ @attributes = attributes
53
+ @attributes[:"data-controller"] = "comment-component"
54
+ attributes[:"data-comment-component-target"] = "commentComponent"
55
+ end
56
+ end
57
+ end
@@ -18,9 +18,10 @@ module Ariadne
18
18
  include LoggerHelper
19
19
  include Ariadne::ActionViewExtensions::FormHelper
20
20
 
21
- BASE_HTML_CLASSES = "h-full scroll-smooth bg-white antialiased"
22
- BASE_BODY_CLASSES = "flex flex-col min-h-screen"
23
- BASE_MAIN_CLASSES = "flex-auto"
21
+ BASE_HTML_CLASSES = "ariadne-h-full scroll-smooth ariadne-bg-white ariadne-antialiased"
22
+ BASE_BODY_CLASSES = "ariadne-flex ariadne-h-full ariadne-flex-col"
23
+ BASE_WRAPPER_CLASSES = "ariadne-flex ariadne-flex-col ariadne-h-screen ariadne-justify-between"
24
+ BASE_MAIN_CLASSES = "ariadne-flex-auto"
24
25
 
25
26
  INVALID_ARIA_LABEL_TAGS = [:div, :span, :p].freeze
26
27
 
@@ -3,7 +3,7 @@
3
3
  module Ariadne
4
4
  # The container wraps the majority, if not all, of the content on a page.
5
5
  class ContainerComponent < Ariadne::Component
6
- DEFAULT_CLASSES = "px-4 py-5 sm:px-6 lg:px-8"
6
+ DEFAULT_CLASSES = "ariadne-px-4 sm:ariadne-px-6 lg:ariadne-px-8"
7
7
 
8
8
  # @example Default
9
9
  # <%= render(Ariadne::ContainerComponent.new) do |container| %>
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ariadne
4
- # Use `Counter` to add a count to navigational elements and buttons.
4
+ # Use `CounterComponent` to add a count to navigational elements and buttons.
5
5
  #
6
6
  # @accessibility
7
- # Always use `Counter` with adjacent text that provides supplementary information regarding what the count is for. For instance, `Counter`
7
+ # Always use `CounterComponent` with adjacent text that provides supplementary information regarding what the count is for. For instance, `Counter`
8
8
  # should be accompanied with text such as `issues` or `pull requests`.
9
9
  #
10
10
  class CounterComponent < Ariadne::Component
11
- DEFAULT_CLASSES = "inline-flex items-center p-1 border border-transparent rounded-full shadow-sm text-white bg-gray-600 hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500"
12
- #
11
+ DEFAULT_CLASSES = "ariadne-inline-flex ariadne-items-center ariadne-p-1 ariadne-border ariadne-border-transparent ariadne-rounded-full ariadne-shadow-sm focus:ariadne-outline-none focus:ariadne-ring-2 focus:ariadne-ring-offset-2"
12
+
13
13
  # @example Default
14
14
  # <%= render(Ariadne::CounterComponent.new(count: 25)) %>
15
15
  #