ariadne_view_components 0.0.2 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +8 -7
- data/app/assets/builds/ariadne_view_components.css +1874 -0
- data/app/assets/config/manifest.js +2 -0
- data/app/assets/javascripts/ariadne.d.ts +1 -0
- data/app/assets/javascripts/ariadne_view_components.js +1 -1
- data/app/assets/javascripts/ariadne_view_components.js.map +1 -1
- data/app/assets/javascripts/clipboard-copy-component.d.ts +4 -0
- data/app/assets/javascripts/slideover-component.d.ts +9 -0
- data/app/assets/javascripts/time_ago_component.d.ts +1 -0
- data/app/assets/javascripts/tooltip-component.d.ts +24 -0
- data/app/assets/stylesheets/application.ariadne_view_components.css +5 -0
- data/app/assets/stylesheets/tooltip-component.css +37 -0
- data/app/components/ariadne/ariadne.d.ts +1 -0
- data/app/components/ariadne/ariadne.js +9 -0
- data/app/components/ariadne/ariadne.ts +8 -9
- data/app/components/ariadne/base_button.rb +10 -8
- data/app/components/ariadne/blankslate_component.html.erb +26 -0
- data/app/components/ariadne/blankslate_component.rb +151 -0
- data/app/components/ariadne/body_component.rb +30 -0
- data/app/components/ariadne/button_component.html.erb +1 -1
- data/app/components/ariadne/button_component.rb +9 -11
- data/app/components/ariadne/clipboard-copy-component.d.ts +4 -0
- data/app/components/ariadne/clipboard-copy-component.js +18 -0
- data/app/components/ariadne/{clipboard_copy_component.ts → clipboard-copy-component.ts} +0 -0
- data/app/components/ariadne/clipboard_copy_component.d.ts +4 -0
- data/app/components/ariadne/clipboard_copy_component.html.erb +2 -2
- data/app/components/ariadne/clipboard_copy_component.js +18 -0
- data/app/components/ariadne/clipboard_copy_component.rb +45 -5
- data/app/components/ariadne/comment_component.html.erb +25 -0
- data/app/components/ariadne/comment_component.rb +45 -0
- data/app/components/ariadne/component.rb +6 -1
- data/app/components/ariadne/container_component.html.erb +3 -0
- data/app/components/ariadne/container_component.rb +25 -0
- data/app/components/ariadne/flash_component.rb +9 -9
- data/app/components/ariadne/flex_component.rb +51 -0
- data/app/components/ariadne/footer_component.html.erb +7 -0
- data/app/components/ariadne/footer_component.rb +23 -0
- data/app/components/ariadne/grid_component.html.erb +26 -0
- data/app/components/ariadne/grid_component.rb +66 -0
- data/app/components/ariadne/header_component.html.erb +29 -0
- data/app/components/ariadne/header_component.rb +114 -0
- data/app/components/ariadne/heading_component.rb +3 -3
- data/app/components/ariadne/heroicon_component.html.erb +2 -5
- data/app/components/ariadne/heroicon_component.rb +20 -7
- data/app/components/ariadne/image_component.rb +5 -3
- data/app/components/ariadne/inline_flex_component.html.erb +5 -0
- data/app/components/ariadne/inline_flex_component.rb +65 -0
- data/app/components/ariadne/link_component.rb +65 -0
- data/app/components/ariadne/list_component.html.erb +15 -0
- data/app/components/ariadne/list_component.rb +67 -0
- data/app/components/ariadne/main_component.rb +32 -0
- data/app/components/ariadne/pill_component.html.erb +3 -0
- data/app/components/ariadne/pill_component.rb +30 -0
- data/app/components/ariadne/slideover-component.d.ts +9 -0
- data/app/components/ariadne/slideover-component.js +20 -0
- data/app/components/ariadne/slideover-component.ts +26 -0
- data/app/components/ariadne/slideover_component.d.ts +9 -0
- data/app/components/ariadne/slideover_component.html.erb +11 -0
- data/app/components/ariadne/slideover_component.js +19 -0
- data/app/components/ariadne/slideover_component.rb +81 -0
- data/app/components/ariadne/time_ago_component.d.ts +1 -0
- data/app/components/ariadne/time_ago_component.js +1 -0
- data/app/components/ariadne/time_ago_component.rb +56 -0
- data/app/components/ariadne/time_ago_component.ts +1 -0
- data/app/components/ariadne/timeline_component.html.erb +19 -0
- data/app/components/ariadne/timeline_component.rb +34 -0
- data/app/components/ariadne/tooltip-component.d.ts +24 -0
- data/app/components/ariadne/tooltip-component.js +42 -0
- data/app/components/ariadne/tooltip-component.ts +57 -0
- data/app/components/ariadne/tooltip_component.html.erb +4 -0
- data/app/components/ariadne/tooltip_component.rb +34 -31
- data/app/lib/ariadne/action_view_extensions/form_helper.rb +23 -0
- data/app/lib/ariadne/form_builder.rb +71 -0
- data/lib/ariadne/classify.rb +4 -90
- data/lib/ariadne/view_components/engine.rb +6 -0
- data/lib/ariadne/view_components/version.rb +1 -1
- data/lib/ariadne/view_components.rb +31 -29
- data/lib/rubocop/cop/ariadne/ariadne_heroicon.rb +2 -2
- data/lib/tasks/docs.rake +52 -58
- data/static/arguments.yml +290 -17
- data/static/audited_at.json +18 -0
- data/static/classes.yml +189 -1
- data/static/constants.json +173 -30
- data/static/statuses.json +18 -0
- metadata +77 -9
- data/app/assets/stylesheets/application.tailwind.css +0 -3
- data/lib/tasks/tailwind.rake +0 -31
@@ -0,0 +1,9 @@
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
|
+
export default class SlideoverComponent extends Controller {
|
3
|
+
static targets: string[];
|
4
|
+
readonly expandableTarget: HTMLDivElement;
|
5
|
+
readonly expandWrapperTarget: HTMLDivElement;
|
6
|
+
readonly slidePanelTargets: [HTMLDivElement];
|
7
|
+
readonly buttonWrapperTarget: HTMLDivElement;
|
8
|
+
toggle(): void;
|
9
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
import '@github/time-elements';
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
|
+
import type { Instance, Placement } from '@popperjs/core';
|
3
|
+
export default class TooltipComponent extends Controller {
|
4
|
+
static targets: string[];
|
5
|
+
readonly triggerTarget: HTMLElement;
|
6
|
+
readonly tooltipTarget: HTMLElement;
|
7
|
+
static values: {
|
8
|
+
placement: {
|
9
|
+
type: StringConstructor;
|
10
|
+
default: string;
|
11
|
+
};
|
12
|
+
offset: {
|
13
|
+
type: ArrayConstructor;
|
14
|
+
default: number[];
|
15
|
+
};
|
16
|
+
};
|
17
|
+
readonly placementValue: Placement;
|
18
|
+
readonly offsetValue: Array<number>;
|
19
|
+
popperInstance: Instance;
|
20
|
+
connect(): void;
|
21
|
+
disconnect(): void;
|
22
|
+
show(): void;
|
23
|
+
hide(): void;
|
24
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
.tooltip-arrow,
|
2
|
+
.tooltip-arrow::before {
|
3
|
+
position: absolute;
|
4
|
+
width: 8px;
|
5
|
+
height: 8px;
|
6
|
+
background: inherit;
|
7
|
+
}
|
8
|
+
|
9
|
+
.tooltip-arrow {
|
10
|
+
visibility: hidden;
|
11
|
+
}
|
12
|
+
|
13
|
+
tooltip[data-tooltip-show] .tooltip-arrow::before {
|
14
|
+
visibility: visible;
|
15
|
+
content: '';
|
16
|
+
transform: rotate(45deg);
|
17
|
+
}
|
18
|
+
|
19
|
+
tooltip[data-popper-placement^='top'][data-tooltip-show] > .tooltip-arrow {
|
20
|
+
bottom: -4px;
|
21
|
+
}
|
22
|
+
|
23
|
+
tooltip[data-popper-placement^='bottom'] > .tooltip-arrow {
|
24
|
+
top: -4px;
|
25
|
+
}
|
26
|
+
|
27
|
+
tooltip[data-popper-placement^='left'] > .tooltip-arrow {
|
28
|
+
right: -4px;
|
29
|
+
}
|
30
|
+
|
31
|
+
tooltip[data-popper-placement^='right'] > .tooltip-arrow {
|
32
|
+
left: -4px;
|
33
|
+
}
|
34
|
+
|
35
|
+
tooltip[data-tooltip-show] {
|
36
|
+
display: block;
|
37
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
import './time_ago_component';
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { Application } from '@hotwired/stimulus';
|
2
|
+
import ClipboardCopyComponent from './clipboard-copy-component';
|
3
|
+
import SlideoverComponent from './slideover-component';
|
4
|
+
import TooltipComponent from './tooltip-component';
|
5
|
+
import './time_ago_component';
|
6
|
+
const application = Application.start();
|
7
|
+
application.register('clipboard-copy-component', ClipboardCopyComponent);
|
8
|
+
application.register('slideover-component', SlideoverComponent);
|
9
|
+
application.register('tooltip-component', TooltipComponent);
|
@@ -1,14 +1,13 @@
|
|
1
1
|
import {Application} from '@hotwired/stimulus'
|
2
2
|
|
3
|
-
import ClipboardCopyComponent from './
|
3
|
+
import ClipboardCopyComponent from './clipboard-copy-component'
|
4
|
+
import SlideoverComponent from './slideover-component'
|
5
|
+
import TooltipComponent from './tooltip-component'
|
4
6
|
|
5
|
-
|
6
|
-
// import './tab_container_component'
|
7
|
-
// import './time_ago_component'
|
8
|
-
// import './local_time'
|
9
|
-
// import './image_crop'
|
10
|
-
// import './dropdown'
|
11
|
-
// import './alpha/tool-tip-element'
|
7
|
+
import './time_ago_component'
|
12
8
|
|
13
9
|
const application = Application.start()
|
14
|
-
|
10
|
+
|
11
|
+
application.register('clipboard-copy-component', ClipboardCopyComponent)
|
12
|
+
application.register('slideover-component', SlideoverComponent)
|
13
|
+
application.register('tooltip-component', TooltipComponent)
|
@@ -7,26 +7,28 @@ module Ariadne
|
|
7
7
|
TAG_OPTIONS = [DEFAULT_TAG, :a, :summary].freeze
|
8
8
|
|
9
9
|
DEFAULT_TYPE = :button
|
10
|
-
|
10
|
+
TYPE_SUBMIT = :submit
|
11
|
+
TYPE_OPTIONS = [DEFAULT_TYPE, :reset, TYPE_SUBMIT].freeze
|
11
12
|
|
13
|
+
# TODO: dedupe the classes
|
12
14
|
SIZE_CLASS_MAPPINGS = {
|
13
15
|
xs: "inline-flex items-center px-2.5 py-1.5 text-xs font-medium rounded",
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
sm: "inline-flex items-center px-3 py-2 text-sm leading-4 font-medium rounded-m",
|
17
|
+
md: "inline-flex items-center px-4 py-2 text-sm font-medium rounded-md",
|
18
|
+
lg: "inline-flex items-center px-4 py-2 text-base font-medium rounded-md",
|
17
19
|
xl: "inline-flex items-center px-6 py-3 text-base font-medium rounded-md",
|
18
20
|
}.freeze
|
19
21
|
VALID_SIZES = SIZE_CLASS_MAPPINGS.keys.freeze
|
20
22
|
|
21
23
|
DEFAULT_CLASSES = "inline-flex items-center px-4 py-2 text-sm border border-gray-300 shadow-sm text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
|
22
24
|
|
23
|
-
DEFAULT_SIZE = :
|
25
|
+
DEFAULT_SIZE = :md
|
24
26
|
|
25
27
|
# @example Setting the size
|
26
28
|
# <%= render(Ariadne::BaseButton.new(size: :xs)) { "I am an extra small button!" } %>
|
27
|
-
# <%= render(Ariadne::BaseButton.new(size: :
|
28
|
-
# <%= render(Ariadne::BaseButton.new(size: :
|
29
|
-
# <%= render(Ariadne::BaseButton.new(size: :
|
29
|
+
# <%= render(Ariadne::BaseButton.new(size: :sm)) { "I am a small button!" } %>
|
30
|
+
# <%= render(Ariadne::BaseButton.new(size: :md)) { "I am a medium button!" } %>
|
31
|
+
# <%= render(Ariadne::BaseButton.new(size: :lg)) { "I am a large button!" } %>
|
30
32
|
# <%= render(Ariadne::BaseButton.new(size: :xl)) { "I am an extra large button!" } %>
|
31
33
|
#
|
32
34
|
# @param tag [Symbol] <%= one_of(Ariadne::BaseButton::TAG_OPTIONS) %>
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<div class="bg-white">
|
2
|
+
<%= render Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes) do %>
|
3
|
+
<% if icon.present? %>
|
4
|
+
<%= icon %>
|
5
|
+
<% elsif image.present? %>
|
6
|
+
<%= image %>
|
7
|
+
<% end %>
|
8
|
+
<%= heading %>
|
9
|
+
<% if description.present? %>
|
10
|
+
<%= description %>
|
11
|
+
<% end %>
|
12
|
+
<%= content %>
|
13
|
+
<div class="mt-8 flex justify-center">
|
14
|
+
<% if primary_action.present? %>
|
15
|
+
<div class="inline-flex rounded-md shadow">
|
16
|
+
<%= primary_action %>
|
17
|
+
</div>
|
18
|
+
<% end %>
|
19
|
+
<% if secondary_action.present? %>
|
20
|
+
<div class="ml-3 inline-flex">
|
21
|
+
<%= secondary_action %>
|
22
|
+
</div>
|
23
|
+
<% end %>
|
24
|
+
</div>
|
25
|
+
<% end %>
|
26
|
+
</div>
|
@@ -0,0 +1,151 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ariadne
|
4
|
+
# Use `Blankslate` when there is a lack of content within a page or section. Use as placeholder to tell users why something isn't there.
|
5
|
+
#
|
6
|
+
# @accessibility
|
7
|
+
# - The blankslate uses a semantic heading that must be set at the appropriate level based on the hierarchy of the page.
|
8
|
+
# - All blankslate visuals have been programmed as decorative images, using `aria-hidden=”true”` and `img alt=””`, which will hide the visual from screen reader users.
|
9
|
+
# - The blankslate supports a primary and secondary action. Both actions have been built as semantic links with primary and secondary styling.
|
10
|
+
# - `secondary_action` text should be meaningful out of context and clearly describe the destination. Avoid using vague text like, "Learn more" or "Click here".
|
11
|
+
class BlankslateComponent < Ariadne::Component
|
12
|
+
DEFAULT_TAG = :div
|
13
|
+
TAG_OPTIONS = [DEFAULT_TAG].freeze
|
14
|
+
|
15
|
+
DEFAULT_CLASSES = "max-w-7xl mx-auto text-center py-12 px-4 sm:px-6 lg:py-16 lg:px-8"
|
16
|
+
|
17
|
+
# Optional visual that renders an <%= link_to_component(Ariadne::HeroiconComponent) %>.
|
18
|
+
#
|
19
|
+
# @param tag [Symbol, String] The rendered tag name
|
20
|
+
# @param icon [String] Name of <%= link_to_heroicons %> to use.
|
21
|
+
# @param size [Symbol] <%= one_of(Ariadne::HeroiconComponent::SIZE_MAPPINGS, sort: false) %>
|
22
|
+
# @param variant [String] <%= one_of(HeroiconsHelper::Icon::VARIANTS, sort: false) %>
|
23
|
+
# @param classes [String] <%= link_to_classes_docs %>
|
24
|
+
# @param attributes [Hash] Same arguments as <%= link_to_component(Ariadne::HeroiconComponent) %>.
|
25
|
+
renders_one :icon, lambda { |tag: :svg, icon:, size: Ariadne::HeroiconComponent::SIZE_DEFAULT, variant: HeroiconsHelper::Icon::VARIANT_SOLID, classes: "", attributes: {}|
|
26
|
+
@icon = icon
|
27
|
+
@variant = variant
|
28
|
+
tag = check_incoming_tag(:svg, tag)
|
29
|
+
Ariadne::HeroiconComponent.new(tag: tag, icon: icon, size: size, variant: variant, classes: classes, attributes: attributes)
|
30
|
+
}
|
31
|
+
|
32
|
+
# Optional visual that renders an <%= link_to_component(Ariadne::ImageComponent) %>.
|
33
|
+
#
|
34
|
+
# @param tag [Symbol, String] The rendered tag name
|
35
|
+
# @param src [String] The source url of the image.
|
36
|
+
# @param alt [String] Specifies an alternate text for the image.
|
37
|
+
# @param lazy [Boolean] Whether or not to lazily load the image.
|
38
|
+
# @param classes [String] <%= link_to_classes_docs %>
|
39
|
+
# @param attributes [Hash] <%= link_to_attributes_docs %>
|
40
|
+
DEFAULT_IMAGE_SIZE = 56
|
41
|
+
renders_one :image, lambda { |tag: Ariadne::ImageComponent::DEFAULT_TAG, src:, alt:, lazy: false, classes: "", attributes: {}|
|
42
|
+
attributes[:height] = DEFAULT_IMAGE_SIZE
|
43
|
+
attributes[:width] = DEFAULT_IMAGE_SIZE
|
44
|
+
|
45
|
+
Ariadne::ImageComponent.new(tag: tag, src: src, alt: alt, lazy: lazy, classes: classes, attributes: attributes)
|
46
|
+
}
|
47
|
+
|
48
|
+
# Required heading.
|
49
|
+
#
|
50
|
+
# @param tag [Symbol, String] <%= one_of(Ariadne::HeadingComponent::TAG_OPTIONS) %>
|
51
|
+
# @param classes [String] <%= link_to_classes_docs %>
|
52
|
+
# @param attributes [Hash] Same arguments as <%= link_to_component(Ariadne::HeroiconComponent) %>.
|
53
|
+
DEFAULT_HEADING_CLASSES = "text-3xl font-extrabold tracking-tight text-gray-900 sm:text-4xl"
|
54
|
+
renders_one :heading, lambda { |tag: :h1, classes: "", attributes: {}|
|
55
|
+
actual_classes = class_names(DEFAULT_HEADING_CLASSES, classes)
|
56
|
+
|
57
|
+
Ariadne::HeadingComponent.new(tag: tag, classes: actual_classes, attributes: attributes)
|
58
|
+
}
|
59
|
+
|
60
|
+
# Optional description.
|
61
|
+
#
|
62
|
+
# - The description should always be informative and actionable.
|
63
|
+
# - Don't use phrases like "You can".
|
64
|
+
#
|
65
|
+
# @param tag [Symbol, String] The rendered tag name
|
66
|
+
# @param classes [String] <%= link_to_classes_docs %>
|
67
|
+
# @param attributes [Hash] Same arguments as <%= link_to_component(Ariadne::HeroiconComponent) %>.
|
68
|
+
renders_one :description, lambda { |tag: :p, classes: "", attributes: {}|
|
69
|
+
actual_tag = check_incoming_tag(:p, tag)
|
70
|
+
|
71
|
+
Ariadne::BaseComponent.new(tag: actual_tag, classes: classes, attributes: attributes)
|
72
|
+
}
|
73
|
+
|
74
|
+
# Optional primary action
|
75
|
+
#
|
76
|
+
# The `primary_action` slot renders an anchor link which is visually styled as a button to provide more emphasis to the
|
77
|
+
# Blankslate's primary action.
|
78
|
+
#
|
79
|
+
# @param href [String] URL to be used for the primary action.
|
80
|
+
# @param classes [String] <%= link_to_classes_docs %>
|
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: :md, scheme: :default, classes: "", attributes: {}|
|
83
|
+
attributes[:href] = href
|
84
|
+
attributes[:method] = method
|
85
|
+
|
86
|
+
Ariadne::ButtonComponent.new(tag: tag,
|
87
|
+
type: Ariadne::BaseButton::DEFAULT_TYPE,
|
88
|
+
scheme: scheme,
|
89
|
+
size: size,
|
90
|
+
classes: classes,
|
91
|
+
attributes: attributes)
|
92
|
+
}
|
93
|
+
|
94
|
+
# Optional secondary action
|
95
|
+
#
|
96
|
+
# The `secondary_action` slot renders a normal anchor link, which can be used to redirect the user to additional information
|
97
|
+
# (e.g. Help documentation).
|
98
|
+
#
|
99
|
+
# @param href [String] URL to be used for the secondary action.
|
100
|
+
# @param classes [String] <%= link_to_classes_docs %>
|
101
|
+
# @param attributes [Hash] Same arguments as <%= link_to_component(Ariadne::HeroiconComponent) %>.
|
102
|
+
renders_one :secondary_action, lambda { |href:, classes: "", attributes: {}|
|
103
|
+
attributes[:href] = href
|
104
|
+
|
105
|
+
Ariadne::LinkComponent.new(href: href, classes: classes, attributes: attributes)
|
106
|
+
}
|
107
|
+
|
108
|
+
# @example Basic
|
109
|
+
# <%= render Ariadne::BlankslateComponent.new do |c| %>
|
110
|
+
# <% c.heading(tag: :h2).with_content("heading") %>
|
111
|
+
# <% c.description { "Description"} %>
|
112
|
+
# <% end %>
|
113
|
+
#
|
114
|
+
# @example Icon
|
115
|
+
# @description
|
116
|
+
# Add an `icon` to give additional context. Refer to the [Octicons](https://primer.style/octicons/) documentation to choose an icon.
|
117
|
+
# @code
|
118
|
+
# <%= render Ariadne::BlankslateComponent.new do |c| %>
|
119
|
+
# <% c.icon(icon: :globe) %>
|
120
|
+
# <% c.heading(tag: :h2).with_content("heading") %>
|
121
|
+
# <% c.description { "Description"} %>
|
122
|
+
# <% end %>
|
123
|
+
#
|
124
|
+
# @example Using an image
|
125
|
+
# @description
|
126
|
+
# Add an `image` to give context that an Octicon couldn't.
|
127
|
+
# @code
|
128
|
+
# <%= render Ariadne::BlankslateComponent.new do |c| %>
|
129
|
+
# <% c.image(src: "https://github.githubassets.com/images/modules/site/features/security-icon.svg", alt: "Security - secure vault") %>
|
130
|
+
# <% c.heading(tag: :h2).with_content("heading") %>
|
131
|
+
# <% end %>
|
132
|
+
#
|
133
|
+
# @param tag [Symbol, String] The rendered tag name
|
134
|
+
# @param classes [String] <%= link_to_classes_docs %>
|
135
|
+
# @param attributes [Hash] <%= link_to_attributes_docs %>
|
136
|
+
def initialize(tag: DEFAULT_TAG, classes: "", attributes: {})
|
137
|
+
@tag = check_incoming_tag(DEFAULT_TAG, tag)
|
138
|
+
@classes = class_names(DEFAULT_CLASSES, classes)
|
139
|
+
@attributes = attributes
|
140
|
+
end
|
141
|
+
|
142
|
+
def render?
|
143
|
+
heading.present?
|
144
|
+
end
|
145
|
+
|
146
|
+
def wrapper
|
147
|
+
yield
|
148
|
+
nil # returning `yield` causes a double render
|
149
|
+
end
|
150
|
+
end
|
151
|
+
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 = "flex flex-col 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
|
@@ -1,4 +1,4 @@
|
|
1
|
-
<%= render Ariadne::BaseButton.new(tag: @tag, type:
|
1
|
+
<%= render Ariadne::BaseButton.new(tag: @tag, type: @type, classes: @classes, attributes: @attributes) do -%>
|
2
2
|
<%= icon %><%= trimmed_content %><%= counter %>
|
3
3
|
<%= tooltip %>
|
4
4
|
<% end -%>
|
@@ -9,7 +9,7 @@ module Ariadne
|
|
9
9
|
LINK_SCHEME = :link
|
10
10
|
|
11
11
|
SCHEME_CLASS_MAPPINGS = {
|
12
|
-
default: "text-
|
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
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
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
15
|
warning: "text-yellow-800 bg-yellow-50 hover:bg-yellow-100 border-yellow-300 focus:ring-offset-yellow-50 focus:ring-yellow-600",
|
@@ -58,18 +58,13 @@ module Ariadne
|
|
58
58
|
#
|
59
59
|
# @param tag [Symbol, String] The rendered tag name
|
60
60
|
# @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::
|
61
|
+
# @param direction [Symbol] <%= one_of(Ariadne::TooltipComponent::VALID_PLACEMENTS) %>
|
62
62
|
# @param classes [String] <%= link_to_classes_docs %>
|
63
63
|
# @param attributes [Hash] Same arguments as <%= link_to_component(Ariadne::TooltipComponent) %>.
|
64
|
-
renders_one :tooltip, lambda { |tag:
|
64
|
+
renders_one :tooltip, lambda { |tag: Ariadne::TooltipComponent::DEFAULT_TAG, text:, direction: Ariadne::TooltipComponent::DEFAULT_PLACEMENT, type: Ariadne::TooltipComponent::TYPE_DEFAULT, classes: "", attributes: {}|
|
65
65
|
raise ArgumentError, "Buttons with a tooltip must have a unique `id` set on the `Button`." if @id.blank?
|
66
66
|
|
67
|
-
|
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)
|
67
|
+
Ariadne::TooltipComponent.new(for_id: @id, tag: tag, text: text, direction: direction, type: type, classes: classes, attributes: attributes)
|
73
68
|
}
|
74
69
|
|
75
70
|
# @example Schemes
|
@@ -81,8 +76,8 @@ module Ariadne
|
|
81
76
|
# <%= render(Ariadne::ButtonComponent.new(scheme: :danger)) { "Danger" } %>
|
82
77
|
#
|
83
78
|
# @example Sizes
|
84
|
-
# <%= render(Ariadne::ButtonComponent.new(size: :
|
85
|
-
# <%= render(Ariadne::ButtonComponent.new(size: :
|
79
|
+
# <%= render(Ariadne::ButtonComponent.new(size: :sm)) { "Small" } %>
|
80
|
+
# <%= render(Ariadne::ButtonComponent.new(size: :md)) { "Medium" } %>
|
86
81
|
#
|
87
82
|
# @example With leading visual
|
88
83
|
# <%= render(Ariadne::ButtonComponent.new) do |c| %>
|
@@ -113,6 +108,7 @@ module Ariadne
|
|
113
108
|
# <% end %>
|
114
109
|
#
|
115
110
|
# @param tag [Symbol] <%= one_of(Ariadne::BaseButton::TAG_OPTIONS) %>
|
111
|
+
# @param type [Symbol] <%= one_of(Ariadne::BaseButton::TYPE_OPTIONS) %>
|
116
112
|
# @param scheme [Symbol] <%= one_of(Ariadne::ButtonComponent::VALID_SCHEMES) %>
|
117
113
|
# @param size [Symbol] <%= one_of(Ariadne::BaseButton::VALID_SIZES) %>
|
118
114
|
# @param type [Symbol] <%= one_of(Ariadne::BaseButton::TYPE_OPTIONS) %>
|
@@ -120,12 +116,14 @@ module Ariadne
|
|
120
116
|
# @param attributes [Hash] <%= link_to_attributes_docs %>
|
121
117
|
def initialize(
|
122
118
|
tag: Ariadne::BaseButton::DEFAULT_TAG,
|
119
|
+
type: Ariadne::BaseButton::DEFAULT_TYPE,
|
123
120
|
scheme: DEFAULT_SCHEME,
|
124
121
|
size: BaseButton::DEFAULT_SIZE,
|
125
122
|
classes: "",
|
126
123
|
attributes: {}
|
127
124
|
)
|
128
125
|
@tag = tag
|
126
|
+
@type = type
|
129
127
|
@scheme = scheme
|
130
128
|
|
131
129
|
@attributes = attributes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
|
+
export default class ClipboardCopyComponent extends Controller {
|
3
|
+
copy() {
|
4
|
+
const value = this.element.attributes.getNamedItem('value');
|
5
|
+
const forNode = this.element.attributes.getNamedItem('for');
|
6
|
+
if (value) {
|
7
|
+
navigator.clipboard.writeText(value.value);
|
8
|
+
}
|
9
|
+
else if (forNode) {
|
10
|
+
const node = document.getElementById(forNode.value);
|
11
|
+
navigator.clipboard.writeText((node === null || node === void 0 ? void 0 : node.textContent) || '');
|
12
|
+
}
|
13
|
+
else {
|
14
|
+
// just copy inner text
|
15
|
+
navigator.clipboard.writeText(this.element.textContent || '');
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
|
-
<%= render Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes.merge(
|
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
5
|
<%= render Ariadne::HeroiconComponent.new(icon: :duplicate, variant: HeroiconsHelper::Icon::VARIANT_OUTLINE) %>
|
6
6
|
<%= render Ariadne::HeroiconComponent.new(icon: :check, variant: HeroiconsHelper::Icon::VARIANT_OUTLINE, attributes: { color: :success, style: "display: none;" }) %>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { Controller } from '@hotwired/stimulus';
|
2
|
+
export default class ClipboardCopyComponent extends Controller {
|
3
|
+
copy() {
|
4
|
+
const value = this.element.attributes.getNamedItem('value');
|
5
|
+
const forNode = this.element.attributes.getNamedItem('for');
|
6
|
+
if (value) {
|
7
|
+
navigator.clipboard.writeText(value.value);
|
8
|
+
}
|
9
|
+
else if (forNode) {
|
10
|
+
const node = document.getElementById(forNode.value);
|
11
|
+
navigator.clipboard.writeText((node === null || node === void 0 ? void 0 : node.textContent) || '');
|
12
|
+
}
|
13
|
+
else {
|
14
|
+
// just copy inner text
|
15
|
+
navigator.clipboard.writeText(this.element.textContent || '');
|
16
|
+
}
|
17
|
+
}
|
18
|
+
}
|
@@ -8,8 +8,27 @@ module Ariadne
|
|
8
8
|
class ClipboardCopyComponent < Ariadne::Component
|
9
9
|
DEFAULT_TAG = :"clipboard-copy"
|
10
10
|
|
11
|
-
|
12
|
-
|
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
|
+
}
|
13
32
|
|
14
33
|
# @example Default
|
15
34
|
# <%= render(Ariadne::ClipboardCopyComponent.new(value: "Text to copy", aria_label: "Copy text to the system clipboard" )) %>
|
@@ -20,23 +39,26 @@ module Ariadne
|
|
20
39
|
# <% end %>
|
21
40
|
#
|
22
41
|
# @example Copying from an element
|
23
|
-
# <%= render(Ariadne::ClipboardCopyComponent.new(
|
42
|
+
# <%= render(Ariadne::ClipboardCopyComponent.new(for_id: "blob-path", aria_label: "Copy text to the system clipboard" )) %>
|
24
43
|
# <div id="blob-path">src/index.js</div>
|
25
44
|
#
|
26
45
|
# @param tag [Symbol, String] The rendered tag name
|
27
46
|
# @param classes [String] <%= link_to_classes_docs %>
|
28
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.
|
29
49
|
# @param aria_label [String] Text for accessibility. Can also be passed in as part of `attributes`, but it must be present.
|
30
50
|
# @param attributes [Hash] <%= link_to_attributes_docs %>
|
31
|
-
def initialize(tag: DEFAULT_TAG, value: "", aria_label: "", classes: "", attributes: {})
|
51
|
+
def initialize(tag: DEFAULT_TAG, value: "", for_id: nil, aria_label: "", classes: "", attributes: {})
|
32
52
|
@attributes = attributes
|
33
53
|
@value = value
|
34
54
|
|
35
55
|
@attributes[:"aria-label"] = aria_label
|
56
|
+
@attributes[:for] ||= for_id
|
57
|
+
@id = @attributes[:id]
|
36
58
|
|
37
59
|
validate!
|
38
60
|
|
39
|
-
@classes = classes
|
61
|
+
@classes = class_names(DEFAULT_CLASSES, classes)
|
40
62
|
@tag = check_incoming_tag(DEFAULT_TAG, tag)
|
41
63
|
@attributes[:value] = value if value.present?
|
42
64
|
end
|
@@ -46,5 +68,23 @@ module Ariadne
|
|
46
68
|
raise ArgumentError, "Must provide either `value` or `for`" if @value.blank? && @attributes[:for].blank?
|
47
69
|
raise ArgumentError, "Must provide only `value` or `for`, not both" if @value.present? && @attributes[:for].present?
|
48
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
|
49
89
|
end
|
50
90
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<%= render Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes) do |comment| %>
|
2
|
+
<div>
|
3
|
+
<div class="flex items-center" aria-orientation="horizontal" role="tablist">
|
4
|
+
<% tabs.each do |tab| %>
|
5
|
+
<%= tab %>
|
6
|
+
<% end %>
|
7
|
+
</div>
|
8
|
+
<div class="mt-2">
|
9
|
+
<div id="tabs-1-panel-1" class="p-0.5 -m-0.5 rounded-lg" aria-labelledby="tabs-1-tab-1" role="tabpanel" tabindex="0">
|
10
|
+
<label for="comment" class="sr-only">Comment</label>
|
11
|
+
<div>
|
12
|
+
<textarea rows="5" name="comment" id="comment" class="shadow-sm focus:ring-indigo-500 focus:border-indigo-500 block w-full sm:text-sm border-gray-300 rounded-md" placeholder="Add your comment..."></textarea>
|
13
|
+
</div>
|
14
|
+
</div>
|
15
|
+
<div id="tabs-1-panel-2" class="p-0.5 -m-0.5 rounded-lg" aria-labelledby="tabs-1-tab-2" role="tabpanel" tabindex="0">
|
16
|
+
<div class="border-b">
|
17
|
+
<div class="mx-px mt-px px-3 pt-2 pb-12 text-sm leading-5 text-gray-800">Preview content will render here.</div>
|
18
|
+
</div>
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
</div>
|
22
|
+
<div class="mt-2 flex justify-end">
|
23
|
+
<%= submit %>
|
24
|
+
</div>
|
25
|
+
<% end %>
|