@personizely/ui 0.0.42
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/LICENSE.md +21 -0
- package/README.md +1 -0
- package/dist/personizely-ui.css +6 -0
- package/dist/personizely-ui.js +26854 -0
- package/dist/personizely-ui.umd.cjs +111 -0
- package/package.json +117 -0
- package/src/assets/index.css +136 -0
- package/src/components/ui/accordion/Accordion.vue +19 -0
- package/src/components/ui/accordion/AccordionContent.vue +24 -0
- package/src/components/ui/accordion/AccordionItem.vue +37 -0
- package/src/components/ui/accordion/AccordionTrigger.vue +39 -0
- package/src/components/ui/accordion/index.ts +2 -0
- package/src/components/ui/alert/Alert.vue +68 -0
- package/src/components/ui/alert/index.ts +22 -0
- package/src/components/ui/alert-dialog/AlertDialog.vue +66 -0
- package/src/components/ui/alert-dialog/AlertDialogContent.vue +44 -0
- package/src/components/ui/alert-dialog/AlertDialogProvider.vue +27 -0
- package/src/components/ui/alert-dialog/AlertDialogTrigger.vue +11 -0
- package/src/components/ui/alert-dialog/index.ts +3 -0
- package/src/components/ui/alert-dialog/useAlertDialog.ts +19 -0
- package/src/components/ui/autocomplete/Autocomplete.vue +170 -0
- package/src/components/ui/autocomplete/AutocompleteContent.vue +27 -0
- package/src/components/ui/autocomplete/AutocompleteEmpty.vue +20 -0
- package/src/components/ui/autocomplete/AutocompleteGroup.vue +29 -0
- package/src/components/ui/autocomplete/AutocompleteItem.vue +26 -0
- package/src/components/ui/autocomplete/AutocompleteRoot.vue +31 -0
- package/src/components/ui/autocomplete/AutocompleteSeparator.vue +23 -0
- package/src/components/ui/autocomplete/index.ts +1 -0
- package/src/components/ui/avatar/Avatar.vue +31 -0
- package/src/components/ui/avatar/AvatarFallback.vue +11 -0
- package/src/components/ui/avatar/AvatarImage.vue +9 -0
- package/src/components/ui/avatar/index.ts +19 -0
- package/src/components/ui/badge/Badge.vue +16 -0
- package/src/components/ui/badge/index.ts +22 -0
- package/src/components/ui/button/Button.vue +123 -0
- package/src/components/ui/button/index.ts +78 -0
- package/src/components/ui/calendar/Calendar.vue +76 -0
- package/src/components/ui/calendar/CalendarCell.vue +24 -0
- package/src/components/ui/calendar/CalendarCellTrigger.vue +38 -0
- package/src/components/ui/calendar/CalendarGrid.vue +24 -0
- package/src/components/ui/calendar/CalendarGridBody.vue +11 -0
- package/src/components/ui/calendar/CalendarGridHead.vue +11 -0
- package/src/components/ui/calendar/CalendarGridRow.vue +21 -0
- package/src/components/ui/calendar/CalendarHeadCell.vue +21 -0
- package/src/components/ui/calendar/CalendarHeader.vue +21 -0
- package/src/components/ui/calendar/CalendarHeading.vue +27 -0
- package/src/components/ui/calendar/CalendarNextButton.vue +32 -0
- package/src/components/ui/calendar/CalendarPrevButton.vue +32 -0
- package/src/components/ui/calendar/index.ts +1 -0
- package/src/components/ui/card/Card.vue +57 -0
- package/src/components/ui/card/CardContent.vue +14 -0
- package/src/components/ui/card/CardDescription.vue +14 -0
- package/src/components/ui/card/CardFooter.vue +14 -0
- package/src/components/ui/card/CardHeader.vue +14 -0
- package/src/components/ui/card/CardTitle.vue +18 -0
- package/src/components/ui/card/CardTray.vue +14 -0
- package/src/components/ui/card/index.ts +1 -0
- package/src/components/ui/checkbox/Checkbox.vue +63 -0
- package/src/components/ui/checkbox/CheckboxBase.vue +39 -0
- package/src/components/ui/checkbox/index.ts +1 -0
- package/src/components/ui/checkbox-group/CheckboxGroup.vue +65 -0
- package/src/components/ui/checkbox-group/index.ts +15 -0
- package/src/components/ui/color-picker/Alpha.vue +63 -0
- package/src/components/ui/color-picker/Angle.vue +145 -0
- package/src/components/ui/color-picker/Checkboard.vue +43 -0
- package/src/components/ui/color-picker/Color.vue +255 -0
- package/src/components/ui/color-picker/ColorPicker.vue +25 -0
- package/src/components/ui/color-picker/Gradient.vue +172 -0
- package/src/components/ui/color-picker/Handle.vue +19 -0
- package/src/components/ui/color-picker/Hue.vue +80 -0
- package/src/components/ui/color-picker/LabelInput.vue +16 -0
- package/src/components/ui/color-picker/Rail.vue +100 -0
- package/src/components/ui/color-picker/Saturation.vue +142 -0
- package/src/components/ui/color-picker/index.ts +4 -0
- package/src/components/ui/combobox/Combobox.vue +202 -0
- package/src/components/ui/combobox/ComboboxContent.vue +27 -0
- package/src/components/ui/combobox/ComboboxEmpty.vue +20 -0
- package/src/components/ui/combobox/ComboboxGroup.vue +29 -0
- package/src/components/ui/combobox/ComboboxInput.vue +52 -0
- package/src/components/ui/combobox/ComboboxItem.vue +26 -0
- package/src/components/ui/combobox/ComboboxRoot.vue +31 -0
- package/src/components/ui/combobox/ComboboxSeparator.vue +23 -0
- package/src/components/ui/combobox/index.ts +1 -0
- package/src/components/ui/date-picker/DatePicker.vue +55 -0
- package/src/components/ui/date-picker/index.ts +1 -0
- package/src/components/ui/date-range-picker/DateRangePicker.vue +137 -0
- package/src/components/ui/date-range-picker/index.ts +1 -0
- package/src/components/ui/dialog/Dialog.vue +78 -0
- package/src/components/ui/dialog/DialogContent.vue +46 -0
- package/src/components/ui/dialog/DialogDescription.vue +24 -0
- package/src/components/ui/dialog/DialogFooter.vue +19 -0
- package/src/components/ui/dialog/DialogHeader.vue +16 -0
- package/src/components/ui/dialog/DialogTitle.vue +29 -0
- package/src/components/ui/dialog/DialogTrigger.vue +11 -0
- package/src/components/ui/dialog/index.ts +1 -0
- package/src/components/ui/drawer/Drawer.vue +88 -0
- package/src/components/ui/drawer/DrawerContent.vue +57 -0
- package/src/components/ui/drawer/DrawerDescription.vue +22 -0
- package/src/components/ui/drawer/DrawerFooter.vue +19 -0
- package/src/components/ui/drawer/DrawerHeader.vue +16 -0
- package/src/components/ui/drawer/DrawerTitle.vue +22 -0
- package/src/components/ui/drawer/DrawerTrigger.vue +11 -0
- package/src/components/ui/drawer/index.ts +21 -0
- package/src/components/ui/dropdown-menu/DropdownCheckboxGroupMenu.vue +87 -0
- package/src/components/ui/dropdown-menu/DropdownMenu.vue +72 -0
- package/src/components/ui/dropdown-menu/DropdownMenuCheckboxItem.vue +40 -0
- package/src/components/ui/dropdown-menu/DropdownMenuContent.vue +37 -0
- package/src/components/ui/dropdown-menu/DropdownMenuGroup.vue +11 -0
- package/src/components/ui/dropdown-menu/DropdownMenuHelp.vue +14 -0
- package/src/components/ui/dropdown-menu/DropdownMenuItem.vue +28 -0
- package/src/components/ui/dropdown-menu/DropdownMenuLabel.vue +24 -0
- package/src/components/ui/dropdown-menu/DropdownMenuPart.vue +64 -0
- package/src/components/ui/dropdown-menu/DropdownMenuPartItem.vue +76 -0
- package/src/components/ui/dropdown-menu/DropdownMenuRadioGroup.vue +19 -0
- package/src/components/ui/dropdown-menu/DropdownMenuRadioItem.vue +41 -0
- package/src/components/ui/dropdown-menu/DropdownMenuSeparator.vue +22 -0
- package/src/components/ui/dropdown-menu/DropdownMenuShortcut.vue +14 -0
- package/src/components/ui/dropdown-menu/DropdownMenuSub.vue +19 -0
- package/src/components/ui/dropdown-menu/DropdownMenuSubContent.vue +30 -0
- package/src/components/ui/dropdown-menu/DropdownMenuSubTrigger.vue +33 -0
- package/src/components/ui/dropdown-menu/DropdownMenuTrigger.vue +13 -0
- package/src/components/ui/dropdown-menu/DropdownRadioGroupMenu.vue +75 -0
- package/src/components/ui/dropdown-menu/index.ts +36 -0
- package/src/components/ui/file-upload-button/FileUploadButton.vue +55 -0
- package/src/components/ui/file-upload-button/index.ts +1 -0
- package/src/components/ui/form/Form.vue +13 -0
- package/src/components/ui/form/FormControl.vue +16 -0
- package/src/components/ui/form/FormDescription.vue +20 -0
- package/src/components/ui/form/FormField.vue +61 -0
- package/src/components/ui/form/FormLabel.vue +23 -0
- package/src/components/ui/form/FormMessage.vue +16 -0
- package/src/components/ui/form/index.ts +2 -0
- package/src/components/ui/form/useFormField.ts +30 -0
- package/src/components/ui/icon/Icon.vue +16 -0
- package/src/components/ui/icon/index.ts +1 -0
- package/src/components/ui/input/Input.vue +51 -0
- package/src/components/ui/input/InputBase.vue +18 -0
- package/src/components/ui/input/index.ts +1 -0
- package/src/components/ui/label/Label.vue +27 -0
- package/src/components/ui/label/index.ts +1 -0
- package/src/components/ui/pagination/Pagination.vue +50 -0
- package/src/components/ui/pagination/PaginationContent.vue +21 -0
- package/src/components/ui/pagination/PaginationEllipsis.vue +24 -0
- package/src/components/ui/pagination/PaginationFirst.vue +32 -0
- package/src/components/ui/pagination/PaginationItem.vue +32 -0
- package/src/components/ui/pagination/PaginationLast.vue +32 -0
- package/src/components/ui/pagination/PaginationNext.vue +32 -0
- package/src/components/ui/pagination/PaginationPrevious.vue +32 -0
- package/src/components/ui/pagination/index.ts +1 -0
- package/src/components/ui/popover/Popover.vue +57 -0
- package/src/components/ui/popover/PopoverTrigger.vue +15 -0
- package/src/components/ui/popover/index.ts +1 -0
- package/src/components/ui/progress/Progress.vue +35 -0
- package/src/components/ui/progress/ProgressIndicator.vue +19 -0
- package/src/components/ui/progress/index.ts +2 -0
- package/src/components/ui/progress-circular/ProgressCircular.vue +85 -0
- package/src/components/ui/progress-circular/index.ts +1 -0
- package/src/components/ui/radio-group/RadioGroup.vue +81 -0
- package/src/components/ui/radio-group/RadioGroupItem.vue +39 -0
- package/src/components/ui/radio-group/index.ts +15 -0
- package/src/components/ui/range-calendar/RangeCalendar.vue +71 -0
- package/src/components/ui/range-calendar/RangeCalendarCell.vue +28 -0
- package/src/components/ui/range-calendar/RangeCalendarCellTrigger.vue +40 -0
- package/src/components/ui/range-calendar/RangeCalendarGrid.vue +24 -0
- package/src/components/ui/range-calendar/RangeCalendarGridBody.vue +11 -0
- package/src/components/ui/range-calendar/RangeCalendarGridHead.vue +11 -0
- package/src/components/ui/range-calendar/RangeCalendarGridRow.vue +21 -0
- package/src/components/ui/range-calendar/RangeCalendarHeadCell.vue +21 -0
- package/src/components/ui/range-calendar/RangeCalendarHeader.vue +21 -0
- package/src/components/ui/range-calendar/RangeCalendarHeading.vue +27 -0
- package/src/components/ui/range-calendar/RangeCalendarNextButton.vue +32 -0
- package/src/components/ui/range-calendar/RangeCalendarPrevButton.vue +32 -0
- package/src/components/ui/range-calendar/index.ts +1 -0
- package/src/components/ui/select/Select.vue +120 -0
- package/src/components/ui/select/SelectContent.vue +45 -0
- package/src/components/ui/select/SelectGroup.vue +19 -0
- package/src/components/ui/select/SelectItem.vue +43 -0
- package/src/components/ui/select/SelectLabel.vue +13 -0
- package/src/components/ui/select/SelectSeparator.vue +17 -0
- package/src/components/ui/select/SelectTrigger.vue +31 -0
- package/src/components/ui/select/SelectValue.vue +11 -0
- package/src/components/ui/select/index.ts +1 -0
- package/src/components/ui/slider/Slider.vue +100 -0
- package/src/components/ui/slider/index.ts +1 -0
- package/src/components/ui/switch/Switch.vue +40 -0
- package/src/components/ui/switch/SwitchBase.vue +36 -0
- package/src/components/ui/switch/index.ts +1 -0
- package/src/components/ui/tabs/Tabs.vue +63 -0
- package/src/components/ui/tabs/TabsContent.vue +26 -0
- package/src/components/ui/tabs/TabsTrigger.vue +27 -0
- package/src/components/ui/tabs/index.ts +28 -0
- package/src/components/ui/textarea/Textarea.vue +13 -0
- package/src/components/ui/textarea/index.ts +1 -0
- package/src/components/ui/toast/Toast.vue +28 -0
- package/src/components/ui/toast/ToastAction.vue +26 -0
- package/src/components/ui/toast/ToastClose.vue +29 -0
- package/src/components/ui/toast/ToastDescription.vue +19 -0
- package/src/components/ui/toast/ToastProvider.vue +11 -0
- package/src/components/ui/toast/ToastTitle.vue +19 -0
- package/src/components/ui/toast/ToastViewport.vue +17 -0
- package/src/components/ui/toast/Toaster.vue +30 -0
- package/src/components/ui/toast/index.ts +34 -0
- package/src/components/ui/toast/useToast.ts +163 -0
- package/src/components/ui/toggle/Toggle.vue +51 -0
- package/src/components/ui/toggle/index.ts +71 -0
- package/src/components/ui/toggle-group/ToggleGroup.vue +58 -0
- package/src/components/ui/toggle-group/ToggleGroupItem.vue +54 -0
- package/src/components/ui/toggle-group/index.ts +1 -0
- package/src/components/ui/tooltip/Tooltip.vue +42 -0
- package/src/components/ui/tooltip/TooltipProvider.vue +11 -0
- package/src/components/ui/tooltip/index.ts +2 -0
- package/src/composables/delegated-props.ts +6 -0
- package/src/composables/emits-as-props.ts +17 -0
- package/src/composables/forward-props-emits.ts +11 -0
- package/src/directives/autofocus.ts +7 -0
- package/src/index.ts +159 -0
- package/src/options-provider.ts +19 -0
- package/src/utils/gradient.ts +158 -0
- package/src/utils/options.ts +40 -0
- package/src/utils/tailwind.ts +14 -0
- package/web-types.json +10560 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<CheckboxGroupRoot v-bind="forwarded" :class="checkboxGroupVariants({ orientation })">
|
|
3
|
+
<Checkbox
|
|
4
|
+
v-for="(option, index) in preparedOptions"
|
|
5
|
+
:key="option[keys.id] || option[keys.value] || index"
|
|
6
|
+
:value="option[keys.value]"
|
|
7
|
+
:disabled="disabled || option[keys.disabled]"
|
|
8
|
+
:help="option[keys.help]"
|
|
9
|
+
@blur="$emit('blur', option, $event)"
|
|
10
|
+
@focus="$emit('focus', option, $event)"
|
|
11
|
+
>
|
|
12
|
+
<slot v-bind="{ option }">
|
|
13
|
+
{{ option[keys.label] || option }}
|
|
14
|
+
</slot>
|
|
15
|
+
<template v-if="$slots.help" #help>
|
|
16
|
+
<slot v-bind="{ option }" name="help">
|
|
17
|
+
{{ option[keys.help] }}
|
|
18
|
+
</slot>
|
|
19
|
+
</template>
|
|
20
|
+
</Checkbox>
|
|
21
|
+
</CheckboxGroupRoot>
|
|
22
|
+
</template>
|
|
23
|
+
|
|
24
|
+
<script setup lang="ts">
|
|
25
|
+
import { computed, type Events } from 'vue'
|
|
26
|
+
import { prepareOptions } from '@/utils/options'
|
|
27
|
+
import type { Keys, Option, CustomOption } from '@/utils/options'
|
|
28
|
+
import { checkboxGroupVariants } from './'
|
|
29
|
+
import {
|
|
30
|
+
CheckboxGroupRoot,
|
|
31
|
+
type CheckboxGroupRootProps,
|
|
32
|
+
type CheckboxGroupRootEmits
|
|
33
|
+
} from 'reka-ui'
|
|
34
|
+
import Checkbox from '@/components/ui/checkbox/Checkbox.vue'
|
|
35
|
+
import { useForwardPropsEmits } from '@/composables/forward-props-emits'
|
|
36
|
+
import { useDelegatedProps } from '@/composables/delegated-props'
|
|
37
|
+
import { useEmitAsProps } from '@/composables/emits-as-props'
|
|
38
|
+
|
|
39
|
+
const props = withDefaults(defineProps<Omit<CheckboxGroupRootProps, 'as' | 'asChild'> & {
|
|
40
|
+
keys?: Keys
|
|
41
|
+
options: string[] | Option[] | CustomOption[] | { [key:string]: string }
|
|
42
|
+
}>(), {
|
|
43
|
+
loop: false,
|
|
44
|
+
dir: 'ltr',
|
|
45
|
+
orientation: 'vertical',
|
|
46
|
+
keys: () => ({
|
|
47
|
+
id: 'id',
|
|
48
|
+
label: 'label',
|
|
49
|
+
help: 'help',
|
|
50
|
+
value: 'value',
|
|
51
|
+
disabled: 'disabled'
|
|
52
|
+
})
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
const emits = defineEmits<CheckboxGroupRootEmits & {
|
|
56
|
+
focus: [option: Option | CustomOption, event: Events['onFocus']]
|
|
57
|
+
blur: [option: Option | CustomOption, event: Events['onBlur']]
|
|
58
|
+
}>()
|
|
59
|
+
|
|
60
|
+
const delegatedProps = useDelegatedProps(props, ['keys', 'options'])
|
|
61
|
+
const delegatedEmits = useEmitAsProps(emits, ['focus', 'blur'])
|
|
62
|
+
const forwarded = useForwardPropsEmits(delegatedProps, delegatedEmits)
|
|
63
|
+
|
|
64
|
+
const preparedOptions = computed(() => prepareOptions(props.options, props.keys))
|
|
65
|
+
</script>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { cva } from 'class-variance-authority'
|
|
2
|
+
|
|
3
|
+
export { default as CheckboxGroup } from './CheckboxGroup.vue'
|
|
4
|
+
|
|
5
|
+
export const checkboxGroupVariants = cva('flex ', {
|
|
6
|
+
variants: {
|
|
7
|
+
orientation: {
|
|
8
|
+
vertical: 'flex-col gap-2',
|
|
9
|
+
horizontal: 'gap-4'
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
defaultVariants: {
|
|
13
|
+
orientation: 'vertical'
|
|
14
|
+
}
|
|
15
|
+
})
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Rail
|
|
3
|
+
:orientation="orientation"
|
|
4
|
+
:background="background"
|
|
5
|
+
@drag="update"
|
|
6
|
+
@drag-start="update"
|
|
7
|
+
>
|
|
8
|
+
<Handle
|
|
9
|
+
:style="{ [orientation === 'horizontal' ? 'left' : 'top']: modelValue * 100 + '%' }"
|
|
10
|
+
:class="orientation === 'horizontal' ? 'h-full w-2 -translate-x-1/2' : 'w-full h-2 -translate-y-1/2'"
|
|
11
|
+
@up="increment"
|
|
12
|
+
@down="decrement"
|
|
13
|
+
/>
|
|
14
|
+
</Rail>
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<script setup lang="ts">
|
|
18
|
+
import { computed } from 'vue'
|
|
19
|
+
import Rail from './Rail.vue'
|
|
20
|
+
import Handle from './Handle.vue'
|
|
21
|
+
import type { Numberify } from '@ctrl/tinycolor'
|
|
22
|
+
|
|
23
|
+
interface RGB {
|
|
24
|
+
r: string
|
|
25
|
+
g: string
|
|
26
|
+
b: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const modelValue = defineModel<number>({ required: true })
|
|
30
|
+
const props = withDefaults(defineProps<{
|
|
31
|
+
rgb: Numberify<RGB>
|
|
32
|
+
orientation?: 'horizontal' | 'vertical'
|
|
33
|
+
}>(), {
|
|
34
|
+
orientation: 'horizontal'
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
const background = computed(() => {
|
|
38
|
+
const { rgb, orientation } = props
|
|
39
|
+
const rgbStr = [rgb.r, rgb.g, rgb.b].join(', ')
|
|
40
|
+
return orientation === 'horizontal'
|
|
41
|
+
? `linear-gradient(to right, rgba(${rgbStr}, 0) 0%, rgba(${rgbStr}, 1) 100%)`
|
|
42
|
+
: `linear-gradient(to bottom, rgba(${rgbStr}, 0) 0%, rgba(${rgbStr}, 1) 100%)`
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const update = (left: number) => {
|
|
46
|
+
const alpha = left / 100
|
|
47
|
+
if (alpha !== modelValue.value) {
|
|
48
|
+
modelValue.value = alpha
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const increment = () => {
|
|
53
|
+
let i = 0.1
|
|
54
|
+
const value = modelValue.value + i
|
|
55
|
+
modelValue.value = value <= 1 ? value : 1
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const decrement = () => {
|
|
59
|
+
let i = 0.1
|
|
60
|
+
const value = modelValue.value - i
|
|
61
|
+
modelValue.value = value >= 0 ? value : 0
|
|
62
|
+
}
|
|
63
|
+
</script>
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
ref="container"
|
|
4
|
+
class="relative select-none rounded-full w-8 h-8 cursor-pointer border dark:border-gray-700 border-gray-200 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
|
5
|
+
tabindex="0"
|
|
6
|
+
@focus="beginKeyboardInput"
|
|
7
|
+
@blur="endKeyboardInput"
|
|
8
|
+
@mousedown="beginTracking"
|
|
9
|
+
@touchmove.prevent.passive="onMouseMove"
|
|
10
|
+
@touchstart.prevent.passive="onMouseMove"
|
|
11
|
+
>
|
|
12
|
+
<span
|
|
13
|
+
class="absolute bottom-0 top-0 h-full left-1/2 before:content[''] before:absolute before:top-[6px] before:rounded-full before:bg-primary before:-translate-x-1/2 before:w-[6px] before:h-[6px]"
|
|
14
|
+
:style="{ transform: `rotate(${modelValue}deg)` }"
|
|
15
|
+
/>
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
18
|
+
|
|
19
|
+
<script setup lang="ts">
|
|
20
|
+
import { ref, onUnmounted } from 'vue'
|
|
21
|
+
|
|
22
|
+
const props = withDefaults(defineProps<{
|
|
23
|
+
modelValue: number
|
|
24
|
+
max?: number
|
|
25
|
+
min?: number
|
|
26
|
+
step?: number
|
|
27
|
+
}>(), {
|
|
28
|
+
max: 360,
|
|
29
|
+
min: 0,
|
|
30
|
+
step: 1
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const emit = defineEmits<{
|
|
34
|
+
'update:model-value': [value: number]
|
|
35
|
+
change: [value: number]
|
|
36
|
+
}>()
|
|
37
|
+
|
|
38
|
+
const container = ref<HTMLElement | null>(null)
|
|
39
|
+
const tracking = ref(false)
|
|
40
|
+
|
|
41
|
+
const radToDeg = (rad: number): number => {
|
|
42
|
+
return rad * (180 / Math.PI)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const getCenter = (element: HTMLElement): [number, number] => {
|
|
46
|
+
const rect = element.getBoundingClientRect()
|
|
47
|
+
return [rect.left + (rect.width / 2), rect.top + (rect.height / 2)]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const angle = (vector: [number, number], element: HTMLElement): number => {
|
|
51
|
+
const center = getCenter(element)
|
|
52
|
+
const x = vector[0] - center[0]
|
|
53
|
+
const y = vector[1] - center[1]
|
|
54
|
+
let deg = -radToDeg(Math.atan2(x, y))
|
|
55
|
+
deg += 180
|
|
56
|
+
if (deg < 0) deg += 360
|
|
57
|
+
return deg
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const normalize = (degree: number): number => {
|
|
61
|
+
const n = Math.max(props.min, Math.min(degree, props.max))
|
|
62
|
+
const high = Math.ceil(n / props.step)
|
|
63
|
+
const low = Math.round(n / props.step)
|
|
64
|
+
return high >= n / props.step ? (high * props.step === 360 ? 0 : high * props.step) : low * props.step
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Event handlers
|
|
68
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
69
|
+
const LEFT_ARROW = 37
|
|
70
|
+
const UP_ARROW = 38
|
|
71
|
+
const RIGHT_ARROW = 39
|
|
72
|
+
const DOWN_ARROW = 40
|
|
73
|
+
|
|
74
|
+
let dir = 0
|
|
75
|
+
switch (e.keyCode) {
|
|
76
|
+
case UP_ARROW:
|
|
77
|
+
case RIGHT_ARROW:
|
|
78
|
+
dir = 1
|
|
79
|
+
break
|
|
80
|
+
case DOWN_ARROW:
|
|
81
|
+
case LEFT_ARROW:
|
|
82
|
+
dir = -1
|
|
83
|
+
break
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let val = props.modelValue + (dir * props.step)
|
|
87
|
+
if (val === props.max + 1) val = props.min
|
|
88
|
+
if (val === props.min - 1) val = props.max - 1
|
|
89
|
+
val = normalize(val)
|
|
90
|
+
|
|
91
|
+
if (dir) {
|
|
92
|
+
e.preventDefault()
|
|
93
|
+
emit('update:model-value', val)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const updateWithEvent = (e: MouseEvent | TouchEvent) => {
|
|
98
|
+
if (!container.value) return
|
|
99
|
+
|
|
100
|
+
const vector: [number, number] = [
|
|
101
|
+
'touches' in e ? e.touches[0].clientX : (e as MouseEvent).x,
|
|
102
|
+
'touches' in e ? e.touches[0].clientY : (e as MouseEvent).y
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
const deg = angle(vector, container.value)
|
|
106
|
+
const value = normalize(deg)
|
|
107
|
+
emit('update:model-value', value)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const onMouseMove = (e: MouseEvent | TouchEvent) => {
|
|
111
|
+
updateWithEvent(e)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const onMouseUp = (e: MouseEvent | TouchEvent) => {
|
|
115
|
+
updateWithEvent(e)
|
|
116
|
+
endTracking()
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const beginTracking = () => {
|
|
120
|
+
document.addEventListener('mousemove', onMouseMove)
|
|
121
|
+
document.addEventListener('mouseup', onMouseUp)
|
|
122
|
+
tracking.value = true
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const endTracking = () => {
|
|
126
|
+
document.removeEventListener('mousemove', onMouseMove)
|
|
127
|
+
document.removeEventListener('mouseup', onMouseUp)
|
|
128
|
+
tracking.value = false
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const beginKeyboardInput = () => {
|
|
132
|
+
document.addEventListener('keydown', onKeyDown)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const endKeyboardInput = () => {
|
|
136
|
+
document.removeEventListener('keydown', onKeyDown)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
onUnmounted(() => {
|
|
140
|
+
if (tracking.value) {
|
|
141
|
+
endTracking()
|
|
142
|
+
}
|
|
143
|
+
endKeyboardInput()
|
|
144
|
+
})
|
|
145
|
+
</script>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :style="{ backgroundImage: background }" />
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script setup lang="ts">
|
|
6
|
+
import { computed } from 'vue'
|
|
7
|
+
|
|
8
|
+
const props = withDefaults(defineProps<{
|
|
9
|
+
size?: number
|
|
10
|
+
white?: string
|
|
11
|
+
black?: string
|
|
12
|
+
}>(), {
|
|
13
|
+
size: 8,
|
|
14
|
+
white: '#ffffff',
|
|
15
|
+
black: '#e6e6e6'
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const background = computed(() => `url(${getCheckboard(props.white, props.black, props.size)})`)
|
|
19
|
+
|
|
20
|
+
const renderCheckboard = (c1: string, c2: string, size: number) => {
|
|
21
|
+
if (typeof document === 'undefined') return ''
|
|
22
|
+
|
|
23
|
+
const canvas = document.createElement('canvas')
|
|
24
|
+
canvas.width = canvas.height = size * 2
|
|
25
|
+
const ctx = canvas.getContext('2d')
|
|
26
|
+
if (!ctx) {
|
|
27
|
+
return null
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
ctx.fillStyle = c1
|
|
31
|
+
ctx.fillRect(0, 0, canvas.width, canvas.height)
|
|
32
|
+
ctx.fillStyle = c2
|
|
33
|
+
ctx.fillRect(0, 0, size, size)
|
|
34
|
+
ctx.translate(size, size)
|
|
35
|
+
ctx.fillRect(0, 0, size, size)
|
|
36
|
+
|
|
37
|
+
return canvas.toDataURL()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const getCheckboard = (c1: string, c2: string, size: number) => {
|
|
41
|
+
return renderCheckboard(c1, c2, size)
|
|
42
|
+
}
|
|
43
|
+
</script>
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="flex flex-col gap-4">
|
|
3
|
+
<div
|
|
4
|
+
class="flex gap-4"
|
|
5
|
+
:class="[
|
|
6
|
+
orientation === 'horizontal' && 'flex-col',
|
|
7
|
+
orientation === 'vertical' && 'flex-row'
|
|
8
|
+
]"
|
|
9
|
+
>
|
|
10
|
+
<Saturation
|
|
11
|
+
:saturation="s"
|
|
12
|
+
:value="v"
|
|
13
|
+
:hue="hue"
|
|
14
|
+
class="h-40"
|
|
15
|
+
@update:value="setHsv({ v: $event })"
|
|
16
|
+
@update:saturation="setHsv({ s: $event })"
|
|
17
|
+
@update="setHsv($event)"
|
|
18
|
+
/>
|
|
19
|
+
<Hue v-model="hue" :orientation="orientation" />
|
|
20
|
+
<Alpha
|
|
21
|
+
v-model="alpha"
|
|
22
|
+
:orientation="orientation"
|
|
23
|
+
:rgb="color.toRgb()"
|
|
24
|
+
/>
|
|
25
|
+
</div>
|
|
26
|
+
<div class="flex justify-between gap-1 md:gap-2">
|
|
27
|
+
<Input
|
|
28
|
+
v-if="mode === 'hex'"
|
|
29
|
+
v-model="hex"
|
|
30
|
+
class="w-28 [&>input]:uppercase"
|
|
31
|
+
icon="hash"
|
|
32
|
+
@paste.prevent="onPasteHex"
|
|
33
|
+
/>
|
|
34
|
+
<div v-else-if="mode === 'rgba'" class="flex gap-1 md:gap-2">
|
|
35
|
+
<LabelInput v-slot="{ id }" label="R">
|
|
36
|
+
<Input
|
|
37
|
+
:id="id"
|
|
38
|
+
:model-value="Math.round(color.r)"
|
|
39
|
+
class="w-12 *:text-center"
|
|
40
|
+
@update:model-value="setRgb(Number($event) || color.r, 'r')"
|
|
41
|
+
/>
|
|
42
|
+
</LabelInput>
|
|
43
|
+
<LabelInput v-slot="{ id }" label="G">
|
|
44
|
+
<Input
|
|
45
|
+
:id="id"
|
|
46
|
+
:model-value="Math.round(color.g)"
|
|
47
|
+
class="w-12 [&>input]:text-center"
|
|
48
|
+
@update:model-value="setRgb(Number($event) || color.g, 'g')"
|
|
49
|
+
/>
|
|
50
|
+
</LabelInput>
|
|
51
|
+
<LabelInput v-slot="{ id }" label="B">
|
|
52
|
+
<Input
|
|
53
|
+
:id="id"
|
|
54
|
+
:model-value="Math.round(color.b)"
|
|
55
|
+
class="w-12 [&>input]:text-center"
|
|
56
|
+
@update:model-value="setRgb(Number($event) || color.b, 'b')"
|
|
57
|
+
/>
|
|
58
|
+
</LabelInput>
|
|
59
|
+
<LabelInput v-slot="{ id }" label="A">
|
|
60
|
+
<Input
|
|
61
|
+
:id="id"
|
|
62
|
+
v-model.number="alpha"
|
|
63
|
+
class="w-12 [&>input]:text-center"
|
|
64
|
+
/>
|
|
65
|
+
</LabelInput>
|
|
66
|
+
</div>
|
|
67
|
+
<div v-else-if="mode === 'hsla'" class="flex gap-1 md:gap-2">
|
|
68
|
+
<LabelInput v-slot="{ id }" label="H">
|
|
69
|
+
<Input
|
|
70
|
+
:id="id"
|
|
71
|
+
:model-value="Math.round(h)"
|
|
72
|
+
class="w-12 *:text-center"
|
|
73
|
+
@update:model-value="setHsl(Number($event) || color.toHsl().h, 'h')"
|
|
74
|
+
/>
|
|
75
|
+
</LabelInput>
|
|
76
|
+
<LabelInput v-slot="{ id }" label="S">
|
|
77
|
+
<Input
|
|
78
|
+
:id="id"
|
|
79
|
+
:model-value="Math.round(s * 100)"
|
|
80
|
+
class="w-12 [&>input]:text-center"
|
|
81
|
+
@update:model-value="setHsl(Number($event) || color.toHsl().s / 100, 's')"
|
|
82
|
+
/>
|
|
83
|
+
</LabelInput>
|
|
84
|
+
<LabelInput v-slot="{ id }" label="L">
|
|
85
|
+
<Input
|
|
86
|
+
:id="id"
|
|
87
|
+
:model-value="Math.round(color.toHsl().l * 100)"
|
|
88
|
+
class="w-12 [&>input]:text-center"
|
|
89
|
+
@update:model-value="setHsl(Number($event) || color.toHsl().l / 100, 'l')"
|
|
90
|
+
/>
|
|
91
|
+
</LabelInput>
|
|
92
|
+
<LabelInput v-slot="{ id }" label="A">
|
|
93
|
+
<Input
|
|
94
|
+
:id="id"
|
|
95
|
+
v-model.number="alpha"
|
|
96
|
+
class="w-12 [&>input]:text-center"
|
|
97
|
+
/>
|
|
98
|
+
</LabelInput>
|
|
99
|
+
</div>
|
|
100
|
+
<Button
|
|
101
|
+
variant="ghost"
|
|
102
|
+
@click="toggleMode"
|
|
103
|
+
>
|
|
104
|
+
<template #icon>
|
|
105
|
+
<ChevronsUpDown class="w-4 h-4" />
|
|
106
|
+
</template>
|
|
107
|
+
</Button>
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
</template>
|
|
111
|
+
|
|
112
|
+
<script setup lang="ts">
|
|
113
|
+
import { TinyColor } from '@ctrl/tinycolor'
|
|
114
|
+
import { computed, ref, watch } from 'vue'
|
|
115
|
+
import Saturation from './Saturation.vue'
|
|
116
|
+
import Hue from './Hue.vue'
|
|
117
|
+
import Alpha from './Alpha.vue'
|
|
118
|
+
import LabelInput from './LabelInput.vue'
|
|
119
|
+
import { Input } from '@/components/ui/input'
|
|
120
|
+
import { Button } from '@/components/ui/button'
|
|
121
|
+
import { ChevronsUpDown } from 'lucide-vue-next'
|
|
122
|
+
|
|
123
|
+
const modelValue = defineModel<string>({
|
|
124
|
+
default: 'transparent'
|
|
125
|
+
})
|
|
126
|
+
withDefaults(defineProps<{
|
|
127
|
+
orientation?: 'horizontal' | 'vertical'
|
|
128
|
+
}>(), {
|
|
129
|
+
orientation: 'horizontal'
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
type Mode = 'hex' | 'rgba' | 'hsla'
|
|
133
|
+
|
|
134
|
+
const mode = ref<Mode>('hex')
|
|
135
|
+
const modes: Mode[] = ['hex', 'rgba', 'hsla']
|
|
136
|
+
|
|
137
|
+
const toggleMode = () => {
|
|
138
|
+
const idx = modes.indexOf(mode.value)
|
|
139
|
+
mode.value = modes[idx + 1 > modes.length - 1 ? 0 : idx + 1]
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const onPasteHex = (e: ClipboardEvent) => {
|
|
143
|
+
const value = e.clipboardData!.getData('text')
|
|
144
|
+
hex.value = value.startsWith('#') ? value.slice(1) : value
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const c = new TinyColor(modelValue.value || 'transparent')
|
|
148
|
+
const rgb = c.toRgb()
|
|
149
|
+
|
|
150
|
+
const r = ref(rgb.r)
|
|
151
|
+
const g = ref(rgb.g)
|
|
152
|
+
const b = ref(rgb.b)
|
|
153
|
+
|
|
154
|
+
const hsv = c.toHsv()
|
|
155
|
+
const h = ref(hsv.h)
|
|
156
|
+
const s = ref(hsv.s)
|
|
157
|
+
const v = ref(hsv.v)
|
|
158
|
+
|
|
159
|
+
const a = ref(rgb.a)
|
|
160
|
+
|
|
161
|
+
const color = computed(() => new TinyColor({ h: h.value, s: s.value, v: v.value, a: 1 }))
|
|
162
|
+
|
|
163
|
+
const hex = computed({
|
|
164
|
+
get () {
|
|
165
|
+
return color.value.toHex()
|
|
166
|
+
},
|
|
167
|
+
set (value) {
|
|
168
|
+
const c = new TinyColor('#' + value)
|
|
169
|
+
if (c.isValid && value.length === 6) {
|
|
170
|
+
update(c)
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
const alpha = computed({
|
|
176
|
+
get () {
|
|
177
|
+
return a.value
|
|
178
|
+
},
|
|
179
|
+
set (value) {
|
|
180
|
+
a.value = value
|
|
181
|
+
update(new TinyColor(color.value))
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
const hue = computed({
|
|
186
|
+
get () {
|
|
187
|
+
return h.value
|
|
188
|
+
},
|
|
189
|
+
set (value) {
|
|
190
|
+
h.value = value
|
|
191
|
+
const hsl = color.value.toHsl()
|
|
192
|
+
hsl.h = value
|
|
193
|
+
update(new TinyColor(hsl))
|
|
194
|
+
}
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
watch(modelValue, (to) => {
|
|
199
|
+
const c = new TinyColor(to)
|
|
200
|
+
|
|
201
|
+
const rgb = c.clone().toRgb()
|
|
202
|
+
r.value = rgb.r
|
|
203
|
+
g.value = rgb.g
|
|
204
|
+
b.value = rgb.b
|
|
205
|
+
|
|
206
|
+
const hsv = c.clone().toHsv()
|
|
207
|
+
h.value = hsv.h === 0 ? h.value : hsv.h
|
|
208
|
+
s.value = hsv.s
|
|
209
|
+
v.value = hsv.v
|
|
210
|
+
|
|
211
|
+
a.value = rgb.a
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
const setRgb = (value: number, key: 'r' | 'g' | 'b') => {
|
|
215
|
+
const rgb = color.value.toRgb()
|
|
216
|
+
rgb[key] = value
|
|
217
|
+
update(new TinyColor(rgb))
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const setHsv = (value: { v?: number, s?: number, h?: number }) => {
|
|
221
|
+
const hsv = color.value.toHsv()
|
|
222
|
+
Object.assign(hsv, value)
|
|
223
|
+
update(new TinyColor(hsv))
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const setHsl = (value: number, key: 'h' | 's' | 'l') => {
|
|
227
|
+
const hsl = color.value.toHsl()
|
|
228
|
+
hsl[key] = value
|
|
229
|
+
update(new TinyColor(hsl))
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const isSafeHex = (color: TinyColor) => {
|
|
233
|
+
const from = new TinyColor(color.clone().toHexString()).toHsl()
|
|
234
|
+
const to = color.toHsl()
|
|
235
|
+
return to.h === from.h && to.s === from.s && to.l === from.l
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const isSafeRgba = (color: TinyColor) => {
|
|
239
|
+
const from = new TinyColor(color.clone().toRgbString()).toHsl()
|
|
240
|
+
const to = color.toHsl()
|
|
241
|
+
return to.h === from.h && to.s === from.s && to.l === from.l
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const update = (value: TinyColor) => {
|
|
245
|
+
value.setAlpha(a.value)
|
|
246
|
+
|
|
247
|
+
if (isSafeHex(value) && a.value === 1) {
|
|
248
|
+
modelValue.value = value.toHexString()
|
|
249
|
+
} else if (isSafeRgba(value)) {
|
|
250
|
+
modelValue.value = value.toRgbString()
|
|
251
|
+
} else {
|
|
252
|
+
modelValue.value = value.toHslString()
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
</script>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Popover>
|
|
3
|
+
<template #trigger>
|
|
4
|
+
<Button variant="ghost">
|
|
5
|
+
<template #icon>
|
|
6
|
+
<span class="relative size-4">
|
|
7
|
+
<Checkboard :size="4" class="absolute size-4 rounded-full inset-0" />
|
|
8
|
+
<span class="size-4 rounded-full absolute inset-0 shadow-[0_0_1px_1px_rgba(0,0,0,0.05)]" :style="{ backgroundColor: modelValue }" />
|
|
9
|
+
</span>
|
|
10
|
+
</template>
|
|
11
|
+
</Button>
|
|
12
|
+
</template>
|
|
13
|
+
|
|
14
|
+
<Color v-model="modelValue" />
|
|
15
|
+
</Popover>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<script setup lang="ts">
|
|
19
|
+
import { Button } from '@/components/ui/button'
|
|
20
|
+
import { Popover } from '@/components/ui/popover'
|
|
21
|
+
import Color from './Color.vue'
|
|
22
|
+
import Checkboard from './Checkboard.vue'
|
|
23
|
+
|
|
24
|
+
const modelValue = defineModel<string>()
|
|
25
|
+
</script>
|