ariadne_view_components 0.0.13 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/builds/ariadne_view_components.css +2355 -0
  3. data/app/assets/javascripts/ariadne_view_components.js +2 -2
  4. data/app/assets/javascripts/ariadne_view_components.js.map +1 -1
  5. data/app/assets/javascripts/comment-component.d.ts +1 -2
  6. data/app/assets/stylesheets/ariadne_view_components.css +1 -0
  7. data/app/assets/stylesheets/dropdown.css +46 -0
  8. data/app/assets/stylesheets/tooltip-component.css +8 -8
  9. data/app/components/ariadne/ariadne-form-with.d.ts +20 -0
  10. data/app/components/ariadne/ariadne-form-with.js +85 -0
  11. data/app/components/ariadne/ariadne-form.d.ts +22 -0
  12. data/app/components/ariadne/ariadne-form.js +84 -0
  13. data/app/components/ariadne/ariadne.d.ts +2 -0
  14. data/app/components/ariadne/ariadne.js +16 -0
  15. data/app/components/ariadne/ariadne.ts +0 -2
  16. data/app/components/ariadne/avatar_component.rb +81 -0
  17. data/app/components/ariadne/avatar_stack_component.html.erb +12 -0
  18. data/app/components/ariadne/avatar_stack_component.rb +75 -0
  19. data/app/components/ariadne/base_button.rb +13 -4
  20. data/app/components/ariadne/blankslate_component.rb +4 -4
  21. data/app/components/ariadne/body_component.rb +1 -1
  22. data/app/components/ariadne/button_component.html.erb +1 -1
  23. data/app/components/ariadne/button_component.rb +9 -3
  24. data/app/components/ariadne/clipboard-copy-component.d.ts +4 -0
  25. data/app/components/ariadne/clipboard-copy-component.js +18 -0
  26. data/app/components/ariadne/clipboard_copy_component.d.ts +4 -0
  27. data/app/components/ariadne/clipboard_copy_component.js +18 -0
  28. data/app/components/ariadne/comment-component.d.ts +0 -0
  29. data/app/components/ariadne/comment-component.js +33 -0
  30. data/app/components/ariadne/comment-component.ts +32 -50
  31. data/app/components/ariadne/comment_component.html.erb +32 -10
  32. data/app/components/ariadne/comment_component.rb +17 -5
  33. data/app/components/ariadne/component.rb +0 -2
  34. data/app/components/ariadne/details_component.html.erb +4 -0
  35. data/app/components/ariadne/details_component.rb +80 -0
  36. data/app/components/ariadne/dropdown/menu_component.html.erb +20 -0
  37. data/app/components/ariadne/dropdown/menu_component.rb +101 -0
  38. data/app/components/ariadne/dropdown/menu_component.ts +1 -0
  39. data/app/components/ariadne/dropdown_component.html.erb +8 -0
  40. data/app/components/ariadne/dropdown_component.rb +172 -0
  41. data/app/components/ariadne/flex_component.rb +1 -1
  42. data/app/components/ariadne/footer_component.html.erb +1 -1
  43. data/app/components/ariadne/header_component.rb +3 -3
  44. data/app/components/ariadne/heroicon_component.rb +6 -4
  45. data/app/components/ariadne/inline_flex_component.html.erb +1 -0
  46. data/app/components/ariadne/inline_flex_component.rb +8 -1
  47. data/app/components/ariadne/link_component.rb +2 -2
  48. data/app/components/ariadne/list_component.html.erb +2 -9
  49. data/app/components/ariadne/list_component.rb +11 -15
  50. data/app/components/ariadne/pill_component.rb +19 -5
  51. data/app/components/ariadne/rich-text-area-component.d.ts +4 -0
  52. data/app/components/ariadne/rich-text-area-component.js +27 -0
  53. data/app/components/ariadne/rich-text-area-component.ts +4 -4
  54. data/app/components/ariadne/rich_text_area_component.html.erb +1 -1
  55. data/app/components/ariadne/rich_text_area_component.rb +1 -1
  56. data/app/components/ariadne/slideover-component.d.ts +9 -0
  57. data/app/components/ariadne/slideover-component.js +20 -0
  58. data/app/components/ariadne/slideover_component.d.ts +9 -0
  59. data/app/components/ariadne/slideover_component.html.erb +1 -1
  60. data/app/components/ariadne/slideover_component.js +19 -0
  61. data/app/components/ariadne/tab-component.js +1 -0
  62. data/app/components/ariadne/tab-container-component copy.d.ts +1 -0
  63. data/app/components/ariadne/tab-container-component copy.js +23 -0
  64. data/app/components/ariadne/tab-container-component.d.ts +1 -0
  65. data/app/components/ariadne/tab-container-component.js +23 -0
  66. data/app/components/ariadne/tab-container-component.ts +21 -21
  67. data/app/components/ariadne/tab-nav-component.d.ts +9 -0
  68. data/app/components/ariadne/tab-nav-component.js +32 -0
  69. data/app/components/ariadne/tab_component.rb +4 -7
  70. data/app/components/ariadne/tab_container_component.rb +8 -2
  71. data/app/components/ariadne/tab_nav_component.html.erb +1 -1
  72. data/app/components/ariadne/tab_nav_component.rb +1 -1
  73. data/app/components/ariadne/table_nav_component.html.erb +52 -0
  74. data/app/components/ariadne/table_nav_component.rb +338 -0
  75. data/app/components/ariadne/tabs-component.d.ts +0 -0
  76. data/app/components/ariadne/tabs-component.js +1 -0
  77. data/app/components/ariadne/time-ago-component.d.ts +1 -0
  78. data/app/components/ariadne/time-ago-component.js +1 -0
  79. data/app/components/ariadne/time_ago_component.d.ts +1 -0
  80. data/app/components/ariadne/time_ago_component.js +1 -0
  81. data/app/components/ariadne/tooltip-component.d.ts +24 -0
  82. data/app/components/ariadne/tooltip-component.js +42 -0
  83. data/app/components/ariadne/tooltip_component.html.erb +1 -1
  84. data/app/components/ariadne/tooltip_component.rb +4 -4
  85. data/app/lib/ariadne/action_view_extensions/form_helper.rb +21 -7
  86. data/app/lib/ariadne/form_builder.rb +4 -4
  87. data/lib/ariadne/view_components/version.rb +1 -1
  88. data/lib/tasks/docs.rake +19 -4
  89. data/static/arguments.yml +103 -22
  90. data/static/audited_at.json +15 -8
  91. data/static/classes.yml +51 -47
  92. data/static/constants.json +180 -55
  93. data/static/statuses.json +15 -8
  94. data/tailwind.config.js +25 -1
  95. metadata +53 -9
  96. data/app/components/ariadne/main_component.rb +0 -32
  97. data/app/components/ariadne/table_component.html.erb +0 -17
  98. data/app/components/ariadne/table_component.rb +0 -281
@@ -7,7 +7,6 @@ export default class CommentComponent extends Controller {
7
7
  SELECTED_TAB_CLASSES: string[];
8
8
  PUBLIC_BACKGROUND_COLOR: string;
9
9
  INTERNAL_BACKGROUND_COLOR: string;
10
- connect(): void;
11
10
  toggleTab(): void;
12
- toggleBackgrounds(tab: HTMLButtonElement): void;
11
+ toggleBackgrounds(tab: HTMLButtonElement, publicComment: boolean): void;
13
12
  }
@@ -4,3 +4,4 @@
4
4
 
5
5
  @import 'tooltip-component.css';
6
6
  @import 'prosemirror.css';
7
+ @import 'dropdown.css';
@@ -0,0 +1,46 @@
1
+ .ariadne__details-reset > summary {
2
+ list-style: none;
3
+ transition: 80ms cubic-bezier(0.33, 1, 0.68, 1);
4
+ transition-property: color, background-color, box-shadow, border-color;
5
+ }
6
+
7
+ .ariadne__details-reset > summary:focus {
8
+ outline: 2px solid var(--color-accent-fg);
9
+ outline-offset: -2px;
10
+ box-shadow: none;
11
+ }
12
+
13
+ .ariadne__details-reset > summary:focus:not(:focus-visible) {
14
+ outline: solid 1px transparent;
15
+ }
16
+
17
+ .ariadne__details-reset > summary:focus-visible {
18
+ outline: 2px solid var(--color-accent-fg);
19
+ outline-offset: -2px;
20
+ box-shadow: none;
21
+ }
22
+
23
+ .ariadne__details-reset > summary.btn-primary:focus {
24
+ outline: 2px solid var(--color-accent-fg);
25
+ outline-offset: -2px;
26
+ box-shadow: inset 0 0 0 3px var(--color-fg-on-emphasis);
27
+ }
28
+
29
+ .ariadne__details-reset > summary.btn-primary:focus:not(:focus-visible) {
30
+ outline: solid 1px transparent;
31
+ box-shadow: none;
32
+ }
33
+
34
+ .ariadne__details-reset > summary.btn-primary:focus-visible {
35
+ outline: 2px solid var(--color-accent-fg);
36
+ outline-offset: -2px;
37
+ box-shadow: inset 0 0 0 3px var(--color-fg-on-emphasis);
38
+ }
39
+
40
+ .ariadne__details-reset > summary::before {
41
+ display: none;
42
+ }
43
+
44
+ .ariadne__details-reset > summary::-webkit-details-marker {
45
+ display: none;
46
+ }
@@ -1,34 +1,34 @@
1
- .tooltip-arrow,
2
- .tooltip-arrow::before {
1
+ .ariadne-tooltip-arrow,
2
+ .ariadne-tooltip-arrow::before {
3
3
  position: absolute;
4
4
  width: 8px;
5
5
  height: 8px;
6
6
  background: inherit;
7
7
  }
8
8
 
9
- .tooltip-arrow {
9
+ .ariadne-tooltip-arrow {
10
10
  visibility: hidden;
11
11
  }
12
12
 
13
- tooltip[data-tooltip-show] .tooltip-arrow::before {
13
+ tooltip[data-tooltip-show] .ariadne-tooltip-arrow::before {
14
14
  visibility: visible;
15
15
  content: '';
16
16
  transform: rotate(45deg);
17
17
  }
18
18
 
19
- tooltip[data-popper-placement^='top'][data-tooltip-show] > .tooltip-arrow {
19
+ tooltip[data-popper-placement^='top'][data-tooltip-show] > .ariadne-tooltip-arrow {
20
20
  bottom: -4px;
21
21
  }
22
22
 
23
- tooltip[data-popper-placement^='bottom'] > .tooltip-arrow {
23
+ tooltip[data-popper-placement^='bottom'] > .ariadne-tooltip-arrow {
24
24
  top: -4px;
25
25
  }
26
26
 
27
- tooltip[data-popper-placement^='left'] > .tooltip-arrow {
27
+ tooltip[data-popper-placement^='left'] > .ariadne-tooltip-arrow {
28
28
  right: -4px;
29
29
  }
30
30
 
31
- tooltip[data-popper-placement^='right'] > .tooltip-arrow {
31
+ tooltip[data-popper-placement^='right'] > .ariadne-tooltip-arrow {
32
32
  left: -4px;
33
33
  }
34
34
 
@@ -0,0 +1,20 @@
1
+ import { Controller } from '@hotwired/stimulus';
2
+ import { TemplateResult } from 'lit-html';
3
+ declare type HTMLFormField = HTMLInputElement | HTMLButtonElement | HTMLSelectElement | HTMLTextAreaElement;
4
+ export default class AriadneFormWith extends Controller {
5
+ connect(): void;
6
+ disconnect(): void;
7
+ onBlur: (event: Event) => void;
8
+ onSubmit: (event: Event) => void;
9
+ validateForm(): boolean;
10
+ validateField(field: HTMLFormField): boolean;
11
+ shouldValidateField(field: HTMLFormField): boolean;
12
+ refreshErrorForInvalidField(field: HTMLFormField, isValid: boolean): void;
13
+ removeExistingErrorMessage(field: HTMLFormField): void;
14
+ showErrorForInvalidField(field: HTMLFormField): void;
15
+ buildFieldErrorHtml(field: HTMLFormField): string;
16
+ get formFields(): HTMLFormField[];
17
+ get firstInvalidField(): HTMLFormField | undefined;
18
+ getRenderString: (data: TemplateResult) => string;
19
+ }
20
+ export {};
@@ -0,0 +1,85 @@
1
+ import { Controller } from '@hotwired/stimulus';
2
+ import { html } from 'lit-html';
3
+ export default 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 && !['file', 'reset', 'submit', 'button'].includes(field.type);
52
+ }
53
+ refreshErrorForInvalidField(field, isValid) {
54
+ this.removeExistingErrorMessage(field);
55
+ if (!isValid)
56
+ this.showErrorForInvalidField(field);
57
+ }
58
+ removeExistingErrorMessage(field) {
59
+ var _a;
60
+ const fieldContainer = field.closest('.field');
61
+ if (!fieldContainer)
62
+ return;
63
+ const existingErrorMessageElement = fieldContainer.querySelector('.error');
64
+ if (existingErrorMessageElement) {
65
+ (_a = existingErrorMessageElement === null || existingErrorMessageElement === void 0 ? void 0 : existingErrorMessageElement.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(existingErrorMessageElement);
66
+ }
67
+ }
68
+ showErrorForInvalidField(field) {
69
+ field.insertAdjacentHTML('afterend', this.buildFieldErrorHtml(field));
70
+ }
71
+ buildFieldErrorHtml(field) {
72
+ const data = html `<p class="error">${field.validationMessage}</p>`;
73
+ return this.getRenderString(data);
74
+ }
75
+ get formFields() {
76
+ return Array.from(this.element.children).filter(node => {
77
+ const data = node.attributes.getNamedItem('data-ariadne-form-field');
78
+ if ((data === null || data === void 0 ? void 0 : data.value) === 'true')
79
+ return true;
80
+ });
81
+ }
82
+ get firstInvalidField() {
83
+ return this.formFields.find(field => !field.checkValidity());
84
+ }
85
+ }
@@ -0,0 +1,22 @@
1
+ import { Controller } from '@hotwired/stimulus';
2
+ import type { TemplateResult } from 'lit-html';
3
+ declare 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,84 @@
1
+ import { Controller } from '@hotwired/stimulus';
2
+ import { html } from 'lit-html';
3
+ export default 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'];
@@ -0,0 +1,2 @@
1
+ import './tab-container-component';
2
+ import './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';
4
+ import RichTextAreaComponent from './rich-text-area-component';
5
+ import SlideoverComponent from './slideover-component';
6
+ import TabNavComponent from './tab-nav-component';
7
+ import TooltipComponent from './tooltip-component';
8
+ import './tab-container-component';
9
+ import './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);
@@ -3,7 +3,6 @@ import {Application} from '@hotwired/stimulus'
3
3
  import AriadneForm from './ariadne-form'
4
4
 
5
5
  import ClipboardCopyComponent from './clipboard-copy-component'
6
- import CommentComponent from './comment-component'
7
6
  import RichTextAreaComponent from './rich-text-area-component'
8
7
  import SlideoverComponent from './slideover-component'
9
8
  import TabNavComponent from './tab-nav-component'
@@ -16,7 +15,6 @@ const application = Application.start()
16
15
 
17
16
  application.register('clipboard-copy-component', ClipboardCopyComponent)
18
17
  application.register('ariadne-form', AriadneForm)
19
- application.register('comment-component', CommentComponent)
20
18
  application.register('rich-text-area-component', RichTextAreaComponent)
21
19
  application.register('slideover-component', SlideoverComponent)
22
20
  application.register('tab-nav-component', TabNavComponent)
@@ -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 = 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.avatar(src: "http://placekitten.com/200/200", alt: "@kittenuser") %>
39
+ # <% c.avatar(src: "http://placekitten.com/200/200", alt: "@kittenuser") %>
40
+ # <% c.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.avatar(src: "http://placekitten.com/200/200", alt: "@kittenuser") %>
46
+ # <% c.avatar(src: "http://placekitten.com/200/200", alt: "@kittenuser") %>
47
+ # <% c.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 = 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
@@ -8,7 +8,7 @@ module Ariadne
8
8
 
9
9
  DEFAULT_TYPE = :button
10
10
  TYPE_SUBMIT = :submit
11
- TYPE_OPTIONS = [DEFAULT_TYPE, :reset, TYPE_SUBMIT].freeze
11
+ VALID_TYPES = [DEFAULT_TYPE, :reset, TYPE_SUBMIT].freeze
12
12
 
13
13
  SIZE_CLASS_MAPPINGS = {
14
14
  xs: "ariadne-px-2.5 ariadne-py-1.5 ariadne-text-xs ariadne-font-medium ariadne-rounded",
@@ -20,6 +20,7 @@ module Ariadne
20
20
  VALID_SIZES = SIZE_CLASS_MAPPINGS.keys.freeze
21
21
 
22
22
  DEFAULT_CLASSES = "ariadne-inline-flex 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 = "ariadne-inline-flex focus:ariadne-outline-none focus:ariadne-ring-2 focus:ariadne-ring-offset-2"
23
24
 
24
25
  DEFAULT_SIZE = :md
25
26
 
@@ -31,7 +32,7 @@ module Ariadne
31
32
  # <%= render(Ariadne::BaseButton.new(size: :xl)) { "I am an extra large button!" } %>
32
33
  #
33
34
  # @param tag [Symbol] <%= one_of(Ariadne::BaseButton::TAG_OPTIONS) %>
34
- # @param type [Symbol] <%= one_of(Ariadne::BaseButton::TYPE_OPTIONS) %>
35
+ # @param type [Symbol] <%= one_of(Ariadne::BaseButton::VALID_TYPES) %>
35
36
  # @param size [Symbol] <%= one_of(Ariadne::BaseButton::VALID_SIZES) %>
36
37
  # @param classes [String] <%= link_to_classes_docs %>
37
38
  # @param attributes [Hash] <%= link_to_attributes_docs %>
@@ -46,14 +47,22 @@ module Ariadne
46
47
  @tag = fetch_or_raise(TAG_OPTIONS, tag)
47
48
  @size = fetch_or_raise(VALID_SIZES, size)
48
49
 
49
- @attributes[:type] = fetch_or_raise(TYPE_OPTIONS, type) if button?
50
- @classes = class_names(DEFAULT_CLASSES, SIZE_CLASS_MAPPINGS[@size], classes)
50
+ if button?
51
+ @attributes[:type] = fetch_or_raise(VALID_TYPES, type)
52
+ @classes = class_names(DEFAULT_CLASSES, SIZE_CLASS_MAPPINGS[@size], classes)
53
+ else
54
+ @classes = class_names(DEFAULT_NUDE_CLASSES, SIZE_CLASS_MAPPINGS[@size], classes)
55
+ end
51
56
  end
52
57
 
53
58
  def call
54
59
  render(Ariadne::BaseComponent.new(tag: @tag, classes: @classes, attributes: @attributes)) { content }
55
60
  end
56
61
 
62
+ private def link?(type)
63
+ type == :link
64
+ end
65
+
57
66
  private def button?
58
67
  @tag == :button
59
68
  end
@@ -50,7 +50,7 @@ module Ariadne
50
50
  # @param tag [Symbol, String] <%= one_of(Ariadne::HeadingComponent::TAG_OPTIONS) %>
51
51
  # @param classes [String] <%= link_to_classes_docs %>
52
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"
53
+ DEFAULT_HEADING_CLASSES = "ariadne-text-3xl ariadne-font-extrabold ariadne-tracking-tight ariadne-text-gray-900 sm:ariadne-text-4xl"
54
54
  renders_one :heading, lambda { |tag: :h1, classes: "", attributes: {}|
55
55
  actual_classes = class_names(DEFAULT_HEADING_CLASSES, classes)
56
56
 
@@ -107,7 +107,7 @@ module Ariadne
107
107
 
108
108
  # @example Basic
109
109
  # <%= render Ariadne::BlankslateComponent.new do |c| %>
110
- # <% c.heading(tag: :h2).with_content("heading") %>
110
+ # <% c.heading(tag: :h2) { "heading" } %>
111
111
  # <% c.description { "Description"} %>
112
112
  # <% end %>
113
113
  #
@@ -117,7 +117,7 @@ module Ariadne
117
117
  # @code
118
118
  # <%= render Ariadne::BlankslateComponent.new do |c| %>
119
119
  # <% c.icon(icon: :"globe-europe-africa") %>
120
- # <% c.heading(tag: :h2).with_content("heading") %>
120
+ # <% c.heading(tag: :h2) { "heading" } %>
121
121
  # <% c.description { "Description"} %>
122
122
  # <% end %>
123
123
  #
@@ -127,7 +127,7 @@ module Ariadne
127
127
  # @code
128
128
  # <%= render Ariadne::BlankslateComponent.new do |c| %>
129
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") %>
130
+ # <% c.heading(tag: :h2){ "heading" } %>
131
131
  # <% end %>
132
132
  #
133
133
  # @param tag [Symbol, String] The rendered tag name
@@ -5,7 +5,7 @@ module Ariadne
5
5
  # Add additional usage considerations or best practices that may aid the user to use the component correctly.
6
6
  # @accessibility Add any accessibility considerations
7
7
  class BodyComponent < Ariadne::Component
8
- DEFAULT_CLASSES = "ariadne-flex ariadne-flex-col ariadne-min-h-screen"
8
+ DEFAULT_CLASSES = "ariadne-scroll-smooth ariadne-bg-white ariadne-antialiased"
9
9
 
10
10
  # @example Default
11
11
  #
@@ -1,4 +1,4 @@
1
1
  <%= render Ariadne::BaseButton.new(tag: @tag, type: @type, classes: @classes, attributes: @attributes) do -%>
2
- <%= icon %><%= trimmed_content %><%= counter %>
2
+ <%= icon %><%= trimmed_content %><%= counter %><%= ariadne_heroicon(icon: :"chevron-down", variant: HeroiconsHelper::Icon::VARIANT_MINI, classes: "ariadne-ml-2 ariadne--mr-1") if dropdown? %>
3
3
  <%= tooltip %>
4
4
  <% end -%>