mirror of
https://github.com/HoshinoSuzumi/rayine-ui.git
synced 2025-04-16 17:28:50 +08:00
30 lines
685 B
TypeScript
30 lines
685 B
TypeScript
import type { DeepPartial, Strategy } from "../types/utils";
|
|
|
|
export const useUI = <T>(
|
|
key: string,
|
|
ui?: Ref<(DeepPartial<T> & { strategy?: Strategy }) | undefined>,
|
|
config?: T | Ref<T>
|
|
) => {
|
|
const _attrs = useAttrs();
|
|
const appConfig = useAppConfig();
|
|
|
|
const attrs = computed(() => omit(_attrs, ["class"]));
|
|
|
|
const _computedUiConfig = computed(() => {
|
|
const _ui = toValue(ui);
|
|
const _config = toValue(config);
|
|
|
|
return mergeUiConfig<T>(
|
|
_ui?.strategy || (appConfig.rayui?.strategy as Strategy),
|
|
_ui || {},
|
|
getValueByPath(appConfig.rayui, key, {}),
|
|
_config || {}
|
|
);
|
|
});
|
|
|
|
return {
|
|
ui: _computedUiConfig,
|
|
attrs,
|
|
};
|
|
};
|