-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
382 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { VuiBadge, VuiFlexContainer, VuiLink, VuiSpinner, VuiText } from "../vui"; | ||
|
||
interface Props { | ||
score?: number; | ||
} | ||
|
||
export const FactualConsistencyBadge = ({ score }: Props) => { | ||
let badge; | ||
|
||
if (score === undefined) { | ||
badge = <VuiBadge color="accent">Calculating Factual Consistency Score…</VuiBadge>; | ||
} else { | ||
const sanitizedScore = parseFloat(score.toFixed(2)); | ||
let badgeColor = "neutral"; | ||
|
||
if (sanitizedScore === 0) { | ||
badgeColor = "danger"; | ||
} else if (sanitizedScore === 1) { | ||
badgeColor = "success"; | ||
} | ||
|
||
badge = ( | ||
<VuiBadge color={badgeColor as "neutral" | "success" | "danger"}> | ||
Factual Consistency Score: {sanitizedScore} | ||
</VuiBadge> | ||
); | ||
} | ||
|
||
return ( | ||
<VuiFlexContainer alignItems="center" data-testid="factualConsistencyBadge"> | ||
{score === undefined && <VuiSpinner size="s" />} | ||
|
||
{badge} | ||
|
||
<VuiText size="xs"> | ||
<p> | ||
<VuiLink | ||
href="https://docs.vectara.com/docs/api-reference/search-apis/search?#factual-consistency-score" | ||
target="_blank" | ||
> | ||
What's this? | ||
</VuiLink> | ||
</p> | ||
</VuiText> | ||
</VuiFlexContainer> | ||
); | ||
}; |
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,50 @@ | ||
import { MouseEvent } from "react"; | ||
import classNames from "classnames"; | ||
import { getTrackingProps } from "../../utils/getTrackingProps"; | ||
import { useVuiContext } from "../context/Context"; | ||
import { LinkProps } from "../link/types"; | ||
|
||
export const BADGE_COLOR = ["accent", "primary", "danger", "warning", "success", "neutral"] as const; | ||
|
||
type Props = { | ||
children: React.ReactNode; | ||
className?: string; | ||
color: (typeof BADGE_COLOR)[number]; | ||
onClick?: (event: MouseEvent<HTMLButtonElement>) => void; | ||
href?: LinkProps["href"]; | ||
target?: LinkProps["target"]; | ||
track?: LinkProps["track"]; | ||
}; | ||
|
||
export const VuiBadge = ({ children, className, color, onClick, href, target, track, ...rest }: Props) => { | ||
const { createLink } = useVuiContext(); | ||
|
||
const classes = classNames(className, "vuiBadge", `vuiBadge--${color}`, { | ||
"vuiBadge--clickable": onClick ?? href | ||
}); | ||
|
||
if (onClick) { | ||
return ( | ||
<button className={classes} onClick={onClick} {...rest}> | ||
{children} | ||
</button> | ||
); | ||
} | ||
|
||
if (href) { | ||
return createLink({ | ||
className: classes, | ||
href, | ||
onClick, | ||
children, | ||
target, | ||
...getTrackingProps(track) | ||
}); | ||
} | ||
|
||
return ( | ||
<div className={classes} {...rest}> | ||
{children} | ||
</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,64 @@ | ||
@use "sass:map"; | ||
|
||
.vuiBadge { | ||
display: inline-block; | ||
font-size: $fontSizeSmall; | ||
line-height: 1; | ||
padding: $sizeXxs $sizeXs; | ||
border-radius: $sizeS; | ||
font-family: inherit; | ||
white-space: nowrap; | ||
text-decoration: none; | ||
} | ||
|
||
.vuiBadge--clickable { | ||
cursor: pointer; | ||
} | ||
|
||
// Color | ||
$color: ( | ||
accent: ( | ||
"color": $colorAccent, | ||
"background-color": transparentize($colorAccent, 0.9), | ||
"border-color": transparentize($colorAccent, 0.9) | ||
), | ||
primary: ( | ||
"color": $colorPrimary, | ||
"background-color": transparentize($colorPrimary, 0.9), | ||
"border-color": transparentize($colorPrimary, 0.9) | ||
), | ||
success: ( | ||
"color": $colorSuccess, | ||
"background-color": transparentize($colorSuccess, 0.9), | ||
"border-color": transparentize($colorSuccess, 0.9) | ||
), | ||
warning: ( | ||
"color": $colorWarning, | ||
"background-color": transparentize($colorWarning, 0.9), | ||
"border-color": transparentize($colorWarning, 0.9) | ||
), | ||
danger: ( | ||
"color": $colorDanger, | ||
"background-color": transparentize($colorDanger, 0.9), | ||
"border-color": transparentize($colorDanger, 0.9) | ||
), | ||
neutral: ( | ||
"color": $colorText, | ||
"background-color": $colorLightShade, | ||
"border-color": transparentize($colorText, 0.9) | ||
) | ||
); | ||
|
||
@each $colorName, $colorValue in $color { | ||
.vuiBadge--#{$colorName} { | ||
color: #{map.get($colorValue, "color")} !important; | ||
background-color: #{map.get($colorValue, "background-color")}; | ||
border: 1px solid #{map.get($colorValue, "border-color")}; | ||
transition: all $transitionSpeed; | ||
|
||
&.vuiBadge--clickable:hover { | ||
border-color: #{map.get($colorValue, "color")}; | ||
text-decoration: none; | ||
} | ||
} | ||
} |
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,18 @@ | ||
import { render } from "@testing-library/react"; | ||
import { Link } from "react-router-dom"; | ||
import { LinkProps } from "../link/types"; | ||
import { VuiContextProvider } from "./Context"; | ||
|
||
const linkProvider = (linkConfig: LinkProps) => { | ||
const { className, href, onClick, children, ...rest } = linkConfig; | ||
|
||
return ( | ||
<Link className={className} to={href ?? ""} onClick={onClick} {...rest}> | ||
{children} | ||
</Link> | ||
); | ||
}; | ||
|
||
export const renderWithContext = (children: React.ReactNode, ...rest: any) => { | ||
return render(<VuiContextProvider linkProvider={linkProvider}>{children}</VuiContextProvider>, ...rest); | ||
}; |
Oops, something went wrong.