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

chat message actions #12

Merged
merged 3 commits into from
Jul 22, 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
3 changes: 2 additions & 1 deletion packages/ui-stencil-vue/lib/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export const OramaButton = /*@__PURE__*/ defineContainer<JSX.OramaButton>('orama
'class',
'variant',
'type',
'disabled'
'disabled',
'withTooltip'
]);


Expand Down
2 changes: 2 additions & 0 deletions packages/ui-stencil/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export namespace Components {
"disabled"?: boolean;
"type"?: ButtonProps['type'];
"variant"?: ButtonProps['variant'];
"withTooltip"?: string;
}
interface OramaChat {
}
Expand Down Expand Up @@ -302,6 +303,7 @@ declare namespace LocalJSX {
"disabled"?: boolean;
"type"?: ButtonProps['type'];
"variant"?: ButtonProps['variant'];
"withTooltip"?: string;
}
interface OramaChat {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// TODO: We need to revisit this styles. There are some duplications and variables without fallback
.button {
position: relative;
display: inline-flex;
gap: var(--spacing-s, $spacing-s);
align-items: center;
Expand All @@ -8,9 +9,22 @@
padding: var(--spacing-m, $spacing-m);
cursor: pointer;
font-family: var(--font-primary, font('primary'));

transition: all 0.2s;
transition-property: color, background-color, opacity;

&__tooltip {
display: block;
opacity: 0;
position: absolute;
background-color: var(--text-color-primary, text-color('primary'));
color: var(--background-color-primary, background-color('primary'));
padding: var(--spacing-s, $spacing-s);
border-radius: var(--radius-s, $radius-s);
font-size: 10px;
z-index: 1;
top: -28px;
animation: fadeInOut 1s ease-in-out 1;
}
}

.button--primary {
Expand Down Expand Up @@ -50,3 +64,15 @@
background-color: var(--background-color-tertiary, background-color('tertiary'));
}
}

@keyframes fadeInOut {
0% {
opacity: 0;
}
50% {
opacity: 1;
}
100% {
opacity: 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class OramaButton {
@Prop() variant?: ButtonProps['variant'] = 'primary'
@Prop() type?: ButtonProps['type']
@Prop() disabled?: boolean
@Prop() withTooltip?: string

render() {
const Tag = this.as
Expand All @@ -51,6 +52,7 @@ export class OramaButton {
return (
<Tag class={buttonClass} {...buttonProps} disabled={this.disabled}>
<slot />
{this.withTooltip && <span class="button__tooltip">{this.withTooltip}</span>}
</Tag>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

## Properties

| Property | Attribute | Description | Type | Default |
| ---------- | ---------- | ----------- | ------------------------------------ | ----------- |
| `as` | `as` | | `"a" \| "button"` | `'button'` |
| `class` | `class` | | `string` | `undefined` |
| `disabled` | `disabled` | | `boolean` | `undefined` |
| `type` | `type` | | `"button" \| "reset" \| "submit"` | `undefined` |
| `variant` | `variant` | | `"icon" \| "primary" \| "secondary"` | `'primary'` |
| Property | Attribute | Description | Type | Default |
| ------------- | -------------- | ----------- | ------------------------------------ | ----------- |
| `as` | `as` | | `"a" \| "button"` | `'button'` |
| `class` | `class` | | `string` | `undefined` |
| `disabled` | `disabled` | | `boolean` | `undefined` |
| `type` | `type` | | `"button" \| "reset" \| "submit"` | `undefined` |
| `variant` | `variant` | | `"icon" \| "primary" \| "secondary"` | `'primary'` |
| `withTooltip` | `with-tooltip` | | `string` | `undefined` |


## Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,16 @@ orama-chat-assistent-message {
white-space: nowrap;
}
}

.retrying {
animation: rotate360 2s ease-in-out 1;
}

@keyframes rotate360 {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Host, Prop, h } from '@stencil/core'
import { Component, Host, Listen, Prop, State, h } from '@stencil/core'
import type { TChatMessage } from '@/context/chatContext'
import '@phosphor-icons/webcomponents/dist/icons/PhCopy.mjs'
import '@phosphor-icons/webcomponents/dist/icons/PhArrowsClockwise.mjs'
Expand All @@ -13,24 +13,58 @@ import { copyToClipboard } from '@/utils/utils'
export class OramaChatAssistentMessage {
@Prop() message: TChatMessage

@State() isCopied = false
handleCopyToClipboard = () => {
this.isCopied = true
setTimeout(() => (this.isCopied = false), 1000)
copyToClipboard(this.message.content)
}

@State() isRetrying = false
handleRetryMessage = () => {
// todo: replace with actual retry logic
setTimeout(() => (this.isRetrying = false), 2000)
this.isRetrying = !this.isRetrying
}

@State() isDisliked = false
handleDislikeMessage = () => {
// todo: replace with actual dislike logic
this.isDisliked = !this.isDisliked
}

render() {
return (
<Host>
<div class="message-wrapper">
<orama-markdown content={this.message.content} />
<div class="message-actions">
<orama-button type="button" variant="icon">
{/* TODO: We need a feedback for copy to clipboard action */}
<ph-copy
onClick={() => copyToClipboard(this.message.content)}
onKeyDown={() => copyToClipboard(this.message.content)}
/>
<orama-button
type="button"
variant="icon"
onClick={this.handleCopyToClipboard}
onKeyDown={this.handleCopyToClipboard}
withTooltip={this.isCopied ? 'Copied!' : undefined}
>
<ph-copy />
</orama-button>
<orama-button type="button" variant="icon">
<ph-arrows-clockwise />
<orama-button
type="button"
variant="icon"
onClick={this.handleRetryMessage}
onKeyDown={this.handleRetryMessage}
>
<span class={this.isRetrying ? 'retrying' : ''}>
{this.isRetrying ? <ph-arrows-clockwise weight="fill" /> : <ph-arrows-clockwise />}
</span>
</orama-button>
<orama-button type="button" variant="icon">
<ph-thumbs-down />
<orama-button
type="button"
variant="icon"
onClick={this.handleDislikeMessage}
onKeyDown={this.handleDislikeMessage}
>
{this.isDisliked ? <ph-thumbs-down weight="fill" /> : <ph-thumbs-down />}
</orama-button>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-stencil/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CloudIndexConfig } from '@/types'
import type { CloudIndexConfig } from '@/types'
import { OramaClient } from '@oramacloud/client'

export function format(first: string, middle: string, last: string): string {
Expand Down
Loading