@proj-airi/ui 0.10.1 → 0.10.2

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@proj-airi/ui",
3
3
  "type": "module",
4
- "version": "0.10.1",
4
+ "version": "0.10.2",
5
5
  "description": "A collection of UI components that used by Project AIRI",
6
6
  "author": {
7
7
  "name": "Moeru AI Project AIRI Team",
@@ -1,4 +1,5 @@
1
1
  <script setup lang="ts">
2
+ import { useElementHover, useKeyModifier } from '@vueuse/core'
2
3
  import { computed, onMounted, ref, watch } from 'vue'
3
4
 
4
5
  const props = withDefaults(defineProps<{
@@ -6,6 +7,7 @@ const props = withDefaults(defineProps<{
6
7
  max?: number
7
8
  step?: number
8
9
  disabled?: boolean
10
+ handleWheel?: boolean
9
11
  }>(), {
10
12
  min: 0,
11
13
  max: 100,
@@ -13,17 +15,22 @@ const props = withDefaults(defineProps<{
13
15
  disabled: false,
14
16
  })
15
17
 
16
- const modelValue = defineModel<number>({ required: true })
18
+ const smoothingFactor = 10000
17
19
 
18
- const scaledMin = computed(() => props.min * 10000)
19
- const scaledMax = computed(() => props.max * 10000)
20
- const scaledStep = computed(() => props.step * 10000)
20
+ const modelValue = defineModel<number>({ required: true })
21
21
 
22
22
  const sliderRef = ref<HTMLInputElement>()
23
+
24
+ const scaledMin = computed(() => props.min * smoothingFactor)
25
+ const scaledMax = computed(() => props.max * smoothingFactor)
26
+ const scaledStep = computed(() => props.step * smoothingFactor)
27
+ const shiftPressed = useKeyModifier('Shift')
28
+ const isHovered = useElementHover(sliderRef)
29
+
23
30
  const sliderValue = computed({
24
- get: () => modelValue.value * 10000,
31
+ get: () => modelValue.value * smoothingFactor,
25
32
  set: (value: number) => {
26
- modelValue.value = value / 10000
33
+ modelValue.value = value / smoothingFactor
27
34
  updateTrackColor()
28
35
  },
29
36
  })
@@ -31,6 +38,15 @@ const sliderValue = computed({
31
38
  onMounted(() => updateTrackColor())
32
39
  watch(sliderValue, () => updateTrackColor(), { immediate: true })
33
40
  watch([scaledMin, scaledMax, scaledStep], () => updateTrackColor(), { immediate: true })
41
+ watch(isHovered, (hovered: boolean) => {
42
+ if (!props.handleWheel)
43
+ return
44
+ if (hovered) {
45
+ sliderRef.value?.addEventListener('wheel', onWheelInput)
46
+ return
47
+ }
48
+ sliderRef.value?.removeEventListener('wheel', onWheelInput)
49
+ })
34
50
 
35
51
  function updateTrackColor() {
36
52
  if (!sliderRef.value) {
@@ -46,6 +62,15 @@ function handleInput(e: Event) {
46
62
  const target = e.target as HTMLInputElement
47
63
  target.style.setProperty('--value', target.value)
48
64
  }
65
+
66
+ function onWheelInput(ev: WheelEvent) {
67
+ let valueAfter = 0
68
+ if (ev.deltaY < 0)
69
+ valueAfter = modelValue.value += props.step * (shiftPressed.value ? 50 : 1)
70
+ if (ev.deltaY > 0)
71
+ valueAfter = modelValue.value -= props.step * (shiftPressed.value ? 50 : 1)
72
+ modelValue.value = Math.min(Math.max(valueAfter, props.min), props.max)
73
+ }
49
74
  </script>
50
75
 
51
76
  <template>
@@ -66,21 +91,23 @@ function handleInput(e: Event) {
66
91
  /*generated with Input range slider CSS style generator (version 20211225)
67
92
  https://toughengineer.github.io/demo/slider-styler*/
68
93
  .form_input-round-range {
69
- --height: 2em;
94
+ --height: 100%;
95
+ --width: 2rem;
70
96
 
71
- min-height: var(--height);
97
+ min-height: var(--width);
72
98
  appearance: none;
73
99
  background: transparent;
74
100
  transition: background-color 0.2s ease;
75
101
 
76
- --thumb-width: var(--height);
77
- --thumb-height: var(--height);
102
+ --thumb-width: var(--width);
103
+ --thumb-height: var(--width);
78
104
  --thumb-box-shadow: none;
79
105
  --thumb-border: none;
80
106
  --thumb-border-radius: 0px;
81
107
  --thumb-background: transparent;
82
108
 
83
109
  --track-height: calc(var(--height) - var(--track-value-padding) * 2);
110
+ --track-width: var(--width);
84
111
  --track-box-shadow: 0 0 12px -2px rgb(0 0 0 / 22%);
85
112
  --track-border: none;
86
113
  --track-border-radius: 16px;
@@ -95,8 +122,6 @@ https://toughengineer.github.io/demo/slider-styler*/
95
122
  }
96
123
 
97
124
  .dark .form_input-round-range {
98
- --thumb-background: rgb(238, 238, 238);
99
-
100
125
  --track-border: none;
101
126
  --track-background: rgba(64, 64, 64, 0.7);
102
127
  --track-box-shadow: 0 0 12px -2px rgb(0 0 0 / 22%);