Skip to content

feat: Ariakit comments #1448

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

Merged
merged 2 commits into from
Feb 20, 2025
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
183 changes: 183 additions & 0 deletions packages/ariakit/src/ariakitStyles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1003,4 +1003,187 @@ responsible for the majority of the styling. */

.bn-ak-link:where(.dark, .dark *) {
color: hsl(204 100% 64%);
}

/* https://ariakit.org/components/hovercard */
/*.bn-ak-button {*/
/* --border: rgb(0 0 0/13%);*/
/* --highlight: rgb(255 255 255/20%);*/
/* --shadow: rgb(0 0 0/10%);*/
/* display: flex;*/
/* height: 2.5rem;*/
/* user-select: none;*/
/* align-items: center;*/
/* justify-content: center;*/
/* gap: 0.25rem;*/
/* white-space: nowrap;*/
/* border-style: none;*/
/* background-color: white;*/
/* padding-left: 1rem;*/
/* padding-right: 1rem;*/
/* font-size: 1rem;*/
/* line-height: 1.5rem;*/
/* color: black;*/
/* text-decoration-line: none;*/
/* outline-width: 2px;*/
/* outline-offset: 2px;*/
/* outline-color: hsl(204 100% 40%);*/
/* box-shadow:*/
/* inset 0 0 0 1px var(--border),*/
/* inset 0 2px 0 var(--highlight),*/
/* inset 0 -1px 0 var(--shadow),*/
/* 0 1px 1px var(--shadow);*/
/* position: absolute;*/
/* top: 1rem;*/
/* right: 1rem;*/
/* border-radius: 9999px;*/
/* font-weight: 600;*/
/*}*/

/*.bn-ak-button:where(.dark, .dark *) {*/
/* --border: rgb(255 255 255/10%);*/
/* --highlight: rgb(255 255 255/5%);*/
/* --shadow: rgb(0 0 0/25%);*/
/* background-color: rgb(255 255 255 / 0.05);*/
/* color: white;*/
/* box-shadow:*/
/* inset 0 0 0 1px var(--border),*/
/* inset 0 -1px 0 1px var(--shadow),*/
/* inset 0 1px 0 var(--highlight);*/
/*}*/

/*.bn-ak-button:not(:active):hover {*/
/* --border: rgb(0 0 0/33%);*/
/*}*/

/*.bn-ak-button:where(.dark, .dark *):not(:active):hover {*/
/* --border: rgb(255 255 255/25%);*/
/*}*/

.bn-ak-primary {
--border: rgba(0, 0, 0, 0.15);
--highlight: rgba(255, 255, 255, 0.25);
--shadow: rgba(0, 0, 0, 0.15);
background-color: hsl(204 100% 40%);
color: white;
}

.bn-ak-primary:hover {
--border: rgba(0, 0, 0, 0.35);
background-color: hsl(204 100% 35%);
}

.bn-ak-primary:where(.dark, .dark *) {
--border: rgba(255, 255, 255, 0.25);
--highlight: rgba(255, 255, 255, 0.1);
--shadow: rgba(0, 0, 0, 0.25);
background-color: hsl(204 100% 35%);
}

.bn-ak-primary:hover:where(.dark, .dark *) {
--border: rgba(255, 255, 255, 0.45);
background-color: hsl(204 100% 40%);
}

.bn-ak-button[aria-disabled="true"] {
opacity: 0.5;
}

.bn-ak-button[data-focus-visible] {
outline-style: solid;
}

.bn-ak-button:active,
.bn-ak-button[data-active] {
padding-top: 0.125rem;
box-shadow:
inset 0 0 0 1px var(--border),
inset 0 2px 0 var(--border);
}

@media (min-width: 640px) {
.bn-ak-button {
gap: 0.5rem;
}
}

.bn-ak-button:active:where(.dark, .dark *),
.bn-ak-button[data-active]:where(.dark, .dark *) {
box-shadow:
inset 0 0 0 1px var(--border),
inset 0 1px 1px 1px var(--shadow);
}

.bn-ak-flat {
box-shadow: none;
}

.bn-ak-flat:where(.dark, .dark *) {
box-shadow: none;
}

.bn-ak-flat:active:where(.dark, .dark *),
.bn-ak-flat[data-active]:where(.dark, .dark *) {
box-shadow: none;
}

.bn-ak-anchor {
font-weight: 500;
color: hsl(204 100% 35%);
text-decoration-line: underline;
text-underline-offset: 0.25em;
text-decoration-skip-ink: none;
}

.bn-ak-anchor:hover {
text-decoration-thickness: 3px;
}

.bn-ak-anchor:where(.dark, .dark *) {
color: hsl(204 100% 64%);
}

.bn-ak-hovercard {
position: relative;
z-index: 50;
display: flex;
width: 300px;
flex-direction: column;
gap: 0.5rem;
border-radius: 0.5rem;
border-width: 1px;
border-style: solid;
border-color: hsl(204 20% 88%);
background-color: white;
padding: 1rem;
color: black;
box-shadow:
0 10px 15px -3px rgb(0 0 0 / 0.1),
0 4px 6px -4px rgb(0 0 0 / 0.1);
}

.bn-ak-hovercard:focus-visible,
.bn-ak-hovercard[data-focus-visible] {
outline: 2px solid hsl(204 100% 40%);
outline-offset: 2px;
}

.bn-ak-hovercard:where(.dark, .dark *) {
border-color: hsl(204 4% 24%);
background-color: hsl(204 4% 16%);
color: white;
box-shadow:
0 10px 15px -3px rgb(0 0 0 / 0.25),
0 4px 6px -4px rgb(0 0 0 / 0.1);
}

.bn-ak-avatar {
width: 4rem;
border-radius: 9999px;
}

.bn-ak-username {
font-size: 1.125rem;
line-height: 1.75rem;
font-weight: 600;
}
75 changes: 75 additions & 0 deletions packages/ariakit/src/badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import {
Button as AriakitButton,
Group as AriakitGroup,
Tooltip as AriakitTooltip,
TooltipAnchor as AriakitTooltipAnchor,
TooltipProvider as AriakitTooltipProvider,
} from "@ariakit/react";

import { assertEmpty, mergeCSSClasses } from "@blocknote/core";
import { ComponentProps } from "@blocknote/react";
import { forwardRef } from "react";

export const Badge = forwardRef<
HTMLButtonElement,
ComponentProps["Generic"]["Badge"]["Root"]
>((props, ref) => {
const {
className,
text,
icon,
isSelected,
mainTooltip,
secondaryTooltip,
onClick,
...rest
} = props;

assertEmpty(rest, false);

const badge = (
<AriakitButton
className={mergeCSSClasses(
className,
"bn-ak-badge bn-ak-button",
isSelected && "bn-ak-primary"
)}
aria-selected={isSelected === true}
onClick={(event) => onClick?.(event)}
ref={ref}>
<span>{icon}</span>
<span>{text}</span>
</AriakitButton>
);

if (!mainTooltip) {
return badge;
}

return (
<AriakitTooltipProvider>
<AriakitTooltipAnchor render={badge} />
<AriakitTooltip className="bn-ak-tooltip" portal={false}>
<span>{mainTooltip}</span>
{secondaryTooltip && <span>{secondaryTooltip}</span>}
</AriakitTooltip>
</AriakitTooltipProvider>
);
});

export const BadgeGroup = forwardRef<
HTMLDivElement,
ComponentProps["Generic"]["Badge"]["Group"]
>((props, ref) => {
const { className, children, ...rest } = props;

assertEmpty(rest);

return (
<AriakitGroup
className={mergeCSSClasses(className, "bn-ak-badge-group")}
ref={ref}>
{children}
</AriakitGroup>
);
});
39 changes: 39 additions & 0 deletions packages/ariakit/src/comments/Card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Group as AriakitGroup } from "@ariakit/react";

import { assertEmpty, mergeCSSClasses } from "@blocknote/core";
import { ComponentProps } from "@blocknote/react";
import { forwardRef } from "react";

export const Card = forwardRef<
HTMLDivElement,
ComponentProps["Comments"]["Card"]
>((props, ref) => {
const { className, children, ...rest } = props;

assertEmpty(rest, false);

return (
<AriakitGroup
className={mergeCSSClasses(className, "bn-ak-hovercard")}
ref={ref}>
{children}
</AriakitGroup>
);
});

export const CardSection = forwardRef<
HTMLDivElement,
ComponentProps["Comments"]["CardSection"]
>((props, ref) => {
const { className, children, ...rest } = props;

assertEmpty(rest, false);

return (
<AriakitGroup
className={mergeCSSClasses(className, "bn-ak-card-section")}
ref={ref}>
{children}
</AriakitGroup>
);
});
84 changes: 84 additions & 0 deletions packages/ariakit/src/comments/Comment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { Group as AriakitGroup } from "@ariakit/react";

import { assertEmpty } from "@blocknote/core";
import { ComponentProps } from "@blocknote/react";
import { forwardRef, useState } from "react";

const AuthorInfo = forwardRef<
HTMLDivElement,
Pick<ComponentProps["Comments"]["Comment"], "authorInfo" | "timeString">
>((props, _ref) => {
const { authorInfo, timeString, ...rest } = props;

assertEmpty(rest, false);

if (authorInfo === "loading") {
return (
<AriakitGroup className={"bn-ak-author-info"}>
<div className={"bn-ak-avatar bn-ak-skeleton"} />
<div className={"bn-ak-username bn-ak-skeleton"} />
</AriakitGroup>
);
}

return (
<AriakitGroup className={"bn-ak-author-info"}>
<img
src={authorInfo.avatarUrl}
alt={authorInfo.username}
className={"bn-ak-avatar"}
/>
<div className={"bn-ak-username"}>
{authorInfo.username}
<span>{timeString}</span>
</div>
</AriakitGroup>
);
});

export const Comment = forwardRef<
HTMLDivElement,
ComponentProps["Comments"]["Comment"]
>((props, ref) => {
const {
className,
showActions,
authorInfo,
timeString,
actions,
children,
...rest
} = props;

assertEmpty(rest, false);

const [hovered, setHovered] = useState(false);

const doShowActions =
actions &&
(showActions === true ||
showActions === undefined ||
(showActions === "hover" && hovered));

return (
<AriakitGroup
ref={ref}
className={className}
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}>
{doShowActions ? (
<AriakitGroup
style={{
position: "absolute",
right: 0,
top: 0,
zIndex: 10,
}}>
{actions}
</AriakitGroup>
) : null}
<AuthorInfo {...props} />
{children}
</AriakitGroup>
);
});
Loading
Loading