Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Guillaume Chau <guillaume.b.chau@gmail.com>
- Loading branch information
Showing
7 changed files
with
147 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,3 @@ html.htw-dark { | |
background: #27272a ; | ||
color: #e9e9ed; | ||
} | ||
|
||
.__histoire-sandbox input { | ||
border: solid 1px #ccc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,3 @@ html.htw-dark { | |
background: #27272a ; | ||
color: #e9e9ed; | ||
} | ||
|
||
.__histoire-sandbox input { | ||
border: solid 1px #ccc; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,3 @@ html.htw-dark { | |
background: #27272a ; | ||
color: #e9e9ed; | ||
} | ||
|
||
.__histoire-sandbox input { | ||
border: solid 1px #ccc; | ||
} |
35 changes: 35 additions & 0 deletions
35
packages/histoire-controls/src/components/slider/HstSlider.story.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<script lang="ts" setup> | ||
import { reactive } from 'vue' | ||
import HstSlider from './HstSlider.vue' | ||
const state = reactive({ | ||
value: 20, | ||
min: 0, | ||
max: 100, | ||
step: 5, | ||
}) | ||
</script> | ||
|
||
<template> | ||
<Story | ||
title="HstSlider" | ||
> | ||
<HstSlider | ||
v-model="state.value" | ||
:step="state.step" | ||
:min="state.min" | ||
:max="state.max" | ||
title="Slide" | ||
/> | ||
<pre>{{ state }}</pre> | ||
<template #controls> | ||
<HstSlider | ||
v-model="state.value" | ||
:step="state.step" | ||
:min="state.min" | ||
:max="state.max" | ||
title="Value" | ||
/> | ||
</template> | ||
</Story> | ||
</template> |
103 changes: 103 additions & 0 deletions
103
packages/histoire-controls/src/components/slider/HstSlider.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
<script lang="ts"> | ||
export default { | ||
name: 'HstSlider', | ||
inheritAttrs: false, | ||
} | ||
</script> | ||
|
||
<script lang="ts" setup> | ||
import { computed, ref } from 'vue' | ||
import type { CSSProperties } from 'vue' | ||
import HstWrapper from '../HstWrapper.vue' | ||
import { VTooltip as vTooltip } from 'floating-vue' | ||
const props = defineProps<{ | ||
title?: string | ||
modelValue: number | ||
min: number | ||
max: number | ||
}>() | ||
const emit = defineEmits({ | ||
'update:modelValue': (newValue: number) => true, | ||
}) | ||
const showTooltip = ref(false) | ||
const input = ref<HTMLInputElement>(null) | ||
const numberModel = computed({ | ||
get: () => props.modelValue, | ||
set: value => { | ||
emit('update:modelValue', value) | ||
}, | ||
}) | ||
const percentage = computed(() => { | ||
return (props.modelValue - props.min) / (props.max - props.min) | ||
}) | ||
const tooltipStyle = computed<CSSProperties>(() => { | ||
const gap = 8 | ||
if (input.value) { | ||
const position = gap + ((input.value.clientWidth - 2 * gap) * percentage.value) | ||
return { | ||
left: position + 'px', | ||
} | ||
} | ||
return {} | ||
}) | ||
</script> | ||
|
||
<template> | ||
<HstWrapper | ||
class="htw-items-center" | ||
:title="title" | ||
:class="$attrs.class" | ||
:style="$attrs.style" | ||
> | ||
<div class="htw-relative htw-w-full htw-flex htw-items-center"> | ||
<div class="htw-absolute htw-inset-0 htw-flex htw-items-center"> | ||
<div class="htw-border htw-border-black/25 dark:htw-border-white/25 htw-h-1 htw-w-full htw-rounded-full" /> | ||
</div> | ||
<input | ||
ref="input" | ||
v-model.number="numberModel" | ||
class="htw-range-input htw-appearance-none htw-border-0 htw-bg-transparent htw-cursor-pointer htw-relative htw-w-full htw-m-0 htw-text-gray-700" | ||
type="range" | ||
v-bind="{ ...$attrs, class: null, style: null }" | ||
@mouseover="showTooltip = true" | ||
@mouseleave="showTooltip = false" | ||
> | ||
<div | ||
v-if="showTooltip" | ||
v-tooltip="{ content: modelValue.toString(), shown: true, distance: 16, delay: 0 }" | ||
class="htw-absolute" | ||
:style="tooltipStyle" | ||
/> | ||
</div> | ||
</HstWrapper> | ||
</template> | ||
|
||
<style lang="pcss"> | ||
.htw-range-input { | ||
&::-webkit-slider-thumb { | ||
@apply htw-appearance-none htw-h-3 htw-w-3 htw-bg-white dark:htw-bg-gray-700 htw-border htw-border-solid htw-border-black/25 dark:htw-border-white/25 htw-rounded-full; | ||
} | ||
&:hover::-webkit-slider-thumb { | ||
@apply !htw-bg-primary-500 !htw-border-primary-500; | ||
} | ||
} | ||
/* Separate rules for -moz-range-thumb to prevent a bug with Safari that causes it to ignore custom style */ | ||
.htw-range-input { | ||
&::-moz-range-thumb { | ||
@apply htw-appearance-none htw-h-3 htw-w-3 htw-bg-white dark:htw-bg-gray-700 htw-border htw-border-solid htw-border-black/25 dark:htw-border-white/25 htw-rounded-full; | ||
} | ||
&:hover::-moz-range-thumb { | ||
@apply !htw-bg-primary-500 !htw-border-primary-500; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters