Add divider to numeric slider (#10268)

https://github.com/enso-org/enso/assets/1047859/5a9ba761-dfec-4ec7-99ce-3088556e63e4

Closes #10234.

# Important Notes
- Tested in combination with #10267, though they can be merged separately.
This commit is contained in:
Kaz Wesley 2024-06-13 06:03:43 -07:00 committed by GitHub
parent fadb81abe6
commit 0ff2ed6cc3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 29 additions and 27 deletions

View File

@ -55,7 +55,7 @@ test('Widget in plain AST', async ({ page }) => {
const numberNode = locate.graphNodeByBinding(page, 'five') const numberNode = locate.graphNodeByBinding(page, 'five')
const numberWidget = numberNode.locator('.WidgetNumber') const numberWidget = numberNode.locator('.WidgetNumber')
await expect(numberWidget).toBeVisible() await expect(numberWidget).toBeVisible()
await expect(numberWidget.locator('input')).toHaveValue('5') await expect(numberWidget).toHaveValue('5')
const listNode = locate.graphNodeByBinding(page, 'list') const listNode = locate.graphNodeByBinding(page, 'list')
const listWidget = listNode.locator('.WidgetVector') const listWidget = listNode.locator('.WidgetVector')

View File

@ -15,6 +15,7 @@
--color-dim: rgb(0 0 0 / 0.25); --color-dim: rgb(0 0 0 / 0.25);
--color-frame-bg: rgb(255 255 255 / 0.3); --color-frame-bg: rgb(255 255 255 / 0.3);
--color-frame-selected-bg: rgb(255 255 255 / 0.7); --color-frame-selected-bg: rgb(255 255 255 / 0.7);
--color-widget-slight: rgb(255 255 255 / 0.06);
--color-widget: rgb(255 255 255 / 0.12); --color-widget: rgb(255 255 255 / 0.12);
--color-widget-focus: rgb(255 255 255 / 0.25); --color-widget-focus: rgb(255 255 255 / 0.25);
--color-widget-selected: rgb(255 255 255 / 0.58); --color-widget-selected: rgb(255 255 255 / 0.58);

View File

@ -1,6 +1,6 @@
<script setup lang="ts"> <script setup lang="ts">
import { usePointer } from '@/composables/events' import { usePointer } from '@/composables/events'
import { computed, ref, watch, type ComponentInstance, type StyleValue } from 'vue' import { computed, ref, watch, type CSSProperties, type ComponentInstance } from 'vue'
import AutoSizedInput from './AutoSizedInput.vue' import AutoSizedInput from './AutoSizedInput.vue'
const props = defineProps<{ const props = defineProps<{
@ -60,7 +60,7 @@ const sliderWidth = computed(() => {
const inputComponent = ref<ComponentInstance<typeof AutoSizedInput>>() const inputComponent = ref<ComponentInstance<typeof AutoSizedInput>>()
const MIN_CONTENT_WIDTH = 56 const MIN_CONTENT_WIDTH = 56
const inputStyle = computed<StyleValue>(() => { const inputStyle = computed<CSSProperties>(() => {
const value = `${editedValue.value}` const value = `${editedValue.value}`
const dotIdx = value.indexOf('.') const dotIdx = value.indexOf('.')
let indent = 0 let indent = 0
@ -109,20 +109,19 @@ defineExpose({
</script> </script>
<template> <template>
<label class="NumericInputWidget"> <AutoSizedInput
<div v-if="props.limits != null" class="slider" :style="{ width: sliderWidth }"></div> ref="inputComponent"
<AutoSizedInput v-model="editedValue"
ref="inputComponent" autoSelect
v-model="editedValue" class="NumericInputWidget"
autoSelect :class="{ slider: sliderWidth != null }"
:style="inputStyle" :style="{ ...inputStyle, '--slider-width': sliderWidth }"
v-on="dragPointer.events" v-on="dragPointer.events"
@click.stop @click.stop
@blur="blurred" @blur="blurred"
@focus="focused" @focus="focused"
@input="emit('input', editedValue)" @input="emit('input', editedValue)"
/> />
</label>
</template> </template>
<style scoped> <style scoped>
@ -130,22 +129,24 @@ defineExpose({
position: relative; position: relative;
overflow: clip; overflow: clip;
border-radius: var(--radius-full); border-radius: var(--radius-full);
}
.AutoSizedInput {
user-select: none; user-select: none;
padding: 0 4px;
background: var(--color-widget); background: var(--color-widget);
border-radius: var(--radius-full);
overflow: clip;
padding: 0px 4px;
&:focus { &:focus {
background: var(--color-widget-focus); background: var(--color-widget-focus);
} }
} }
.slider { .NumericInputWidget.slider {
position: absolute; &:focus {
height: 100%; /* Color will be blended with background defined below. */
left: 0; background-color: var(--color-widget);
background: var(--color-widget); }
background: linear-gradient(
to right,
var(--color-widget-focus) 0 calc(var(--slider-width) - 1px),
var(--color-widget-slight) calc(var(--slider-width) - 1px) var(--slider-width),
var(--color-widget) var(--slider-width) 100%
);
} }
</style> </style>