@hyvor/design 0.0.63 → 0.0.66

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.
@@ -3,7 +3,7 @@ import { clickOutside } from "../index.js";
3
3
  import { createEventDispatcher } from "svelte";
4
4
  export let color = "#000000";
5
5
  export let size = 30;
6
- let show = false;
6
+ export let show = false;
7
7
  const dispatch = createEventDispatcher();
8
8
  function handleInput() {
9
9
  dispatch("input", color);
@@ -19,7 +19,13 @@ function handleClose() {
19
19
  style:width="{size}px"
20
20
  style:height="{size}px"
21
21
  style:background-color={color}
22
- on:click={() => show = true}
22
+ on:click={() => {
23
+ if (show) {
24
+ handleClose();
25
+ } else {
26
+ show = true;
27
+ }
28
+ }}
23
29
  ></button>
24
30
 
25
31
  {#if show}
@@ -29,9 +35,9 @@ function handleClose() {
29
35
  callback: () => handleClose(),
30
36
  }}
31
37
  >
32
- <ColorPicker
38
+ <ColorPicker
33
39
  bind:hex={color}
34
- --input-size={size + 'px'}
40
+ --input-size={size + "px"}
35
41
  isDialog={false}
36
42
  isAlpha={false}
37
43
  on:input={handleInput}
@@ -55,4 +61,4 @@ function handleClose() {
55
61
  width: 0;
56
62
  z-index: 1000;
57
63
  }
58
- </style>
64
+ </style>
@@ -3,6 +3,7 @@ declare const __propDef: {
3
3
  props: {
4
4
  color?: string | undefined;
5
5
  size?: number | undefined;
6
+ show?: boolean | undefined;
6
7
  };
7
8
  events: {
8
9
  input: CustomEvent<string>;
@@ -0,0 +1,128 @@
1
+ <script>import { createEventDispatcher } from "svelte";
2
+ export let min;
3
+ export let max;
4
+ export let value;
5
+ export let step = 1;
6
+ export let disabled = false;
7
+ export let dots = false;
8
+ const dispatch = createEventDispatcher();
9
+ function toStep(value2) {
10
+ return Math.max(min, Math.min(max, Math.round(value2 / step) * step));
11
+ }
12
+ $:
13
+ progress = (value - min) / (max - min) * 100;
14
+ let dragging = false;
15
+ let trackEl;
16
+ function handleMousedown(event) {
17
+ dragging = true;
18
+ handleMousemove(event);
19
+ window.addEventListener("mousemove", handleMousemove);
20
+ window.addEventListener("mouseup", handleMouseup);
21
+ }
22
+ function handleMouseup() {
23
+ dragging = false;
24
+ window.removeEventListener("mousemove", handleMousemove);
25
+ }
26
+ function handleMousemove(event) {
27
+ if (dragging) {
28
+ const rect = trackEl.getBoundingClientRect();
29
+ const x = event.clientX - rect.left;
30
+ const width = rect.width;
31
+ const newValue = min + x / width * (max - min);
32
+ value = toStep(newValue);
33
+ dispatch("change", value);
34
+ }
35
+ }
36
+ </script>
37
+
38
+ <div class="slider">
39
+ <!-- svelte-ignore a11y-no-static-element-interactions -->
40
+ <div
41
+ class="track"
42
+ bind:this={trackEl}
43
+ class:dragging
44
+ on:mousedown={handleMousedown}
45
+ >
46
+ <div class="progress" style="width: {progress}%"></div>
47
+ <button class="handle" style="left: {progress}%">
48
+ <span class="tip">
49
+ {value}
50
+ </span>
51
+ </button>
52
+
53
+ {#if dots}
54
+ {#each Array.from({ length: (max - min) / step + 1 }, (_, i) => i) as i}
55
+ <div
56
+ class="dot"
57
+ style="left: {(i * 100) / ((max - min) / step)}%"
58
+ ></div>
59
+ {/each}
60
+ {/if}
61
+ </div>
62
+ </div>
63
+
64
+ <style>
65
+ .track {
66
+ background-color: var(--input);
67
+ height: 10px;
68
+ border-radius: 20px;
69
+ position: relative;
70
+ }
71
+ .handle {
72
+ background-color: var(--accent);
73
+ width: 20px;
74
+ height: 20px;
75
+ border-radius: 50%;
76
+ position: absolute;
77
+ top: 50%;
78
+ transform: translate(-50%, -50%);
79
+ cursor: grab;
80
+ z-index: 1;
81
+ transition: 0.2s box-shadow;
82
+ }
83
+ .handle:hover {
84
+ box-shadow: 0 0 0 2px var(--accent-light);
85
+ }
86
+ .tip {
87
+ position: absolute;
88
+ bottom: 100%;
89
+ margin-bottom: 3px;
90
+ left: 50%;
91
+ transform: translateX(-50%);
92
+ padding: 3px 6px;
93
+ border-radius: 5px;
94
+
95
+ /* from Tooltip */
96
+ --local-bg: #24292f;
97
+ --local-color: #fff;
98
+
99
+ background-color: var(--local-bg);
100
+ color: var(--local-color);
101
+ display: none;
102
+ }
103
+
104
+ .dot {
105
+ background-color: var(--accent-light);
106
+ z-index: 0;
107
+ width: 8px;
108
+ height: 8px;
109
+ border-radius: 50%;
110
+ position: absolute;
111
+ top: 50%;
112
+ transform: translate(-50%, -50%);
113
+ }
114
+
115
+ .handle:hover .tip,
116
+ .track.dragging .tip {
117
+ display: block;
118
+ }
119
+
120
+ .track.dragging,
121
+ .track.dragging .handle {
122
+ cursor: grabbing;
123
+ }
124
+
125
+ .track.dragging .handle {
126
+ box-shadow: 0 0 0 3px var(--accent-light);
127
+ }
128
+ </style>
@@ -0,0 +1,23 @@
1
+ import { SvelteComponent } from "svelte";
2
+ declare const __propDef: {
3
+ props: {
4
+ min: number;
5
+ max: number;
6
+ value: number;
7
+ step?: number | undefined;
8
+ disabled?: boolean | undefined;
9
+ dots?: boolean | undefined;
10
+ };
11
+ events: {
12
+ change: CustomEvent<number>;
13
+ } & {
14
+ [evt: string]: CustomEvent<any>;
15
+ };
16
+ slots: {};
17
+ };
18
+ export type SliderProps = typeof __propDef.props;
19
+ export type SliderEvents = typeof __propDef.events;
20
+ export type SliderSlots = typeof __propDef.slots;
21
+ export default class Slider extends SvelteComponent<SliderProps, SliderEvents, SliderSlots> {
22
+ }
23
+ export {};
@@ -27,6 +27,7 @@ export { default as Modal } from './Modal/Modal.svelte';
27
27
  export { confirm } from './Modal/confirm.js';
28
28
  export { default as NavLink } from './NavLink/NavLink.svelte';
29
29
  export { default as Radio } from './Radio/Radio.svelte';
30
+ export { default as Slider } from './Slider/Slider.svelte';
30
31
  export { default as SplitControl } from './SplitControl/SplitControl.svelte';
31
32
  export { default as Switch } from './Switch/Switch.svelte';
32
33
  export { default as Table } from './Table/Table.svelte';
@@ -27,6 +27,7 @@ export { default as Modal } from './Modal/Modal.svelte';
27
27
  export { confirm } from './Modal/confirm.js';
28
28
  export { default as NavLink } from './NavLink/NavLink.svelte';
29
29
  export { default as Radio } from './Radio/Radio.svelte';
30
+ export { default as Slider } from './Slider/Slider.svelte';
30
31
  export { default as SplitControl } from './SplitControl/SplitControl.svelte';
31
32
  export { default as Switch } from './Switch/Switch.svelte';
32
33
  export { default as Table } from './Table/Table.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyvor/design",
3
- "version": "0.0.63",
3
+ "version": "0.0.66",
4
4
  "license": "MIT",
5
5
  "private": false,
6
6
  "scripts": {