generated from react-component/portal
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Tour support aria-* in closable (#52)
* feat: Tour support aria-* in closable * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * feat: optimize code * refactor: simplify code * feat: optimize code --------- Co-authored-by: 二货机器人 <[email protected]>
- Loading branch information
1 parent
2116e35
commit dc93652
Showing
9 changed files
with
553 additions
and
88 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { useMemo } from 'react'; | ||
import type { TourProps } from '../interface'; | ||
import type { TourStepInfo } from '../TourStep'; | ||
|
||
type ClosableConfig = Exclude<TourStepInfo['closable'], boolean> | null; | ||
|
||
function isConfigObj( | ||
closable: TourStepInfo['closable'], | ||
): closable is Exclude<TourStepInfo['closable'], boolean> { | ||
return closable !== null && typeof closable === 'object'; | ||
} | ||
|
||
function getClosableConfig( | ||
prefixCls: string, | ||
closable: TourStepInfo['closable'], | ||
closeIcon: TourStepInfo['closeIcon'], | ||
preset: true, | ||
): ClosableConfig; | ||
function getClosableConfig( | ||
prefixCls: string, | ||
closable: TourStepInfo['closable'], | ||
closeIcon: TourStepInfo['closeIcon'], | ||
preset: false, | ||
): ClosableConfig | 'empty'; | ||
/** | ||
* Convert `closable` to ClosableConfig. | ||
* When `preset` is true, will auto fill ClosableConfig with default value. | ||
*/ | ||
function getClosableConfig( | ||
prefixCls: string, | ||
closable: TourStepInfo['closable'], | ||
closeIcon: TourStepInfo['closeIcon'], | ||
preset: boolean, | ||
): ClosableConfig | 'empty' { | ||
if ( | ||
closable === false || | ||
(closeIcon === false && (!isConfigObj(closable) || !closable.closeIcon)) | ||
) { | ||
return null; | ||
} | ||
|
||
const defaultIcon = <span className={`${prefixCls}-close-x`}>×</span>; | ||
const mergedCloseIcon = | ||
(typeof closeIcon !== 'boolean' && closeIcon) || defaultIcon; | ||
|
||
if (isConfigObj(closable)) { | ||
return { | ||
...closable, | ||
closeIcon: closable.closeIcon || mergedCloseIcon, | ||
}; | ||
} | ||
|
||
// When StepClosable no need auto fill, but RootClosable need this. | ||
return preset || closable || closeIcon | ||
? { | ||
closeIcon: mergedCloseIcon, | ||
} | ||
: 'empty'; | ||
} | ||
|
||
export function useClosable( | ||
prefixCls: string, | ||
stepClosable: TourStepInfo['closable'], | ||
stepCloseIcon: TourStepInfo['closeIcon'], | ||
closable: TourProps['closable'], | ||
closeIcon: TourProps['closeIcon'], | ||
) { | ||
return useMemo(() => { | ||
const stepClosableConfig = getClosableConfig( | ||
prefixCls, | ||
stepClosable, | ||
stepCloseIcon, | ||
false, | ||
); | ||
|
||
const rootClosableConfig = getClosableConfig( | ||
prefixCls, | ||
closable, | ||
closeIcon, | ||
true, | ||
); | ||
|
||
if (stepClosableConfig !== 'empty') { | ||
return stepClosableConfig; | ||
} | ||
|
||
return rootClosableConfig; | ||
}, [closable, closeIcon, prefixCls, stepClosable, stepCloseIcon]); | ||
} |
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,5 +1,4 @@ | ||
import Tour from './Tour'; | ||
export type { TourProps } from './Tour'; | ||
export type { TourStepInfo, TourStepProps } from './TourStep'; | ||
export type { TourProps, TourStepInfo, TourStepProps } from './interface'; | ||
|
||
export default Tour; |
Oops, something went wrong.