rc-segmented
Advanced tools
Comparing version 1.1.0 to 1.2.0
import * as React from 'react'; | ||
export declare type SegmentedValue = string | number; | ||
declare type SegmentedRawOption = SegmentedValue; | ||
interface SegmentedLabeledOption { | ||
export declare type SegmentedRawOption = SegmentedValue; | ||
export interface SegmentedLabeledOption { | ||
className?: string; | ||
@@ -6,0 +6,0 @@ disabled?: boolean; |
@@ -6,3 +6,3 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2"; | ||
import _typeof from "@babel/runtime/helpers/esm/typeof"; | ||
var _excluded = ["prefixCls", "direction", "options", "disabled", "onChange", "className", "motionName"]; | ||
var _excluded = ["prefixCls", "direction", "options", "disabled", "defaultValue", "value", "onChange", "className", "motionName"]; | ||
import * as React from 'react'; | ||
@@ -73,2 +73,4 @@ import classNames from 'classnames'; | ||
disabled = props.disabled, | ||
defaultValue = props.defaultValue, | ||
value = props.value, | ||
onChange = props.onChange, | ||
@@ -83,3 +85,3 @@ _props$className = props.className, | ||
var mergedRef = composeRef(containerRef, ref); | ||
var thumbMoveStyles = React.useRef({ | ||
var thumbMoveStatus = React.useRef({ | ||
from: null, | ||
@@ -92,3 +94,6 @@ to: null | ||
var _useMergedState = useMergedState(props.defaultValue || ((_segmentedOptions$ = segmentedOptions[0]) === null || _segmentedOptions$ === void 0 ? void 0 : _segmentedOptions$.value)), | ||
var _useMergedState = useMergedState((_segmentedOptions$ = segmentedOptions[0]) === null || _segmentedOptions$ === void 0 ? void 0 : _segmentedOptions$.value, { | ||
value: value, | ||
defaultValue: defaultValue | ||
}), | ||
_useMergedState2 = _slicedToArray(_useMergedState, 2), | ||
@@ -108,3 +113,3 @@ selected = _useMergedState2[0], | ||
var calcThumbMoveStyle = function calcThumbMoveStyle(event) { | ||
var calcThumbMoveStatus = function calcThumbMoveStatus(event) { | ||
var _containerRef$current; | ||
@@ -115,5 +120,5 @@ | ||
if (fromElement && toElement && thumbMoveStyles.current) { | ||
thumbMoveStyles.current.from = calcThumbStyle(fromElement); | ||
thumbMoveStyles.current.to = calcThumbStyle(toElement); | ||
if (fromElement && toElement && thumbMoveStatus.current) { | ||
thumbMoveStatus.current.from = calcThumbStyle(fromElement); | ||
thumbMoveStatus.current.to = calcThumbStyle(toElement); | ||
setThumbShow(true); | ||
@@ -123,3 +128,3 @@ } | ||
var handleChange = function handleChange(event, value) { | ||
var handleChange = function handleChange(event, val) { | ||
if (disabled) { | ||
@@ -129,12 +134,9 @@ return; | ||
if (value !== selected) { | ||
calcThumbMoveStyle(event); | ||
} | ||
calcThumbMoveStatus(event); | ||
setSelected(val); | ||
setSelected(value); | ||
if (onChange) { | ||
var mutatedTarget = Object.create(event.target, { | ||
value: { | ||
value: value | ||
value: val | ||
} | ||
@@ -153,3 +155,3 @@ }); | ||
var handleThumbEnterStart = function handleThumbEnterStart() { | ||
var fromStyle = thumbMoveStyles.current.from; | ||
var fromStyle = thumbMoveStatus.current.from; | ||
@@ -163,3 +165,3 @@ if (fromStyle) { | ||
var handleThumbEnterActive = function handleThumbEnterActive() { | ||
var toStyle = thumbMoveStyles.current.to; | ||
var toStyle = thumbMoveStatus.current.to; | ||
@@ -175,4 +177,4 @@ if (toStyle) { | ||
if (thumbMoveStyles.current) { | ||
thumbMoveStyles.current = { | ||
if (thumbMoveStatus.current) { | ||
thumbMoveStatus.current = { | ||
from: null, | ||
@@ -213,3 +215,5 @@ to: null | ||
Segmented.displayName = 'Segmented'; | ||
Segmented.defaultProps = {}; | ||
Segmented.defaultProps = { | ||
options: [] | ||
}; | ||
export default Segmented; |
import * as React from 'react'; | ||
export declare type SegmentedValue = string | number; | ||
declare type SegmentedRawOption = SegmentedValue; | ||
interface SegmentedLabeledOption { | ||
export declare type SegmentedRawOption = SegmentedValue; | ||
export interface SegmentedLabeledOption { | ||
className?: string; | ||
@@ -6,0 +6,0 @@ disabled?: boolean; |
@@ -34,3 +34,3 @@ "use strict"; | ||
var _excluded = ["prefixCls", "direction", "options", "disabled", "onChange", "className", "motionName"]; | ||
var _excluded = ["prefixCls", "direction", "options", "disabled", "defaultValue", "value", "onChange", "className", "motionName"]; | ||
@@ -95,2 +95,4 @@ function normalizeOptions(options) { | ||
disabled = props.disabled, | ||
defaultValue = props.defaultValue, | ||
value = props.value, | ||
onChange = props.onChange, | ||
@@ -104,3 +106,3 @@ _props$className = props.className, | ||
var mergedRef = (0, _ref3.composeRef)(containerRef, ref); | ||
var thumbMoveStyles = React.useRef({ | ||
var thumbMoveStatus = React.useRef({ | ||
from: null, | ||
@@ -113,3 +115,6 @@ to: null | ||
var _useMergedState = (0, _useMergedState3.default)(props.defaultValue || ((_segmentedOptions$ = segmentedOptions[0]) === null || _segmentedOptions$ === void 0 ? void 0 : _segmentedOptions$.value)), | ||
var _useMergedState = (0, _useMergedState3.default)((_segmentedOptions$ = segmentedOptions[0]) === null || _segmentedOptions$ === void 0 ? void 0 : _segmentedOptions$.value, { | ||
value: value, | ||
defaultValue: defaultValue | ||
}), | ||
_useMergedState2 = (0, _slicedToArray2.default)(_useMergedState, 2), | ||
@@ -129,3 +134,3 @@ selected = _useMergedState2[0], | ||
var calcThumbMoveStyle = function calcThumbMoveStyle(event) { | ||
var calcThumbMoveStatus = function calcThumbMoveStatus(event) { | ||
var _containerRef$current; | ||
@@ -136,5 +141,5 @@ | ||
if (fromElement && toElement && thumbMoveStyles.current) { | ||
thumbMoveStyles.current.from = calcThumbStyle(fromElement); | ||
thumbMoveStyles.current.to = calcThumbStyle(toElement); | ||
if (fromElement && toElement && thumbMoveStatus.current) { | ||
thumbMoveStatus.current.from = calcThumbStyle(fromElement); | ||
thumbMoveStatus.current.to = calcThumbStyle(toElement); | ||
setThumbShow(true); | ||
@@ -144,3 +149,3 @@ } | ||
var handleChange = function handleChange(event, value) { | ||
var handleChange = function handleChange(event, val) { | ||
if (disabled) { | ||
@@ -150,12 +155,9 @@ return; | ||
if (value !== selected) { | ||
calcThumbMoveStyle(event); | ||
} | ||
calcThumbMoveStatus(event); | ||
setSelected(val); | ||
setSelected(value); | ||
if (onChange) { | ||
var mutatedTarget = Object.create(event.target, { | ||
value: { | ||
value: value | ||
value: val | ||
} | ||
@@ -174,3 +176,3 @@ }); | ||
var handleThumbEnterStart = function handleThumbEnterStart() { | ||
var fromStyle = thumbMoveStyles.current.from; | ||
var fromStyle = thumbMoveStatus.current.from; | ||
@@ -184,3 +186,3 @@ if (fromStyle) { | ||
var handleThumbEnterActive = function handleThumbEnterActive() { | ||
var toStyle = thumbMoveStyles.current.to; | ||
var toStyle = thumbMoveStatus.current.to; | ||
@@ -196,4 +198,4 @@ if (toStyle) { | ||
if (thumbMoveStyles.current) { | ||
thumbMoveStyles.current = { | ||
if (thumbMoveStatus.current) { | ||
thumbMoveStatus.current = { | ||
from: null, | ||
@@ -234,4 +236,6 @@ to: null | ||
Segmented.displayName = 'Segmented'; | ||
Segmented.defaultProps = {}; | ||
Segmented.defaultProps = { | ||
options: [] | ||
}; | ||
var _default = Segmented; | ||
exports.default = _default; |
{ | ||
"name": "rc-segmented", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "React segmented controls used in ant.design", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -54,2 +54,3 @@ # rc-segmented | ||
| defaultValue | string \| number | | defaultValue of segmented | | ||
| value | string \| number | | currently selected value of segmented | | ||
| onChange | (e: any) => void | | defaultValue of segmented | | ||
@@ -56,0 +57,0 @@ | disabled | boolean | false | disabled status of segmented | |
39425
525
77