Skip to content

Commit

Permalink
Added optional range.decimals to be validated for NumberInlineInput (#…
Browse files Browse the repository at this point in the history
…100)

* Added optional range.decimals to be validated for NumberInlineInput

* prettier thing
  • Loading branch information
bencefr authored Sep 29, 2020
1 parent 051c655 commit 6067c4c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
5 changes: 5 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 4.9.6
### Added
- Added optional range.decimals to be validated for NumberInlineInput
- Updated index.d.ts with rangeShape

## 4.9.5
### Fixed
- More type enhancements:
Expand Down
16 changes: 8 additions & 8 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,16 @@ declare module 'pc-nrfconnect-shared' {

// Slider.jsx

interface rangeShape {
min: number;
max: number;
decimals?: number;
}

export class SliderProps {
id?: string;
values: readonly number[];
range: {
min: number;
max: number;
};
range: rangeShape;
onChange: readonly ((value: number) => void)[];
onChangeComplete?: () => void;
}
Expand Down Expand Up @@ -330,10 +333,7 @@ declare module 'pc-nrfconnect-shared' {

interface NumberInlineInputProps {
value: number;
range: {
min: number;
max: number;
};
range: rangeShape;
onChange: (value: number) => void;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pc-nrfconnect-shared",
"version": "4.9.5",
"version": "4.9.6",
"description": "Shared commodities for developing pc-nrfconnect-* packages",
"repository": {
"type": "git",
Expand Down
11 changes: 5 additions & 6 deletions src/InlineInput/NumberInlineInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@
*/

import React from 'react';
import { func, number, shape } from 'prop-types';
import { func, number } from 'prop-types';

import InlineInput from './InlineInput';
import rangeShape from '../Slider/rangeShape';

import './number-inline-input.scss';

const charCount = value => String(value).length + 1;
const isInRange = (value, { min, max }) => value >= min && value <= max;
const isInRange = (value, { min, max, decimals = 0 }) =>
value >= min && value <= max && value === Number(value.toFixed(decimals));

const NumberInlineInput = ({
value,
Expand All @@ -63,10 +65,7 @@ const NumberInlineInput = ({

NumberInlineInput.propTypes = {
value: number.isRequired,
range: shape({
min: number.isRequired,
max: number.isRequired,
}).isRequired,
range: rangeShape.isRequired,
onChange: func.isRequired,
chars: number,
};
Expand Down

0 comments on commit 6067c4c

Please sign in to comment.