-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update README, version, and enhance components with new features and …
…improved styling
- Loading branch information
Showing
14 changed files
with
137 additions
and
32 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
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,69 @@ | ||
import { ObjectInspector } from 'react-inspector'; | ||
import inspectorTheme from '#constants/inspectorTheme'; | ||
import packageJsonUrl from '#constants/packageJsonUrl'; | ||
import { useAsyncMemo } from '#src/lib'; | ||
import delayWithSignal from '../utils/delayWithSignal'; | ||
|
||
type PackageJson = typeof import('#src/../package.json'); | ||
|
||
const whiteList = ['name', 'version', 'author', 'license', 'homepage']; | ||
const whiteListSet = new Set(whiteList); | ||
|
||
export default function UseAsyncMemoDemo() { | ||
const { | ||
state: { result, pending, error }, | ||
load, | ||
stop, | ||
} = useAsyncMemo( | ||
async ({ signal }) => | ||
delayWithSignal(200, signal) | ||
.then(() => fetch(packageJsonUrl, { signal })) | ||
.then((res) => res.json() as Promise<PackageJson>), | ||
[ | ||
/* No dependencies */ | ||
], | ||
{ autoLoad: false }, | ||
); | ||
|
||
const newResult = | ||
result && typeof result === 'object' | ||
? Object.fromEntries( | ||
Object.entries(result).filter(([key]) => whiteListSet.has(key)), | ||
) | ||
: result; | ||
|
||
const data = { result: newResult, pending, error }; | ||
|
||
return ( | ||
<> | ||
<div | ||
className="flex flex-col justify-center items-center gap-2 py-4 p-2 rounded-md prose-pre" | ||
style={{ textShadow: 'rgba(0, 0, 0, 0.3) 0px 1px' }} | ||
> | ||
<div className="w-full"> | ||
<ObjectInspector data={data} expandLevel={3} theme={inspectorTheme} /> | ||
</div> | ||
|
||
<div className="bg-gray-500/10 m-2 py-[0.5px] w-full" /> | ||
<div className="flex gap-4 w-[24em]"> | ||
<button | ||
type="button" | ||
className="flex-1 text-base btn btn-blue" | ||
onClick={load} | ||
disabled={pending} | ||
> | ||
{pending ? 'Loading...' : 'Load'} | ||
</button> | ||
<button | ||
type="button" | ||
className="flex-1 text-base btn btn-red" | ||
onClick={stop} | ||
disabled={!pending} | ||
> | ||
Stop | ||
</button> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} |
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,13 @@ | ||
import { chromeDark } from 'react-inspector'; | ||
|
||
const inspectorTheme: typeof chromeDark = { | ||
...chromeDark, | ||
...{ | ||
BASE_BACKGROUND_COLOR: 'transparent', | ||
BASE_FONT_SIZE: 'var(--text-sm)', | ||
ARROW_FONT_SIZE: 'var(--text-sm)' as unknown as number, | ||
TREENODE_FONT_SIZE: 'var(--text-sm)', | ||
}, | ||
}; | ||
|
||
export default inspectorTheme as unknown as 'chromeDark'; |
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 @@ | ||
const packageJsonUrl = new URL('../../../package.json', import.meta.url).href; | ||
|
||
export default packageJsonUrl; |
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,3 +1,3 @@ | ||
import { version } from '../../../package.json'; | ||
import { version } from '#src/../package.json'; | ||
|
||
export default version; |
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