-
Notifications
You must be signed in to change notification settings - Fork 141
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
FEAT: development helper in env hint #537
Open
HugoPerard
wants to merge
2
commits into
master
Choose a base branch
from
feat/development-helper
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { useId } from 'react'; | ||
|
||
import { | ||
FormControl, | ||
FormLabel, | ||
HStack, | ||
Switch, | ||
useColorMode, | ||
} from '@chakra-ui/react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
export const DarkModeSwitch = () => { | ||
const { t } = useTranslation(['account']); | ||
const { colorMode, setColorMode } = useColorMode(); | ||
const id = useId(); | ||
|
||
return ( | ||
<FormControl display="flex" alignItems="center"> | ||
<HStack> | ||
<FormLabel | ||
as={colorMode === 'light' ? 'span' : undefined} | ||
opacity={colorMode !== 'light' ? 0.5 : undefined} | ||
htmlFor={id} | ||
mb="0" | ||
mr={0} | ||
> | ||
{t('account:preferences.theme.light')} | ||
</FormLabel> | ||
<Switch | ||
colorScheme="brand" | ||
id={id} | ||
isChecked={colorMode === 'dark'} | ||
onChange={(e) => setColorMode(e.target.checked ? 'dark' : 'light')} | ||
/> | ||
<FormLabel | ||
as={colorMode === 'dark' ? 'span' : undefined} | ||
opacity={colorMode !== 'dark' ? 0.5 : undefined} | ||
htmlFor={id} | ||
mb="0" | ||
> | ||
{t('account:preferences.theme.dark')} | ||
</FormLabel> | ||
</HStack> | ||
</FormControl> | ||
); | ||
}; |
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,82 @@ | ||
import { Box, HStack, Text, useDisclosure } from '@chakra-ui/react'; | ||
import { LuAppWindow, LuPanelLeftOpen, LuPencilRuler } from 'react-icons/lu'; | ||
|
||
import { env } from '@/env.mjs'; | ||
import { DevToolsDrawer } from '@/features/devtools/DevToolsDrawer'; | ||
|
||
export const getEnvHintTitlePrefix = () => { | ||
if (env.NEXT_PUBLIC_ENV_EMOJI) return `${env.NEXT_PUBLIC_ENV_EMOJI} `; | ||
if (env.NEXT_PUBLIC_ENV_NAME) return `[${env.NEXT_PUBLIC_ENV_NAME}] `; | ||
return ''; | ||
}; | ||
|
||
export const AppHint = () => { | ||
if (!env.NEXT_PUBLIC_ENV_NAME && !env.NEXT_PUBLIC_DEV_TOOLS_ENABLED) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Box | ||
zIndex="9999" | ||
position="fixed" | ||
top="0" | ||
insetStart="0" | ||
insetEnd="0" | ||
h="2px" | ||
bg={`${env.NEXT_PUBLIC_ENV_COLOR_SCHEME}.400`} | ||
> | ||
<HStack | ||
position="fixed" | ||
top="0" | ||
insetStart="4" | ||
fontSize="0.6rem" | ||
fontWeight="bold" | ||
alignItems="start" | ||
textTransform="uppercase" | ||
> | ||
{env.NEXT_PUBLIC_ENV_NAME && <EnvHint />} | ||
{env.NEXT_PUBLIC_DEV_TOOLS_ENABLED && <DevToolsHint />} | ||
</HStack> | ||
</Box> | ||
); | ||
}; | ||
|
||
const EnvHint = () => { | ||
return ( | ||
<Text | ||
bg={`${env.NEXT_PUBLIC_ENV_COLOR_SCHEME}.400`} | ||
color={`${env.NEXT_PUBLIC_ENV_COLOR_SCHEME}.900`} | ||
px="1" | ||
borderBottomStartRadius="sm" | ||
borderBottomEndRadius="sm" | ||
> | ||
{env.NEXT_PUBLIC_ENV_NAME} | ||
</Text> | ||
); | ||
}; | ||
const DevToolsHint = () => { | ||
const devToolsDrawer = useDisclosure(); | ||
|
||
return ( | ||
<> | ||
<Text | ||
as="button" | ||
fontWeight="bold" | ||
onClick={devToolsDrawer.onToggle} | ||
bg={`${env.NEXT_PUBLIC_ENV_COLOR_SCHEME}.400`} | ||
color={`${env.NEXT_PUBLIC_ENV_COLOR_SCHEME}.900`} | ||
px="1" | ||
borderBottomStartRadius="sm" | ||
borderBottomEndRadius="sm" | ||
textTransform="uppercase" | ||
display="flex" | ||
alignItems="center" | ||
gap="1" | ||
> | ||
<LuPanelLeftOpen /> | ||
Dev helper | ||
</Text> | ||
<DevToolsDrawer disclosure={devToolsDrawer} /> | ||
</> | ||
); | ||
}; |
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,72 @@ | ||
'use client'; | ||
|
||
import { | ||
Checkbox, | ||
Drawer, | ||
DrawerBody, | ||
DrawerCloseButton, | ||
DrawerContent, | ||
DrawerHeader, | ||
FormControl, | ||
FormLabel, | ||
Radio, | ||
RadioGroup, | ||
Stack, | ||
Wrap, | ||
useColorMode, | ||
useDisclosure, | ||
} from '@chakra-ui/react'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { AVAILABLE_LANGUAGES } from '@/lib/i18n/constants'; | ||
|
||
export const DevToolsDrawer = ({ | ||
disclosure, | ||
}: { | ||
disclosure: ReturnType<typeof useDisclosure>; | ||
}) => { | ||
const { colorMode, setColorMode } = useColorMode(); | ||
|
||
const { t, i18n } = useTranslation(['common']); | ||
|
||
return ( | ||
<Drawer | ||
onClose={disclosure.onClose} | ||
isOpen={disclosure.isOpen} | ||
size="xs" | ||
placement="left" | ||
> | ||
<DrawerContent> | ||
<DrawerCloseButton /> | ||
<DrawerHeader>Development panel</DrawerHeader> | ||
<DrawerBody> | ||
<Stack spacing={6}> | ||
<Checkbox | ||
isChecked={colorMode === 'dark'} | ||
onChange={(e) => | ||
setColorMode(e.target.checked ? 'dark' : 'light') | ||
} | ||
> | ||
Dark mode | ||
</Checkbox> | ||
<FormControl> | ||
<FormLabel>Language</FormLabel> | ||
<RadioGroup | ||
value={i18n.language} | ||
onChange={(newValue) => i18n.changeLanguage(newValue)} | ||
> | ||
<Wrap spacing={4}> | ||
{AVAILABLE_LANGUAGES.map((language) => ( | ||
<Radio key={language.key} value={language.key}> | ||
{t(`common:languages.${language.key}`)} | ||
</Radio> | ||
))} | ||
</Wrap> | ||
</RadioGroup> | ||
</FormControl> | ||
</Stack> | ||
</DrawerBody> | ||
</DrawerContent> | ||
</Drawer> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO we can extract these components into external files; we can see them as a lib of standalone dev components we can add / remove based on project needs :) And I think it will make the drawer more readable in long term, even if it's only development tools
I don't know if it is too much or not, but I prefer to see something like this:
instead of adding everything inside the drawer; So if I add a new tool for managing tanstack query (toggle dev tools, delete cache, etc...) I can just add and It Just Works™ :p
I also know that I can update only DarkModeDevTool instead of finding related code inside the drawer for future updates :)
I think you get the idea :p