Skip to content
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

Fix inline styles for CodeBlock component #2444

Merged
merged 2 commits into from
Nov 27, 2024
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
8 changes: 2 additions & 6 deletions src/lib/holocene/code-block.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import { EditorState } from '@codemirror/state';
import { EditorView, keymap } from '@codemirror/view';
import { createEventDispatcher, onMount } from 'svelte';
import { twMerge as merge } from 'tailwind-merge';

import CopyButton from '$lib/holocene/copyable/button.svelte';
import { copyToClipboard } from '$lib/utilities/copy-to-clipboard';
Expand All @@ -27,7 +26,6 @@
} from '$lib/utilities/parse-with-big-int';
import {
TEMPORAL_SYNTAX,
TEMPORAL_SYNTAX_DARK,
TEMPORAL_THEME,
} from '$lib/vendor/codemirror/theme';

Expand Down Expand Up @@ -113,9 +111,7 @@
const extensions = [
keymap.of([...standardKeymap, ...historyKeymap]),
TEMPORAL_THEME(isDark),
syntaxHighlighting(isDark ? TEMPORAL_SYNTAX_DARK : TEMPORAL_SYNTAX, {
fallback: true,
}),
syntaxHighlighting(TEMPORAL_SYNTAX, { fallback: true }),
indentUnit.of(' '),
closeBrackets(),
autocompletion(),
Expand Down Expand Up @@ -195,7 +191,7 @@
<div class="relative min-w-[80px] grow">
<div
bind:this={editor}
class={merge('surface-primary rounded border-2 border-subtle', className)}
class={className}
class:inline
data-testid={$$props.testId}
class:editable
Expand Down
2 changes: 1 addition & 1 deletion src/lib/theme/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const variables = {
dark: 'yellow.500',
},
'--color-text-pink': {
light: 'pink.500',
light: 'pink.800',
dark: 'pink.400',
},
'--color-text-brand': {
Expand Down
37 changes: 15 additions & 22 deletions src/lib/vendor/codemirror/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@ import { EditorView } from '@codemirror/view';
import { tags } from '@lezer/highlight';
import colors from 'tailwindcss/colors';

import { css } from '$lib/theme/utilities';

export const TEMPORAL_THEME = (isDark) =>
EditorView.theme(
{
'&': {
color: css('--color-text-primary'),
backgroundColor: css('--color-surface-primary'),
borderRadius: '0.25rem',
borderWidth: '2px',
borderColor: css('--color-border-subtle'),
padding: '0.5rem',
},
'.cm-scroller': {
fontFamily: 'Consolas, Monaco, "Andale Mono", "Ubuntu Mono", monospace',
},
'.cm-content': {
caretColor: css('--color-text-primary'),
fontSize: '0.875em',
},
'.cm-editor&.cm-focused': {
Expand All @@ -29,28 +36,14 @@ export const TEMPORAL_THEME = (isDark) =>

export const TEMPORAL_SYNTAX = HighlightStyle.define(
[
{ tag: tags.punctuation, color: colors.slate['800'] },
{ tag: tags.string, color: colors.slate['800'] },
{ tag: tags.propertyName, color: colors.indigo['600'] },
{ tag: tags.bool, color: colors.slate['800'] },
{ tag: tags.number, color: colors.slate['800'] },
{ tag: tags.operator, color: colors.pink['400'] },
{ tag: tags.comment, color: colors.green['400'] },
{ tag: tags.variableName, color: colors.pink['600'] },
{ tag: tags.punctuation, color: css('--color-text-primary') },
{ tag: tags.string, color: css('--color-text-primary') },
{ tag: tags.propertyName, color: css('--color-text-brand') },
{ tag: tags.bool, color: css('--color-text-primary') },
{ tag: tags.number, color: css('--color-text-primary') },
{ tag: tags.operator, color: css('--color-text-pink') },
{ tag: tags.comment, color: css('--color-text-success') },
{ tag: tags.variableName, color: css('--color-text-pink') },
],
{ themeType: 'light' },
);

export const TEMPORAL_SYNTAX_DARK = HighlightStyle.define(
[
{ tag: tags.punctuation, color: colors.slate['200'] },
{ tag: tags.string, color: colors.slate['200'] },
{ tag: tags.propertyName, color: colors.indigo['400'] },
{ tag: tags.bool, color: colors.slate['200'] },
{ tag: tags.number, color: colors.slate['200'] },
{ tag: tags.operator, color: colors.pink['500'] },
{ tag: tags.comment, color: colors.green['600'] },
{ tag: tags.variableName, color: colors.pink['500'] },
],
{ themeType: 'dark' },
);
Loading