@prefecthq/prefect-ui-library
Version:
This library is the Vue and Typescript component library for [Prefect 2](https://github.com/PrefectHQ/prefect) and [Prefect Cloud 2](https://www.prefect.io/cloud/). _The components and utilities in this project are not meant to be used independently_.
42 lines (32 loc) • 1.06 kB
text/typescript
import { PNumberInput, PCombobox } from '@prefecthq/prefect-design'
import { SchemaPropertyService } from '@/services/schemas/properties/SchemaPropertyService'
import { SchemaPropertyComponentWithProps } from '@/services/schemas/utilities'
import { SchemaPropertyInputAttrs, SchemaValue } from '@/types/schemas'
export class SchemaPropertyNumber extends SchemaPropertyService {
protected get default(): unknown {
return this.property.default ?? null
}
protected override get component(): SchemaPropertyComponentWithProps {
if (this.has('enum')) {
return this.withProps(PCombobox, {
options: this.getSelectOptions(),
})
}
return this.withProps(PNumberInput)
}
protected get attrs(): SchemaPropertyInputAttrs {
return {
step: 'any',
}
}
protected request(value: SchemaValue): unknown {
return value
}
protected response(value: SchemaValue): unknown {
const result = parseFloat(value as string)
if (isNaN(result)) {
return this.invalid()
}
return result
}
}