-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
88 additions
and
32 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
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
57 changes: 57 additions & 0 deletions
57
packages/mockline/src/runtime/composables/useComponentIcons.ts
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,57 @@ | ||
import { computed, toValue, type MaybeRefOrGetter, type ComputedRef } from 'vue' | ||
|
||
export type UseComponentIconsProps = { | ||
/** Display an icon based on the `leading` and `trailing` props. */ | ||
icon?: string | ||
/** When `true`, the icon will be displayed on the left side. */ | ||
leading?: boolean | ||
/** Display an icon on the left side. */ | ||
leadingIcon?: string | ||
/** When `true`, the icon will be displayed on the right side. */ | ||
trailing?: boolean | ||
/** Display an icon on the right side. */ | ||
trailingIcon?: string | ||
/** When `true`, the loading icon will be displayed. */ | ||
loading?: boolean | ||
/** | ||
* The icon when the `loading` prop is `true`. | ||
* @defaultValue appConfig.ui.icons.loading | ||
*/ | ||
loadingIcon?: string | ||
} | ||
|
||
export type UseComponentIconsReturn = { | ||
isLeading: ComputedRef<boolean> | ||
isTrailing: ComputedRef<boolean> | ||
leadingIconName: ComputedRef<string | undefined> | ||
trailingIconName: ComputedRef<string | undefined> | ||
} | ||
|
||
export function useComponentIcons(componentProps: MaybeRefOrGetter<UseComponentIconsProps>): UseComponentIconsReturn { | ||
const props = computed(() => toValue(componentProps)) | ||
|
||
const isLeading = computed(() => (props.value.icon && props.value.leading) || (props.value.icon && !props.value.trailing) || (props.value.loading && !props.value.trailing) || !!props.value.leadingIcon) | ||
const isTrailing = computed(() => (props.value.icon && props.value.trailing) || (props.value.loading && props.value.trailing) || !!props.value.trailingIcon) | ||
|
||
const leadingIconName = computed(() => { | ||
if (props.value.loading) { | ||
return props.value.loadingIcon || 'lucide:loader' | ||
} | ||
|
||
return props.value.leadingIcon || props.value.icon | ||
}) | ||
const trailingIconName = computed(() => { | ||
if (props.value.loading && !isLeading.value) { | ||
return props.value.loadingIcon || 'lucide:loader' | ||
} | ||
|
||
return props.value.trailingIcon || props.value.icon | ||
}) | ||
|
||
return { | ||
isLeading, | ||
isTrailing, | ||
leadingIconName, | ||
trailingIconName | ||
} | ||
} |
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