-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ConnectModal support group configuration (#547)
* feat: ConnectModal support group=false * feat: add changelog * chore: Merge group and grouporder * revert: groupOrder * chore: update * feat: add deprecated warning * feat: add warning util * fix: rm
- Loading branch information
1 parent
393cad6
commit 90db5e8
Showing
21 changed files
with
420 additions
and
132 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@ant-design/web3': minor | ||
--- | ||
|
||
feat: ConnectModal support group configuration |
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,107 @@ | ||
import * as React from 'react'; | ||
import rcWarning, { resetWarned as rcResetWarned } from 'rc-util/lib/warning'; | ||
|
||
export function noop() {} | ||
|
||
let deprecatedWarnList: Record<string, string[]> | null = null; | ||
|
||
export function resetWarned() { | ||
deprecatedWarnList = null; | ||
rcResetWarned(); | ||
} | ||
|
||
type Warning = (valid: boolean, component: string, message?: string) => void; | ||
|
||
// eslint-disable-next-line | ||
let warning: Warning = noop; | ||
if (process.env.NODE_ENV !== 'production') { | ||
warning = (valid, component, message) => { | ||
rcWarning(valid, `[ant-design-web3: ${component}] ${message}`); | ||
|
||
// StrictMode will inject console which will not throw warning in React 17. | ||
if (process.env.NODE_ENV === 'test') { | ||
resetWarned(); | ||
} | ||
}; | ||
} | ||
|
||
type BaseTypeWarning = ( | ||
valid: boolean, | ||
/** | ||
* - deprecated: Some API will be removed in future but still support now. | ||
* - usage: Some API usage is not correct. | ||
* - breaking: Breaking change like API is removed. | ||
*/ | ||
type: 'deprecated' | 'usage' | 'breaking', | ||
message?: string, | ||
) => void; | ||
|
||
type TypeWarning = BaseTypeWarning & { | ||
deprecated: (valid: boolean, oldProp: string, newProp: string, message?: string) => void; | ||
}; | ||
|
||
export interface WarningContextProps { | ||
strict?: boolean; | ||
} | ||
|
||
export const WarningContext = React.createContext<WarningContextProps>({}); | ||
|
||
/** | ||
* This is a hook but we not named as `useWarning` | ||
* since this is only used in development. | ||
* We should always wrap this in `if (process.env.NODE_ENV !== 'production')` condition | ||
*/ | ||
export const devUseWarning: (component: string) => TypeWarning = | ||
process.env.NODE_ENV !== 'production' | ||
? (component) => { | ||
const { strict } = React.useContext(WarningContext); | ||
|
||
const typeWarning: TypeWarning = (valid, type, message) => { | ||
if (!valid) { | ||
if (strict === false && type === 'deprecated') { | ||
const existWarning = deprecatedWarnList; | ||
|
||
if (!deprecatedWarnList) { | ||
deprecatedWarnList = {}; | ||
} | ||
|
||
deprecatedWarnList[component] = deprecatedWarnList[component] || []; | ||
if (!deprecatedWarnList[component].includes(message || '')) { | ||
deprecatedWarnList[component].push(message || ''); | ||
} | ||
|
||
// Warning for the first time | ||
if (!existWarning) { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
'[ant-design-web3] There exists deprecated usage in your code:', | ||
deprecatedWarnList, | ||
); | ||
} | ||
} else { | ||
warning(valid, component, message); | ||
} | ||
} | ||
}; | ||
|
||
typeWarning.deprecated = (valid, oldProp, newProp, message) => { | ||
typeWarning( | ||
valid, | ||
'deprecated', | ||
`\`${oldProp}\` is deprecated. Please use \`${newProp}\` instead.${ | ||
message ? ` ${message}` : '' | ||
}`, | ||
); | ||
}; | ||
|
||
return typeWarning; | ||
} | ||
: () => { | ||
const noopWarning: TypeWarning = () => {}; | ||
|
||
noopWarning.deprecated = noop; | ||
|
||
return noopWarning; | ||
}; | ||
|
||
export default warning; |
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
Oops, something went wrong.