Skip to content

Commit

Permalink
feat: add default icon size (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux authored Sep 6, 2022
1 parent ecf8917 commit 4f7d17b
Show file tree
Hide file tree
Showing 6 changed files with 1,240 additions and 1,242 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ You can use any name from the https://icones.js.org collection:

Note that `NuxtIcon` needs to be inside `components/global/` folder (see [example](./playground/components/global/NuxtIcon.vue)).

## Configuration

To update the default size (`1em`) of the `<Icon />`, create an `app.config.ts` with the `nuxtIcon.size` property:

```ts
// app.config.ts
export default defineAppConfig({
nuxtIcon: {
size: '24px' // default <Icon> size applied
}
})
```

## Contributing

1. Clone this repository
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
},
"dependencies": {
"@iconify/vue": "^3.2.1",
"@nuxt/kit": "^3.0.0-rc.8"
"@nuxt/kit": "^3.0.0-rc.9"
},
"devDependencies": {
"@nuxt/module-builder": "latest",
"@nuxtjs/eslint-config-typescript": "latest",
"eslint": "latest",
"nuxt": "^3.0.0-rc.8",
"nuxt": "^3.0.0-rc.9",
"standard-version": "^9.5.0"
}
}
5 changes: 5 additions & 0 deletions playground/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default defineAppConfig({
nuxtIcon: {
size: '1em'
}
})
17 changes: 15 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@ import { defineNuxtModule, createResolver, addComponent } from '@nuxt/kit'

export interface ModuleOptions {}

declare module '@nuxt/schema' {
interface AppConfig {
/** nuxt-icon configuration */
nuxtIcon: {
/** default size */
size: string
}
}
}

export default defineNuxtModule<ModuleOptions>({
meta: {
name: 'icon',
configKey: 'icon'
name: 'nuxt-icon',
configKey: 'icon',
compatibility: {
nuxt: '^3.0.0-rc.9'
}
},
defaults: {},
setup (_options, nuxt) {
Expand Down
10 changes: 6 additions & 4 deletions src/runtime/Icon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@ import { loadIcon } from '@iconify/vue'
import { useNuxtApp, useState, ref, computed, watch } from '#imports'

const nuxtApp = useNuxtApp()
const nuxtIcon = useAppConfig().nuxtIcon
const props = defineProps({
name: {
type: String,
required: true
},
size: {
type: String,
default: '1em'
default: ''
}
})
const state = useState('icons', () => ({}))
const isFetching = ref(false)
const icon = computed<IconifyIcon | null>(() => state.value?.[props.name])
const component = computed(() => nuxtApp.vueApp.component(props.name))
const sSize = computed(() => {
if (String(Number(props.size)) === props.size) {
return `${props.size}px`
const size = props.size || nuxtIcon?.size || '1em'
if (String(Number(size)) === size) {
return `${size}px`
}
return props.size
return size
})

async function loadIconComponent () {
Expand Down
Loading

0 comments on commit 4f7d17b

Please sign in to comment.