@itwin/components-react 4.10.0 → 4.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -1
- package/lib/cjs/components-react/UiComponents.d.ts +1 -1
- package/lib/cjs/components-react/UiComponents.js +2 -4
- package/lib/cjs/components-react/UiComponents.js.map +1 -1
- package/lib/cjs/components-react/common/DelayedSpinner.js +3 -2
- package/lib/cjs/components-react/common/DelayedSpinner.js.map +1 -1
- package/lib/cjs/components-react/common/UseDebouncedAsyncValue.js +2 -1
- package/lib/cjs/components-react/common/UseDebouncedAsyncValue.js.map +1 -1
- package/lib/cjs/components-react/converters/NumericTypeConverter.js +4 -2
- package/lib/cjs/components-react/converters/NumericTypeConverter.js.map +1 -1
- package/lib/cjs/components-react/converters/TypeConverter.js +2 -1
- package/lib/cjs/components-react/converters/TypeConverter.js.map +1 -1
- package/lib/cjs/components-react/datepicker/DatePicker.d.ts +2 -0
- package/lib/cjs/components-react/datepicker/DatePicker.d.ts.map +1 -1
- package/lib/cjs/components-react/datepicker/DatePicker.js +43 -40
- package/lib/cjs/components-react/datepicker/DatePicker.js.map +1 -1
- package/lib/cjs/components-react/datepicker/DatePickerPopupButton.d.ts +5 -2
- package/lib/cjs/components-react/datepicker/DatePickerPopupButton.d.ts.map +1 -1
- package/lib/cjs/components-react/datepicker/DatePickerPopupButton.js +8 -7
- package/lib/cjs/components-react/datepicker/DatePickerPopupButton.js.map +1 -1
- package/lib/cjs/components-react/datepicker/IntlFormatter.d.ts +1 -0
- package/lib/cjs/components-react/datepicker/IntlFormatter.d.ts.map +1 -1
- package/lib/cjs/components-react/datepicker/IntlFormatter.js +1 -0
- package/lib/cjs/components-react/datepicker/IntlFormatter.js.map +1 -1
- package/lib/cjs/components-react/datepicker/TimeField.d.ts.map +1 -1
- package/lib/cjs/components-react/datepicker/TimeField.js +28 -30
- package/lib/cjs/components-react/datepicker/TimeField.js.map +1 -1
- package/lib/cjs/components-react/editors/CustomNumberEditor.js +8 -6
- package/lib/cjs/components-react/editors/CustomNumberEditor.js.map +1 -1
- package/lib/cjs/components-react/editors/DateTimeEditor.js +5 -3
- package/lib/cjs/components-react/editors/DateTimeEditor.js.map +1 -1
- package/lib/cjs/components-react/editors/EnumEditor.d.ts +0 -1
- package/lib/cjs/components-react/editors/EnumEditor.d.ts.map +1 -1
- package/lib/cjs/components-react/editors/EnumEditor.js +2 -3
- package/lib/cjs/components-react/editors/EnumEditor.js.map +1 -1
- package/lib/cjs/components-react/editors/PopupButton.d.ts.map +1 -1
- package/lib/cjs/components-react/editors/PopupButton.js +8 -5
- package/lib/cjs/components-react/editors/PopupButton.js.map +1 -1
- package/lib/cjs/components-react/editors/TextEditor.d.ts +0 -1
- package/lib/cjs/components-react/editors/TextEditor.d.ts.map +1 -1
- package/lib/cjs/components-react/editors/TextEditor.js +5 -4
- package/lib/cjs/components-react/editors/TextEditor.js.map +1 -1
- package/lib/cjs/components-react/editors/TextareaEditor.d.ts +0 -1
- package/lib/cjs/components-react/editors/TextareaEditor.d.ts.map +1 -1
- package/lib/cjs/components-react/editors/TextareaEditor.js +1 -2
- package/lib/cjs/components-react/editors/TextareaEditor.js.map +1 -1
- package/lib/cjs/components-react/favorite/FavoritePropertyList.js +3 -3
- package/lib/cjs/components-react/favorite/FavoritePropertyList.js.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderLogicalOperator.d.ts.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderLogicalOperator.js +4 -3
- package/lib/cjs/components-react/filter-builder/FilterBuilderLogicalOperator.js.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleOperator.js +2 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleOperator.js.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleProperty.d.ts.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleProperty.js +6 -5
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleProperty.js.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleValue.js +4 -3
- package/lib/cjs/components-react/filter-builder/FilterBuilderRuleValue.js.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderState.js +3 -3
- package/lib/cjs/components-react/filter-builder/FilterBuilderState.js.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderToolbar.d.ts.map +1 -1
- package/lib/cjs/components-react/filter-builder/FilterBuilderToolbar.js +4 -3
- package/lib/cjs/components-react/filter-builder/FilterBuilderToolbar.js.map +1 -1
- package/lib/cjs/components-react/filtering/FilteringInput.d.ts +0 -3
- package/lib/cjs/components-react/filtering/FilteringInput.d.ts.map +1 -1
- package/lib/cjs/components-react/filtering/FilteringInput.js +5 -7
- package/lib/cjs/components-react/filtering/FilteringInput.js.map +1 -1
- package/lib/cjs/components-react/filtering/ResultSelector.d.ts +0 -1
- package/lib/cjs/components-react/filtering/ResultSelector.d.ts.map +1 -1
- package/lib/cjs/components-react/filtering/ResultSelector.js +1 -2
- package/lib/cjs/components-react/filtering/ResultSelector.js.map +1 -1
- package/lib/cjs/components-react/properties/ValueRendererManager.d.ts +3 -0
- package/lib/cjs/components-react/properties/ValueRendererManager.d.ts.map +1 -1
- package/lib/cjs/components-react/properties/ValueRendererManager.js +12 -1
- package/lib/cjs/components-react/properties/ValueRendererManager.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/CommonPropertyRenderer.js +4 -3
- package/lib/cjs/components-react/properties/renderers/CommonPropertyRenderer.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/CustomizablePropertyRenderer.d.ts +25 -0
- package/lib/cjs/components-react/properties/renderers/CustomizablePropertyRenderer.d.ts.map +1 -0
- package/lib/cjs/components-react/properties/renderers/CustomizablePropertyRenderer.js +62 -0
- package/lib/cjs/components-react/properties/renderers/CustomizablePropertyRenderer.js.map +1 -0
- package/lib/cjs/components-react/properties/renderers/NonPrimitivePropertyRenderer.js +1 -1
- package/lib/cjs/components-react/properties/renderers/NonPrimitivePropertyRenderer.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/PrimitivePropertyRenderer.d.ts +3 -4
- package/lib/cjs/components-react/properties/renderers/PrimitivePropertyRenderer.d.ts.map +1 -1
- package/lib/cjs/components-react/properties/renderers/PrimitivePropertyRenderer.js +6 -44
- package/lib/cjs/components-react/properties/renderers/PrimitivePropertyRenderer.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/PropertyView.d.ts +1 -1
- package/lib/cjs/components-react/properties/renderers/PropertyView.d.ts.map +1 -1
- package/lib/cjs/components-react/properties/renderers/PropertyView.js +2 -3
- package/lib/cjs/components-react/properties/renderers/PropertyView.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/label/PropertyLabelRenderer.js +4 -4
- package/lib/cjs/components-react/properties/renderers/label/PropertyLabelRenderer.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/value/Common.js +2 -1
- package/lib/cjs/components-react/properties/renderers/value/Common.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/value/MultilineTextPropertyValueRenderer.d.ts.map +1 -1
- package/lib/cjs/components-react/properties/renderers/value/MultilineTextPropertyValueRenderer.js +8 -11
- package/lib/cjs/components-react/properties/renderers/value/MultilineTextPropertyValueRenderer.js.map +1 -1
- package/lib/cjs/components-react/properties/renderers/value/PrimitivePropertyValueRenderer.js +6 -3
- package/lib/cjs/components-react/properties/renderers/value/PrimitivePropertyValueRenderer.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/PropertyCategoryRendererManager.js +2 -1
- package/lib/cjs/components-react/propertygrid/PropertyCategoryRendererManager.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/component/ColumnResizingPropertyListPropsSupplier.js +2 -1
- package/lib/cjs/components-react/propertygrid/component/ColumnResizingPropertyListPropsSupplier.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/component/PropertyCategoryBlock.js +2 -1
- package/lib/cjs/components-react/propertygrid/component/PropertyCategoryBlock.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/component/PropertyGridCommons.js +2 -2
- package/lib/cjs/components-react/propertygrid/component/PropertyGridCommons.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/component/PropertyGridEventsRelatedPropsSupplier.d.ts.map +1 -1
- package/lib/cjs/components-react/propertygrid/component/PropertyGridEventsRelatedPropsSupplier.js +1 -3
- package/lib/cjs/components-react/propertygrid/component/PropertyGridEventsRelatedPropsSupplier.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/component/VirtualizedPropertyGrid.d.ts +1 -3
- package/lib/cjs/components-react/propertygrid/component/VirtualizedPropertyGrid.d.ts.map +1 -1
- package/lib/cjs/components-react/propertygrid/component/VirtualizedPropertyGrid.js +90 -80
- package/lib/cjs/components-react/propertygrid/component/VirtualizedPropertyGrid.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/dataproviders/FilteringDataProvider.js +13 -11
- package/lib/cjs/components-react/propertygrid/dataproviders/FilteringDataProvider.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/dataproviders/filterers/CompositePropertyDataFilterer.js +2 -2
- package/lib/cjs/components-react/propertygrid/dataproviders/filterers/CompositePropertyDataFilterer.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/dataproviders/filterers/DisplayValuePropertyDataFilterer.js +2 -1
- package/lib/cjs/components-react/propertygrid/dataproviders/filterers/DisplayValuePropertyDataFilterer.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-items/MutableCustomGridCategory.js +2 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-items/MutableCustomGridCategory.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-items/MutableFlatGridItem.js +2 -2
- package/lib/cjs/components-react/propertygrid/internal/flat-items/MutableFlatGridItem.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-items/MutableGridCategory.js +3 -2
- package/lib/cjs/components-react/propertygrid/internal/flat-items/MutableGridCategory.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-items/MutableGridItemFactory.js +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-items/MutableGridItemFactory.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-properties/FlatNonPrimitivePropertyRenderer.js +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-properties/FlatNonPrimitivePropertyRenderer.js.map +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-properties/FlatPropertyRenderer.d.ts +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-properties/FlatPropertyRenderer.d.ts.map +1 -1
- package/lib/cjs/components-react/propertygrid/internal/flat-properties/FlatPropertyRenderer.js +22 -12
- package/lib/cjs/components-react/propertygrid/internal/flat-properties/FlatPropertyRenderer.js.map +1 -1
- package/lib/cjs/components-react/selectable-content/SelectableContent.js +3 -2
- package/lib/cjs/components-react/selectable-content/SelectableContent.js.map +1 -1
- package/lib/cjs/components-react/toolbar/InternalToolbarComponent.d.ts.map +1 -1
- package/lib/cjs/components-react/toolbar/InternalToolbarComponent.js +15 -14
- package/lib/cjs/components-react/toolbar/InternalToolbarComponent.js.map +1 -1
- package/lib/cjs/components-react/toolbar/useConditionalSynchedItems.js +6 -5
- package/lib/cjs/components-react/toolbar/useConditionalSynchedItems.js.map +1 -1
- package/lib/cjs/components-react/tree/controlled/TreeModel.js +8 -7
- package/lib/cjs/components-react/tree/controlled/TreeModel.js.map +1 -1
- package/lib/cjs/components-react/tree/controlled/TreeNodeLoader.js +8 -6
- package/lib/cjs/components-react/tree/controlled/TreeNodeLoader.js.map +1 -1
- package/lib/cjs/components-react/tree/controlled/component/ControlledTree.d.ts.map +1 -1
- package/lib/cjs/components-react/tree/controlled/component/ControlledTree.js +3 -2
- package/lib/cjs/components-react/tree/controlled/component/ControlledTree.js.map +1 -1
- package/lib/cjs/components-react/tree/controlled/internal/SparseTree.js +2 -1
- package/lib/cjs/components-react/tree/controlled/internal/SparseTree.js.map +1 -1
- package/lib/cjs/components-react/tree/controlled/internal/TreeSelectionManager.js +4 -2
- package/lib/cjs/components-react/tree/controlled/internal/TreeSelectionManager.js.map +1 -1
- package/lib/cjs/components-react/useTranslation.d.ts +10 -0
- package/lib/cjs/components-react/useTranslation.d.ts.map +1 -0
- package/lib/cjs/components-react/useTranslation.js +20 -0
- package/lib/cjs/components-react/useTranslation.js.map +1 -0
- package/lib/cjs/components-react.d.ts +1 -0
- package/lib/cjs/components-react.d.ts.map +1 -1
- package/lib/cjs/components-react.js +1 -0
- package/lib/cjs/components-react.js.map +1 -1
- package/lib/esm/components-react/UiComponents.d.ts +1 -1
- package/lib/esm/components-react/UiComponents.js +2 -4
- package/lib/esm/components-react/UiComponents.js.map +1 -1
- package/lib/esm/components-react/common/DelayedSpinner.js +3 -2
- package/lib/esm/components-react/common/DelayedSpinner.js.map +1 -1
- package/lib/esm/components-react/common/UseDebouncedAsyncValue.js +2 -1
- package/lib/esm/components-react/common/UseDebouncedAsyncValue.js.map +1 -1
- package/lib/esm/components-react/converters/NumericTypeConverter.js +4 -2
- package/lib/esm/components-react/converters/NumericTypeConverter.js.map +1 -1
- package/lib/esm/components-react/converters/TypeConverter.js +2 -1
- package/lib/esm/components-react/converters/TypeConverter.js.map +1 -1
- package/lib/esm/components-react/datepicker/DatePicker.d.ts +2 -0
- package/lib/esm/components-react/datepicker/DatePicker.d.ts.map +1 -1
- package/lib/esm/components-react/datepicker/DatePicker.js +43 -40
- package/lib/esm/components-react/datepicker/DatePicker.js.map +1 -1
- package/lib/esm/components-react/datepicker/DatePickerPopupButton.d.ts +5 -2
- package/lib/esm/components-react/datepicker/DatePickerPopupButton.d.ts.map +1 -1
- package/lib/esm/components-react/datepicker/DatePickerPopupButton.js +8 -7
- package/lib/esm/components-react/datepicker/DatePickerPopupButton.js.map +1 -1
- package/lib/esm/components-react/datepicker/IntlFormatter.d.ts +1 -0
- package/lib/esm/components-react/datepicker/IntlFormatter.d.ts.map +1 -1
- package/lib/esm/components-react/datepicker/IntlFormatter.js +1 -0
- package/lib/esm/components-react/datepicker/IntlFormatter.js.map +1 -1
- package/lib/esm/components-react/datepicker/TimeField.d.ts.map +1 -1
- package/lib/esm/components-react/datepicker/TimeField.js +28 -30
- package/lib/esm/components-react/datepicker/TimeField.js.map +1 -1
- package/lib/esm/components-react/editors/CustomNumberEditor.js +8 -6
- package/lib/esm/components-react/editors/CustomNumberEditor.js.map +1 -1
- package/lib/esm/components-react/editors/DateTimeEditor.js +5 -3
- package/lib/esm/components-react/editors/DateTimeEditor.js.map +1 -1
- package/lib/esm/components-react/editors/EnumEditor.d.ts +0 -1
- package/lib/esm/components-react/editors/EnumEditor.d.ts.map +1 -1
- package/lib/esm/components-react/editors/EnumEditor.js +2 -3
- package/lib/esm/components-react/editors/EnumEditor.js.map +1 -1
- package/lib/esm/components-react/editors/PopupButton.d.ts.map +1 -1
- package/lib/esm/components-react/editors/PopupButton.js +9 -6
- package/lib/esm/components-react/editors/PopupButton.js.map +1 -1
- package/lib/esm/components-react/editors/TextEditor.d.ts +0 -1
- package/lib/esm/components-react/editors/TextEditor.d.ts.map +1 -1
- package/lib/esm/components-react/editors/TextEditor.js +5 -4
- package/lib/esm/components-react/editors/TextEditor.js.map +1 -1
- package/lib/esm/components-react/editors/TextareaEditor.d.ts +0 -1
- package/lib/esm/components-react/editors/TextareaEditor.d.ts.map +1 -1
- package/lib/esm/components-react/editors/TextareaEditor.js +1 -2
- package/lib/esm/components-react/editors/TextareaEditor.js.map +1 -1
- package/lib/esm/components-react/favorite/FavoritePropertyList.js +3 -3
- package/lib/esm/components-react/favorite/FavoritePropertyList.js.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderLogicalOperator.d.ts.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderLogicalOperator.js +4 -3
- package/lib/esm/components-react/filter-builder/FilterBuilderLogicalOperator.js.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleOperator.js +2 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleOperator.js.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleProperty.d.ts.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleProperty.js +6 -5
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleProperty.js.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleValue.js +4 -3
- package/lib/esm/components-react/filter-builder/FilterBuilderRuleValue.js.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderState.js +3 -3
- package/lib/esm/components-react/filter-builder/FilterBuilderState.js.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderToolbar.d.ts.map +1 -1
- package/lib/esm/components-react/filter-builder/FilterBuilderToolbar.js +4 -3
- package/lib/esm/components-react/filter-builder/FilterBuilderToolbar.js.map +1 -1
- package/lib/esm/components-react/filtering/FilteringInput.d.ts +0 -3
- package/lib/esm/components-react/filtering/FilteringInput.d.ts.map +1 -1
- package/lib/esm/components-react/filtering/FilteringInput.js +6 -8
- package/lib/esm/components-react/filtering/FilteringInput.js.map +1 -1
- package/lib/esm/components-react/filtering/ResultSelector.d.ts +0 -1
- package/lib/esm/components-react/filtering/ResultSelector.d.ts.map +1 -1
- package/lib/esm/components-react/filtering/ResultSelector.js +1 -2
- package/lib/esm/components-react/filtering/ResultSelector.js.map +1 -1
- package/lib/esm/components-react/properties/ValueRendererManager.d.ts +3 -0
- package/lib/esm/components-react/properties/ValueRendererManager.d.ts.map +1 -1
- package/lib/esm/components-react/properties/ValueRendererManager.js +12 -1
- package/lib/esm/components-react/properties/ValueRendererManager.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/CommonPropertyRenderer.js +4 -3
- package/lib/esm/components-react/properties/renderers/CommonPropertyRenderer.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/CustomizablePropertyRenderer.d.ts +25 -0
- package/lib/esm/components-react/properties/renderers/CustomizablePropertyRenderer.d.ts.map +1 -0
- package/lib/esm/components-react/properties/renderers/CustomizablePropertyRenderer.js +35 -0
- package/lib/esm/components-react/properties/renderers/CustomizablePropertyRenderer.js.map +1 -0
- package/lib/esm/components-react/properties/renderers/NonPrimitivePropertyRenderer.js +1 -1
- package/lib/esm/components-react/properties/renderers/NonPrimitivePropertyRenderer.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/PrimitivePropertyRenderer.d.ts +3 -4
- package/lib/esm/components-react/properties/renderers/PrimitivePropertyRenderer.d.ts.map +1 -1
- package/lib/esm/components-react/properties/renderers/PrimitivePropertyRenderer.js +3 -21
- package/lib/esm/components-react/properties/renderers/PrimitivePropertyRenderer.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/PropertyView.d.ts +1 -1
- package/lib/esm/components-react/properties/renderers/PropertyView.d.ts.map +1 -1
- package/lib/esm/components-react/properties/renderers/PropertyView.js +2 -3
- package/lib/esm/components-react/properties/renderers/PropertyView.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/label/PropertyLabelRenderer.js +4 -4
- package/lib/esm/components-react/properties/renderers/label/PropertyLabelRenderer.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/value/Common.js +2 -1
- package/lib/esm/components-react/properties/renderers/value/Common.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/value/MultilineTextPropertyValueRenderer.d.ts.map +1 -1
- package/lib/esm/components-react/properties/renderers/value/MultilineTextPropertyValueRenderer.js +8 -11
- package/lib/esm/components-react/properties/renderers/value/MultilineTextPropertyValueRenderer.js.map +1 -1
- package/lib/esm/components-react/properties/renderers/value/PrimitivePropertyValueRenderer.js +6 -3
- package/lib/esm/components-react/properties/renderers/value/PrimitivePropertyValueRenderer.js.map +1 -1
- package/lib/esm/components-react/propertygrid/PropertyCategoryRendererManager.js +2 -1
- package/lib/esm/components-react/propertygrid/PropertyCategoryRendererManager.js.map +1 -1
- package/lib/esm/components-react/propertygrid/component/ColumnResizingPropertyListPropsSupplier.js +2 -1
- package/lib/esm/components-react/propertygrid/component/ColumnResizingPropertyListPropsSupplier.js.map +1 -1
- package/lib/esm/components-react/propertygrid/component/PropertyCategoryBlock.js +2 -1
- package/lib/esm/components-react/propertygrid/component/PropertyCategoryBlock.js.map +1 -1
- package/lib/esm/components-react/propertygrid/component/PropertyGridCommons.js +2 -2
- package/lib/esm/components-react/propertygrid/component/PropertyGridCommons.js.map +1 -1
- package/lib/esm/components-react/propertygrid/component/PropertyGridEventsRelatedPropsSupplier.d.ts.map +1 -1
- package/lib/esm/components-react/propertygrid/component/PropertyGridEventsRelatedPropsSupplier.js +1 -3
- package/lib/esm/components-react/propertygrid/component/PropertyGridEventsRelatedPropsSupplier.js.map +1 -1
- package/lib/esm/components-react/propertygrid/component/VirtualizedPropertyGrid.d.ts +1 -3
- package/lib/esm/components-react/propertygrid/component/VirtualizedPropertyGrid.d.ts.map +1 -1
- package/lib/esm/components-react/propertygrid/component/VirtualizedPropertyGrid.js +90 -80
- package/lib/esm/components-react/propertygrid/component/VirtualizedPropertyGrid.js.map +1 -1
- package/lib/esm/components-react/propertygrid/dataproviders/FilteringDataProvider.js +13 -11
- package/lib/esm/components-react/propertygrid/dataproviders/FilteringDataProvider.js.map +1 -1
- package/lib/esm/components-react/propertygrid/dataproviders/filterers/CompositePropertyDataFilterer.js +2 -2
- package/lib/esm/components-react/propertygrid/dataproviders/filterers/CompositePropertyDataFilterer.js.map +1 -1
- package/lib/esm/components-react/propertygrid/dataproviders/filterers/DisplayValuePropertyDataFilterer.js +2 -1
- package/lib/esm/components-react/propertygrid/dataproviders/filterers/DisplayValuePropertyDataFilterer.js.map +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-items/MutableCustomGridCategory.js +2 -1
- package/lib/esm/components-react/propertygrid/internal/flat-items/MutableCustomGridCategory.js.map +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-items/MutableFlatGridItem.js +2 -2
- package/lib/esm/components-react/propertygrid/internal/flat-items/MutableFlatGridItem.js.map +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-items/MutableGridCategory.js +3 -2
- package/lib/esm/components-react/propertygrid/internal/flat-items/MutableGridCategory.js.map +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-items/MutableGridItemFactory.js +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-items/MutableGridItemFactory.js.map +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-properties/FlatNonPrimitivePropertyRenderer.js +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-properties/FlatNonPrimitivePropertyRenderer.js.map +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-properties/FlatPropertyRenderer.d.ts +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-properties/FlatPropertyRenderer.d.ts.map +1 -1
- package/lib/esm/components-react/propertygrid/internal/flat-properties/FlatPropertyRenderer.js +22 -12
- package/lib/esm/components-react/propertygrid/internal/flat-properties/FlatPropertyRenderer.js.map +1 -1
- package/lib/esm/components-react/selectable-content/SelectableContent.js +3 -2
- package/lib/esm/components-react/selectable-content/SelectableContent.js.map +1 -1
- package/lib/esm/components-react/toolbar/InternalToolbarComponent.d.ts.map +1 -1
- package/lib/esm/components-react/toolbar/InternalToolbarComponent.js +15 -14
- package/lib/esm/components-react/toolbar/InternalToolbarComponent.js.map +1 -1
- package/lib/esm/components-react/toolbar/useConditionalSynchedItems.js +6 -5
- package/lib/esm/components-react/toolbar/useConditionalSynchedItems.js.map +1 -1
- package/lib/esm/components-react/tree/controlled/TreeModel.js +8 -7
- package/lib/esm/components-react/tree/controlled/TreeModel.js.map +1 -1
- package/lib/esm/components-react/tree/controlled/TreeNodeLoader.js +8 -6
- package/lib/esm/components-react/tree/controlled/TreeNodeLoader.js.map +1 -1
- package/lib/esm/components-react/tree/controlled/component/ControlledTree.d.ts.map +1 -1
- package/lib/esm/components-react/tree/controlled/component/ControlledTree.js +3 -2
- package/lib/esm/components-react/tree/controlled/component/ControlledTree.js.map +1 -1
- package/lib/esm/components-react/tree/controlled/internal/SparseTree.js +2 -1
- package/lib/esm/components-react/tree/controlled/internal/SparseTree.js.map +1 -1
- package/lib/esm/components-react/tree/controlled/internal/TreeSelectionManager.js +4 -2
- package/lib/esm/components-react/tree/controlled/internal/TreeSelectionManager.js.map +1 -1
- package/lib/esm/components-react/useTranslation.d.ts +10 -0
- package/lib/esm/components-react/useTranslation.d.ts.map +1 -0
- package/lib/esm/components-react/useTranslation.js +16 -0
- package/lib/esm/components-react/useTranslation.js.map +1 -0
- package/lib/esm/components-react.d.ts +1 -0
- package/lib/esm/components-react.d.ts.map +1 -1
- package/lib/esm/components-react.js +1 -0
- package/lib/esm/components-react.js.map +1 -1
- package/lib/public/locales/en/UiComponents.json +7 -1
- package/package.json +4 -4
|
@@ -35,20 +35,20 @@ const React = __importStar(require("react"));
|
|
|
35
35
|
const appui_abstract_1 = require("@itwin/appui-abstract");
|
|
36
36
|
const core_react_1 = require("@itwin/core-react");
|
|
37
37
|
const itwinui_react_1 = require("@itwin/itwinui-react");
|
|
38
|
-
const UiComponents_1 = require("../UiComponents");
|
|
39
38
|
const DatePicker_1 = require("./DatePicker");
|
|
40
39
|
const DateField_1 = require("./DateField");
|
|
41
40
|
const TimeField_1 = require("./TimeField");
|
|
42
41
|
require("./DatePickerPopupButton.scss");
|
|
42
|
+
const useTranslation_1 = require("../useTranslation");
|
|
43
43
|
/** Component that displays a button used to pick a date and optionally a time.
|
|
44
44
|
* @alpha
|
|
45
|
-
*
|
|
45
|
+
* @deprecated in 4.11.x. Use {@link https://itwinui.bentley.com/docs/datepicker iTwinUI date picker} instead.
|
|
46
|
+
*/
|
|
46
47
|
function DatePickerPopupButton({ displayEditField, timeDisplay, selected, onDateChange, dateFormatter, buttonToolTip, fieldStyle, fieldClassName, style, }) {
|
|
48
|
+
const { translate } = (0, useTranslation_1.useTranslation)();
|
|
47
49
|
const [workingDate, setWorkingDate] = React.useState(new Date(selected.getTime()));
|
|
48
50
|
const [isSettingsOpen, setIsSettingsOpen] = React.useState(false);
|
|
49
|
-
const
|
|
50
|
-
const toolTipLabelRef = React.useRef(UiComponents_1.UiComponents.translate("datepicker.selectDate"));
|
|
51
|
-
const toolTipLabel = React.useMemo(() => (buttonToolTip ? buttonToolTip : toolTipLabelRef.current), [buttonToolTip]);
|
|
51
|
+
const toolTipLabel = buttonToolTip !== null && buttonToolTip !== void 0 ? buttonToolTip : translate("datepicker.selectDate");
|
|
52
52
|
// See if props have changed since component mounted
|
|
53
53
|
React.useEffect(() => {
|
|
54
54
|
const newWorkingDate = new Date(selected.getTime());
|
|
@@ -97,9 +97,10 @@ function DatePickerPopupButton({ displayEditField, timeDisplay, selected, onDate
|
|
|
97
97
|
React.createElement("path", { d: "M13,13H9V10h4ZM16,3V15a1,1,0,0,1-1,1H1a1,1,0,0,1-1-1V3A1,1,0,0,1,1,2H3V0H4V2h8V0h1V2h2A1,1,0,0,1,16,3ZM15,6H1v9H15Z" })))),
|
|
98
98
|
React.createElement(core_react_1.Popup, { isOpen: isSettingsOpen, position: appui_abstract_1.RelativePosition.BottomLeft, onClose: handleCloseSetting, target: buttonRef.current, closeOnEnter: false, moveFocus: showFocusOutline, closeOnNestedPopupOutsideClick: true },
|
|
99
99
|
React.createElement("div", { className: "components-date-picker-calendar-popup-panel", "data-testid": "components-date-picker-calendar-popup-panel" },
|
|
100
|
-
React.createElement(DatePicker_1.DatePicker
|
|
100
|
+
React.createElement(DatePicker_1.DatePicker // eslint-disable-line deprecation/deprecation
|
|
101
|
+
, { selected: workingDate, onDateChange: handleOnDateChanged, showFocusOutline: showFocusOutline }),
|
|
101
102
|
timeDisplay && (React.createElement("div", { className: "time-container" },
|
|
102
|
-
React.createElement(itwinui_react_1.Text, { variant: "body", className: "time-label" },
|
|
103
|
+
React.createElement(itwinui_react_1.Text, { variant: "body", className: "time-label" }, translate("datepicker.time")),
|
|
103
104
|
React.createElement(TimeField_1.TimeField, { time: timeSpec, timeDisplay: timeDisplay, onTimeChange: handleOnTimeChanged }))))),
|
|
104
105
|
!!displayEditField && (React.createElement(DateField_1.DateField, { style: fieldStyle, className: fieldClassName, initialDate: workingDate, timeDisplay: timeDisplay, dateFormatter: dateFormatter, onDateChange: handleOnDateChanged }))));
|
|
105
106
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePickerPopupButton.js","sourceRoot":"","sources":["../../../../src/components-react/datepicker/DatePickerPopupButton.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAA+B;AAE/B,0DAAyD;AAEzD,kDAA0C;AAC1C,wDAA4C;AAC5C,kDAA+C;AAC/C,6CAA0C;AAC1C,2CAAwC;AAExC,2CAAwC;AACxC,wCAAsC;AAwBtC;;KAEK;AACL,SAAgB,qBAAqB,CAAC,EACpC,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,aAAa,EACb,UAAU,EACV,cAAc,EACd,KAAK,GACsB;IAC3B,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,KAAK,CAAC,QAAQ,CAClD,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAC7B,CAAC;IACF,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClE,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,2BAAY,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC7E,MAAM,eAAe,GAAG,KAAK,CAAC,MAAM,CAClC,2BAAY,CAAC,SAAS,CAAC,uBAAuB,CAAC,CAChD,CAAC;IACF,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAChC,GAAG,EAAE,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,eAAe,CAAC,OAAO,CAAC,EAC/D,CAAC,aAAa,CAAC,CAChB,CAAC;IAEF,oDAAoD;IACpD,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,cAAc,GAAG,IAAI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9B,6BACE,SAAS,EAAC,6CAA6C,iBAC3C,6CAA6C;gBAEzD,oBAAC,uBAAU,IACT,QAAQ,EAAE,WAAW,EACrB,YAAY,EAAE,mBAAmB,EACjC,gBAAgB,EAAE,gBAAgB,GAClC;gBACD,WAAW,IAAI,CACd,6BAAK,SAAS,EAAC,gBAAgB;oBAC7B,oBAAC,oBAAI,IAAC,OAAO,EAAC,MAAM,EAAC,SAAS,EAAC,YAAY,IACxC,YAAY,CAAC,OAAO,CAChB;oBACP,oBAAC,qBAAS,IACR,IAAI,EAAE,QAAQ,EACd,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,mBAAmB,GACjC,CACE,CACP,CACG,CACA;QACP,CAAC,CAAC,gBAAgB,IAAI,CACrB,oBAAC,qBAAS,IACR,KAAK,EAAE,UAAU,EACjB,SAAS,EAAE,cAAc,EACzB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,mBAAmB,GACjC,CACH,CACA,CACJ,CAAC;AACJ,CAAC;AA9ID,sDA8IC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Date\n */\n\nimport * as React from \"react\";\nimport type { DateFormatter, TimeDisplay } from \"@itwin/appui-abstract\";\nimport { RelativePosition } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { Popup } from \"@itwin/core-react\";\nimport { Text } from \"@itwin/itwinui-react\";\nimport { UiComponents } from \"../UiComponents\";\nimport { DatePicker } from \"./DatePicker\";\nimport { DateField } from \"./DateField\";\nimport type { TimeSpec } from \"./TimeField\";\nimport { TimeField } from \"./TimeField\";\nimport \"./DatePickerPopupButton.scss\";\n\n/** Props used by [[DatePickerPopupButton]] component.\n * @alpha */\nexport interface DatePickerPopupButtonProps extends CommonProps {\n /** Date to be shown as the selected date. */\n selected: Date;\n /** If true show the date (and optionally time) edit field next to button */\n displayEditField?: boolean;\n // If defined show time in popup and also display time if input field is shown\n timeDisplay?: TimeDisplay;\n /** Function called when Date changes. */\n onDateChange?: (day: Date) => void;\n /** Optional tooltip */\n buttonToolTip?: string;\n /* Custom date formatter. WARNING: if used values will only be shown in specified format and will not be based on locale.\n * If used the existence of a parseDate function will determine if the edit field allows editing. */\n dateFormatter?: DateFormatter;\n /** User defined class name for edit field. */\n fieldClassName?: string;\n /** User defined style for edit field. */\n fieldStyle?: React.CSSProperties;\n}\n\n/** Component that displays a button used to pick a date and optionally a time.\n * @alpha\n * */\nexport function DatePickerPopupButton({\n displayEditField,\n timeDisplay,\n selected,\n onDateChange,\n dateFormatter,\n buttonToolTip,\n fieldStyle,\n fieldClassName,\n style,\n}: DatePickerPopupButtonProps) {\n const [workingDate, setWorkingDate] = React.useState(\n new Date(selected.getTime())\n );\n const [isSettingsOpen, setIsSettingsOpen] = React.useState(false);\n const timeLabelRef = React.useRef(UiComponents.translate(\"datepicker.time\"));\n const toolTipLabelRef = React.useRef(\n UiComponents.translate(\"datepicker.selectDate\")\n );\n const toolTipLabel = React.useMemo(\n () => (buttonToolTip ? buttonToolTip : toolTipLabelRef.current),\n [buttonToolTip]\n );\n\n // See if props have changed since component mounted\n React.useEffect(() => {\n const newWorkingDate = new Date(selected.getTime());\n setWorkingDate(newWorkingDate);\n }, [selected]);\n\n const buttonRef = React.useRef<HTMLButtonElement>(null);\n const togglePopupDisplay = React.useCallback(\n (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {\n event.preventDefault();\n setShowFocusOutline(false);\n setIsSettingsOpen((prev) => !prev);\n },\n [setIsSettingsOpen]\n );\n\n const handleCloseSetting = React.useCallback(() => {\n setIsSettingsOpen(false);\n }, [setIsSettingsOpen]);\n\n const handleOnDateChanged = (day: Date) => {\n // combine current time into selected Date\n const newWorkingDate = new Date(day.getTime());\n newWorkingDate.setHours(\n workingDate.getHours(),\n workingDate.getMinutes(),\n workingDate.getSeconds()\n );\n onDateChange && onDateChange(newWorkingDate);\n !timeDisplay && setIsSettingsOpen(false);\n };\n\n const handleOnTimeChanged = (time: TimeSpec) => {\n // Combine new time into selected Date\n const newWorkingDate = new Date(workingDate.getTime());\n newWorkingDate.setHours(time.hours, time.minutes, time.seconds);\n setWorkingDate(newWorkingDate);\n onDateChange && onDateChange(newWorkingDate);\n };\n\n const [showFocusOutline, setShowFocusOutline] = React.useState(false);\n const handlePopupKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLButtonElement>) => {\n // istanbul ignore else\n if (event.key === \" \") {\n setShowFocusOutline(true);\n setIsSettingsOpen(true);\n }\n },\n []\n );\n\n const timeSpec: TimeSpec = {\n hours: workingDate.getHours(),\n minutes: workingDate.getMinutes(),\n seconds: workingDate.getSeconds(),\n };\n return (\n <>\n <button\n title={toolTipLabel}\n style={style}\n className=\"components-date-picker-calendar-popup-button\"\n onKeyDown={handlePopupKeyDown}\n data-testid=\"components-date-picker-calendar-popup-button\"\n onPointerDown={togglePopupDisplay}\n ref={buttonRef}\n >\n <div className=\"datepicker-button\">\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\">\n <path d=\"M13,13H9V10h4ZM16,3V15a1,1,0,0,1-1,1H1a1,1,0,0,1-1-1V3A1,1,0,0,1,1,2H3V0H4V2h8V0h1V2h2A1,1,0,0,1,16,3ZM15,6H1v9H15Z\" />\n </svg>\n </div>\n </button>\n <Popup\n isOpen={isSettingsOpen}\n position={RelativePosition.BottomLeft}\n onClose={handleCloseSetting}\n target={buttonRef.current}\n closeOnEnter={false}\n moveFocus={showFocusOutline}\n closeOnNestedPopupOutsideClick\n >\n <div\n className=\"components-date-picker-calendar-popup-panel\"\n data-testid=\"components-date-picker-calendar-popup-panel\"\n >\n <DatePicker\n selected={workingDate}\n onDateChange={handleOnDateChanged}\n showFocusOutline={showFocusOutline}\n />\n {timeDisplay && (\n <div className=\"time-container\">\n <Text variant=\"body\" className=\"time-label\">\n {timeLabelRef.current}\n </Text>\n <TimeField\n time={timeSpec}\n timeDisplay={timeDisplay}\n onTimeChange={handleOnTimeChanged}\n />\n </div>\n )}\n </div>\n </Popup>\n {!!displayEditField && (\n <DateField\n style={fieldStyle}\n className={fieldClassName}\n initialDate={workingDate}\n timeDisplay={timeDisplay}\n dateFormatter={dateFormatter}\n onDateChange={handleOnDateChanged}\n />\n )}\n </>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DatePickerPopupButton.js","sourceRoot":"","sources":["../../../../src/components-react/datepicker/DatePickerPopupButton.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAA+B;AAE/B,0DAAyD;AAEzD,kDAA0C;AAC1C,wDAA4C;AAC5C,6CAA0C;AAC1C,2CAAwC;AAExC,2CAAwC;AACxC,wCAAsC;AACtC,sDAAmD;AA0BnD;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,EACpC,gBAAgB,EAChB,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,aAAa,EACb,aAAa,EACb,UAAU,EACV,cAAc,EACd,KAAK,GAEmB;IACxB,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,+BAAc,GAAE,CAAC;IACvC,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,KAAK,CAAC,QAAQ,CAClD,IAAI,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAC7B,CAAC;IACF,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAClE,MAAM,YAAY,GAAG,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,SAAS,CAAC,uBAAuB,CAAC,CAAC;IAEzE,oDAAoD;IACpD,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,cAAc,GAAG,IAAI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9B,6BACE,SAAS,EAAC,6CAA6C,iBAC3C,6CAA6C;gBAEzD,oBAAC,uBAAU,CAAC,8CAA8C;oBACxD,QAAQ,EAAE,WAAW,EACrB,YAAY,EAAE,mBAAmB,EACjC,gBAAgB,EAAE,gBAAgB,GAClC;gBACD,WAAW,IAAI,CACd,6BAAK,SAAS,EAAC,gBAAgB;oBAC7B,oBAAC,oBAAI,IAAC,OAAO,EAAC,MAAM,EAAC,SAAS,EAAC,YAAY,IACxC,SAAS,CAAC,iBAAiB,CAAC,CACxB;oBACP,oBAAC,qBAAS,IACR,IAAI,EAAE,QAAQ,EACd,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,mBAAmB,GACjC,CACE,CACP,CACG,CACA;QACP,CAAC,CAAC,gBAAgB,IAAI,CACrB,oBAAC,qBAAS,IACR,KAAK,EAAE,UAAU,EACjB,SAAS,EAAE,cAAc,EACzB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,mBAAmB,GACjC,CACH,CACA,CACJ,CAAC;AACJ,CAAC;AAzID,sDAyIC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Date\n */\n\nimport * as React from \"react\";\nimport type { DateFormatter, TimeDisplay } from \"@itwin/appui-abstract\";\nimport { RelativePosition } from \"@itwin/appui-abstract\";\nimport type { CommonProps } from \"@itwin/core-react\";\nimport { Popup } from \"@itwin/core-react\";\nimport { Text } from \"@itwin/itwinui-react\";\nimport { DatePicker } from \"./DatePicker\";\nimport { DateField } from \"./DateField\";\nimport type { TimeSpec } from \"./TimeField\";\nimport { TimeField } from \"./TimeField\";\nimport \"./DatePickerPopupButton.scss\";\nimport { useTranslation } from \"../useTranslation\";\n\n/** Props used by [[DatePickerPopupButton]] component.\n * @alpha\n * @deprecated in 4.11.x. Props of deprecated component {@link DatePickerPopupButton}.\n */\nexport interface DatePickerPopupButtonProps extends CommonProps {\n /** Date to be shown as the selected date. */\n selected: Date;\n /** If true show the date (and optionally time) edit field next to button */\n displayEditField?: boolean;\n // If defined show time in popup and also display time if input field is shown\n timeDisplay?: TimeDisplay;\n /** Function called when Date changes. */\n onDateChange?: (day: Date) => void;\n /** Optional tooltip */\n buttonToolTip?: string;\n /* Custom date formatter. WARNING: if used values will only be shown in specified format and will not be based on locale.\n * If used the existence of a parseDate function will determine if the edit field allows editing. */\n dateFormatter?: DateFormatter;\n /** User defined class name for edit field. */\n fieldClassName?: string;\n /** User defined style for edit field. */\n fieldStyle?: React.CSSProperties;\n}\n\n/** Component that displays a button used to pick a date and optionally a time.\n * @alpha\n * @deprecated in 4.11.x. Use {@link https://itwinui.bentley.com/docs/datepicker iTwinUI date picker} instead.\n */\nexport function DatePickerPopupButton({\n displayEditField,\n timeDisplay,\n selected,\n onDateChange,\n dateFormatter,\n buttonToolTip,\n fieldStyle,\n fieldClassName,\n style,\n}: // eslint-disable-next-line deprecation/deprecation\nDatePickerPopupButtonProps) {\n const { translate } = useTranslation();\n const [workingDate, setWorkingDate] = React.useState(\n new Date(selected.getTime())\n );\n const [isSettingsOpen, setIsSettingsOpen] = React.useState(false);\n const toolTipLabel = buttonToolTip ?? translate(\"datepicker.selectDate\");\n\n // See if props have changed since component mounted\n React.useEffect(() => {\n const newWorkingDate = new Date(selected.getTime());\n setWorkingDate(newWorkingDate);\n }, [selected]);\n\n const buttonRef = React.useRef<HTMLButtonElement>(null);\n const togglePopupDisplay = React.useCallback(\n (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {\n event.preventDefault();\n setShowFocusOutline(false);\n setIsSettingsOpen((prev) => !prev);\n },\n [setIsSettingsOpen]\n );\n\n const handleCloseSetting = React.useCallback(() => {\n setIsSettingsOpen(false);\n }, [setIsSettingsOpen]);\n\n const handleOnDateChanged = (day: Date) => {\n // combine current time into selected Date\n const newWorkingDate = new Date(day.getTime());\n newWorkingDate.setHours(\n workingDate.getHours(),\n workingDate.getMinutes(),\n workingDate.getSeconds()\n );\n onDateChange && onDateChange(newWorkingDate);\n !timeDisplay && setIsSettingsOpen(false);\n };\n\n const handleOnTimeChanged = (time: TimeSpec) => {\n // Combine new time into selected Date\n const newWorkingDate = new Date(workingDate.getTime());\n newWorkingDate.setHours(time.hours, time.minutes, time.seconds);\n setWorkingDate(newWorkingDate);\n onDateChange && onDateChange(newWorkingDate);\n };\n\n const [showFocusOutline, setShowFocusOutline] = React.useState(false);\n const handlePopupKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLButtonElement>) => {\n // istanbul ignore else\n if (event.key === \" \") {\n setShowFocusOutline(true);\n setIsSettingsOpen(true);\n }\n },\n []\n );\n\n const timeSpec: TimeSpec = {\n hours: workingDate.getHours(),\n minutes: workingDate.getMinutes(),\n seconds: workingDate.getSeconds(),\n };\n return (\n <>\n <button\n title={toolTipLabel}\n style={style}\n className=\"components-date-picker-calendar-popup-button\"\n onKeyDown={handlePopupKeyDown}\n data-testid=\"components-date-picker-calendar-popup-button\"\n onPointerDown={togglePopupDisplay}\n ref={buttonRef}\n >\n <div className=\"datepicker-button\">\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\">\n <path d=\"M13,13H9V10h4ZM16,3V15a1,1,0,0,1-1,1H1a1,1,0,0,1-1-1V3A1,1,0,0,1,1,2H3V0H4V2h8V0h1V2h2A1,1,0,0,1,16,3ZM15,6H1v9H15Z\" />\n </svg>\n </div>\n </button>\n <Popup\n isOpen={isSettingsOpen}\n position={RelativePosition.BottomLeft}\n onClose={handleCloseSetting}\n target={buttonRef.current}\n closeOnEnter={false}\n moveFocus={showFocusOutline}\n closeOnNestedPopupOutsideClick\n >\n <div\n className=\"components-date-picker-calendar-popup-panel\"\n data-testid=\"components-date-picker-calendar-popup-panel\"\n >\n <DatePicker // eslint-disable-line deprecation/deprecation\n selected={workingDate}\n onDateChange={handleOnDateChanged}\n showFocusOutline={showFocusOutline}\n />\n {timeDisplay && (\n <div className=\"time-container\">\n <Text variant=\"body\" className=\"time-label\">\n {translate(\"datepicker.time\")}\n </Text>\n <TimeField\n time={timeSpec}\n timeDisplay={timeDisplay}\n onTimeChange={handleOnTimeChanged}\n />\n </div>\n )}\n </div>\n </Popup>\n {!!displayEditField && (\n <DateField\n style={fieldStyle}\n className={fieldClassName}\n initialDate={workingDate}\n timeDisplay={timeDisplay}\n dateFormatter={dateFormatter}\n onDateChange={handleOnDateChanged}\n />\n )}\n </>\n );\n}\n"]}
|
|
@@ -9,6 +9,7 @@ import type { DateFormatter } from "@itwin/appui-abstract";
|
|
|
9
9
|
* support parsing, so when used by [[DatePickerPopup]] the edit field will be readonly. If
|
|
10
10
|
* a parseData function is implemented then the edit field will be editable.
|
|
11
11
|
* @alpha
|
|
12
|
+
* @deprecated in 4.11.x. Use {@link https://itwinui.bentley.com/docs/datepicker iTwinUI date picker} instead.
|
|
12
13
|
*/
|
|
13
14
|
export declare class IntlFormatter implements DateFormatter {
|
|
14
15
|
private _intlFormatter?;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlFormatter.d.ts","sourceRoot":"","sources":["../../../../src/components-react/datepicker/IntlFormatter.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D
|
|
1
|
+
{"version":3,"file":"IntlFormatter.d.ts","sourceRoot":"","sources":["../../../../src/components-react/datepicker/IntlFormatter.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D;;;;;;;;GAQG;AACH,qBAAa,aAAc,YAAW,aAAa;IACrC,OAAO,CAAC,cAAc,CAAC;gBAAf,cAAc,CAAC,iCAAqB;IAExD,IAAW,SAAS,IAAI,IAAI,CAAC,cAAc,CAgB1C;IAEM,WAAW,CAAC,GAAG,EAAE,IAAI;CAO7B"}
|
|
@@ -15,6 +15,7 @@ exports.IntlFormatter = void 0;
|
|
|
15
15
|
* support parsing, so when used by [[DatePickerPopup]] the edit field will be readonly. If
|
|
16
16
|
* a parseData function is implemented then the edit field will be editable.
|
|
17
17
|
* @alpha
|
|
18
|
+
* @deprecated in 4.11.x. Use {@link https://itwinui.bentley.com/docs/datepicker iTwinUI date picker} instead.
|
|
18
19
|
*/
|
|
19
20
|
class IntlFormatter {
|
|
20
21
|
constructor(_intlFormatter) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlFormatter.js","sourceRoot":"","sources":["../../../../src/components-react/datepicker/IntlFormatter.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAIH
|
|
1
|
+
{"version":3,"file":"IntlFormatter.js","sourceRoot":"","sources":["../../../../src/components-react/datepicker/IntlFormatter.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;AAIH;;;;;;;;GAQG;AACH,MAAa,aAAa;IACxB,YAAoB,cAAoC;QAApC,mBAAc,GAAd,cAAc,CAAsB;IAAG,CAAC;IAE5D,IAAW,SAAS;QAClB,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE;YACxB,+DAA+D;YAC/D,IAAI,CAAC,cAAc,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE;gBACvD,OAAO,EAAE,OAAO,CAAC,+BAA+B;gBAChD,IAAI,EAAE,SAAS,CAAC,0BAA0B;gBAC1C,KAAK,EAAE,SAAS,CAAC,qDAAqD;gBACtE,GAAG,EAAE,SAAS,CAAC,0BAA0B;gBACzC,IAAI,EAAE,SAAS,CAAC,0BAA0B;gBAC1C,MAAM,EAAE,IAAI;gBACZ,MAAM,EAAE,SAAS,CAAC,0BAA0B;gBAC5C,MAAM,EAAE,SAAS,CAAC,0BAA0B,CAAC,qBAAqB;gBAClE,4BAA4B;aAC7B,CAAC,CAAC;SACJ;QACD,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAEM,WAAW,CAAC,GAAS;QAC1B,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACpC,CAAC;CAKF;AA5BD,sCA4BC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Date\n */\n\nimport type { DateFormatter } from \"@itwin/appui-abstract\";\n\n/**\n * A basic class that allows user to provide an Intl.DateTimeFormat\n * that can be used to format the date and time display. If no format is\n * specified a default format will be used. This default implementation does not\n * support parsing, so when used by [[DatePickerPopup]] the edit field will be readonly. If\n * a parseData function is implemented then the edit field will be editable.\n * @alpha\n * @deprecated in 4.11.x. Use {@link https://itwinui.bentley.com/docs/datepicker iTwinUI date picker} instead.\n */\nexport class IntlFormatter implements DateFormatter {\n constructor(private _intlFormatter?: Intl.DateTimeFormat) {}\n\n public get formatter(): Intl.DateTimeFormat {\n if (!this._intlFormatter) {\n // https://tc39.es/ecma402/#sec-intl-datetimeformat-constructor\n this._intlFormatter = new Intl.DateTimeFormat(undefined, {\n weekday: \"short\" /* \"narrow\", \"short\", \"long\" */,\n year: \"numeric\" /* \"2-digit\", \"numeric\" */,\n month: \"2-digit\" /* \"2-digit\", \"numeric\", \"narrow\", \"short\", \"long\" */,\n day: \"2-digit\" /* \"2-digit\", \"numeric\" */,\n hour: \"numeric\" /* \"2-digit\", \"numeric\" */,\n hour12: true,\n minute: \"numeric\" /* \"2-digit\", \"numeric\" */,\n second: \"numeric\" /* \"2-digit\", \"numeric\" */ /* \"short\", \"long\" */,\n /* timeZoneName:\t\"short\", */\n });\n }\n return this._intlFormatter;\n }\n\n public formateDate(day: Date) {\n return this.formatter.format(day);\n }\n\n // The default implementation does not currently support parsing. If a derived class supports parsing then the\n // parseDate function must be implemented.\n // parseDate(dateString: string): Date|undefined {}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeField.d.ts","sourceRoot":"","sources":["../../../../src/components-react/datepicker/TimeField.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"TimeField.d.ts","sourceRoot":"","sources":["../../../../src/components-react/datepicker/TimeField.tsx"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,kBAAkB,CAAC;AAG1B;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,QAAQ,CAAC;IACf,WAAW,EAAE,WAAW,CAAC;IACzB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;IACxC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAwBD;;;GAGG;AACH,wBAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,YAAY,GACb,EAAE,cAAc,qBAgVhB"}
|
|
@@ -38,8 +38,8 @@ const React = __importStar(require("react"));
|
|
|
38
38
|
const classnames_1 = __importDefault(require("classnames"));
|
|
39
39
|
const ts_key_enum_1 = require("ts-key-enum");
|
|
40
40
|
const itwinui_react_1 = require("@itwin/itwinui-react");
|
|
41
|
-
const UiComponents_1 = require("../UiComponents");
|
|
42
41
|
require("./TimeField.scss");
|
|
42
|
+
const useTranslation_1 = require("../useTranslation");
|
|
43
43
|
function getValidInt(intText, min, max, defaultValue) {
|
|
44
44
|
try {
|
|
45
45
|
const newValue = parseInt(intText, 10);
|
|
@@ -60,9 +60,10 @@ function isSameTime(a, b) {
|
|
|
60
60
|
* @internal
|
|
61
61
|
*/
|
|
62
62
|
function TimeField({ time, timeDisplay, readOnly, onTimeChange, }) {
|
|
63
|
+
const { translate } = (0, useTranslation_1.useTranslation)();
|
|
63
64
|
const initialDateRef = React.useRef(time);
|
|
64
|
-
const
|
|
65
|
-
const
|
|
65
|
+
const amLabel = translate("timepicker.day-period-am");
|
|
66
|
+
const pmLabel = translate("timepicker.day-period-pm");
|
|
66
67
|
const [timeSpec, setTimeSpec] = React.useState(time);
|
|
67
68
|
const { hours, minutes, seconds } = timeSpec;
|
|
68
69
|
const showDayPeriod = -1 !== timeDisplay.search("aa");
|
|
@@ -81,11 +82,7 @@ function TimeField({ time, timeDisplay, readOnly, onTimeChange, }) {
|
|
|
81
82
|
}
|
|
82
83
|
}, [time]);
|
|
83
84
|
const displayHour = getDisplayHours(hours);
|
|
84
|
-
const [dayPeriodText, setDayPeriodText] = React.useState(showDayPeriod
|
|
85
|
-
? hours >= 12
|
|
86
|
-
? pmLabelRef.current
|
|
87
|
-
: amLabelRef.current
|
|
88
|
-
: undefined);
|
|
85
|
+
const [dayPeriodText, setDayPeriodText] = React.useState(showDayPeriod ? (hours >= 12 ? pmLabel : amLabel) : undefined);
|
|
89
86
|
const [hoursText, setHoursText] = React.useState(displayHour.toString().padStart(2, "0"));
|
|
90
87
|
const [minutesText, setMinutesText] = React.useState(minutes.toString().padStart(2, "0"));
|
|
91
88
|
const [secondsText, setSecondsText] = React.useState(seconds.toString().padStart(2, "0"));
|
|
@@ -113,12 +110,13 @@ function TimeField({ time, timeDisplay, readOnly, onTimeChange, }) {
|
|
|
113
110
|
const newHours = getValidInt(hoursText, 0, 24, hours);
|
|
114
111
|
setHoursText(getDisplayHours(newHours).toString().padStart(2, "0"));
|
|
115
112
|
updateTimeSpec({ ...timeSpec, hours: newHours });
|
|
116
|
-
showDayPeriod &&
|
|
117
|
-
setDayPeriodText(newHours >= 12 ? pmLabelRef.current : amLabelRef.current);
|
|
113
|
+
showDayPeriod && setDayPeriodText(newHours >= 12 ? pmLabel : amLabel);
|
|
118
114
|
}, [
|
|
115
|
+
amLabel,
|
|
119
116
|
getDisplayHours,
|
|
120
117
|
hours,
|
|
121
118
|
hoursText,
|
|
119
|
+
pmLabel,
|
|
122
120
|
showDayPeriod,
|
|
123
121
|
timeSpec,
|
|
124
122
|
updateTimeSpec,
|
|
@@ -138,23 +136,23 @@ function TimeField({ time, timeDisplay, readOnly, onTimeChange, }) {
|
|
|
138
136
|
// istanbul ignore else
|
|
139
137
|
if (dayPeriodText === "AM" ||
|
|
140
138
|
dayPeriodText === "am" ||
|
|
141
|
-
dayPeriodText ===
|
|
142
|
-
newPeriodText =
|
|
139
|
+
dayPeriodText === amLabel)
|
|
140
|
+
newPeriodText = amLabel;
|
|
143
141
|
else if (dayPeriodText === "PM" ||
|
|
144
142
|
dayPeriodText === "pm" ||
|
|
145
|
-
dayPeriodText ===
|
|
146
|
-
newPeriodText =
|
|
143
|
+
dayPeriodText === pmLabel)
|
|
144
|
+
newPeriodText = pmLabel;
|
|
147
145
|
// istanbul ignore else
|
|
148
146
|
if (undefined !== newPeriodText) {
|
|
149
147
|
setDayPeriodText(newPeriodText);
|
|
150
|
-
if (newPeriodText ===
|
|
148
|
+
if (newPeriodText === amLabel && hours > 12) {
|
|
151
149
|
updateTimeSpec({ ...timeSpec, hours: hours - 12 });
|
|
152
150
|
}
|
|
153
|
-
else if (newPeriodText ===
|
|
151
|
+
else if (newPeriodText === pmLabel && hours <= 11) {
|
|
154
152
|
updateTimeSpec({ ...timeSpec, hours: hours + 12 });
|
|
155
153
|
}
|
|
156
154
|
}
|
|
157
|
-
}, [dayPeriodText, hours, timeSpec, updateTimeSpec]);
|
|
155
|
+
}, [amLabel, dayPeriodText, hours, pmLabel, timeSpec, updateTimeSpec]);
|
|
158
156
|
const handleHoursOnKeyDown = React.useCallback((event) => {
|
|
159
157
|
// istanbul ignore else
|
|
160
158
|
if (event.key === ts_key_enum_1.Key.ArrowDown.valueOf() ||
|
|
@@ -166,23 +164,23 @@ function TimeField({ time, timeDisplay, readOnly, onTimeChange, }) {
|
|
|
166
164
|
newHours = 0;
|
|
167
165
|
setHoursText(getDisplayHours(newHours).toString().padStart(2, "0"));
|
|
168
166
|
updateTimeSpec({ ...timeSpec, hours: newHours });
|
|
169
|
-
showDayPeriod &&
|
|
170
|
-
setDayPeriodText(newHours >= 12 ? pmLabelRef.current : amLabelRef.current);
|
|
167
|
+
showDayPeriod && setDayPeriodText(newHours >= 12 ? pmLabel : amLabel);
|
|
171
168
|
event.preventDefault();
|
|
172
169
|
}
|
|
173
170
|
else if (event.key === ts_key_enum_1.Key.Enter.valueOf()) {
|
|
174
171
|
const newHours = getValidInt(hoursText, 0, 24, hours);
|
|
175
172
|
setHoursText(getDisplayHours(newHours).toString().padStart(2, "0"));
|
|
176
173
|
updateTimeSpec({ ...timeSpec, hours: newHours });
|
|
177
|
-
showDayPeriod &&
|
|
178
|
-
setDayPeriodText(newHours >= 12 ? pmLabelRef.current : amLabelRef.current);
|
|
174
|
+
showDayPeriod && setDayPeriodText(newHours >= 12 ? pmLabel : amLabel);
|
|
179
175
|
event.preventDefault();
|
|
180
176
|
}
|
|
181
177
|
}, [
|
|
178
|
+
amLabel,
|
|
182
179
|
getDisplayHours,
|
|
183
180
|
hours,
|
|
184
181
|
hoursText,
|
|
185
182
|
minutes,
|
|
183
|
+
pmLabel,
|
|
186
184
|
seconds,
|
|
187
185
|
showDayPeriod,
|
|
188
186
|
timeSpec,
|
|
@@ -251,39 +249,39 @@ function TimeField({ time, timeDisplay, readOnly, onTimeChange, }) {
|
|
|
251
249
|
event.key === ts_key_enum_1.Key.Home.valueOf() ||
|
|
252
250
|
event.key === "a" ||
|
|
253
251
|
event.key === "A") {
|
|
254
|
-
newPeriodText =
|
|
252
|
+
newPeriodText = amLabel;
|
|
255
253
|
event.preventDefault();
|
|
256
254
|
}
|
|
257
255
|
else if (event.key === ts_key_enum_1.Key.ArrowUp.valueOf() ||
|
|
258
256
|
event.key === ts_key_enum_1.Key.End.valueOf() ||
|
|
259
257
|
event.key === "p" ||
|
|
260
258
|
event.key === "P") {
|
|
261
|
-
newPeriodText =
|
|
259
|
+
newPeriodText = pmLabel;
|
|
262
260
|
event.preventDefault();
|
|
263
261
|
}
|
|
264
262
|
else if (event.key === ts_key_enum_1.Key.Enter.valueOf()) {
|
|
265
263
|
if (dayPeriodText === "AM" ||
|
|
266
264
|
dayPeriodText === "am" ||
|
|
267
|
-
dayPeriodText ===
|
|
268
|
-
newPeriodText =
|
|
265
|
+
dayPeriodText === amLabel)
|
|
266
|
+
newPeriodText = amLabel;
|
|
269
267
|
else if (dayPeriodText === "PM" ||
|
|
270
268
|
dayPeriodText === "pm" ||
|
|
271
|
-
dayPeriodText ===
|
|
272
|
-
newPeriodText =
|
|
269
|
+
dayPeriodText === pmLabel)
|
|
270
|
+
newPeriodText = pmLabel;
|
|
273
271
|
event.preventDefault();
|
|
274
272
|
}
|
|
275
273
|
// istanbul ignore else
|
|
276
274
|
if (undefined !== newPeriodText) {
|
|
277
275
|
setDayPeriodText(newPeriodText);
|
|
278
276
|
/* istanbul ignore else */
|
|
279
|
-
if (newPeriodText ===
|
|
277
|
+
if (newPeriodText === amLabel && hours > 12) {
|
|
280
278
|
updateTimeSpec({ ...timeSpec, hours: hours - 12 });
|
|
281
279
|
}
|
|
282
|
-
else if (newPeriodText ===
|
|
280
|
+
else if (newPeriodText === pmLabel && hours <= 11) {
|
|
283
281
|
updateTimeSpec({ ...timeSpec, hours: hours + 12 });
|
|
284
282
|
}
|
|
285
283
|
}
|
|
286
|
-
}, [dayPeriodText, hours, timeSpec, updateTimeSpec]);
|
|
284
|
+
}, [amLabel, dayPeriodText, hours, pmLabel, timeSpec, updateTimeSpec]);
|
|
287
285
|
const showSeconds = -1 !== timeDisplay.search(":ss");
|
|
288
286
|
return (React.createElement("div", { "data-testid": "components-time-input", className: "components-time" },
|
|
289
287
|
React.createElement(itwinui_react_1.Input, { className: (0, classnames_1.default)("components-time-input", "components-input"), onKeyDown: handleHoursOnKeyDown, onBlur: handleHoursOnBlur, onChange: handleHoursChange, value: hoursText, disabled: readOnly, size: "small" }),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TimeField.js","sourceRoot":"","sources":["../../../../src/components-react/datepicker/TimeField.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAA+B;AAC/B,4DAAoC;AACpC,6CAAkC;AAClC,wDAA6C;AAE7C,kDAA+C;AAC/C,4BAA0B;AAsB1B,SAAS,WAAW,CAClB,OAAe,EACf,GAAW,EACX,GAAW,EACX,YAAoB;IAEpB,IAAI;QACF,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACvC,IAAI,QAAQ,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG;YAAE,OAAO,QAAQ,CAAC;KACzD;IAAC,OAAO,EAAE,EAAE;QACX,uBAAuB;QACvB,OAAO,YAAY,CAAC;KACrB;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,UAAU,CAAC,CAAW,EAAE,CAAW;IAC1C,OAAO,CACL,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO,CAC1E,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,YAAY,GACG;IACf,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,UAAU,GAAG,KAA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,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAC,OAAO,GACZ,CACH,CACG,CACP,CAAC;AACJ,CAAC;AAjWD,8BAiWC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Date\n */\n\nimport * as React from \"react\";\nimport classnames from \"classnames\";\nimport { Key } from \"ts-key-enum\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport type { TimeDisplay } from \"@itwin/appui-abstract\";\nimport { UiComponents } from \"../UiComponents\";\nimport \"./TimeField.scss\";\n\n/** Interface used to hold 24 hour time in\n * hours, minutes, and seconds.\n * @internal\n */\nexport interface TimeSpec {\n hours: number;\n minutes: number;\n seconds: number;\n}\n\n/** Interface for props used by [[TimeField]] component.\n * @internal\n */\nexport interface TimeFieldProps {\n time: TimeSpec;\n timeDisplay: TimeDisplay;\n onTimeChange?: (time: TimeSpec) => void;\n readOnly?: boolean;\n}\n\nfunction getValidInt(\n intText: string,\n min: number,\n max: number,\n defaultValue: number\n) {\n try {\n const newValue = parseInt(intText, 10);\n if (newValue >= min && newValue <= max) return newValue;\n } catch (_e) {\n // istanbul ignore next\n return defaultValue;\n }\n return defaultValue;\n}\n\nfunction isSameTime(a: TimeSpec, b: TimeSpec) {\n return (\n a.hours === b.hours && a.minutes === b.minutes && a.seconds === b.seconds\n );\n}\n\n/** Field used to set the Hour:Minutes:Seconds in the [[DatePicker]] Popup panel. The user may key-in the value or use up/down keys to\n * change the time.\n * @internal\n */\nexport function TimeField({\n time,\n timeDisplay,\n readOnly,\n onTimeChange,\n}: TimeFieldProps) {\n const initialDateRef = React.useRef(time);\n const amLabelRef = React.useRef(\n UiComponents.translate(\"timepicker.day-period-am\")\n );\n const pmLabelRef = React.useRef(\n UiComponents.translate(\"timepicker.day-period-pm\")\n );\n const [timeSpec, setTimeSpec] = React.useState(time);\n const { hours, minutes, seconds } = timeSpec;\n const showDayPeriod = -1 !== (timeDisplay as string).search(\"aa\");\n\n const getDisplayHours = React.useCallback(\n (timeHours: number) => {\n if (!showDayPeriod) {\n return timeHours;\n }\n const outHours =\n 0 === timeHours ? 12 : timeHours > 12 ? timeHours - 12 : timeHours;\n return outHours;\n },\n [showDayPeriod]\n );\n\n // See if new initialDate props have changed since component mounted\n React.useEffect(() => {\n if (!isSameTime(time, initialDateRef.current)) {\n setTimeSpec(time);\n initialDateRef.current = time;\n }\n }, [time]);\n\n const displayHour = getDisplayHours(hours);\n const [dayPeriodText, setDayPeriodText] = React.useState(\n showDayPeriod\n ? hours >= 12\n ? pmLabelRef.current\n : amLabelRef.current\n : undefined\n );\n const [hoursText, setHoursText] = React.useState(\n displayHour.toString().padStart(2, \"0\")\n );\n const [minutesText, setMinutesText] = React.useState(\n minutes.toString().padStart(2, \"0\")\n );\n const [secondsText, setSecondsText] = React.useState(\n seconds.toString().padStart(2, \"0\")\n );\n\n const updateTimeSpec = React.useCallback(\n (newTime: TimeSpec) => {\n if (\n newTime.hours !== timeSpec.hours ||\n newTime.minutes !== timeSpec.minutes ||\n newTime.seconds !== timeSpec.seconds\n ) {\n setTimeSpec(newTime);\n onTimeChange && onTimeChange(newTime);\n }\n },\n [onTimeChange, timeSpec.hours, timeSpec.minutes, timeSpec.seconds]\n );\n\n const handleHoursChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setHoursText(event.currentTarget.value);\n },\n []\n );\n\n const handleMinutesChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setMinutesText(event.currentTarget.value);\n },\n []\n );\n const handleSecondsChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setSecondsText(event.currentTarget.value);\n },\n []\n );\n const handleDayPeriodChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setDayPeriodText(event.currentTarget.value);\n },\n []\n );\n\n const handleHoursOnBlur = React.useCallback(() => {\n const newHours = getValidInt(hoursText, 0, 24, hours);\n setHoursText(getDisplayHours(newHours).toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, hours: newHours });\n showDayPeriod &&\n setDayPeriodText(\n newHours >= 12 ? pmLabelRef.current : amLabelRef.current\n );\n }, [\n getDisplayHours,\n hours,\n hoursText,\n showDayPeriod,\n timeSpec,\n updateTimeSpec,\n ]);\n const handleMinutesOnBlur = React.useCallback(() => {\n const newMinutes = getValidInt(minutesText, 0, 59, minutes);\n setMinutesText(newMinutes.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, minutes: newMinutes });\n }, [minutes, minutesText, timeSpec, updateTimeSpec]);\n const handleSecondsOnBlur = React.useCallback(() => {\n const newSeconds = getValidInt(secondsText, 0, 59, seconds);\n setSecondsText(newSeconds.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, seconds: newSeconds });\n }, [seconds, secondsText, timeSpec, updateTimeSpec]);\n const handleDayPeriodOnBlur = React.useCallback(() => {\n let newPeriodText: string | undefined;\n // istanbul ignore else\n if (\n dayPeriodText === \"AM\" ||\n dayPeriodText === \"am\" ||\n dayPeriodText === amLabelRef.current\n )\n newPeriodText = amLabelRef.current;\n else if (\n dayPeriodText === \"PM\" ||\n dayPeriodText === \"pm\" ||\n dayPeriodText === pmLabelRef.current\n )\n newPeriodText = pmLabelRef.current;\n\n // istanbul ignore else\n if (undefined !== newPeriodText) {\n setDayPeriodText(newPeriodText);\n if (newPeriodText === amLabelRef.current && hours > 12) {\n updateTimeSpec({ ...timeSpec, hours: hours - 12 });\n } else if (newPeriodText === pmLabelRef.current && hours <= 11) {\n updateTimeSpec({ ...timeSpec, hours: hours + 12 });\n }\n }\n }, [dayPeriodText, hours, timeSpec, updateTimeSpec]);\n\n const handleHoursOnKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (\n event.key === Key.ArrowDown.valueOf() ||\n event.key === Key.ArrowUp.valueOf()\n ) {\n let newHours = hours + (event.key === Key.ArrowDown.valueOf() ? -1 : 1);\n if (newHours < 0) newHours = 24;\n if (newHours > 24 || (newHours > 23 && minutes + seconds > 0))\n newHours = 0;\n setHoursText(getDisplayHours(newHours).toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, hours: newHours });\n showDayPeriod &&\n setDayPeriodText(\n newHours >= 12 ? pmLabelRef.current : amLabelRef.current\n );\n event.preventDefault();\n } else if (event.key === Key.Enter.valueOf()) {\n const newHours = getValidInt(hoursText, 0, 24, hours);\n setHoursText(getDisplayHours(newHours).toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, hours: newHours });\n showDayPeriod &&\n setDayPeriodText(\n newHours >= 12 ? pmLabelRef.current : amLabelRef.current\n );\n event.preventDefault();\n }\n },\n [\n getDisplayHours,\n hours,\n hoursText,\n minutes,\n seconds,\n showDayPeriod,\n timeSpec,\n updateTimeSpec,\n ]\n );\n\n const handleMinutesOnKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (event.key === Key.ArrowDown.valueOf()) {\n const newMinutes = minutes === 0 ? 59 : minutes - 1;\n setMinutesText(newMinutes.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, minutes: newMinutes });\n event.preventDefault();\n } else if (event.key === Key.ArrowUp.valueOf()) {\n const newMinutes = minutes === 59 ? 0 : minutes + 1;\n setMinutesText(newMinutes.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, minutes: newMinutes });\n event.preventDefault();\n } else if (\n event.key === Key.Home.valueOf() ||\n event.key === Key.End.valueOf()\n ) {\n const newMinutes = event.key === Key.Home.valueOf() ? 0 : 59;\n setMinutesText(newMinutes.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, minutes: newMinutes });\n event.preventDefault();\n } else if (event.key === Key.Enter.valueOf()) {\n const newMinutes = getValidInt(minutesText, 0, 59, minutes);\n setMinutesText(newMinutes.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, minutes: newMinutes });\n event.preventDefault();\n }\n },\n [minutesText, minutes, timeSpec, updateTimeSpec]\n );\n\n const handleSecondsOnKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (event.key === Key.ArrowDown.valueOf()) {\n const newSeconds = seconds === 0 ? 59 : seconds - 1;\n setSecondsText(newSeconds.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, seconds: newSeconds });\n event.preventDefault();\n } else if (event.key === Key.ArrowUp.valueOf()) {\n const newSeconds = seconds === 59 ? 0 : seconds + 1;\n setSecondsText(newSeconds.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, seconds: newSeconds });\n event.preventDefault();\n } else if (\n event.key === Key.Home.valueOf() ||\n event.key === Key.End.valueOf()\n ) {\n const newSeconds = event.key === Key.Home.valueOf() ? 0 : 59;\n setSecondsText(newSeconds.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, seconds: newSeconds });\n event.preventDefault();\n } else if (event.key === Key.Enter.valueOf()) {\n const newSeconds = getValidInt(secondsText, 0, 59, seconds);\n setSecondsText(newSeconds.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, seconds: newSeconds });\n event.preventDefault();\n }\n },\n [seconds, secondsText, timeSpec, updateTimeSpec]\n );\n\n const handleDayPeriodOnKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLInputElement>) => {\n let newPeriodText: string | undefined;\n // istanbul ignore else\n if (\n event.key === Key.ArrowDown.valueOf() ||\n event.key === Key.Home.valueOf() ||\n event.key === \"a\" ||\n event.key === \"A\"\n ) {\n newPeriodText = amLabelRef.current;\n event.preventDefault();\n } else if (\n event.key === Key.ArrowUp.valueOf() ||\n event.key === Key.End.valueOf() ||\n event.key === \"p\" ||\n event.key === \"P\"\n ) {\n newPeriodText = pmLabelRef.current;\n event.preventDefault();\n } else if (event.key === Key.Enter.valueOf()) {\n if (\n dayPeriodText === \"AM\" ||\n dayPeriodText === \"am\" ||\n dayPeriodText === amLabelRef.current\n )\n newPeriodText = amLabelRef.current;\n else if (\n dayPeriodText === \"PM\" ||\n dayPeriodText === \"pm\" ||\n dayPeriodText === pmLabelRef.current\n )\n newPeriodText = pmLabelRef.current;\n event.preventDefault();\n }\n // istanbul ignore else\n if (undefined !== newPeriodText) {\n setDayPeriodText(newPeriodText);\n /* istanbul ignore else */\n if (newPeriodText === amLabelRef.current && hours > 12) {\n updateTimeSpec({ ...timeSpec, hours: hours - 12 });\n } else if (newPeriodText === pmLabelRef.current && hours <= 11) {\n updateTimeSpec({ ...timeSpec, hours: hours + 12 });\n }\n }\n },\n [dayPeriodText, hours, timeSpec, updateTimeSpec]\n );\n\n const showSeconds = -1 !== (timeDisplay as string).search(\":ss\");\n\n return (\n <div data-testid=\"components-time-input\" className=\"components-time\">\n <Input\n className={classnames(\"components-time-input\", \"components-input\")}\n onKeyDown={handleHoursOnKeyDown}\n onBlur={handleHoursOnBlur}\n onChange={handleHoursChange}\n value={hoursText}\n disabled={readOnly}\n size=\"small\"\n />\n <span className=\"component-time-separator\">:</span>\n <Input\n className={classnames(\"components-time-input\", \"components-input\")}\n onKeyDown={handleMinutesOnKeyDown}\n onBlur={handleMinutesOnBlur}\n onChange={handleMinutesChange}\n value={minutesText}\n disabled={readOnly}\n size=\"small\"\n />\n {showSeconds && (\n <>\n <span className=\"component-time-separator\">:</span>\n <Input\n className={classnames(\"components-time-input\", \"components-input\")}\n onKeyDown={handleSecondsOnKeyDown}\n onBlur={handleSecondsOnBlur}\n onChange={handleSecondsChange}\n value={secondsText}\n disabled={readOnly}\n size=\"small\"\n />\n </>\n )}\n {dayPeriodText && (\n <Input\n className={classnames(\n \"components-time-period-input\",\n \"components-input\"\n )}\n onKeyDown={handleDayPeriodOnKeyDown}\n onBlur={handleDayPeriodOnBlur}\n onChange={handleDayPeriodChange}\n value={dayPeriodText}\n disabled={readOnly}\n size=\"small\"\n />\n )}\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TimeField.js","sourceRoot":"","sources":["../../../../src/components-react/datepicker/TimeField.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAA+B;AAC/B,4DAAoC;AACpC,6CAAkC;AAClC,wDAA6C;AAE7C,4BAA0B;AAC1B,sDAAmD;AAsBnD,SAAS,WAAW,CAClB,OAAe,EACf,GAAW,EACX,GAAW,EACX,YAAoB;IAEpB,IAAI;QACF,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACvC,IAAI,QAAQ,IAAI,GAAG,IAAI,QAAQ,IAAI,GAAG;YAAE,OAAO,QAAQ,CAAC;KACzD;IAAC,OAAO,EAAE,EAAE;QACX,uBAAuB;QACvB,OAAO,YAAY,CAAC;KACrB;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,SAAS,UAAU,CAAC,CAAW,EAAE,CAAW;IAC1C,OAAO,CACL,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,OAAO,CAC1E,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAgB,SAAS,CAAC,EACxB,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,YAAY,GACG;IACf,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,+BAAc,GAAE,CAAC;IACvC,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,OAAO,GAAG,SAAS,CAAC,0BAA0B,CAAC,CAAC;IACtD,MAAM,OAAO,GAAG,SAAS,CAAC,0BAA0B,CAAC,CAAC;IACtD,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,KAAK,CAAC,QAAQ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AI,EAAC,OAAO,GACZ;QACF,8BAAM,SAAS,EAAC,0BAA0B,QAAS;QACnD,oBAAC,qBAAK,IACJ,SAAS,EAAE,IAAA,oBAAU,EAAC,uBAAuB,EAAE,kBAAkB,CAAC,EAClE,SAAS,EAAE,sBAAsB,EACjC,MAAM,EAAE,mBAAmB,EAC3B,QAAQ,EAAE,mBAAmB,EAC7B,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAC,OAAO,GACZ;QACD,WAAW,IAAI,CACd;YACE,8BAAM,SAAS,EAAC,0BAA0B,QAAS;YACnD,oBAAC,qBAAK,IACJ,SAAS,EAAE,IAAA,oBAAU,EAAC,uBAAuB,EAAE,kBAAkB,CAAC,EAClE,SAAS,EAAE,sBAAsB,EACjC,MAAM,EAAE,mBAAmB,EAC3B,QAAQ,EAAE,mBAAmB,EAC7B,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAC,OAAO,GACZ,CACD,CACJ;QACA,aAAa,IAAI,CAChB,oBAAC,qBAAK,IACJ,SAAS,EAAE,IAAA,oBAAU,EACnB,8BAA8B,EAC9B,kBAAkB,CACnB,EACD,SAAS,EAAE,wBAAwB,EACnC,MAAM,EAAE,qBAAqB,EAC7B,QAAQ,EAAE,qBAAqB,EAC/B,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAC,OAAO,GACZ,CACH,CACG,CACP,CAAC;AACJ,CAAC;AArVD,8BAqVC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module Date\n */\n\nimport * as React from \"react\";\nimport classnames from \"classnames\";\nimport { Key } from \"ts-key-enum\";\nimport { Input } from \"@itwin/itwinui-react\";\nimport type { TimeDisplay } from \"@itwin/appui-abstract\";\nimport \"./TimeField.scss\";\nimport { useTranslation } from \"../useTranslation\";\n\n/** Interface used to hold 24 hour time in\n * hours, minutes, and seconds.\n * @internal\n */\nexport interface TimeSpec {\n hours: number;\n minutes: number;\n seconds: number;\n}\n\n/** Interface for props used by [[TimeField]] component.\n * @internal\n */\nexport interface TimeFieldProps {\n time: TimeSpec;\n timeDisplay: TimeDisplay;\n onTimeChange?: (time: TimeSpec) => void;\n readOnly?: boolean;\n}\n\nfunction getValidInt(\n intText: string,\n min: number,\n max: number,\n defaultValue: number\n) {\n try {\n const newValue = parseInt(intText, 10);\n if (newValue >= min && newValue <= max) return newValue;\n } catch (_e) {\n // istanbul ignore next\n return defaultValue;\n }\n return defaultValue;\n}\n\nfunction isSameTime(a: TimeSpec, b: TimeSpec) {\n return (\n a.hours === b.hours && a.minutes === b.minutes && a.seconds === b.seconds\n );\n}\n\n/** Field used to set the Hour:Minutes:Seconds in the [[DatePicker]] Popup panel. The user may key-in the value or use up/down keys to\n * change the time.\n * @internal\n */\nexport function TimeField({\n time,\n timeDisplay,\n readOnly,\n onTimeChange,\n}: TimeFieldProps) {\n const { translate } = useTranslation();\n const initialDateRef = React.useRef(time);\n const amLabel = translate(\"timepicker.day-period-am\");\n const pmLabel = translate(\"timepicker.day-period-pm\");\n const [timeSpec, setTimeSpec] = React.useState(time);\n const { hours, minutes, seconds } = timeSpec;\n const showDayPeriod = -1 !== (timeDisplay as string).search(\"aa\");\n\n const getDisplayHours = React.useCallback(\n (timeHours: number) => {\n if (!showDayPeriod) {\n return timeHours;\n }\n const outHours =\n 0 === timeHours ? 12 : timeHours > 12 ? timeHours - 12 : timeHours;\n return outHours;\n },\n [showDayPeriod]\n );\n\n // See if new initialDate props have changed since component mounted\n React.useEffect(() => {\n if (!isSameTime(time, initialDateRef.current)) {\n setTimeSpec(time);\n initialDateRef.current = time;\n }\n }, [time]);\n\n const displayHour = getDisplayHours(hours);\n const [dayPeriodText, setDayPeriodText] = React.useState(\n showDayPeriod ? (hours >= 12 ? pmLabel : amLabel) : undefined\n );\n const [hoursText, setHoursText] = React.useState(\n displayHour.toString().padStart(2, \"0\")\n );\n const [minutesText, setMinutesText] = React.useState(\n minutes.toString().padStart(2, \"0\")\n );\n const [secondsText, setSecondsText] = React.useState(\n seconds.toString().padStart(2, \"0\")\n );\n\n const updateTimeSpec = React.useCallback(\n (newTime: TimeSpec) => {\n if (\n newTime.hours !== timeSpec.hours ||\n newTime.minutes !== timeSpec.minutes ||\n newTime.seconds !== timeSpec.seconds\n ) {\n setTimeSpec(newTime);\n onTimeChange && onTimeChange(newTime);\n }\n },\n [onTimeChange, timeSpec.hours, timeSpec.minutes, timeSpec.seconds]\n );\n\n const handleHoursChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setHoursText(event.currentTarget.value);\n },\n []\n );\n\n const handleMinutesChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setMinutesText(event.currentTarget.value);\n },\n []\n );\n const handleSecondsChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setSecondsText(event.currentTarget.value);\n },\n []\n );\n const handleDayPeriodChange = React.useCallback(\n (event: React.ChangeEvent<HTMLInputElement>) => {\n setDayPeriodText(event.currentTarget.value);\n },\n []\n );\n\n const handleHoursOnBlur = React.useCallback(() => {\n const newHours = getValidInt(hoursText, 0, 24, hours);\n setHoursText(getDisplayHours(newHours).toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, hours: newHours });\n showDayPeriod && setDayPeriodText(newHours >= 12 ? pmLabel : amLabel);\n }, [\n amLabel,\n getDisplayHours,\n hours,\n hoursText,\n pmLabel,\n showDayPeriod,\n timeSpec,\n updateTimeSpec,\n ]);\n const handleMinutesOnBlur = React.useCallback(() => {\n const newMinutes = getValidInt(minutesText, 0, 59, minutes);\n setMinutesText(newMinutes.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, minutes: newMinutes });\n }, [minutes, minutesText, timeSpec, updateTimeSpec]);\n const handleSecondsOnBlur = React.useCallback(() => {\n const newSeconds = getValidInt(secondsText, 0, 59, seconds);\n setSecondsText(newSeconds.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, seconds: newSeconds });\n }, [seconds, secondsText, timeSpec, updateTimeSpec]);\n const handleDayPeriodOnBlur = React.useCallback(() => {\n let newPeriodText: string | undefined;\n // istanbul ignore else\n if (\n dayPeriodText === \"AM\" ||\n dayPeriodText === \"am\" ||\n dayPeriodText === amLabel\n )\n newPeriodText = amLabel;\n else if (\n dayPeriodText === \"PM\" ||\n dayPeriodText === \"pm\" ||\n dayPeriodText === pmLabel\n )\n newPeriodText = pmLabel;\n\n // istanbul ignore else\n if (undefined !== newPeriodText) {\n setDayPeriodText(newPeriodText);\n if (newPeriodText === amLabel && hours > 12) {\n updateTimeSpec({ ...timeSpec, hours: hours - 12 });\n } else if (newPeriodText === pmLabel && hours <= 11) {\n updateTimeSpec({ ...timeSpec, hours: hours + 12 });\n }\n }\n }, [amLabel, dayPeriodText, hours, pmLabel, timeSpec, updateTimeSpec]);\n\n const handleHoursOnKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (\n event.key === Key.ArrowDown.valueOf() ||\n event.key === Key.ArrowUp.valueOf()\n ) {\n let newHours = hours + (event.key === Key.ArrowDown.valueOf() ? -1 : 1);\n if (newHours < 0) newHours = 24;\n if (newHours > 24 || (newHours > 23 && minutes + seconds > 0))\n newHours = 0;\n setHoursText(getDisplayHours(newHours).toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, hours: newHours });\n showDayPeriod && setDayPeriodText(newHours >= 12 ? pmLabel : amLabel);\n event.preventDefault();\n } else if (event.key === Key.Enter.valueOf()) {\n const newHours = getValidInt(hoursText, 0, 24, hours);\n setHoursText(getDisplayHours(newHours).toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, hours: newHours });\n showDayPeriod && setDayPeriodText(newHours >= 12 ? pmLabel : amLabel);\n event.preventDefault();\n }\n },\n [\n amLabel,\n getDisplayHours,\n hours,\n hoursText,\n minutes,\n pmLabel,\n seconds,\n showDayPeriod,\n timeSpec,\n updateTimeSpec,\n ]\n );\n\n const handleMinutesOnKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (event.key === Key.ArrowDown.valueOf()) {\n const newMinutes = minutes === 0 ? 59 : minutes - 1;\n setMinutesText(newMinutes.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, minutes: newMinutes });\n event.preventDefault();\n } else if (event.key === Key.ArrowUp.valueOf()) {\n const newMinutes = minutes === 59 ? 0 : minutes + 1;\n setMinutesText(newMinutes.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, minutes: newMinutes });\n event.preventDefault();\n } else if (\n event.key === Key.Home.valueOf() ||\n event.key === Key.End.valueOf()\n ) {\n const newMinutes = event.key === Key.Home.valueOf() ? 0 : 59;\n setMinutesText(newMinutes.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, minutes: newMinutes });\n event.preventDefault();\n } else if (event.key === Key.Enter.valueOf()) {\n const newMinutes = getValidInt(minutesText, 0, 59, minutes);\n setMinutesText(newMinutes.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, minutes: newMinutes });\n event.preventDefault();\n }\n },\n [minutesText, minutes, timeSpec, updateTimeSpec]\n );\n\n const handleSecondsOnKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (event.key === Key.ArrowDown.valueOf()) {\n const newSeconds = seconds === 0 ? 59 : seconds - 1;\n setSecondsText(newSeconds.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, seconds: newSeconds });\n event.preventDefault();\n } else if (event.key === Key.ArrowUp.valueOf()) {\n const newSeconds = seconds === 59 ? 0 : seconds + 1;\n setSecondsText(newSeconds.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, seconds: newSeconds });\n event.preventDefault();\n } else if (\n event.key === Key.Home.valueOf() ||\n event.key === Key.End.valueOf()\n ) {\n const newSeconds = event.key === Key.Home.valueOf() ? 0 : 59;\n setSecondsText(newSeconds.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, seconds: newSeconds });\n event.preventDefault();\n } else if (event.key === Key.Enter.valueOf()) {\n const newSeconds = getValidInt(secondsText, 0, 59, seconds);\n setSecondsText(newSeconds.toString().padStart(2, \"0\"));\n updateTimeSpec({ ...timeSpec, seconds: newSeconds });\n event.preventDefault();\n }\n },\n [seconds, secondsText, timeSpec, updateTimeSpec]\n );\n\n const handleDayPeriodOnKeyDown = React.useCallback(\n (event: React.KeyboardEvent<HTMLInputElement>) => {\n let newPeriodText: string | undefined;\n // istanbul ignore else\n if (\n event.key === Key.ArrowDown.valueOf() ||\n event.key === Key.Home.valueOf() ||\n event.key === \"a\" ||\n event.key === \"A\"\n ) {\n newPeriodText = amLabel;\n event.preventDefault();\n } else if (\n event.key === Key.ArrowUp.valueOf() ||\n event.key === Key.End.valueOf() ||\n event.key === \"p\" ||\n event.key === \"P\"\n ) {\n newPeriodText = pmLabel;\n event.preventDefault();\n } else if (event.key === Key.Enter.valueOf()) {\n if (\n dayPeriodText === \"AM\" ||\n dayPeriodText === \"am\" ||\n dayPeriodText === amLabel\n )\n newPeriodText = amLabel;\n else if (\n dayPeriodText === \"PM\" ||\n dayPeriodText === \"pm\" ||\n dayPeriodText === pmLabel\n )\n newPeriodText = pmLabel;\n event.preventDefault();\n }\n // istanbul ignore else\n if (undefined !== newPeriodText) {\n setDayPeriodText(newPeriodText);\n /* istanbul ignore else */\n if (newPeriodText === amLabel && hours > 12) {\n updateTimeSpec({ ...timeSpec, hours: hours - 12 });\n } else if (newPeriodText === pmLabel && hours <= 11) {\n updateTimeSpec({ ...timeSpec, hours: hours + 12 });\n }\n }\n },\n [amLabel, dayPeriodText, hours, pmLabel, timeSpec, updateTimeSpec]\n );\n\n const showSeconds = -1 !== (timeDisplay as string).search(\":ss\");\n\n return (\n <div data-testid=\"components-time-input\" className=\"components-time\">\n <Input\n className={classnames(\"components-time-input\", \"components-input\")}\n onKeyDown={handleHoursOnKeyDown}\n onBlur={handleHoursOnBlur}\n onChange={handleHoursChange}\n value={hoursText}\n disabled={readOnly}\n size=\"small\"\n />\n <span className=\"component-time-separator\">:</span>\n <Input\n className={classnames(\"components-time-input\", \"components-input\")}\n onKeyDown={handleMinutesOnKeyDown}\n onBlur={handleMinutesOnBlur}\n onChange={handleMinutesChange}\n value={minutesText}\n disabled={readOnly}\n size=\"small\"\n />\n {showSeconds && (\n <>\n <span className=\"component-time-separator\">:</span>\n <Input\n className={classnames(\"components-time-input\", \"components-input\")}\n onKeyDown={handleSecondsOnKeyDown}\n onBlur={handleSecondsOnBlur}\n onChange={handleSecondsChange}\n value={secondsText}\n disabled={readOnly}\n size=\"small\"\n />\n </>\n )}\n {dayPeriodText && (\n <Input\n className={classnames(\n \"components-time-period-input\",\n \"components-input\"\n )}\n onKeyDown={handleDayPeriodOnKeyDown}\n onBlur={handleDayPeriodOnBlur}\n onChange={handleDayPeriodChange}\n value={dayPeriodText}\n disabled={readOnly}\n size=\"small\"\n />\n )}\n </div>\n );\n}\n"]}
|
|
@@ -61,11 +61,12 @@ class CustomNumberEditor extends React.PureComponent {
|
|
|
61
61
|
this._applyUpdatedValue(e.target.value);
|
|
62
62
|
};
|
|
63
63
|
this._onKeyPress = (e) => {
|
|
64
|
+
var _a;
|
|
64
65
|
// istanbul ignore else
|
|
65
66
|
if (e.key === ts_key_enum_1.Key.Escape.valueOf()) {
|
|
66
|
-
const initialDisplayValue = (this._lastValidValue &&
|
|
67
|
-
this._lastValidValue.displayValue)
|
|
68
|
-
|
|
67
|
+
const initialDisplayValue = (_a = (this._lastValidValue &&
|
|
68
|
+
this._lastValidValue.displayValue)) !== null && _a !== void 0 ? _a :
|
|
69
|
+
/* istanbul ignore next */ this._getInitialDisplayValue();
|
|
69
70
|
if (initialDisplayValue !== this.state.inputValue) {
|
|
70
71
|
e.preventDefault();
|
|
71
72
|
e.stopPropagation();
|
|
@@ -260,9 +261,10 @@ class CustomNumberEditor extends React.PureComponent {
|
|
|
260
261
|
});
|
|
261
262
|
}
|
|
262
263
|
_resetToLastValidDisplayValue() {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
264
|
+
var _a;
|
|
265
|
+
const initialDisplayValue = (_a = (this._lastValidValue &&
|
|
266
|
+
this._lastValidValue.displayValue)) !== null && _a !== void 0 ? _a :
|
|
267
|
+
/* istanbul ignore next */ this._getInitialDisplayValue();
|
|
266
268
|
this.setState({ inputValue: initialDisplayValue });
|
|
267
269
|
}
|
|
268
270
|
/** @internal */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomNumberEditor.js","sourceRoot":"","sources":["../../../../src/components-react/editors/CustomNumberEditor.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oCAAoC;AAEpC,qCAAmC;AACnC,4DAAoC;AACpC,6CAA+B;AAC/B,6CAAkC;AAClC,sDAA6C;AAU7C,0DAO+B;AAC/B,kDAAoD;AACpD,wDAA6C;AAI7C,kDAA+C;AAE/C,mEAGiC;AAUjC;;GAEG;AACH,MAAa,kBACX,SAAQ,KAAK,CAAC,aAA2D;IAD3E;;QAIU,eAAU,GAAG,KAAK,CAAC;QAEnB,kBAAa,GAAG,KAAK,CAAC,SAAS,EAAoB,CAAC;QAG5D,gBAAgB;QACS,UAAK,GAAsC;YAClE,UAAU,EAAE,EAAE;SACf,CAAC;QA6GM,sBAAiB,GAAG,CAAC,CAAsC,EAAE,EAAE;YACrE,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC,CAAC;QAoIM,gBAAW,GAAG,CAAC,CAAwC,EAAE,EAAE;YACjE,uBAAuB;YACvB,IAAI,CA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;YAC5B,QAAQ,EAAE,IAAI,CAAC,iBAAiB;YAChC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM;YACzB,OAAO,EAAE,IAAI,CAAC,QAAQ;YACtB,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE;YAChC,SAAS,EAAE,IAAI,CAAC,WAAW;SAC5B,CAAC;QAEF,IAAI,SAA0B,CAAC;QAC/B,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;YACvB,MAAM,IAAI,GAAG,oBAAC,iBAAI,IAAC,QAAQ,EAAE,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAI,CAAC;YACrD,SAAS,GAAG,CACV,oBAAC,sBAAS,OACJ,UAAU,EACd,GAAG,EAAE,IAAI,CAAC,aAAa,EACvB,IAAI,EAAE,IAAI,iBACE,gCAAgC,GAC5C,CACH,CAAC;SACH;aAAM;YACL,uFAAuF;YACvF,SAAS,GAAG,CACV,oBAAC,qBAAK,OACA,UAAU,EACd,GAAG,EAAE,IAAI,CAAC,aAAa,iBACX,gCAAgC,EAC5C,IAAI,EAAC,OAAO,GACZ,CACH,CAAC;SACH;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AApVD,gDAoVC;AAED;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,0CAAkB;IAChE,IAAW,SAAS;QAClB,OAAO,oBAAC,kBAAkB,OAAG,CAAC;IAChC,CAAC;IACD,IAAoB,sBAAsB;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAPD,gEAOC;AACD,6CAAqB,CAAC,cAAc,CAClC,kCAAiB,CAAC,MAAM,EACxB,0BAA0B,EAC1B,oCAAmB,CAAC,YAAY,CACjC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\n// cSpell:ignore customnumber testid\n\nimport \"./CustomNumberEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport { Logger } from \"@itwin/core-bentley\";\nimport type {\n CustomFormattedNumberParams,\n IconEditorParams,\n InputEditorSizeParams,\n PrimitiveValue,\n PropertyEditorParams,\n PropertyRecord,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport {\n MessageSeverity,\n PropertyEditorParamTypes,\n PropertyValueFormat,\n StandardEditorNames,\n StandardTypeNames,\n UiAdmin,\n} from \"@itwin/appui-abstract\";\nimport { Icon, IconInput } from \"@itwin/core-react\";\nimport { Input } from \"@itwin/itwinui-react\";\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Input>;\n\nimport { UiComponents } from \"../UiComponents\";\nimport type { PropertyEditorProps, TypeEditor } from \"./EditorContainer\";\nimport {\n PropertyEditorBase,\n PropertyEditorManager,\n} from \"./PropertyEditorManager\";\n\n/** @internal */\ninterface CustomNumberEditorState {\n inputValue: string;\n size?: number;\n maxLength?: number;\n iconSpec?: string;\n}\n\n/** CustomNumberEditor is a React component that is a property editor for numbers that specify custom formatting and parsing functions.\n * @alpha\n */\nexport class CustomNumberEditor\n extends React.PureComponent<PropertyEditorProps, CustomNumberEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _formatParams: CustomFormattedNumberParams | undefined;\n private _inputElement = React.createRef<HTMLInputElement>();\n private _lastValidValue: PropertyValue | undefined;\n\n /** @internal */\n public override readonly state: Readonly<CustomNumberEditorState> = {\n inputValue: \"\",\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord as PropertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record.isReadonly) {\n return {\n valueFormat: PropertyValueFormat.Primitive,\n value: (record.value as PrimitiveValue).value,\n displayValue: (record.value as PrimitiveValue).displayValue,\n };\n }\n\n // istanbul ignore else\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n const parseResults = (\n this._formatParams as CustomFormattedNumberParams\n ).parseFunction(this.state.inputValue);\n if (!parseResults.parseError && undefined !== parseResults.value) {\n const newDisplayValue = (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(parseResults.value as number);\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: parseResults.value,\n displayValue: newDisplayValue,\n };\n this._lastValidValue = { ...propertyValue };\n // make sure the text in the input item matches the latest formatted text... this could get out if the input string say 1.5 === the display string of 1'-6\"\n // istanbul ignore else\n if (newDisplayValue !== this.state.inputValue) {\n this.setState({ inputValue: newDisplayValue });\n }\n } else {\n // istanbul ignore else\n if (this.htmlElement) {\n UiAdmin.messagePresenter.displayInputFieldMessage(\n this.htmlElement,\n MessageSeverity.Error,\n parseResults.parseError\n ? parseResults.parseError\n : /* istanbul ignore next */ UiComponents.translate(\n \"errors.unable-to-parse-quantity\"\n )\n );\n this.htmlElement.focus();\n } else {\n UiAdmin.messagePresenter.displayMessage(\n MessageSeverity.Error,\n parseResults.parseError\n ? parseResults.parseError\n : /* istanbul ignore next */ UiComponents.translate(\n \"errors.unable-to-parse-quantity\"\n )\n );\n }\n\n const displayValue =\n record.value.displayValue && record.value.displayValue.length > 0\n ? record.value.displayValue\n : /* istanbul ignore next */ (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(record.value.value as number);\n propertyValue = this._lastValidValue\n ? { ...this._lastValidValue }\n : /* istanbul ignore next */ {\n valueFormat: PropertyValueFormat.Primitive,\n value: record.value.value,\n displayValue,\n };\n }\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._inputElement.current;\n }\n\n public get hasFocus(): boolean {\n return document.activeElement === this._inputElement.current;\n }\n\n private shouldSetFocus(): boolean {\n if (!this.props.setFocus) return false;\n\n const record = this.props.propertyRecord as PropertyRecord;\n const disabled = record && !record.isDisabled ? false : true;\n const readonly = record && !record.isReadonly ? false : true;\n\n return !disabled && !readonly;\n }\n\n private _applyUpdatedValue(userInput: string) {\n const record = this.props.propertyRecord as PropertyRecord;\n const readonly = record && !record.isReadonly ? false : true;\n const disabled = record && !record.isDisabled ? false : true;\n\n if (readonly || disabled) return;\n\n // istanbul ignore else\n if (this._isMounted)\n this.setState({\n inputValue: userInput,\n });\n }\n\n private _updateInputValue = (e: React.ChangeEvent<HTMLInputElement>) => {\n this._applyUpdatedValue(e.target.value);\n };\n\n /** @internal */\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n /** @internal */\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private _getInitialDisplayValue(): string {\n const record = this.props.propertyRecord;\n let initialDisplayValue = \"\";\n let numberValue = 0;\n // istanbul ignore else\n if (record) {\n // istanbul ignore else\n if (record.value.valueFormat === PropertyValueFormat.Primitive) {\n const primitiveValue = record.value;\n numberValue =\n undefined !== primitiveValue.value\n ? (primitiveValue.value as number)\n : /* istanbul ignore next */ 0;\n // istanbul ignore else\n if (primitiveValue.displayValue)\n initialDisplayValue = primitiveValue.displayValue;\n else\n initialDisplayValue = (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(numberValue);\n }\n }\n\n return initialDisplayValue;\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n // istanbul ignore next\n if (!record || !record.property) {\n Logger.logError(\n UiComponents.loggerCategory(this),\n \"PropertyRecord must be defined to use CustomNumberPropertyEditor\"\n );\n return;\n }\n // istanbul ignore else\n if (\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n this._formatParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type ===\n PropertyEditorParamTypes.CustomFormattedNumber.valueOf()\n ) as CustomFormattedNumberParams;\n }\n\n if (!this._formatParams) {\n Logger.logError(\n UiComponents.loggerCategory(this),\n `CustomFormattedNumberParams must be defined for property ${record.property.name}`\n );\n return;\n }\n\n const initialDisplayValue = this._getInitialDisplayValue();\n this._lastValidValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: (record.value as PrimitiveValue).value,\n displayValue: initialDisplayValue,\n };\n let size: number | undefined;\n let maxLength: number | undefined;\n let iconSpec: string | undefined;\n\n // istanbul ignore else\n if (\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n const editorSizeParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.InputEditorSize.valueOf()\n ) as InputEditorSizeParams;\n // istanbul ignore else\n if (editorSizeParams) {\n // istanbul ignore else\n if (editorSizeParams.size) size = editorSizeParams.size;\n // istanbul ignore else\n if (editorSizeParams.maxLength) maxLength = editorSizeParams.maxLength;\n }\n\n const iconParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.Icon.valueOf()\n ) as IconEditorParams;\n if (iconParams) {\n iconSpec = iconParams.definition.iconSpec;\n }\n }\n\n // istanbul ignore else\n if (this._isMounted)\n this.setState({\n inputValue: initialDisplayValue,\n size,\n maxLength,\n iconSpec,\n });\n }\n\n private _resetToLastValidDisplayValue() {\n const initialDisplayValue =\n (this._lastValidValue &&\n (this._lastValidValue as PrimitiveValue).displayValue) ??\n /* istanbul ignore next */ this._getInitialDisplayValue();\n this.setState({ inputValue: initialDisplayValue });\n }\n\n private _onKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (e.key === Key.Escape.valueOf()) {\n const initialDisplayValue =\n (this._lastValidValue &&\n (this._lastValidValue as PrimitiveValue).displayValue) ??\n /* istanbul ignore next */ this._getInitialDisplayValue();\n if (initialDisplayValue !== this.state.inputValue) {\n e.preventDefault();\n e.stopPropagation();\n this._resetToLastValidDisplayValue();\n } else {\n // istanbul ignore else\n if (this.props.onCancel) this.props.onCancel();\n }\n }\n\n // istanbul ignore else\n if (e.key !== Key.Enter.valueOf()) {\n UiAdmin.messagePresenter.closeInputFieldMessage();\n }\n };\n\n // istanbul ignore next\n private _onFocus = (e: React.FocusEvent<HTMLInputElement>) => {\n e.target.select();\n };\n\n /** @internal */\n public override render(): React.ReactNode {\n const minSize = this.state.size ? this.state.size : 8;\n const minWidthStyle: React.CSSProperties = {\n minWidth: `${minSize * 0.75}em`,\n };\n const record = this.props.propertyRecord as PropertyRecord;\n if (!record || !this._formatParams) return null;\n\n const readOnly = !record.isReadonly ? false : true;\n const disabled = !record.isDisabled ? false : true;\n\n const className = classnames(\n \"components-cell-editor\",\n \"components-customnumber-editor\",\n this.props.className\n );\n\n const inputProps: Omit<InputProps, \"size\"> = {\n className,\n style: this.props.style ? this.props.style : minWidthStyle,\n readOnly,\n disabled,\n maxLength: this.state.maxLength,\n value: this.state.inputValue,\n onChange: this._updateInputValue,\n onBlur: this.props.onBlur,\n onFocus: this._onFocus,\n autoFocus: this.shouldSetFocus(),\n onKeyDown: this._onKeyPress,\n };\n\n let reactNode: React.ReactNode;\n if (this.state.iconSpec) {\n const icon = <Icon iconSpec={this.state.iconSpec} />;\n reactNode = (\n <IconInput\n {...inputProps}\n ref={this._inputElement}\n icon={icon}\n data-testid=\"components-customnumber-editor\"\n />\n );\n } else {\n // NEEDSWORK: still using core-react Input component because of `nativeKeyHandler` prop\n reactNode = (\n <Input\n {...inputProps}\n ref={this._inputElement}\n data-testid=\"components-customnumber-editor\"\n size=\"small\"\n />\n );\n }\n\n return reactNode;\n }\n}\n\n/** Custom Property Editor registered for the \"number\" type name and the \"number-custom\" editor name.\n * It uses the [[CustomNumberEditor]] React component.\n * @alpha\n */\nexport class CustomNumberPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <CustomNumberEditor />;\n }\n public override get containerHandlesEscape(): boolean {\n return false;\n }\n}\nPropertyEditorManager.registerEditor(\n StandardTypeNames.Number,\n CustomNumberPropertyEditor,\n StandardEditorNames.NumberCustom\n);\n"]}
|
|
1
|
+
{"version":3,"file":"CustomNumberEditor.js","sourceRoot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AI,iBACE,gCAAgC,GAC5C,CACH,CAAC;SACH;aAAM;YACL,uFAAuF;YACvF,SAAS,GAAG,CACV,oBAAC,qBAAK,OACA,UAAU,EACd,GAAG,EAAE,IAAI,CAAC,aAAa,iBACX,gCAAgC,EAC5C,IAAI,EAAC,OAAO,GACZ,CACH,CAAC;SACH;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AApVD,gDAoVC;AAED;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,0CAAkB;IAChE,IAAW,SAAS;QAClB,OAAO,oBAAC,kBAAkB,OAAG,CAAC;IAChC,CAAC;IACD,IAAoB,sBAAsB;QACxC,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAPD,gEAOC;AACD,6CAAqB,CAAC,cAAc,CAClC,kCAAiB,CAAC,MAAM,EACxB,0BAA0B,EAC1B,oCAAmB,CAAC,YAAY,CACjC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module PropertyEditors\n */\n\n// cSpell:ignore customnumber testid\n\nimport \"./CustomNumberEditor.scss\";\nimport classnames from \"classnames\";\nimport * as React from \"react\";\nimport { Key } from \"ts-key-enum\";\nimport { Logger } from \"@itwin/core-bentley\";\nimport type {\n CustomFormattedNumberParams,\n IconEditorParams,\n InputEditorSizeParams,\n PrimitiveValue,\n PropertyEditorParams,\n PropertyRecord,\n PropertyValue,\n} from \"@itwin/appui-abstract\";\nimport {\n MessageSeverity,\n PropertyEditorParamTypes,\n PropertyValueFormat,\n StandardEditorNames,\n StandardTypeNames,\n UiAdmin,\n} from \"@itwin/appui-abstract\";\nimport { Icon, IconInput } from \"@itwin/core-react\";\nimport { Input } from \"@itwin/itwinui-react\";\n\ntype InputProps = React.ComponentPropsWithoutRef<typeof Input>;\n\nimport { UiComponents } from \"../UiComponents\";\nimport type { PropertyEditorProps, TypeEditor } from \"./EditorContainer\";\nimport {\n PropertyEditorBase,\n PropertyEditorManager,\n} from \"./PropertyEditorManager\";\n\n/** @internal */\ninterface CustomNumberEditorState {\n inputValue: string;\n size?: number;\n maxLength?: number;\n iconSpec?: string;\n}\n\n/** CustomNumberEditor is a React component that is a property editor for numbers that specify custom formatting and parsing functions.\n * @alpha\n */\nexport class CustomNumberEditor\n extends React.PureComponent<PropertyEditorProps, CustomNumberEditorState>\n implements TypeEditor\n{\n private _isMounted = false;\n private _formatParams: CustomFormattedNumberParams | undefined;\n private _inputElement = React.createRef<HTMLInputElement>();\n private _lastValidValue: PropertyValue | undefined;\n\n /** @internal */\n public override readonly state: Readonly<CustomNumberEditorState> = {\n inputValue: \"\",\n };\n\n public async getPropertyValue(): Promise<PropertyValue | undefined> {\n const record = this.props.propertyRecord as PropertyRecord;\n let propertyValue: PropertyValue | undefined;\n\n if (record.isReadonly) {\n return {\n valueFormat: PropertyValueFormat.Primitive,\n value: (record.value as PrimitiveValue).value,\n displayValue: (record.value as PrimitiveValue).displayValue,\n };\n }\n\n // istanbul ignore else\n if (record && record.value.valueFormat === PropertyValueFormat.Primitive) {\n const parseResults = (\n this._formatParams as CustomFormattedNumberParams\n ).parseFunction(this.state.inputValue);\n if (!parseResults.parseError && undefined !== parseResults.value) {\n const newDisplayValue = (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(parseResults.value as number);\n propertyValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: parseResults.value,\n displayValue: newDisplayValue,\n };\n this._lastValidValue = { ...propertyValue };\n // make sure the text in the input item matches the latest formatted text... this could get out if the input string say 1.5 === the display string of 1'-6\"\n // istanbul ignore else\n if (newDisplayValue !== this.state.inputValue) {\n this.setState({ inputValue: newDisplayValue });\n }\n } else {\n // istanbul ignore else\n if (this.htmlElement) {\n UiAdmin.messagePresenter.displayInputFieldMessage(\n this.htmlElement,\n MessageSeverity.Error,\n parseResults.parseError\n ? parseResults.parseError\n : /* istanbul ignore next */ UiComponents.translate(\n \"errors.unable-to-parse-quantity\"\n )\n );\n this.htmlElement.focus();\n } else {\n UiAdmin.messagePresenter.displayMessage(\n MessageSeverity.Error,\n parseResults.parseError\n ? parseResults.parseError\n : /* istanbul ignore next */ UiComponents.translate(\n \"errors.unable-to-parse-quantity\"\n )\n );\n }\n\n const displayValue =\n record.value.displayValue && record.value.displayValue.length > 0\n ? record.value.displayValue\n : /* istanbul ignore next */ (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(record.value.value as number);\n propertyValue = this._lastValidValue\n ? { ...this._lastValidValue }\n : /* istanbul ignore next */ {\n valueFormat: PropertyValueFormat.Primitive,\n value: record.value.value,\n displayValue,\n };\n }\n }\n\n return propertyValue;\n }\n\n public get htmlElement(): HTMLElement | null {\n return this._inputElement.current;\n }\n\n public get hasFocus(): boolean {\n return document.activeElement === this._inputElement.current;\n }\n\n private shouldSetFocus(): boolean {\n if (!this.props.setFocus) return false;\n\n const record = this.props.propertyRecord as PropertyRecord;\n const disabled = record && !record.isDisabled ? false : true;\n const readonly = record && !record.isReadonly ? false : true;\n\n return !disabled && !readonly;\n }\n\n private _applyUpdatedValue(userInput: string) {\n const record = this.props.propertyRecord as PropertyRecord;\n const readonly = record && !record.isReadonly ? false : true;\n const disabled = record && !record.isDisabled ? false : true;\n\n if (readonly || disabled) return;\n\n // istanbul ignore else\n if (this._isMounted)\n this.setState({\n inputValue: userInput,\n });\n }\n\n private _updateInputValue = (e: React.ChangeEvent<HTMLInputElement>) => {\n this._applyUpdatedValue(e.target.value);\n };\n\n /** @internal */\n public override componentDidMount() {\n this._isMounted = true;\n void this.setStateFromProps();\n }\n\n /** @internal */\n public override componentWillUnmount() {\n this._isMounted = false;\n }\n\n /** @internal */\n public override componentDidUpdate(prevProps: PropertyEditorProps) {\n if (this.props.propertyRecord !== prevProps.propertyRecord) {\n void this.setStateFromProps();\n }\n }\n\n private _getInitialDisplayValue(): string {\n const record = this.props.propertyRecord;\n let initialDisplayValue = \"\";\n let numberValue = 0;\n // istanbul ignore else\n if (record) {\n // istanbul ignore else\n if (record.value.valueFormat === PropertyValueFormat.Primitive) {\n const primitiveValue = record.value;\n numberValue =\n undefined !== primitiveValue.value\n ? (primitiveValue.value as number)\n : /* istanbul ignore next */ 0;\n // istanbul ignore else\n if (primitiveValue.displayValue)\n initialDisplayValue = primitiveValue.displayValue;\n else\n initialDisplayValue = (\n this._formatParams as CustomFormattedNumberParams\n ).formatFunction(numberValue);\n }\n }\n\n return initialDisplayValue;\n }\n\n private async setStateFromProps() {\n const record = this.props.propertyRecord;\n // istanbul ignore next\n if (!record || !record.property) {\n Logger.logError(\n UiComponents.loggerCategory(this),\n \"PropertyRecord must be defined to use CustomNumberPropertyEditor\"\n );\n return;\n }\n // istanbul ignore else\n if (\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n this._formatParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type ===\n PropertyEditorParamTypes.CustomFormattedNumber.valueOf()\n ) as CustomFormattedNumberParams;\n }\n\n if (!this._formatParams) {\n Logger.logError(\n UiComponents.loggerCategory(this),\n `CustomFormattedNumberParams must be defined for property ${record.property.name}`\n );\n return;\n }\n\n const initialDisplayValue = this._getInitialDisplayValue();\n this._lastValidValue = {\n valueFormat: PropertyValueFormat.Primitive,\n value: (record.value as PrimitiveValue).value,\n displayValue: initialDisplayValue,\n };\n let size: number | undefined;\n let maxLength: number | undefined;\n let iconSpec: string | undefined;\n\n // istanbul ignore else\n if (\n record.property &&\n record.property.editor &&\n record.property.editor.params\n ) {\n const editorSizeParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.InputEditorSize.valueOf()\n ) as InputEditorSizeParams;\n // istanbul ignore else\n if (editorSizeParams) {\n // istanbul ignore else\n if (editorSizeParams.size) size = editorSizeParams.size;\n // istanbul ignore else\n if (editorSizeParams.maxLength) maxLength = editorSizeParams.maxLength;\n }\n\n const iconParams = record.property.editor.params.find(\n (param: PropertyEditorParams) =>\n param.type === PropertyEditorParamTypes.Icon.valueOf()\n ) as IconEditorParams;\n if (iconParams) {\n iconSpec = iconParams.definition.iconSpec;\n }\n }\n\n // istanbul ignore else\n if (this._isMounted)\n this.setState({\n inputValue: initialDisplayValue,\n size,\n maxLength,\n iconSpec,\n });\n }\n\n private _resetToLastValidDisplayValue() {\n const initialDisplayValue =\n (this._lastValidValue &&\n (this._lastValidValue as PrimitiveValue).displayValue) ??\n /* istanbul ignore next */ this._getInitialDisplayValue();\n this.setState({ inputValue: initialDisplayValue });\n }\n\n private _onKeyPress = (e: React.KeyboardEvent<HTMLInputElement>) => {\n // istanbul ignore else\n if (e.key === Key.Escape.valueOf()) {\n const initialDisplayValue =\n (this._lastValidValue &&\n (this._lastValidValue as PrimitiveValue).displayValue) ??\n /* istanbul ignore next */ this._getInitialDisplayValue();\n if (initialDisplayValue !== this.state.inputValue) {\n e.preventDefault();\n e.stopPropagation();\n this._resetToLastValidDisplayValue();\n } else {\n // istanbul ignore else\n if (this.props.onCancel) this.props.onCancel();\n }\n }\n\n // istanbul ignore else\n if (e.key !== Key.Enter.valueOf()) {\n UiAdmin.messagePresenter.closeInputFieldMessage();\n }\n };\n\n // istanbul ignore next\n private _onFocus = (e: React.FocusEvent<HTMLInputElement>) => {\n e.target.select();\n };\n\n /** @internal */\n public override render(): React.ReactNode {\n const minSize = this.state.size ? this.state.size : 8;\n const minWidthStyle: React.CSSProperties = {\n minWidth: `${minSize * 0.75}em`,\n };\n const record = this.props.propertyRecord as PropertyRecord;\n if (!record || !this._formatParams) return null;\n\n const readOnly = !record.isReadonly ? false : true;\n const disabled = !record.isDisabled ? false : true;\n\n const className = classnames(\n \"components-cell-editor\",\n \"components-customnumber-editor\",\n this.props.className\n );\n\n const inputProps: Omit<InputProps, \"size\"> = {\n className,\n style: this.props.style ? this.props.style : minWidthStyle,\n readOnly,\n disabled,\n maxLength: this.state.maxLength,\n value: this.state.inputValue,\n onChange: this._updateInputValue,\n onBlur: this.props.onBlur,\n onFocus: this._onFocus,\n autoFocus: this.shouldSetFocus(),\n onKeyDown: this._onKeyPress,\n };\n\n let reactNode: React.ReactNode;\n if (this.state.iconSpec) {\n const icon = <Icon iconSpec={this.state.iconSpec} />;\n reactNode = (\n <IconInput\n {...inputProps}\n ref={this._inputElement}\n icon={icon}\n data-testid=\"components-customnumber-editor\"\n />\n );\n } else {\n // NEEDSWORK: still using core-react Input component because of `nativeKeyHandler` prop\n reactNode = (\n <Input\n {...inputProps}\n ref={this._inputElement}\n data-testid=\"components-customnumber-editor\"\n size=\"small\"\n />\n );\n }\n\n return reactNode;\n }\n}\n\n/** Custom Property Editor registered for the \"number\" type name and the \"number-custom\" editor name.\n * It uses the [[CustomNumberEditor]] React component.\n * @alpha\n */\nexport class CustomNumberPropertyEditor extends PropertyEditorBase {\n public get reactNode(): React.ReactNode {\n return <CustomNumberEditor />;\n }\n public override get containerHandlesEscape(): boolean {\n return false;\n }\n}\nPropertyEditorManager.registerEditor(\n StandardTypeNames.Number,\n CustomNumberPropertyEditor,\n StandardEditorNames.NumberCustom\n);\n"]}
|
|
@@ -169,6 +169,7 @@ class DateTimeEditor extends React.PureComponent {
|
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
async setStateFromProps() {
|
|
172
|
+
var _a, _b;
|
|
172
173
|
const record = this.props.propertyRecord;
|
|
173
174
|
let initialValue;
|
|
174
175
|
let typeConverter;
|
|
@@ -187,8 +188,8 @@ class DateTimeEditor extends React.PureComponent {
|
|
|
187
188
|
initialValue = new Date(record.value.value);
|
|
188
189
|
else if (record.value.value === undefined)
|
|
189
190
|
initialValue = new Date();
|
|
190
|
-
typeConverter = TypeConverterManager_1.TypeConverterManager.getConverter(record.property.typename, record.property.converter
|
|
191
|
-
const options = record.property.converter
|
|
191
|
+
typeConverter = TypeConverterManager_1.TypeConverterManager.getConverter(record.property.typename, (_a = record.property.converter) === null || _a === void 0 ? void 0 : _a.name);
|
|
192
|
+
const options = (_b = record.property.converter) === null || _b === void 0 ? void 0 : _b.options;
|
|
192
193
|
if (options) {
|
|
193
194
|
// istanbul ignore else
|
|
194
195
|
if ("alternateDateFormat" in options) {
|
|
@@ -270,7 +271,8 @@ class DateTimeEditor extends React.PureComponent {
|
|
|
270
271
|
React.createElement(PopupButton_1.PopupContent, null,
|
|
271
272
|
React.createElement(React.Fragment, null,
|
|
272
273
|
React.createElement("div", { className: "components-date-picker-calendar-popup-panel", "data-testid": "components-date-picker-calendar-popup-panel" },
|
|
273
|
-
React.createElement(DatePicker_1.DatePicker
|
|
274
|
+
React.createElement(DatePicker_1.DatePicker // eslint-disable-line deprecation/deprecation
|
|
275
|
+
, { selected: date, onDateChange: this._handleChange, showFocusOutline: false }),
|
|
274
276
|
this.state.timeDisplay && (React.createElement("div", { className: "time-container" },
|
|
275
277
|
React.createElement(itwinui_react_1.Text, { variant: "body", className: "time-label" }, "Time"),
|
|
276
278
|
React.createElement(TimeField_1.TimeField, { time: timeSpec, timeDisplay: this.state.timeDisplay, onTimeChange: this._handleTimeChange }))))),
|