bonkers-ui 1.0.11 → 1.0.12

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,6 +1,6 @@
1
1
  {
2
2
  "name": "bonkers-ui",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "scripts": {
5
5
  "storybook": "start-storybook -p 6006",
6
6
  "build-storybook": "build-storybook",
@@ -1,28 +1,36 @@
1
1
  <template>
2
2
  <div
3
- class="ui-input-range relative h-lg"
3
+ class="ui-input-range relative h-xl mx-xs"
4
4
  >
5
5
  <input
6
- class="appearance-none cursor-pointer bg-transparent w-full h-full"
6
+ ref="track"
7
+ v-model="rangeModel"
8
+ class="appearance-none absolute cursor-pointer bg-transparent w-full h-full"
7
9
  type="range"
8
10
  :min="min"
9
11
  :max="max"
10
- :value="modelValue"
11
12
  :step="step"
12
- @input="$emit('update:modelValue', ($event.target as HTMLInputElement).value)"
13
+ @touchmove="moveHandler"
13
14
  >
14
- <div class="ui-input-range__line h-xs w-full bg-secondary-alt rounded absolute left-0 -z-10" />
15
15
  <div
16
- class="ui-input-range__line h-xs bg-primary rounded absolute left-0 -z-10"
16
+ class="ui-input-range__line h-xs w-full bg-secondary-alt rounded absolute left-0 -z-10 -translate-y-1/2"
17
+ />
18
+ <div
19
+ class="ui-input-range__line h-xs bg-primary rounded absolute left-0 -z-10 -translate-y-1/2"
17
20
  :style="{
18
21
  width: getPercentage + '%',
19
22
  }"
20
23
  />
24
+
25
+ <div
26
+ class="ui-input-range__thumb bg-primary absolute border-8 border-white rounded-full box-content -translate-y-1/2 -translate-x-1/2"
27
+ :style="{left: getPercentage + '%'}"
28
+ />
21
29
  </div>
22
30
  </template>
23
31
 
24
32
  <script lang="ts" setup>
25
- import { computed } from "vue";
33
+ import { computed, ref } from "vue";
26
34
 
27
35
  const props = defineProps<{
28
36
  modelValue: string | number;
@@ -31,42 +39,79 @@
31
39
  step: string | number;
32
40
  }>();
33
41
 
34
- defineEmits<{
42
+ const emit = defineEmits<{
35
43
  (e: "update:modelValue", state: string | number): void
36
44
  }>();
37
45
 
46
+ const rangeModel = computed({
47
+ get() {
48
+ return props.modelValue;
49
+ },
50
+ set(value) {
51
+ emit("update:modelValue", value);
52
+ }
53
+ });
54
+
55
+ const track = ref();
56
+
38
57
  const getPercentage = computed(() => {
39
58
  return Math.round(((+props.modelValue - +props.min) / (+props.max - +props.min)) * 100);
40
59
  });
60
+
61
+ const parseMouseMove = (e: MouseEvent | TouchEvent) => {
62
+ if(track.value){
63
+ const CLICK = "clientX";
64
+
65
+ const {
66
+ left: trackStart,
67
+ width: trackLength,
68
+ } = track.value.getBoundingClientRect();
69
+
70
+ const clickOffset = "touches" in e ? e.touches[0][CLICK] : e[CLICK];
71
+
72
+ // It is possible for left to be NaN, force to number
73
+ const clickPos = Math.min(Math.max((clickOffset - trackStart ) / trackLength, 0), 1) || 0;
74
+
75
+ const mousePositionInPercent = parseFloat(String(props.min)) + clickPos * (+props.max - +props.min);
76
+
77
+ const newValue = Math.round((mousePositionInPercent) / +props.step) * +props.step;
78
+
79
+ return parseFloat(Math.min(newValue, +props.max).toFixed(2));
80
+ }
81
+ };
82
+
83
+ const moveHandler = (e: MouseEvent | TouchEvent) => {
84
+ rangeModel.value = parseMouseMove(e) || 0;
85
+ };
86
+
41
87
  </script>
42
88
 
43
89
  <style scoped>
44
90
  input[type="range"]::-webkit-slider-thumb {
45
91
  appearance: none;
46
- background-color: var(--color-primary);
47
- height: 13px;
48
- width: 13px;
49
- border-radius: 50%;
50
- border: var(--xs) solid var(--color-white);
51
- box-shadow: 0 0 0 4px var(--color-primary);
52
- box-sizing: content-box;
53
- z-index: 1;
92
+ height: 8px;
93
+ width: 8px;
94
+ transform: scale(5);
95
+ background-color: transparent;
96
+ border: 0;
97
+ box-shadow: none;
54
98
  }
55
99
 
56
100
  input[type="range"]::-moz-range-thumb {
57
101
  appearance: none;
58
- background-color: var(--color-primary);
59
- height: 13px;
60
- width: 13px;
61
- border-radius: 50%;
62
- border: var(--xs) solid var(--color-white);
63
- box-shadow: 0 0 0 4px var(--color-primary);
64
- box-sizing: content-box;
65
- z-index: 1;
102
+ background-color: transparent;
103
+ border: 0;
104
+ box-shadow: none;
66
105
  }
67
106
 
68
107
  .ui-input-range__line {
69
108
  top: 50%;
70
- transform: translate3d(0, -50%, 0);
109
+ }
110
+
111
+ .ui-input-range__thumb {
112
+ top: 50%;
113
+ height: 13px;
114
+ width: 13px;
115
+ box-shadow: 0 0 0 4px var(--color-primary);
71
116
  }
72
117
  </style>
@@ -13,7 +13,7 @@
13
13
  >
14
14
  <select
15
15
  v-model="localModel"
16
- class="appearance-none bg-transparent border-0 m-0 outline-0 w-full p-sm cursor-pointer italic text-secondary-alt"
16
+ class="appearance-none absolute bg-transparent border-0 m-0 outline-0 w-full p-sm cursor-pointer italic text-secondary-alt"
17
17
  @change=" $emit('update:value', ($event.target as HTMLTextAreaElement)?.value)"
18
18
  >
19
19
  <option
@@ -10,7 +10,7 @@
10
10
  <input
11
11
  v-model="localValue"
12
12
  type="radio"
13
- class="appearance-none"
13
+ class="appearance-none absolute"
14
14
  :value="tab"
15
15
  :name="name || 'default'"
16
16
  @input="$emit('update:modelValue', ($event.target as HTMLTextAreaElement)?.value)"
package/src/main.css CHANGED
@@ -18,3 +18,17 @@
18
18
  body {
19
19
  font-family: var(--base-font);
20
20
  }
21
+
22
+ *:focus,
23
+ *:active {
24
+ outline: none;
25
+ }
26
+
27
+ input,
28
+ textarea,
29
+ button,
30
+ select,
31
+ label,
32
+ a {
33
+ -webkit-tap-highlight-color: transparent;
34
+ }