Skip to content

Instantly share code, notes, and snippets.

@tokisakiyuu
Created April 26, 2022 06:30
Show Gist options
  • Save tokisakiyuu/41a58bc1ca15ee6aae05b6de6b0b35f5 to your computer and use it in GitHub Desktop.
Save tokisakiyuu/41a58bc1ca15ee6aae05b6de6b0b35f5 to your computer and use it in GitHub Desktop.
Solution for extend a typedef parameter in jsdoc
/**
* @typedef {import('react').ReactNode} ReactNode
* @typedef {import('antd/lib/input-number').InputNumberProps} InputNumberProps
* @typedef {Object} AddonProps
* @property {ReactNode} addonAfter
* @property {ReactNode} addonBefore
* @typedef {InputNumberProps & AddonProps} InputNumberPropsWithAddon
*/
import { Input, InputNumber, Button } from 'antd'
/**
* 弥补antd的InputNumber组件不支持addonAfter和addonBefore的问题
* @param {InputNumberPropsWithAddon} param0
* @returns
*/
const InputNumberPlus = ({ addonAfter, addonBefore, ...rest }) => {
return (
<Input.Group compact>
{addonBefore && <Addon>{addonAfter}</Addon>}
<InputNumber {...rest} />
{addonAfter && <Addon>{addonAfter}</Addon>}
</Input.Group>
)
}
const Addon = ({ children }) => (
<Button disabled style={{ color: 'black', cursor: 'default' }}>{children}</Button>
)
export default InputNumberPlus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment