|
| 1 | +# react-inline-edit |
| 2 | + |
| 3 | +Inline edit component for React(基于 React 的内联编辑组件) |
| 4 | + |
| 5 | +## 安装 |
| 6 | + |
| 7 | +```bash |
| 8 | +npm install @twp0217/react-inline-edit --save |
| 9 | +``` |
| 10 | + |
| 11 | +## 使用 |
| 12 | + |
| 13 | +```typescript |
| 14 | +import React from 'react'; |
| 15 | +import InlineEdit from '@twp0217/react-inline-edit'; |
| 16 | + |
| 17 | +export default () => { |
| 18 | + const [editValue, setEditValue] = React.useState<string>(''); |
| 19 | + |
| 20 | + return ( |
| 21 | + <InlineEdit |
| 22 | + defaultValue={editValue} |
| 23 | + readView={editValue || '请点击输入值'} |
| 24 | + editView={<input placeholder="请输入值" />} |
| 25 | + onConfirm={setEditValue} |
| 26 | + /> |
| 27 | + ); |
| 28 | +}; |
| 29 | +``` |
| 30 | + |
| 31 | +## API |
| 32 | + |
| 33 | +### InlineEditProps |
| 34 | + |
| 35 | +| 名称 | 类型 | 默认值 | 说明 | |
| 36 | +| -------------- | -------------------- | --------- | ------------------ | ---- | |
| 37 | +| className | string | - | 类名 | |
| 38 | +| style | React.CSSProperties | - | 样式 | |
| 39 | +| keepOpenOnBlur | `boolean` | `false` | 失去焦点时保持打开 | |
| 40 | +| hideActions | `boolean` | `false` | 是否隐藏操作按钮 | |
| 41 | +| confirmText | `string` | `Confirm` | 确认文本 | |
| 42 | +| cancelText | `string` | `Cancel` | 取消文本 | |
| 43 | +| defaultValue | `string` | - | 默认值 | |
| 44 | +| isEditing | `boolean` | - | 是否正在编辑 | |
| 45 | +| loading | `boolean` | - | 加载中 | |
| 46 | +| placement | `'top' | 'bottom'` | - | 位置 | |
| 47 | +| readView | `React.ReactNode` | - | 查看视图 | |
| 48 | +| editView | `React.ReactNode` | - | 编辑视图 | |
| 49 | +| onEdit | `() => void` | - | 编辑事件 | |
| 50 | +| onBlur | `() => void` | - | 失去焦点事件 | |
| 51 | +| onConfirm | `(value: T) => void` | - | 确认事件 | |
| 52 | +| onCancel | `() => void` | - | 取消事件 | |
| 53 | + |
| 54 | +## 支持 |
| 55 | + |
| 56 | +- 如果项目对你有帮助,请点颗星星:star:,谢谢。 |
| 57 | +- 如果你对项目有想法、问题、BUG,欢迎讨论。 |
0 commit comments