-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Respect app light/dark mode over OS preference #228
Signed-off-by: Innei <i@innei.in>
- Loading branch information
Showing
15 changed files
with
322 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/renderer/src/components/ui/code-highlighter/shiki/hooks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { useDark } from "@renderer/hooks/common" | ||
import { useIsDark } from "@renderer/hooks/common" | ||
|
||
export const useShikiDefaultTheme = () => { | ||
const isDark = useDark() | ||
const isDark = useIsDark() | ||
|
||
return isDark ? "github-dark" : "github-light" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { createContext } from "use-context-selector" | ||
|
||
export interface SegmentGroupContextValue { | ||
value: string | ||
setValue: (value: string) => void | ||
componentId: string | ||
} | ||
export const SegmentGroupContext = createContext<SegmentGroupContextValue>( | ||
null!, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { cn } from "@renderer/lib/utils" | ||
import { m } from "framer-motion" | ||
import type { ReactNode } from "react" | ||
import { useId, useMemo, useState } from "react" | ||
import { useContextSelector } from "use-context-selector" | ||
|
||
import { SegmentGroupContext } from "./ctx" | ||
|
||
interface SegmentGroupProps { | ||
value?: string | ||
onValueChanged?: (value: string) => void | ||
} | ||
export const SegmentGroup = (props: ComponentType<SegmentGroupProps>) => { | ||
const { onValueChanged, value, className } = props | ||
|
||
const [currentValue, setCurrentValue] = useState(value || "") | ||
const componentId = useId() | ||
|
||
return ( | ||
<SegmentGroupContext.Provider | ||
value={useMemo( | ||
() => ({ | ||
value: currentValue, | ||
setValue: (value) => { | ||
setCurrentValue(value) | ||
onValueChanged?.(value) | ||
}, | ||
componentId, | ||
}), | ||
[componentId, currentValue, onValueChanged], | ||
)} | ||
> | ||
<div | ||
role="tablist" | ||
className={cn( | ||
"inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground outline-none", | ||
className, | ||
)} | ||
tabIndex={0} | ||
data-orientation="horizontal" | ||
> | ||
{props.children} | ||
</div> | ||
</SegmentGroupContext.Provider> | ||
) | ||
} | ||
|
||
export const SegmentItem: Component<{ | ||
value: string | ||
label: ReactNode | ||
}> = ({ label, value, className }) => { | ||
const isActive = useContextSelector( | ||
SegmentGroupContext, | ||
(v) => v.value === value, | ||
) | ||
const setValue = useContextSelector(SegmentGroupContext, (v) => v.setValue) | ||
const layoutId = useContextSelector( | ||
SegmentGroupContext, | ||
(v) => v.componentId, | ||
) | ||
return ( | ||
<button | ||
type="button" | ||
role="tab" | ||
className={cn( | ||
"relative inline-flex items-center justify-center whitespace-nowrap px-3 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:text-foreground", | ||
"h-full rounded-md focus-visible:ring-accent/30", | ||
className, | ||
)} | ||
tabIndex={-1} | ||
data-orientation="horizontal" | ||
onClick={() => { | ||
setValue(value) | ||
}} | ||
data-state={isActive ? "active" : "inactive"} | ||
> | ||
<span className="z-[1]">{label}</span> | ||
|
||
{isActive && ( | ||
<m.span | ||
layout | ||
layoutId={layoutId} | ||
className="absolute inset-0 z-0 rounded-md bg-background shadow" | ||
/> | ||
)} | ||
</button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.