Skip to content

Commit

Permalink
Refactor Markdown component. (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
blrchen authored Apr 6, 2024
1 parent c436af2 commit 0624b56
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 421 deletions.
2 changes: 1 addition & 1 deletion components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ const Chat = (props: ChatProps, ref: any) => {
<FiSend className="size-4" />
</IconButton>
</Tooltip>
<Tooltip content={'Clear Message'}>
<Tooltip content={'Clear History'}>
<IconButton
variant="soft"
color="gray"
Expand Down
2 changes: 2 additions & 0 deletions components/Markdown.tsx → components/Markdown/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import { useCopyToClipboard } from '@/hooks/useCopyToClipboard'

import './index.scss'

export interface MarkdownProps {
className?: string
children: string
Expand Down
18 changes: 18 additions & 0 deletions components/Markdown/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.prose {
img {
@apply max-w-3xl max-lg:max-w-full;
}

:where(pre):not(:where([class~='not-prose'], [class~='not-prose'] *)) {
position: relative;
background-color: rgb(30, 30, 30) !important;
}

:where(pre code):not(:where([class~='not-prose'], [class~='not-prose'] *)) {
@apply whitespace-pre-wrap #{!important};
}

:where(code[class~='highlight']) {
background-color: var(--accent-a5);
}
}
1 change: 1 addition & 0 deletions components/Markdown/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Markdown'
19 changes: 10 additions & 9 deletions components/Themes/ThemeProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import { Fragment, useCallback, useContext, useEffect, useMemo, useState } from 'react'
import { ThemeProviderProps } from './interface'
import { ThemeProviderProps, UseThemeProps } from './interface'
import { ThemeContext } from './ThemeContext'
import ThemeScript from './ThemeScript'
import { ColorSchemes, disableAnimation, getSystemTheme, MEDIA } from './utils'
Expand Down Expand Up @@ -141,14 +141,15 @@ const Theme = ({
}, [defaultTheme, storageKey])

const providerValue = useMemo(
() => ({
theme,
setTheme,
forcedTheme,
resolvedTheme: theme === 'system' ? resolvedTheme : theme,
themes: enableSystem ? [...themes, 'system'] : themes,
systemTheme: (enableSystem ? resolvedTheme : undefined) as 'light' | 'dark' | undefined
}),
() =>
({
theme,
setTheme,
forcedTheme,
resolvedTheme: theme === 'system' ? resolvedTheme : theme,
themes: enableSystem ? [...themes, 'system'] : themes,
systemTheme: (enableSystem ? resolvedTheme : undefined) as 'light' | 'dark' | undefined
}) as UseThemeProps,
[theme, setTheme, forcedTheme, resolvedTheme, enableSystem, themes]
)

Expand Down
2 changes: 1 addition & 1 deletion components/Themes/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface UseThemeProps {
/**
* If `enableSystem` is true and the active theme is "system", this returns whether the system preference resolved to "dark" or "light". Otherwise, identical to `theme`
*/
resolvedTheme?: string | undefined
resolvedTheme?: 'dark' | 'light'
/**
* If enableSystem is true, returns the System theme preference ("dark" or "light"), regardless what the active theme is
*/
Expand Down
Loading

0 comments on commit 0624b56

Please sign in to comment.