Skip to content

Commit

Permalink
Fix post-rebase typing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Jun 23, 2022
1 parent f0d1336 commit a304615
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function useBorderControl(
);

const onSliderChange = useCallback(
( value: number ) => {
( value?: number ) => {
onWidthChange( `${ value }${ widthUnit }` );
},
[ onWidthChange, widthUnit ]
Expand Down
16 changes: 8 additions & 8 deletions packages/components/src/color-picker/hsl-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export const HslInput = ( { color, onChange, enableAlpha }: HslInputProps ) => {
label="Hue"
abbreviation="H"
value={ h }
onChange={ ( nextH: number ) => {
onChange( colord( { h: nextH, s, l, a } ) );
onChange={ ( nextH?: number ) => {
onChange( colord( { h: nextH as number, s, l, a } ) );
} }
/>
<InputWithSlider
Expand All @@ -35,11 +35,11 @@ export const HslInput = ( { color, onChange, enableAlpha }: HslInputProps ) => {
label="Saturation"
abbreviation="S"
value={ s }
onChange={ ( nextS: number ) => {
onChange={ ( nextS?: number ) => {
onChange(
colord( {
h,
s: nextS,
s: nextS as number,
l,
a,
} )
Expand All @@ -52,12 +52,12 @@ export const HslInput = ( { color, onChange, enableAlpha }: HslInputProps ) => {
label="Lightness"
abbreviation="L"
value={ l }
onChange={ ( nextL: number ) => {
onChange={ ( nextL?: number ) => {
onChange(
colord( {
h,
s,
l: nextL,
l: nextL as number,
a,
} )
);
Expand All @@ -70,13 +70,13 @@ export const HslInput = ( { color, onChange, enableAlpha }: HslInputProps ) => {
label="Alpha"
abbreviation="A"
value={ Math.trunc( 100 * a ) }
onChange={ ( nextA: number ) => {
onChange={ ( nextA?: number ) => {
onChange(
colord( {
h,
s,
l,
a: nextA / 100,
a: ( nextA as number ) / 100,
} )
);
} }
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/color-picker/input-with-slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface InputWithSliderProps {
value: number;
label: string;
abbreviation: string;
onChange: ( value: number ) => void;
onChange: ( value?: number ) => void;
}

export const InputWithSlider = ( {
Expand Down
16 changes: 8 additions & 8 deletions packages/components/src/color-picker/rgb-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export const RgbInput = ( { color, onChange, enableAlpha }: RgbInputProps ) => {
label="Red"
abbreviation="R"
value={ r }
onChange={ ( nextR: number ) =>
onChange( colord( { r: nextR, g, b, a } ) )
onChange={ ( nextR?: number ) =>
onChange( colord( { r: nextR as number, g, b, a } ) )
}
/>
<InputWithSlider
Expand All @@ -35,8 +35,8 @@ export const RgbInput = ( { color, onChange, enableAlpha }: RgbInputProps ) => {
label="Green"
abbreviation="G"
value={ g }
onChange={ ( nextG: number ) =>
onChange( colord( { r, g: nextG, b, a } ) )
onChange={ ( nextG?: number ) =>
onChange( colord( { r, g: nextG as number, b, a } ) )
}
/>
<InputWithSlider
Expand All @@ -45,8 +45,8 @@ export const RgbInput = ( { color, onChange, enableAlpha }: RgbInputProps ) => {
label="Blue"
abbreviation="B"
value={ b }
onChange={ ( nextB: number ) =>
onChange( colord( { r, g, b: nextB, a } ) )
onChange={ ( nextB?: number ) =>
onChange( colord( { r, g, b: nextB as number, a } ) )
}
/>
{ enableAlpha && (
Expand All @@ -56,13 +56,13 @@ export const RgbInput = ( { color, onChange, enableAlpha }: RgbInputProps ) => {
label="Alpha"
abbreviation="A"
value={ Math.trunc( a * 100 ) }
onChange={ ( nextA: number ) =>
onChange={ ( nextA?: number ) =>
onChange(
colord( {
r,
g,
b,
a: nextA / 100,
a: ( nextA as number ) / 100,
} )
)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/range-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ Callback for when `RangeControl` input loses focus.
- Required: No
- Platform: Web

### `onChange`: `FocusEventHandler< HTMLInputElement >`
### `onChange`: `( value?: number ) => void`

A function that receives the new value. The value will be less than `max` and more than `min` unless a reset (enabled by `allowReset`) has occurred. In which case the value will be either that of `resetFallbackValue` if it has been specified or otherwise `undefined`.

Expand Down
6 changes: 4 additions & 2 deletions packages/components/src/range-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,18 @@ function UnforwardedRangeControl< IconProps = unknown >(
};

const handleOnChange = ( next: string ) => {
let nextValue: number | null = parseFloat( next );
let nextValue = parseFloat( next );
setValue( nextValue );

/*
* Calls onChange only when nextValue is numeric
* otherwise may queue a reset for the blur event.
*/
if ( ! isNaN( nextValue ) ) {
if ( nextValue < min || nextValue > max ) {
nextValue = floatClamp( nextValue, min, max );
nextValue = floatClamp( nextValue, min, max ) as number;
}

onChange( nextValue );
isResetPendent.current = false;
} else if ( allowReset ) {
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/range-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export type RangeControlProps< IconProps = unknown > = Pick<
*
* @default () => void
*/
onChange?: ( value: number ) => void;
onChange?: ( value?: number ) => void;
/**
* Callback for when `RangeControl` input gains focus.
*
Expand Down Expand Up @@ -279,7 +279,7 @@ export type useControlledRangeValueProps = {

export type useControlledRangeValueReturn = [
number | '' | null,
( nextValue: any ) => void
( nextValue: number | null ) => void
];

export type useMarksArgs = NumericProps & {
Expand Down
9 changes: 6 additions & 3 deletions packages/components/src/range-control/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// @ts-nocheck
/**
* External dependencies
*/
import type { MouseEventHandler } from 'react';

/**
* WordPress dependencies
Expand Down Expand Up @@ -86,8 +89,8 @@ export function useControlledRangeValue( {
*/
export function useDebouncedHoverInteraction( {
onHide = noop,
onMouseLeave = noop,
onMouseMove = noop,
onMouseLeave = noop as MouseEventHandler,
onMouseMove = noop as MouseEventHandler,
onShow = noop,
timeout = 300,
} ) {
Expand Down

0 comments on commit a304615

Please sign in to comment.