@teammodlr/ui-kit 1.0.7 → 2.0.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/lib/__storybook__/argTypes.d.ts +10 -1
- package/lib/components/avatar/Avatar.vue.d.ts +16 -30
- package/lib/components/avatar/style/Avatar.css.d.ts +9 -0
- package/lib/components/avatar/style/index.d.ts +1 -0
- package/lib/components/avatargroup/AvatarGroup.vue.d.ts +28 -13
- package/lib/components/avatargroup/style/AvatarGroup.css.d.ts +2 -0
- package/lib/components/avatargroup/style/index.d.ts +1 -0
- package/lib/components/avatargroup/symbol.d.ts +13 -0
- package/lib/components/badge/Badge.vue.d.ts +30 -0
- package/lib/components/badge/style/Badge.css.d.ts +4 -0
- package/lib/components/badge/style/index.d.ts +1 -0
- package/lib/components/breadcrumb/Breadcrumb.vue.d.ts +12 -3
- package/lib/components/{breadcrumbitem → breadcrumb}/BreadcrumbItem.vue.d.ts +11 -0
- package/lib/components/breadcrumb/style/Breadcrumb.css.d.ts +4 -0
- package/lib/components/breadcrumb/style/index.d.ts +1 -0
- package/lib/components/breadcrumb/symbol.d.ts +13 -0
- package/lib/components/button/Button.vue.d.ts +39 -28
- package/lib/components/button/style/Button.css.d.ts +24 -0
- package/lib/components/button/style/index.d.ts +1 -0
- package/lib/components/buttongroup/ButtonGroup.vue.d.ts +2 -13
- package/lib/components/buttongroup/style/ButtonGroup.css.d.ts +2 -0
- package/lib/components/buttongroup/style/index.d.ts +1 -0
- package/lib/components/buttongroup/symbol.d.ts +6 -0
- package/lib/components/checkbox/Checkbox.vue.d.ts +17 -20
- package/lib/components/checkbox/style/Checkbox.css.d.ts +16 -0
- package/lib/components/checkbox/style/index.d.ts +1 -0
- package/lib/components/colorpicker/ColorPicker.vue.d.ts +75 -0
- package/lib/components/colorpicker/style/ColorPicker.css.d.ts +9 -0
- package/lib/components/colorpicker/style/index.d.ts +1 -0
- package/lib/components/colorpicker/utils.d.ts +16 -0
- package/lib/components/dropdown/Dropdown.vue.d.ts +5 -4
- package/lib/components/dropdown/DropdownItem.vue.d.ts +12 -5
- package/lib/components/dropdown/DropdownList.vue.d.ts +4 -1
- package/lib/components/dropdown/style/Dropdown.css.d.ts +5 -0
- package/lib/components/dropdown/style/index.d.ts +1 -0
- package/lib/components/dropdown/symbol.d.ts +6 -0
- package/lib/components/index.d.ts +10 -1
- package/lib/components/input/Input.vue.d.ts +35 -19
- package/lib/components/input/style/Input.css.d.ts +23 -0
- package/lib/components/input/style/index.d.ts +1 -0
- package/lib/components/link/Link.vue.d.ts +2 -2
- package/lib/components/messageprovider/Message.vue.d.ts +13 -1
- package/lib/components/messageprovider/MessageProvider.vue.d.ts +6 -5
- package/lib/components/messageprovider/style/Message.css.d.ts +12 -0
- package/lib/components/messageprovider/style/index.d.ts +1 -0
- package/lib/components/messageprovider/types.d.ts +2 -1
- package/lib/components/modal/Modal.vue.d.ts +52 -0
- package/lib/components/modal/style/Modal.css.d.ts +21 -0
- package/lib/components/modal/style/index.d.ts +1 -0
- package/lib/components/radio/Radio.vue.d.ts +85 -0
- package/lib/components/radio/style/Checkbox.css.d.ts +16 -0
- package/lib/components/radio/style/index.d.ts +1 -0
- package/lib/components/radiobutton/RadioButton.vue.d.ts +98 -0
- package/lib/components/radiobutton/style/RadioButton.css.d.ts +14 -0
- package/lib/components/radiobutton/style/index.d.ts +1 -0
- package/lib/components/radiobuttongroup/RadioButtonGroup.vue.d.ts +48 -0
- package/lib/components/radiobuttongroup/style/RadioButtonGroup.css.d.ts +3 -0
- package/lib/components/radiobuttongroup/style/index.d.ts +1 -0
- package/lib/components/radiobuttongroup/symbol.d.ts +9 -0
- package/lib/components/select/Select.vue.d.ts +22 -13
- package/lib/components/select/style/Select.css.d.ts +30 -0
- package/lib/components/select/style/index.d.ts +1 -0
- package/lib/components/skeleton/Skeleton.vue.d.ts +15 -21
- package/lib/components/skeleton/style/Skeleton.css.d.ts +8 -0
- package/lib/components/skeleton/style/index.d.ts +2 -0
- package/lib/components/slider/Slider.vue.d.ts +32 -0
- package/lib/components/slider/style/Slider.css.d.ts +4 -0
- package/lib/components/slider/style/index.d.ts +1 -0
- package/lib/components/tab/TabGroup.vue.d.ts +1 -1
- package/lib/components/table/Table.vue.d.ts +1 -1
- package/lib/components/tag/Tag.vue.d.ts +44 -0
- package/lib/components/tag/style/Tag.css.d.ts +11 -0
- package/lib/components/tag/style/index.d.ts +1 -0
- package/lib/components/tooltip/Tooltip.vue.d.ts +17 -2
- package/lib/components/tooltip/style/Tooltip.css.d.ts +6 -0
- package/lib/components/tooltip/style/index.d.ts +1 -0
- package/lib/components/virtualscroll/VirtualScroll.vue.d.ts +46 -16
- package/lib/components/virtualscroll/style/VirtualScroll.css.d.ts +1 -0
- package/lib/components/virtualscroll/style/index.d.ts +1 -0
- package/lib/composables/useInput.d.ts +1 -1
- package/lib/composables/useInteractive.d.ts +15 -0
- package/lib/composables/useZIndex.d.ts +8 -0
- package/lib/index.cjs.js +8 -2
- package/lib/index.d.ts +0 -1
- package/lib/index.es.js +3688 -1692
- package/lib/style.css +1 -1
- package/lib/styles/theme.css.d.ts +147 -0
- package/lib/styles/typography.css.d.ts +22 -0
- package/lib/types/props.d.ts +1 -0
- package/package.json +33 -26
- package/src/__storybook__/argTypes.ts +19 -1
- package/src/components/avatar/Avatar.vue +33 -26
- package/src/components/avatar/examples/index.stories.ts +1 -1
- package/src/components/avatar/style/Avatar.css.ts +92 -0
- package/src/components/avatar/style/index.ts +1 -0
- package/src/components/avatargroup/AvatarGroup.vue +71 -32
- package/src/components/avatargroup/examples/basic.vue +33 -7
- package/src/components/avatargroup/examples/index.stories.ts +4 -8
- package/src/components/avatargroup/style/AvatarGroup.css.ts +21 -0
- package/src/components/avatargroup/style/index.ts +1 -0
- package/src/components/avatargroup/symbol.ts +17 -0
- package/src/components/badge/Badge.css +128 -0
- package/src/components/badge/Badge.vue +43 -0
- package/src/components/badge/examples/basic.vue +10 -0
- package/src/components/badge/examples/index.stories.ts +21 -0
- package/src/components/badge/examples/index.ts +1 -0
- package/src/components/badge/style/Badge.css.ts +124 -0
- package/src/components/badge/style/index.ts +1 -0
- package/src/components/breadcrumb/Breadcrumb.vue +22 -15
- package/src/components/breadcrumb/BreadcrumbItem.vue +73 -0
- package/src/components/breadcrumb/examples/basic.vue +5 -7
- package/src/components/breadcrumb/examples/index.stories.ts +2 -2
- package/src/components/breadcrumb/style/Breadcrumb.css.ts +40 -0
- package/src/components/breadcrumb/style/index.ts +1 -0
- package/src/components/breadcrumb/symbol.ts +17 -0
- package/src/components/button/Button.vue +194 -107
- package/src/components/button/examples/icon-left.vue +12 -0
- package/src/components/button/examples/icon.vue +6 -7
- package/src/components/button/examples/index.stories.ts +9 -7
- package/src/components/button/examples/index.ts +3 -2
- package/src/components/button/examples/variants-secondary.vue +8 -0
- package/src/components/button/examples/variants.vue +8 -0
- package/src/components/button/style/Button.css.ts +585 -0
- package/src/components/button/style/index.ts +1 -0
- package/src/components/buttongroup/ButtonGroup.vue +36 -47
- package/src/components/buttongroup/examples/basic.vue +2 -2
- package/src/components/buttongroup/examples/icon-group.vue +22 -0
- package/src/components/buttongroup/examples/index.stories.ts +4 -2
- package/src/components/buttongroup/examples/index.ts +1 -0
- package/src/components/buttongroup/style/ButtonGroup.css.ts +40 -0
- package/src/components/buttongroup/style/index.ts +1 -0
- package/src/components/buttongroup/symbol.ts +8 -0
- package/src/components/checkbox/Checkbox.vue +70 -54
- package/src/components/checkbox/examples/index.stories.ts +1 -1
- package/src/components/checkbox/style/Checkbox.css.ts +127 -0
- package/src/components/checkbox/style/index.ts +1 -0
- package/src/components/colorpicker/ColorPicker.vue +283 -0
- package/src/components/colorpicker/examples/basic.vue +3 -0
- package/src/components/colorpicker/examples/index.stories.ts +17 -0
- package/src/components/colorpicker/examples/index.ts +1 -0
- package/src/components/colorpicker/style/ColorPicker.css.ts +97 -0
- package/src/components/colorpicker/style/index.ts +1 -0
- package/src/components/colorpicker/utils.ts +188 -0
- package/src/components/dropdown/Dropdown.vue +45 -24
- package/src/components/dropdown/DropdownItem.vue +121 -118
- package/src/components/dropdown/DropdownList.vue +3 -3
- package/src/components/dropdown/DropdownWrapper.vue +2 -1
- package/src/components/dropdown/examples/custom.vue +13 -0
- package/src/components/dropdown/examples/index.stories.ts +4 -2
- package/src/components/dropdown/examples/index.ts +1 -0
- package/src/components/dropdown/style/Dropdown.css.ts +48 -0
- package/src/components/dropdown/style/index.ts +1 -0
- package/src/components/dropdown/symbol.ts +8 -0
- package/src/components/form/examples/basic.vue +4 -2
- package/src/components/form/examples/index.stories.ts +4 -2
- package/src/components/image/examples/index.stories.ts +1 -1
- package/src/components/index.ts +10 -2
- package/src/components/input/Input.vue +84 -42
- package/src/components/input/examples/basic.vue +2 -1
- package/src/components/input/examples/index.stories.ts +1 -1
- package/src/components/input/examples/prefix.vue +4 -2
- package/src/components/input/examples/suffix.vue +4 -2
- package/src/components/input/style/Input.css.ts +221 -0
- package/src/components/input/style/index.ts +1 -0
- package/src/components/link/examples/index.stories.ts +1 -1
- package/src/components/messageprovider/Message.vue +52 -5
- package/src/components/messageprovider/MessageProvider.css +0 -13
- package/src/components/messageprovider/MessageProvider.vue +18 -16
- package/src/components/messageprovider/examples/basic.vue +56 -5
- package/src/components/messageprovider/examples/index.stories.ts +0 -1
- package/src/components/messageprovider/examples/index.ts +1 -0
- package/src/components/messageprovider/examples/update.vue +34 -0
- package/src/components/messageprovider/examples/wrapper.vue +1 -1
- package/src/components/messageprovider/style/Message.css.ts +109 -0
- package/src/components/messageprovider/style/index.ts +1 -0
- package/src/components/messageprovider/types.ts +9 -1
- package/src/components/modal/Modal.vue +126 -0
- package/src/components/modal/examples/basic.vue +40 -0
- package/src/components/modal/examples/index.stories.ts +20 -0
- package/src/components/modal/examples/index.ts +2 -0
- package/src/components/modal/examples/modal-form.vue +99 -0
- package/src/components/modal/style/Modal.css.ts +257 -0
- package/src/components/modal/style/index.ts +1 -0
- package/src/components/radio/Checkbox.css +185 -0
- package/src/components/radio/Radio.vue +137 -0
- package/src/components/radio/examples/basic.vue +9 -0
- package/src/components/radio/examples/index.stories.ts +19 -0
- package/src/components/radio/examples/index.ts +2 -0
- package/src/components/radio/style/Checkbox.css.ts +132 -0
- package/src/components/radio/style/index.ts +1 -0
- package/src/components/radiobutton/RadioButton.vue +131 -0
- package/src/components/radiobutton/style/RadioButton.css.ts +185 -0
- package/src/components/radiobutton/style/index.ts +1 -0
- package/src/components/radiobuttongroup/RadioButtonGroup.vue +75 -0
- package/src/components/radiobuttongroup/examples/basic.vue +17 -0
- package/src/components/radiobuttongroup/examples/index.stories.ts +22 -0
- package/src/components/radiobuttongroup/examples/index.ts +2 -0
- package/src/components/radiobuttongroup/style/RadioButtonGroup.css.ts +37 -0
- package/src/components/radiobuttongroup/style/index.ts +1 -0
- package/src/components/radiobuttongroup/symbol.ts +11 -0
- package/src/components/select/Select.css +0 -226
- package/src/components/select/Select.vue +116 -48
- package/src/components/select/examples/index.stories.ts +1 -1
- package/src/components/select/examples/multiple.vue +1 -2
- package/src/components/select/style/Select.css.ts +254 -0
- package/src/components/select/style/index.ts +1 -0
- package/src/components/skeleton/Skeleton.vue +55 -47
- package/src/components/skeleton/examples/index.stories.ts +1 -8
- package/src/components/skeleton/style/Skeleton.css.ts +57 -0
- package/src/components/skeleton/style/index.ts +2 -0
- package/src/components/slider/Slider.vue +76 -0
- package/src/components/slider/style/Slider.css.ts +43 -0
- package/src/components/slider/style/index.ts +1 -0
- package/src/components/tab/examples/index.stories.ts +1 -1
- package/src/components/table/examples/index.stories.ts +1 -1
- package/src/components/tag/Tag.css +0 -0
- package/src/components/tag/Tag.vue +66 -0
- package/src/components/tag/examples/basic.vue +5 -0
- package/src/components/tag/examples/index.stories.ts +22 -0
- package/src/components/tag/examples/index.ts +1 -0
- package/src/components/tag/style/Tag.css.ts +79 -0
- package/src/components/tag/style/index.ts +1 -0
- package/src/components/tooltip/Tooltip.css +0 -6
- package/src/components/tooltip/Tooltip.vue +53 -22
- package/src/components/tooltip/examples/basic.vue +2 -5
- package/src/components/tooltip/examples/index.stories.ts +1 -1
- package/src/components/tooltip/style/Tooltip.css.ts +48 -0
- package/src/components/tooltip/style/index.ts +1 -0
- package/src/components/virtualscroll/VirtualScroll.vue +159 -53
- package/src/components/virtualscroll/examples/basic.vue +21 -27
- package/src/components/virtualscroll/examples/index.stories.ts +2 -18
- package/src/components/virtualscroll/style/VirtualScroll.css.ts +18 -0
- package/src/components/virtualscroll/style/index.ts +1 -0
- package/src/composables/useInput.ts +2 -2
- package/src/composables/useInteractive.ts +20 -0
- package/src/composables/usePopper.ts +1 -1
- package/src/composables/useZIndex.ts +31 -0
- package/src/css/components.css +4 -3
- package/src/css/normalize.css +0 -379
- package/src/css/variables.css +2 -2
- package/src/examples/cards/cards.stories.ts +9 -0
- package/src/examples/cards/sidebar.vue +263 -0
- package/src/index.ts +1 -1
- package/src/styles/theme.css.ts +149 -0
- package/src/styles/typography.css.ts +91 -0
- package/src/types/props.ts +2 -0
- package/lib/components/breadcrumbitem/index.d.ts +0 -1
- package/src/components/avatar/Avatar.css +0 -69
- package/src/components/breadcrumbitem/BreadcrumbItem.vue +0 -66
- package/src/components/breadcrumbitem/index.ts +0 -1
- package/src/components/button/examples/colors-secondary.vue +0 -8
- package/src/components/button/examples/colors.vue +0 -8
- package/src/components/dropdown/Dropdown.css +0 -68
- /package/src/components/button/{Button.css → Button-old.css} +0 -0
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div ref="wrapper">
|
|
3
|
+
<div ref="referenceRef"
|
|
4
|
+
@click="isOpen = !isOpen"
|
|
5
|
+
:class="style.reference"
|
|
6
|
+
>
|
|
7
|
+
<div :class="style.referenceColor"
|
|
8
|
+
:style="{ backgroundColor: `rgba(${finalColor.r}, ${finalColor.g}, ${finalColor.b}, ${finalColor.a})` }">
|
|
9
|
+
</div>
|
|
10
|
+
</div>
|
|
11
|
+
<Teleport to="body">
|
|
12
|
+
<div :class="style.container" v-if="isOpen" ref="popper" :style="{zIndex: zIndex}">
|
|
13
|
+
<div ref="picker" @mousedown="handleMouseDown" :class="style.colours"
|
|
14
|
+
:style="`background: rgb(${mainColor.r}, ${mainColor.g}, ${mainColor.b});` ">
|
|
15
|
+
<div :class="style.whiteGradient"></div>
|
|
16
|
+
<div :class="style.blackGradient"></div>
|
|
17
|
+
<div draggable="true" :class="style.sliderThumb" @mousedown="handleMouseDown"
|
|
18
|
+
:style="{ left: `${position.x * 100}%`, top: `${position.y * 100}%` }"></div>
|
|
19
|
+
</div>
|
|
20
|
+
|
|
21
|
+
<div :class="style.colorActions">
|
|
22
|
+
<div :class="style.preview">
|
|
23
|
+
<div
|
|
24
|
+
:style="`width: 100%; height: 100%; background-color: rgba(${finalColor.r}, ${finalColor.g}, ${finalColor.b}, ${finalColor.a});`">
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
<div style="width: 100%; display: flex; flex-direction: column; gap: 10px;">
|
|
28
|
+
<MSlider v-model="hueSlider"
|
|
29
|
+
background="linear-gradient(to right, #FF0000, #FFFF00, #00FF00, #00FFFF, #0000FF, #FF00FF, #FF0000)">
|
|
30
|
+
</MSlider>
|
|
31
|
+
|
|
32
|
+
<MSlider v-model="opacitySlider"
|
|
33
|
+
:background="`linear-gradient(to right, rgba(${finalColor.r}, ${finalColor.g}, ${finalColor.b}, 0), rgba(${finalColor.r}, ${finalColor.g}, ${finalColor.b}, 1))`">
|
|
34
|
+
</MSlider>
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
<div
|
|
39
|
+
:class="style.colorActions">
|
|
40
|
+
<template v-if="rgbOrHex">
|
|
41
|
+
<MInput @keyup.enter="updateFromRGB" @blur="updateFromRGB" block ref="rInputElement"
|
|
42
|
+
v-model="rInput"
|
|
43
|
+
name="r" placeholder="R"/>
|
|
44
|
+
<MInput @keyup.enter="updateFromRGB" @blur="updateFromRGB" block ref="gInputElement"
|
|
45
|
+
v-model="gInput"
|
|
46
|
+
name="g" placeholder="G"/>
|
|
47
|
+
<MInput @keyup.enter="updateFromRGB" @blur="updateFromRGB" block ref="bInputElement"
|
|
48
|
+
v-model="bInput"
|
|
49
|
+
name="b" placeholder="B"/>
|
|
50
|
+
<MInput @keyup.enter="updateFromRGB" @blur="updateFromRGB" block ref="aInputElement"
|
|
51
|
+
v-model="aInput"
|
|
52
|
+
name="a" placeholder="A"/>
|
|
53
|
+
</template>
|
|
54
|
+
<template v-else>
|
|
55
|
+
<MInput @keyup.enter="updateFromHex" @blur="updateFromHex" block
|
|
56
|
+
ref="hexInputElement"
|
|
57
|
+
v-model="hexInput" name="hex" placeholder="#00000000"/>
|
|
58
|
+
</template>
|
|
59
|
+
|
|
60
|
+
<MButton icon @click.prevent="rgbOrHex = !rgbOrHex">
|
|
61
|
+
<svg style="width: 18px; height: 18px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"
|
|
62
|
+
fill="currentColor" class="w-5 h-5">
|
|
63
|
+
<path fill-rule="evenodd"
|
|
64
|
+
d="M10 3a.75.75 0 01.55.24l3.25 3.5a.75.75 0 11-1.1 1.02L10 4.852 7.3 7.76a.75.75 0 01-1.1-1.02l3.25-3.5A.75.75 0 0110 3zm-3.76 9.2a.75.75 0 011.06.04l2.7 2.908 2.7-2.908a.75.75 0 111.1 1.02l-3.25 3.5a.75.75 0 01-1.1 0l-3.25-3.5a.75.75 0 01.04-1.06z"
|
|
65
|
+
clip-rule="evenodd"/>
|
|
66
|
+
</svg>
|
|
67
|
+
</MButton>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
</Teleport>
|
|
71
|
+
</div>
|
|
72
|
+
</template>
|
|
73
|
+
|
|
74
|
+
<script lang="ts">
|
|
75
|
+
import {onClickOutside, useMouseInElement, useMousePressed} from '@vueuse/core';
|
|
76
|
+
import {computed, defineComponent, onMounted, type PropType, reactive, ref, toRef, watch} from "vue";
|
|
77
|
+
import * as style from './style';
|
|
78
|
+
import {hexToRGB, type HSV, HSVToRGBA, HueToRGBA, RGBAToHex, RGBToHSV} from './utils';
|
|
79
|
+
import {usePopper} from "../../composables/usePopper";
|
|
80
|
+
import type {Placement} from "@popperjs/core";
|
|
81
|
+
import {useZIndex} from "../../composables/useZIndex";
|
|
82
|
+
import {MButton, MInput} from "../../components";
|
|
83
|
+
import MSlider from "../../components/slider/Slider.vue";
|
|
84
|
+
|
|
85
|
+
export default defineComponent({
|
|
86
|
+
name: "MColorPicker",
|
|
87
|
+
props: {
|
|
88
|
+
modelValue: {
|
|
89
|
+
type: String,
|
|
90
|
+
default: "#FF00FF"
|
|
91
|
+
},
|
|
92
|
+
transfer: {
|
|
93
|
+
type: Boolean,
|
|
94
|
+
default: false
|
|
95
|
+
},
|
|
96
|
+
placement: {
|
|
97
|
+
type: String as PropType<Placement>,
|
|
98
|
+
default: "bottom-start"
|
|
99
|
+
},
|
|
100
|
+
zIndex: {
|
|
101
|
+
type: Number
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
emits: ['update:modelValue'],
|
|
105
|
+
components: {
|
|
106
|
+
MSlider,
|
|
107
|
+
MInput,
|
|
108
|
+
MButton
|
|
109
|
+
},
|
|
110
|
+
setup(props, {emit}) {
|
|
111
|
+
const {nextZIndex} = useZIndex();
|
|
112
|
+
const isOpen = ref(false);
|
|
113
|
+
const rgbOrHex = ref<boolean>(false);
|
|
114
|
+
const hexInput = ref("");
|
|
115
|
+
const rInput = ref("");
|
|
116
|
+
const gInput = ref("");
|
|
117
|
+
const bInput = ref("");
|
|
118
|
+
const aInput = ref("");
|
|
119
|
+
|
|
120
|
+
const picker = ref<HTMLElement>();
|
|
121
|
+
const wrapper = ref<HTMLElement>();
|
|
122
|
+
const referenceRef = ref<HTMLElement>();
|
|
123
|
+
const transfer = toRef(props, 'transfer');
|
|
124
|
+
const placement = toRef(props, 'placement');
|
|
125
|
+
const hexInputElement = ref();
|
|
126
|
+
const hueSlider = ref(0);
|
|
127
|
+
const opacitySlider = ref(100);
|
|
128
|
+
const dragging = ref(false);
|
|
129
|
+
const position = reactive({
|
|
130
|
+
x: 0,
|
|
131
|
+
y: 0
|
|
132
|
+
});
|
|
133
|
+
const zIndex = ref(props.zIndex ?? nextZIndex());
|
|
134
|
+
|
|
135
|
+
const {elementX, elementY} = useMouseInElement(picker);
|
|
136
|
+
const {pressed} = useMousePressed();
|
|
137
|
+
const {popper, transferTo, updatePopper} = usePopper({
|
|
138
|
+
reference: referenceRef,
|
|
139
|
+
placement,
|
|
140
|
+
transfer,
|
|
141
|
+
wrapper,
|
|
142
|
+
isDrop: false,
|
|
143
|
+
offset: [-2, 2]
|
|
144
|
+
});
|
|
145
|
+
const brightness = computed(() => {
|
|
146
|
+
return 1 - position.y;
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
const saturation = computed(() => {
|
|
150
|
+
return position.x;
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
const finalColor = computed(() => {
|
|
154
|
+
return HSVToRGBA(hueSlider.value * 3.6, brightness.value, saturation.value, opacitySlider.value / 100);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const mainColor = computed(() => {
|
|
158
|
+
return HueToRGBA(hueSlider.value * 3.6, opacitySlider.value / 100);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const setInputs = () => {
|
|
162
|
+
hexInput.value = RGBAToHex(finalColor.value.r, finalColor.value.g, finalColor.value.b, finalColor.value.a);
|
|
163
|
+
rInput.value = finalColor.value.r.toString();
|
|
164
|
+
gInput.value = finalColor.value.g.toString();
|
|
165
|
+
bInput.value = finalColor.value.b.toString();
|
|
166
|
+
aInput.value = finalColor.value.a.toFixed(2).toString();
|
|
167
|
+
|
|
168
|
+
emit('update:modelValue', hexInput.value);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
watch(() => finalColor.value, () => {
|
|
172
|
+
setInputs();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
const updateFromHSV = (hsv: HSV, alpha: number) => {
|
|
176
|
+
position.x = hsv.s;
|
|
177
|
+
position.y = 1 - hsv.v;
|
|
178
|
+
hueSlider.value = ((1 / 360) * hsv.h) * 100;
|
|
179
|
+
opacitySlider.value = alpha * 100;
|
|
180
|
+
setInputs();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const updateFromHex = () => {
|
|
184
|
+
var color = hexToRGB(hexInput.value, finalColor.value.r, finalColor.value.g, finalColor.value.b, finalColor.value.a);
|
|
185
|
+
updateFromHSV(RGBToHSV(color.r, color.g, color.b), color.a);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const updateFromRGB = () => {
|
|
189
|
+
var red = parseInt(rInput.value);
|
|
190
|
+
if (isNaN(red) || red > 255 || red < 0) {
|
|
191
|
+
red = finalColor.value.r;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
var green = parseInt(gInput.value);
|
|
195
|
+
if (isNaN(green) || green > 255 || green < 0) {
|
|
196
|
+
green = finalColor.value.g;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
var blue = parseInt(bInput.value);
|
|
200
|
+
if (isNaN(blue) || blue > 255 || blue < 0) {
|
|
201
|
+
blue = finalColor.value.b;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
var alpha = parseFloat(aInput.value);
|
|
205
|
+
if (isNaN(alpha) || alpha > 1 || alpha < 0) {
|
|
206
|
+
alpha = finalColor.value.a;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
updateFromHSV(RGBToHSV(red, green, blue), alpha);
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
watch(() => pressed.value, () => {
|
|
213
|
+
if (!pressed.value) {
|
|
214
|
+
dragging.value = false;
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
watch(() => [elementX.value, elementY.value], () => {
|
|
219
|
+
if (!dragging.value) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
setThumbPosition();
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
watch(() => props.modelValue, () => {
|
|
227
|
+
hexInput.value = props.modelValue;
|
|
228
|
+
updateFromHex();
|
|
229
|
+
console.log('hi');
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const setThumbPosition = () => {
|
|
233
|
+
position.x = ((Math.min(Math.max(elementX.value, 0), picker.value?.clientWidth || 0) / (picker.value?.clientWidth || 0)));
|
|
234
|
+
position.y = ((Math.min(Math.max(elementY.value, 0), picker.value?.clientHeight || 0) / (picker.value?.clientHeight || 0)));
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const handleMouseDown = () => {
|
|
238
|
+
dragging.value = true;
|
|
239
|
+
setThumbPosition();
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
onMounted(() => {
|
|
243
|
+
hexInput.value = props.modelValue;
|
|
244
|
+
updateFromHex();
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
onClickOutside(popper, (e) => {
|
|
248
|
+
isOpen.value = false;
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
return {
|
|
252
|
+
isOpen,
|
|
253
|
+
popper,
|
|
254
|
+
transferTo,
|
|
255
|
+
wrapper,
|
|
256
|
+
referenceRef,
|
|
257
|
+
updateFromRGB,
|
|
258
|
+
updateFromHex,
|
|
259
|
+
setInputs,
|
|
260
|
+
rgbOrHex,
|
|
261
|
+
hexInputElement,
|
|
262
|
+
hexInput,
|
|
263
|
+
rInput,
|
|
264
|
+
gInput,
|
|
265
|
+
bInput,
|
|
266
|
+
aInput,
|
|
267
|
+
finalColor,
|
|
268
|
+
hueSlider,
|
|
269
|
+
opacitySlider,
|
|
270
|
+
dragging,
|
|
271
|
+
setThumbPosition,
|
|
272
|
+
position,
|
|
273
|
+
elementX,
|
|
274
|
+
pressed,
|
|
275
|
+
handleMouseDown,
|
|
276
|
+
picker,
|
|
277
|
+
style,
|
|
278
|
+
mainColor,
|
|
279
|
+
zIndex
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
})
|
|
283
|
+
</script>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import MColorPicker from "../ColorPicker.vue";
|
|
2
|
+
import {
|
|
3
|
+
MColorBasic,
|
|
4
|
+
} from "./index";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
createStory
|
|
8
|
+
} from "../../../__storybook__";
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
component: MColorPicker,
|
|
12
|
+
title: 'Components/Color Picker',
|
|
13
|
+
argTypes: {
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const Basic = createStory(MColorBasic);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as MColorBasic } from './basic.vue';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { createVar, globalKeyframes, globalStyle, style, styleVariants } from "@vanilla-extract/css";
|
|
2
|
+
import { themeVars } from "../../../styles/theme.css";
|
|
3
|
+
|
|
4
|
+
export const container = style({
|
|
5
|
+
display: "flex",
|
|
6
|
+
flexDirection: "column",
|
|
7
|
+
width: '280px',
|
|
8
|
+
alignItems: 'center',
|
|
9
|
+
gap: '10px',
|
|
10
|
+
userSelect: 'none',
|
|
11
|
+
zIndex: 100,
|
|
12
|
+
backgroundColor: '#FFF',
|
|
13
|
+
borderRadius: "5px",
|
|
14
|
+
padding: themeVars.space[3],
|
|
15
|
+
border: `1px solid ${themeVars.color.gray[200]}`,
|
|
16
|
+
boxShadow: themeVars.shadow.md
|
|
17
|
+
});
|
|
18
|
+
export const sliderThumb = style({
|
|
19
|
+
transform: 'translate(-50%, -50%)',
|
|
20
|
+
position: 'absolute',
|
|
21
|
+
width: '14px',
|
|
22
|
+
height: '14px',
|
|
23
|
+
borderRadius: '50%',
|
|
24
|
+
backgroundColor: 'transparent',
|
|
25
|
+
border: '2px solid white',
|
|
26
|
+
boxShadow: themeVars.shadow.sm,
|
|
27
|
+
cursor: 'crosshair',
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export const preview = style({
|
|
31
|
+
backgroundImage: 'linear-gradient(45deg, #bebebe 25%, transparent 25%), linear-gradient(-45deg, #bebebe 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #bebebe 75%), linear-gradient(-45deg, transparent 75%, #bebebe 75%)',
|
|
32
|
+
backgroundSize: '16px 16px',
|
|
33
|
+
backgroundPosition: '0 0, 0 8px, 8px -8px, -8px 0px',
|
|
34
|
+
overflow: 'hidden',
|
|
35
|
+
minWidth: '32px',
|
|
36
|
+
minHeight: '32px',
|
|
37
|
+
width: '32px',
|
|
38
|
+
height: '32px',
|
|
39
|
+
borderRadius: '100%',
|
|
40
|
+
border: `1px solid ${themeVars.color.gray[200]}`
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const colours = style({
|
|
44
|
+
position: 'relative',
|
|
45
|
+
height: '160px',
|
|
46
|
+
width: '100%',
|
|
47
|
+
cursor: 'crosshair'
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
export const reference = style({
|
|
51
|
+
backgroundImage: 'linear-gradient(45deg, #bebebe 25%, transparent 25%), linear-gradient(-45deg, #bebebe 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #bebebe 75%), linear-gradient(-45deg, transparent 75%, #bebebe 75%)',
|
|
52
|
+
backgroundSize: '16px 16px',
|
|
53
|
+
backgroundPosition: '0 0, 0 8px, 8px -8px, -8px 0px',
|
|
54
|
+
overflow: 'hidden',
|
|
55
|
+
minWidth: '28px',
|
|
56
|
+
minHeight: '28px',
|
|
57
|
+
width: '28px',
|
|
58
|
+
height: '28px',
|
|
59
|
+
borderRadius: '5px',
|
|
60
|
+
border: `1px solid ${themeVars.color.gray[200]}`,
|
|
61
|
+
position: "relative",
|
|
62
|
+
cursor: "pointer"
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
export const referenceColor = style({
|
|
66
|
+
position: 'absolute',
|
|
67
|
+
top: 0,
|
|
68
|
+
left: 0,
|
|
69
|
+
right: 0,
|
|
70
|
+
bottom: 0
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export const colorActions = style({
|
|
74
|
+
display: 'flex',
|
|
75
|
+
gap: themeVars.space[2],
|
|
76
|
+
width: '100%',
|
|
77
|
+
alignItems: 'center',
|
|
78
|
+
justifyContent: 'space-between'
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
export const whiteGradient = style({
|
|
82
|
+
position: 'absolute',
|
|
83
|
+
top: 0,
|
|
84
|
+
left: 0,
|
|
85
|
+
right: 0,
|
|
86
|
+
bottom: 0,
|
|
87
|
+
background: 'linear-gradient(90deg, #FFF, rgba(255, 255, 255, 0))'
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
export const blackGradient = style({
|
|
91
|
+
position: 'absolute',
|
|
92
|
+
top: 0,
|
|
93
|
+
left: 0,
|
|
94
|
+
right: 0,
|
|
95
|
+
bottom: 0,
|
|
96
|
+
background: 'linear-gradient(0deg, #000, transparent)'
|
|
97
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ColorPicker.css';
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
export interface Color {
|
|
2
|
+
r: number;
|
|
3
|
+
g: number;
|
|
4
|
+
b: number;
|
|
5
|
+
a: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface HSV {
|
|
9
|
+
h: number;
|
|
10
|
+
s: number;
|
|
11
|
+
v: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const RGBAToHex = (r: number, g: number, b: number, a: number): string => {
|
|
15
|
+
const hexR: string = r.toString(16).padStart(2, "0");
|
|
16
|
+
const hexG: string = g.toString(16).padStart(2, "0");
|
|
17
|
+
const hexB: string = b.toString(16).padStart(2, "0");
|
|
18
|
+
const hexA: string = Math.round(a * 255).toString(16).padStart(2, "0");
|
|
19
|
+
|
|
20
|
+
return `#${hexR}${hexG}${hexB}${a >= 1 ? '' : hexA}`;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const hexToRGB = (hexColor: string, defaultR: number = 0, defaultG: number = 0, defaultB: number = 0, defaultA: number = 0): Color => {
|
|
24
|
+
hexColor = hexColor.replace("#", "");
|
|
25
|
+
|
|
26
|
+
let r = defaultR;
|
|
27
|
+
let g = defaultG;
|
|
28
|
+
let b = defaultB;
|
|
29
|
+
let a = defaultA;
|
|
30
|
+
|
|
31
|
+
if (hexColor.length >= 2) {
|
|
32
|
+
r = parseInt(hexColor.substring(0, 2), 16);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (hexColor.length >= 4) {
|
|
36
|
+
g = parseInt(hexColor.substring(2, 4), 16);
|
|
37
|
+
} else {
|
|
38
|
+
g = 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (hexColor.length >= 6) {
|
|
42
|
+
b = parseInt(hexColor.substring(4, 6), 16);
|
|
43
|
+
} else {
|
|
44
|
+
b = 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (hexColor.length >= 8) {
|
|
48
|
+
a = parseInt(hexColor.substring(6, 8), 16) / 255;
|
|
49
|
+
} else {
|
|
50
|
+
a = 1;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (isNaN(r) || isNaN(g) || isNaN(b) || isNaN(a)) {
|
|
54
|
+
r = 0;
|
|
55
|
+
b = 0;
|
|
56
|
+
g = 0;
|
|
57
|
+
a = 1;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
r: r,
|
|
62
|
+
g: g,
|
|
63
|
+
b: b,
|
|
64
|
+
a: a
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const RGBToHSV = (r: number, g: number, b: number): HSV => {
|
|
69
|
+
var max = Math.max(r, g, b);
|
|
70
|
+
var min = Math.min(r, g, b);
|
|
71
|
+
|
|
72
|
+
var delta = max - min;
|
|
73
|
+
var brightness = max;
|
|
74
|
+
var saturation = 0;
|
|
75
|
+
if (max !== 0) {
|
|
76
|
+
saturation = delta / max;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
var hue = 0;
|
|
80
|
+
if (delta !== 0) {
|
|
81
|
+
if (max === r) {
|
|
82
|
+
hue = ((g - b) / delta) % 6;
|
|
83
|
+
} else if (max === g) {
|
|
84
|
+
hue = (b - r) / delta + 2;
|
|
85
|
+
} else {
|
|
86
|
+
hue = (r - g) / delta + 4;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
hue *= 60;
|
|
90
|
+
if (hue < 0) {
|
|
91
|
+
hue += 360;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
h: hue,
|
|
97
|
+
s: saturation,
|
|
98
|
+
v: brightness / 255
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const HSVToRGBA = (hue: number, brightness: number, saturation: number, alpha: number): Color => {
|
|
103
|
+
const hueInDegrees = hue;
|
|
104
|
+
const chroma = brightness * saturation;
|
|
105
|
+
const hue1 = hueInDegrees / 60;
|
|
106
|
+
const x = chroma * (1 - Math.abs(hue1 % 2 - 1));
|
|
107
|
+
let r1 = 0;
|
|
108
|
+
let g1 = 0;
|
|
109
|
+
let b1 = 0;
|
|
110
|
+
if (hue1 >= 0 && hue1 < 1) {
|
|
111
|
+
r1 = chroma;
|
|
112
|
+
g1 = x;
|
|
113
|
+
} else if (hue1 >= 1 && hue1 < 2) {
|
|
114
|
+
r1 = x;
|
|
115
|
+
g1 = chroma;
|
|
116
|
+
} else if (hue1 >= 2 && hue1 < 3) {
|
|
117
|
+
g1 = chroma;
|
|
118
|
+
b1 = x;
|
|
119
|
+
} else if (hue1 >= 3 && hue1 < 4) {
|
|
120
|
+
g1 = x;
|
|
121
|
+
b1 = chroma;
|
|
122
|
+
} else if (hue1 >= 4 && hue1 < 5) {
|
|
123
|
+
r1 = x;
|
|
124
|
+
b1 = chroma;
|
|
125
|
+
} else {
|
|
126
|
+
r1 = chroma;
|
|
127
|
+
b1 = x;
|
|
128
|
+
}
|
|
129
|
+
const m = brightness - chroma;
|
|
130
|
+
const r = Math.round((r1 + m) * 255);
|
|
131
|
+
const g = Math.round((g1 + m) * 255);
|
|
132
|
+
const b = Math.round((b1 + m) * 255);
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
r: r,
|
|
136
|
+
g: g,
|
|
137
|
+
b: b,
|
|
138
|
+
a: alpha
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export const HueToRGBA = (hue: number, alpha: number): Color => {
|
|
143
|
+
const chroma = (1 - Math.abs((2 * 0.5) - 1));
|
|
144
|
+
const huePrime = (hue / 360) * 6;
|
|
145
|
+
const intermediateValue = chroma * (1 - Math.abs((huePrime % 2) - 1));
|
|
146
|
+
let red = 0;
|
|
147
|
+
let green = 0;
|
|
148
|
+
let blue = 0;
|
|
149
|
+
|
|
150
|
+
if (huePrime >= 0 && huePrime < 1) {
|
|
151
|
+
red = chroma;
|
|
152
|
+
green = intermediateValue;
|
|
153
|
+
blue = 0;
|
|
154
|
+
} else if (huePrime >= 1 && huePrime < 2) {
|
|
155
|
+
red = intermediateValue;
|
|
156
|
+
green = chroma;
|
|
157
|
+
blue = 0;
|
|
158
|
+
} else if (huePrime >= 2 && huePrime < 3) {
|
|
159
|
+
red = 0;
|
|
160
|
+
green = chroma;
|
|
161
|
+
blue = intermediateValue;
|
|
162
|
+
} else if (huePrime >= 3 && huePrime < 4) {
|
|
163
|
+
red = 0;
|
|
164
|
+
green = intermediateValue;
|
|
165
|
+
blue = chroma;
|
|
166
|
+
} else if (huePrime >= 4 && huePrime < 5) {
|
|
167
|
+
red = intermediateValue;
|
|
168
|
+
green = 0;
|
|
169
|
+
blue = chroma;
|
|
170
|
+
} else {
|
|
171
|
+
red = chroma;
|
|
172
|
+
green = 0;
|
|
173
|
+
blue = intermediateValue;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const lightnessDecimal = 0.5;
|
|
177
|
+
const lightnessAdjustment = (1 - chroma) * (lightnessDecimal - 0.5);
|
|
178
|
+
const finalRed = Math.round((red + lightnessAdjustment) * 255);
|
|
179
|
+
const finalGreen = Math.round((green + lightnessAdjustment) * 255);
|
|
180
|
+
const finalBlue = Math.round((blue + lightnessAdjustment) * 255);
|
|
181
|
+
|
|
182
|
+
return {
|
|
183
|
+
r: finalRed,
|
|
184
|
+
g: finalGreen,
|
|
185
|
+
b: finalBlue,
|
|
186
|
+
a: alpha,
|
|
187
|
+
};
|
|
188
|
+
}
|