-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components/config): add
transitionRegistry
and `componentTrans…
…itions` global context config; add `useTransition` hook and `registerTransition` util
- Loading branch information
Showing
5 changed files
with
64 additions
and
2 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,14 @@ | ||
--- | ||
'@lun-web/components': patch | ||
'@lun-web/core': patch | ||
'@lun-web/plugins': patch | ||
'@lun-web/react': patch | ||
'@lun-web/theme': patch | ||
'@lun-web/utils': patch | ||
--- | ||
|
||
## Features | ||
|
||
- `config`: add `transitionRegistry` and `componentTransitions` global context config; add `useTransition` hook and `registerTransition` util | ||
- `dialog`: add custom renderer for header, remove `title` prop | ||
- `switch`: add `beforeUpdate` to asynchronously determine whether to update checked status |
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,29 @@ | ||
import { ComponentTransition, GlobalContextConfig, OpenShadowComponentKey, useContextConfig } from 'config'; | ||
import { isObject, isString } from '@lun-web/utils'; | ||
import { computed } from 'vue'; | ||
|
||
type ExtractTransitionProps< | ||
T extends Record<string, unknown>, | ||
K extends keyof T = keyof T, | ||
> = K extends `${infer P}Transition` ? P : never; | ||
|
||
export function useTransition< | ||
P extends Record<string, any>, | ||
T extends ExtractTransitionProps<P> = ExtractTransitionProps<P>, | ||
>(props: P, compName: OpenShadowComponentKey, transitionProp: T, defaultTransition?: string) { | ||
const config = useContextConfig(); | ||
return computed(() => { | ||
const val = props[transitionProp]; | ||
const registry = config.transitionRegistry, | ||
transitionOfConfig = config.componentTransitions[compName][transitionProp]; | ||
if (isString(val) && registry[val]) return registry[val]; | ||
else if (isObject(val)) return val; | ||
else if (registry[transitionOfConfig]) return registry[transitionOfConfig]; | ||
else if (defaultTransition && registry[defaultTransition]) return registry[defaultTransition]; | ||
}); | ||
} | ||
|
||
export function registerTransition(name: string, transition: ComponentTransition, override = false) { | ||
if (!GlobalContextConfig.transitionRegistry[name] || override) | ||
GlobalContextConfig.transitionRegistry[name] = transition; | ||
} |