ariadne_view_components 0.0.39-arm64-darwin → 0.0.40-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/lib/ariadne/view_components/upstream.rb +0 -1
  4. data/lib/ariadne/view_components/version.rb +1 -1
  5. metadata +2 -94
  6. data/app/assets/config/manifest.js +0 -2
  7. data/app/assets/stylesheets/ariadne_view_components.css +0 -7
  8. data/app/assets/stylesheets/dropdown.css +0 -46
  9. data/app/assets/stylesheets/prosemirror.css +0 -323
  10. data/app/assets/stylesheets/tooltip-component.css +0 -37
  11. data/app/components/ariadne/ariadne-form.ts +0 -96
  12. data/app/components/ariadne/ariadne.ts +0 -21
  13. data/app/components/ariadne/avatar_component.rb +0 -81
  14. data/app/components/ariadne/avatar_stack_component/avatar_stack_component.html.erb +0 -12
  15. data/app/components/ariadne/avatar_stack_component.rb +0 -75
  16. data/app/components/ariadne/base_button.rb +0 -70
  17. data/app/components/ariadne/base_component.rb +0 -37
  18. data/app/components/ariadne/blankslate_component/blankslate_component.html.erb +0 -26
  19. data/app/components/ariadne/blankslate_component.rb +0 -148
  20. data/app/components/ariadne/body_component.rb +0 -30
  21. data/app/components/ariadne/button_component/button_component.html.erb +0 -4
  22. data/app/components/ariadne/button_component.rb +0 -165
  23. data/app/components/ariadne/clipboard_copy_component/clipboard-copy-component.ts +0 -19
  24. data/app/components/ariadne/clipboard_copy_component/clipboard_copy_component.html.erb +0 -9
  25. data/app/components/ariadne/clipboard_copy_component.rb +0 -90
  26. data/app/components/ariadne/comment_component/comment_component.html.erb +0 -37
  27. data/app/components/ariadne/comment_component.rb +0 -71
  28. data/app/components/ariadne/component.rb +0 -127
  29. data/app/components/ariadne/container_component/container_component.html.erb +0 -3
  30. data/app/components/ariadne/container_component.rb +0 -25
  31. data/app/components/ariadne/content.rb +0 -12
  32. data/app/components/ariadne/counter_component.rb +0 -100
  33. data/app/components/ariadne/details_component/details_component.html.erb +0 -4
  34. data/app/components/ariadne/details_component.rb +0 -81
  35. data/app/components/ariadne/dropdown/menu_component.html.erb +0 -20
  36. data/app/components/ariadne/dropdown/menu_component.rb +0 -101
  37. data/app/components/ariadne/dropdown/menu_component.ts +0 -1
  38. data/app/components/ariadne/dropdown_component/dropdown_component.html.erb +0 -8
  39. data/app/components/ariadne/dropdown_component.rb +0 -172
  40. data/app/components/ariadne/flash_component/flash_component.html.erb +0 -31
  41. data/app/components/ariadne/flash_component.rb +0 -128
  42. data/app/components/ariadne/flex_component/flex_component.html.erb +0 -5
  43. data/app/components/ariadne/flex_component.rb +0 -56
  44. data/app/components/ariadne/footer_component/footer_component.html.erb +0 -7
  45. data/app/components/ariadne/footer_component.rb +0 -23
  46. data/app/components/ariadne/grid_component/grid_component.html.erb +0 -26
  47. data/app/components/ariadne/grid_component.rb +0 -67
  48. data/app/components/ariadne/header_component/header_component.html.erb +0 -29
  49. data/app/components/ariadne/header_component.rb +0 -111
  50. data/app/components/ariadne/heading_component.rb +0 -49
  51. data/app/components/ariadne/heroicon_component/heroicon_component.html.erb +0 -4
  52. data/app/components/ariadne/heroicon_component.rb +0 -166
  53. data/app/components/ariadne/image_component.rb +0 -53
  54. data/app/components/ariadne/inline_flex_component/inline_flex_component.html.erb +0 -6
  55. data/app/components/ariadne/inline_flex_component.rb +0 -72
  56. data/app/components/ariadne/link_component.rb +0 -65
  57. data/app/components/ariadne/list_component/list_component.html.erb +0 -6
  58. data/app/components/ariadne/list_component.rb +0 -70
  59. data/app/components/ariadne/narrow_container_component/narrow_container_component.html.erb +0 -3
  60. data/app/components/ariadne/narrow_container_component.rb +0 -30
  61. data/app/components/ariadne/panel_bar_component/panel_bar_component.html.erb +0 -20
  62. data/app/components/ariadne/panel_bar_component.rb +0 -80
  63. data/app/components/ariadne/pill_component/pill_component.html.erb +0 -3
  64. data/app/components/ariadne/pill_component.rb +0 -44
  65. data/app/components/ariadne/rich_text_area_component/rich-text-area-component.ts +0 -47
  66. data/app/components/ariadne/rich_text_area_component/rich_text_area_component.html.erb +0 -6
  67. data/app/components/ariadne/rich_text_area_component.rb +0 -35
  68. data/app/components/ariadne/slideover_component/slideover-component.ts +0 -17
  69. data/app/components/ariadne/slideover_component/slideover_component.html.erb +0 -9
  70. data/app/components/ariadne/slideover_component.rb +0 -66
  71. data/app/components/ariadne/tab_component/tab_component.html.erb +0 -3
  72. data/app/components/ariadne/tab_component.rb +0 -98
  73. data/app/components/ariadne/tab_container_component/tab-container-component.ts +0 -24
  74. data/app/components/ariadne/tab_container_component.erb +0 -10
  75. data/app/components/ariadne/tab_container_component.rb +0 -68
  76. data/app/components/ariadne/tab_nav_component/tab-nav-component.ts +0 -34
  77. data/app/components/ariadne/tab_nav_component/tab_nav_component.html.erb +0 -7
  78. data/app/components/ariadne/tab_nav_component.rb +0 -72
  79. data/app/components/ariadne/table_nav_component/table_nav_component.html.erb +0 -52
  80. data/app/components/ariadne/table_nav_component.rb +0 -338
  81. data/app/components/ariadne/text.rb +0 -25
  82. data/app/components/ariadne/time_ago_component/time-ago-component.ts +0 -1
  83. data/app/components/ariadne/time_ago_component.rb +0 -56
  84. data/app/components/ariadne/timeline_component/timeline_component.html.erb +0 -19
  85. data/app/components/ariadne/timeline_component.rb +0 -34
  86. data/app/components/ariadne/tooltip_component/tooltip-component.ts +0 -57
  87. data/app/components/ariadne/tooltip_component/tooltip_component.html.erb +0 -4
  88. data/app/components/ariadne/tooltip_component.rb +0 -108
  89. data/app/lib/ariadne/action_view_extensions/form_helper.rb +0 -30
  90. data/app/lib/ariadne/audited/dsl.rb +0 -32
  91. data/app/lib/ariadne/class_name_helper.rb +0 -22
  92. data/app/lib/ariadne/fetch_or_fallback_helper.rb +0 -110
  93. data/app/lib/ariadne/form_builder.rb +0 -74
  94. data/app/lib/ariadne/icon_helper.rb +0 -51
  95. data/app/lib/ariadne/logger_helper.rb +0 -23
  96. data/app/lib/ariadne/status/dsl.rb +0 -41
  97. data/app/lib/ariadne/view_helper.rb +0 -22
@@ -1,19 +0,0 @@
1
- import {Controller} from '@hotwired/stimulus'
2
-
3
- export default class ClipboardCopyComponent extends Controller {
4
- copy() {
5
- const value = this.element.attributes.getNamedItem('value')
6
-
7
- const forNode = this.element.attributes.getNamedItem('for')
8
-
9
- if (value) {
10
- navigator.clipboard.writeText(value.value)
11
- } else if (forNode) {
12
- const node = document.getElementById(forNode.value)
13
- navigator.clipboard.writeText(node?.textContent || '')
14
- } else {
15
- // just copy inner text
16
- navigator.clipboard.writeText(this.element.textContent || '')
17
- }
18
- }
19
- }
@@ -1,9 +0,0 @@
1
- <%= render Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes.merge(controller_data)) do %>
2
- <% if content.present? %>
3
- <%= content.to_s + tooltip.to_s %>
4
- <% else %>
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;" }) %>
8
- <% end %>
9
- <% end %>
@@ -1,90 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ariadne
4
- # Use `ClipboardCopyComponent` to copy element text content or input values to the clipboard.
5
- #
6
- # @accessibility
7
- # Always set an accessible label to help the user interact with the component.
8
- class ClipboardCopyComponent < Ariadne::Component
9
- DEFAULT_TAG = :"clipboard-copy"
10
-
11
- DEFAULT_CLASSES = LinkComponent::DEFAULT_ACTIONABLE_CLASSES
12
-
13
- DATA_CONTROLLER = "clipboard-copy-component"
14
- DATA_ACTION = "click->clipboard-copy-component#copy"
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
-
33
- # @example Default
34
- # <%= render(Ariadne::ClipboardCopyComponent.new(value: "Text to copy", aria_label: "Copy text to the system clipboard" )) %>
35
- #
36
- # @example With text instead of icons
37
- # <%= render(Ariadne::ClipboardCopyComponent.new(value: "Text to copy", aria_label: "Copy text to the system clipboard" )) do %>
38
- # Click to copy!
39
- # <% end %>
40
- #
41
- # @example Copying from an element
42
- # <%= render(Ariadne::ClipboardCopyComponent.new(for_id: "blob-path", aria_label: "Copy text to the system clipboard" )) %>
43
- # <div id="blob-path">src/index.js</div>
44
- #
45
- # @param tag [Symbol, String] The rendered tag name
46
- # @param classes [String] <%= link_to_classes_docs %>
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.
49
- # @param aria_label [String] Text for accessibility. Can also be passed in as part of `attributes`, but it must be present.
50
- # @param attributes [Hash] <%= link_to_attributes_docs %>
51
- def initialize(tag: DEFAULT_TAG, value: "", for_id: nil, aria_label: "", classes: "", attributes: {})
52
- @attributes = attributes
53
- @value = value
54
-
55
- @attributes[:"aria-label"] = aria_label
56
- @attributes[:for] ||= for_id
57
- @id = @attributes[:id]
58
-
59
- validate!
60
-
61
- @classes = merge_class_names(DEFAULT_CLASSES, classes)
62
- @tag = check_incoming_tag(DEFAULT_TAG, tag)
63
- @attributes[:value] = value if value.present?
64
- end
65
-
66
- private def validate!
67
- validate_aria_label!
68
- raise ArgumentError, "Must provide either `value` or `for`" if @value.blank? && @attributes[:for].blank?
69
- raise ArgumentError, "Must provide only `value` or `for`, not both" if @value.present? && @attributes[:for].present?
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
89
- end
90
- end
@@ -1,37 +0,0 @@
1
- <%= render(Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes)) do %>
2
- <%= render(Ariadne::TabContainerComponent.new(sr_label: @sr_label)) do |tab_container| %>
3
- <%= tab_container.with_tab(id: public_tab.id, selected: public_tab.selected, classes: public_tab.classes, attributes: public_tab.attributes) do |tab| %>
4
- <% tab.with_text { @public_tab_text } %>
5
- <% tab.with_panel(attributes: {:"data-public" => true}) do %>
6
- <%= ariadne_form_with(url: @url, method: @method, classes: @classes, attributes: @attributes) do |comment_box| %>
7
- <% @hidden_fields.each do |name, value| %>
8
- <%= hidden_field_tag name, value %>
9
- <% end %>
10
- <div class="ariadne-overflow-hidden ariadne-border ariadne-border-slate-300 ariadne-shadow-sm">
11
- <%= hidden_field_tag 'message_is_public', true %>
12
- <%= render(Ariadne::RichTextAreaComponent.new(name: :message_public_bodytext, sr_label: "Select reply type", attributes: { required: true})) %>
13
- <% comment_box.submit { @submit } %>
14
- </div>
15
- <div class="ariadne-py-2 ariadne-flex ariadne-justify-end">
16
- <%= public_submit %>
17
- </div>
18
- <% end %>
19
- <% end %>
20
- <% end %>
21
- <%= tab_container.with_tab(id: internal_tab.id, selected: internal_tab.selected, classes: internal_tab.classes, attributes: internal_tab.attributes) do |tab| %>
22
- <% tab.with_text { @internal_tab_text } %>
23
- <% tab.with_panel do %>
24
- <%= ariadne_form_with(url: @url, method: @method, classes: @classes, attributes: @attributes) do |comment_box| %>
25
- <div class="ariadne-overflow-hidden ariadne-border ariadne-border-gray-300 ariadne-shadow-sm">
26
- <%= hidden_field_tag 'message_is_public', false %>
27
- <%= render(Ariadne::RichTextAreaComponent.new(name: :message_internal_bodytext, sr_label: "Select reply type", attributes: { required: true})) %>
28
- <% comment_box.submit { @submit } %>
29
- </div>
30
- <div class="ariadne-py-2 ariadne-flex ariadne-justify-end">
31
- <%= internal_submit %>
32
- </div>
33
- <% end %>
34
- <% end %>
35
- <% end %>
36
- <% end %>
37
- <% end %>
@@ -1,71 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ariadne
4
- # Defines a submittable form for adding comments to a conversation.
5
- #
6
- #
7
- # @accessibility This component requires you to pass in a `sr_label`
8
- # attribute, which will be used to label the tabs for screen readers.
9
- class CommentComponent < Ariadne::Component
10
- DEFAULT_TAG = :div
11
- TAG_OPTIONS = [DEFAULT_TAG].freeze
12
-
13
- DEFAULT_CLASSES = "ariadne-border-gray-300 ariadne-border ariadne-shadow ariadne-py-5 ariadne-px-5 ariadne-rounded-md "
14
-
15
- renders_one :public_tab, lambda { |selected: false, text:, classes: "", attributes: {}|
16
- attributes[:"data-public"] = true
17
- @tab_idx += 1
18
- id = attributes.fetch(:id, "public-tab-#{@tab_idx}")
19
- @public_tab_text = text
20
-
21
- Ariadne::TabComponent.new(selected: selected, classes: classes, id: id, with_panel: true, attributes: attributes)
22
- }
23
-
24
- renders_one :public_submit, lambda { |classes: "", attributes: {}|
25
- Ariadne::ButtonComponent.new(type: Ariadne::BaseButton::TYPE_SUBMIT, scheme: Ariadne::ButtonComponent::DEFAULT_SCHEME, classes: classes, attributes: attributes)
26
- }
27
-
28
- renders_one :internal_tab, lambda { |selected: false, text:, classes: "", attributes: {}|
29
- attributes[:"data-public"] = false
30
- @tab_idx += 1
31
- id = attributes.fetch(:id, "internal-tab-#{@tab_idx}")
32
- @internal_tab_text = text
33
-
34
- Ariadne::TabComponent.new(selected: selected, classes: classes, id: id, with_panel: true, attributes: attributes)
35
- }
36
-
37
- renders_one :internal_submit, lambda { |classes: "", attributes: {}|
38
- Ariadne::ButtonComponent.new(type: Ariadne::BaseButton::TYPE_SUBMIT, scheme: Ariadne::ButtonComponent::DEFAULT_SCHEME, classes: classes, attributes: attributes)
39
- }
40
-
41
- # @example Default
42
- #
43
- # <%= render(Ariadne::CommentComponent.new(url: "/messages", method: :post, sr_label: "Select delivery time")) do |comment| %>
44
- # <% comment.with_public_tab(selected: true, text: "Reply to sender") %>
45
- # <% comment.with_public_submit { "Send" } %>
46
- # <% comment.with_internal_tab(text: "Internal comment") %>
47
- # <% comment.with_internal_submit { "Send" } %>
48
- # <% end %>
49
- #
50
- # @param url [String] The URL to take action against.
51
- # @param method [String] The method to use when submitting the form.
52
- # @param sr_label [String] A label to introduce these tabs for screen readers.
53
- # @param hidden_fields [[String]] An array of arrays of additional (hidden) fields to add to the form.
54
- # @param classes [String] <%= link_to_classes_docs %>
55
- # @param attributes [Hash] <%= link_to_attributes_docs %>
56
- def initialize(url:, method: :post, sr_label:, hidden_fields: [], classes: "", attributes: {})
57
- @tag = DEFAULT_TAG
58
- @classes = merge_class_names(
59
- DEFAULT_CLASSES,
60
- classes,
61
- )
62
- @url = url
63
- @method = method
64
- @sr_label = sr_label
65
-
66
- @tab_idx = -1
67
- @hidden_fields = hidden_fields
68
- @attributes = attributes
69
- end
70
- end
71
- end
@@ -1,127 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "view_component/version"
4
-
5
- require "heroicons_helper"
6
-
7
- module Ariadne
8
- # @private
9
- class Component < ViewComponent::Base
10
- include ClassNameHelper
11
- include FetchOrFallbackHelper
12
- include ViewHelper
13
- include Status::Dsl
14
- include Audited::Dsl
15
- include LoggerHelper
16
- include Ariadne::ActionViewExtensions::FormHelper
17
-
18
- BASE_WRAPPER_CLASSES = "ariadne-flex ariadne-flex-col ariadne-h-screen ariadne-justify-between"
19
- BASE_MAIN_CLASSES = "ariadne-flex-auto"
20
-
21
- # this is defined here for the Tailwind parser to pick up; it can be useful
22
- # in situations where hiddenness is defined by a kwarg, eg `selected: false`
23
- BASE_HIDDEN_CLASS = "ariadne-hidden"
24
-
25
- INVALID_ARIA_LABEL_TAGS = [:div, :span, :p].freeze
26
-
27
- private def raise_on_invalid_options?
28
- Rails.application.config.ariadne_view_components.raise_on_invalid_options
29
- end
30
-
31
- private def raise_on_invalid_aria?
32
- Rails.application.config.ariadne_view_components.raise_on_invalid_aria
33
- end
34
-
35
- private def deprecated_component_warning(new_class: nil, version: nil)
36
- return if silence_deprecations?
37
-
38
- message = "#{self.class.name} is deprecated"
39
- message += " and will be removed in v#{version}." if version
40
- message += " Use #{new_class.name} instead." if new_class
41
-
42
- ActiveSupport::Deprecation.warn(message)
43
- end
44
-
45
- private def aria(val, attributes)
46
- attributes[:"aria-#{val}"] || attributes.dig(:aria, val.to_sym)
47
- end
48
-
49
- private def validate_aria_label!
50
- aria_label = aria("label", @attributes)
51
- raise ArgumentError, "`aria-label` is required." if aria_label.blank?
52
- end
53
-
54
- private def check_denylist(denylist = [], attributes = {})
55
- if should_raise_error?
56
-
57
- # Convert denylist from:
58
- # { [:p, :pt] => "message" } to:
59
- # { p: "message", pt: "message" }
60
- unpacked_denylist =
61
- denylist.each_with_object({}) do |(keys, value), memo|
62
- keys.each { |key| memo[key] = value }
63
- end
64
-
65
- violations = unpacked_denylist.keys & attributes.keys
66
-
67
- if violations.any?
68
- message = "Found #{violations.count} #{"violation".pluralize(violations)}:"
69
- violations.each do |violation|
70
- message += "\n The #{violation} argument is not allowed here. #{unpacked_denylist[violation]}"
71
- end
72
-
73
- raise(ArgumentError, message)
74
- end
75
- end
76
-
77
- attributes
78
- end
79
-
80
- private def validate_attributes(tag:, denylist_name: :attributes_denylist, attributes: {})
81
- deny_single_argument(:class, "Use `classes` instead.", attributes)
82
-
83
- if (denylist = attributes[denylist_name])
84
- check_denylist(denylist, attributes)
85
-
86
- # Remove :attributes_denylist key and any denied keys from attributes
87
- attributes.except!(denylist_name)
88
- attributes.except!(*denylist.keys.flatten)
89
- end
90
-
91
- deny_aria_label(tag: tag, attributes: attributes)
92
-
93
- attributes
94
- end
95
-
96
- private def deny_single_argument(key, help_text, attributes)
97
- raise ArgumentError, "`#{key}` is an invalid argument. #{help_text}" \
98
- if should_raise_error? && attributes.key?(key)
99
-
100
- attributes.except!(key)
101
- end
102
-
103
- private def deny_aria_label(tag:, attributes:)
104
- return attributes.except!(:skip_aria_label_check) if attributes[:skip_aria_label_check]
105
- return if attributes[:role]
106
- return unless INVALID_ARIA_LABEL_TAGS.include?(tag)
107
-
108
- deny_aria_key(
109
- :label,
110
- "Don't use `aria-label` on `#{tag}` elements. See https://www.tpgi.com/short-note-on-aria-label-aria-labelledby-and-aria-describedby/",
111
- attributes,
112
- )
113
- end
114
-
115
- private def deny_aria_key(key, help_text, attributes)
116
- raise ArgumentError, help_text if should_raise_aria_error? && aria(key, attributes)
117
- end
118
-
119
- private def should_raise_error?
120
- raise_on_invalid_options? && !ENV["ARIADNE_WARNINGS_DISABLED"]
121
- end
122
-
123
- private def should_raise_aria_error?
124
- raise_on_invalid_aria? && !ENV["ARIADNE_WARNINGS_DISABLED"]
125
- end
126
- end
127
- end
@@ -1,3 +0,0 @@
1
- <%= render Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes) do |component| %>
2
- <%= content %>
3
- <% end %>
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ariadne
4
- # The container wraps the majority, if not all, of the content on a page.
5
- class ContainerComponent < Ariadne::Component
6
- DEFAULT_CLASSES = "ariadne-px-4 sm:ariadne-px-6 lg:ariadne-px-8"
7
-
8
- # @example Default
9
- # <%= render(Ariadne::ContainerComponent.new) do |container| %>
10
- # <%= render(Ariadne::ButtonComponent.new) { "Click me!" } %>
11
- # <% end %>
12
- #
13
- # @param classes [String] <%= link_to_classes_docs %>
14
- # @param attributes [Hash] <%= link_to_attributes_docs %>
15
- def initialize(classes: "", attributes: {})
16
- @tag = :div
17
- @classes = merge_class_names(
18
- DEFAULT_CLASSES,
19
- classes,
20
- )
21
-
22
- @attributes = attributes
23
- end
24
- end
25
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ariadne
4
- #
5
- # Use `Content` as a helper to render content passed to a slot without adding any tags.
6
- #
7
- class Content < Ariadne::Component
8
- def call
9
- content
10
- end
11
- end
12
- end
@@ -1,100 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ariadne
4
- # Use `CounterComponent` to add a count to navigational elements and buttons.
5
- #
6
- # @accessibility
7
- # Always use `CounterComponent` with adjacent text that provides supplementary information regarding what the count is for. For instance, `Counter`
8
- # should be accompanied with text such as `issues` or `pull requests`.
9
- #
10
- class CounterComponent < Ariadne::Component
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
- # @example Default
14
- # <%= render(Ariadne::CounterComponent.new(count: 25)) %>
15
- #
16
- # @example Schemes
17
- # <%= render(Ariadne::CounterComponent.new(count: 25)) %>
18
- # <%= render(Ariadne::CounterComponent.new(count: 25)) %>
19
- #
20
- # @param tag [Symbol, String] The rendered tag name
21
- # @param classes [String] <%= link_to_classes_docs %>
22
- # @param count [Integer, Float::INFINITY, nil] The number to be displayed (e.x. # of issues, pull requests)
23
- # @param limit [Integer, nil] Maximum value to display. Pass `nil` for no limit. (e.x. if `count` == 6,000 and `limit` == 5000, counter will display "5,000+")
24
- # @param hide_if_zero [Boolean] If true, a `hidden` attribute is added to the counter if `count` is zero.
25
- # @param text [String] Text to display instead of count.
26
- # @param round [Boolean] Whether to apply rounding logic to value.
27
- # @param attributes [Hash] <%= link_to_attributes_docs %>
28
- def initialize(
29
- tag: :span,
30
- count: 0,
31
- limit: 9_000,
32
- hide_if_zero: false,
33
- text: "",
34
- round: false,
35
- classes: "",
36
- attributes: {}
37
- )
38
- @count = count
39
- @limit = limit
40
- @hide_if_zero = hide_if_zero
41
- @text = text
42
- @round = round
43
- @attributes = attributes
44
-
45
- @has_limit = !@limit.nil?
46
-
47
- @tag = check_incoming_tag(:span, tag)
48
-
49
- @attributes[:title] = title
50
-
51
- @classes = merge_class_names(
52
- DEFAULT_CLASSES,
53
- classes,
54
- )
55
- @attributes[:hidden] = true if count == 0 && hide_if_zero
56
- end
57
-
58
- def call
59
- render(Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes)) { value }
60
- end
61
-
62
- private def title
63
- if @text.present?
64
- @text
65
- elsif @count.nil?
66
- "Not available"
67
- elsif @count == Float::INFINITY
68
- "Infinity"
69
- else
70
- count = @count.to_i
71
- str = number_with_delimiter(@has_limit ? [count, @limit].min : count)
72
- str += "+" if @has_limit && count > @limit
73
- str
74
- end
75
- end
76
-
77
- private def value
78
- if @text.present?
79
- @text
80
- elsif @count.nil?
81
- "" # CSS will hide it
82
- elsif @count == Float::INFINITY
83
- "∞"
84
- else
85
- if @round
86
- count = @has_limit ? [@count.to_i, @limit].min : @count.to_i
87
- precision = count.between?(100_000, 999_999) ? 0 : 1
88
- units = { thousand: "k", million: "m", billion: "b" }
89
- str = number_to_human(count, precision: precision, significant: false, units: units, format: "%n%u")
90
- else
91
- @count = @count.to_i
92
- str = number_with_delimiter(@has_limit ? [@count, @limit].min : @count)
93
- end
94
-
95
- str += "+" if @has_limit && @count.to_i > @limit
96
- str
97
- end
98
- end
99
- end
100
- end
@@ -1,4 +0,0 @@
1
- <%= render Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes) do |component| %>
2
- <%= summary %>
3
- <%= body %>
4
- <% end %>
@@ -1,81 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Ariadne
4
- # Use `DetailsComponent` to reveal content after clicking a button.
5
- class DetailsComponent < Ariadne::Component
6
- DEFAULT_TAG = :details
7
- DEFAULT_BODY_TAG = :div
8
-
9
- VALID_BODY_TAGS = [:ul, :"details-menu", :"details-dialog", DEFAULT_BODY_TAG].freeze
10
-
11
- NO_OVERLAY = :none
12
- OVERLAY_MAPPINGS = {
13
- NO_OVERLAY => "",
14
- :default => "",
15
- }.freeze
16
-
17
- # Use the Summary as a trigger to reveal the content.
18
- #
19
- # @param button [Boolean] (true) Whether to render the Summary as a button or not.
20
- # @param classes [String] <%= link_to_classes_docs %>
21
- # @param attributes [Hash] <%= link_to_attributes_docs %>
22
- renders_one :summary, lambda { |button: true, classes: "", attributes: {}|
23
- tag = :summary
24
- attributes[:role] = "button"
25
- if button
26
- Ariadne::ButtonComponent.new(tag: tag, classes: classes, attributes: attributes)
27
- else
28
- Ariadne::BaseComponent.new(tag: tag, classes: classes, attributes: attributes)
29
- end
30
- }
31
-
32
- DEFAULT_BODY_CLASSES = "ariadne-absolute ariadne-mt-2 ariadne-w-56 ariadne-divide-y ariadne-divide-gray-100 ariadne-rounded-md ariadne-shadow-lg ariadne-ring-1 ariadne-ring-black ariadne-ring-opacity-5 focus:ariadne-outline-none"
33
- # Use the Body slot as the main content to be shown when triggered by the Summary.
34
- #
35
- # @param tag [Symbol] The tag to use for the body/ <%= one_of(Ariadne::DetailsComponent::VALID_BODY_TAGS) %>
36
- # @param classes [String] <%= link_to_classes_docs %>
37
- # @param attributes [Hash] <%= link_to_attributes_docs %>
38
- renders_one :body, lambda { |tag: DEFAULT_BODY_TAG, classes: "", attributes: {}|
39
- tag = fetch_or_raise(VALID_BODY_TAGS, tag)
40
- actual_classes = merge_class_names(DEFAULT_BODY_CLASSES, classes)
41
-
42
- Ariadne::BaseComponent.new(tag: tag, classes: actual_classes, attributes: attributes)
43
- }
44
-
45
- DEFAULT_CLASSES = ""
46
-
47
- # @example Default
48
- #
49
- # <%= render Ariadne::DetailsComponent.new do |c| %>
50
- # <% c.with_summary do %>
51
- # Summary
52
- # <% end %>
53
- # <% c.with_body do %>
54
- # Body
55
- # <% end %>
56
- # <% end %>
57
- #
58
- # @param overlay [Symbol] Dictates the type of overlay to render with. <%= one_of(Ariadne::DetailsComponent::OVERLAY_MAPPINGS.keys) %>
59
- # @param reset [Boolean] If set to true, it will remove the default caret and remove style from the summary element
60
- # @param classes [String] <%= link_to_classes_docs %>
61
- # @param attributes [Hash] <%= link_to_attributes_docs %>
62
- def initialize(overlay: NO_OVERLAY, reset: true, classes: "", attributes: {})
63
- @tag = DEFAULT_TAG
64
- @reset = reset
65
-
66
- @classes = merge_class_names(
67
- DEFAULT_CLASSES,
68
- classes,
69
- @reset ? "ariadne__details-reset" : "",
70
- )
71
-
72
- @attributes = attributes
73
-
74
- @overlay = fetch_or_raise(OVERLAY_MAPPINGS.keys, overlay)
75
- end
76
-
77
- def render?
78
- summary? && body?
79
- end
80
- end
81
- end
@@ -1,20 +0,0 @@
1
- <%= render Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes) do |component| %>
2
- <%= header %>
3
- <% if list? %>
4
- <ul>
5
- <% items.each do |item| %>
6
- <% if item.divider? %>
7
- <%= item %>
8
- <% else %>
9
- <li>
10
- <%= item %>
11
- </li>
12
- <% end %>
13
- <% end %>
14
- </ul>
15
- <% else %>
16
- <% items.each do |item| %>
17
- <%= item %>
18
- <% end %>
19
- <% end %>
20
- <% end %>