ariadne_view_components 0.0.43-x86_64-linux → 0.0.44-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/app/components/ariadne/ariadne-form.d.ts +22 -0
  4. data/app/components/ariadne/ariadne-form.js +85 -0
  5. data/app/components/ariadne/ariadne-form.ts +96 -0
  6. data/app/components/ariadne/ariadne.d.ts +2 -0
  7. data/app/components/ariadne/ariadne.js +16 -0
  8. data/app/components/ariadne/ariadne.ts +21 -0
  9. data/app/components/ariadne/avatar_component.rb +81 -0
  10. data/app/components/ariadne/avatar_stack_component/avatar_stack_component.html.erb +12 -0
  11. data/app/components/ariadne/avatar_stack_component.rb +75 -0
  12. data/app/components/ariadne/base_button.rb +70 -0
  13. data/app/components/ariadne/base_component.rb +37 -0
  14. data/app/components/ariadne/blankslate_component/blankslate_component.html.erb +26 -0
  15. data/app/components/ariadne/blankslate_component.rb +148 -0
  16. data/app/components/ariadne/body_component.rb +30 -0
  17. data/app/components/ariadne/button_component/button_component.html.erb +4 -0
  18. data/app/components/ariadne/button_component.rb +165 -0
  19. data/app/components/ariadne/clipboard_copy_component/clipboard-copy-component.d.ts +4 -0
  20. data/app/components/ariadne/clipboard_copy_component/clipboard-copy-component.js +18 -0
  21. data/app/components/ariadne/clipboard_copy_component/clipboard-copy-component.ts +19 -0
  22. data/app/components/ariadne/clipboard_copy_component/clipboard_copy_component.html.erb +9 -0
  23. data/app/components/ariadne/clipboard_copy_component.rb +90 -0
  24. data/app/components/ariadne/comment_component/comment_component.html.erb +37 -0
  25. data/app/components/ariadne/comment_component.rb +71 -0
  26. data/app/components/ariadne/component.rb +127 -0
  27. data/app/components/ariadne/container_component/container_component.html.erb +3 -0
  28. data/app/components/ariadne/container_component.rb +25 -0
  29. data/app/components/ariadne/content.rb +12 -0
  30. data/app/components/ariadne/counter_component.rb +100 -0
  31. data/app/components/ariadne/details_component/details_component.html.erb +4 -0
  32. data/app/components/ariadne/details_component.rb +81 -0
  33. data/app/components/ariadne/dropdown/menu_component.html.erb +20 -0
  34. data/app/components/ariadne/dropdown/menu_component.rb +101 -0
  35. data/app/components/ariadne/dropdown/menu_component.ts +1 -0
  36. data/app/components/ariadne/dropdown_component/dropdown_component.html.erb +8 -0
  37. data/app/components/ariadne/dropdown_component.rb +172 -0
  38. data/app/components/ariadne/flash_component/flash_component.html.erb +31 -0
  39. data/app/components/ariadne/flash_component.rb +128 -0
  40. data/app/components/ariadne/flex_component/flex_component.html.erb +5 -0
  41. data/app/components/ariadne/flex_component.rb +56 -0
  42. data/app/components/ariadne/footer_component/footer_component.html.erb +7 -0
  43. data/app/components/ariadne/footer_component.rb +23 -0
  44. data/app/components/ariadne/grid_component/grid_component.html.erb +26 -0
  45. data/app/components/ariadne/grid_component.rb +67 -0
  46. data/app/components/ariadne/header_component/header_component.html.erb +29 -0
  47. data/app/components/ariadne/header_component.rb +111 -0
  48. data/app/components/ariadne/heading_component.rb +49 -0
  49. data/app/components/ariadne/heroicon_component/heroicon_component.html.erb +4 -0
  50. data/app/components/ariadne/heroicon_component.rb +166 -0
  51. data/app/components/ariadne/image_component.rb +53 -0
  52. data/app/components/ariadne/inline_flex_component/inline_flex_component.html.erb +6 -0
  53. data/app/components/ariadne/inline_flex_component.rb +72 -0
  54. data/app/components/ariadne/link_component.rb +65 -0
  55. data/app/components/ariadne/list_component/list_component.html.erb +6 -0
  56. data/app/components/ariadne/list_component.rb +70 -0
  57. data/app/components/ariadne/narrow_container_component/narrow_container_component.html.erb +3 -0
  58. data/app/components/ariadne/narrow_container_component.rb +30 -0
  59. data/app/components/ariadne/panel_bar_component/panel_bar_component.html.erb +20 -0
  60. data/app/components/ariadne/panel_bar_component.rb +80 -0
  61. data/app/components/ariadne/pill_component/pill_component.html.erb +3 -0
  62. data/app/components/ariadne/pill_component.rb +44 -0
  63. data/app/components/ariadne/rich_text_area_component/rich-text-area-component.d.ts +6 -0
  64. data/app/components/ariadne/rich_text_area_component/rich-text-area-component.js +38 -0
  65. data/app/components/ariadne/rich_text_area_component/rich-text-area-component.ts +47 -0
  66. data/app/components/ariadne/rich_text_area_component/rich_text_area_component.html.erb +6 -0
  67. data/app/components/ariadne/rich_text_area_component.rb +35 -0
  68. data/app/components/ariadne/slideover_component/slideover-component.d.ts +9 -0
  69. data/app/components/ariadne/slideover_component/slideover-component.js +11 -0
  70. data/app/components/ariadne/slideover_component/slideover-component.ts +17 -0
  71. data/app/components/ariadne/slideover_component/slideover_component.html.erb +9 -0
  72. data/app/components/ariadne/slideover_component.rb +66 -0
  73. data/app/components/ariadne/tab_component/tab_component.html.erb +3 -0
  74. data/app/components/ariadne/tab_component.rb +98 -0
  75. data/app/components/ariadne/tab_container_component/tab-container-component.d.ts +1 -0
  76. data/app/components/ariadne/tab_container_component/tab-container-component.js +23 -0
  77. data/app/components/ariadne/tab_container_component/tab-container-component.ts +24 -0
  78. data/app/components/ariadne/tab_container_component.erb +10 -0
  79. data/app/components/ariadne/tab_container_component.rb +68 -0
  80. data/app/components/ariadne/tab_nav_component/tab-nav-component.d.ts +9 -0
  81. data/app/components/ariadne/tab_nav_component/tab-nav-component.js +33 -0
  82. data/app/components/ariadne/tab_nav_component/tab-nav-component.ts +34 -0
  83. data/app/components/ariadne/tab_nav_component/tab_nav_component.html.erb +7 -0
  84. data/app/components/ariadne/tab_nav_component.rb +72 -0
  85. data/app/components/ariadne/table_nav_component/table_nav_component.html.erb +52 -0
  86. data/app/components/ariadne/table_nav_component.rb +338 -0
  87. data/app/components/ariadne/text.rb +25 -0
  88. data/app/components/ariadne/time_ago_component/time-ago-component.d.ts +1 -0
  89. data/app/components/ariadne/time_ago_component/time-ago-component.js +1 -0
  90. data/app/components/ariadne/time_ago_component/time-ago-component.ts +1 -0
  91. data/app/components/ariadne/time_ago_component.rb +56 -0
  92. data/app/components/ariadne/timeline_component/timeline_component.html.erb +19 -0
  93. data/app/components/ariadne/timeline_component.rb +34 -0
  94. data/app/components/ariadne/tooltip_component/tooltip-component.d.ts +24 -0
  95. data/app/components/ariadne/tooltip_component/tooltip-component.js +43 -0
  96. data/app/components/ariadne/tooltip_component/tooltip-component.ts +57 -0
  97. data/app/components/ariadne/tooltip_component/tooltip_component.html.erb +4 -0
  98. data/app/components/ariadne/tooltip_component.rb +108 -0
  99. data/lib/ariadne/view_components/engine.rb +0 -22
  100. data/lib/ariadne/view_components/version.rb +1 -1
  101. data/tailwind.config.js +10 -15
  102. metadata +98 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4261f61c7046a8639c29a8704dbf2030b23b7f00ce54e0ab15d3bab66c40cbe1
4
- data.tar.gz: 0d4e1e4f56a960eacd504bf80a85e52d512e28ed9ed24e5603858f0b9a35c332
3
+ metadata.gz: 25f526fcbe94fc0acc726cfbbe0f7ed2a34f72fdcab459e979eedf2a5ab35317
4
+ data.tar.gz: 891bf24d1595018b2251ebcd8b24e873be4323c14b00c878fe4b4d60af6bcd38
5
5
  SHA512:
6
- metadata.gz: 27356ca48cfc853bb8be0a26cdd6c9618450576d3d19a23e3c1f3bde923ca1067050b9ab4e6fb2a79faff5ff4e1cacc4cb4d48d364ffd7559f10570297976bc1
7
- data.tar.gz: 49be04ae9907af51f60614a532c481f2790f5d6da8060f17b3cda04b6986e931ccaf47078a016985d115ca1b932071a0fe4a9c32662f4ac3cd7a0b96591726c1
6
+ metadata.gz: 7bf5e9e3721261388ff74f617b7765a86972f6f9a9402f2ecf7be62ef93a80955fff10bbc5f682a79d6afc39ffb00f88ca4576ec0842740267a4f8ecea73f714
7
+ data.tar.gz: 1e20d90e850f132c000a4351f4bdc32afe854e21759f251c86383b883bcbc49b4a3cfdaeee32d946241b66a7f711cf166ed4d5f7035c87f62479311c0d76449a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [v0.0.43](https://github.com/yettoapp/ariadne/tree/v0.0.43) (2023-05-02)
4
+
5
+ [Full Changelog](https://github.com/yettoapp/ariadne/compare/v0.0.42...v0.0.43)
6
+
3
7
  ## [v0.0.42](https://github.com/yettoapp/ariadne/tree/v0.0.42) (2023-05-02)
4
8
 
5
9
  [Full Changelog](https://github.com/yettoapp/ariadne/compare/v0.0.41...v0.0.42)
@@ -0,0 +1,22 @@
1
+ import { Controller } from '@hotwired/stimulus';
2
+ import type { TemplateResult } from 'lit-html';
3
+ type HTMLFormField = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
4
+ export default class AriadneFormWith extends Controller {
5
+ static targets: string[];
6
+ readonly formFieldTargets: [HTMLFormField];
7
+ connect(): void;
8
+ disconnect(): void;
9
+ onBlur: (event: Event) => void;
10
+ onSubmit: (event: Event) => void;
11
+ validateForm(): boolean;
12
+ validateField(field: HTMLFormField): boolean;
13
+ shouldValidateField(field: HTMLFormField): boolean;
14
+ refreshErrorForInvalidField(field: HTMLFormField, isValid: boolean): void;
15
+ removeExistingErrorMessage(field: HTMLFormField): void;
16
+ showErrorForInvalidField(field: HTMLFormField): void;
17
+ buildFieldErrorHtml(field: HTMLFormField): string;
18
+ get formFields(): HTMLFormField[];
19
+ get firstInvalidField(): HTMLFormField | undefined;
20
+ getRenderString: (data: TemplateResult) => string;
21
+ }
22
+ export {};
@@ -0,0 +1,85 @@
1
+ import { Controller } from '@hotwired/stimulus';
2
+ import { html } from 'lit-html';
3
+ class AriadneFormWith extends Controller {
4
+ constructor() {
5
+ super(...arguments);
6
+ this.onBlur = (event) => {
7
+ this.validateField(event.target);
8
+ };
9
+ this.onSubmit = (event) => {
10
+ var _a;
11
+ if (!this.validateForm()) {
12
+ event.preventDefault();
13
+ (_a = this.firstInvalidField) === null || _a === void 0 ? void 0 : _a.focus();
14
+ }
15
+ };
16
+ this.getRenderString = (data) => {
17
+ const { strings, values } = data;
18
+ const v = [...values, ''].map(e => (typeof e === 'object' ? this.getRenderString(e) : e));
19
+ return strings.reduce((acc, s, i) => acc + s + v[i], '');
20
+ };
21
+ }
22
+ connect() {
23
+ this.element.setAttribute('novalidate', 'true');
24
+ this.element.addEventListener('blur', this.onBlur, true);
25
+ this.element.addEventListener('submit', this.onSubmit);
26
+ this.element.addEventListener('ajax:beforeSend', this.onSubmit);
27
+ }
28
+ disconnect() {
29
+ this.element.removeEventListener('blur', this.onBlur);
30
+ this.element.removeEventListener('submit', this.onSubmit);
31
+ this.element.removeEventListener('ajax:beforeSend', this.onSubmit);
32
+ }
33
+ validateForm() {
34
+ let isValid = true;
35
+ // Not using `find` because we want to validate all the fields
36
+ for (const field of this.formFields) {
37
+ if (this.shouldValidateField(field) && !this.validateField(field))
38
+ isValid = false;
39
+ }
40
+ return isValid;
41
+ }
42
+ validateField(field) {
43
+ if (!this.shouldValidateField(field))
44
+ return true;
45
+ const isValid = field.checkValidity();
46
+ field.classList.toggle('invalid', !isValid);
47
+ this.refreshErrorForInvalidField(field, isValid);
48
+ return isValid;
49
+ }
50
+ shouldValidateField(field) {
51
+ return (!field.disabled &&
52
+ !field.classList.contains('ProseMirror') &&
53
+ !['file', 'reset', 'submit', 'button'].includes(field.type));
54
+ }
55
+ refreshErrorForInvalidField(field, isValid) {
56
+ this.removeExistingErrorMessage(field);
57
+ if (!isValid)
58
+ this.showErrorForInvalidField(field);
59
+ }
60
+ removeExistingErrorMessage(field) {
61
+ var _a;
62
+ const fieldContainer = field.closest('.field');
63
+ if (!fieldContainer)
64
+ return;
65
+ const existingErrorMessageElement = fieldContainer.querySelector('.error');
66
+ if (existingErrorMessageElement) {
67
+ (_a = existingErrorMessageElement === null || existingErrorMessageElement === void 0 ? void 0 : existingErrorMessageElement.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(existingErrorMessageElement);
68
+ }
69
+ }
70
+ showErrorForInvalidField(field) {
71
+ field.insertAdjacentHTML('afterend', this.buildFieldErrorHtml(field));
72
+ }
73
+ buildFieldErrorHtml(field) {
74
+ const data = html `<p class="error">${field.validationMessage}</p>`;
75
+ return this.getRenderString(data);
76
+ }
77
+ get formFields() {
78
+ return Array.from(this.formFieldTargets);
79
+ }
80
+ get firstInvalidField() {
81
+ return this.formFields.find(field => !field.checkValidity());
82
+ }
83
+ }
84
+ AriadneFormWith.targets = ['formField'];
85
+ export default AriadneFormWith;
@@ -0,0 +1,96 @@
1
+ import {Controller} from '@hotwired/stimulus'
2
+ import {html} from 'lit-html'
3
+ import type {TemplateResult} from 'lit-html'
4
+
5
+ type HTMLFormField = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement
6
+
7
+ export default class AriadneFormWith extends Controller {
8
+ static targets = ['formField']
9
+ declare readonly formFieldTargets: [HTMLFormField]
10
+
11
+ connect() {
12
+ this.element.setAttribute('novalidate', 'true')
13
+ this.element.addEventListener('blur', this.onBlur, true)
14
+ this.element.addEventListener('submit', this.onSubmit)
15
+ this.element.addEventListener('ajax:beforeSend', this.onSubmit)
16
+ }
17
+
18
+ disconnect() {
19
+ this.element.removeEventListener('blur', this.onBlur)
20
+ this.element.removeEventListener('submit', this.onSubmit)
21
+ this.element.removeEventListener('ajax:beforeSend', this.onSubmit)
22
+ }
23
+
24
+ onBlur = (event: Event) => {
25
+ this.validateField(event.target as HTMLFormField)
26
+ }
27
+
28
+ onSubmit = (event: Event) => {
29
+ if (!this.validateForm()) {
30
+ event.preventDefault()
31
+ this.firstInvalidField?.focus()
32
+ }
33
+ }
34
+
35
+ validateForm() {
36
+ let isValid = true
37
+ // Not using `find` because we want to validate all the fields
38
+ for (const field of this.formFields) {
39
+ if (this.shouldValidateField(field) && !this.validateField(field)) isValid = false
40
+ }
41
+ return isValid
42
+ }
43
+
44
+ validateField(field: HTMLFormField) {
45
+ if (!this.shouldValidateField(field)) return true
46
+ const isValid = field.checkValidity()
47
+ field.classList.toggle('invalid', !isValid)
48
+ this.refreshErrorForInvalidField(field, isValid)
49
+ return isValid
50
+ }
51
+
52
+ shouldValidateField(field: HTMLFormField) {
53
+ return (
54
+ !field.disabled &&
55
+ !field.classList.contains('ProseMirror') &&
56
+ !['file', 'reset', 'submit', 'button'].includes(field.type)
57
+ )
58
+ }
59
+
60
+ refreshErrorForInvalidField(field: HTMLFormField, isValid: boolean) {
61
+ this.removeExistingErrorMessage(field)
62
+ if (!isValid) this.showErrorForInvalidField(field)
63
+ }
64
+
65
+ removeExistingErrorMessage(field: HTMLFormField) {
66
+ const fieldContainer = field.closest('.field')
67
+ if (!fieldContainer) return
68
+ const existingErrorMessageElement = fieldContainer.querySelector('.error')
69
+ if (existingErrorMessageElement) {
70
+ existingErrorMessageElement?.parentNode?.removeChild(existingErrorMessageElement)
71
+ }
72
+ }
73
+
74
+ showErrorForInvalidField(field: HTMLFormField) {
75
+ field.insertAdjacentHTML('afterend', this.buildFieldErrorHtml(field))
76
+ }
77
+
78
+ buildFieldErrorHtml(field: HTMLFormField) {
79
+ const data = html`<p class="error">${field.validationMessage}</p>`
80
+ return this.getRenderString(data)
81
+ }
82
+
83
+ get formFields(): HTMLFormField[] {
84
+ return Array.from(this.formFieldTargets)
85
+ }
86
+
87
+ get firstInvalidField() {
88
+ return this.formFields.find(field => !field.checkValidity())
89
+ }
90
+
91
+ getRenderString = (data: TemplateResult): string => {
92
+ const {strings, values} = data
93
+ const v = [...values, ''].map(e => (typeof e === 'object' ? this.getRenderString(e as TemplateResult) : e))
94
+ return strings.reduce((acc, s, i) => acc + s + v[i], '')
95
+ }
96
+ }
@@ -0,0 +1,2 @@
1
+ import './tab_container_component/tab-container-component';
2
+ import './time_ago_component/time-ago-component';
@@ -0,0 +1,16 @@
1
+ import { Application } from '@hotwired/stimulus';
2
+ import AriadneForm from './ariadne-form';
3
+ import ClipboardCopyComponent from './clipboard_copy_component/clipboard-copy-component';
4
+ import RichTextAreaComponent from './rich_text_area_component/rich-text-area-component';
5
+ import SlideoverComponent from './slideover_component/slideover-component';
6
+ import TabNavComponent from './tab_nav_component/tab-nav-component';
7
+ import TooltipComponent from './tooltip_component/tooltip-component';
8
+ import './tab_container_component/tab-container-component';
9
+ import './time_ago_component/time-ago-component';
10
+ const application = Application.start();
11
+ application.register('clipboard-copy-component', ClipboardCopyComponent);
12
+ application.register('ariadne-form', AriadneForm);
13
+ application.register('rich-text-area-component', RichTextAreaComponent);
14
+ application.register('slideover-component', SlideoverComponent);
15
+ application.register('tab-nav-component', TabNavComponent);
16
+ application.register('tooltip-component', TooltipComponent);
@@ -0,0 +1,21 @@
1
+ import {Application} from '@hotwired/stimulus'
2
+
3
+ import AriadneForm from './ariadne-form'
4
+
5
+ import ClipboardCopyComponent from './clipboard_copy_component/clipboard-copy-component'
6
+ import RichTextAreaComponent from './rich_text_area_component/rich-text-area-component'
7
+ import SlideoverComponent from './slideover_component/slideover-component'
8
+ import TabNavComponent from './tab_nav_component/tab-nav-component'
9
+ import TooltipComponent from './tooltip_component/tooltip-component'
10
+
11
+ import './tab_container_component/tab-container-component'
12
+ import './time_ago_component/time-ago-component'
13
+
14
+ const application = Application.start()
15
+
16
+ application.register('clipboard-copy-component', ClipboardCopyComponent)
17
+ application.register('ariadne-form', AriadneForm)
18
+ application.register('rich-text-area-component', RichTextAreaComponent)
19
+ application.register('slideover-component', SlideoverComponent)
20
+ application.register('tab-nav-component', TabNavComponent)
21
+ application.register('tooltip-component', TooltipComponent)
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ariadne
4
+ # `Avatar` can be used to represent users.
5
+ #
6
+ # - Use the default circle avatar for users, and the square shape
7
+ # for or any other non-human avatars.
8
+ # - By default, `Avatar` will render a static `<img>`. To have `Avatar` function as a link, set the `href` which will wrap the `<img>` in a `<a>`.
9
+ # - Set `size` to update the height and width of the `Avatar` in pixels.
10
+ # - To stack multiple avatars together, use <%= link_to_component(Ariadne::AvatarStackComponent) %>.
11
+ #
12
+ # @accessibility
13
+ # Images should have text alternatives that describe the information or function represented.
14
+ # If the avatar functions as a link, provide alt text that helps convey the function. For instance,
15
+ # if `Avatar` is a link to a user profile, the alt attribute should be `@kittenuser profile`
16
+ # rather than `@kittenuser`.
17
+ # [Learn more about best image practices (WAI Images)](https://www.w3.org/WAI/tutorials/images/)
18
+ class AvatarComponent < Ariadne::Component
19
+ DEFAULT_SIZE = 20
20
+ SMALL_THRESHOLD = 24
21
+
22
+ DEFAULT_SHAPE = :circle
23
+ SHAPE_OPTIONS = [DEFAULT_SHAPE, :square].freeze
24
+
25
+ SIZE_OPTIONS = [16, DEFAULT_SIZE, SMALL_THRESHOLD, 32, 40, 48, 80].freeze
26
+
27
+ DEFAULT_CLASSES = "ariadne-inline-block ariadne-rounded-full ariadne-ring-2 ariadne-ring-white"
28
+
29
+ # @example Default
30
+ # <%= render(Ariadne::AvatarComponent.new(src: "http://placekitten.com/200/200", alt: "@kittenuser")) %>
31
+ #
32
+ # @example Square
33
+ # <%= render(Ariadne::AvatarComponent.new(src: "http://placekitten.com/200/200", alt: "@kittenuser", shape: :square)) %>
34
+ #
35
+ # @example Link
36
+ # <%= render(Ariadne::AvatarComponent.new(href: "#", src: "http://placekitten.com/200/200", alt: "@kittenuser profile")) %>
37
+ #
38
+ # @example With size
39
+ # <%= render(Ariadne::AvatarComponent.new(src: "http://placekitten.com/200/200", alt: "@kittenuser", size: 16)) %>
40
+ # <%= render(Ariadne::AvatarComponent.new(src: "http://placekitten.com/200/200", alt: "@kittenuser", size: 20)) %>
41
+ # <%= render(Ariadne::AvatarComponent.new(src: "http://placekitten.com/200/200", alt: "@kittenuser", size: 24)) %>
42
+ # <%= render(Ariadne::AvatarComponent.new(src: "http://placekitten.com/200/200", alt: "@kittenuser", size: 32)) %>
43
+ # <%= render(Ariadne::AvatarComponent.new(src: "http://placekitten.com/200/200", alt: "@kittenuser", size: 40)) %>
44
+ # <%= render(Ariadne::AvatarComponent.new(src: "http://placekitten.com/200/200", alt: "@kittenuser", size: 48)) %>
45
+ # <%= render(Ariadne::AvatarComponent.new(src: "http://placekitten.com/200/200", alt: "@kittenuser", size: 80)) %>
46
+ #
47
+ # @param src [String] The source url of the avatar image.
48
+ # @param alt [String] Passed through to alt on img tag.
49
+ # @param size [Integer] <%= one_of(Ariadne::AvatarComponent::SIZE_OPTIONS) %>
50
+ # @param shape [Symbol] Shape of the avatar. <%= one_of(Ariadne::AvatarComponent::SHAPE_OPTIONS) %>
51
+ # @param href [String] The URL to link to. If used, component will be wrapped by an `<a>` tag.
52
+ # @param classes [String] <%= link_to_classes_docs %>
53
+ # @param attributes [Hash] <%= link_to_attributes_docs %>
54
+ def initialize(src:, alt:, size: DEFAULT_SIZE, shape: DEFAULT_SHAPE, href: nil, classes: "", attributes: {})
55
+ @tag = :img
56
+ @href = href
57
+
58
+ @classes = merge_class_names(
59
+ DEFAULT_CLASSES,
60
+ classes,
61
+ )
62
+
63
+ @attributes = attributes
64
+ @attributes[:src] = src
65
+ @attributes[:alt] = alt
66
+ @attributes[:size] = fetch_or_raise(SIZE_OPTIONS, size)
67
+ @attributes[:height] = @attributes[:size]
68
+ @attributes[:width] = @attributes[:size]
69
+ end
70
+
71
+ def call
72
+ if @href
73
+ render(Ariadne::LinkComponent.new(href: @href, classes: @classes, attributes: @attributes)) do
74
+ render(Ariadne::BaseComponent.new(tag: @tag)) { content }
75
+ end
76
+ else
77
+ render(Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes)) { content }
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,12 @@
1
+ <%= render Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes) do %>
2
+ <% if tooltipped? %>
3
+ <%= tooltip.to_s %>
4
+ <% avatars.each_with_index do |avatar, i| %>
5
+ <%= avatar %>
6
+ <% end %>
7
+ <% else %>
8
+ <% avatars.each_with_index do |avatar, i| %>
9
+ <%= avatar %>
10
+ <% end %>
11
+ <% end %>
12
+ <% end %>
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ariadne
4
+ # Use `AvatarStack` to stack multiple avatars together.
5
+ class AvatarStackComponent < Ariadne::Component
6
+ ALIGN_DEFAULT = :left
7
+ ALIGN_OPTIONS = [ALIGN_DEFAULT, :right].freeze
8
+
9
+ DEFAULT_TAG = :div
10
+ TAG_OPTIONS = [DEFAULT_TAG, :span].freeze
11
+
12
+ DEFAULT_BODY_TAG = :div
13
+ BODY_TAG_OPTIONS = [DEFAULT_BODY_TAG, :span].freeze
14
+
15
+ # `Tooltip` that appears on mouse hover or keyboard focus over the stack.
16
+ #
17
+ # @param tag [Symbol, String] The rendered tag name
18
+ # @param text [String] The text content of the tooltip. This should be brief and no longer than a sentence.
19
+ # @param direction [Symbol] <%= one_of(Ariadne::TooltipComponent::VALID_PLACEMENTS) %>
20
+ # @param classes [String] <%= link_to_classes_docs %>
21
+ # @param attributes [Hash] Same arguments as <%= link_to_component(Ariadne::TooltipComponent) %>.
22
+ renders_one :tooltip, lambda { |tag: Ariadne::TooltipComponent::DEFAULT_TAG, text:, direction: Ariadne::TooltipComponent::DEFAULT_PLACEMENT, classes: "", attributes: {}|
23
+ raise ArgumentError, "Avatar stacks with a tooltip must have a unique `id` set." if @id.blank?
24
+
25
+ Ariadne::TooltipComponent.new(for_id: @id, tag: tag, text: text, direction: direction, type: :label, classes: classes, attributes: attributes)
26
+ }
27
+
28
+ # Required list of stacked avatars.
29
+ #
30
+ # @param classes [String] <%= link_to_classes_docs %>
31
+ # @param attributes [Hash] <%= link_to_attributes_docs %>
32
+ renders_many :avatars, "Ariadne::AvatarComponent"
33
+
34
+ DEFAULT_CLASSES = "ariadne-flex ariadne--space-x-2 ariadne-overflow-hidden"
35
+
36
+ # @example Default
37
+ # <%= render(Ariadne::AvatarStackComponent.new) do |c| %>
38
+ # <% c.with_avatar(src: "http://placekitten.com/200/200", alt: "@kittenuser") %>
39
+ # <% c.with_avatar(src: "http://placekitten.com/200/200", alt: "@kittenuser") %>
40
+ # <% c.with_avatar(src: "http://placekitten.com/200/200", alt: "@kittenuser") %>
41
+ # <% end %>
42
+ #
43
+ # @example Align right
44
+ # <%= render(Ariadne::AvatarStackComponent.new(align: :right)) do |c| %>
45
+ # <% c.with_avatar(src: "http://placekitten.com/200/200", alt: "@kittenuser") %>
46
+ # <% c.with_avatar(src: "http://placekitten.com/200/200", alt: "@kittenuser") %>
47
+ # <% c.with_avatar(src: "http://placekitten.com/200/200", alt: "@kittenuser") %>
48
+ # <% end %>
49
+ #
50
+ # @param tag [Symbol] <%= one_of(Ariadne::AvatarStackComponent::TAG_OPTIONS) %>
51
+ # @param align [Symbol] <%= one_of(Ariadne::AvatarStackComponent::ALIGN_OPTIONS) %>
52
+ # @param classes [String] <%= link_to_classes_docs %>
53
+ # @param attributes [Hash] <%= link_to_attributes_docs %>
54
+ def initialize(tag: DEFAULT_TAG, align: ALIGN_DEFAULT, classes: "", attributes: {})
55
+ @tag = check_incoming_tag(DEFAULT_TAG, tag)
56
+ @align = fetch_or_raise(ALIGN_OPTIONS, align)
57
+ @classes = merge_class_names(
58
+ DEFAULT_CLASSES,
59
+ classes,
60
+ )
61
+
62
+ @attributes = attributes
63
+ @attributes[:id] ||= "avatar-stack-#{SecureRandom.hex(4)}"
64
+ @id = @attributes[:id]
65
+ end
66
+
67
+ def render?
68
+ avatars.any?
69
+ end
70
+
71
+ def tooltipped?
72
+ tooltip.present?
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ariadne
4
+ # Use `BaseButton` to render an unstyled `<button>` tag that can be customized.
5
+ class BaseButton < Ariadne::Component
6
+ DEFAULT_TAG = :button
7
+ TAG_OPTIONS = [DEFAULT_TAG, :a, :summary].freeze
8
+
9
+ DEFAULT_TYPE = :button
10
+ TYPE_SUBMIT = :submit
11
+ VALID_TYPES = [DEFAULT_TYPE, :reset, TYPE_SUBMIT].freeze
12
+
13
+ SIZE_CLASS_MAPPINGS = {
14
+ xs: "ariadne-px-2.5 ariadne-py-1.5 ariadne-text-xs ariadne-font-medium ariadne-rounded",
15
+ sm: "ariadne-px-3 ariadne-py-2 ariadne-text-sm ariadne-leading-4 ariadne-font-medium ariadne-rounded-m",
16
+ md: "ariadne-px-4 ariadne-py-2 ariadne-text-sm ariadne-font-medium ariadne-rounded-md",
17
+ lg: "ariadne-px-4 ariadne-py-2 ariadne-text-base ariadne-font-medium ariadne-rounded-md",
18
+ xl: "ariadne-px-6 ariadne-py-3 ariadne-text-base ariadne-font-medium ariadne-rounded-md",
19
+ }.freeze
20
+ VALID_SIZES = SIZE_CLASS_MAPPINGS.keys.freeze
21
+
22
+ DEFAULT_CLASSES = "ariadne-items-center ariadne-border ariadne-shadow-sm focus:ariadne-outline-none focus:ariadne-ring-2 focus:ariadne-ring-offset-2"
23
+ DEFAULT_NUDE_CLASSES = "focus:ariadne-outline-none focus:ariadne-ring-2 focus:ariadne-ring-offset-2"
24
+
25
+ DEFAULT_SIZE = :md
26
+
27
+ # @example Setting the size
28
+ # <%= render(Ariadne::BaseButton.new(size: :xs)) { "I am an extra small button!" } %>
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!" } %>
32
+ # <%= render(Ariadne::BaseButton.new(size: :xl)) { "I am an extra large button!" } %>
33
+ #
34
+ # @param tag [Symbol] <%= one_of(Ariadne::BaseButton::TAG_OPTIONS) %>
35
+ # @param type [Symbol] <%= one_of(Ariadne::BaseButton::VALID_TYPES) %>
36
+ # @param size [Symbol] <%= one_of(Ariadne::BaseButton::VALID_SIZES) %>
37
+ # @param classes [String] <%= link_to_classes_docs %>
38
+ # @param attributes [Hash] <%= link_to_attributes_docs %>
39
+ def initialize(
40
+ tag: DEFAULT_TAG,
41
+ type: DEFAULT_TYPE,
42
+ size: DEFAULT_SIZE,
43
+ classes: "",
44
+ attributes: {}
45
+ )
46
+ @attributes = attributes
47
+ @tag = fetch_or_raise(TAG_OPTIONS, tag)
48
+ @size = fetch_or_raise(VALID_SIZES, size)
49
+
50
+ if button?
51
+ @attributes[:type] = fetch_or_raise(VALID_TYPES, type)
52
+ @classes = merge_class_names(DEFAULT_CLASSES, SIZE_CLASS_MAPPINGS[@size], classes)
53
+ else
54
+ @classes = merge_class_names(DEFAULT_NUDE_CLASSES, SIZE_CLASS_MAPPINGS[@size], classes)
55
+ end
56
+ end
57
+
58
+ def call
59
+ render(Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes)) { content }
60
+ end
61
+
62
+ private def link?(type)
63
+ type == :link
64
+ end
65
+
66
+ private def button?
67
+ @tag == :button
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ariadne
4
+ # All Ariadne ViewComponents accept a standard set of options: classes, which match Tailwind CSS classes, and attributes, which match HTML attributes..
5
+ #
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).
8
+ class BaseComponent < Ariadne::Component
9
+ SELF_CLOSING_TAGS = [:area, :base, :br, :col, :embed, :hr, :img, :input, :link, :meta, :param, :source, :track, :wbr].freeze
10
+
11
+ def initialize(tag:, classes: "", attributes: {})
12
+ @tag = tag
13
+
14
+ @attributes = validate_attributes(tag: tag, attributes: attributes) || {}
15
+ @attributes[:"data-ariadne-view-component"] = true
16
+
17
+ classes = @attributes.fetch(:classes, "") if classes.blank?
18
+ @classes = validate_merge_class_names(classes) || {}
19
+ @content_tag_args = {}
20
+ end
21
+
22
+ def call
23
+ options = @attributes.merge(@classes)
24
+ if SELF_CLOSING_TAGS.include?(@tag)
25
+ tag(@tag, options)
26
+ else
27
+ content_tag(@tag, content, options)
28
+ end
29
+ end
30
+
31
+ private def validate_merge_class_names(classes)
32
+ return if classes.blank?
33
+
34
+ { class: Ariadne::ViewComponents.tailwind_merger.merge(classes) }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ <%= render Ariadne::NarrowContainerComponent.new do %>
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="ariadne-mt-8 ariadne-flex ariadne-justify-center">
14
+ <% if primary_action.present? %>
15
+ <div class="ariadne-inline-flex ariadne-rounded-md shadow">
16
+ <%= primary_action %>
17
+ </div>
18
+ <% end %>
19
+ <% if secondary_action.present? %>
20
+ <div class="ariadne-ml-3 ariadne-inline-flex">
21
+ <%= secondary_action %>
22
+ </div>
23
+ <% end %>
24
+ </div>
25
+ <% end %>
26
+ <% end %>