Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Nov 23, 2022
1 parent fc4c4cd commit d211a80
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/components/src/number-control/stories/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,23 @@ export const Default = Template.bind( {} );
Default.args = {
label: 'Value',
};

// Check if this was broken and at what point
// in particular on commit actions, when `min` is not `undefined`

export const Uncontrolled = ( { onChange, ...props } ) => {
const [ isValidValue, setIsValidValue ] = useState( true );

return (
<>
<NumberControl
{ ...props }
onChange={ ( v, extra ) => {
setIsValidValue( extra.event.target.validity.valid );
onChange( v, extra );
} }
/>
<p>Is valid? { isValidValue ? 'Yes' : 'No' }</p>
</>
);
};
2 changes: 2 additions & 0 deletions packages/components/src/number-control/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export const computeStep = ( {
baseStep: number;
enableShift?: boolean;
} ) => ( enableShift ? shiftStep * baseStep : baseStep );

// Move spin and constrain here?
2 changes: 2 additions & 0 deletions packages/components/src/utils/test/values.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,5 @@ describe( 'isValueNumeric', () => {
} );
} );
} );

// TODO: ensureNumber / ensureString tests
1 change: 1 addition & 0 deletions packages/components/src/utils/values.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const numberToString = ( value ) => {
* @return {number} The parsed number.
*/
export const ensureNumber = ( value ) => {
// TODO: how to translate empty string?
return typeof value === 'string' ? stringToNumber( value ) : value;
};

Expand Down

0 comments on commit d211a80

Please sign in to comment.