Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

feat(harper-editor): add a dark mode (#4729)

Elijah Potter14f6c0f21efd
diff --git a/packages/harper-editor/src/lib/Editor.stories.svelte b/packages/harper-editor/src/lib/Editor.stories.svelte
index 437f11d17..654674962 100644
--- a/packages/harper-editor/src/lib/Editor.stories.svelte
+++ b/packages/harper-editor/src/lib/Editor.stories.svelte
@@ -13,3 +13,4 @@ const { Story } = defineMeta({
await waitFor(() => expect(canvasElement.querySelector('.harper-editor-surface')).not.toBeNull(), { timeout: 30000 });
}} />
<Story name="Empty" args={{ content: '' }} />
+<Story name="Dark" args={{ dark: true }} />
diff --git a/packages/harper-editor/src/lib/Editor.svelte b/packages/harper-editor/src/lib/Editor.svelte
index c808e7ef7..73aff6285 100644
--- a/packages/harper-editor/src/lib/Editor.svelte
+++ b/packages/harper-editor/src/lib/Editor.svelte
@@ -19,6 +19,13 @@ import {
import LintSidebar from './LintSidebar.svelte';
import StatusBar from './StatusBar.svelte';
+/**
+ * Harper editor shell: a Quill document surface, a problems sidebar, and a
+ * status bar, all linted through `lint-framework`.
+ * The editor switches to its dark palette under a `.dark` ancestor through
+ * Tailwind `dark:` variants; it does not read `prefers-color-scheme` itself.
+ */
+
/** Who initiated an action on the sidebar. Automated actions can be overwritten by anyone, user actions can only be overwritten by the user. */
type SidebarAction = 'user' | 'automated';
@@ -317,12 +324,12 @@ function hideSidebar(reason: SidebarAction = 'automated'): void {
</script>
<div
- class="harper-editor @container flex h-full min-h-0 w-full flex-col overflow-hidden rounded-[10px] border-[0.5px] border-[rgba(28,26,22,0.14)] bg-[#fbfaf6] text-stone-950 shadow-2xl shadow-stone-950/5"
+ class="harper-editor @container flex h-full min-h-0 w-full flex-col overflow-hidden rounded-[10px] border-[0.5px] border-[rgba(28,26,22,0.14)] bg-[#fbfaf6] text-stone-950 shadow-2xl shadow-stone-950/5 dark:border-white/10 dark:bg-stone-900 dark:text-stone-100 dark:shadow-black/30"
style={editorStyle}
bind:this={editorContainer}
>
<div class="flex min-h-0 min-w-0 flex-1">
- <section class="relative min-w-0 flex-1 bg-[#fbfaf6]" aria-label="Document editor">
+ <section class="relative min-w-0 flex-1 bg-[#fbfaf6] dark:bg-stone-900" aria-label="Document editor">
<div class="h-full overflow-auto p-[34px_40px_56px] @max-[760px]:p-[28px_24px_42px]">
<div class="mx-auto flex min-h-full max-w-[640px]">
<div bind:this={editor} class="flex min-h-full w-full flex-1" spellcheck="false"></div>
@@ -332,7 +339,7 @@ function hideSidebar(reason: SidebarAction = 'automated'): void {
<DelayedRender active={!sidebarVisible} delayMs={restoreButtonDelay}>
<button
type="button"
- class="absolute top-3 right-3 z-20 inline-flex h-8 w-8 items-center justify-center rounded-md border-0 bg-transparent text-stone-600 shadow-none transition-colors duration-150 hover:text-stone-950 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500"
+ class="absolute top-3 right-3 z-20 inline-flex h-8 w-8 items-center justify-center rounded-md border-0 bg-transparent text-stone-600 shadow-none transition-colors duration-150 hover:text-stone-950 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500 dark:text-stone-400 dark:hover:text-stone-100"
aria-label="Show problems sidebar"
title="Show problems sidebar"
in:fade={{ duration: 120 }}
diff --git a/packages/harper-editor/src/lib/LintCard.stories.svelte b/packages/harper-editor/src/lib/LintCard.stories.svelte
index ec19163dd..112efb07f 100644
--- a/packages/harper-editor/src/lib/LintCard.stories.svelte
+++ b/packages/harper-editor/src/lib/LintCard.stories.svelte
@@ -20,3 +20,10 @@ const { Story } = defineMeta({
<Story name="Closed" />
<Story name="Open" args={{ open: true, active: true }} />
<Story name="No suggestions" args={{ open: true, lint: { ...exampleLint, suggestions: [] } }} />
+<Story name="Dark open" args={{ open: true, active: true }}>
+ {#snippet template(args)}
+ <div class="dark rounded-xl bg-stone-950 p-4">
+ <LintCard {...args} />
+ </div>
+ {/snippet}
+</Story>
diff --git a/packages/harper-editor/src/lib/LintCard.svelte b/packages/harper-editor/src/lib/LintCard.svelte
index fb7496cf1..4e9c219f8 100644
--- a/packages/harper-editor/src/lib/LintCard.svelte
+++ b/packages/harper-editor/src/lib/LintCard.svelte
@@ -56,8 +56,8 @@ function handleFocus() {
<div
bind:this={cardEl}
role="group"
- class={`shrink-0 overflow-hidden rounded-[10px] border-[0.5px] bg-white shadow-sm shadow-stone-950/5 transition-[box-shadow,border-color] duration-150 ${
- active ? lintKindStyle.activeClass : 'border-[rgba(28,26,22,0.14)]'
+ class={`shrink-0 overflow-hidden rounded-[10px] border-[0.5px] bg-white shadow-sm shadow-stone-950/5 transition-[box-shadow,border-color] duration-150 dark:bg-stone-900 dark:shadow-black/20 ${
+ active ? lintKindStyle.activeClass : 'border-[rgba(28,26,22,0.14)] dark:border-white/10'
}`}
on:mouseenter={onActivate}
>
@@ -72,11 +72,11 @@ function handleFocus() {
>
<span class={`h-[7px] w-[7px] rounded-full ${lintKindStyle.dotClass}`}></span>
</span>
- <span class="text-[12.5px] leading-[1.1] font-semibold text-stone-950">
+ <span class="text-[12.5px] leading-[1.1] font-semibold text-stone-950 dark:text-stone-100">
{lintKindStyle.label}
</span>
<span
- class={`ml-auto inline-flex shrink-0 text-stone-500 transition-transform duration-150 ${
+ class={`ml-auto inline-flex shrink-0 text-stone-500 transition-transform duration-150 dark:text-stone-400 ${
open ? 'rotate-180' : ''
}`}
>
@@ -90,7 +90,7 @@ function handleFocus() {
<div class="flex flex-col gap-2.5 px-3 pt-0.5 pb-3" in:slide={{ duration: 130 }} out:slide={{ duration: 130 }}>
<button
type="button"
- class="m-0 flex w-full flex-col border-0 bg-transparent p-0 text-left text-[13px] leading-[1.4] font-medium text-stone-950"
+ class="m-0 flex w-full flex-col border-0 bg-transparent p-0 text-left text-[13px] leading-[1.4] font-medium text-stone-950 dark:text-stone-100"
on:click={handleFocus}
>
<span>{@html lint.message_html}</span>
@@ -98,18 +98,18 @@ function handleFocus() {
<button
type="button"
- class="m-0 block max-h-[84px] w-full overflow-hidden rounded-[7px] border-[0.5px] border-[rgba(28,26,22,0.09)] bg-[#fbfaf6] px-3 py-2.5 text-left text-xs leading-[1.45] text-stone-700"
+ class="m-0 block max-h-[84px] w-full overflow-hidden rounded-[7px] border-[0.5px] border-[rgba(28,26,22,0.09)] bg-[#fbfaf6] px-3 py-2.5 text-left text-xs leading-[1.45] text-stone-700 dark:border-white/10 dark:bg-stone-950 dark:text-stone-300"
on:click={handleFocus}
aria-label="Focus problem in editor"
>
- <span class="text-stone-500">
+ <span class="text-stone-500 dark:text-stone-400">
{snippet.prefixEllipsis ? '...' : ''}{snippet.prefix}
</span>
<mark
class={`rounded-[3px] px-0.5 font-semibold ${lintKindStyle.softClass} ${lintKindStyle.textClass}`}
>{snippet.problem}</mark
>
- <span class="text-stone-500">
+ <span class="text-stone-500 dark:text-stone-400">
{snippet.suffix}{snippet.suffixEllipsis ? '...' : ''}
</span>
</button>
@@ -123,7 +123,7 @@ function handleFocus() {
class={`${baseSuggestionClass} ${
i === 0
? `border-transparent ${lintKindStyle.softClass} ${lintKindStyle.textClass} shadow-none`
- : 'border-[0.5px] border-stone-300 bg-linear-to-b from-white to-stone-50 text-stone-950 shadow-sm shadow-stone-950/5'
+ : 'border-[0.5px] border-stone-300 bg-linear-to-b from-white to-stone-50 text-stone-950 shadow-sm shadow-stone-950/5 dark:border-white/15 dark:from-stone-800 dark:to-stone-900 dark:text-stone-100 dark:shadow-black/20'
}`}
title={`Replace with "${suggestionText(suggestion)}"`}
on:click={(event) => {
@@ -136,12 +136,12 @@ function handleFocus() {
{/each}
</div>
{:else}
- <span class="mr-auto text-xs text-stone-400">No suggestions available.</span>
+ <span class="mr-auto text-xs text-stone-400 dark:text-stone-500">No suggestions available.</span>
{/if}
<button
type="button"
- class="h-[26px] shrink-0 border-0 bg-transparent px-1 text-[12.5px] font-medium text-stone-500 shadow-none"
+ class="h-[26px] shrink-0 border-0 bg-transparent px-1 text-[12.5px] font-medium text-stone-500 shadow-none dark:text-stone-400"
on:click={(event) => {
event.stopPropagation();
onIgnore();
diff --git a/packages/harper-editor/src/lib/LintSidebar.stories.svelte b/packages/harper-editor/src/lib/LintSidebar.stories.svelte
index 24ec4716b..af23afeb6 100644
--- a/packages/harper-editor/src/lib/LintSidebar.stories.svelte
+++ b/packages/harper-editor/src/lib/LintSidebar.stories.svelte
@@ -10,3 +10,5 @@ const { Story } = defineMeta({
<Story name="With problems" />
<Story name="All clear" args={{ populated: false }} />
+<Story name="Dark with problems" args={{ dark: true }} />
+<Story name="Dark all clear" args={{ dark: true, populated: false }} />
diff --git a/packages/harper-editor/src/lib/LintSidebar.svelte b/packages/harper-editor/src/lib/LintSidebar.svelte
index ede9811b3..2cae33013 100644
--- a/packages/harper-editor/src/lib/LintSidebar.svelte
+++ b/packages/harper-editor/src/lib/LintSidebar.svelte
@@ -22,11 +22,11 @@ let menuOpen = false;
let showIgnoreConfirm = false;
const iconButtonClass =
- 'inline-flex h-7 w-7 items-center justify-center rounded-md border-0 bg-transparent text-stone-600 shadow-none transition-colors duration-150 hover:text-stone-950 disabled:opacity-50';
+ 'inline-flex h-7 w-7 items-center justify-center rounded-md border-0 bg-transparent text-stone-600 shadow-none transition-colors duration-150 hover:text-stone-950 disabled:opacity-50 dark:text-stone-400 dark:hover:text-stone-100';
const menuItemClass =
- 'm-0 flex h-8 w-full items-center border-0 bg-transparent px-3 text-left text-[13px] font-medium text-stone-700 shadow-none hover:bg-stone-100 disabled:text-stone-300 disabled:hover:bg-transparent';
+ 'm-0 flex h-8 w-full items-center border-0 bg-transparent px-3 text-left text-[13px] font-medium text-stone-700 shadow-none hover:bg-stone-100 disabled:text-stone-300 disabled:hover:bg-transparent dark:text-stone-200 dark:hover:bg-white/5 dark:disabled:text-stone-600';
const dangerMenuItemClass =
- 'm-0 flex h-8 w-full items-center border-0 bg-transparent px-3 text-left text-[13px] font-medium text-red-700 shadow-none hover:bg-red-50 disabled:text-stone-300 disabled:hover:bg-transparent';
+ 'm-0 flex h-8 w-full items-center border-0 bg-transparent px-3 text-left text-[13px] font-medium text-red-700 shadow-none hover:bg-red-50 disabled:text-stone-300 disabled:hover:bg-transparent dark:text-red-400 dark:hover:bg-red-950/40 dark:disabled:text-stone-600';
$: allOpen = lintBoxes.length > 0 && openSet.size === lintBoxes.length;
$: problemCountLabel = `${lintBoxes.length} ${lintBoxes.length === 1 ? 'problem' : 'problems'}`;
@@ -167,14 +167,14 @@ function createSnippetFor(lintBox: LintBox) {
<svelte:window on:click={handleWindowClick} on:keydown={handleWindowKeydown} />
<aside
- class="flex min-h-0 w-[320px] flex-[0_0_320px] overflow-hidden border-l-[0.5px] border-[rgba(28,26,22,0.14)] bg-[#f4f0e7] @max-[760px]:w-full @max-[760px]:flex-[0_0_42%] @max-[760px]:border-t-[0.5px] @max-[760px]:border-l-0"
+ class="flex min-h-0 w-[320px] flex-[0_0_320px] overflow-hidden border-l-[0.5px] border-[rgba(28,26,22,0.14)] bg-[#f4f0e7] @max-[760px]:w-full @max-[760px]:flex-[0_0_42%] @max-[760px]:border-t-[0.5px] @max-[760px]:border-l-0 dark:border-white/10 dark:bg-stone-950"
aria-label="Problems"
transition:fly={{ x: 320, duration: 250, easing: cubicOut }}
>
<div class="flex min-h-0 flex-1 flex-col" transition:fade={{ duration: 250 }}>
<header class="flex items-center gap-1.5 px-3.5 pt-2.5 pb-2">
<h2
- class="m-0! flex min-w-0 flex-1 items-center p-0! text-[15px]! leading-none! font-bold! text-stone-950 font-[inherit]!"
+ class="m-0! flex min-w-0 flex-1 items-center p-0! text-[15px]! leading-none! font-bold! text-stone-950 font-[inherit]! dark:text-stone-100"
>
<button
type="button"
@@ -189,7 +189,7 @@ function createSnippetFor(lintBox: LintBox) {
{lintBoxes.length}
</span>
<span
- class={`inline-flex shrink-0 text-stone-500 transition-transform duration-150 ${
+ class={`inline-flex shrink-0 text-stone-500 transition-transform duration-150 dark:text-stone-400 ${
showLintKindCounts ? 'rotate-180' : ''
}`}
>
@@ -242,7 +242,7 @@ function createSnippetFor(lintBox: LintBox) {
<div
id="problem-actions-menu"
role="menu"
- class="absolute top-[calc(100%+6px)] right-0 z-30 w-36 overflow-hidden rounded-lg border-[0.5px] border-[rgba(28,26,22,0.16)] bg-white py-1 shadow-lg shadow-stone-950/10"
+ class="absolute top-[calc(100%+6px)] right-0 z-30 w-36 overflow-hidden rounded-lg border-[0.5px] border-[rgba(28,26,22,0.16)] bg-white py-1 shadow-lg shadow-stone-950/10 dark:border-white/10 dark:bg-stone-900 dark:shadow-black/40"
transition:fade={{ duration: 100 }}
>
<button
@@ -263,7 +263,7 @@ function createSnippetFor(lintBox: LintBox) {
>
Close All
</button>
- <div class="my-1 h-px bg-[rgba(28,26,22,0.09)]"></div>
+ <div class="my-1 h-px bg-[rgba(28,26,22,0.09)] dark:bg-white/10"></div>
<button
type="button"
role="menuitem"
@@ -280,12 +280,12 @@ function createSnippetFor(lintBox: LintBox) {
{#if showLintKindCounts && visibleLintKindEntries.length > 0}
<div
- class="grid grid-cols-3 gap-x-2 gap-y-[7px] overflow-hidden border-b-[0.5px] border-[rgba(28,26,22,0.09)] px-[18px] pb-3"
+ class="grid grid-cols-3 gap-x-2 gap-y-[7px] overflow-hidden border-b-[0.5px] border-[rgba(28,26,22,0.09)] px-[18px] pb-3 dark:border-white/10"
aria-label="Problem lint kinds"
>
{#each visibleLintKindEntries as [key, lintKindStyle]}
<div
- class="grid min-w-0 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-1 whitespace-nowrap text-[10px] font-medium text-stone-500"
+ class="grid min-w-0 grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-1 whitespace-nowrap text-[10px] font-medium text-stone-500 dark:text-stone-400"
>
<span
class={`inline-flex h-[9px] w-[9px] shrink-0 items-center justify-center rounded-full ${lintKindStyle.haloClass}`}
@@ -293,7 +293,7 @@ function createSnippetFor(lintBox: LintBox) {
<span class={`h-[7px] w-[7px] rounded-full ${lintKindStyle.dotClass}`}></span>
</span>
<span class="overflow-hidden text-ellipsis">{lintKindStyle.label}</span>
- <strong class="font-medium text-stone-400 tabular-nums">{counts[key]}</strong>
+ <strong class="font-medium text-stone-400 tabular-nums dark:text-stone-500">{counts[key]}</strong>
</div>
{/each}
</div>
@@ -302,7 +302,7 @@ function createSnippetFor(lintBox: LintBox) {
<div class="flex min-h-0 flex-1 flex-col gap-2 overflow-auto px-3.5 pt-3.5 pb-6" data-problems-scroller>
{#if lintBoxes.length === 0}
<div
- class="m-auto max-w-[220px] px-3 py-7 text-center text-[12.5px] leading-[1.55] text-stone-500"
+ class="m-auto max-w-[220px] px-3 py-7 text-center text-[12.5px] leading-[1.55] text-stone-500 dark:text-stone-400"
>
<div
aria-hidden="true"
@@ -315,7 +315,7 @@ function createSnippetFor(lintBox: LintBox) {
<path d="M3.5 8.5 6.5 11.5 12.5 5" />
</svg>
</div>
- <strong class="mb-0.5 block font-semibold text-stone-950">All clear</strong>
+ <strong class="mb-0.5 block font-semibold text-stone-950 dark:text-stone-100">All clear</strong>
<p class="m-0">Harper has no suggestions for this document.</p>
</div>
{:else}
@@ -352,7 +352,7 @@ function createSnippetFor(lintBox: LintBox) {
on:click={handleIgnoreBackdropClick}
>
<div
- class="w-full max-w-[340px] rounded-lg border-[0.5px] border-[rgba(28,26,22,0.16)] bg-white p-4 text-stone-950 shadow-2xl shadow-stone-950/20"
+ class="w-full max-w-[340px] rounded-lg border-[0.5px] border-[rgba(28,26,22,0.16)] bg-white p-4 text-stone-950 shadow-2xl shadow-stone-950/20 dark:border-white/10 dark:bg-stone-900 dark:text-stone-100 dark:shadow-black/50"
role="dialog"
aria-modal="true"
aria-labelledby="ignore-all-title"
@@ -361,13 +361,13 @@ function createSnippetFor(lintBox: LintBox) {
<h3 id="ignore-all-title" class="!m-0 !p-0 text-[15px] leading-5 font-semibold">
Ignore all problems?
</h3>
- <p class="mt-2 mb-4 text-[13px] leading-5 text-stone-600">
+ <p class="mt-2 mb-4 text-[13px] leading-5 text-stone-600 dark:text-stone-400">
This will ignore {problemCountLabel} in the current document.
</p>
<div class="flex justify-end gap-2">
<button
type="button"
- class="h-8 rounded-md border-[0.5px] border-stone-300 bg-linear-to-b from-white to-stone-50 px-3 text-[13px] font-medium text-stone-700 shadow-sm shadow-stone-950/5"
+ class="h-8 rounded-md border-[0.5px] border-stone-300 bg-linear-to-b from-white to-stone-50 px-3 text-[13px] font-medium text-stone-700 shadow-sm shadow-stone-950/5 dark:border-white/15 dark:from-stone-800 dark:to-stone-900 dark:text-stone-200 dark:shadow-black/20"
on:click={cancelIgnoreAll}
>
Cancel
diff --git a/packages/harper-editor/src/lib/StatusBar.svelte b/packages/harper-editor/src/lib/StatusBar.svelte
index 8b07e3490..aba06d3fd 100644
--- a/packages/harper-editor/src/lib/StatusBar.svelte
+++ b/packages/harper-editor/src/lib/StatusBar.svelte
@@ -15,14 +15,14 @@ export let onFontFamilyChange: (fontFamily: EditorFontFamily) => void = () => {}
export let onFontSizeChange: (fontSize: EditorFontSize) => void = () => {};
const fontButtonClass =
- 'inline-flex h-4 min-w-7 items-center justify-center rounded px-2 text-xs leading-none font-medium text-stone-500';
+ 'inline-flex h-4 min-w-7 items-center justify-center rounded px-2 text-xs leading-none font-medium text-stone-500 dark:text-stone-400';
$: words = wordCount(text);
$: chars = text.length;
</script>
<footer
- class="flex min-h-[26px] flex-[0_0_26px] items-center gap-3.5 border-t-[0.5px] border-[rgba(28,26,22,0.09)] bg-[#f4f0e7] px-2 pr-2 pl-3.5 text-[11px] whitespace-nowrap text-stone-500 tabular-nums [font-family:'JetBrains_Mono',ui-monospace,'SF_Mono',Menlo,monospace] @max-[760px]:h-auto @max-[760px]:min-h-[30px] @max-[760px]:flex-wrap @max-[760px]:gap-y-1.5 @max-[760px]:py-[5px]"
+ class="flex min-h-[26px] flex-[0_0_26px] items-center gap-3.5 border-t-[0.5px] border-[rgba(28,26,22,0.09)] bg-[#f4f0e7] dark:border-white/10 dark:bg-stone-950 dark:text-stone-400 px-2 pr-2 pl-3.5 text-[11px] whitespace-nowrap text-stone-500 tabular-nums [font-family:'JetBrains_Mono',ui-monospace,'SF_Mono',Menlo,monospace] @max-[760px]:h-auto @max-[760px]:min-h-[30px] @max-[760px]:flex-wrap @max-[760px]:gap-y-1.5 @max-[760px]:py-[5px]"
aria-label="Editor status"
>
<div class="inline-flex items-center gap-2">
@@ -40,14 +40,14 @@ $: chars = text.length;
</span>
</div>
- <span class="h-2.5 w-px bg-[rgba(28,26,22,0.14)]"></span>
+ <span class="h-2.5 w-px bg-[rgba(28,26,22,0.14)] dark:bg-white/15"></span>
<span>{words} words</span>
<span>{chars} chars</span>
<span class="flex-1"></span>
<div
- class="inline-flex h-[18px] items-center rounded-[5px] border-[0.5px] border-stone-200 bg-stone-200/60 p-px"
+ class="inline-flex h-[18px] items-center rounded-[5px] border-[0.5px] border-stone-200 bg-stone-200/60 p-px dark:border-white/10 dark:bg-white/5"
aria-label="Font family"
>
{#each FONT_OPTIONS as option}
@@ -55,7 +55,7 @@ $: chars = text.length;
type="button"
class={`${fontButtonClass} ${
fontFamily === option.value
- ? 'bg-white font-bold text-stone-950 shadow-sm shadow-stone-950/10'
+ ? 'bg-white font-bold text-stone-950 shadow-sm shadow-stone-950/10 dark:bg-stone-700! dark:text-stone-100 dark:shadow-black/30'
: ''
}`}
style={`font-family: ${option.stack}`}
@@ -70,7 +70,7 @@ $: chars = text.length;
</div>
<label
- class="relative inline-flex h-[18px] items-center rounded-[5px] border-[0.5px] border-stone-200 bg-stone-200/60 pr-[18px] pl-2 text-[11px] font-medium text-stone-950 after:absolute after:top-1/2 after:right-[5px] after:-translate-y-1/2 after:text-[9px] after:leading-none after:text-stone-500 after:content-['v'] after:[font-family:-apple-system,BlinkMacSystemFont,'SF_Pro_Text',sans-serif]"
+ class="relative inline-flex h-[18px] items-center rounded-[5px] border-[0.5px] border-stone-200 bg-stone-200/60 pr-[18px] pl-2 text-[11px] font-medium text-stone-950 dark:border-white/10 dark:bg-white/5 dark:text-stone-100 dark:after:text-stone-400 after:absolute after:top-1/2 after:right-[5px] after:-translate-y-1/2 after:text-[9px] after:leading-none after:text-stone-500 after:content-['v'] after:[font-family:-apple-system,BlinkMacSystemFont,'SF_Pro_Text',sans-serif]"
>
<span>{fontSize === 'default' ? 'Default' : `${fontSize}px`}</span>
<select
diff --git a/packages/harper-editor/src/lib/editorDisplay.ts b/packages/harper-editor/src/lib/editorDisplay.ts
index 03e4932d5..8278ee4db 100644
--- a/packages/harper-editor/src/lib/editorDisplay.ts
+++ b/packages/harper-editor/src/lib/editorDisplay.ts
@@ -75,7 +75,9 @@ export const LINT_KIND_ORDER: LintKind[] = [
*
* Keeping these classes here lets the editor share one visual language across
* cards, counts, and active states without spreading Tailwind class maps through
- * Svelte components.
+ * Svelte components. Every class string except `dotClass` also carries its
+ * `dark:` variant, so the palette follows a `.dark` ancestor without extra
+ * logic in components.
*/
export const LINT_KIND_STYLES: Record<
LintKind,
@@ -91,170 +93,191 @@ export const LINT_KIND_STYLES: Record<
Agreement: {
label: 'Agreement',
dotClass: 'bg-emerald-500',
- haloClass: 'bg-emerald-100',
- textClass: 'text-emerald-700',
- softClass: 'bg-emerald-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-emerald-500/10',
+ haloClass: 'bg-emerald-100 dark:bg-emerald-950',
+ textClass: 'text-emerald-700 dark:text-emerald-300',
+ softClass: 'bg-emerald-50 dark:bg-emerald-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-emerald-500/10 dark:border-white/15 dark:shadow-emerald-500/20',
},
BoundaryError: {
label: 'Boundary',
dotClass: 'bg-indigo-500',
- haloClass: 'bg-indigo-100',
- textClass: 'text-indigo-700',
- softClass: 'bg-indigo-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-indigo-500/10',
+ haloClass: 'bg-indigo-100 dark:bg-indigo-950',
+ textClass: 'text-indigo-700 dark:text-indigo-300',
+ softClass: 'bg-indigo-50 dark:bg-indigo-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-indigo-500/10 dark:border-white/15 dark:shadow-indigo-500/20',
},
Capitalization: {
label: 'Capitalization',
dotClass: 'bg-rose-500',
- haloClass: 'bg-rose-100',
- textClass: 'text-rose-700',
- softClass: 'bg-rose-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-rose-500/10',
+ haloClass: 'bg-rose-100 dark:bg-rose-950',
+ textClass: 'text-rose-700 dark:text-rose-300',
+ softClass: 'bg-rose-50 dark:bg-rose-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-rose-500/10 dark:border-white/15 dark:shadow-rose-500/20',
},
Eggcorn: {
label: 'Eggcorn',
dotClass: 'bg-violet-500',
- haloClass: 'bg-violet-100',
- textClass: 'text-violet-700',
- softClass: 'bg-violet-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-violet-500/10',
+ haloClass: 'bg-violet-100 dark:bg-violet-950',
+ textClass: 'text-violet-700 dark:text-violet-300',
+ softClass: 'bg-violet-50 dark:bg-violet-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-violet-500/10 dark:border-white/15 dark:shadow-violet-500/20',
},
Enhancement: {
label: 'Enhancement',
dotClass: 'bg-amber-600',
- haloClass: 'bg-amber-100',
- textClass: 'text-amber-700',
- softClass: 'bg-amber-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-amber-600/10',
+ haloClass: 'bg-amber-100 dark:bg-amber-950',
+ textClass: 'text-amber-700 dark:text-amber-300',
+ softClass: 'bg-amber-50 dark:bg-amber-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-amber-600/10 dark:border-white/15 dark:shadow-amber-600/20',
},
Formatting: {
label: 'Formatting',
dotClass: 'bg-slate-500',
- haloClass: 'bg-slate-100',
- textClass: 'text-slate-700',
- softClass: 'bg-slate-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-slate-500/10',
+ haloClass: 'bg-slate-100 dark:bg-slate-950',
+ textClass: 'text-slate-700 dark:text-slate-300',
+ softClass: 'bg-slate-50 dark:bg-slate-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-slate-500/10 dark:border-white/15 dark:shadow-slate-500/20',
},
Grammar: {
label: 'Grammar',
dotClass: 'bg-emerald-600',
- haloClass: 'bg-emerald-100',
- textClass: 'text-emerald-700',
- softClass: 'bg-emerald-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-emerald-600/10',
+ haloClass: 'bg-emerald-100 dark:bg-emerald-950',
+ textClass: 'text-emerald-700 dark:text-emerald-300',
+ softClass: 'bg-emerald-50 dark:bg-emerald-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-emerald-600/10 dark:border-white/15 dark:shadow-emerald-600/20',
},
Malapropism: {
label: 'Malapropism',
dotClass: 'bg-fuchsia-500',
- haloClass: 'bg-fuchsia-100',
- textClass: 'text-fuchsia-700',
- softClass: 'bg-fuchsia-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-fuchsia-500/10',
+ haloClass: 'bg-fuchsia-100 dark:bg-fuchsia-950',
+ textClass: 'text-fuchsia-700 dark:text-fuchsia-300',
+ softClass: 'bg-fuchsia-50 dark:bg-fuchsia-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-fuchsia-500/10 dark:border-white/15 dark:shadow-fuchsia-500/20',
},
Miscellaneous: {
label: 'Miscellaneous',
dotClass: 'bg-sky-500',
- haloClass: 'bg-sky-100',
- textClass: 'text-sky-700',
- softClass: 'bg-sky-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-sky-500/10',
+ haloClass: 'bg-sky-100 dark:bg-sky-950',
+ textClass: 'text-sky-700 dark:text-sky-300',
+ softClass: 'bg-sky-50 dark:bg-sky-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-sky-500/10 dark:border-white/15 dark:shadow-sky-500/20',
},
Nonstandard: {
label: 'Nonstandard',
dotClass: 'bg-stone-500',
- haloClass: 'bg-stone-100',
- textClass: 'text-stone-700',
- softClass: 'bg-stone-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-stone-500/10',
+ haloClass: 'bg-stone-100 dark:bg-stone-950',
+ textClass: 'text-stone-700 dark:text-stone-300',
+ softClass: 'bg-stone-50 dark:bg-stone-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-stone-500/10 dark:border-white/15 dark:shadow-stone-500/20',
},
Punctuation: {
label: 'Punctuation',
dotClass: 'bg-cyan-600',
- haloClass: 'bg-cyan-100',
- textClass: 'text-cyan-700',
- softClass: 'bg-cyan-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-cyan-600/10',
+ haloClass: 'bg-cyan-100 dark:bg-cyan-950',
+ textClass: 'text-cyan-700 dark:text-cyan-300',
+ softClass: 'bg-cyan-50 dark:bg-cyan-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-cyan-600/10 dark:border-white/15 dark:shadow-cyan-600/20',
},
Readability: {
label: 'Readability',
dotClass: 'bg-violet-600',
- haloClass: 'bg-violet-100',
- textClass: 'text-violet-700',
- softClass: 'bg-violet-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-violet-600/10',
+ haloClass: 'bg-violet-100 dark:bg-violet-950',
+ textClass: 'text-violet-700 dark:text-violet-300',
+ softClass: 'bg-violet-50 dark:bg-violet-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-violet-600/10 dark:border-white/15 dark:shadow-violet-600/20',
},
Redundancy: {
label: 'Redundancy',
dotClass: 'bg-amber-600',
- haloClass: 'bg-amber-100',
- textClass: 'text-amber-700',
- softClass: 'bg-amber-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-amber-600/10',
+ haloClass: 'bg-amber-100 dark:bg-amber-950',
+ textClass: 'text-amber-700 dark:text-amber-300',
+ softClass: 'bg-amber-50 dark:bg-amber-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-amber-600/10 dark:border-white/15 dark:shadow-amber-600/20',
},
Regionalism: {
label: 'Regionalism',
dotClass: 'bg-teal-700',
- haloClass: 'bg-teal-100',
- textClass: 'text-teal-700',
- softClass: 'bg-teal-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-teal-700/10',
+ haloClass: 'bg-teal-100 dark:bg-teal-950',
+ textClass: 'text-teal-700 dark:text-teal-300',
+ softClass: 'bg-teal-50 dark:bg-teal-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-teal-700/10 dark:border-white/15 dark:shadow-teal-700/20',
},
Repetition: {
label: 'Repetition',
dotClass: 'bg-amber-700',
- haloClass: 'bg-amber-100',
- textClass: 'text-amber-700',
- softClass: 'bg-amber-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-amber-700/10',
+ haloClass: 'bg-amber-100 dark:bg-amber-950',
+ textClass: 'text-amber-700 dark:text-amber-300',
+ softClass: 'bg-amber-50 dark:bg-amber-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-amber-700/10 dark:border-white/15 dark:shadow-amber-700/20',
},
Spelling: {
label: 'Spelling',
dotClass: 'bg-rose-500',
- haloClass: 'bg-rose-100',
- textClass: 'text-rose-700',
- softClass: 'bg-rose-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-rose-500/10',
+ haloClass: 'bg-rose-100 dark:bg-rose-950',
+ textClass: 'text-rose-700 dark:text-rose-300',
+ softClass: 'bg-rose-50 dark:bg-rose-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-rose-500/10 dark:border-white/15 dark:shadow-rose-500/20',
},
Style: {
label: 'Style',
dotClass: 'bg-blue-500',
- haloClass: 'bg-blue-100',
- textClass: 'text-blue-700',
- softClass: 'bg-blue-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-blue-500/10',
+ haloClass: 'bg-blue-100 dark:bg-blue-950',
+ textClass: 'text-blue-700 dark:text-blue-300',
+ softClass: 'bg-blue-50 dark:bg-blue-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-blue-500/10 dark:border-white/15 dark:shadow-blue-500/20',
},
Typo: {
label: 'Typo',
dotClass: 'bg-rose-500',
- haloClass: 'bg-rose-100',
- textClass: 'text-rose-700',
- softClass: 'bg-rose-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-rose-500/10',
+ haloClass: 'bg-rose-100 dark:bg-rose-950',
+ textClass: 'text-rose-700 dark:text-rose-300',
+ softClass: 'bg-rose-50 dark:bg-rose-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-rose-500/10 dark:border-white/15 dark:shadow-rose-500/20',
},
Usage: {
label: 'Usage',
dotClass: 'bg-green-600',
- haloClass: 'bg-green-100',
- textClass: 'text-green-700',
- softClass: 'bg-green-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-green-600/10',
+ haloClass: 'bg-green-100 dark:bg-green-950',
+ textClass: 'text-green-700 dark:text-green-300',
+ softClass: 'bg-green-50 dark:bg-green-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-green-600/10 dark:border-white/15 dark:shadow-green-600/20',
},
WordChoice: {
label: 'Word Choice',
dotClass: 'bg-blue-600',
- haloClass: 'bg-blue-100',
- textClass: 'text-blue-700',
- softClass: 'bg-blue-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-blue-600/10',
+ haloClass: 'bg-blue-100 dark:bg-blue-950',
+ textClass: 'text-blue-700 dark:text-blue-300',
+ softClass: 'bg-blue-50 dark:bg-blue-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-blue-600/10 dark:border-white/15 dark:shadow-blue-600/20',
},
WordOrder: {
label: 'Word Order',
dotClass: 'bg-indigo-600',
- haloClass: 'bg-indigo-100',
- textClass: 'text-indigo-700',
- softClass: 'bg-indigo-50',
- activeClass: 'border-[rgba(28,26,22,0.14)] shadow-indigo-600/10',
+ haloClass: 'bg-indigo-100 dark:bg-indigo-950',
+ textClass: 'text-indigo-700 dark:text-indigo-300',
+ softClass: 'bg-indigo-50 dark:bg-indigo-500/15',
+ activeClass:
+ 'border-[rgba(28,26,22,0.14)] shadow-indigo-600/10 dark:border-white/15 dark:shadow-indigo-600/20',
},
};
diff --git a/packages/harper-editor/src/lib/stories/EditorExample.svelte b/packages/harper-editor/src/lib/stories/EditorExample.svelte
index 6a1f5e3c6..ceb92653f 100644
--- a/packages/harper-editor/src/lib/stories/EditorExample.svelte
+++ b/packages/harper-editor/src/lib/stories/EditorExample.svelte
@@ -4,6 +4,8 @@ import { onMount } from 'svelte';
import Editor from '../Editor.svelte';
export let content = 'Try teh Harper editor. It checks your writing as you type.';
+/** Wrap the editor in a `.dark` ancestor to show its dark palette. */
+export let dark = false;
let linter: Linter | undefined;
let error = '';
@@ -30,7 +32,7 @@ onMount(() => {
});
</script>
-<div style="width: min(900px, 90vw); height: 500px;">
+<div class:dark style="width: min(900px, 90vw); height: 500px;">
{#if linter}
<Editor {content} {linter} />
{:else if error}
diff --git a/packages/harper-editor/src/lib/stories/SidebarExample.svelte b/packages/harper-editor/src/lib/stories/SidebarExample.svelte
index 7d2d62948..0de8d9dc1 100644
--- a/packages/harper-editor/src/lib/stories/SidebarExample.svelte
+++ b/packages/harper-editor/src/lib/stories/SidebarExample.svelte
@@ -4,6 +4,8 @@ import type { IgnorableLintBox } from '../types.js';
import { exampleLint } from './fixtures.js';
export let populated = true;
+/** Wrap the sidebar in a `.dark` ancestor to show its dark palette. */
+export let dark = false;
const lintBox: IgnorableLintBox = {
x: 0,
@@ -18,6 +20,8 @@ const lintBox: IgnorableLintBox = {
};
</script>
-<div class="harper-editor" style="height: 450px; display: flex;">
- <LintSidebar lintBoxes={populated ? [lintBox] : []} />
+<div class:dark>
+ <div class="harper-editor" style="height: 450px; display: flex;">
+ <LintSidebar lintBoxes={populated ? [lintBox] : []} />
+ </div>
</div>
diff --git a/packages/harper-editor/src/lib/styles.css b/packages/harper-editor/src/lib/styles.css
index 885f6d2f8..c76076c0b 100644
--- a/packages/harper-editor/src/lib/styles.css
+++ b/packages/harper-editor/src/lib/styles.css
@@ -12,6 +12,12 @@
--harper-editor-font-size: inherit;
}
+/* Dark mode starts under a `.dark` ancestor, the same as the Tailwind `dark:` variant. */
+.dark .harper-editor,
+.dark.harper-editor {
+ color-scheme: dark;
+}
+
.harper-editor *,
.harper-editor *::before,
.harper-editor *::after {
@@ -38,6 +44,11 @@
outline-offset: 2px;
}
+.dark .harper-editor button:focus-visible,
+.dark .harper-editor select:focus-visible {
+ outline-color: var(--color-blue-400);
+}
+
.harper-editor-quill-container {
display: flex;
flex: 1;
@@ -80,6 +91,10 @@
pointer-events: none;
}
+.dark .harper-editor-surface.ql-editor.ql-blank::before {
+ color: var(--color-stone-400);
+}
+
.harper-editor-surface p,
.harper-editor-surface.ql-editor p {
margin: 0;