Skip to content

Commit

Permalink
feat: add option to set size to false to disable forcing style
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux committed Feb 16, 2023
1 parent 62b27b2 commit e545ab8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ export default defineNuxtModule<ModuleOptions>({
description: 'Configure the defaults of Nuxt Icon'
},
size: {
$default: '',
$default: '1em',
$schema: {
title: 'Icon Size',
description: 'Set the default icon size',
description: 'Set the default icon size. Set to false to disable the sizing of icon in style.',
tags: ['@studioIcon material-symbols:format-size-rounded'],
tsType: 'string | false'
},
},
class: {
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/Icon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const iconName = computed(() => ((appConfig as any)?.nuxtIcon?.aliases || {})[pr
const icon = computed<IconifyIcon | undefined>(() => state.value?.[iconName.value])
const component = computed(() => nuxtApp.vueApp.component(iconName.value))
const sSize = computed(() => {
// Disable size if appConfig.nuxtIcon.size === false
if (!props.size && typeof appConfig.nuxtIcon?.size === 'boolean' && !appConfig.nuxtIcon?.size) {
return undefined
}
const size = props.size || appConfig.nuxtIcon?.size || '1em'
if (String(Number(size)) === size) {
return `${size}px`
Expand Down
4 changes: 4 additions & 0 deletions src/runtime/IconCSS.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const props = defineProps({
const iconName = computed(() => ((appConfig as any)?.nuxtIcon?.aliases || {})[props.name] || props.name)
const iconUrl = computed(() => `url('https://api.iconify.design/${iconName.value.replace(':', '/')}.svg')`)
const sSize = computed(() => {
// Disable size if appConfig.nuxtIcon.size === false
if (!props.size && typeof appConfig.nuxtIcon?.size === 'boolean' && !appConfig.nuxtIcon?.size) {
return undefined
}
const size = props.size || appConfig.nuxtIcon?.size || '1em'
if (String(Number(size)) === size) {
return `${size}px`
Expand Down

0 comments on commit e545ab8

Please sign in to comment.