Skip to content

Commit

Permalink
chore(typescript): migrate components (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
smarroufin authored Apr 28, 2022
1 parent 57354f6 commit 1bda2ec
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 95 deletions.
33 changes: 22 additions & 11 deletions docs/pages/migration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ const components = [
to: '/components/Avatar',
nuxt3: true,
preset: true,
capi: true
capi: true,
typescript: true
},
{
label: 'AvatarGroup',
Expand All @@ -82,7 +83,8 @@ const components = [
to: '/components/Badge',
nuxt3: true,
capi: true,
preset: true
preset: true,
typescript: true
},
{
label: 'Button',
Expand All @@ -102,7 +104,8 @@ const components = [
label: 'Icon',
to: '/components/Icon',
nuxt3: true,
capi: true
capi: true,
typescript: true
},
{
label: 'Link',
Expand All @@ -115,7 +118,8 @@ const components = [
to: '/components/Toggle',
nuxt3: true,
preset: true,
capi: true
capi: true,
typescript: true
},
{
label: 'Alert',
Expand All @@ -127,7 +131,8 @@ const components = [
to: '/components/AlertDialog',
nuxt3: true,
capi: true,
preset: true
preset: true,
typescript: true
},
{
label: 'Input',
Expand Down Expand Up @@ -165,7 +170,8 @@ const components = [
},
{
label: 'SelectCustom',
to: '/components/SelectCustom'
to: '/components/SelectCustom',
typescript: true
},
{
label: 'Textarea',
Expand All @@ -186,21 +192,24 @@ const components = [
to: '/components/Container',
nuxt3: true,
preset: true,
capi: true
capi: true,
typescript: true
},
{
label: 'Tabs',
to: '/components/Tabs',
nuxt3: true,
capi: true,
preset: true
preset: true,
typescript: true
},
{
label: 'Pills',
to: '/components/Pills',
nuxt3: true,
capi: true,
preset: true
preset: true,
typescript: true
},
{
label: 'VerticalNavigation',
Expand All @@ -226,7 +235,8 @@ const components = [
label: 'Notifications',
to: '/components/Notifications',
nuxt3: true,
capi: true
capi: true,
typescript: true
},
{
label: 'Popover',
Expand All @@ -238,7 +248,8 @@ const components = [
label: 'Slideover',
to: '/components/Slideover',
nuxt3: true,
capi: true
capi: true,
typescript: true
},
{
label: 'Tooltip',
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/components/elements/Avatar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</span>
</template>

<script setup>
<script setup lang="ts">
import { ref, computed, watch } from 'vue'
import { classNames } from '../../utils'
import $ui from '#build/ui'
Expand All @@ -29,7 +29,7 @@ const props = defineProps({
size: {
type: String,
default: 'md',
validator (value) {
validator (value: string) {
return Object.keys($ui.avatar.size).includes(value)
}
},
Expand All @@ -44,14 +44,14 @@ const props = defineProps({
chipVariant: {
type: String,
default: 'primary',
validator (value) {
validator (value: string) {
return Object.keys($ui.avatar.chip.variant).includes(value)
}
},
chipPosition: {
type: String,
default: 'top-right',
validator (value) {
validator (value: string) {
return Object.keys($ui.avatar.chip.position).includes(value)
}
},
Expand Down
75 changes: 34 additions & 41 deletions src/runtime/components/elements/Badge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,53 +4,46 @@
</span>
</template>

<script>
<script setup lang="ts">
import { computed } from 'vue'
import { classNames } from '../../utils'
import $ui from '#build/ui'
export default {
props: {
size: {
type: String,
default: 'md',
validator (value) {
return Object.keys($ui.badge.size).includes(value)
}
},
variant: {
type: String,
default: 'primary',
validator (value) {
return Object.keys($ui.badge.variant).includes(value)
}
},
baseClass: {
type: String,
default: () => $ui.badge.base
},
rounded: {
type: Boolean,
default: false
},
label: {
type: String,
default: null
const props = defineProps({
size: {
type: String,
default: 'md',
validator (value: string) {
return Object.keys($ui.badge.size).includes(value)
}
},
setup (props) {
const badgeClass = computed(() => {
return classNames(
props.baseClass,
$ui.badge.size[props.size],
$ui.badge.variant[props.variant],
props.rounded ? 'rounded-full' : 'rounded-md'
)
})
return {
badgeClass
variant: {
type: String,
default: 'primary',
validator (value: string) {
return Object.keys($ui.badge.variant).includes(value)
}
},
baseClass: {
type: String,
default: () => $ui.badge.base
},
rounded: {
type: Boolean,
default: false
},
label: {
type: String,
default: null
}
}
})
const badgeClass = computed(() => {
return classNames(
props.baseClass,
$ui.badge.size[props.size],
$ui.badge.variant[props.variant],
props.rounded ? 'rounded-full' : 'rounded-md'
)
})
</script>
6 changes: 4 additions & 2 deletions src/runtime/components/elements/Icon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<Icon :icon="icon" />
</template>

<script setup>
<script setup lang="ts">
import type { Ref } from 'vue'
import type { IconifyIcon } from '@iconify/vue'
import { ref, watch } from 'vue'
import { Icon } from '@iconify/vue/dist/offline'
import { loadIcon } from '@iconify/vue'
Expand All @@ -14,7 +16,7 @@ const props = defineProps({
}
})
const icon = ref(null)
const icon: Ref<IconifyIcon> = ref(null)
icon.value = await loadIcon(props.name)
watch(() => props.name, async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/feedback/AlertDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</Modal>
</template>

<script setup>
<script setup lang="ts">
import { computed } from 'vue'
import { DialogTitle, DialogDescription } from '@headlessui/vue'
import Modal from '../overlays/Modal'
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/components/forms/SelectCustom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</Listbox>
</template>

<script setup>
<script setup lang="ts">
import { computed } from 'vue'
import {
Listbox,
Expand Down Expand Up @@ -76,7 +76,7 @@ const props = defineProps({
size: {
type: String,
default: 'md',
validator (value) {
validator (value: string) {
return Object.keys($ui.selectCustom.size).includes(value)
}
},
Expand Down Expand Up @@ -161,15 +161,15 @@ const iconClass = computed(() => {
const iconWrapperClass = $ui.selectCustom.icon.trailing.wrapper
function resolveOptionClass ({ active, disabled }) {
function resolveOptionClass ({ active, disabled }: { active: boolean, disabled: boolean }) {
return classNames(
props.listOptionBaseClass,
active ? props.listOptionActiveClass : props.listOptionInactiveClass,
disabled && props.listOptionDisabledClass
)
}
function resolveOptionIconClass ({ active }) {
function resolveOptionIconClass ({ active }: { active: boolean }) {
return classNames(
props.listOptionIconBaseClass,
active ? props.listOptionIconActiveClass : props.listOptionIconInactiveClass
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/forms/Toggle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</Switch>
</template>

<script setup>
<script setup lang="ts">
import { computed } from 'vue'
import { Switch } from '@headlessui/vue'
import Icon from '../elements/Icon'
Expand Down
49 changes: 21 additions & 28 deletions src/runtime/components/layout/Container.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,31 @@
</div>
</template>

<script>
<script setup lang="ts">
import { computed } from 'vue'
import { classNames } from '../../utils/'
import $ui from '#build/ui'
export default {
props: {
padded: {
type: Boolean,
default: false
},
constrained: {
type: Boolean,
default: true
},
constrainedClass: {
type: String,
default: () => $ui.container.constrained
}
const props = defineProps({
padded: {
type: Boolean,
default: false
},
setup (props) {
const containerClass = computed(() => {
return classNames(
'mx-auto sm:px-6 lg:px-8',
props.padded && 'px-4',
props.constrained && props.constrainedClass
)
})
return {
containerClass
}
constrained: {
type: Boolean,
default: true
},
constrainedClass: {
type: String,
default: () => $ui.container.constrained
}
}
})
const containerClass = computed(() => {
return classNames(
'mx-auto sm:px-6 lg:px-8',
props.padded && 'px-4',
props.constrained && props.constrainedClass
)
})
</script>
2 changes: 1 addition & 1 deletion src/runtime/components/navigation/Pills.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</nav>
</template>

<script setup>
<script setup lang="ts">
import Link from '../elements/Link'
import $ui from '#build/ui'
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/navigation/Tabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</nav>
</template>

<script setup>
<script setup lang="ts">
import Link from '../elements/Link'
import $ui from '#build/ui'
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/overlays/Notifications.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</div>
</template>

<script setup>
<script setup lang="ts">
import { useNuxtApp, useState } from '#app'
import Notification from './Notification'
Expand Down

1 comment on commit 1bda2ec

@vercel
Copy link

@vercel vercel bot commented on 1bda2ec Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ui – ./

ui-nuxtlabs.vercel.app
nuxthq-ui.vercel.app
ui-git-dev-nuxtlabs.vercel.app

Please sign in to comment.