aloha-vue 2.85.0 → 2.87.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/CHANGELOG.md +1215 -1200
- package/README.md +117 -117
- package/dist/aloha-vue.css +13827 -13601
- package/dist/aloha-vue.css.map +1 -1
- package/dist/aloha-vue.es.js +60235 -57401
- package/dist/aloha-vue.umd.js +319 -319
- package/package.json +1 -1
- package/scss/components/AButton.scss +6 -6
- package/scss/components/ADivider.scss +9 -9
- package/scss/components/AElement.scss +6 -6
- package/scss/components/AGroupButtonDropdown.scss +4 -4
- package/scss/components/AIcon.scss +17 -17
- package/scss/components/ALoading.scss +18 -18
- package/scss/components/AMenu.scss +634 -634
- package/scss/components/AProgressCirle.scss +43 -43
- package/scss/components/AShowMore.scss +9 -9
- package/scss/components/ATableForm.scss +7 -7
- package/scss/components/ATabs.scss +186 -186
- package/scss/components/ui/AColorPicker.scss +243 -0
- package/scss/components/ui/AJson.scss +11 -11
- package/scss/components/ui/ui.scss +1 -0
- package/scss/text/text_line_height.scss +17 -17
- package/scss/text/text_size.scss +88 -88
- package/scss/utils/acordion.scss +173 -173
- package/scss/utils/alert.scss +81 -81
- package/scss/utils/aloha_prefix.scss +1 -1
- package/scss/utils/backdrop.scss +24 -24
- package/scss/utils/border.scss +65 -65
- package/scss/utils/breakpoint.scss +48 -48
- package/scss/utils/button_close.scss +22 -22
- package/scss/utils/button_group.scss +69 -69
- package/scss/utils/color_utils.scss +234 -234
- package/scss/utils/display.scss +67 -67
- package/scss/utils/flex.scss +141 -141
- package/scss/utils/float.scss +10 -10
- package/scss/utils/global.scss +44 -44
- package/scss/utils/global_variables.scss +26 -26
- package/scss/utils/grid.scss +95 -95
- package/scss/utils/list_columns.scss +31 -31
- package/scss/utils/list_group.scss +127 -127
- package/scss/utils/notification.scss +36 -36
- package/scss/utils/overflow.scss +40 -40
- package/scss/utils/pagination.scss +94 -94
- package/scss/utils/position.scss +90 -90
- package/scss/utils/progress.scss +70 -70
- package/scss/utils/screenreader.scss +16 -16
- package/scss/utils/spinner.scss +35 -35
- package/scss/utils/utils.scss +19 -19
- package/scss/utils/vars_global.scss +12 -12
- package/src/AAlert/i18n/AAlertI18n.js +4 -0
- package/src/AAlert/i18n/nl.json +3 -0
- package/src/AAlert/i18n/pl.json +3 -0
- package/src/ACarousel/i18n/ACarouselI18n.js +4 -0
- package/src/ACarousel/i18n/nl.json +9 -0
- package/src/ACarousel/i18n/pl.json +9 -0
- package/src/ACloak/i18n/ACloakI18n.js +4 -0
- package/src/ACloak/i18n/nl.json +3 -0
- package/src/ACloak/i18n/pl.json +3 -0
- package/src/ADisclosure/i18n/ADisclosureI18n.js +4 -0
- package/src/ADisclosure/i18n/nl.json +4 -0
- package/src/ADisclosure/i18n/pl.json +4 -0
- package/src/AFilters/i18n/AFiltersI18n.js +4 -0
- package/src/AFilters/i18n/nl.json +30 -0
- package/src/AFilters/i18n/pl.json +30 -0
- package/src/AGroupButtonDropdown/AGroupButtonDropdown.js +119 -119
- package/src/ALinkCopy/i18n/ALinkCopyI18n.js +4 -0
- package/src/ALinkCopy/i18n/nl.json +4 -0
- package/src/ALinkCopy/i18n/pl.json +4 -0
- package/src/ALoading/i18n/ALoadingI18n.js +4 -0
- package/src/ALoading/i18n/nl.json +3 -0
- package/src/ALoading/i18n/pl.json +3 -0
- package/src/AMenu/i18n/AMenu2I18n.js +4 -0
- package/src/AMenu/i18n/nl.json +14 -0
- package/src/AMenu/i18n/pl.json +14 -0
- package/src/AModal/compositionAPI/ZIndexAPI.js +48 -48
- package/src/AModal/i18n/AModalI18n.js +4 -0
- package/src/AModal/i18n/nl.json +7 -0
- package/src/AModal/i18n/pl.json +7 -0
- package/src/APagination/i18n/APaginationI18n.js +4 -0
- package/src/APagination/i18n/nl.json +12 -0
- package/src/APagination/i18n/pl.json +12 -0
- package/src/AProgress/AProgress.js +141 -141
- package/src/AProgressCircle/AProgressCircle.js +160 -160
- package/src/AShowMore/i18n/AShowMoreI18n.js +4 -0
- package/src/AShowMore/i18n/nl.json +6 -0
- package/src/AShowMore/i18n/pl.json +6 -0
- package/src/ASpinner/i18n/ASpinnerI18n.js +4 -0
- package/src/ASpinner/i18n/nl.json +3 -0
- package/src/ASpinner/i18n/pl.json +3 -0
- package/src/ATable/ATableHeaderTh/ATableHeaderTh.js +188 -188
- package/src/ATable/i18n/ATableI18n.js +4 -0
- package/src/ATable/i18n/nl.json +54 -0
- package/src/ATable/i18n/pl.json +54 -0
- package/src/ATableForm/i18n/ATableFormI18n.js +4 -0
- package/src/ATableForm/i18n/nl.json +18 -0
- package/src/ATableForm/i18n/pl.json +18 -0
- package/src/ATranslation/compositionAPI/UtilsAPI.js +6 -1
- package/src/ATranslation/compositionAPI/__tests__/UtilsAPI.getTranslatedText.test.js +38 -0
- package/src/AVerticalScroll/i18n/AVerticalScrollI18n.js +4 -0
- package/src/AVerticalScroll/i18n/nl.json +4 -0
- package/src/AVerticalScroll/i18n/pl.json +4 -0
- package/src/AWizard/i18n/AWizardI18n.js +4 -0
- package/src/AWizard/i18n/nl.json +16 -0
- package/src/AWizard/i18n/pl.json +16 -0
- package/src/PVP/new.txt +39 -39
- package/src/PuxDatepicker/PuxDatepicker.js +670 -670
- package/src/PuxDatepicker/PuxDatepicker.pug +131 -131
- package/src/PuxDatepicker/PuxDatepicker.vue +2 -2
- package/src/PuxDatepicker/PuxDatepickerCalendarPanel/PuxDatepickerCalendarPanel.pug +136 -136
- package/src/PuxDatepicker/PuxDatepickerCalendarPanel/PuxDatepickerCalendarPanel.vue +2 -2
- package/src/PuxDatepicker/PuxDatepickerIcon/PuxDatepickerIcon.js +30 -30
- package/src/PuxDatepicker/PuxDatepickerIcon/PuxDatepickerIcon.pug +6 -6
- package/src/PuxDatepicker/PuxDatepickerIcon/PuxDatepickerIcon.vue +2 -2
- package/src/PuxDatepicker/locale/languages.js +174 -174
- package/src/PuxDatepicker/mixins/PanelMixin.js +76 -76
- package/src/PuxDatepicker/panel/PanelDate/PanelDate.pug +41 -41
- package/src/PuxDatepicker/panel/PanelDate/PanelDate.vue +2 -2
- package/src/PuxDatepicker/panel/PanelMonth/PanelMonth.pug +16 -16
- package/src/PuxDatepicker/panel/PanelMonth/PanelMonth.vue +2 -2
- package/src/PuxDatepicker/panel/PanelTime/PanelTime.pug +20 -20
- package/src/PuxDatepicker/panel/PanelTime/PanelTime.vue +2 -2
- package/src/PuxDatepicker/panel/PanelYear/PanelYear.pug +16 -16
- package/src/PuxDatepicker/panel/PanelYear/PanelYear.vue +2 -2
- package/src/PuxDatepicker/panel/PanelYearItem/PanelYearItem.js +55 -55
- package/src/PuxDatepicker/panel/PanelYearItem/PanelYearItem.pug +9 -9
- package/src/PuxDatepicker/panel/PanelYearItem/PanelYearItem.vue +2 -2
- package/src/PuxDatepicker/utils/keysCode.js +9 -9
- package/src/PuxDatepicker/utils/scroll-into-view.js +23 -23
- package/src/PuxDatepicker/utils/transform.js +23 -23
- package/src/filters/i18n/Filters18n.js +4 -0
- package/src/filters/i18n/nl.json +11 -0
- package/src/filters/i18n/pl.json +11 -0
- package/src/i18n/allLanguages.js +96 -0
- package/src/i18n/nl.json +4 -0
- package/src/i18n/pl.json +4 -0
- package/src/index.js +4 -0
- package/src/ui/ACheckbox/ACheckbox.js +5 -0
- package/src/ui/ACheckbox/i18n/ACheckboxI18n.js +4 -0
- package/src/ui/ACheckbox/i18n/nl.json +5 -0
- package/src/ui/ACheckbox/i18n/pl.json +5 -0
- package/src/ui/AColorPicker/AColorPicker.js +743 -0
- package/src/ui/AColorPicker/AColorPickerSaturation/AColorPickerSaturation.js +102 -0
- package/src/ui/AColorPicker/AColorPickerSaturation/compositionAPI/SaturationAPI.js +77 -0
- package/src/ui/AColorPicker/AColorPickerSlider/AColorPickerSlider.js +125 -0
- package/src/ui/AColorPicker/AColorPickerSlider/compositionAPI/SliderAPI.js +73 -0
- package/src/ui/AColorPicker/__tests__/AColorPicker.test.js +204 -0
- package/src/ui/AColorPicker/__tests__/colorUtils.test.js +104 -0
- package/src/ui/AColorPicker/compositionAPI/ColorStateAPI.js +133 -0
- package/src/ui/AColorPicker/compositionAPI/ConfirmAPI.js +36 -0
- package/src/ui/AColorPicker/compositionAPI/FormatAPI.js +59 -0
- package/src/ui/AColorPicker/compositionAPI/InputAPI.js +63 -0
- package/src/ui/AColorPicker/compositionAPI/KeyboardStepAPI.js +42 -0
- package/src/ui/AColorPicker/compositionAPI/PointerDragAPI.js +70 -0
- package/src/ui/AColorPicker/compositionAPI/PopoverAPI.js +196 -0
- package/src/ui/AColorPicker/compositionAPI/PredefineAPI.js +42 -0
- package/src/ui/AColorPicker/compositionAPI/ToggleClassAPI.js +24 -0
- package/src/ui/AColorPicker/i18n/AColorPickerI18n.js +25 -0
- package/src/ui/AColorPicker/i18n/ar.json +14 -0
- package/src/ui/AColorPicker/i18n/de.json +14 -0
- package/src/ui/AColorPicker/i18n/en.json +14 -0
- package/src/ui/AColorPicker/i18n/es.json +14 -0
- package/src/ui/AColorPicker/i18n/fr.json +14 -0
- package/src/ui/AColorPicker/i18n/hr.json +14 -0
- package/src/ui/AColorPicker/i18n/it.json +14 -0
- package/src/ui/AColorPicker/i18n/nl.json +14 -0
- package/src/ui/AColorPicker/i18n/pl.json +14 -0
- package/src/ui/AColorPicker/i18n/ru.json +14 -0
- package/src/ui/AColorPicker/i18n/uk.json +14 -0
- package/src/ui/AColorPicker/utils/colorUtils.js +296 -0
- package/src/ui/ADatepicker/ADatepickerCalendarPanel/ADatepickerCalendarPanel.js +68 -68
- package/src/ui/ADatepicker/i18n/ADatepickerI18n.js +4 -0
- package/src/ui/ADatepicker/i18n/nl.json +58 -0
- package/src/ui/ADatepicker/i18n/pl.json +58 -0
- package/src/ui/ADatepicker/panel/APanelTime/APanelTime.js +147 -147
- package/src/ui/ADatepicker/panel/APanelYear/APanelYear.js +123 -123
- package/src/ui/ADatepickerAlt/ADatepickerCalendarPanel/ADatepickerCalendarPanel.js +804 -804
- package/src/ui/ADatepickerAlt/panel/APanelDate/APanelDate.js +353 -353
- package/src/ui/ADatepickerAlt/panel/APanelMonth/APanelMonth.js +187 -187
- package/src/ui/ADatepickerAlt/panel/APanelTime/APanelTime.js +303 -303
- package/src/ui/ADatepickerAlt/panel/APanelYear/APanelYear.js +162 -162
- package/src/ui/ADatepickerRange/i18n/ADatepickerRangeI18n.js +4 -0
- package/src/ui/ADatepickerRange/i18n/nl.json +4 -0
- package/src/ui/ADatepickerRange/i18n/pl.json +4 -0
- package/src/ui/AErrors/i18n/AErrorsI18n.js +4 -0
- package/src/ui/AErrors/i18n/nl.json +3 -0
- package/src/ui/AErrors/i18n/pl.json +3 -0
- package/src/ui/AFieldset/__tests__/AFieldset.ClassColumn.test.js +1 -0
- package/src/ui/AFieldset/i18n/AFieldsetI18n.js +4 -0
- package/src/ui/AFieldset/i18n/nl.json +4 -0
- package/src/ui/AFieldset/i18n/pl.json +4 -0
- package/src/ui/AFormElementBtnClear/i18n/AFormElementBtnClearI18n.js +4 -0
- package/src/ui/AFormElementBtnClear/i18n/nl.json +3 -0
- package/src/ui/AFormElementBtnClear/i18n/pl.json +3 -0
- package/src/ui/AInput/i18n/AInputI18n.js +4 -0
- package/src/ui/AInput/i18n/nl.json +4 -0
- package/src/ui/AInput/i18n/pl.json +4 -0
- package/src/ui/AInputCurrency/i18n/AInputCurrencyI18n.js +4 -0
- package/src/ui/AInputCurrency/i18n/nl.json +4 -0
- package/src/ui/AInputCurrency/i18n/pl.json +4 -0
- package/src/ui/AInputNumber/i18n/AInputNumberI18n.js +4 -0
- package/src/ui/AInputNumber/i18n/nl.json +4 -0
- package/src/ui/AInputNumber/i18n/pl.json +4 -0
- package/src/ui/AInputNumberRange/i18n/AInputNumberRangeI18n.js +4 -0
- package/src/ui/AInputNumberRange/i18n/nl.json +4 -0
- package/src/ui/AInputNumberRange/i18n/pl.json +4 -0
- package/src/ui/AJson/i18n/AJsonI18n.js +4 -0
- package/src/ui/AJson/i18n/nl.json +8 -0
- package/src/ui/AJson/i18n/pl.json +8 -0
- package/src/ui/AMultiselectOrdered/i18n/AMultiselectOrderedI18n.js +4 -0
- package/src/ui/AMultiselectOrdered/i18n/nl.json +12 -0
- package/src/ui/AMultiselectOrdered/i18n/pl.json +12 -0
- package/src/ui/ARadio/i18n/ARadioI18n.js +4 -0
- package/src/ui/ARadio/i18n/nl.json +5 -0
- package/src/ui/ARadio/i18n/pl.json +5 -0
- package/src/ui/ARequired/i18n/ARequiredI18n.js +4 -0
- package/src/ui/ARequired/i18n/nl.json +3 -0
- package/src/ui/ARequired/i18n/pl.json +3 -0
- package/src/ui/ARouterLinkConfig/i18n/ARouterLinkConfigI18n.js +4 -0
- package/src/ui/ARouterLinkConfig/i18n/nl.json +14 -0
- package/src/ui/ARouterLinkConfig/i18n/pl.json +14 -0
- package/src/ui/ASelect/i18n/ASelectI18n.js +4 -0
- package/src/ui/ASelect/i18n/ar.json +5 -5
- package/src/ui/ASelect/i18n/de.json +4 -4
- package/src/ui/ASelect/i18n/en.json +5 -5
- package/src/ui/ASelect/i18n/es.json +5 -5
- package/src/ui/ASelect/i18n/fr.json +5 -5
- package/src/ui/ASelect/i18n/hr.json +5 -5
- package/src/ui/ASelect/i18n/it.json +5 -5
- package/src/ui/ASelect/i18n/nl.json +11 -0
- package/src/ui/ASelect/i18n/pl.json +11 -0
- package/src/ui/ASelect/i18n/ru.json +5 -5
- package/src/ui/ASelectStyle/i18n/ASelectStyleI18n.js +4 -0
- package/src/ui/ASelectStyle/i18n/nl.json +292 -0
- package/src/ui/ASelectStyle/i18n/pl.json +292 -0
- package/src/ui/ASlider/i18n/ASliderI18n.js +4 -0
- package/src/ui/ASlider/i18n/nl.json +5 -0
- package/src/ui/ASlider/i18n/pl.json +5 -0
- package/src/ui/ASwitch/i18n/ASwitchI18n.js +4 -0
- package/src/ui/ASwitch/i18n/nl.json +5 -0
- package/src/ui/ASwitch/i18n/pl.json +5 -0
- package/src/ui/AUiComponents.js +2 -0
- package/src/ui/AValidatedJson/i18n/AValidatedJsonI18n.js +4 -0
- package/src/ui/AValidatedJson/i18n/nl.json +25 -0
- package/src/ui/AValidatedJson/i18n/pl.json +25 -0
- package/src/ui/compositionApi/__tests__/UiStyleHideAPI.test.js +9 -4
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
h,
|
|
3
|
+
} from "vue";
|
|
4
|
+
|
|
5
|
+
import SaturationAPI from "./compositionAPI/SaturationAPI";
|
|
6
|
+
import {
|
|
7
|
+
getTranslatedText,
|
|
8
|
+
} from "../../../ATranslation/compositionAPI/UtilsAPI";
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
name: "AColorPickerSaturation",
|
|
12
|
+
props: {
|
|
13
|
+
alwaysTranslate: {
|
|
14
|
+
type: Boolean,
|
|
15
|
+
required: false,
|
|
16
|
+
},
|
|
17
|
+
brightness: {
|
|
18
|
+
type: Number,
|
|
19
|
+
required: true,
|
|
20
|
+
},
|
|
21
|
+
disabled: {
|
|
22
|
+
type: Boolean,
|
|
23
|
+
required: false,
|
|
24
|
+
},
|
|
25
|
+
hue: {
|
|
26
|
+
type: Number,
|
|
27
|
+
required: true,
|
|
28
|
+
},
|
|
29
|
+
id: {
|
|
30
|
+
type: String,
|
|
31
|
+
required: true,
|
|
32
|
+
},
|
|
33
|
+
saturation: {
|
|
34
|
+
type: Number,
|
|
35
|
+
required: true,
|
|
36
|
+
},
|
|
37
|
+
thumbColor: {
|
|
38
|
+
type: String,
|
|
39
|
+
required: false,
|
|
40
|
+
default: undefined,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
emits: [
|
|
44
|
+
"change",
|
|
45
|
+
],
|
|
46
|
+
setup(props, context) {
|
|
47
|
+
const {
|
|
48
|
+
areaRef,
|
|
49
|
+
areaStyle,
|
|
50
|
+
onKeydown,
|
|
51
|
+
onPointerDown,
|
|
52
|
+
thumbRef,
|
|
53
|
+
thumbStyle,
|
|
54
|
+
} = SaturationAPI(props, context);
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
areaRef,
|
|
58
|
+
areaStyle,
|
|
59
|
+
onKeydown,
|
|
60
|
+
onPointerDown,
|
|
61
|
+
thumbRef,
|
|
62
|
+
thumbStyle,
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
render() {
|
|
66
|
+
return h("div", {
|
|
67
|
+
ref: "areaRef",
|
|
68
|
+
class: "a_color_picker_saturation",
|
|
69
|
+
style: this.areaStyle,
|
|
70
|
+
onPointerdown: this.onPointerDown,
|
|
71
|
+
}, [
|
|
72
|
+
h("div", {
|
|
73
|
+
ref: "thumbRef",
|
|
74
|
+
id: this.id,
|
|
75
|
+
class: "a_color_picker_saturation__thumb",
|
|
76
|
+
style: {
|
|
77
|
+
...this.thumbStyle,
|
|
78
|
+
"--a_color_picker_thumb_color": this.thumbColor,
|
|
79
|
+
},
|
|
80
|
+
role: "slider",
|
|
81
|
+
tabindex: this.disabled ? -1 : 0,
|
|
82
|
+
"aria-label": getTranslatedText({
|
|
83
|
+
placeholder: "_A_COLOR_PICKER_SATURATION_",
|
|
84
|
+
alwaysTranslate: this.alwaysTranslate,
|
|
85
|
+
}),
|
|
86
|
+
"aria-valuemin": 0,
|
|
87
|
+
"aria-valuemax": 100,
|
|
88
|
+
"aria-valuenow": this.saturation,
|
|
89
|
+
"aria-valuetext": getTranslatedText({
|
|
90
|
+
placeholder: "_A_COLOR_PICKER_SATURATION_VALUE_{{saturation}}_{{brightness}}_",
|
|
91
|
+
alwaysTranslate: this.alwaysTranslate,
|
|
92
|
+
extra: {
|
|
93
|
+
saturation: this.saturation,
|
|
94
|
+
brightness: this.brightness,
|
|
95
|
+
},
|
|
96
|
+
}),
|
|
97
|
+
"aria-disabled": this.disabled ? "true" : undefined,
|
|
98
|
+
onKeydown: this.onKeydown,
|
|
99
|
+
}),
|
|
100
|
+
]);
|
|
101
|
+
},
|
|
102
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
ref,
|
|
4
|
+
toRef,
|
|
5
|
+
} from "vue";
|
|
6
|
+
|
|
7
|
+
import PointerDragAPI from "../../compositionAPI/PointerDragAPI";
|
|
8
|
+
import {
|
|
9
|
+
getValueForKey,
|
|
10
|
+
} from "../../compositionAPI/KeyboardStepAPI";
|
|
11
|
+
|
|
12
|
+
export default function SaturationAPI(props, { emit }) {
|
|
13
|
+
const brightness = toRef(props, "brightness");
|
|
14
|
+
const hue = toRef(props, "hue");
|
|
15
|
+
const saturation = toRef(props, "saturation");
|
|
16
|
+
|
|
17
|
+
const areaRef = ref(undefined);
|
|
18
|
+
const thumbRef = ref(undefined);
|
|
19
|
+
|
|
20
|
+
const areaStyle = computed(() => {
|
|
21
|
+
return {
|
|
22
|
+
"--a_color_picker_hue": `hsl(${ hue.value }, 100%, 50%)`,
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const thumbStyle = computed(() => {
|
|
27
|
+
return {
|
|
28
|
+
left: `${ saturation.value }%`,
|
|
29
|
+
top: `${ 100 - brightness.value }%`,
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const update = ({ s = saturation.value, v = brightness.value }) => {
|
|
34
|
+
emit("change", {
|
|
35
|
+
saturation: Math.round(s),
|
|
36
|
+
brightness: Math.round(v),
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const focusThumb = () => {
|
|
41
|
+
thumbRef.value?.focus();
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const {
|
|
45
|
+
onPointerDown,
|
|
46
|
+
} = PointerDragAPI(props, {
|
|
47
|
+
elementRef: areaRef,
|
|
48
|
+
onStart: focusThumb,
|
|
49
|
+
onMove: ({ x, y }) => update({ s: x * 100, v: (1 - y) * 100 }),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// ←/→ and Home/End: saturation, ↑/↓ and Page Up/Page Down: brightness
|
|
53
|
+
const onKeydown = $event => {
|
|
54
|
+
const IS_SATURATION = ["ArrowLeft", "ArrowRight", "Home", "End"].includes($event.key);
|
|
55
|
+
const VALUE = getValueForKey({
|
|
56
|
+
key: $event.key,
|
|
57
|
+
shiftKey: $event.shiftKey,
|
|
58
|
+
value: IS_SATURATION ? saturation.value : brightness.value,
|
|
59
|
+
min: 0,
|
|
60
|
+
max: 100,
|
|
61
|
+
});
|
|
62
|
+
if (VALUE === undefined) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
$event.preventDefault();
|
|
66
|
+
update(IS_SATURATION ? { s: VALUE } : { v: VALUE });
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
areaRef,
|
|
71
|
+
areaStyle,
|
|
72
|
+
onKeydown,
|
|
73
|
+
onPointerDown,
|
|
74
|
+
thumbRef,
|
|
75
|
+
thumbStyle,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
h,
|
|
3
|
+
} from "vue";
|
|
4
|
+
|
|
5
|
+
import SliderAPI from "./compositionAPI/SliderAPI";
|
|
6
|
+
import {
|
|
7
|
+
getTranslatedText,
|
|
8
|
+
} from "../../../ATranslation/compositionAPI/UtilsAPI";
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
name: "AColorPickerSlider",
|
|
12
|
+
props: {
|
|
13
|
+
alwaysTranslate: {
|
|
14
|
+
type: Boolean,
|
|
15
|
+
required: false,
|
|
16
|
+
},
|
|
17
|
+
background: {
|
|
18
|
+
type: String,
|
|
19
|
+
required: true,
|
|
20
|
+
},
|
|
21
|
+
class: {
|
|
22
|
+
type: [String, Object, Array],
|
|
23
|
+
required: false,
|
|
24
|
+
default: undefined,
|
|
25
|
+
},
|
|
26
|
+
disabled: {
|
|
27
|
+
type: Boolean,
|
|
28
|
+
required: false,
|
|
29
|
+
},
|
|
30
|
+
id: {
|
|
31
|
+
type: String,
|
|
32
|
+
required: true,
|
|
33
|
+
},
|
|
34
|
+
label: {
|
|
35
|
+
type: String,
|
|
36
|
+
required: true,
|
|
37
|
+
},
|
|
38
|
+
largeStep: {
|
|
39
|
+
type: Number,
|
|
40
|
+
required: false,
|
|
41
|
+
default: 10,
|
|
42
|
+
},
|
|
43
|
+
max: {
|
|
44
|
+
type: Number,
|
|
45
|
+
required: true,
|
|
46
|
+
},
|
|
47
|
+
min: {
|
|
48
|
+
type: Number,
|
|
49
|
+
required: false,
|
|
50
|
+
default: 0,
|
|
51
|
+
},
|
|
52
|
+
modelValue: {
|
|
53
|
+
type: Number,
|
|
54
|
+
required: true,
|
|
55
|
+
},
|
|
56
|
+
step: {
|
|
57
|
+
type: Number,
|
|
58
|
+
required: false,
|
|
59
|
+
default: 1,
|
|
60
|
+
},
|
|
61
|
+
thumbColor: {
|
|
62
|
+
type: String,
|
|
63
|
+
required: false,
|
|
64
|
+
default: undefined,
|
|
65
|
+
},
|
|
66
|
+
valueText: {
|
|
67
|
+
type: String,
|
|
68
|
+
required: false,
|
|
69
|
+
default: undefined,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
emits: [
|
|
73
|
+
"update:modelValue",
|
|
74
|
+
],
|
|
75
|
+
setup(props, context) {
|
|
76
|
+
const {
|
|
77
|
+
onKeydown,
|
|
78
|
+
onPointerDown,
|
|
79
|
+
thumbRef,
|
|
80
|
+
thumbStyle,
|
|
81
|
+
trackRef,
|
|
82
|
+
} = SliderAPI(props, context);
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
onKeydown,
|
|
86
|
+
onPointerDown,
|
|
87
|
+
thumbRef,
|
|
88
|
+
thumbStyle,
|
|
89
|
+
trackRef,
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
render() {
|
|
93
|
+
return h("div", {
|
|
94
|
+
ref: "trackRef",
|
|
95
|
+
class: ["a_color_picker_slider", this.class],
|
|
96
|
+
style: {
|
|
97
|
+
"--a_color_picker_slider_bg": this.background,
|
|
98
|
+
},
|
|
99
|
+
onPointerdown: this.onPointerDown,
|
|
100
|
+
}, [
|
|
101
|
+
h("div", {
|
|
102
|
+
ref: "thumbRef",
|
|
103
|
+
id: this.id,
|
|
104
|
+
class: "a_color_picker_slider__thumb",
|
|
105
|
+
style: {
|
|
106
|
+
...this.thumbStyle,
|
|
107
|
+
"--a_color_picker_thumb_color": this.thumbColor,
|
|
108
|
+
},
|
|
109
|
+
role: "slider",
|
|
110
|
+
tabindex: this.disabled ? -1 : 0,
|
|
111
|
+
"aria-label": getTranslatedText({
|
|
112
|
+
placeholder: this.label,
|
|
113
|
+
alwaysTranslate: this.alwaysTranslate,
|
|
114
|
+
}),
|
|
115
|
+
"aria-valuemin": this.min,
|
|
116
|
+
"aria-valuemax": this.max,
|
|
117
|
+
"aria-valuenow": Math.round(this.modelValue),
|
|
118
|
+
"aria-valuetext": this.valueText,
|
|
119
|
+
"aria-orientation": "horizontal",
|
|
120
|
+
"aria-disabled": this.disabled ? "true" : undefined,
|
|
121
|
+
onKeydown: this.onKeydown,
|
|
122
|
+
}),
|
|
123
|
+
]);
|
|
124
|
+
},
|
|
125
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
ref,
|
|
4
|
+
toRef,
|
|
5
|
+
} from "vue";
|
|
6
|
+
|
|
7
|
+
import PointerDragAPI from "../../compositionAPI/PointerDragAPI";
|
|
8
|
+
import {
|
|
9
|
+
getValueForKey,
|
|
10
|
+
} from "../../compositionAPI/KeyboardStepAPI";
|
|
11
|
+
|
|
12
|
+
export default function SliderAPI(props, { emit }) {
|
|
13
|
+
const largeStep = toRef(props, "largeStep");
|
|
14
|
+
const max = toRef(props, "max");
|
|
15
|
+
const min = toRef(props, "min");
|
|
16
|
+
const modelValue = toRef(props, "modelValue");
|
|
17
|
+
const step = toRef(props, "step");
|
|
18
|
+
|
|
19
|
+
const thumbRef = ref(undefined);
|
|
20
|
+
const trackRef = ref(undefined);
|
|
21
|
+
|
|
22
|
+
const percent = computed(() => {
|
|
23
|
+
const RANGE = max.value - min.value;
|
|
24
|
+
return RANGE ? (modelValue.value - min.value) / RANGE * 100 : 0;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const thumbStyle = computed(() => {
|
|
28
|
+
return {
|
|
29
|
+
left: `${ percent.value }%`,
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const updateValue = value => {
|
|
34
|
+
emit("update:modelValue", Math.round(value / step.value) * step.value);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const focusThumb = () => {
|
|
38
|
+
thumbRef.value?.focus();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const {
|
|
42
|
+
onPointerDown,
|
|
43
|
+
} = PointerDragAPI(props, {
|
|
44
|
+
elementRef: trackRef,
|
|
45
|
+
onStart: focusThumb,
|
|
46
|
+
onMove: ({ x }) => updateValue(min.value + x * (max.value - min.value)),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const onKeydown = $event => {
|
|
50
|
+
const VALUE = getValueForKey({
|
|
51
|
+
key: $event.key,
|
|
52
|
+
shiftKey: $event.shiftKey,
|
|
53
|
+
value: modelValue.value,
|
|
54
|
+
min: min.value,
|
|
55
|
+
max: max.value,
|
|
56
|
+
step: step.value,
|
|
57
|
+
largeStep: largeStep.value,
|
|
58
|
+
});
|
|
59
|
+
if (VALUE === undefined) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
$event.preventDefault();
|
|
63
|
+
updateValue(VALUE);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
onKeydown,
|
|
68
|
+
onPointerDown,
|
|
69
|
+
thumbRef,
|
|
70
|
+
thumbStyle,
|
|
71
|
+
trackRef,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import {
|
|
2
|
+
nextTick,
|
|
3
|
+
} from "vue";
|
|
4
|
+
import {
|
|
5
|
+
afterEach,
|
|
6
|
+
describe,
|
|
7
|
+
expect,
|
|
8
|
+
it,
|
|
9
|
+
vi,
|
|
10
|
+
} from "vitest";
|
|
11
|
+
import {
|
|
12
|
+
mount,
|
|
13
|
+
} from "@vue/test-utils";
|
|
14
|
+
|
|
15
|
+
import AColorPicker from "../AColorPicker";
|
|
16
|
+
|
|
17
|
+
const mountPicker = props => {
|
|
18
|
+
return mount(AColorPicker, {
|
|
19
|
+
attachTo: document.body,
|
|
20
|
+
props: {
|
|
21
|
+
label: "Color",
|
|
22
|
+
...props,
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const flush = async() => {
|
|
28
|
+
await nextTick();
|
|
29
|
+
await nextTick();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const getPopup = () => document.body.querySelector(".a_color_picker__popup");
|
|
33
|
+
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
document.body.innerHTML = "";
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("AColorPicker", () => {
|
|
39
|
+
it("renders an accessible toggle filled with the model color", () => {
|
|
40
|
+
const wrapper = mountPicker({ modelValue: "#0775b0" });
|
|
41
|
+
const toggle = wrapper.get("button.a_color_picker__toggle");
|
|
42
|
+
|
|
43
|
+
expect(toggle.attributes("aria-haspopup")).toBe("dialog");
|
|
44
|
+
expect(toggle.attributes("aria-expanded")).toBe("false");
|
|
45
|
+
expect(toggle.attributes("aria-labelledby")).toContain("_label");
|
|
46
|
+
const parent = wrapper.get(".a_color_picker");
|
|
47
|
+
expect(parent.attributes("style")).toContain("--a_color_picker_color: rgb(7, 117, 176)");
|
|
48
|
+
expect(parent.attributes("style")).toContain("--a_color_picker_text_color: #fff");
|
|
49
|
+
expect(toggle.text()).toBe("#0775b0");
|
|
50
|
+
wrapper.unmount();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("opens a dialog, changes the hue with the keyboard and confirms", async() => {
|
|
54
|
+
const change = vi.fn();
|
|
55
|
+
const wrapper = mountPicker({ modelValue: "#ff0000", change });
|
|
56
|
+
await wrapper.get("button.a_color_picker__toggle").trigger("click");
|
|
57
|
+
await flush();
|
|
58
|
+
|
|
59
|
+
const popup = getPopup();
|
|
60
|
+
expect(popup.getAttribute("role")).toBe("dialog");
|
|
61
|
+
expect(wrapper.get("button.a_color_picker__toggle").attributes("aria-expanded")).toBe("true");
|
|
62
|
+
|
|
63
|
+
const hue = popup.querySelector(".a_color_picker_slider_hue [role='slider']");
|
|
64
|
+
expect(hue.getAttribute("aria-valuenow")).toBe("0");
|
|
65
|
+
hue.dispatchEvent(new KeyboardEvent("keydown", { key: "End", bubbles: true }));
|
|
66
|
+
await flush();
|
|
67
|
+
hue.dispatchEvent(new KeyboardEvent("keydown", { key: "ArrowLeft", bubbles: true, shiftKey: true }));
|
|
68
|
+
await flush();
|
|
69
|
+
expect(hue.getAttribute("aria-valuenow")).toBe("345");
|
|
70
|
+
|
|
71
|
+
[...popup.querySelectorAll("button")].find(button => button.textContent.includes("_A_COLOR_PICKER_CONFIRM_")).click();
|
|
72
|
+
await flush();
|
|
73
|
+
|
|
74
|
+
expect(wrapper.emitted("update:modelValue").at(-1)).toEqual(["#ff0040"]);
|
|
75
|
+
expect(change).toHaveBeenCalledWith(expect.objectContaining({ model: "#ff0040" }));
|
|
76
|
+
expect(getPopup()).toBeNull();
|
|
77
|
+
wrapper.unmount();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("focuses the dialog only after it is positioned", async() => {
|
|
81
|
+
const wrapper = mountPicker({ modelValue: "#ff0000" });
|
|
82
|
+
await wrapper.get("button.a_color_picker__toggle").trigger("click");
|
|
83
|
+
await nextTick();
|
|
84
|
+
|
|
85
|
+
expect(getPopup().classList.contains("a_color_picker__popup_positioning")).toBe(true);
|
|
86
|
+
|
|
87
|
+
await new Promise(resolve => setTimeout(resolve, 20));
|
|
88
|
+
await flush();
|
|
89
|
+
|
|
90
|
+
expect(getPopup().classList.contains("a_color_picker__popup_positioning")).toBe(false);
|
|
91
|
+
expect(document.activeElement.classList.contains("a_color_picker_saturation__thumb")).toBe(true);
|
|
92
|
+
wrapper.unmount();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("closes with Escape without changing the model and returns the focus", async() => {
|
|
96
|
+
const wrapper = mountPicker({ modelValue: "#ff0000" });
|
|
97
|
+
const toggle = wrapper.get("button.a_color_picker__toggle");
|
|
98
|
+
await toggle.trigger("click");
|
|
99
|
+
await flush();
|
|
100
|
+
|
|
101
|
+
const saturation = getPopup().querySelector(".a_color_picker_saturation__thumb");
|
|
102
|
+
saturation.dispatchEvent(new KeyboardEvent("keydown", { key: "Home", bubbles: true }));
|
|
103
|
+
await flush();
|
|
104
|
+
saturation.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
|
|
105
|
+
await flush();
|
|
106
|
+
|
|
107
|
+
expect(getPopup()).toBeNull();
|
|
108
|
+
expect(wrapper.emitted("update:modelValue")).toBeUndefined();
|
|
109
|
+
expect(document.activeElement).toBe(toggle.element);
|
|
110
|
+
wrapper.unmount();
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("applies a typed value and shows an error for an invalid one", async() => {
|
|
114
|
+
const wrapper = mountPicker({ modelValue: "#ff0000", colorFormats: "rgb", showAlpha: true });
|
|
115
|
+
await wrapper.get("button.a_color_picker__toggle").trigger("click");
|
|
116
|
+
await flush();
|
|
117
|
+
|
|
118
|
+
const input = getPopup().querySelector(".a_color_picker__input input");
|
|
119
|
+
input.value = "no color";
|
|
120
|
+
input.dispatchEvent(new Event("input"));
|
|
121
|
+
input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
|
|
122
|
+
await flush();
|
|
123
|
+
expect(input.getAttribute("aria-invalid")).toBe("true");
|
|
124
|
+
|
|
125
|
+
input.value = "#00ff0080";
|
|
126
|
+
input.dispatchEvent(new Event("input"));
|
|
127
|
+
input.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
|
|
128
|
+
await flush();
|
|
129
|
+
expect(input.value).toBe("rgba(0, 255, 0, 0.5)");
|
|
130
|
+
expect(getPopup().querySelector(".a_color_picker_slider_alpha [role='slider']").getAttribute("aria-valuenow")).toBe("50");
|
|
131
|
+
wrapper.unmount();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("opens with the format of the model and switches formats in the given order", async() => {
|
|
135
|
+
const wrapper = mountPicker({ modelValue: "hsl(0, 100%, 50%)", colorFormats: ["hex", "hsl", "rgb"] });
|
|
136
|
+
await wrapper.get("button.a_color_picker__toggle").trigger("click");
|
|
137
|
+
await flush();
|
|
138
|
+
|
|
139
|
+
const input = () => getPopup().querySelector(".a_color_picker__input input");
|
|
140
|
+
const switchButton = () => getPopup().querySelector(".a_color_picker__format");
|
|
141
|
+
expect(input().value).toBe("hsl(0, 100%, 50%)");
|
|
142
|
+
expect(switchButton().textContent).toBe("HSL");
|
|
143
|
+
expect(switchButton().getAttribute("aria-label")).toBe("_A_COLOR_PICKER_FORMAT_SWITCH_{{format}}_{{next}}_");
|
|
144
|
+
|
|
145
|
+
switchButton().click();
|
|
146
|
+
await flush();
|
|
147
|
+
expect(input().value).toBe("rgb(255, 0, 0)");
|
|
148
|
+
switchButton().click();
|
|
149
|
+
await flush();
|
|
150
|
+
expect(input().value).toBe("#ff0000");
|
|
151
|
+
|
|
152
|
+
[...getPopup().querySelectorAll("button")].find(button => button.textContent.includes("_A_COLOR_PICKER_CONFIRM_")).click();
|
|
153
|
+
await flush();
|
|
154
|
+
expect(wrapper.emitted("update:modelValue").at(-1)).toEqual(["#ff0000"]);
|
|
155
|
+
wrapper.unmount();
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("keeps the model text when nothing is changed", async() => {
|
|
159
|
+
const wrapper = mountPicker({ modelValue: "hsl(145, 63%, 29%)", colorFormats: ["hex", "hsl"] });
|
|
160
|
+
await wrapper.get("button.a_color_picker__toggle").trigger("click");
|
|
161
|
+
await flush();
|
|
162
|
+
|
|
163
|
+
expect(getPopup().querySelector(".a_color_picker__input input").value).toBe("hsl(145, 63%, 29%)");
|
|
164
|
+
[...getPopup().querySelectorAll("button")].find(button => button.textContent.includes("_A_COLOR_PICKER_CONFIRM_")).click();
|
|
165
|
+
await flush();
|
|
166
|
+
expect(wrapper.emitted("update:modelValue").at(-1)).toEqual(["hsl(145, 63%, 29%)"]);
|
|
167
|
+
wrapper.unmount();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("uses the first format if the model format is not allowed and hides the switch for one format", async() => {
|
|
171
|
+
const wrapper = mountPicker({ modelValue: "#ff0000", colorFormats: ["rgb", "hsv"] });
|
|
172
|
+
await wrapper.get("button.a_color_picker__toggle").trigger("click");
|
|
173
|
+
await flush();
|
|
174
|
+
expect(getPopup().querySelector(".a_color_picker__input input").value).toBe("rgb(255, 0, 0)");
|
|
175
|
+
wrapper.unmount();
|
|
176
|
+
|
|
177
|
+
const single = mountPicker({ modelValue: "#ff0000", colorFormats: "hex" });
|
|
178
|
+
await single.get("button.a_color_picker__toggle").trigger("click");
|
|
179
|
+
await flush();
|
|
180
|
+
expect(getPopup().querySelector(".a_color_picker__format")).toBeNull();
|
|
181
|
+
single.unmount();
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("marks the selected predefined color", async() => {
|
|
185
|
+
const wrapper = mountPicker({ modelValue: "#ff0000", predefine: ["#ff0000", "#00ff00", "invalid"] });
|
|
186
|
+
await wrapper.get("button.a_color_picker__toggle").trigger("click");
|
|
187
|
+
await flush();
|
|
188
|
+
|
|
189
|
+
const items = getPopup().querySelectorAll(".a_color_picker__predefine__item");
|
|
190
|
+
expect(items).toHaveLength(2);
|
|
191
|
+
expect(items[0].getAttribute("aria-pressed")).toBe("true");
|
|
192
|
+
items[1].click();
|
|
193
|
+
await flush();
|
|
194
|
+
expect(items[1].getAttribute("aria-pressed")).toBe("true");
|
|
195
|
+
wrapper.unmount();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("renders the readonly value with a swatch", () => {
|
|
199
|
+
const wrapper = mountPicker({ modelValue: "#0775b0", readonly: true });
|
|
200
|
+
expect(wrapper.find(".a_color_picker__swatch").exists()).toBe(true);
|
|
201
|
+
expect(wrapper.text()).toContain("#0775b0");
|
|
202
|
+
wrapper.unmount();
|
|
203
|
+
});
|
|
204
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import {
|
|
2
|
+
describe,
|
|
3
|
+
expect,
|
|
4
|
+
it,
|
|
5
|
+
} from "vitest";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
contrastRatio,
|
|
9
|
+
detectColorFormat,
|
|
10
|
+
formatColor,
|
|
11
|
+
getContrastTextColor,
|
|
12
|
+
hslToHsv,
|
|
13
|
+
hsvToHsl,
|
|
14
|
+
hsvToRgb,
|
|
15
|
+
isSameColor,
|
|
16
|
+
parseColor,
|
|
17
|
+
rgbToHsl,
|
|
18
|
+
rgbToHsv,
|
|
19
|
+
} from "../utils/colorUtils";
|
|
20
|
+
|
|
21
|
+
describe("colorUtils parseColor", () => {
|
|
22
|
+
it("parses hex in all lengths", () => {
|
|
23
|
+
expect(parseColor("#f00")).toEqual({ r: 255, g: 0, b: 0, a: 1 });
|
|
24
|
+
expect(parseColor("#f008")).toEqual({ r: 255, g: 0, b: 0, a: 0.53 });
|
|
25
|
+
expect(parseColor("#0775B0")).toEqual({ r: 7, g: 117, b: 176, a: 1 });
|
|
26
|
+
expect(parseColor("0775b080")).toEqual({ r: 7, g: 117, b: 176, a: 0.5 });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("parses rgb, hsl and hsv functions with commas, spaces and slash", () => {
|
|
30
|
+
expect(parseColor("rgb(7, 117, 176)")).toEqual({ r: 7, g: 117, b: 176, a: 1 });
|
|
31
|
+
expect(parseColor("rgba(7, 117, 176, .5)")).toEqual({ r: 7, g: 117, b: 176, a: 0.5 });
|
|
32
|
+
expect(parseColor("rgb(7 117 176 / 50%)")).toEqual({ r: 7, g: 117, b: 176, a: 0.5 });
|
|
33
|
+
expect(parseColor("hsl(0, 100%, 50%)")).toEqual({ r: 255, g: 0, b: 0, a: 1 });
|
|
34
|
+
expect(parseColor("hsva(120, 100%, 100%, 0.25)")).toEqual({ r: 0, g: 255, b: 0, a: 0.25 });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("returns undefined for invalid values", () => {
|
|
38
|
+
expect(parseColor("")).toBeUndefined();
|
|
39
|
+
expect(parseColor("red")).toBeUndefined();
|
|
40
|
+
expect(parseColor("#12345")).toBeUndefined();
|
|
41
|
+
expect(parseColor("rgb(1, 2)")).toBeUndefined();
|
|
42
|
+
expect(parseColor(undefined)).toBeUndefined();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe("colorUtils detectColorFormat", () => {
|
|
47
|
+
it("detects the format of a value", () => {
|
|
48
|
+
expect(detectColorFormat("#0775b0")).toBe("hex");
|
|
49
|
+
expect(detectColorFormat("RGBA(7, 117, 176, .5)")).toBe("rgb");
|
|
50
|
+
expect(detectColorFormat("hsl(0, 100%, 50%)")).toBe("hsl");
|
|
51
|
+
expect(detectColorFormat("hsva(0, 100%, 100%, 1)")).toBe("hsv");
|
|
52
|
+
expect(detectColorFormat("red")).toBeUndefined();
|
|
53
|
+
expect(detectColorFormat(undefined)).toBeUndefined();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("colorUtils formatColor", () => {
|
|
58
|
+
const COLOR = { r: 7, g: 117, b: 176, a: 0.5 };
|
|
59
|
+
|
|
60
|
+
it("writes alpha only with showAlpha and a < 1", () => {
|
|
61
|
+
expect(formatColor(COLOR, "hex")).toBe("#0775b0");
|
|
62
|
+
expect(formatColor(COLOR, "hex", true)).toBe("#0775b080");
|
|
63
|
+
expect(formatColor({ ...COLOR, a: 1 }, "hex", true)).toBe("#0775b0");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("formats rgb, hsl and hsv", () => {
|
|
67
|
+
expect(formatColor(COLOR, "rgb", true)).toBe("rgba(7, 117, 176, 0.5)");
|
|
68
|
+
expect(formatColor(COLOR, "rgb")).toBe("rgb(7, 117, 176)");
|
|
69
|
+
expect(formatColor({ r: 255, g: 0, b: 0 }, "hsl")).toBe("hsl(0, 100%, 50%)");
|
|
70
|
+
expect(formatColor({ r: 255, g: 0, b: 0 }, "hsv")).toBe("hsv(0, 100%, 100%)");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("round-trips through parseColor", () => {
|
|
74
|
+
["#0775b0", "rgb(7, 117, 176)", "hsl(201, 92%, 36%)"].forEach(value => {
|
|
75
|
+
const FORMAT = value.startsWith("#") ? "hex" : value.slice(0, 3);
|
|
76
|
+
expect(formatColor(parseColor(value), FORMAT)).toBe(value);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("colorUtils conversions", () => {
|
|
82
|
+
it("converts between rgb, hsv and hsl", () => {
|
|
83
|
+
expect(hsvToRgb({ h: 201, s: 96, v: 69 })).toEqual({ r: 7, g: 117, b: 176 });
|
|
84
|
+
expect(rgbToHsv({ r: 255, g: 255, b: 255 })).toEqual({ h: 0, s: 0, v: 100 });
|
|
85
|
+
const HSL = rgbToHsl({ r: 255, g: 0, b: 0 });
|
|
86
|
+
expect(HSL).toEqual({ h: 0, s: 100, l: 50 });
|
|
87
|
+
expect(hslToHsv(hsvToHsl({ h: 10, s: 40, v: 80 }))).toEqual({ h: 10, s: expect.closeTo(40, 6), v: expect.closeTo(80, 6) });
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe("colorUtils contrast", () => {
|
|
92
|
+
it("chooses the more readable text color", () => {
|
|
93
|
+
expect(getContrastTextColor({ r: 255, g: 255, b: 0 })).toBe("#000");
|
|
94
|
+
expect(getContrastTextColor({ r: 7, g: 117, b: 176 })).toBe("#fff");
|
|
95
|
+
// almost transparent dark color on white stays readable with black text
|
|
96
|
+
expect(getContrastTextColor({ r: 0, g: 0, b: 0, a: 0.1 })).toBe("#000");
|
|
97
|
+
expect(contrastRatio({ r: 0, g: 0, b: 0 }, { r: 255, g: 255, b: 255 })).toBeCloseTo(21);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("compares colors including alpha", () => {
|
|
101
|
+
expect(isSameColor(parseColor("#f00"), parseColor("rgb(255, 0, 0)"))).toBe(true);
|
|
102
|
+
expect(isSameColor(parseColor("#f00"), parseColor("#f008"))).toBe(false);
|
|
103
|
+
});
|
|
104
|
+
});
|