-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add feedback buttons on acceptsFeedback
- Loading branch information
Showing
11 changed files
with
299 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
.memori-chat--feedback { | ||
padding: 0 3.5rem; | ||
margin-top: -0.5em; | ||
margin-bottom: 1.5em; | ||
} | ||
|
||
.memori-chat--feedback button { | ||
padding: 0.5em; | ||
opacity: 0.4; | ||
transition: all 0.3s ease-in-out; | ||
} | ||
|
||
.memori-chat--feedback button:hover, | ||
.memori-chat--feedback button:focus { | ||
opacity: 1; | ||
} | ||
|
||
.memori-chat--feedback button .memori-button--icon svg { | ||
fill: none; | ||
} | ||
.memori-chat--feedback button .memori-button--icon svg.memori-chat--feedback-clicked { | ||
fill: var(--memori-primary); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/components/FeedbackButtons/FeedbackButtons.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import { Meta, Story } from '@storybook/react'; | ||
import FeedbackButtons, { Props } from './FeedbackButtons'; | ||
import { memori } from '../../mocks/data'; | ||
|
||
const meta: Meta = { | ||
title: 'Feedback Buttons', | ||
component: FeedbackButtons, | ||
argTypes: {}, | ||
parameters: { | ||
controls: { expanded: true }, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
const Template: Story<Props> = args => <FeedbackButtons {...args} />; | ||
|
||
// By passing using the Args format for exported stories, you can control the props for a component for reuse in a test | ||
// https://storybook.js.org/docs/react/workflows/unit-testing | ||
export const Default = Template.bind({}); | ||
Default.args = { | ||
memori, | ||
simulateUserPrompt: () => {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { memori } from '../../mocks/data'; | ||
import FeedbackButtons from './FeedbackButtons'; | ||
|
||
it('renders FeedbackButtons unchanged', () => { | ||
const { container } = render( | ||
<FeedbackButtons memori={memori} simulateUserPrompt={jest.fn()} /> | ||
); | ||
expect(container).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { Memori } from '@memori.ai/memori-api-client/dist/types'; | ||
import React, { useState } from 'react'; | ||
import Tooltip from '../ui/Tooltip'; | ||
import Button from '../ui/Button'; | ||
import ThumbUp from '../icons/ThumbUp'; | ||
import ThumbDown from '../icons/ThumbDown'; | ||
|
||
import './FeedbackButtons.css'; | ||
|
||
const feedbackMsgs = { | ||
'it-IT': 'Non è quello che ti ho chiesto', | ||
'fr-FR': "Ce n'est pas ce que je t'ai demandé", | ||
'en-GB': "It's not what I asked", | ||
}; | ||
|
||
export interface Props { | ||
memori: Memori; | ||
simulateUserPrompt: (msg: string) => void; | ||
} | ||
|
||
const FeedbackButtons = ({ memori, simulateUserPrompt }: Props) => { | ||
const [clicked, setClicked] = useState<'up' | 'down'>(); | ||
const feedbackMsg = | ||
memori.culture === 'it-IT' | ||
? feedbackMsgs['it-IT'] | ||
: memori.culture === 'fr-FR' | ||
? feedbackMsgs['fr-FR'] | ||
: feedbackMsgs['en-GB']; | ||
|
||
return ( | ||
<div className="memori-chat--feedback"> | ||
<Button | ||
ghost | ||
shape="circle" | ||
onClick={() => { | ||
if (clicked === 'up') { | ||
setClicked(undefined); | ||
} else { | ||
setClicked('up'); | ||
} | ||
}} | ||
icon={ | ||
<ThumbUp | ||
className={ | ||
clicked === 'up' ? 'memori-chat--feedback-clicked' : undefined | ||
} | ||
/> | ||
} | ||
/> | ||
<Tooltip content={feedbackMsg}> | ||
<Button | ||
ghost | ||
shape="circle" | ||
onClick={() => { | ||
if (clicked === 'down') { | ||
setClicked(undefined); | ||
} else { | ||
setClicked('down'); | ||
} | ||
simulateUserPrompt(feedbackMsg); | ||
}} | ||
icon={ | ||
<ThumbDown | ||
className={ | ||
clicked === 'down' ? 'memori-chat--feedback-clicked' : undefined | ||
} | ||
/> | ||
} | ||
/> | ||
</Tooltip> | ||
</div> | ||
); | ||
}; | ||
|
||
export default FeedbackButtons; |
73 changes: 73 additions & 0 deletions
73
src/components/FeedbackButtons/__snapshots__/FeedbackButtons.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders FeedbackButtons unchanged 1`] = ` | ||
<div> | ||
<div | ||
class="memori-chat--feedback" | ||
> | ||
<button | ||
class="memori-button memori-button--ghost memori-button--circle memori-button--padded memori-button--icon-only" | ||
> | ||
<span | ||
class="memori-button--icon" | ||
> | ||
<svg | ||
aria-hidden="true" | ||
fill="none" | ||
focusable="false" | ||
role="img" | ||
stroke="currentColor" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="2" | ||
tabindex="-1" | ||
viewBox="0 0 24 24" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M14 9V5a3 3 0 00-3-3l-4 9v11h11.28a2 2 0 002-1.7l1.38-9a2 2 0 00-2-2.3zM7 22H4a2 2 0 01-2-2v-7a2 2 0 012-2h3" | ||
/> | ||
</svg> | ||
</span> | ||
</button> | ||
<div | ||
class="memori-tooltip" | ||
> | ||
<div | ||
class="memori-tooltip--content" | ||
> | ||
Non è quello che ti ho chiesto | ||
</div> | ||
<div | ||
class="memori-tooltip--trigger" | ||
> | ||
<button | ||
class="memori-button memori-button--ghost memori-button--circle memori-button--padded memori-button--icon-only" | ||
> | ||
<span | ||
class="memori-button--icon" | ||
> | ||
<svg | ||
aria-hidden="true" | ||
fill="none" | ||
focusable="false" | ||
role="img" | ||
stroke="currentColor" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="2" | ||
tabindex="-1" | ||
viewBox="0 0 24 24" | ||
xmlns="http://www.w3.org/2000/svg" | ||
> | ||
<path | ||
d="M10 15v4a3 3 0 003 3l4-9V2H5.72a2 2 0 00-2 1.7l-1.38 9a2 2 0 002 2.3zm7-13h2.67A2.31 2.31 0 0122 4v7a2.31 2.31 0 01-2.33 2H17" | ||
/> | ||
</svg> | ||
</span> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
|
||
const ThumbDown = ({ | ||
className, | ||
title, | ||
}: { | ||
className?: string; | ||
title?: string; | ||
}) => ( | ||
<svg | ||
{...(!title ? { 'aria-hidden': 'true' } : {})} | ||
focusable="false" | ||
role="img" | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth="2" | ||
tabIndex={-1} | ||
className={className} | ||
aria-label={title} | ||
> | ||
<path d="M10 15v4a3 3 0 003 3l4-9V2H5.72a2 2 0 00-2 1.7l-1.38 9a2 2 0 002 2.3zm7-13h2.67A2.31 2.31 0 0122 4v7a2.31 2.31 0 01-2.33 2H17"></path> | ||
</svg> | ||
); | ||
|
||
export default ThumbDown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React from 'react'; | ||
|
||
const ThumbUp = ({ | ||
className, | ||
title, | ||
}: { | ||
className?: string; | ||
title?: string; | ||
}) => ( | ||
<svg | ||
{...(!title ? { 'aria-hidden': 'true' } : {})} | ||
focusable="false" | ||
role="img" | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
stroke="currentColor" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth="2" | ||
tabIndex={-1} | ||
className={className} | ||
aria-label={title} | ||
> | ||
<path d="M14 9V5a3 3 0 00-3-3l-4 9v11h11.28a2 2 0 002-1.7l1.38-9a2 2 0 00-2-2.3zM7 22H4a2 2 0 01-2-2v-7a2 2 0 012-2h3"></path> | ||
</svg> | ||
); | ||
|
||
export default ThumbUp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters