Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Rich text fixes/improvements (#3087)

Tim Wilsonf0fe555bc9fd
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx
index 984a61d7ed..da54fad2d2 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/bounties/add-edit-bounty-sheet.tsx
@@ -18,6 +18,7 @@ import {
} from "@/ui/partners/program-sheet-accordion";
import { AmountInput } from "@/ui/shared/amount-input";
import { X } from "@/ui/shared/icons";
+import { MaxCharactersCounter } from "@/ui/shared/max-characters-counter";
import {
AnimatedSizeContainer,
Button,
@@ -33,7 +34,7 @@ import {
ToggleGroup,
useRouterStuff,
} from "@dub/ui";
-import { cn, formatDate, nFormatter } from "@dub/utils";
+import { cn, formatDate } from "@dub/utils";
import { Dispatch, SetStateAction, useMemo, useState } from "react";
import {
Controller,
@@ -821,7 +822,7 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
features={["bold", "italic", "links"]}
markdown
placeholder="Provide any bounty requirements to the partner"
- editorClassName="block max-h-24 overflow-hidden w-full resize-none border-none p-3 text-base sm:text-sm"
+ editorClassName="block max-h-48 overflow-auto scrollbar-hide w-full resize-none border-none p-3 text-base sm:text-sm"
initialValue={field.value}
onChange={(editor) =>
field.onChange(
@@ -846,12 +847,13 @@ function BountySheetContent({ setIsOpen, bounty }: BountySheetProps) {
/>
<div className="mt-1 text-left">
- <span className="text-xs text-neutral-400">
- {description?.length || 0} /{" "}
- {nFormatter(BOUNTY_DESCRIPTION_MAX_LENGTH, {
- full: true,
- })}
- </span>
+ <MaxCharactersCounter
+ name="description"
+ control={control}
+ maxLength={BOUNTY_DESCRIPTION_MAX_LENGTH}
+ spaced
+ className="text-content-muted"
+ />
</div>
</div>
</div>
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-editor.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-editor.tsx
index ab1493e601..a78487afa9 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-editor.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/campaigns/[campaignId]/campaign-editor.tsx
@@ -511,6 +511,7 @@ export function CampaignEditor({ campaign }: { campaign: Campaign }) {
<RichTextProvider
ref={editorRef}
editorClassName="-m-2 min-h-[200px] p-2"
+ style="relaxed"
initialValue={field.value}
onChange={(editor) => field.onChange(editor.getJSON())}
variables={[...EMAIL_TEMPLATE_VARIABLES]}
diff --git a/apps/web/ui/messages/messages-panel.tsx b/apps/web/ui/messages/messages-panel.tsx
index 299310860f..2ed094c4d5 100644
--- a/apps/web/ui/messages/messages-panel.tsx
+++ b/apps/web/ui/messages/messages-panel.tsx
@@ -4,6 +4,7 @@ import {
Check2,
Envelope,
LoadingSpinner,
+ PROSE_STYLES,
Tooltip,
useMediaQuery,
} from "@dub/ui";
@@ -188,7 +189,8 @@ export function MessagesPanel({
isMySide
? "text-content-inverted prose-invert prose-a:text-content-inverted"
: "text-content-default prose-a:text-content-emphasis",
- "prose prose-sm prose-p:m-0 break-words",
+ "prose prose-sm break-words",
+ PROSE_STYLES.condensed,
"prose-a:font-medium prose-a:underline-offset-4",
)}
allowedElements={[
diff --git a/apps/web/ui/oauth-apps/add-edit-app-form.tsx b/apps/web/ui/oauth-apps/add-edit-app-form.tsx
index 86fb934b45..bbc1ca44d3 100644
--- a/apps/web/ui/oauth-apps/add-edit-app-form.tsx
+++ b/apps/web/ui/oauth-apps/add-edit-app-form.tsx
@@ -13,6 +13,9 @@ import {
FileUpload,
InfoTooltip,
LoadingSpinner,
+ RichTextArea,
+ RichTextProvider,
+ RichTextToolbar,
Switch,
useEnterSubmit,
} from "@dub/ui";
@@ -332,24 +335,33 @@ export default function AddOAuthAppForm({
<InfoTooltip content="Provide some details about your integration. This will be displayed on the integration page. Markdown is supported." />
</label>
<div className="relative mt-2 rounded-md shadow-sm">
- <TextareaAutosize
- name="readme"
- minRows={10}
- className={cn(
- "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",
- {
- "cursor-not-allowed bg-neutral-50": !canManageApp,
- },
- )}
- placeholder="## My Awesome Integration"
- value={readme || ""}
- maxLength={1000}
- onChange={(e) => {
- setData({ ...data, readme: e.target.value });
- }}
- onKeyDown={handleKeyDown}
- disabled={!canManageApp}
- />
+ <RichTextProvider
+ editable={canManageApp}
+ features={["headings", "bold", "italic", "links"]}
+ style="relaxed"
+ markdown
+ placeholder="Provide details about the application"
+ editorClassName="block max-h-64 min-h-32 overflow-auto scrollbar-hide w-full resize-none border-none p-3 text-base sm:text-sm"
+ initialValue={readme || ""}
+ onChange={(editor) =>
+ setData({
+ ...data,
+ readme: (editor as any).getMarkdown() || null,
+ })
+ }
+ >
+ <div
+ className={cn(
+ "border-border-subtle overflow-hidden rounded-md border border-neutral-300 shadow-sm focus-within:border-neutral-500 focus-within:ring-1 focus-within:ring-neutral-500",
+ !canManageApp && "cursor-not-allowed bg-neutral-50",
+ )}
+ >
+ <div className="flex flex-col">
+ <RichTextArea />
+ <RichTextToolbar className="px-1 pb-1" />
+ </div>
+ </div>
+ </RichTextProvider>
</div>
</div>
diff --git a/apps/web/ui/oauth-apps/add-edit-integration-form.tsx b/apps/web/ui/oauth-apps/add-edit-integration-form.tsx
index e11b273040..8a928d9bab 100644
--- a/apps/web/ui/oauth-apps/add-edit-integration-form.tsx
+++ b/apps/web/ui/oauth-apps/add-edit-integration-form.tsx
@@ -10,6 +10,9 @@ import {
FileUpload,
InfoTooltip,
LoadingSpinner,
+ RichTextArea,
+ RichTextProvider,
+ RichTextToolbar,
useEnterSubmit,
} from "@dub/ui";
import { cn } from "@dub/utils";
@@ -238,24 +241,33 @@ export default function AddEditIntegrationForm({
<InfoTooltip content="Provide some details about your integration. This will be displayed on the integration page. Markdown is supported." />
</label>
<div className="relative mt-2 rounded-md shadow-sm">
- <TextareaAutosize
- name="readme"
- minRows={10}
- className={cn(
- "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",
- {
- "cursor-not-allowed bg-neutral-50": !canManageApp,
- },
- )}
- placeholder="## My Awesome Integration"
- value={readme || ""}
- maxLength={1000}
- onChange={(e) => {
- setData({ ...data, readme: e.target.value });
- }}
- onKeyDown={handleKeyDown}
- disabled={!canManageApp}
- />
+ <RichTextProvider
+ editable={canManageApp}
+ features={["headings", "bold", "italic", "links"]}
+ style="relaxed"
+ markdown
+ placeholder="Provide details about the integration"
+ editorClassName="block max-h-64 min-h-32 overflow-auto scrollbar-hide w-full resize-none border-none p-3 text-base sm:text-sm"
+ initialValue={readme || ""}
+ onChange={(editor) =>
+ setData({
+ ...data,
+ readme: (editor as any).getMarkdown() || null,
+ })
+ }
+ >
+ <div
+ className={cn(
+ "border-border-subtle overflow-hidden rounded-md border border-neutral-300 shadow-sm focus-within:border-neutral-500 focus-within:ring-1 focus-within:ring-neutral-500",
+ !canManageApp && "cursor-not-allowed bg-neutral-50",
+ )}
+ >
+ <div className="flex flex-col">
+ <RichTextArea />
+ <RichTextToolbar className="px-1 pb-1" />
+ </div>
+ </div>
+ </RichTextProvider>
</div>
</div>
diff --git a/apps/web/ui/partners/bounties/claim-bounty-modal.tsx b/apps/web/ui/partners/bounties/claim-bounty-modal.tsx
index 32c71a1bf1..45f0f08141 100644
--- a/apps/web/ui/partners/bounties/claim-bounty-modal.tsx
+++ b/apps/web/ui/partners/bounties/claim-bounty-modal.tsx
@@ -21,6 +21,7 @@ import {
Gift,
LoadingSpinner,
Modal,
+ PROSE_STYLES,
StatusBadge,
Trash,
buttonVariants,
@@ -415,7 +416,9 @@ function ClaimBountyModalContent({ bounty }: ClaimBountyModalProps) {
Details
</span>
<p className="text-content-subtle font-medium">
- <Markdown className="p-0">{bounty.description}</Markdown>
+ <Markdown className={cn("p-0", PROSE_STYLES.default)}>
+ {bounty.description}
+ </Markdown>
</p>
</div>
)}
diff --git a/apps/web/ui/shared/max-characters-counter.tsx b/apps/web/ui/shared/max-characters-counter.tsx
index 0f519e1f3f..72a3f871fc 100644
--- a/apps/web/ui/shared/max-characters-counter.tsx
+++ b/apps/web/ui/shared/max-characters-counter.tsx
@@ -1,22 +1,26 @@
-import { cn } from "@dub/utils";
+import { cn, nFormatter } from "@dub/utils";
import { Control, useWatch } from "react-hook-form";
export function MaxCharactersCounter({
name,
maxLength,
control,
+ spaced,
className,
}: {
name: string;
maxLength: number;
control?: Control<any, any>;
+ spaced?: boolean;
className?: string;
}) {
const value = useWatch({ control, name });
return (
<span className={cn("text-content-subtle text-xs tabular-nums", className)}>
- {value?.toString().length || 0}/{maxLength}
+ {nFormatter(value?.toString().length || 0, { full: true })}
+ {spaced && " "}/{spaced && " "}
+ {nFormatter(maxLength, { full: true })}
</span>
);
}
diff --git a/apps/web/ui/shared/message-input.tsx b/apps/web/ui/shared/message-input.tsx
index ba1053a1d6..4d8fabbf65 100644
--- a/apps/web/ui/shared/message-input.tsx
+++ b/apps/web/ui/shared/message-input.tsx
@@ -53,10 +53,11 @@ export function MessageInput({
<RichTextProvider
ref={richTextRef}
features={["bold", "italic", "links"]}
+ style="condensed"
markdown
autoFocus={autoFocus}
placeholder={placeholder}
- editorClassName="block max-h-24 w-full resize-none border-none p-3 text-base sm:text-sm"
+ editorClassName="block max-h-24 w-full resize-none border-none overflow-auto scrollbar-hide p-3 text-base sm:text-sm"
onChange={(editor) => setTypedMessage((editor as any).getMarkdown())}
editorProps={{
handleDOMEvents: {
diff --git a/packages/ui/src/rich-text-area/rich-text-provider.tsx b/packages/ui/src/rich-text-area/rich-text-provider.tsx
index 6e3b7b2d4c..17d3580681 100644
--- a/packages/ui/src/rich-text-area/rich-text-provider.tsx
+++ b/packages/ui/src/rich-text-area/rich-text-provider.tsx
@@ -17,6 +17,12 @@ import {
} from "react";
import { suggestions } from "./variables";
+export const PROSE_STYLES = {
+ default: "prose-p:my-2 prose-ul:my-2 prose-ol:my-2",
+ condensed: "prose-p:my-0 prose-ul:my-2 prose-ol:my-2",
+ relaxed: "",
+} as const;
+
const FEATURES = [
"images",
"variables",
@@ -31,6 +37,7 @@ type RichTextProviderProps = PropsWithChildren<{
initialValue?: any;
features?: (typeof FEATURES)[number][];
markdown?: boolean;
+ style?: keyof typeof PROSE_STYLES;
onChange?: (editor: Editor) => void;
uploadImage?: (file: File) => Promise<string | null>;
variables?: string[];
@@ -68,6 +75,7 @@ export const RichTextProvider = forwardRef<
children,
features = FEATURES as any,
markdown = false,
+ style = "default",
placeholder = "Start typing...",
uploadImage,
editable,
@@ -112,7 +120,7 @@ export const RichTextProvider = forwardRef<
);
const editor = useEditor({
- editable: editable,
+ editable: editable ?? true, // Explicitly pass `true` to make sure placeholder works
autofocus: autoFocus ? "end" : false,
extensions: [
...(markdown ? [Markdown] : []),
@@ -194,7 +202,9 @@ export const RichTextProvider = forwardRef<
attributes: {
...editorProps?.attributes,
class: cn(
- "prose prose-sm prose-neutral max-w-none focus:outline-none",
+ "max-w-none focus:outline-none",
+ "prose prose-sm prose-neutral",
+ PROSE_STYLES[style],
"[&_.ProseMirror-selectednode]:outline [&_.ProseMirror-selectednode]:outline-2 [&_.ProseMirror-selectednode]:outline-blue-500 [&_.ProseMirror-selectednode]:outline-offset-2",
editorClassName,
),