-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7816cce
commit 7c38133
Showing
67 changed files
with
9,562 additions
and
206 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
18.13.0 | ||
16.13.2 |
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,12 @@ | ||
module.exports = { | ||
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.@(js|jsx|ts|tsx)'], | ||
addons: [ | ||
'@storybook/addon-links', | ||
'@storybook/addon-essentials', | ||
'@storybook/addon-interactions', | ||
], | ||
framework: '@storybook/react', | ||
docs: { | ||
autodocs: true, | ||
}, | ||
}; |
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,9 @@ | ||
export const parameters = { | ||
actions: { argTypesRegex: '^on[A-Z].*' }, | ||
controls: { | ||
matchers: { | ||
color: /(background|color)$/i, | ||
date: /Date$/, | ||
}, | ||
}, | ||
}; |
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,3 @@ | ||
{ | ||
"recommendations": ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"] | ||
} |
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,17 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"[javascript,typescript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode" | ||
}, | ||
"files.autoSave": "onFocusChange", | ||
"editor.smoothScrolling": true, | ||
"eslint.validate": [ | ||
"javascript", | ||
"javascriptreact", | ||
"typescript", | ||
"typescriptreact" | ||
], | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true | ||
} | ||
} |
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,84 @@ | ||
import { StrictMode, useEffect, useState } from 'react'; | ||
import { | ||
ColorScheme, | ||
ColorSchemeProvider, | ||
MantineProvider, | ||
MantineThemeOverride, | ||
} from '@mantine/core'; | ||
import { | ||
DevToolsOptions, | ||
useSetDevToolsOptions, | ||
} from './atoms/devtools-options'; | ||
import { Extension, ExtensionProps } from './Extension'; | ||
import '@fontsource/inter/latin-400.css'; | ||
import '@fontsource/inter/latin-500.css'; | ||
import '@fontsource/inter/latin-600.css'; | ||
import '@fontsource/inter/latin-700.css'; | ||
import '@fontsource/jetbrains-mono/latin-400.css'; | ||
import '@fontsource/jetbrains-mono/latin-600.css'; | ||
import '@fontsource/jetbrains-mono/latin-700.css'; | ||
import { | ||
InternalDevToolsContext, | ||
internalJotaiStore, | ||
} from './internal-jotai-store'; | ||
|
||
const theme: MantineThemeOverride = { | ||
primaryColor: 'dark', | ||
activeStyles: { transform: 'scale(1)' }, | ||
fontFamily: | ||
'Inter, JetBrains Mono, -apple-system, BlinkMacSystemFont, Segoe, sans-serif', | ||
fontFamilyMonospace: | ||
'JetBrains Mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace', | ||
headings: { | ||
fontFamily: | ||
'Inter, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial, sans-serif, Apple Color Emoji, Segoe UI Emoji', | ||
}, | ||
}; | ||
|
||
export type DevToolsProps = ExtensionProps & { | ||
theme?: 'dark' | 'light'; | ||
options?: DevToolsOptions; | ||
}; | ||
|
||
export const DevTools = ({ | ||
store, | ||
isInitialOpen, | ||
theme: userColorScheme = 'light', | ||
options, | ||
}: DevToolsProps): JSX.Element => { | ||
const [colorScheme, setColorScheme] = useState<ColorScheme>(userColorScheme); | ||
const setDevToolsOptions = useSetDevToolsOptions(); | ||
|
||
const toggleColorScheme = (value?: ColorScheme) => | ||
setColorScheme(value || (colorScheme === 'dark' ? 'light' : 'dark')); | ||
|
||
useEffect(() => { | ||
setColorScheme(userColorScheme); | ||
}, [userColorScheme]); | ||
|
||
useEffect(() => { | ||
// Should we consider caching these options in the future instead of allowing users to change these? | ||
setDevToolsOptions(options); | ||
}, [setDevToolsOptions, options]); | ||
|
||
const theme_ = { | ||
...theme, | ||
colorScheme, | ||
}; | ||
|
||
return ( | ||
<StrictMode> | ||
<ColorSchemeProvider | ||
colorScheme={colorScheme} | ||
toggleColorScheme={toggleColorScheme} | ||
> | ||
{/* FIXME remove `withGlobalStyles` - this changes themes outside of this component and may impact userland */} | ||
<MantineProvider withGlobalStyles withNormalizeCSS theme={theme_}> | ||
<InternalDevToolsContext.Provider value={internalJotaiStore}> | ||
<Extension store={store} isInitialOpen={isInitialOpen} /> | ||
</InternalDevToolsContext.Provider> | ||
</MantineProvider> | ||
</ColorSchemeProvider> | ||
</StrictMode> | ||
); | ||
}; |
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,73 @@ | ||
import { useEffect } from 'react'; | ||
import { ActionIcon, Sx } from '@mantine/core'; | ||
import { useAtom, useSetAtom } from 'jotai/react'; | ||
import { Store } from 'src/types'; | ||
import { isShellOpenAtom } from '../atoms/is-shell-open-atom'; | ||
import { | ||
devtoolsJotaiStoreOptions, | ||
useDevtoolsJotaiStoreOptions, | ||
} from '../internal-jotai-store'; | ||
import logo from './assets/jotai-mascot.png'; | ||
import { Shell } from './components/Shell'; | ||
|
||
const shellTriggerButtonStyles: Sx = () => ({ | ||
position: 'fixed', | ||
left: 10, | ||
bottom: 10, | ||
borderRadius: '50%', | ||
padding: '2rem', | ||
zIndex: 99999, | ||
img: { | ||
height: '2rem', | ||
}, | ||
}); | ||
|
||
const ShellTriggerButton = () => { | ||
const setIsShellOpen = useSetAtom(isShellOpenAtom, devtoolsJotaiStoreOptions); | ||
|
||
return ( | ||
<ActionIcon | ||
variant="filled" | ||
// TODO make this themable | ||
color="dark" | ||
onClick={() => setIsShellOpen(true)} | ||
sx={shellTriggerButtonStyles} | ||
> | ||
<img src={logo} alt="Jotai Mascot" /> | ||
</ActionIcon> | ||
); | ||
}; | ||
|
||
export type ExtensionProps = { | ||
// false by default | ||
isInitialOpen?: boolean; | ||
store?: Store; | ||
// TODO Allow user to pass theme | ||
// theme?: 'dark' | 'light'; | ||
}; | ||
|
||
export const Extension = ({ | ||
isInitialOpen = false, | ||
store, | ||
}: ExtensionProps): JSX.Element => { | ||
const [isShellOpen, setIsShellOpen] = useAtom( | ||
isShellOpenAtom, | ||
useDevtoolsJotaiStoreOptions(), | ||
); | ||
|
||
useEffect(() => { | ||
// Avoid setting the initial value if the value is found in the local storage | ||
if (typeof isShellOpen !== 'boolean') { | ||
setIsShellOpen(isInitialOpen); | ||
} | ||
// Intentionally disabled | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
|
||
return ( | ||
<> | ||
{!isShellOpen && <ShellTriggerButton />} | ||
{isShellOpen ? <Shell store={store} /> : null} | ||
</> | ||
); | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,61 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import { Tabs } from '@mantine/core'; | ||
import { useAtomValue } from 'jotai/react'; | ||
import { Store } from 'src/types'; | ||
import { shellStylesAtom } from '../../../atoms/shell-styles'; | ||
import { useSetCustomStore } from '../../../atoms/user-custom-store'; | ||
import { TabKeys, shellStyleDefaults } from '../../../constants'; | ||
import { devtoolsJotaiStoreOptions } from '../../../internal-jotai-store'; | ||
import { AtomViewer } from './components/AtomViewer'; | ||
import { Header } from './components/Header'; | ||
import { ShellResizeBar } from './components/ShellResizeBar'; | ||
import { shellStyles } from './styles'; | ||
|
||
type ShellProps = { | ||
store?: Store; | ||
}; | ||
|
||
export const Shell = ({ store }: ShellProps) => { | ||
const setUserStore = useSetCustomStore(); | ||
|
||
useEffect(() => { | ||
setUserStore(store); | ||
}, [setUserStore, store]); | ||
|
||
const shellRef = useRef<HTMLDivElement>(null); | ||
const { height } = useAtomValue(shellStylesAtom, devtoolsJotaiStoreOptions); | ||
|
||
useEffect(() => { | ||
// Allocating more height at the end of the content allows users to scroll down fully | ||
// FIXME should we handle a use-case where there is padding set around `body`? | ||
document.body.style.paddingBottom = height + 'px'; | ||
|
||
return () => { | ||
document.body.style.paddingBottom = `0px`; | ||
}; | ||
}, [height]); | ||
|
||
return ( | ||
<Tabs | ||
keepMounted={false} | ||
variant="default" | ||
defaultValue={TabKeys.AtomViewer} | ||
m={10} | ||
sx={shellStyles} | ||
h={height} | ||
mah={shellStyleDefaults.maxHeight} | ||
ref={shellRef} | ||
> | ||
<ShellResizeBar shellRef={shellRef} /> | ||
<Header /> | ||
|
||
<Tabs.Panel | ||
value={TabKeys.AtomViewer} | ||
h="100%" | ||
sx={{ overflow: 'hidden' }} | ||
> | ||
<AtomViewer /> | ||
</Tabs.Panel> | ||
</Tabs> | ||
); | ||
}; |
Oops, something went wrong.