Skip to content

Commit

Permalink
Convert RangeControl to TypeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed May 30, 2022
1 parent 3ac6020 commit 78783d3
Show file tree
Hide file tree
Showing 11 changed files with 582 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function useBorderControl(
);

const onSliderChange = useCallback(
( value: string ) => {
( value: number ) => {
onWidthChange( `${ value }${ widthUnit }` );
},
[ onWidthChange, widthUnit ]
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/icon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { SVG } from '@wordpress/primitives';
import Dashicon from '../dashicon';
import type { IconKey as DashiconIconKey } from '../dashicon/types';

type IconType< P > = DashiconIconKey | ComponentType< P > | JSX.Element;
export type IconType< P > = DashiconIconKey | ComponentType< P > | JSX.Element;

interface BaseProps< P > {
/**
Expand Down
180 changes: 102 additions & 78 deletions packages/components/src/range-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,75 +109,96 @@ const MyRangeControl = () => {
};
```

### Props
## Props

The set of props accepted by the component will be specified below.
Props not included in this set will be applied to the input elements.

#### label
### `afterIcon`: `string|Function|WPComponent|null`

If this property is added, a label will be generated using label property as the content.
If this property is added, a DashIcon component will be rendered after the slider with the icon equal to afterIcon.

- Required: No
- Platform: Web

### `allowReset`: `boolean`

If this property is true, a button to reset the the slider is rendered.

- Type: `String`
- Required: No
- Default: `false`
- Platform: Web | Mobile

#### help
### `beforeIcon`: `string|Function|WPComponent|null`

If this property is added, a help text will be generated using help property as the content.
If this property is added, a DashIcon component will be rendered before the slider with the icon equal to beforeIcon.

- Type: `String|WPElement`
- Required: No
- Platform: Web

#### beforeIcon
### `color`: `CSSProperties['color']`

If this property is added, a DashIcon component will be rendered before the slider with the icon equal to beforeIcon
If supplied, this property sets the `color` for the `RangeControl` wrapper.

- Type: `String`
- Required: No
- Platform: Web

#### afterIcon
### `currentInput`: `number`

If this property is added, a DashIcon component will be rendered after the slider with the icon equal to afterIcon
The current input to use as a fallback if `value` is currently `undefined`.

- Type: `String`
- Required: No
- Platform: Web

#### allowReset
### `disabled`: `boolean`

If this property is true, a button to reset the the slider is rendered.
Disables the `input`, preventing new values from being applied.

- Type: `Boolean`
- Required: No
- Platform: Web | Mobile
- Platform: Web

#### disabled

Disables the `input`, preventing new values from being applied.
### `help`: `string|WPElement`

If this property is added, a help text will be generated using help property as the content.

- Type: `Boolean`
- Required: No
- Platform: Web

#### initialPosition
### `hideLabelFromVision`: `boolean`

Provides control over whether the label will only be visible to screen readers.

- Required: No

### `icon`: `string`

An icon to be shown above the slider next to it's container title.

- Required: No
- Platform: Mobile

### `initialPosition`: `number`

If no value exists this prop contains the slider starting position.

- Type: `Number`
- Required: No
- Platform: Web | Mobile

#### isShiftStepEnabled
### `isShiftStepEnabled`: `boolean`

Passed as a prop to the `NumberControl` component and is only applicable if `withInputField` is true. If true, while the number input has focus, pressing `UP` or `DOWN` along with the `SHIFT` key will change the value by the `shiftStep` value.

- Type: `Boolean`
- Required: No

#### marks
### `label`: `string`

If this property is added, a label will be generated using label property as the content.

- Required: No
- Platform: Web | Mobile

### `marks`: `Array|boolean`

Renders a visual representation of `step` ticks. Custom mark indicators can be provided by an `Array`.

Expand All @@ -204,49 +225,72 @@ const marks = [
];

const MyRangeControl() {
return (<RangeControl marks={ marks } min={ 0 } max={ 10 } step={ 1 } />)
return ( <RangeControl marks={ marks } min={ 0 } max={ 10 } step={ 1 } /> )
}
```

- Type: `Array|Boolean`
- Required: No
- Platform: Web

#### onChange
### `onBlur`: `FocusEventHandler< HTMLInputElement >`

Callback for when `RangeControl` input loses focus.

- Required: No
- Platform: Web

### `onChange`: `FocusEventHandler< HTMLInputElement >`

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`.

- Type: `function`
- Required: Yes
- Required: No
- Platform: Web | Mobile

#### min
### `onFocus`: `FocusEventHandler< HTMLInputElement >`

Callback for when `RangeControl` input gains focus.

- Required: No
- Platform: Web

### `onMouseLeave`: `MouseEventHandler< HTMLInputElement >`

Callback for when mouse exits the `RangeControl`.

- Required: No
- Platform: Web

### `onMouseMove`: `MouseEventHandler< HTMLInputElement >`

Callback for when mouse moves within the `RangeControl`.

- Required: No
- Platform: Web

### `min`: `number`

The minimum `value` allowed.

- Type: `Number`
- Required: No
- Default: 0
- Platform: Web | Mobile

#### max
### `max`: `number`

The maximum `value` allowed.

- Type: `Number`
- Required: No
- Default: 100
- Platform: Web | Mobile

#### railColor
### `railColor`: `CSSProperties[ 'color' ]`

Customizes the (background) color of the rail element.

- Type: `String`
- Required: No
- Platform: Web

#### renderTooltipContent
### `renderTooltipContent`: ( value ) => value

A way to customize the rendered UI of the value. Example:

Expand All @@ -258,89 +302,69 @@ const MyRangeControl() {
}
```

- Type: `Function`
- Required: No
- Platform: Web

#### resetFallbackValue
### `resetFallbackValue`: `number` | `string` | `null`

The value to revert to if the Reset button is clicked (enabled by `allowReset`)

- Type: `Number`
- Required: No
- Platform: Web

#### showTooltip

Forcing the Tooltip UI to show or hide. This is overriden to `false` when `step` is set to the special string value `any`.
### `separatorType`: `'none' | 'fullWidth' | 'topFullWidth'`

- Type: `Boolean`
- Required: No
- Platform: Web

#### step

The minimum amount by which `value` changes. It is also a factor in validation as `value` must be a multiple of `step` (offset by `min`) to be valid. Accepts the special string value `any` that voids the validation constraint and overrides both `withInputField` and `showTooltip` props to `false`.
Define if separator line under/above control row should be disabled or full width. By default it is placed below excluding underline the control icon.

- Type: `Number | "any"`
- Required: No
- Platform: Web
- Platform: Mobile

#### shiftStep
### `shiftStep`: `number`

Passed as a prop to the `NumberControl` component and is only applicable if `withInputField` and `isShiftStepEnabled` are both true and while the number input has focus. Acts as a multiplier of `step`.

- Type: `Number`
- Required: No

#### trackColor
### `showTooltip`: `boolean`

Customizes the (background) color of the track element.
Forcing the Tooltip UI to show or hide. This is overridden to `false` when `step` is set to the special string value `any`.

- Type: `String`
- Required: No
- Platform: Web

#### value

The current value of the range slider.
### `step`: `number | 'any'`

- Type: `Number`
- Required: Yes
- Platform: Web | Mobile
The minimum amount by which `value` changes. It is also a factor in validation as `value` must be a multiple of `step` (offset by `min`) to be valid. Accepts the special string value `any` that voids the validation constraint and overrides both `withInputField` and `showTooltip` props to `false`.

#### withInputField
- Required: No
- Platform: Web
### `trackColor`: `CSSProperties[ 'color' ]`

Determines if the `input` number field will render next to the RangeControl. This is overriden to `false` when `step` is set to the special string value `any`.
Customizes the (background) color of the track element.

- Type: `Boolean`
- Required: No
- Platform: Web

#### icon
### `type`: `string`

An icon to be shown above the slider next to it's container title.
Define if the value selection should present a stepper control or a slider control in the bottom sheet on mobile. To use the stepper set the type value as `stepper`. Defaults to slider if no option is provided.

- Type: `String`
- Required: No
- Platform: Mobile

#### separatorType
### `value`: `number`

Define if separator line under/above control row should be disabled or full width. By default it is placed below excluding underline the control icon.
The current value of the range slider.

- Type: `String Enum`
- Values: `none` | `fullWidth` | `topFullWidth`
- Required: No
- Platform: Mobile
- Platform: Web | Mobile

#### type
### `withInputField`: `boolean`

Define if the value selection should present a stepper control or a slider control in the bottom sheet on mobile. To use the stepper set the type value as `stepper`. Defaults to slider if no option is provided.
Determines if the `input` number field will render next to the RangeControl. This is overridden to `false` when `step` is set to the special string value `any`.

- Type: `String`
- Required: No
- Platform: Mobile
- Platform: Web

## Related components

Expand Down
Loading

0 comments on commit 78783d3

Please sign in to comment.