-
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: Set merge strategy per component on app.config
- Loading branch information
Showing
14 changed files
with
70 additions
and
86 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 |
---|---|---|
@@ -1,6 +1,3 @@ | ||
{ | ||
"tailwindCSS.experimental.classRegex": [ | ||
["ui:\\s*{([^)]*)\\s*}", "[\"'`]([^\"'`]*).*?[\"'`]"], | ||
["/\\*ui\\*/\\s*{([^;]*)}", ":\\s*[\"'`]([^\"'`]*).*?[\"'`]"] | ||
] | ||
"tailwindCSS.experimental.classRegex": [["/\\*ui\\*/\\s*{([^;]*)}", ":\\s*[\"'`]([^\"'`]*).*?[\"'`]"]] | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,36 @@ | ||
import { useAppConfig } from "#imports"; | ||
import omit from "just-omit"; | ||
import get from "just-safe-get"; | ||
import type { Ref } from "vue"; | ||
import { computed, toValue, useAttrs } from "vue"; | ||
import type { Strategy } from "../types"; | ||
import { mergeConfig } from "../utils"; | ||
import { useAppConfig } from '#imports'; | ||
import omit from 'just-omit'; | ||
import get from 'just-safe-get'; | ||
import { computed, toValue, useAttrs, type Ref } from 'vue'; | ||
import type { Strategy } from '../types'; | ||
import { mergeConfig } from '../utils'; | ||
|
||
/** | ||
* Internal composable that helps merging `app.config.ts` and component `ui` classes. | ||
* | ||
* It returns the merged `ui` configs and the `attrs` without the `class` to avoid clashes | ||
*/ | ||
export const useUI = <T>( | ||
key, | ||
key: string, | ||
$ui: Ref<Partial<T & { strategy: Strategy }> | undefined>, | ||
$config?: Ref<T> | T, | ||
$wrapperClass?: Ref<string>, | ||
withAppConfig: boolean = false, | ||
) => { | ||
const $attrs = useAttrs(); | ||
const appConfig = useAppConfig(); | ||
|
||
const ui = computed(() => { | ||
const _ui = toValue($ui); | ||
const _config = toValue($config); | ||
const _wrapperClass = toValue($wrapperClass); | ||
|
||
return mergeConfig<T>( | ||
_ui?.strategy || (appConfig.ui?.strategy as Strategy), | ||
_wrapperClass ? { wrapper: _wrapperClass } : {}, | ||
_ui?.strategy || 'merge', | ||
_ui || {}, | ||
process.dev || withAppConfig ? get(appConfig.ui, key, {}) : {}, | ||
process.dev ? get(appConfig.ui, key, {}) : {}, | ||
_config || {}, | ||
); | ||
}); | ||
|
||
const attrs = computed(() => omit($attrs, ["class"])); | ||
const attrs = computed(() => omit($attrs, ['class'])); | ||
|
||
return { | ||
ui, | ||
attrs, | ||
}; | ||
return { ui, attrs }; | ||
}; |
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