Skip to content

Commit 2ae1fb5

Browse files
committed
feat: 增加禁用属性
1 parent fe75604 commit 2ae1fb5

6 files changed

Lines changed: 11 additions & 7 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default () => {
3636
| -------------- | -------------------- | --------- | ------------------ |
3737
| className | string | - | 类名 |
3838
| style | React.CSSProperties | - | 样式 |
39+
| disabled | `boolean` | `false` | 是否禁用 |
3940
| keepOpenOnBlur | `boolean` | `false` | 失去焦点时保持打开 |
4041
| hideActions | `boolean` | `false` | 是否隐藏操作按钮 |
4142
| confirmText | `string` | `Confirm` | 确认文本 |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@twp0217/react-inline-edit",
3-
"version": "1.0.6",
3+
"version": "1.0.7",
44
"description": "Inline edit component for React",
55
"scripts": {
66
"start": "dumi dev",

src/InlineEdit.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const InlineEdit = (props: InlineEditProps) => {
99
const {
1010
className,
1111
style,
12+
disabled,
1213
keepOpenOnBlur,
1314
isEditing: customizeIsEditing,
1415
readView,
@@ -80,7 +81,7 @@ const InlineEdit = (props: InlineEditProps) => {
8081

8182
return (
8283
<div className={classNames('inline-edit-container', className)} style={style}>
83-
{isEditing ? (
84+
{!disabled && isEditing ? (
8485
<EditView
8586
{...props}
8687
onBlur={handleBlur}
@@ -90,7 +91,7 @@ const InlineEdit = (props: InlineEditProps) => {
9091
onCancel={handleCancel}
9192
/>
9293
) : (
93-
<ReadView readView={readView} onClick={handleReadViewClick} />
94+
<ReadView disabled={disabled} readView={readView} onClick={handleReadViewClick} />
9495
)}
9596
</div>
9697
);

src/components/ReadView.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import React from 'react';
22
import { InlineEditProps } from '../interface';
3+
import classNames from 'classnames';
34

4-
interface ReadViewProps extends Pick<InlineEditProps, 'readView'> {
5+
interface ReadViewProps extends Pick<InlineEditProps, 'disabled' | 'readView'> {
56
onClick: () => void;
67
}
78

89
const ReadView = (props: ReadViewProps) => {
9-
const { readView, onClick } = props;
10+
const { disabled, readView, onClick } = props;
1011

1112
return (
12-
<div className="inline-edit-read-view-container" onClick={onClick}>
13+
<div className={classNames('inline-edit-read-view-container', { disabled })} onClick={onClick}>
1314
{readView}
1415
</div>
1516
);

src/index.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
border-radius: 2px;
3232
box-shadow: 0 0 0 0 transparent;
3333

34-
&:hover {
34+
&:not(.disabled):hover {
3535
box-shadow: 0 0 0 1px @border-color;
3636
}
3737
}

src/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type Placement = 'top' | 'bottom';
55
export interface InlineEditProps<T = Value> {
66
className?: string;
77
style?: React.CSSProperties;
8+
disabled?: boolean;
89
keepOpenOnBlur?: boolean;
910
hideActions?: boolean;
1011
confirmText?: string;

0 commit comments

Comments
 (0)