diff --git a/packages/ui/time-picker/src/TimePicker.tsx b/packages/ui/time-picker/src/TimePicker.tsx index 78758c806..12e3cbc03 100644 --- a/packages/ui/time-picker/src/TimePicker.tsx +++ b/packages/ui/time-picker/src/TimePicker.tsx @@ -65,6 +65,7 @@ export const TimePicker = forwardRef( overlay, size = 'md', invalid = false, + customRender, }, ref ) => { @@ -257,49 +258,62 @@ export const TimePicker = forwardRef( return (
-
- { - showPopperRef.current = true - setShowPopper(true) - }} - /> + {customRender ? (
{ - showPopperRef.current = !showPopperRef.current - setShowPopper((pre) => !pre) + showPopperRef.current = true + setShowPopper(true) }} > - {showPopper ? ( - { - onCacheChange(type === 'single' ? [''] : ['', '']) - }} - /> - ) : ( - - )} + {typeof customRender === 'function' ? customRender(cacheValue) : customRender}
-
+ ) : ( +
+ { + showPopperRef.current = true + setShowPopper(true) + }} + /> +
{ + showPopperRef.current = !showPopperRef.current + setShowPopper((pre) => !pre) + }} + > + {showPopper ? ( + { + onCacheChange(type === 'single' ? [''] : ['', '']) + }} + /> + ) : ( + + )} +
+
+ )} + React.ReactNode) } if (__DEV__) { diff --git a/packages/ui/time-picker/stories/custom-renser.stories.tsx b/packages/ui/time-picker/stories/custom-renser.stories.tsx new file mode 100644 index 000000000..beb3b201e --- /dev/null +++ b/packages/ui/time-picker/stories/custom-renser.stories.tsx @@ -0,0 +1,45 @@ +import React, { useState } from 'react' +import TimePicker from '../src' +import Input from '@hi-ui/input' + +/** + * @title 新增自定义触发器 + */ +export const CustomRender = () => { + const [basicValue, setBasicValue] = useState(['12:00:00']) + const [rangeValue, setRangeValue] = useState(['11:11:11', '12:00:00']) + + return ( + <> +

CustomRender-Basic

+
+ { + console.log('basic-default', e) + setBasicValue(e) + }} + customRender={(data) => { + return + }} + /> +
+

CustomRender-Range

+
+ { + console.log('range-value', value) + setRangeValue(value) + }} + type="range" + customRender={(data) => { + return + }} + /> +
+ + ) +} diff --git a/packages/ui/time-picker/stories/index.stories.tsx b/packages/ui/time-picker/stories/index.stories.tsx index 7af377483..961498b87 100644 --- a/packages/ui/time-picker/stories/index.stories.tsx +++ b/packages/ui/time-picker/stories/index.stories.tsx @@ -8,6 +8,7 @@ export * from './disabled.stories' export * from './range.stories' export * from './format.stories' export * from './custom-disabled.stories' +export * from './custom-renser.stories' export default { title: 'Data Input/TimePicker',