-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Cole Blanchard <cblanchard@Cole-Blanchards-MacBook-Pro.local>
- Loading branch information
Showing
4 changed files
with
151 additions
and
1 deletion.
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
97 changes: 97 additions & 0 deletions
97
packages/client/hmi-client/src/components/widgets/tera-input-field.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,97 @@ | ||
<template> | ||
<div :class="{ error: errorMessage }" @click.self.stop="focusInput"> | ||
<label @click.self.stop="focusInput">{{ label }}</label> | ||
<input | ||
v-bind="attrs" | ||
ref="inputField" | ||
:value="modelValue" | ||
@input="updateValue" | ||
:style="{ 'text-align': textAlign }" | ||
/> | ||
</div> | ||
<aside v-if="errorMessage"><i class="pi pi-exclamation-circle" /> {{ errorMessage }}</aside> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed, ref, useAttrs } from 'vue'; | ||
defineProps<{ | ||
modelValue: string; | ||
label?: string; | ||
errorMessage?: string; | ||
}>(); | ||
const emit = defineEmits(['update:modelValue']); | ||
const inputField = ref<HTMLInputElement | null>(null); | ||
const attrs = useAttrs(); | ||
const textAlign = computed(() => (attrs.type === 'number' ? 'right' : 'left')); | ||
const focusInput = () => { | ||
inputField.value?.focus(); | ||
}; | ||
const updateValue = (event: Event) => { | ||
const value = (event.target as HTMLInputElement).value; | ||
emit('update:modelValue', value); | ||
}; | ||
</script> | ||
|
||
<style scoped> | ||
div { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
width: 100%; | ||
padding: var(--gap-xsmall) var(--gap-small); | ||
background-color: var(--surface-section); | ||
border: 1px solid var(--surface-border-alt); | ||
border-radius: var(--border-radius-small); | ||
cursor: text; | ||
margin-bottom: var(--gap-small); | ||
transition: border-color 0.3s ease-in-out; | ||
font-family: var(--font-family); | ||
&:has(*:disabled) { | ||
opacity: 0.5; | ||
} | ||
&:has(*:focus) { | ||
border-color: var(--primary-color); | ||
} | ||
&.error { | ||
border-color: var(--error-border-color); | ||
} | ||
input { | ||
min-width: 0; | ||
} | ||
} | ||
label { | ||
background-color: none; | ||
color: var(--text-color-secondary); | ||
cursor: text; | ||
padding-right: var(--gap-small); | ||
} | ||
input { | ||
flex-grow: 1; | ||
border: none; | ||
background-color: none; | ||
&::-webkit-inner-spin-button, | ||
&::-webkit-outer-spin-button { | ||
-webkit-appearance: none; | ||
margin: 0; | ||
} | ||
} | ||
aside { | ||
color: var(--error-message-color); | ||
font-size: var(--font-caption); | ||
word-wrap: break-word; | ||
display: flex; | ||
align-items: center; | ||
i { | ||
margin-right: var(--gap-small); | ||
} | ||
} | ||
</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
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,46 @@ | ||
<template> | ||
<div class="flex flex-column pl-8 gap-5"> | ||
<div class="w-2"> | ||
<label>normal input</label> | ||
<tera-input-field v-model="teststring" label="Label" /> | ||
</div> | ||
|
||
<div class="w-2"> | ||
<label>Error input</label> | ||
<tera-input-field | ||
label="Label" | ||
:error-message="errormessage" | ||
v-model="errorstring" | ||
@update:model-value="onUpdate" | ||
/> | ||
</div> | ||
|
||
<div class="w-2"> | ||
<label>Disabled input</label> | ||
<tera-input-field label="Label" model-value="Disabled" disabled /> | ||
</div> | ||
|
||
<div class="w-2"> | ||
<label>Number input</label> | ||
<tera-input-field label="Label" v-model="numberstring" type="number" /> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import teraInputField from '@/components/widgets/tera-input-field.vue'; | ||
import { ref } from 'vue'; | ||
const teststring = ref<string>(''); | ||
const numberstring = ref<string>(''); | ||
const errorstring = ref<string>('Error message error message'); | ||
const errormessage = ref<string>('Error message error message'); | ||
function onUpdate(value: string) { | ||
if (value) { | ||
errormessage.value = 'Error message error message'; | ||
} else { | ||
errormessage.value = ''; | ||
} | ||
} | ||
</script> |