Skip to content

Commit 2ff412b

Browse files
committed
feat: initial provider
1 parent b689172 commit 2ff412b

9 files changed

+49
-25
lines changed

happydom.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { GlobalRegistrator } from "@happy-dom/global-registrator";
1+
import { GlobalRegistrator } from '@happy-dom/global-registrator'
22

3-
GlobalRegistrator.register();
3+
GlobalRegistrator.register()

inverter-network-react-0.0.0.tgz

10.2 KB
Binary file not shown.

package.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@
1313
"import": "./dist/esm/client.js",
1414
"default": "./dist/cjs/client.js"
1515
},
16-
"./styles": {
17-
"import": "./dist/styles.css",
18-
"default": "./dist/styles.css"
19-
},
2016
"./package.json": "./package.json"
2117
},
2218
"main": "./dist/cjs/index.js",
@@ -37,7 +33,7 @@
3733
"scripts": {
3834
"watch": "tsc -w",
3935
"build": "bun clean && bun build:cjs && bun build:esm && bun build:types && bun build:css",
40-
"build:css": "postcss src/styles/global.css -o dist/styles.css",
36+
"build:css": "postcss src/styles/global.css -o dist/cjs/styles/global.css && cp -r dist/cjs/styles dist/esm/styles",
4137
"build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./dist/cjs/package.json && tsc-alias --outDir ./dist/cjs && ts-add-js-extension --dir=dist/cjs --showchanges=false",
4238
"build:esm": "tsc --project ./tsconfig.build.json --module ESNext --outDir ./dist/esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./dist/esm/package.json && tsc-alias --outDir ./dist/esm && ts-add-js-extension --dir=dist/esm --showchanges=false",
4339
"build:types": "tsc --project ./tsconfig.build.json --module ESNext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap && tsc-alias --outDir ./dist/types",

src/client.ts

+2
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ export * from './components/ui/tooltip'
2626
export * from './components/wallet-widget'
2727
// Hooks
2828
export * from './hooks'
29+
// Providers
30+
export * from './provider'

src/hooks/use-chain-specs.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { useEffect, useRef } from 'react'
3+
import * as React from 'react'
44
import { useAccount, useChains } from 'wagmi'
55

66
export const getIconSrc = (chainId?: number) => {
@@ -45,7 +45,7 @@ export const useChainSpecs = () => {
4545
const showWalletWidget = !isConnected || isUnsupportedChain
4646

4747
// Ref to store the previous chainId
48-
const prevChainId = useRef(chainId)
48+
const prevChainId = React.useRef(chainId)
4949
const didChainIdChange =
5050
chainId !== undefined &&
5151
prevChainId.current !== undefined &&
@@ -55,7 +55,7 @@ export const useChainSpecs = () => {
5555
const explorerUrl = evmNetwork?.blockExplorers?.[0]?.url
5656

5757
// Update the previous chainId when the chainId changes
58-
useEffect(() => {
58+
React.useEffect(() => {
5959
if (didChainIdChange) prevChainId.current = chainId
6060
}, [chainId])
6161

src/hooks/use-deploy/use-deploy-form.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client'
22

3-
import { useRef } from 'react'
3+
import * as React from 'react'
4+
45
import { type UsePrepDeployReturn } from './use-prep-deploy'
56
import { useAccount } from 'wagmi'
67
import { useEffectAfterMount } from '..'
@@ -19,7 +20,7 @@ export const useDeployForm = ({
1920
prepResult: UsePrepDeployReturn
2021
}) => {
2122
const chainId = useAccount().chainId
22-
const prevChainId = useRef(chainId)
23+
const prevChainId = React.useRef(chainId)
2324

2425
const {
2526
deployFormState,

src/hooks/use-effect-after-mount.ts

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
'use client'
22

3-
import {
4-
type DependencyList,
5-
type EffectCallback,
6-
useEffect,
7-
useRef,
8-
} from 'react'
3+
import * as React from 'react'
94

105
export const useEffectAfterMount = (
11-
cb: EffectCallback,
12-
dependencies: DependencyList | undefined
6+
cb: React.EffectCallback,
7+
dependencies: React.DependencyList | undefined
138
) => {
14-
const mounted = useRef(true)
9+
const mounted = React.useRef(true)
1510

16-
useEffect(() => {
11+
React.useEffect(() => {
1712
if (!mounted.current) {
1813
return cb()
1914
}

src/hooks/use-is-hydrated.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use client'
22

3-
import { useEffect, useState } from 'react'
3+
import * as React from 'react'
44

55
export function useIsHydrated() {
6-
const [isHydrated, setIsHydrated] = useState(false)
6+
const [isHydrated, setIsHydrated] = React.useState(false)
77

8-
useEffect(() => {
8+
React.useEffect(() => {
99
setIsHydrated(true)
1010
}, [])
1111

src/provider/index.tsx

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
'use client'
2+
3+
import * as React from 'react'
4+
import '../styles/global.css'
5+
6+
/**
7+
* InverterProviderProps
8+
* @typedef {Object} InverterProviderProps
9+
* @property {React.ReactNode} children
10+
* @property {'light' | 'dark'} theme @default 'light'
11+
*/
12+
type InverterProviderProps = {
13+
children: React.ReactNode
14+
theme?: 'light' | 'dark'
15+
}
16+
17+
export function InverterProvider({
18+
children,
19+
theme = 'light',
20+
}: InverterProviderProps) {
21+
React.useEffect(() => {
22+
if (theme === 'dark') {
23+
document.body.classList.add('dark')
24+
} else {
25+
document.body.classList.remove('dark')
26+
}
27+
}, [theme])
28+
29+
return <>{children}</>
30+
}

0 commit comments

Comments
 (0)