Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RW-1019] AI chat feedback icon fix #77

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 92 additions & 53 deletions modules/ocha_ai_chat/components/chat-form/chat-form.css
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ button doesn't overlay any text */
.ocha-ai-chat-chat-form .ocha-ai-chat-result .chat__refs,
.ocha-ai-chat-chat-form__instructions > * {
align-self: flex-start;
margin-left: 52px;
margin-block-start: 1.5rem;
margin-inline-end: 2rem;
margin-left: 52px;
text-align: start;
color: #333;
background: var(--brand-grey);
Expand All @@ -248,9 +248,10 @@ button doesn't overlay any text */
display: block;
width: 48px;
height: 48px;
background: var(--rw-icons--avatar--avatar--48--dark-grey);
content: '';
background: var(--rw-icons--avatar--avatar--48--dark-grey);
}

&::after {
position: absolute;
bottom: 6px;
Expand Down Expand Up @@ -309,9 +310,9 @@ button doesn't overlay any text */
.ocha-ai-chat-result-feedback .fieldset-wrapper {
display: flex;
flex-flow: row nowrap;
align-items: center;
justify-content: flex-start;
gap: 0.5rem;
align-items: center;
}

.ocha-ai-chat-result-feedback {
Expand All @@ -322,79 +323,117 @@ button doesn't overlay any text */
margin-block-start: 0.5rem;
}

button.feedback-button.feedback-button.feedback-button.feedback-button {
/**
* Feedback buttons.
*
* Note: we need long selectors to have enough specificity to override the
* default button styling when the form is shown on sites like ReliefWeb.
*/
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button:active,
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button:hover,
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button:focus {
border: none;
outline: none;
background: none;
}

.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--icon {
/* Visually hide the text. */
overflow: hidden;
width: 1rem;
height: 1rem;
border: 0;
padding: 0;
margin: 0;
background: none;
padding: 0;
color: transparent;
overflow: hidden;
border: 0;
background: none;
}

.feedback-button::before {
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--icon::before {
display: inline-block;
width: 1rem;
height: 1rem;
content: '';
}

.feedback-button--good::before { background: var(--rw-icons--chat--thumbs-up--16--dark-blue); }
.feedback-button--bad::before { background: var(--rw-icons--chat--thumbs-down--16--dark-blue); }
.feedback-button--copy::before { background: var(--rw-icons--chat--copy--16--dark-blue); }

button.feedback-button.feedback-button.feedback-button.feedback-button:hover,
button.feedback-button.feedback-button.feedback-button.feedback-button:focus {
background: none;
outline: none;
border: none;
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--good::before {
background: var(--rw-icons--chat--thumbs-up--16--dark-blue);
}
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--bad::before {
background: var(--rw-icons--chat--thumbs-down--16--dark-blue);
}
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--copy::before {
background: var(--rw-icons--chat--copy--16--dark-blue);
}

.feedback-button--good:focus::before { background: var(--rw-icons--chat--thumbs-up--16--dark-red); }
.feedback-button--bad:focus::before { background: var(--rw-icons--chat--thumbs-down--16--dark-red); }
.feedback-button--copy:focus::before { background: var(--rw-icons--chat--copy--16--dark-red); }
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--copy:active::before,
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--copy:hover::before,
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--copy:focus::before {
background-position-x: var(--rw-icons--chat--16--dark-red--x);
}

button.feedback-button.feedback-button.feedback-button--pressed.feedback-button--good,
button.feedback-button.feedback-button.feedback-button--pressed.feedback-button--bad {
/* Thumb buttons. */
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--thumb {
position: relative;
width: 1.5rem;
height: 1.5rem;
border: solid 1px #2e3436;
border: solid 1px transparent;
border-radius: 50%;
position: relative;
}

.feedback-button--pressed.feedback-button--good::before,
.feedback-button--pressed.feedback-button--bad::before {
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--thumb.feedback-button--pressed {
border: solid 1px #2e3436;
}
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--thumb.feedback-button--pressed:active,
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--thumb.feedback-button--pressed:hover,
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--thumb.feedback-button--pressed:focus {
border: solid 1px transparent;
}
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--thumb:not(.feedback-button--pressed):active,
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--thumb:not(.feedback-button--pressed):hover,
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--thumb:not(.feedback-button--pressed):focus {
border: solid 1px var(--brand-primary);
}
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--thumb::before {
position: absolute;
left: 0;
top: 0;
right: 0;
left: 0;
margin: auto;
}
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--thumb.feedback-button--good::before {
top: 2px;
}
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--thumb.feedback-button--bad::before {
top: 4px;
}
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--thumb.feedback-button--pressed::before {
background-position-x: var(--rw-icons--chat--16--dark-grey--x);
}
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--thumb + .feedback-button--thumb {
margin-left: -2px;
}

.feedback-button--pressed.feedback-button--good::before { background: var(--rw-icons--chat--thumbs-up--16--dark-grey); }
.feedback-button--pressed.feedback-button--bad::before { background: var(--rw-icons--chat--thumbs-down--16--dark-grey); }

.feedback-button--copy {
/* Copy button. */
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--copy {
/* this icon looks misaligned when the boxes are flush */
position: relative;
top: -1px;
}

.feedback-button--show-detailed {
font-size: 0.8em;
/* Detailed feedback button. */
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--show-detailed {
position: relative;
padding: 0 .25rem;
background: transparent;
color: var(--brand-primary);
position: relative;
}

.feedback-button--show-detailed:hover {
background: transparent;
border: none;
background: none;
font-size: 0.8em;
}

.feedback-button--show-detailed:focus {
background: transparent;
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--show-detailed:active,
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--show-detailed:hover,
.ocha-ai-chat-chat-form .ocha-ai-chat-result .feedback-button.feedback-button--show-detailed:focus {
border: none;
background: none;
}

/**
Expand Down Expand Up @@ -423,28 +462,28 @@ button.feedback-button.feedback-button.feedback-button--pressed.feedback-button-
}

.clipboard-feedback {
font-size: .75em;
position: absolute;
top: -4px;
z-index: 100;
background: var(--cd-black);
color: var(--cd-white);
border-radius: 3px;
top: -4px;
margin-inline-start: 0.5rem;
padding: 0.2rem 0.25rem;
white-space: nowrap;
color: var(--cd-white);
border-radius: 3px;
background: var(--cd-black);
font-size: .75em;
}

.clipboard-feedback::before {
--clipboard-arrow: 7px;

content: '';
border-inline-end: var(--clipboard-arrow) solid black;
border-block: 5px solid transparent;
display: block;
position: absolute;
top: 50%;
display: block;
content: '';
transform: translateY(-50%);
border-inline-end: var(--clipboard-arrow) solid black;
border-block: 5px solid transparent;
}

[dir="ltr"] .clipboard-feedback {
Expand Down
12 changes: 10 additions & 2 deletions modules/ocha_ai_chat/src/Form/OchaAiChatChatForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ public function buildForm(array $form, FormStateInterface $form_state, ?bool $po
'#attributes' => [
'class' => [
'feedback-button',
'feedback-button--icon',
'feedback-button--thumb',
'feedback-button--good',
($thumbs_state == 'up') ? 'feedback-button--pressed' : '',
],
Expand All @@ -265,6 +267,8 @@ public function buildForm(array $form, FormStateInterface $form_state, ?bool $po
'#attributes' => [
'class' => [
'feedback-button',
'feedback-button--icon',
'feedback-button--thumb',
'feedback-button--bad',
($thumbs_state == 'down') ? 'feedback-button--pressed' : '',
],
Expand All @@ -280,7 +284,11 @@ public function buildForm(array $form, FormStateInterface $form_state, ?bool $po
'#name' => 'chat-result-' . $index . '-copy-clipboard',
'#value' => $this->t('Copy to clipboard'),
'#attributes' => [
'class' => ['feedback-button', 'feedback-button--copy'],
'class' => [
'feedback-button',
'feedback-button--icon',
'feedback-button--copy',
],
'data-result-id' => $record['id'],
'data-for' => $answer_id,
],
Expand All @@ -305,7 +313,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ?bool $po
if ($feedback_type === 'both') {
$form['chat'][$index]['feedback_simple']['show_detailed'] = [
'#type' => 'inline_template',
'#template' => '<button data-for="{{ target }}" class="feedback-button--show-detailed">{{ button_text }}</button>',
'#template' => '<button data-for="{{ target }}" class="feedback-button feedback-button--show-detailed">{{ button_text }}</button>',
'#context' => [
'target' => 'chat-result-' . $index . '-feedback',
'button_text' => $this->t('Give detailed feedback'),
Expand Down
Loading