@nuxt/ui 3.0.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nuxt/ui/accordion.ts +25 -4
- package/.nuxt/ui/alert.ts +52 -31
- package/.nuxt/ui/avatar-group.ts +24 -3
- package/.nuxt/ui/avatar.ts +26 -5
- package/.nuxt/ui/badge.ts +56 -35
- package/.nuxt/ui/breadcrumb.ts +28 -7
- package/.nuxt/ui/button-group.ts +23 -2
- package/.nuxt/ui/button.ts +66 -45
- package/.nuxt/ui/calendar.ts +39 -18
- package/.nuxt/ui/card.ts +28 -7
- package/.nuxt/ui/carousel.ts +29 -8
- package/.nuxt/ui/checkbox-group.ts +82 -0
- package/.nuxt/ui/checkbox.ts +163 -29
- package/.nuxt/ui/chip.ts +31 -10
- package/.nuxt/ui/collapsible.ts +23 -2
- package/.nuxt/ui/color-picker.ts +26 -5
- package/.nuxt/ui/command-palette.ts +37 -16
- package/.nuxt/ui/container.ts +24 -3
- package/.nuxt/ui/context-menu.ts +56 -35
- package/.nuxt/ui/drawer.ts +33 -12
- package/.nuxt/ui/dropdown-menu.ts +57 -36
- package/.nuxt/ui/form-field.ts +29 -8
- package/.nuxt/ui/form.ts +23 -2
- package/.nuxt/ui/index.ts +1 -0
- package/.nuxt/ui/input-menu.ts +65 -44
- package/.nuxt/ui/input-number.ts +43 -22
- package/.nuxt/ui/input.ts +46 -25
- package/.nuxt/ui/kbd.ts +27 -6
- package/.nuxt/ui/link.ts +26 -5
- package/.nuxt/ui/modal.ts +28 -7
- package/.nuxt/ui/navigation-menu.ts +103 -84
- package/.nuxt/ui/pagination.ts +23 -2
- package/.nuxt/ui/pin-input.ts +43 -22
- package/.nuxt/ui/popover.ts +25 -4
- package/.nuxt/ui/progress.ts +40 -19
- package/.nuxt/ui/radio-group.ts +273 -37
- package/.nuxt/ui/select-menu.ts +59 -35
- package/.nuxt/ui/select.ts +55 -34
- package/.nuxt/ui/separator.ts +31 -10
- package/.nuxt/ui/skeleton.ts +24 -3
- package/.nuxt/ui/slideover.ts +27 -6
- package/.nuxt/ui/slider.ts +39 -18
- package/.nuxt/ui/stepper.ts +41 -20
- package/.nuxt/ui/switch.ts +44 -23
- package/.nuxt/ui/table.ts +38 -17
- package/.nuxt/ui/tabs.ts +55 -34
- package/.nuxt/ui/textarea.ts +63 -37
- package/.nuxt/ui/toast.ts +47 -26
- package/.nuxt/ui/toaster.ts +23 -2
- package/.nuxt/ui/tooltip.ts +25 -4
- package/.nuxt/ui/tree.ts +41 -20
- package/.nuxt/ui.css +56 -12
- package/README.md +11 -0
- package/cli/templates.mjs +18 -17
- package/dist/module.d.mts +2 -1
- package/dist/module.json +5 -5
- package/dist/module.mjs +11 -7
- package/dist/runtime/components/Accordion.vue +36 -92
- package/dist/runtime/components/Accordion.vue.d.ts +91 -0
- package/dist/runtime/components/Alert.vue +37 -100
- package/dist/runtime/components/Alert.vue.d.ts +96 -0
- package/dist/runtime/components/App.vue +28 -34
- package/dist/runtime/components/App.vue.d.ts +24 -0
- package/dist/runtime/components/Avatar.vue +47 -78
- package/dist/runtime/components/Avatar.vue.d.ts +60 -0
- package/dist/runtime/components/AvatarGroup.vue +40 -77
- package/dist/runtime/components/AvatarGroup.vue.d.ts +40 -0
- package/dist/runtime/components/Badge.vue +33 -62
- package/dist/runtime/components/Badge.vue.d.ts +62 -0
- package/dist/runtime/components/Breadcrumb.vue +36 -88
- package/dist/runtime/components/Breadcrumb.vue.d.ts +82 -0
- package/dist/runtime/components/Button.vue +96 -105
- package/dist/runtime/components/Button.vue.d.ts +73 -0
- package/dist/runtime/components/ButtonGroup.vue +20 -46
- package/dist/runtime/components/ButtonGroup.vue.d.ts +55 -0
- package/dist/runtime/components/Calendar.vue +73 -127
- package/dist/runtime/components/Calendar.vue.d.ts +107 -0
- package/dist/runtime/components/Card.vue +18 -40
- package/dist/runtime/components/Card.vue.d.ts +38 -0
- package/dist/runtime/components/Carousel.vue +112 -230
- package/dist/runtime/components/Carousel.vue.d.ts +120 -0
- package/dist/runtime/components/Checkbox.vue +52 -93
- package/dist/runtime/components/Checkbox.vue.d.ts +76 -0
- package/dist/runtime/components/CheckboxGroup.vue +121 -0
- package/dist/runtime/components/CheckboxGroup.vue.d.ts +75 -0
- package/dist/runtime/components/Chip.vue +26 -69
- package/dist/runtime/components/Chip.vue.d.ts +71 -0
- package/dist/runtime/components/Collapsible.vue +22 -41
- package/dist/runtime/components/Collapsible.vue.d.ts +50 -0
- package/dist/runtime/components/ColorPicker.vue +111 -197
- package/dist/runtime/components/ColorPicker.vue.d.ts +63 -0
- package/dist/runtime/components/CommandPalette.vue +94 -234
- package/dist/runtime/components/CommandPalette.vue.d.ts +173 -0
- package/dist/runtime/components/Container.vue +15 -28
- package/dist/runtime/components/Container.vue.d.ts +27 -0
- package/dist/runtime/components/ContextMenu.vue +32 -119
- package/dist/runtime/components/ContextMenu.vue.d.ts +127 -0
- package/dist/runtime/components/ContextMenuContent.vue +71 -72
- package/dist/runtime/components/ContextMenuContent.vue.d.ts +105 -0
- package/dist/runtime/components/Drawer.vue +49 -87
- package/dist/runtime/components/Drawer.vue.d.ts +88 -0
- package/dist/runtime/components/DropdownMenu.vue +37 -129
- package/dist/runtime/components/DropdownMenu.vue.d.ts +141 -0
- package/dist/runtime/components/DropdownMenuContent.vue +76 -79
- package/dist/runtime/components/DropdownMenuContent.vue.d.ts +55 -0
- package/dist/runtime/components/Form.vue +135 -219
- package/dist/runtime/components/Form.vue.d.ts +66 -0
- package/dist/runtime/components/FormField.vue +36 -77
- package/dist/runtime/components/FormField.vue.d.ts +70 -0
- package/dist/runtime/components/Icon.vue +12 -19
- package/dist/runtime/components/Icon.vue.d.ts +17 -0
- package/dist/runtime/components/Input.vue +82 -140
- package/dist/runtime/components/Input.vue.d.ts +91 -0
- package/dist/runtime/components/InputMenu.vue +193 -302
- package/dist/runtime/components/InputMenu.vue.d.ts +312 -0
- package/dist/runtime/components/InputNumber.vue +71 -133
- package/dist/runtime/components/InputNumber.vue.d.ts +193 -0
- package/dist/runtime/components/Kbd.vue +20 -46
- package/dist/runtime/components/Kbd.vue.d.ts +55 -0
- package/dist/runtime/components/Link.vue +98 -173
- package/dist/runtime/components/Link.vue.d.ts +124 -0
- package/dist/runtime/components/LinkBase.vue +33 -41
- package/dist/runtime/components/LinkBase.vue.d.ts +48 -0
- package/dist/runtime/components/Modal.vue +53 -116
- package/dist/runtime/components/Modal.vue.d.ts +109 -0
- package/dist/runtime/components/NavigationMenu.vue +78 -186
- package/dist/runtime/components/NavigationMenu.vue.d.ts +159 -0
- package/dist/runtime/components/OverlayProvider.vue +14 -18
- package/dist/runtime/components/OverlayProvider.vue.d.ts +2 -0
- package/dist/runtime/components/Pagination.vue +46 -140
- package/dist/runtime/components/Pagination.vue.d.ts +143 -0
- package/dist/runtime/components/PinInput.vue +61 -78
- package/dist/runtime/components/PinInput.vue.d.ts +68 -0
- package/dist/runtime/components/Popover.vue +47 -84
- package/dist/runtime/components/Popover.vue.d.ts +80 -0
- package/dist/runtime/components/Progress.vue +70 -131
- package/dist/runtime/components/Progress.vue.d.ts +97 -0
- package/dist/runtime/components/RadioGroup.vue +75 -126
- package/dist/runtime/components/RadioGroup.vue.d.ts +88 -0
- package/dist/runtime/components/Select.vue +115 -202
- package/dist/runtime/components/Select.vue.d.ts +139 -0
- package/dist/runtime/components/SelectMenu.vue +167 -281
- package/dist/runtime/components/SelectMenu.vue.d.ts +184 -0
- package/dist/runtime/components/Separator.vue +29 -71
- package/dist/runtime/components/Separator.vue.d.ts +75 -0
- package/dist/runtime/components/Skeleton.vue +21 -23
- package/dist/runtime/components/Skeleton.vue.d.ts +26 -0
- package/dist/runtime/components/Slideover.vue +53 -120
- package/dist/runtime/components/Slideover.vue.d.ts +111 -0
- package/dist/runtime/components/Slider.vue +46 -84
- package/dist/runtime/components/Slider.vue.d.ts +71 -0
- package/dist/runtime/components/Stepper.vue +44 -113
- package/dist/runtime/components/Stepper.vue.d.ts +89 -0
- package/dist/runtime/components/Switch.vue +45 -93
- package/dist/runtime/components/Switch.vue.d.ts +73 -0
- package/dist/runtime/components/Table.vue +165 -264
- package/dist/runtime/components/Table.vue.d.ts +183 -0
- package/dist/runtime/components/Tabs.vue +40 -105
- package/dist/runtime/components/Tabs.vue.d.ts +104 -0
- package/dist/runtime/components/Textarea.vue +113 -158
- package/dist/runtime/components/Textarea.vue.d.ts +95 -0
- package/dist/runtime/components/Toast.vue +49 -110
- package/dist/runtime/components/Toast.vue.d.ts +95 -0
- package/dist/runtime/components/Toaster.vue +70 -107
- package/dist/runtime/components/Toaster.vue.d.ts +63 -0
- package/dist/runtime/components/Tooltip.vue +38 -65
- package/dist/runtime/components/Tooltip.vue.d.ts +65 -0
- package/dist/runtime/components/Tree.vue +57 -150
- package/dist/runtime/components/Tree.vue.d.ts +128 -0
- package/dist/runtime/composables/defineShortcuts.d.ts +1 -1
- package/dist/runtime/composables/defineShortcuts.js +0 -1
- package/dist/runtime/composables/useAvatarGroup.d.ts +1 -1
- package/dist/runtime/composables/useButtonGroup.d.ts +2 -2
- package/dist/runtime/composables/useFormField.d.ts +2 -2
- package/dist/runtime/composables/useFormField.js +1 -1
- package/dist/runtime/composables/useOverlay.d.ts +16 -8
- package/dist/runtime/composables/useOverlay.js +14 -6
- package/dist/runtime/composables/usePortal.d.ts +6 -0
- package/dist/runtime/composables/usePortal.js +17 -0
- package/dist/runtime/index.css +1 -1
- package/dist/runtime/inertia/components/Link.vue +146 -0
- package/dist/runtime/inertia/components/Link.vue.d.ts +92 -0
- package/dist/runtime/inertia/stubs.d.ts +43 -0
- package/dist/runtime/inertia/stubs.js +82 -0
- package/dist/runtime/locale/bg.d.ts +3 -0
- package/dist/runtime/locale/bg.js +54 -0
- package/dist/runtime/locale/hy.d.ts +3 -0
- package/dist/runtime/locale/hy.js +54 -0
- package/dist/runtime/locale/index.d.ts +6 -1
- package/dist/runtime/locale/index.js +6 -1
- package/dist/runtime/locale/kk.d.ts +3 -0
- package/dist/runtime/locale/kk.js +54 -0
- package/dist/runtime/locale/tj.d.ts +3 -0
- package/dist/runtime/locale/tj.js +54 -0
- package/dist/runtime/locale/ug_cn.d.ts +3 -0
- package/dist/runtime/locale/ug_cn.js +55 -0
- package/dist/runtime/types/form.d.ts +5 -1
- package/dist/runtime/types/index.d.ts +2 -0
- package/dist/runtime/types/index.js +2 -0
- package/dist/runtime/types/utils.d.ts +70 -10
- package/dist/runtime/utils/index.d.ts +1 -0
- package/dist/runtime/utils/index.js +3 -0
- package/dist/runtime/utils/link.d.ts +4 -27
- package/dist/runtime/utils/link.js +32 -1
- package/dist/runtime/utils/tv.js +2 -2
- package/dist/runtime/vue/components/Icon.vue +7 -8
- package/dist/runtime/vue/components/Icon.vue.d.ts +14 -0
- package/dist/runtime/vue/components/Link.vue +118 -199
- package/dist/runtime/vue/components/Link.vue.d.ts +124 -0
- package/dist/runtime/vue/stubs.d.ts +5 -0
- package/dist/runtime/vue/stubs.js +11 -2
- package/dist/shared/{ui.BCaWD5Ek.mjs → ui.D7lOOabO.mjs} +623 -364
- package/dist/types.d.mts +5 -1
- package/dist/unplugin.d.mts +6 -1
- package/dist/unplugin.mjs +25 -4
- package/dist/vite.mjs +1 -1
- package/package.json +122 -64
- package/dist/module.cjs +0 -62
- package/dist/module.d.cts +0 -44
- package/dist/module.d.ts +0 -44
- package/dist/shared/ui.C6uTSFTI.cjs +0 -3555
- package/dist/types.d.ts +0 -1
- package/dist/unplugin.cjs +0 -232
- package/dist/unplugin.d.cts +0 -61
- package/dist/unplugin.d.ts +0 -61
- package/dist/vite.cjs +0 -23
- package/dist/vite.d.cts +0 -15
- package/dist/vite.d.ts +0 -15
|
@@ -1,46 +1,27 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import
|
|
3
|
-
import type { AppConfig } from '@nuxt/schema'
|
|
4
|
-
import _appConfig from '#build/app.config'
|
|
5
|
-
import theme from '#build/ui/collapsible'
|
|
6
|
-
import { tv } from '../utils/tv'
|
|
7
|
-
|
|
8
|
-
const appConfigCollapsible = _appConfig as AppConfig & { ui: { collapsible: Partial<typeof theme> } }
|
|
9
|
-
|
|
10
|
-
const collapsible = tv({ extend: tv(theme), ...(appConfigCollapsible.ui?.collapsible || {}) })
|
|
11
|
-
|
|
12
|
-
export interface CollapsibleProps extends Pick<CollapsibleRootProps, 'defaultOpen' | 'open' | 'disabled' | 'unmountOnHide'> {
|
|
13
|
-
/**
|
|
14
|
-
* The element or component this component should render as.
|
|
15
|
-
* @defaultValue 'div'
|
|
16
|
-
*/
|
|
17
|
-
as?: any
|
|
18
|
-
class?: any
|
|
19
|
-
ui?: Partial<typeof collapsible.slots>
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface CollapsibleEmits extends CollapsibleRootEmits {}
|
|
23
|
-
|
|
24
|
-
export interface CollapsibleSlots {
|
|
25
|
-
default(props: { open: boolean }): any
|
|
26
|
-
content(props?: {}): any
|
|
27
|
-
}
|
|
1
|
+
<script>
|
|
2
|
+
import theme from "#build/ui/collapsible";
|
|
28
3
|
</script>
|
|
29
4
|
|
|
30
|
-
<script setup
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
5
|
+
<script setup>
|
|
6
|
+
import { computed } from "vue";
|
|
7
|
+
import { CollapsibleRoot, CollapsibleTrigger, CollapsibleContent, useForwardPropsEmits } from "reka-ui";
|
|
8
|
+
import { reactivePick } from "@vueuse/core";
|
|
9
|
+
import { useAppConfig } from "#imports";
|
|
10
|
+
import { tv } from "../utils/tv";
|
|
11
|
+
const props = defineProps({
|
|
12
|
+
as: { type: null, required: false },
|
|
13
|
+
class: { type: null, required: false },
|
|
14
|
+
ui: { type: null, required: false },
|
|
15
|
+
defaultOpen: { type: Boolean, required: false },
|
|
16
|
+
open: { type: Boolean, required: false },
|
|
17
|
+
disabled: { type: Boolean, required: false },
|
|
18
|
+
unmountOnHide: { type: Boolean, required: false, default: true }
|
|
19
|
+
});
|
|
20
|
+
const emits = defineEmits(["update:open"]);
|
|
21
|
+
const slots = defineSlots();
|
|
22
|
+
const appConfig = useAppConfig();
|
|
23
|
+
const rootProps = useForwardPropsEmits(reactivePick(props, "as", "defaultOpen", "open", "disabled", "unmountOnHide"), emits);
|
|
24
|
+
const ui = computed(() => tv({ extend: tv(theme), ...appConfig.ui?.collapsible || {} })());
|
|
44
25
|
</script>
|
|
45
26
|
|
|
46
27
|
<template>
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { CollapsibleRootProps, CollapsibleRootEmits } from 'reka-ui';
|
|
2
|
+
import type { AppConfig } from '@nuxt/schema';
|
|
3
|
+
import theme from '#build/ui/collapsible';
|
|
4
|
+
import type { ComponentConfig } from '../types/utils';
|
|
5
|
+
type Collapsible = ComponentConfig<typeof theme, AppConfig, 'collapsible'>;
|
|
6
|
+
export interface CollapsibleProps extends Pick<CollapsibleRootProps, 'defaultOpen' | 'open' | 'disabled' | 'unmountOnHide'> {
|
|
7
|
+
/**
|
|
8
|
+
* The element or component this component should render as.
|
|
9
|
+
* @defaultValue 'div'
|
|
10
|
+
*/
|
|
11
|
+
as?: any;
|
|
12
|
+
class?: any;
|
|
13
|
+
ui?: Collapsible['slots'];
|
|
14
|
+
}
|
|
15
|
+
export interface CollapsibleEmits extends CollapsibleRootEmits {
|
|
16
|
+
}
|
|
17
|
+
export interface CollapsibleSlots {
|
|
18
|
+
default(props: {
|
|
19
|
+
open: boolean;
|
|
20
|
+
}): any;
|
|
21
|
+
content(props?: {}): any;
|
|
22
|
+
}
|
|
23
|
+
declare const _default: __VLS_WithTemplateSlots<import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<CollapsibleProps>, {
|
|
24
|
+
unmountOnHide: boolean;
|
|
25
|
+
}>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, any, string, import("vue").PublicProps, any, {
|
|
26
|
+
unmountOnHide: boolean;
|
|
27
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>, Readonly<CollapsibleSlots> & CollapsibleSlots>;
|
|
28
|
+
export default _default;
|
|
29
|
+
type __VLS_WithDefaults<P, D> = {
|
|
30
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_PrettifyLocal<P[K] & {
|
|
31
|
+
default: D[K];
|
|
32
|
+
}> : P[K];
|
|
33
|
+
};
|
|
34
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
35
|
+
type __VLS_TypePropsToOption<T> = {
|
|
36
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
37
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
38
|
+
} : {
|
|
39
|
+
type: import('vue').PropType<T[K]>;
|
|
40
|
+
required: true;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
44
|
+
new (): {
|
|
45
|
+
$slots: S;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
type __VLS_PrettifyLocal<T> = {
|
|
49
|
+
[K in keyof T]: T[K];
|
|
50
|
+
} & {};
|
|
@@ -1,271 +1,185 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import _appConfig from '#build/app.config'
|
|
7
|
-
import theme from '#build/ui/color-picker'
|
|
8
|
-
import { tv } from '../utils/tv'
|
|
9
|
-
import type { HSLObject } from 'colortranslator'
|
|
10
|
-
|
|
11
|
-
const appConfigColorPicker = _appConfig as AppConfig & { ui: { colorPicker: Partial<typeof theme> } }
|
|
12
|
-
|
|
13
|
-
const colorPicker = tv({ extend: tv(theme), ...(appConfigColorPicker.ui?.colorPicker || {}) })
|
|
14
|
-
|
|
15
|
-
type ColorPickerVariants = VariantProps<typeof colorPicker>
|
|
16
|
-
|
|
17
|
-
type HSVColor = {
|
|
18
|
-
h: number
|
|
19
|
-
s: number
|
|
20
|
-
v: number
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function HSLtoHSV(hsl: HSLObject): HSVColor {
|
|
24
|
-
const x = hsl.S * (hsl.L < 50 ? hsl.L : 100 - hsl.L)
|
|
25
|
-
const v = hsl.L + (x / 100)
|
|
26
|
-
|
|
1
|
+
<script>
|
|
2
|
+
import theme from "#build/ui/color-picker";
|
|
3
|
+
function HSLtoHSV(hsl) {
|
|
4
|
+
const x = hsl.S * (hsl.L < 50 ? hsl.L : 100 - hsl.L);
|
|
5
|
+
const v = hsl.L + x / 100;
|
|
27
6
|
return {
|
|
28
7
|
h: hsl.H,
|
|
29
8
|
s: hsl.L === 0 ? hsl.S : 2 * x / v,
|
|
30
9
|
v
|
|
31
|
-
}
|
|
10
|
+
};
|
|
32
11
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const x = (200 - hsv.s) * hsv.v / 100
|
|
36
|
-
|
|
12
|
+
function HSVtoHSL(hsv) {
|
|
13
|
+
const x = (200 - hsv.s) * hsv.v / 100;
|
|
37
14
|
return {
|
|
38
15
|
H: hsv.h,
|
|
39
16
|
S: x === 0 || x === 200 ? 0 : Math.round(hsv.s * hsv.v / (x <= 100 ? x : 200 - x)),
|
|
40
17
|
L: Math.round(x / 2)
|
|
41
|
-
}
|
|
18
|
+
};
|
|
42
19
|
}
|
|
43
|
-
|
|
44
|
-
export type ColorPickerProps = {
|
|
45
|
-
/**
|
|
46
|
-
* The element or component this component should render as.
|
|
47
|
-
* @defaultValue 'div'
|
|
48
|
-
*/
|
|
49
|
-
as?: any
|
|
50
|
-
/**
|
|
51
|
-
* Throttle time in ms for the color picker
|
|
52
|
-
*/
|
|
53
|
-
throttle?: number
|
|
54
|
-
/**
|
|
55
|
-
* Disable the color picker
|
|
56
|
-
*/
|
|
57
|
-
disabled?: boolean
|
|
58
|
-
/**
|
|
59
|
-
* The default value of the color picker
|
|
60
|
-
*/
|
|
61
|
-
defaultValue?: string
|
|
62
|
-
/**
|
|
63
|
-
* Format of the color
|
|
64
|
-
* @defaultValue 'hex'
|
|
65
|
-
*/
|
|
66
|
-
format?: 'hex' | 'rgb' | 'hsl' | 'cmyk' | 'lab'
|
|
67
|
-
/**
|
|
68
|
-
* @defaultValue 'md'
|
|
69
|
-
*/
|
|
70
|
-
size?: ColorPickerVariants['size']
|
|
71
|
-
class?: any
|
|
72
|
-
ui?: Partial<typeof colorPicker.slots>
|
|
73
|
-
}
|
|
74
|
-
|
|
75
20
|
</script>
|
|
76
21
|
|
|
77
|
-
<script setup
|
|
78
|
-
import { ref, nextTick, computed, toValue } from
|
|
79
|
-
import { Primitive } from
|
|
80
|
-
import { useEventListener, useElementBounding, watchThrottled, watchPausable } from
|
|
81
|
-
import { isClient } from
|
|
82
|
-
import { ColorTranslator } from
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
22
|
+
<script setup>
|
|
23
|
+
import { ref, nextTick, computed, toValue } from "vue";
|
|
24
|
+
import { Primitive } from "reka-ui";
|
|
25
|
+
import { useEventListener, useElementBounding, watchThrottled, watchPausable } from "@vueuse/core";
|
|
26
|
+
import { isClient } from "@vueuse/shared";
|
|
27
|
+
import { ColorTranslator } from "colortranslator";
|
|
28
|
+
import { useAppConfig } from "#imports";
|
|
29
|
+
import { tv } from "../utils/tv";
|
|
30
|
+
const props = defineProps({
|
|
31
|
+
as: { type: null, required: false },
|
|
32
|
+
throttle: { type: Number, required: false, default: 50 },
|
|
33
|
+
disabled: { type: Boolean, required: false },
|
|
34
|
+
defaultValue: { type: String, required: false, default: "#FFFFFF" },
|
|
35
|
+
format: { type: String, required: false, default: "hex" },
|
|
36
|
+
size: { type: null, required: false },
|
|
37
|
+
class: { type: null, required: false },
|
|
38
|
+
ui: { type: null, required: false }
|
|
39
|
+
});
|
|
40
|
+
const modelValue = defineModel({ type: String, ...void 0 });
|
|
41
|
+
const appConfig = useAppConfig();
|
|
42
|
+
const ui = computed(() => tv({ extend: tv(theme), ...appConfig.ui?.colorPicker || {} })({
|
|
43
|
+
size: props.size
|
|
44
|
+
}));
|
|
45
|
+
const pickedColor = computed({
|
|
92
46
|
get() {
|
|
93
47
|
try {
|
|
94
|
-
const color = new ColorTranslator(modelValue.value || props.defaultValue)
|
|
95
|
-
|
|
96
|
-
return HSLtoHSV(color.HSLObject)
|
|
48
|
+
const color = new ColorTranslator(modelValue.value || props.defaultValue);
|
|
49
|
+
return HSLtoHSV(color.HSLObject);
|
|
97
50
|
} catch (_) {
|
|
98
|
-
return { h: 0, s: 0, v: 100 }
|
|
51
|
+
return { h: 0, s: 0, v: 100 };
|
|
99
52
|
}
|
|
100
53
|
},
|
|
101
54
|
set(value) {
|
|
102
55
|
const color = new ColorTranslator(HSVtoHSL(value), {
|
|
103
56
|
decimals: 2,
|
|
104
|
-
labUnit:
|
|
105
|
-
cmykUnit:
|
|
106
|
-
cmykFunction:
|
|
107
|
-
})
|
|
108
|
-
|
|
57
|
+
labUnit: "percent",
|
|
58
|
+
cmykUnit: "percent",
|
|
59
|
+
cmykFunction: "cmyk"
|
|
60
|
+
});
|
|
109
61
|
switch (props.format) {
|
|
110
|
-
case
|
|
111
|
-
modelValue.value = color.RGB
|
|
112
|
-
break
|
|
113
|
-
case
|
|
114
|
-
modelValue.value = color.HSL
|
|
115
|
-
break
|
|
116
|
-
case
|
|
117
|
-
modelValue.value = color.CMYK
|
|
118
|
-
break
|
|
119
|
-
case
|
|
120
|
-
modelValue.value = color.CIELab
|
|
121
|
-
break
|
|
122
|
-
case
|
|
62
|
+
case "rgb":
|
|
63
|
+
modelValue.value = color.RGB;
|
|
64
|
+
break;
|
|
65
|
+
case "hsl":
|
|
66
|
+
modelValue.value = color.HSL;
|
|
67
|
+
break;
|
|
68
|
+
case "cmyk":
|
|
69
|
+
modelValue.value = color.CMYK;
|
|
70
|
+
break;
|
|
71
|
+
case "lab":
|
|
72
|
+
modelValue.value = color.CIELab;
|
|
73
|
+
break;
|
|
74
|
+
case "hex":
|
|
123
75
|
default:
|
|
124
|
-
modelValue.value = color.HEX
|
|
76
|
+
modelValue.value = color.HEX;
|
|
125
77
|
}
|
|
126
78
|
}
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
)
|
|
135
|
-
|
|
136
|
-
const pressedDelta = ref<{ x: number, y: number }>()
|
|
137
|
-
const targetRect = useElementBounding(targetElement)
|
|
138
|
-
const containerRect = useElementBounding(containerElement)
|
|
139
|
-
|
|
140
|
-
function start(event: PointerEvent) {
|
|
141
|
-
if (toValue(disabled)) return event.preventDefault()
|
|
142
|
-
|
|
143
|
-
const container = toValue(containerElement)
|
|
144
|
-
|
|
79
|
+
});
|
|
80
|
+
function useColorDraggable(targetElement, containerElement, axis = "both", initialPosition = { x: 0, y: 0 }, disabled2) {
|
|
81
|
+
const position = ref(initialPosition);
|
|
82
|
+
const pressedDelta = ref();
|
|
83
|
+
const targetRect = useElementBounding(targetElement);
|
|
84
|
+
const containerRect = useElementBounding(containerElement);
|
|
85
|
+
function start(event) {
|
|
86
|
+
if (toValue(disabled2)) return event.preventDefault();
|
|
87
|
+
const container = toValue(containerElement);
|
|
145
88
|
pressedDelta.value = {
|
|
146
89
|
x: event.clientX - (container ? event.clientX - containerRect.left.value + container.scrollLeft : targetRect.left.value),
|
|
147
90
|
y: event.clientY - (container ? event.clientY - containerRect.top.value + container.scrollTop : targetRect.top.value)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
move(event)
|
|
91
|
+
};
|
|
92
|
+
move(event);
|
|
151
93
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (container && (axis === 'x' || axis === 'both')) {
|
|
160
|
-
x = Math.min(Math.max(0, (event.clientX - pressedDelta.value.x) / container.scrollWidth * 100), 100)
|
|
94
|
+
function move(event) {
|
|
95
|
+
if (!pressedDelta.value) return;
|
|
96
|
+
const container = toValue(containerElement);
|
|
97
|
+
let { x, y } = position.value;
|
|
98
|
+
if (container && (axis === "x" || axis === "both")) {
|
|
99
|
+
x = Math.min(Math.max(0, (event.clientX - pressedDelta.value.x) / container.scrollWidth * 100), 100);
|
|
161
100
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
y = Math.min(Math.max(0, (event.clientY - pressedDelta.value.y) / container.scrollHeight * 100), 100)
|
|
101
|
+
if (container && (axis === "y" || axis === "both")) {
|
|
102
|
+
y = Math.min(Math.max(0, (event.clientY - pressedDelta.value.y) / container.scrollHeight * 100), 100);
|
|
165
103
|
}
|
|
166
|
-
|
|
167
|
-
position.value = { x, y }
|
|
104
|
+
position.value = { x, y };
|
|
168
105
|
}
|
|
169
|
-
|
|
170
106
|
function end() {
|
|
171
107
|
if (!pressedDelta.value) {
|
|
172
|
-
return
|
|
108
|
+
return;
|
|
173
109
|
}
|
|
174
|
-
|
|
175
|
-
pressedDelta.value = undefined
|
|
110
|
+
pressedDelta.value = void 0;
|
|
176
111
|
}
|
|
177
|
-
|
|
178
112
|
if (isClient) {
|
|
179
|
-
useEventListener(containerElement,
|
|
180
|
-
useEventListener(window,
|
|
181
|
-
useEventListener(window,
|
|
113
|
+
useEventListener(containerElement, "pointerdown", start);
|
|
114
|
+
useEventListener(window, "pointermove", move);
|
|
115
|
+
useEventListener(window, "pointerup", end);
|
|
182
116
|
}
|
|
183
|
-
|
|
184
117
|
return {
|
|
185
118
|
position
|
|
186
|
-
}
|
|
119
|
+
};
|
|
187
120
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
return (hue * 100) / 360
|
|
121
|
+
function normalizeHue(hue, dir = "left") {
|
|
122
|
+
if (dir === "right") {
|
|
123
|
+
return hue * 100 / 360;
|
|
192
124
|
}
|
|
193
|
-
|
|
194
|
-
return (hue / 100) * 360
|
|
125
|
+
return hue / 100 * 360;
|
|
195
126
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
return 100 - brightness
|
|
127
|
+
function normalizeBrightness(brightness) {
|
|
128
|
+
return 100 - brightness;
|
|
199
129
|
}
|
|
200
|
-
|
|
201
|
-
const
|
|
202
|
-
const
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
const disabled = computed(() => props.disabled)
|
|
207
|
-
|
|
208
|
-
const { position: selectorThumbPosition } = useColorDraggable(selectorThumbRef, selectorRef, 'both', {
|
|
130
|
+
const selectorRef = ref(null);
|
|
131
|
+
const selectorThumbRef = ref(null);
|
|
132
|
+
const trackRef = ref(null);
|
|
133
|
+
const trackThumbRef = ref(null);
|
|
134
|
+
const disabled = computed(() => props.disabled);
|
|
135
|
+
const { position: selectorThumbPosition } = useColorDraggable(selectorThumbRef, selectorRef, "both", {
|
|
209
136
|
x: pickedColor.value.s,
|
|
210
137
|
y: normalizeBrightness(pickedColor.value.v)
|
|
211
|
-
}, disabled)
|
|
212
|
-
|
|
213
|
-
const { position: trackThumbPosition } = useColorDraggable(trackThumbRef, trackRef, 'y', {
|
|
138
|
+
}, disabled);
|
|
139
|
+
const { position: trackThumbPosition } = useColorDraggable(trackThumbRef, trackRef, "y", {
|
|
214
140
|
x: 0,
|
|
215
|
-
y: normalizeHue(pickedColor.value.h,
|
|
216
|
-
}, disabled)
|
|
217
|
-
|
|
141
|
+
y: normalizeHue(pickedColor.value.h, "right")
|
|
142
|
+
}, disabled);
|
|
218
143
|
const { pause: pauseWatchColor, resume: resumeWatchColor } = watchPausable(pickedColor, (hsb) => {
|
|
219
144
|
selectorThumbPosition.value = {
|
|
220
145
|
x: hsb.s,
|
|
221
146
|
y: normalizeBrightness(hsb.v)
|
|
222
|
-
}
|
|
147
|
+
};
|
|
223
148
|
trackThumbPosition.value = {
|
|
224
149
|
x: 0,
|
|
225
|
-
y: normalizeHue(hsb.h,
|
|
226
|
-
}
|
|
227
|
-
})
|
|
228
|
-
|
|
150
|
+
y: normalizeHue(hsb.h, "right")
|
|
151
|
+
};
|
|
152
|
+
});
|
|
229
153
|
watchThrottled([selectorThumbPosition, trackThumbPosition], () => {
|
|
230
|
-
pauseWatchColor()
|
|
231
|
-
|
|
154
|
+
pauseWatchColor();
|
|
232
155
|
pickedColor.value = {
|
|
233
156
|
h: normalizeHue(trackThumbPosition.value.y),
|
|
234
157
|
s: selectorThumbPosition.value.x,
|
|
235
158
|
v: normalizeBrightness(selectorThumbPosition.value.y)
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}, { throttle: () => props.throttle })
|
|
240
|
-
|
|
159
|
+
};
|
|
160
|
+
nextTick(resumeWatchColor);
|
|
161
|
+
}, { throttle: () => props.throttle });
|
|
241
162
|
const trackThumbColor = computed(() => new ColorTranslator(HSVtoHSL({
|
|
242
163
|
h: normalizeHue(trackThumbPosition.value.y),
|
|
243
164
|
s: 100,
|
|
244
165
|
v: 100
|
|
245
|
-
})).HEX)
|
|
246
|
-
|
|
166
|
+
})).HEX);
|
|
247
167
|
const selectorStyle = computed(() => ({
|
|
248
168
|
backgroundColor: trackThumbColor.value
|
|
249
|
-
}))
|
|
250
|
-
|
|
169
|
+
}));
|
|
251
170
|
const selectorThumbStyle = computed(() => ({
|
|
252
171
|
backgroundColor: new ColorTranslator(modelValue.value || props.defaultValue).HEX,
|
|
253
172
|
left: `${selectorThumbPosition.value.x}%`,
|
|
254
173
|
top: `${selectorThumbPosition.value.y}%`
|
|
255
|
-
}))
|
|
256
|
-
|
|
174
|
+
}));
|
|
257
175
|
const trackThumbStyle = computed(() => ({
|
|
258
176
|
backgroundColor: trackThumbColor.value,
|
|
259
177
|
top: `${trackThumbPosition.value.y}%`
|
|
260
|
-
}))
|
|
261
|
-
|
|
262
|
-
const ui = computed(() => colorPicker({
|
|
263
|
-
size: props.size
|
|
264
|
-
}))
|
|
178
|
+
}));
|
|
265
179
|
</script>
|
|
266
180
|
|
|
267
181
|
<template>
|
|
268
|
-
<Primitive :as="as" :class="ui.root({ class: [props.class, props.ui?.root] })" :data-disabled="disabled ? true :
|
|
182
|
+
<Primitive :as="as" :class="ui.root({ class: [props.class, props.ui?.root] })" :data-disabled="disabled ? true : void 0">
|
|
269
183
|
<div :class="ui.picker({ class: props.ui?.picker })">
|
|
270
184
|
<div
|
|
271
185
|
ref="selectorRef"
|
|
@@ -277,7 +191,7 @@ const ui = computed(() => colorPicker({
|
|
|
277
191
|
ref="selectorThumbRef"
|
|
278
192
|
:class="ui.selectorThumb({ class: props.ui?.selectorThumb })"
|
|
279
193
|
:style="selectorThumbStyle"
|
|
280
|
-
:data-disabled="disabled ? true :
|
|
194
|
+
:data-disabled="disabled ? true : void 0"
|
|
281
195
|
/>
|
|
282
196
|
</div>
|
|
283
197
|
</div>
|
|
@@ -290,7 +204,7 @@ const ui = computed(() => colorPicker({
|
|
|
290
204
|
ref="trackThumbRef"
|
|
291
205
|
:class="ui.trackThumb({ class: props.ui?.trackThumb })"
|
|
292
206
|
:style="trackThumbStyle"
|
|
293
|
-
:data-disabled="disabled ? true :
|
|
207
|
+
:data-disabled="disabled ? true : void 0"
|
|
294
208
|
/>
|
|
295
209
|
</div>
|
|
296
210
|
</div>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { AppConfig } from '@nuxt/schema';
|
|
2
|
+
import theme from '#build/ui/color-picker';
|
|
3
|
+
import type { ComponentConfig } from '../types/utils';
|
|
4
|
+
type ColorPicker = ComponentConfig<typeof theme, AppConfig, 'colorPicker'>;
|
|
5
|
+
export type ColorPickerProps = {
|
|
6
|
+
/**
|
|
7
|
+
* The element or component this component should render as.
|
|
8
|
+
* @defaultValue 'div'
|
|
9
|
+
*/
|
|
10
|
+
as?: any;
|
|
11
|
+
/**
|
|
12
|
+
* Throttle time in ms for the color picker
|
|
13
|
+
*/
|
|
14
|
+
throttle?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Disable the color picker
|
|
17
|
+
*/
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* The default value of the color picker
|
|
21
|
+
*/
|
|
22
|
+
defaultValue?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Format of the color
|
|
25
|
+
* @defaultValue 'hex'
|
|
26
|
+
*/
|
|
27
|
+
format?: 'hex' | 'rgb' | 'hsl' | 'cmyk' | 'lab';
|
|
28
|
+
/**
|
|
29
|
+
* @defaultValue 'md'
|
|
30
|
+
*/
|
|
31
|
+
size?: ColorPicker['variants']['size'];
|
|
32
|
+
class?: any;
|
|
33
|
+
ui?: ColorPicker['slots'];
|
|
34
|
+
};
|
|
35
|
+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToOption<{
|
|
36
|
+
modelValue?: string;
|
|
37
|
+
} & ColorPickerProps>, {
|
|
38
|
+
format: string;
|
|
39
|
+
throttle: number;
|
|
40
|
+
defaultValue: string;
|
|
41
|
+
}>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, any, string, import("vue").PublicProps, any, {
|
|
42
|
+
format: "hex" | "rgb" | "hsl" | "cmyk" | "lab";
|
|
43
|
+
defaultValue: string;
|
|
44
|
+
throttle: number;
|
|
45
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
46
|
+
export default _default;
|
|
47
|
+
type __VLS_WithDefaults<P, D> = {
|
|
48
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_PrettifyLocal<P[K] & {
|
|
49
|
+
default: D[K];
|
|
50
|
+
}> : P[K];
|
|
51
|
+
};
|
|
52
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
53
|
+
type __VLS_TypePropsToOption<T> = {
|
|
54
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
55
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
56
|
+
} : {
|
|
57
|
+
type: import('vue').PropType<T[K]>;
|
|
58
|
+
required: true;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
type __VLS_PrettifyLocal<T> = {
|
|
62
|
+
[K in keyof T]: T[K];
|
|
63
|
+
} & {};
|