Skip to content

Commit

Permalink
fix: fix slider shaking when palette is dragged
Browse files Browse the repository at this point in the history
  • Loading branch information
baiwusanyu-c committed Mar 15, 2024
1 parent df7706b commit 103826e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
13 changes: 9 additions & 4 deletions components/ColorPicker/src/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@
const dispatch = createEventDispatcher();
function handleChangeComplete(e: CustomEvent) {
isDragging = false;
const res = { ...e.detail, a: aColor.a };
aColor = res;
blockColor = res;
formatterColor = res;
isClear = false;
dispatch('changeComplete', formatColor(formatValue, blockColor));
}
let isDragging = false;
function handleChange(e: CustomEvent) {
isDragging = true;
const res = { ...e.detail, a: aColor.a };
aColor = res;
blockColor = res;
Expand All @@ -66,7 +70,6 @@
}
function handleAValueInput(e: CustomEvent) {
console.log(e.detail);
blockColor = e.detail;
formatterColor = e.detail;
isClear = false;
Expand Down Expand Up @@ -116,9 +119,11 @@
let hsvValue: HsvaColor = { h: 0, s: 0, v: 0, a: 100 };
$: {
hsvValue = tinycolor(value).toHsv() as HsvaColor;
hsvValue.s = hsvValue.s * 100;
hsvValue.v = hsvValue.v * 100;
if (!isDragging) {
hsvValue = tinycolor(value).toHsv() as HsvaColor;
hsvValue.s = hsvValue.s * 100;
hsvValue.v = hsvValue.v * 100;
}
}
let hsvDefaultValue: HsvaColor = { h: 0, s: 0, v: 0, a: 100 };
Expand Down
5 changes: 2 additions & 3 deletions components/ColorPicker/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type KColorPickerProps = {
allowClear?: boolean;
/**
* 默认颜色的值
* @expiremrnt 可能会删除,初始化时决定线性范围,他会根据颜色的 slider 来变化
* @expiremrnt 决定线性范围,他会根据颜色的 slider 来变化
* @type string | RgbaColor | HsvaColor;
* @default ''
*/
Expand Down Expand Up @@ -88,7 +88,7 @@ export type KColorPickerPaletteProps = {
value: string | RgbaColor | HsvaColor;
/**
* 默认颜色的值
* @expiremrnt 可能会删除,初始化时决定线性范围,他会根据颜色的 slider 来变化
* @expiremrnt 决定线性范围,他会根据颜色的 slider 来变化
* @type string | RgbaColor | HsvaColor;
* @default ''
*/
Expand Down Expand Up @@ -199,7 +199,6 @@ export type KColorPickerFormatProps = {
// TODO: Kdropdownitem
// TODO: input show format

// TODO 📌0000时拽不动
// TODO 📌360 时变成了0
// TODO: 📌拖拽优化
export interface RgbaColor {
Expand Down

0 comments on commit 103826e

Please sign in to comment.