-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added theme switcher to settings page (#19414)
- Loading branch information
1 parent
5047aa4
commit fcb5236
Showing
4 changed files
with
54 additions
and
36 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
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,40 @@ | ||
import { IconDay, IconLaptop, IconNight } from '@posthog/icons' | ||
import { LemonSelect, LemonSelectProps } from '@posthog/lemon-ui' | ||
import { useActions, useValues } from 'kea' | ||
import { userLogic } from 'scenes/userLogic' | ||
|
||
export function ThemeSwitcher({ | ||
onlyLabel, | ||
...props | ||
}: Partial<LemonSelectProps<any>> & { onlyLabel?: boolean }): JSX.Element { | ||
const { user } = useValues(userLogic) | ||
const { updateUser } = useActions(userLogic) | ||
|
||
return ( | ||
<LemonSelect | ||
options={[ | ||
{ icon: <IconLaptop />, value: null, label: `Sync with system` }, | ||
{ icon: <IconDay />, value: 'light', label: 'Light mode' }, | ||
{ icon: <IconNight />, value: 'dark', label: 'Dark mode' }, | ||
]} | ||
value={user?.theme_mode} | ||
renderButtonContent={(leaf) => { | ||
const labelText = leaf ? leaf.label : 'Sync with system' | ||
return onlyLabel ? ( | ||
labelText | ||
) : ( | ||
<> | ||
<span className="flex-1 flex justify-between items-baseline gap-4"> | ||
<span>Color theme</span> | ||
<span className="font-normal text-xs">{leaf ? leaf.label : 'Sync with system'}</span> | ||
</span> | ||
</> | ||
) | ||
}} | ||
onChange={(value) => updateUser({ theme_mode: value })} | ||
dropdownPlacement="right-start" | ||
dropdownMatchSelectWidth={false} | ||
{...props} | ||
/> | ||
) | ||
} |