-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add disclaimer * Move EmbedDisclaimer component * Remove whitespace * Address coderabbit suggestions --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
57649a6
commit 9c960a5
Showing
4 changed files
with
285 additions
and
29 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
23 changes: 23 additions & 0 deletions
23
apps/web/components/ChatPanel/ChatBubble/EmbedDisclaimer/EmbedDisclaimer.css.ts
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 @@ | ||
import { style } from '@vanilla-extract/css' | ||
|
||
import { theme, themeUtils } from '@island.is/island-ui/theme' | ||
|
||
export const link = style({ | ||
textDecoration: 'underline', | ||
}) | ||
|
||
export const modal = style({ | ||
width: 357, | ||
position: 'fixed', | ||
zIndex: 10000, | ||
bottom: theme.spacing[2], | ||
right: theme.spacing[1], | ||
...themeUtils.responsiveStyle({ | ||
md: { | ||
bottom: theme.spacing[3], | ||
right: theme.spacing[3], | ||
}, | ||
}), | ||
transition: 'opacity 0.3s ease', | ||
boxShadow: '0 4px 30px rgba(0, 0, 0, 0.16)', | ||
}) |
134 changes: 134 additions & 0 deletions
134
apps/web/components/ChatPanel/ChatBubble/EmbedDisclaimer/EmbedDisclaimer.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,134 @@ | ||
import React, { type ReactNode } from 'react' | ||
import { Controller, useForm } from 'react-hook-form' | ||
|
||
import { | ||
Box, | ||
Button, | ||
Checkbox, | ||
FocusableBox, | ||
Icon, | ||
LinkContext, | ||
Stack, | ||
} from '@island.is/island-ui/core' | ||
|
||
import * as styles from './EmbedDisclaimer.css' | ||
|
||
export interface EmbedDisclaimerProps { | ||
texts: { | ||
cancel: string | ||
accept: string | ||
message: ReactNode | ||
remember: string | ||
} | ||
onAnswer: (acceptsTerms: boolean) => void | ||
localStorageKey: string | ||
} | ||
|
||
export const EmbedDisclaimer = ({ | ||
texts, | ||
onAnswer, | ||
localStorageKey, | ||
}: EmbedDisclaimerProps) => { | ||
const methods = useForm() | ||
|
||
const { control } = methods | ||
|
||
return ( | ||
<Box | ||
className={styles.modal} | ||
background="blue100" | ||
borderRadius="large" | ||
padding="gutter" | ||
> | ||
<Stack space={1}> | ||
<Box display="flex" justifyContent="spaceBetween"> | ||
<Box /> | ||
<FocusableBox | ||
tabIndex={0} | ||
aria-label={texts.cancel} | ||
onKeyDown={(ev) => { | ||
if (ev.key === 'Enter' || ev.key === ' ') { | ||
onAnswer(false) | ||
ev.preventDefault() | ||
} | ||
}} | ||
onClick={() => { | ||
onAnswer(false) | ||
}} | ||
> | ||
<Icon icon="close" size="medium" /> | ||
</FocusableBox> | ||
</Box> | ||
<Box padding="p1"> | ||
<LinkContext.Provider | ||
value={{ | ||
linkRenderer: (href, children) => ( | ||
<a | ||
className={styles.link} | ||
href={href} | ||
rel="noopener noreferrer" | ||
target="_blank" | ||
> | ||
{children} | ||
</a> | ||
), | ||
}} | ||
> | ||
<Stack space={3}> | ||
<Stack space={2} align="center"> | ||
<Box>{texts.message}</Box> | ||
<Controller | ||
name={localStorageKey} | ||
defaultValue={false} | ||
control={control} | ||
rules={{ required: false }} | ||
render={({ field: { onChange, value } }) => ( | ||
<Checkbox | ||
label={texts.remember} | ||
labelVariant="small" | ||
checked={value} | ||
onChange={(e) => { | ||
onChange(e.target.checked) | ||
try { | ||
localStorage.setItem( | ||
localStorageKey, | ||
e.target.checked ? 'true' : 'false', | ||
) | ||
} catch (error) { | ||
console.warn('Failed to save preference:', error) | ||
} | ||
}} | ||
/> | ||
)} | ||
/> | ||
</Stack> | ||
<Stack space={2} align="center"> | ||
<Button | ||
fluid={true} | ||
colorScheme="default" | ||
size="small" | ||
onClick={() => { | ||
onAnswer(true) | ||
}} | ||
> | ||
{texts.accept} | ||
</Button> | ||
<Button | ||
fluid={true} | ||
variant="ghost" | ||
colorScheme="default" | ||
size="small" | ||
onClick={() => { | ||
onAnswer(false) | ||
}} | ||
> | ||
{texts.cancel} | ||
</Button> | ||
</Stack> | ||
</Stack> | ||
</LinkContext.Provider> | ||
</Box> | ||
</Stack> | ||
</Box> | ||
) | ||
} |
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