Compare commits

..

45 Commits

Author SHA1 Message Date
Benjamin Canac
2535301bcd chore(release): 0.1.12 2022-11-29 13:56:30 +01:00
Benjamin Canac
629bb72424 fix(Checkbox): types 2022-11-29 13:54:35 +01:00
Benjamin Canac
543b4e025f chore(release): 0.1.11 2022-11-29 12:56:04 +01:00
Benjamin Canac
7f18c6bdc7 fix(Checkbox): revert type fix as it breaks checkboxes 2022-11-29 12:55:44 +01:00
Benjamin Canac
0ea924ca0d chore(release): 0.1.10 2022-11-26 23:44:03 +01:00
renovate[bot]
22f3d42470 chore(deps): update dependency @nuxtjs/color-mode to ^3.2.0 (#63)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2022-11-26 23:43:10 +01:00
Benjamin Canac
1ad96065fd fix: default popper options 2022-11-26 23:42:36 +01:00
Anthony Fu
952786ed79 fix: default props for command palette (#116) 2022-11-26 23:41:25 +01:00
Benjamin Canac
9cf92e34ab chore(release): 0.1.9 2022-11-25 10:00:40 +01:00
Benjamin Canac
6321d3ed8d fix(Icon): couldn't load anymore 2022-11-25 10:00:30 +01:00
Benjamin Canac
bc0c168c0b fix(Icon): eslint ignore 2022-11-23 17:00:08 +01:00
Benjamin Canac
9975305f2a chore(deps): bump 2022-11-23 11:32:08 +01:00
Anthony Fu
edc1bd677b chore: improve types (#115)
* wip: improve types

* feat: improve types

* Apply suggestions from code review

Co-authored-by: Sylvain Marroufin <marroufin.sylvain@gmail.com>

* chore: update

* chore: enable ci typecheck

* chore: fix

Co-authored-by: Sylvain Marroufin <marroufin.sylvain@gmail.com>
2022-11-23 11:30:18 +01:00
Benjamin Canac
32d1f21299 chore(release): 0.1.8 2022-11-16 18:01:05 +01:00
Benjamin Canac
f901e417e1 chore(deps): bump nuxt to 3.0.0 2022-11-16 16:09:50 +01:00
Benjamin Canac
23921e1ae2 chore(release): 0.1.7 2022-11-16 10:57:06 +01:00
Benjamin Canac
8a5f52dbc8 chore(deps): bump 2022-11-16 10:56:50 +01:00
Benjamin Canac
04d5ce1c51 chore(release): 0.1.6 2022-11-15 12:08:10 +01:00
Benjamin Canac
3a300f72c1 fix(SelectCustom): add w-full on ComboboxButton 2022-11-10 14:37:37 +01:00
Benjamin Canac
927debfb6b chore(SelectCustom): add missing inline-flex on button 2022-11-10 13:54:43 +01:00
Benjamin Canac
44176ee897 chore(Notification): improve actions text color 2022-11-09 11:52:52 +01:00
Benjamin Canac
7f9d69183c chore(release): 0.1.5 2022-11-08 16:44:13 +01:00
Benjamin Canac
23e5f4c501 chore(CommandPalette): add autoclear prop 2022-11-08 16:43:18 +01:00
Benjamin Canac
24998e3ac5 chore(release): 0.1.4 2022-11-08 11:02:42 +01:00
Benjamin Canac
bebf18a89a chore(deps): bump 2022-11-08 11:02:22 +01:00
Anthony Fu
1b56b50d4d fix(button): support RouteLocationRaw type for to (#112) 2022-11-08 10:57:55 +01:00
Benjamin Canac
3337559b89 chore(release): 0.1.3 2022-11-04 12:21:08 +01:00
Benjamin Canac
d33a23ebc0 chore(deps): bump 2022-11-04 12:19:20 +01:00
Baptiste Leproux
28586c35a5 fix(types): add missing field in command palette type (#111) 2022-11-02 16:04:50 +01:00
Benjamin Canac
e521e1ac24 fix(docs): component input string field 2022-11-02 11:21:35 +01:00
Sylvain Marroufin
8ea3223071 chore(typescript): minor fixes (#110) 2022-11-02 10:50:40 +01:00
Benjamin Canac
4cbe983f61 chore(release): 0.1.2 2022-10-27 16:05:16 +02:00
Benjamin Canac
e42969f003 chore(Tooltip): improve design 2022-10-27 16:04:49 +02:00
Benjamin Canac
c93e37a0eb chore(Tooltip): handle shortcuts 2022-10-27 14:26:31 +02:00
Sylvain Marroufin
9e20f96b65 chore(Dropdown): don't show outline on keyboard navigation (#108) 2022-10-27 11:52:16 +02:00
Benjamin Canac
9f6f132a76 chore(release): 0.1.1 2022-10-26 13:13:13 +02:00
Sylvain Marroufin
5517cc2846 fix(Dropdown): close on click item with to (#103)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
2022-10-26 13:05:41 +02:00
Benjamin Canac
8c24b5dc97 chore(module): add d.ts file 2022-10-26 13:04:36 +02:00
Benjamin Canac
ec8bd5cdc4 fix(SelectCustom): types and lint 2022-10-26 13:04:36 +02:00
Benjamin Canac
6fab68baa8 fix(CommandPalette): lint 2022-10-26 13:04:36 +02:00
Benjamin Canac
fc951e2980 chore(CommandPalette): improve types 2022-10-26 13:04:36 +02:00
Benjamin Canac
08ff6e6c09 docs: update 2022-10-26 13:04:36 +02:00
Sylvain Marroufin
9dcdaf474e chore(Dropdown|Popover|Tooltip): hover delay (#104) 2022-10-26 11:59:49 +02:00
Sylvain Marroufin
e9f0224b91 fix(Popover): avoid crash on mount if ref not loaded (#105) 2022-10-26 11:57:13 +02:00
Benjamin Canac
929192fd46 chore(deps): bump vueuse 2022-10-25 16:32:42 +02:00
38 changed files with 1520 additions and 1346 deletions

View File

@@ -41,6 +41,9 @@ jobs:
- name: Lint
run: yarn lint
- name: Typecheck
run: yarn typecheck
- name: Build
run: yarn build

View File

@@ -41,6 +41,9 @@ jobs:
- name: Lint
run: yarn lint
- name: Typecheck
run: yarn typecheck
- name: Build
run: yarn build

View File

@@ -2,6 +2,76 @@
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [0.1.12](https://github.com/nuxtlabs/ui/compare/v0.1.11...v0.1.12) (2022-11-29)
### Bug Fixes
* **Checkbox:** types ([629bb72](https://github.com/nuxtlabs/ui/commit/629bb724249cfe1fdd999cf52f8e72ca444bd94d))
### [0.1.11](https://github.com/nuxtlabs/ui/compare/v0.1.10...v0.1.11) (2022-11-29)
### Bug Fixes
* **Checkbox:** revert type fix as it breaks checkboxes ([7f18c6b](https://github.com/nuxtlabs/ui/commit/7f18c6bdc7c0054b2e5d4f9bf4e362847a3ba3a3))
### [0.1.10](https://github.com/nuxtlabs/ui/compare/v0.1.9...v0.1.10) (2022-11-26)
### Bug Fixes
* default popper options ([1ad9606](https://github.com/nuxtlabs/ui/commit/1ad96065fd706d828b906db3a5d578226ff08c36))
* default props for command palette ([#116](https://github.com/nuxtlabs/ui/issues/116)) ([952786e](https://github.com/nuxtlabs/ui/commit/952786ed79cd9cdf523f6eac5958f68790bacbea))
### [0.1.9](https://github.com/nuxtlabs/ui/compare/v0.1.8...v0.1.9) (2022-11-25)
### Bug Fixes
* **Icon:** couldn't load anymore ([6321d3e](https://github.com/nuxtlabs/ui/commit/6321d3ed8d5c9478cb1dafc1da94b21d0c7edb88))
* **Icon:** eslint ignore ([bc0c168](https://github.com/nuxtlabs/ui/commit/bc0c168c0b0feae96d6a1848c3a356d846e2cbb5))
### [0.1.8](https://github.com/nuxtlabs/ui/compare/v0.1.7...v0.1.8) (2022-11-16)
### [0.1.7](https://github.com/nuxtlabs/ui/compare/v0.1.6...v0.1.7) (2022-11-16)
### [0.1.6](https://github.com/nuxtlabs/ui/compare/v0.1.5...v0.1.6) (2022-11-15)
### Bug Fixes
* **SelectCustom:** add `w-full` on `ComboboxButton` ([3a300f7](https://github.com/nuxtlabs/ui/commit/3a300f72c1eca756ffd8f07ab871bf9c7bd7868d))
### [0.1.5](https://github.com/nuxtlabs/ui/compare/v0.1.4...v0.1.5) (2022-11-08)
### [0.1.4](https://github.com/nuxtlabs/ui/compare/v0.1.3...v0.1.4) (2022-11-08)
### Bug Fixes
* **button:** support `RouteLocationRaw` type for `to` ([#112](https://github.com/nuxtlabs/ui/issues/112)) ([1b56b50](https://github.com/nuxtlabs/ui/commit/1b56b50d4d54a5cb9e5febacdf42867988ae6c5d))
### [0.1.3](https://github.com/nuxtlabs/ui/compare/v0.1.2...v0.1.3) (2022-11-04)
### Bug Fixes
* **docs:** component input string field ([e521e1a](https://github.com/nuxtlabs/ui/commit/e521e1ac2421dc331652f1ea4ac2b0b2959dc069))
* **types:** add missing field in command palette type ([#111](https://github.com/nuxtlabs/ui/issues/111)) ([28586c3](https://github.com/nuxtlabs/ui/commit/28586c35a558d9e925094f86e07acdb928d54ad7))
### [0.1.2](https://github.com/nuxtlabs/ui/compare/v0.1.1...v0.1.2) (2022-10-27)
### [0.1.1](https://github.com/nuxtlabs/ui/compare/v0.1.0...v0.1.1) (2022-10-26)
### Bug Fixes
* **CommandPalette:** lint ([6fab68b](https://github.com/nuxtlabs/ui/commit/6fab68baa836c97680446e8cfdee7c5a64008539))
* **Dropdown:** close on click item with `to` ([#103](https://github.com/nuxtlabs/ui/issues/103)) ([5517cc2](https://github.com/nuxtlabs/ui/commit/5517cc28467f957956a20126c1ce48e64677cb82))
* **Popover:** avoid crash on mount if ref not loaded ([#105](https://github.com/nuxtlabs/ui/issues/105)) ([e9f0224](https://github.com/nuxtlabs/ui/commit/e9f0224b919445260d3b19511420a3fd448e4ea7))
* **SelectCustom:** types and lint ([ec8bd5c](https://github.com/nuxtlabs/ui/commit/ec8bd5cdc49feb924dfdff352d9f3d788653c583))
## [0.1.0](https://github.com/nuxtlabs/ui/compare/v0.0.3...v0.1.0) (2022-10-25)

12
build.config.ts Normal file
View File

@@ -0,0 +1,12 @@
import fs from 'node:fs/promises'
import { join, resolve } from 'node:path'
import { defineBuildConfig } from 'unbuild'
export default defineBuildConfig({
hooks: {
'rollup:done': async (ctx) => {
// copy env.d.ts to dist
await fs.copyFile(resolve('src/env.d.ts'), join(ctx.options.outDir, 'env.d.ts'))
}
}
})

View File

@@ -10,7 +10,9 @@
</div>
<div class="flex items-center gap-3">
<UButton variant="transparent" :icon="colorMode.value === 'dark' ? 'heroicons-outline:moon' : 'heroicons-outline:sun'" @click="toggleDark" />
<ColorScheme placeholder="" tag="span">
<UButton variant="transparent" :icon="colorMode.value === 'dark' ? 'heroicons-outline:moon' : 'heroicons-outline:sun'" @click="toggleDark" />
</ColorScheme>
<UButton to="https://github.com/nuxtlabs/ui" target="_blank" variant="transparent" icon="fa-brands:github" />
</div>
</div>
@@ -19,7 +21,7 @@
<UContainer class="mt-16">
<div class="lg:grid lg:grid-cols-10 lg:gap-10 lg:relative">
<aside class="lg:flex lg:flex-col lg:relative pb-8 lg:pb-0 lg:sticky lg:top-0 px-4 sm:px-6 lg:px-0 lg:pt-16 lg:-mt-16 lg:self-start lg:col-span-2 lg:overflow-hidden lg:sticky lg:h-screen">
<aside class="lg:flex lg:flex-col pb-8 lg:pb-0 lg:sticky lg:top-0 px-4 sm:px-6 lg:px-0 lg:pt-16 lg:-mt-16 lg:self-start lg:col-span-2 lg:overflow-hidden lg:h-screen">
<nav class="overflow-y-auto h-auto pt-8 lg:py-12">
<ul class="space-y-6">
<li v-for="section of sections" :key="section">
@@ -57,7 +59,14 @@
</template>
<script setup>
useMeta({
useHead({
title: '@nuxthq/ui',
meta: [
{ name: 'viewport', content: 'width=device-width, initial-scale=1, maximum-scale=1' }
],
link: [
{ rel: 'stylesheet', href: 'https://rsms.me/inter/inter.css' }
],
bodyAttrs: {
class: 'antialiased font-sans text-gray-700 bg-gray-50 dark:bg-gray-900 dark:text-gray-200 bg-white dark:bg-black'
}

View File

@@ -1,18 +1,8 @@
import { defineNuxtConfig } from 'nuxt'
import defaultTheme from 'tailwindcss/defaultTheme'
import nuxtUI from '../src/module'
// https://v3.nuxtjs.org/docs/directory-structure/nuxt.config
export default defineNuxtConfig({
meta: {
title: '@nuxthq/ui',
meta: [
{ name: 'viewport', content: 'width=device-width, initial-scale=1, maximum-scale=1' }
],
link: [
{ rel: 'stylesheet', href: 'https://rsms.me/inter/inter.css' }
]
},
modules: [
nuxtUI
],

View File

@@ -1,3 +1,4 @@
<!-- eslint-disable vue/no-template-shadow -->
<!-- eslint-disable vue/no-v-html -->
<!-- eslint-disable vue/no-v-text-v-html-on-component -->
<template>
@@ -66,7 +67,7 @@
size="sm"
/>
<UInput
v-else-if="prop.type === 'String' && typeof prop.value === 'string'"
v-else-if="prop.type === 'String'"
v-model="prop.value"
:name="prop.key"
size="sm"

View File

@@ -1,3 +1,4 @@
<!-- eslint-disable vue/no-v-html -->
<template>
<div class="space-y-4">
<div class="pb-10 border-b u-border-gray-200 mb-10">
@@ -153,8 +154,8 @@
Tooltip:
</div>
<UTooltip text="Hello tooltip!">
<UIcon name="heroicons-outline:information-circle" class="w-6 h-6 text-black cursor-pointer" />
<UTooltip text="Hello tooltip!" :shortcuts="['⌘', 'G']">
<UIcon name="heroicons-outline:information-circle" class="w-6 h-6 u-text-gray-900 cursor-pointer" />
</UTooltip>
</div>

View File

@@ -1,3 +1,4 @@
<!-- eslint-disable vue/no-v-html -->
<template>
<div class="space-y-4">
<div class="pb-10 border-b u-border-gray-200 mb-10">

View File

@@ -1,6 +1,6 @@
{
"name": "@nuxthq/ui",
"version": "0.1.0",
"version": "0.1.12",
"repository": "https://github.com/nuxtlabs/ui",
"license": "MIT",
"exports": {
@@ -20,34 +20,36 @@
"dev": "nuxi dev docs",
"build:docs": "nuxi generate docs",
"lint": "eslint --ext .ts,.js,.vue .",
"typecheck": "nuxi typecheck",
"prepare": "nuxi prepare docs",
"release": "yarn lint && standard-version && git push --follow-tags"
},
"dependencies": {
"@headlessui/vue": "^1.7.3",
"@headlessui/vue": "^1.7.4",
"@iconify/vue": "^4.0.0",
"@nuxt/kit": "^3.0.0-rc.12",
"@nuxtjs/color-mode": "^3.1.8",
"@nuxtjs/tailwindcss": "^6.1.1",
"@nuxt/kit": "^3.0.0",
"@nuxtjs/color-mode": "^3.2.0",
"@nuxtjs/tailwindcss": "^6.1.3",
"@popperjs/core": "^2.11.6",
"@tailwindcss/aspect-ratio": "^0.4.2",
"@tailwindcss/forms": "^0.5.3",
"@tailwindcss/line-clamp": "^0.4.2",
"@tailwindcss/typography": "^0.5.7",
"@vueuse/core": "^9.3.1",
"@vueuse/integrations": "^9.3.1",
"defu": "^6.1.0",
"@tailwindcss/typography": "^0.5.8",
"@vueuse/core": "^9.6.0",
"@vueuse/integrations": "^9.6.0",
"defu": "^6.1.1",
"fuse.js": "^6.6.2",
"lodash-es": "^4.17.21",
"tailwindcss": "^3.2.1"
"tailwindcss": "^3.2.4"
},
"devDependencies": {
"@nuxt/module-builder": "^0.2.0",
"@nuxtjs/eslint-config-typescript": "^11.0.0",
"@nuxt/module-builder": "^0.2.1",
"@nuxtjs/eslint-config-typescript": "^12.0.0",
"@types/lodash-es": "^4.17.6",
"eslint": "^8.26.0",
"nuxt": "^3.0.0-rc.9",
"eslint": "^8.28.0",
"nuxt": "^3.0.0",
"standard-version": "^9.5.0",
"unbuild": "^1.0.1",
"vue-tsc": "^1.0.9"
},
"build": {

6
src/env.d.ts vendored Normal file
View File

@@ -0,0 +1,6 @@
import type { DefaultPreset } from './runtime/presets/default'
declare module '#build/ui' {
declare const preset: DefaultPreset
export default preset
}

View File

@@ -114,6 +114,11 @@ export default defineNuxtModule<ModuleOptions>({
filename: 'ui.mjs',
getContents: () => `export default ${JSON.stringify(ui)}`
})
addTemplate({
filename: 'ui.d.ts',
write: true,
getContents: () => 'declare const d: any; export default d;'
})
})
await installModule('@nuxtjs/color-mode', { classSuffix: '' })

View File

@@ -6,16 +6,16 @@
:aria-label="ariaLabel"
v-bind="buttonProps"
>
<Icon v-if="isLeading" :name="leadingIconName" :class="leadingIconClass" aria-hidden="true" />
<Icon v-if="isLeading && leadingIconName" :name="leadingIconName" :class="leadingIconClass" aria-hidden="true" />
<slot><span :class="truncate ? 'text-left break-all line-clamp-1' : ''">{{ label }}</span></slot>
<Icon v-if="isTrailing" :name="trailingIconName" :class="trailingIconClass" aria-hidden="true" />
<Icon v-if="isTrailing && trailingIconName" :name="trailingIconName" :class="trailingIconClass" aria-hidden="true" />
</component>
</template>
<script setup lang="ts">
import { ref, computed, useSlots } from 'vue'
import type { PropType } from 'vue'
import type { RouteLocationNormalized } from 'vue-router'
import type { RouteLocationNormalized, RouteLocationRaw } from 'vue-router'
import NuxtLink from '#app/components/nuxt-link'
import Icon from '../elements/Icon.vue'
import { classNames } from '../../utils'
@@ -81,7 +81,7 @@ const props = defineProps({
default: false
},
to: {
type: [String, Object] as PropType<string | RouteLocationNormalized>,
type: [String, Object] as PropType<string | RouteLocationNormalized | RouteLocationRaw>,
default: null
},
target: {

View File

@@ -10,8 +10,8 @@
<transition appear v-bind="transitionClass">
<MenuItems :class="baseClass" static>
<div v-for="(subItems, index) of items" :key="index" :class="groupClass">
<MenuItem v-for="(item, subIndex) of subItems" :key="subIndex" v-slot="{ active, disabled }" :disabled="item.disabled" as="div">
<Component v-bind="item" :is="(item.to && NuxtLink) || (item.click && 'button') || 'div'" :class="resolveItemClass({ active, disabled })" @click="e => onItemClick(e, item)">
<MenuItem v-for="(item, subIndex) of subItems" :key="subIndex" v-slot="{ active, disabled }" :disabled="item.disabled" @click="e => item.click?.(e)">
<Component v-bind="item" :is="(item.to && NuxtLink) || (item.click && 'button') || 'div'" :class="resolveItemClass({ active, disabled })">
<slot :name="item.slot" :item="item">
<Icon v-if="item.icon" :name="item.icon" :class="[itemIconClass, item.iconClass]" />
<Avatar v-if="item.avatar" v-bind="{ size: 'xxs', ...item.avatar }" :class="itemAvatarClass" />
@@ -38,7 +38,7 @@ import {
MenuItems,
MenuItem
} from '@headlessui/vue'
import type { Ref, PropType } from 'vue'
import type { PropType } from 'vue'
import type { RouteLocationNormalized } from 'vue-router'
import { ref, computed, onMounted } from 'vue'
import { defu } from 'defu'
@@ -128,7 +128,15 @@ const props = defineProps({
},
popperOptions: {
type: Object as PropType<PopperOptions>,
default: () => {}
default: () => ({})
},
openDelay: {
type: Number,
default: 50
},
closeDelay: {
type: Number,
default: 0
}
})
@@ -144,22 +152,15 @@ function resolveItemClass ({ active, disabled }: { active: boolean, disabled: bo
)
}
function onItemClick (e, item: any) {
if (item.disabled) {
return
}
// https://github.com/tailwindlabs/headlessui/blob/f66f4926c489fc15289d528294c23a3dc2aee7b1/packages/%40headlessui-vue/src/components/menu/menu.ts#L131
const menuApi = ref<any>(null)
if (item.click) {
item.click(e)
}
}
const menuApi: Ref<any> = ref(null)
let openTimeout: NodeJS.Timeout | null = null
let closeTimeout: NodeJS.Timeout | null = null
onMounted(() => {
setTimeout(() => {
// @ts-expect-error internals
const menuProvides = trigger.value?.$.provides
if (!menuProvides) {
return
@@ -167,7 +168,7 @@ onMounted(() => {
const menuProvidesSymbols = Object.getOwnPropertySymbols(menuProvides)
menuApi.value = menuProvidesSymbols.length && menuProvides[menuProvidesSymbols[0]]
// stop trigger click propagation on hover
menuApi.value?.buttonRef.addEventListener('click', (e: Event) => {
menuApi.value?.buttonRef?.addEventListener('click', (e: Event) => {
if (props.mode === 'hover') {
e.stopPropagation()
}
@@ -192,7 +193,7 @@ function onMouseOver () {
openTimeout = openTimeout || setTimeout(() => {
menuApi.value.openMenu && menuApi.value.openMenu()
openTimeout = null
}, 50)
}, props.openDelay)
}
function onMouseLeave () {
@@ -212,7 +213,7 @@ function onMouseLeave () {
closeTimeout = closeTimeout || setTimeout(() => {
menuApi.value.closeMenu && menuApi.value.closeMenu()
closeTimeout = null
}, 0)
}, props.closeDelay)
}
</script>

View File

@@ -18,10 +18,15 @@ const props = defineProps({
}
})
const nuxtApp = useNuxtApp()
const state = useState('u-icons', () => ({}))
const state = useState<Record<string, Required<IconifyIcon> | Promise<void> | null>>('u-icons', () => ({}))
const isFetching = computed(() => !!state.value?.[props.name]?.then)
const icon = computed<IconifyIcon | null>(() => !state.value?.[props.name] || state.value[props.name].then ? null : state.value[props.name])
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
const isFetching = computed(() => state.value?.[props.name] && ('then' in state.value?.[props.name]!))
const icon = computed<Required<IconifyIcon> | null>(() =>
!state.value?.[props.name] || 'then' in state.value[props.name]!
? null
: state.value[props.name] as Required<IconifyIcon>
)
const component = computed(() => nuxtApp.vueApp.component(props.name))
const loadIconComponent = (name: string) => {

View File

@@ -8,7 +8,7 @@
<router-link
v-else
v-slot="{ href, navigate, isActive, isExactActive }"
v-bind="$props"
v-bind="$props as RouterLinkProps"
custom
>
<a
@@ -25,10 +25,11 @@
<script setup lang="ts">
import { computed } from 'vue'
import type { PropType } from 'vue'
import type { RouteLocationNormalized } from 'vue-router'
import type { RouteLocationNormalized, RouterLinkProps } from 'vue-router'
import { RouterLink } from 'vue-router'
const props = defineProps({
// @ts-expect-error internal props
...RouterLink.props,
to: {
type: [String, Object] as PropType<string | RouteLocationNormalized>,

View File

@@ -2,7 +2,7 @@
<div class="rounded-md p-4" :class="variantClass">
<div class="flex">
<div class="flex-shrink-0">
<Icon :name="iconName" :class="iconClass" class="h-5 w-5" />
<Icon v-if="iconName" :name="iconName" :class="iconClass" class="h-5 w-5" />
</div>
<div class="ml-3 flex-1 md:flex md:justify-between">
<p v-if="title" class="text-sm leading-5" :class="titleClass">

View File

@@ -37,7 +37,7 @@ const props = defineProps({
default: null
},
modelValue: {
type: [String, Number, Boolean, Array],
type: [Boolean, Array],
default: null
},
name: {

View File

@@ -13,22 +13,21 @@
:autocomplete="autocomplete"
:spellcheck="spellcheck"
:class="inputClass"
@input="onInput($event.target.value)"
@input="onInput(($event.target as any).value)"
@focus="$emit('focus', $event)"
@blur="$emit('blur', $event)"
>
<slot />
<div v-if="isLeading" :class="iconLeadingWrapperClass">
<Icon :name="iconName" :class="iconClass" />
<Icon v-if="iconName" :name="iconName" :class="iconClass" />
</div>
<div v-if="isTrailing" :class="iconTrailingWrapperClass">
<Icon :name="iconName" :class="iconClass" />
<Icon v-if="iconName" :name="iconName" :class="iconClass" />
</div>
</div>
</template>
<script setup lang="ts">
import type { Ref } from 'vue'
import { ref, computed, onMounted } from 'vue'
import Icon from '../elements/Icon.vue'
import { classNames } from '../../utils'
@@ -129,11 +128,11 @@ const props = defineProps({
const emit = defineEmits(['update:modelValue', 'focus', 'blur'])
const input: Ref<HTMLInputElement> = ref(null)
const input = ref<HTMLInputElement | null>(null)
const autoFocus = () => {
if (props.autofocus) {
input.value.focus()
input.value?.focus()
}
}

View File

@@ -7,7 +7,7 @@
:required="required"
:disabled="disabled"
:class="selectClass"
@input="onInput($event.target.value)"
@input="onInput(($event.target as any).value)"
>
<template v-for="(option, index) in normalizedOptionsWithPlaceholder">
<optgroup

View File

@@ -12,16 +12,16 @@
>
<input :value="modelValue" :required="required" class="absolute inset-0 w-px opacity-0 cursor-default" tabindex="-1">
<ComboboxButton ref="trigger" v-slot="{ disabled }" as="div">
<slot :open="open" :disabled="disabled">
<ComboboxButton ref="trigger" v-slot="{ disabled: buttonDisabled }" as="div" class="inline-flex w-full">
<slot :open="open" :disabled="buttonDisabled">
<button :class="selectCustomClass" :disabled="disabled" type="button">
<slot name="label">
<span v-if="modelValue" class="block truncate">{{ modelValue[textAttribute] }}</span>
<span v-if="modelValue" class="block truncate">{{ (modelValue as any)[textAttribute] }}</span>
<span v-else class="block truncate u-text-gray-400">{{ placeholder }}</span>
</slot>
<slot name="icon">
<span :class="iconWrapperClass">
<Icon :name="icon" :class="iconClass" aria-hidden="true" />
<Icon v-if="icon" :name="icon" :class="iconClass" aria-hidden="true" />
</span>
</slot>
</button>
@@ -44,13 +44,13 @@
/>
<ComboboxOption
v-for="(option, index) in filteredOptions"
v-slot="{ active, selected, disabled }"
v-slot="{ active, selected, disabled: optionDisabled }"
:key="index"
as="template"
:value="option"
:disabled="option.disabled"
>
<li :class="resolveOptionClass({ active, selected, disabled })">
<li :class="resolveOptionClass({ active, selected, disabled: optionDisabled })">
<div :class="listOptionContainerClass">
<slot name="option" :option="option" :active="active" :selected="selected">
<span class="block truncate">{{ option[textAttribute] }}</span>
@@ -58,7 +58,7 @@
</div>
<span v-if="selected" :class="resolveOptionIconClass({ active })">
<Icon :name="listOptionIcon" :class="listOptionIconSizeClass" aria-hidden="true" />
<Icon v-if="listOptionIcon" :name="listOptionIcon" :class="listOptionIconSizeClass" aria-hidden="true" />
</span>
</li>
</ComboboxOption>
@@ -110,7 +110,7 @@ const props = defineProps({
default: undefined
},
options: {
type: Array as PropType<{ disabled?: boolean }[]>,
type: Array as PropType<{ [key: string]: any, disabled?: boolean }[]>,
default: () => []
},
required: {
@@ -257,7 +257,7 @@ const props = defineProps({
},
popperOptions: {
type: Object as PropType<PopperOptions>,
default: () => {}
default: () => ({})
}
})
@@ -323,7 +323,7 @@ function resolveOptionIconClass ({ active }: { active: boolean }) {
)
}
function onUpdate (event) {
function onUpdate (event: any) {
if (query.value && searchInput.value?.$el) {
query.value = ''
// explicitly set input text because `ComboboxInput` `displayValue` is not reactive

View File

@@ -11,7 +11,7 @@
:placeholder="placeholder"
:autocomplete="autocomplete"
:class="textareaClass"
@input="onInput($event.target.value)"
@input="onInput(($event.target as any).value)"
@focus="$emit('focus', $event)"
@blur="$emit('blur', $event)"
/>
@@ -19,7 +19,6 @@
</template>
<script setup lang="ts">
import type { Ref } from 'vue'
import { ref, computed, watch, onMounted, nextTick } from 'vue'
import { classNames } from '../../utils'
import $ui from '#build/ui'
@@ -95,11 +94,11 @@ const props = defineProps({
const emit = defineEmits(['update:modelValue', 'focus', 'blur'])
const textarea: Ref<HTMLTextAreaElement> = ref(null)
const textarea = ref<HTMLTextAreaElement | null>(null)
const autoFocus = () => {
if (props.autofocus) {
textarea.value.focus()
textarea.value?.focus()
}
}

View File

@@ -104,12 +104,16 @@ const props = defineProps({
},
options: {
type: Object as PropType<Partial<UseFuseOptions<Command>>>,
default: () => {}
default: () => ({})
},
autoselect: {
type: Boolean,
default: true
},
autoclear: {
type: Boolean,
default: true
},
placeholder: {
type: Boolean,
default: true
@@ -130,6 +134,7 @@ onMounted(() => {
onMounted(() => {
setTimeout(() => {
// @ts-expect-error internals
const popoverProvides = comboboxInput.value?.$.provides
if (!popoverProvides) {
return
@@ -166,7 +171,7 @@ const groups = computed(() => map(groupBy(results.value, command => command.item
return {
...props.groups.find(group => group.key === key),
commands: commands.slice(0, options.value.resultLimit)
}
} as Group
}))
// Methods
@@ -183,7 +188,7 @@ function onSelect (option: Command | Command[]) {
emit('update:modelValue', option, { query: query.value })
// Clear input after selection
if (!props.multiple) {
if (props.autoclear) {
setTimeout(() => {
query.value = ''
}, 0)
@@ -199,7 +204,7 @@ function onClear () {
}
defineExpose({
updateQuery: (q) => {
updateQuery: (q: string) => {
query.value = q
},
comboboxApi,

View File

@@ -26,6 +26,7 @@
<div class="flex items-center gap-1.5 min-w-0" :class="{ 'opacity-50': command.disabled }">
<slot :name="`${group.key}-command`" :group="group" :command="command">
<span v-if="command.prefix" class="u-text-gray-400">{{ command.prefix }}</span>
<!-- eslint-disable-next-line vue/no-v-html -->
<span v-if="command.matches?.length" class="truncate" :class="{ 'flex-none': command.suffix }" v-html="highlight(command.matches[0])" />
<span v-else class="truncate" :class="{ 'flex-none': command.suffix }">{{ command[commandAttribute] }}</span>
<span v-if="command.suffix" class="u-text-gray-400 truncate">{{ command.suffix }}</span>
@@ -71,7 +72,7 @@ defineProps({
}
})
function highlight ({ indices, value }, i = 1) {
function highlight ({ indices, value }: { indices: number[][], value:string }, i = 1): string {
const pair = indices[indices.length - i]
if (!pair) {
return value

View File

@@ -5,7 +5,7 @@
v-slot="{ isActive }"
:key="index"
v-bind="link"
:class="[baseClass, spacingClass]"
:class="[baseClass, spacingClass].join(' ')"
:active-class="activeClass"
:inactive-class="inactiveClass"
@click="link.click && link.click()"

View File

@@ -9,8 +9,10 @@
</template>
<script setup lang="ts">
import { PropType, computed, toRef } from 'vue'
import type { PropType } from 'vue'
import { computed, toRef } from 'vue'
import { defu } from 'defu'
import type { VirtualElement } from '@popperjs/core'
import { usePopper } from '../../composables/usePopper'
import type { PopperOptions } from '../../types'
import $ui from '#build/ui'
@@ -21,7 +23,7 @@ const props = defineProps({
default: false
},
virtualElement: {
type: Object,
type: Object as PropType<VirtualElement>,
required: true
},
wrapperClass: {
@@ -46,7 +48,7 @@ const props = defineProps({
},
popperOptions: {
type: Object as PropType<PopperOptions>,
default: () => {}
default: () => ({})
}
})

View File

@@ -20,14 +20,14 @@
</p>
<div v-if="description && actions.length" class="mt-3 flex items-center gap-6">
<button v-for="(action, index) of actions" :key="index" type="button" class="text-sm font-medium focus:outline-none text-primary-500 hover:text-primary-600 dark:hover:text-primary-400" @click.stop="onAction(action)">
<button v-for="(action, index) of actions" :key="index" type="button" class="text-sm font-medium focus:outline-none text-primary-500 dark:text-primary-400 hover:text-primary-400 dark:hover:text-primary-500" @click.stop="onAction(action)">
{{ action.label }}
</button>
</div>
</div>
<div class="flex-shrink-0 flex items-center gap-3">
<div v-if="!description && actions.length" class="flex items-center gap-2">
<button v-for="(action, index) of actions" :key="index" type="button" class="text-sm font-medium focus:outline-none text-primary-500 hover:text-primary-600 dark:hover:text-primary-400" @click.stop="onAction(action)">
<button v-for="(action, index) of actions" :key="index" type="button" class="text-sm font-medium focus:outline-none text-primary-500 dark:text-primary-400 hover:text-primary-400 dark:hover:text-primary-500" @click.stop="onAction(action)">
{{ action.label }}
</button>
</div>
@@ -56,6 +56,7 @@ import type { PropType } from 'vue'
import Icon from '../elements/Icon.vue'
import { useTimer } from '../../composables/useTimer'
import { classNames } from '../../utils'
import type { ToastNotificationAction } from '../../types'
import $ui from '#build/ui'
const props = defineProps({
@@ -172,7 +173,7 @@ function onClose () {
emit('close')
}
function onAction (action) {
function onAction (action: ToastNotificationAction) {
if (timer) {
timer.stop()
}

View File

@@ -17,11 +17,12 @@
</template>
<script setup lang="ts">
import type { ToastNotification } from '../../types'
import Notification from './Notification.vue'
import { useNuxtApp, useState } from '#imports'
const { $toast } = useNuxtApp()
const notifications = useState('notifications', () => [])
const notifications = useState<ToastNotification[]>('notifications', () => [])
</script>
<script lang="ts">

View File

@@ -17,8 +17,8 @@
</template>
<script setup lang="ts">
import type { Ref, PropType } from 'vue'
import { computed, ref, onMounted } from 'vue'
import type { PropType } from 'vue'
import { defu } from 'defu'
import { Popover, PopoverButton, PopoverPanel } from '@headlessui/vue'
import { usePopper } from '../../composables/usePopper'
@@ -55,7 +55,15 @@ const props = defineProps({
},
popperOptions: {
type: Object as PropType<PopperOptions>,
default: () => {}
default: () => ({})
},
openDelay: {
type: Number,
default: 50
},
closeDelay: {
type: Number,
default: 0
}
})
@@ -63,13 +71,15 @@ const popperOptions = computed<PopperOptions>(() => defu({}, props.popperOptions
const [trigger, container] = usePopper(popperOptions.value)
const popoverApi: Ref<any> = ref(null)
// https://github.com/tailwindlabs/headlessui/blob/f66f4926c489fc15289d528294c23a3dc2aee7b1/packages/%40headlessui-vue/src/components/popover/popover.ts#L151
const popoverApi = ref<any>(null)
let openTimeout: NodeJS.Timeout | null = null
let closeTimeout: NodeJS.Timeout | null = null
onMounted(() => {
setTimeout(() => {
// @ts-expect-error internals
const popoverProvides = trigger.value?.$.provides
if (!popoverProvides) {
return
@@ -77,7 +87,7 @@ onMounted(() => {
const popoverProvidesSymbols = Object.getOwnPropertySymbols(popoverProvides)
popoverApi.value = popoverProvidesSymbols.length && popoverProvides[popoverProvidesSymbols[0]]
// stop trigger click propagation on hover
popoverApi.value.button.addEventListener('click', (e: Event) => {
popoverApi.value?.button?.addEventListener('click', (e: Event) => {
if (props.mode === 'hover') {
e.stopPropagation()
}
@@ -89,6 +99,7 @@ function onMouseOver () {
if (props.mode !== 'hover' || !popoverApi.value) {
return
}
// cancel programmed closing
if (closeTimeout) {
clearTimeout(closeTimeout)
@@ -101,13 +112,14 @@ function onMouseOver () {
openTimeout = openTimeout || setTimeout(() => {
popoverApi.value.togglePopover && popoverApi.value.togglePopover()
openTimeout = null
}, 50)
}, props.openDelay)
}
function onMouseLeave () {
if (props.mode !== 'hover' || !popoverApi.value) {
return
}
// cancel programmed opening
if (openTimeout) {
clearTimeout(openTimeout)
@@ -120,7 +132,7 @@ function onMouseLeave () {
closeTimeout = closeTimeout || setTimeout(() => {
popoverApi.value.closePopover && popoverApi.value.closePopover()
closeTimeout = null
}, 0)
}, props.closeDelay)
}
</script>

View File

@@ -1,15 +1,22 @@
<template>
<div ref="trigger" :class="wrapperClass" @mouseover="open = true" @mouseleave="open = false">
<div ref="trigger" :class="wrapperClass" @mouseover="onMouseOver" @mouseleave="onMouseLeave">
<slot :open="open">
Hover me
</slot>
<div v-if="open" ref="container" :class="[containerClass, widthClass]">
<transition appear v-bind="transitionClass">
<div :class="baseClass">
<div :class="[baseClass, backgroundClass, roundedClass, shadowClass, ringClass]">
<slot name="text">
{{ text }}
<span class="truncate">{{ text }}</span>
</slot>
<span v-if="shortcuts?.length" class="inline-flex items-center justify-end flex-shrink-0 gap-0.5 ml-1">
<span class="mr-1 u-text-gray-700">&middot;</span>
<kbd v-for="shortcut of shortcuts" :key="shortcut" class="flex items-center justify-center font-sans px-1 h-4 min-w-[16px] text-[10px] u-bg-gray-100 rounded u-text-gray-900">
{{ shortcut }}
</kbd>
</span>
</div>
</transition>
</div>
@@ -29,6 +36,10 @@ const props = defineProps({
type: String,
default: null
},
shortcuts: {
type: Array as PropType<string[]>,
default: () => []
},
wrapperClass: {
type: String,
default: () => $ui.tooltip.wrapper
@@ -41,6 +52,22 @@ const props = defineProps({
type: String,
default: () => $ui.tooltip.width
},
backgroundClass: {
type: String,
default: () => $ui.tooltip.background
},
shadowClass: {
type: String,
default: () => $ui.tooltip.shadow
},
ringClass: {
type: String,
default: () => $ui.tooltip.ring
},
roundedClass: {
type: String,
default: () => $ui.tooltip.rounded
},
baseClass: {
type: String,
default: () => $ui.tooltip.base
@@ -51,7 +78,15 @@ const props = defineProps({
},
popperOptions: {
type: Object as PropType<PopperOptions>,
default: () => {}
default: () => ({})
},
openDelay: {
type: Number,
default: 0
},
closeDelay: {
type: Number,
default: 0
}
})
@@ -60,6 +95,43 @@ const popperOptions = computed<PopperOptions>(() => defu({}, props.popperOptions
const [trigger, container] = usePopper(popperOptions.value)
const open = ref(false)
let openTimeout: NodeJS.Timeout | null = null
let closeTimeout: NodeJS.Timeout | null = null
// Methods
function onMouseOver () {
// cancel programmed closing
if (closeTimeout) {
clearTimeout(closeTimeout)
closeTimeout = null
}
// dropdown already open
if (open.value) {
return
}
openTimeout = openTimeout || setTimeout(() => {
open.value = true
openTimeout = null
}, props.openDelay)
}
function onMouseLeave () {
// cancel programmed opening
if (openTimeout) {
clearTimeout(openTimeout)
openTimeout = null
}
// dropdown already closed
if (!open.value) {
return
}
closeTimeout = closeTimeout || setTimeout(() => {
open.value = false
closeTimeout = null
}, props.closeDelay)
}
</script>
<script lang="ts">

View File

@@ -1,6 +1,6 @@
import { ref, onMounted, watchEffect } from 'vue'
import type { Ref } from 'vue'
import { popperGenerator, defaultModifiers } from '@popperjs/core/lib/popper-lite'
import { popperGenerator, defaultModifiers, VirtualElement } from '@popperjs/core/lib/popper-lite'
import type { Instance } from '@popperjs/core'
import { omitBy, isUndefined } from 'lodash-es'
import flip from '@popperjs/core/lib/modifiers/flip'
@@ -8,6 +8,7 @@ import offset from '@popperjs/core/lib/modifiers/offset'
import preventOverflow from '@popperjs/core/lib/modifiers/preventOverflow'
import computeStyles from '@popperjs/core/lib/modifiers/computeStyles'
import eventListeners from '@popperjs/core/lib/modifiers/eventListeners'
import { MaybeElement, unrefElement } from '@vueuse/core'
import type { PopperOptions } from '../types'
export const createPopper = popperGenerator({
@@ -25,21 +26,22 @@ export function usePopper ({
resize = true,
placement,
strategy
}: PopperOptions, virtualReference: Ref<Object> = null) {
const reference: Ref<HTMLElement> = ref(null)
const popper: Ref<HTMLElement> = ref(null)
const instance: Ref<Instance> = ref(null)
}: PopperOptions, virtualReference?: Ref<Element | VirtualElement>) {
const reference = ref<MaybeElement>(null)
const popper = ref<MaybeElement>(null)
const instance = ref<Instance | null>(null)
onMounted(() => {
watchEffect((onInvalidate) => {
if (!popper.value) { return }
if (!reference.value && !virtualReference.value) { return }
if (!reference.value && !virtualReference?.value) { return }
const popperEl = popper.value.$el || popper.value
const referenceEl = virtualReference?.value || reference.value.$el || reference.value
const popperEl = unrefElement(popper)
const referenceEl = virtualReference?.value || unrefElement(reference)
// if (!(referenceEl instanceof HTMLElement)) { return }
if (!(popperEl instanceof HTMLElement)) { return }
if (!referenceEl) { return }
instance.value = createPopper(referenceEl, popperEl, omitBy({
placement,
@@ -76,5 +78,5 @@ export function usePopper ({
})
})
return [reference, popper, instance]
return [reference, popper, instance] as const
}

View File

@@ -1,10 +1,10 @@
import { Ref, ref, computed } from 'vue-demi'
import { ref, computed } from 'vue-demi'
import { useTimestamp } from '@vueuse/core'
export function useTimer (cb: (...args: unknown[]) => any, interval: number) {
let timer: number | null = null
const timestamp = useTimestamp({ controls: true })
const startTime: Ref<number | null> = ref(null)
const startTime = ref<number | null>(null)
const remaining = computed(() => {
if (!startTime.value) {
@@ -46,7 +46,7 @@ export function useTimer (cb: (...args: unknown[]) => any, interval: number) {
}
function resume () {
startTime.value += (Date.now() - timestamp.timestamp.value)
startTime.value = (startTime.value || 0) + (Date.now() - timestamp.timestamp.value)
timestamp.resume()
set()
}

View File

@@ -1,9 +1,8 @@
import type { Ref } from 'vue'
import { defineNuxtPlugin, useState } from '#app'
import type { ToastNotification } from '../types'
export default defineNuxtPlugin(() => {
const notifications: Ref<ToastNotification[]> = useState('notifications', () => [])
const notifications = useState<ToastNotification[]>('notifications', () => [])
function addNotification (notification: Partial<ToastNotification>) {
const body = {

View File

@@ -1,4 +1,4 @@
export default (variantColors: string[]) => {
export default function defaultPreset (variantColors: string[]) {
const button = {
base: 'font-medium focus:outline-none disabled:cursor-not-allowed disabled:opacity-75 focus:ring-offset-white dark:focus:ring-offset-black',
rounded: 'rounded-md',
@@ -342,7 +342,7 @@ export default (variantColors: string[]) => {
wrapper: 'relative inline-flex text-left',
container: 'z-20',
width: 'w-48',
base: 'u-bg-white divide-y u-divide-gray-100 rounded-md ring-1 u-ring-gray-200 shadow-lg',
base: 'u-bg-white divide-y u-divide-gray-100 rounded-md ring-1 u-ring-gray-200 shadow-lg focus:outline-none',
group: 'py-1',
item: {
base: 'group flex items-center gap-3 px-4 py-2 text-sm w-full',
@@ -487,7 +487,11 @@ export default (variantColors: string[]) => {
wrapper: 'relative inline-flex',
container: 'z-20',
width: 'max-w-xs',
base: 'invisible w-auto h-6 px-2 py-1 space-x-1 truncate rounded shadow lg:visible u-bg-gray-800 truncate u-text-gray-50 text-xs',
background: 'u-bg-white',
shadow: 'shadow',
rounded: 'rounded',
ring: 'ring-1 u-ring-gray-200',
base: 'invisible lg:visible h-6 px-2 py-1 text-xs font-normal',
transition: {
enterActiveClass: 'transition ease-out duration-200',
enterFromClass: 'opacity-0 translate-y-1',
@@ -566,3 +570,5 @@ export default (variantColors: string[]) => {
contextMenu
}
}
export type DefaultPreset = ReturnType<typeof defaultPreset>

View File

@@ -1,6 +1,6 @@
import type { UseFuseOptions } from '@vueuse/integrations/useFuse'
import type { FuseSortFunctionMatch, FuseSortFunctionMatchList } from 'fuse.js'
import type { Avatar } from './avatar'
export interface Command {
id: string | number
prefix?: string
@@ -11,6 +11,10 @@ export interface Command {
chip?: string
disabled?: boolean
shortcuts?: string[]
group?: string
score?: number
matches?: (FuseSortFunctionMatch | FuseSortFunctionMatchList)[]
[key: string]: any
}
export interface Group {
@@ -19,4 +23,5 @@ export interface Group {
inactive?: string
commands: Command[]
options?: Partial<UseFuseOptions<Command>>
[key: string]: any
}

View File

@@ -1,3 +1,8 @@
export interface ToastNotificationAction {
label: string,
click: Function
}
export interface ToastNotification {
id: string
title: string
@@ -5,10 +10,8 @@ export interface ToastNotification {
type: string
icon?: string
timeout: number
actions?: {
label: string,
click: Function
}[]
actions?: ToastNotificationAction[]
click?: Function
callback?: Function
}

View File

@@ -1,3 +1,14 @@
{
"extends": "./docs/.nuxt/tsconfig.json"
"extends": "./docs/.nuxt/tsconfig.json",
"compilerOptions": {
"module": "esnext"
},
"include": [
"./**/*",
"./docs/.nuxt/nuxt.d.ts"
],
"exclude": [
"node_modules",
"dist"
]
}

2388
yarn.lock

File diff suppressed because it is too large Load Diff