-
Notifications
You must be signed in to change notification settings - Fork 142
/
Copy pathAppHint.tsx
82 lines (76 loc) Β· 2 KB
/
AppHint.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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} />
</>
);
};