Skip to content

Commit 690b878

Browse files
authored
Release/v1.0.2
- Remove onChange from required props
2 parents 735d7ac + 91e9f9d commit 690b878

5 files changed

Lines changed: 35 additions & 13 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default App
4949

5050
### Props
5151

52-
> All props except `onChange` are optional.
52+
> All props are optional, that's how you can **fully customize** it!
5353
5454
| Name | Optional | Type | Description |
5555
| ------------------------ | -------- | ------------------- | --------------------------------------------------------------------- |
@@ -60,7 +60,7 @@ export default App
6060
| disabled | ✔️ | `boolean` | Flag that disables the input element |
6161
| updatedContent | ✔️ | `string` | Text injected from parent element into the input as the current value |
6262
| onContentExternalUpdate | ✔️ | `(content) => void` | Method that emits the injected content by the `updatedContent` prop |
63-
| onChange | | `(content) => void` | Method that emits the current content as a string |
63+
| onChange | ✔️ | `(content) => void` | Method that emits the current content as a string |
6464
| onKeyUp | ✔️ | `(e) => void` | Method that emits the keyUp keyboard event |
6565
| onKeyDown | ✔️ | `(e) => void` | Method that emits the keyDown keyboard event |
6666
| onFocus | ✔️ | `(e) => void` | Method that emits the focus event |

lib/ContentEditable.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface ContentEditableProps {
77
placeholder?: string
88
disabled?: boolean
99
updatedContent?: string
10-
onChange: (content: string) => void
10+
onChange?: (content: string) => void
1111
onKeyUp?: (e: React.KeyboardEvent) => void
1212
onKeyDown?: (e: React.KeyboardEvent) => void
1313
onFocus?: (e: React.FocusEvent) => void
@@ -43,7 +43,7 @@ const ContentEditable: React.FC<ContentEditableProps> = ({
4343
useEffect(() => {
4444
if (divRef.current) {
4545
divRef.current.style.height = "auto"
46-
onChange(content)
46+
if (onChange) onChange(content)
4747
}
4848
}, [content, onChange])
4949

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-basic-contenteditable",
33
"description": "React 18 contenteditable component. Super-customizable!",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"type": "module",
66
"main": "dist/main.js",
77
"types": "dist/main.d.ts",

src/App.css

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,22 @@ body {
2727
.full-width {
2828
width: 100%;
2929
}
30+
.falsy,
31+
.truthy {
32+
padding: 0.1rem 0.4rem;
33+
border-radius: 0.25rem;
34+
}
3035
.falsy {
3136
color: red;
37+
background-color: rgba(248, 84, 84, 0.28);
3238
}
3339
.truthy {
3440
color: green;
41+
background-color: rgba(5, 157, 5, 0.28);
3542
}
3643

3744
.main-container {
38-
min-height: 100vh;
45+
height: 100vh;
3946
display: flex;
4047
flex-direction: column;
4148
justify-content: flex-end;
@@ -55,10 +62,13 @@ body {
5562
align-self: flex-start;
5663
padding: 0.85rem 1rem;
5764
border-radius: 0.35rem;
58-
background-color: #eff1f6;
65+
background-color: #f4f4f5;
66+
border: 1px solid #e4e4e7;
5967
letter-spacing: 0.05ch;
6068
line-height: 1.2;
6169
white-space: pre-wrap;
70+
overflow-wrap: anywhere;
71+
max-width: 100%;
6272
}
6373
.message-history-container,
6474
.input-container {
@@ -69,14 +79,17 @@ body {
6979
position: relative;
7080
}
7181
.input-element {
72-
border: 1px solid #ccc;
82+
border: 1px solid #e4e4e7;
7383
border-radius: 0.35rem;
7484
line-height: 1.3;
7585
min-height: 1.188rem;
7686
max-height: 10rem;
7787
}
88+
.input-element:focus {
89+
outline: 1px solid #86868b;
90+
}
7891
.input-placeholder {
79-
color: #a2acb4;
92+
color: #71717a;
8093
margin-left: 1rem;
8194
}
8295

@@ -89,7 +102,7 @@ body {
89102
font-size: 0.875rem;
90103
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
91104
monospace;
92-
border-top: 1px solid #0b57d0;
105+
border-top: 1px dashed #0b57d0;
93106
background-color: #e0e8f6;
94107
padding: 2rem 3rem;
95108
}
@@ -100,16 +113,22 @@ body {
100113
gap: 0.35rem;
101114
}
102115

116+
.current-message-text {
117+
overflow-wrap: anywhere;
118+
}
119+
103120
button {
104121
cursor: pointer;
105122
appearance: none;
106123
border: none;
107124
background-color: #2f6ed3;
108125
color: white;
109-
padding: 0.875rem 1rem;
126+
line-height: 1.25rem;
127+
font-size: 0.875rem;
128+
padding: 0.5rem 1rem;
110129
border-radius: 0.35rem;
111130
letter-spacing: 0.08ch;
112131
}
113132
button:hover {
114-
background-color: #1f4aa8;
133+
background-color: #255db8;
115134
}

src/App.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ const App = () => {
5959
<div className="full-width metrics-section">
6060
<div className="metrics-section__left-box">
6161
<div>
62-
Content: <b>{truncateString(content, 200)}</b>
62+
Content:{" "}
63+
<b className="current-message-text">
64+
{truncateString(content, 200)}
65+
</b>
6366
</div>
6467
<div>
6568
Is focused:{" "}

0 commit comments

Comments
 (0)