Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[aform] add AQuantity component #79

Draft
wants to merge 13 commits into
base: development
Choose a base branch
from
4 changes: 2 additions & 2 deletions aform/src/components/form/ADropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{{ result }}
</li>
</ul>
<label>{{ label }}</label>
<label v-if="label">{{ label }}</label>
</div>
</div>
</template>
Expand Down Expand Up @@ -119,7 +119,7 @@ const onEnter = () => {
// }
</script>

<style>
<style scoped>
/* variables taken from here: https://github.com/frappe/frappe/blob/version-13/frappe/public/scss/common/awesomeplete.scss */
.autocomplete {
position: relative;
Expand Down
102 changes: 102 additions & 0 deletions aform/src/components/form/AQuantity.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<template>
<div class="input-group">
<label :for="uuid">{{ label }}</label>
<input
v-model="values.quantity"
v-bind="values"
type="number"
:id="uuid"
:disabled="readonly"
:required="required" />

<ADropdown v-if="values.uom" v-model="values.uom" label="" :items="values.uoms" class="input-group-append">
</ADropdown>

<p v-show="validation.errorMessage" v-html="validation.errorMessage"></p>
</div>
</template>

<script setup lang="ts">
import type { Quantity } from '@/types/quantity'
import ADropdown from './ADropdown.vue'

const {
label,
required,
readonly,
uuid,
validation = { errorMessage: '' },
} = defineProps<{
label: string
required?: boolean
readonly?: boolean
uuid?: string
validation?: Record<string, any>
}>()

const values = defineModel<Quantity>({ default: { quantity: 0 } })

// TODO: use stock quantity in template
// const stockQty = computed(() => {
// return props.modelValue.quantity * props.modelValue.conversionFactor
// })
</script>

<style scoped>
.input-group {
display: flex;
flex-direction: row;
align-items: baseline;
}

div {
min-width: 40ch;
border: 1px solid transparent;
padding: 0rem;
margin: 0rem;
margin-right: 1ch;
}

input {
width: 100%;
outline: 1px solid transparent;
border: 1px solid var(--input-border-color);
padding: 1ch 0.5ch 0.5ch 1ch;
margin: calc(1.15rem / 2) 0 0 0;
min-height: 1.15rem;
}

p,
label {
color: var(--input-label-color);
display: block;
min-height: 1.15rem;
padding: 0rem;
margin: 0rem;
border: 1px solid transparent;
margin-bottom: 0.25rem;
}

p {
width: 100%;
color: red;
font-size: 85%;
}

label {
z-index: 2;
font-size: 80%;
position: absolute;
background: white;
margin-left: 1ch;
padding: 0 0.25ch 0 0.25ch;
}

input:focus {
border: 1px solid var(--input-active-border-color);
}

input:focus + label {
color: var(--input-active-label-color);
}
</style>
5 changes: 4 additions & 1 deletion aform/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import AFieldset from '@/components/form/AFieldset.vue'
import AFileAttach from '@/components/form/AFileAttach.vue'
import AForm from '@/components/AForm.vue'
import ANumericInput from '@/components/form/ANumericInput.vue'
import AQuantity from '@/components/form/AQuantity.vue'
import ATextInput from '@/components/form/ATextInput.vue'
import Login from '@/components/utilities/Login.vue'
export type { BasicSchema, FormSchema, TableSchema, FieldsetSchema, SchemaTypes } from '@/types'
Expand All @@ -30,6 +31,7 @@ function install(app: App /* options */) {
app.component('AFileAttach', AFileAttach)
app.component('AForm', AForm)
app.component('ANumericInput', ANumericInput)
app.component('AQuantity', AQuantity)
app.component('ATextInput', ATextInput)
// app.component('ACurrency', ACurrency)
// app.component('AQuantity', AQuantity)
Expand All @@ -39,12 +41,13 @@ export {
ACheckbox,
AComboBox,
ADate,
ADropdown,
ADatePicker,
ADropdown,
AFieldset,
AFileAttach,
AForm,
ANumericInput,
AQuantity,
ATextInput,
Login,
install,
Expand Down
10 changes: 10 additions & 0 deletions aform/src/types/quantity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { InputHTMLAttributes } from 'vue'

export interface Quantity extends InputHTMLAttributes {
quantity: number

conversionFactor?: number
stockUom?: string
uom?: string
uoms?: string[]
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json",
"plugins": [
{
"pluginName": "rush-sort-package-json",
"description": "Rush plugin for sort package.json file in the project",
"commandLineJsonFilePath": "command-line.json"
}
]
}
{
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json",
"plugins": [
{
"pluginName": "rush-sort-package-json",
"description": "Rush plugin for sort package.json file in the project",
"commandLineJsonFilePath": "command-line.json"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json",
"commands": [
{
"name": "sort-package-json",
"commandKind": "global",
"summary": "Rush plugin for sort package.json file in the project",
"shellCommand": "node <packageFolder>/lib/index.js",
"safeForSimultaneousRushProcesses": true
}
]
}
{
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json",
"commands": [
{
"name": "sort-package-json",
"commandKind": "global",
"summary": "Rush plugin for sort package.json file in the project",
"shellCommand": "node <packageFolder>/lib/index.js",
"safeForSimultaneousRushProcesses": true
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@stonecrop/aform",
"comment": "add AQuantity component",
"type": "patch"
}
],
"packageName": "@stonecrop/aform"
}
3 changes: 3 additions & 0 deletions common/reviews/api/aform.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import AFileAttach from '@/components/form/AFileAttach.vue';
import AForm from '@/components/AForm.vue';
import ANumericInput from '@/components/form/ANumericInput.vue';
import { App } from 'vue';
import AQuantity from '@/components/form/AQuantity.vue';
import ATextInput from '@/components/form/ATextInput.vue';
import { BasicSchema } from '@/types';
import { FieldsetSchema } from '@/types';
Expand All @@ -40,6 +41,8 @@ export { AForm }

export { ANumericInput }

export { AQuantity }

export { ATextInput }

export { BasicSchema }
Expand Down
11 changes: 11 additions & 0 deletions examples/aform/assets/basic_form_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
"component": "ANumericInput",
"label": "Age"
},
{
"fieldname": "height",
"component": "AQuantity",
"label": "Height",
"value": {
"quantity": 150,
"uom": "cm",
"uoms": ["cm", "inch", "feet"],
"min": 0
}
},
{
"fieldname": "date",
"fieldtype": "Date",
Expand Down
Loading