diff --git a/CHANGELOG.md b/CHANGELOG.md index f1e3819..fd61a1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.5.21 + +- `InputConfig`: + - Added field `precision`. + - Added support for type `decimal`. + ## 2.5.20 - `UIComponent`: diff --git a/lib/src/bones_ui.dart b/lib/src/bones_ui.dart index 06e2e8e..538c69b 100644 --- a/lib/src/bones_ui.dart +++ b/lib/src/bones_ui.dart @@ -1,3 +1,3 @@ class BonesUI { - static const String version = '2.5.20'; + static const String version = '2.5.21'; } diff --git a/lib/src/component/input_config.dart b/lib/src/component/input_config.dart index 5928c29..8f54df8 100644 --- a/lib/src/component/input_config.dart +++ b/lib/src/component/input_config.dart @@ -36,6 +36,7 @@ class InputConfig { final String _type; String? value; final bool? checked; + final int? precision; final String? _placeholder; final Map? _attributes; final Map? _options; @@ -75,6 +76,7 @@ class InputConfig { var type = parseString(findKeyValue(config, ['type'], true), 'text'); var value = parseString(findKeyValue(config, ['value'], true), ''); var checked = parseBool(findKeyValue(config, ['checked'], true)); + var precision = parseInt(findKeyValue(config, ['precision'], true)); var attributes = findKeyValue(config, ['attributes'], true); var classes = findKeyValue(config, ['class', 'classes'], true); var labelStyle = findKeyValue(config, ['labelStyle'], true); @@ -96,6 +98,7 @@ class InputConfig { type: type, value: value, checked: checked, + precision: precision, attributes: attributes, options: options, optional: optional, @@ -114,6 +117,7 @@ class InputConfig { String? type = 'text', String? value = '', this.checked, + this.precision, String? placeholder = '', Map? attributes, Map? options, @@ -259,6 +263,8 @@ class InputConfig { } } else if (inputType == 'textarea') { inputElement = _renderTextArea(inputValue); + } else if (inputType == 'decimal') { + inputElement = _renderDecimal(inputValue); } else if (inputType == 'select') { inputElement = _renderSelect(inputValue); } else if (inputType == 'image') { @@ -405,6 +411,34 @@ class InputConfig { return textArea; } + InputElement _renderDecimal(Object? inputValue) { + var valText = _resolveValueText(inputValue); + + var input = InputElement() + ..type = 'number' + ..value = valText ?? '' + ..style.width = '100%'; + + var precision = this.precision; + if (precision != null) { + String step; + + if (precision == 0) { + step = '1'; + } else if (precision == 1) { + step = '0.1'; + } else if (precision >= 2) { + step = '0.${'0' * (precision - 1)}1'; + } else { + step = 'any'; + } + + input.step = step; + } + + return input; + } + Element _renderGenericInput(String? inputType, Object? inputValue) { var valText = _resolveValueText(inputValue); diff --git a/pubspec.yaml b/pubspec.yaml index 946102f..e1460e6 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: bones_ui description: Bones_UI - An intuitive and user-friendly Web User Interface framework for Dart. -version: 2.5.20 +version: 2.5.21 homepage: https://github.com/Colossus-Services/bones_ui environment: