-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Connect id-cards page and factor out useEditableValue hook
- Loading branch information
Showing
11 changed files
with
228 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 89 additions & 17 deletions
106
packages/browser-wallet/src/popup/popupX/pages/IdCards/IdCards.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/browser-wallet/src/popup/popupX/shared/EditableValue/EditableValue.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
input.editable-value-x { | ||
background: none; | ||
color: inherit; | ||
border: none; | ||
font-weight: inherit; | ||
font-size: inherit; | ||
font-family: inherit; | ||
padding: 0; | ||
margin: 0; | ||
|
||
&:focus { | ||
outline: none; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/browser-wallet/src/popup/popupX/shared/EditableValue/EditableValue.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, { ChangeEvent, useState, KeyboardEvent, useCallback } from 'react'; | ||
|
||
export default function useEditableValue(current: string, fallback: string, onNewValue: (newValue: string) => void) { | ||
const [isEditing, setIsEditing] = useState(false); | ||
const [edited, setEdited] = useState(current); | ||
// Using edited instead of currentValue to avoid flickering after completing. | ||
const displayName = edited === '' ? fallback : edited; | ||
const onAbort = useCallback(() => { | ||
setIsEditing(false); | ||
setEdited(current); | ||
}, []); | ||
const onComplete = useCallback(() => { | ||
onNewValue(edited.trim()); | ||
setIsEditing(false); | ||
}, []); | ||
const onEdit = useCallback(() => { | ||
setEdited(current); | ||
setIsEditing(true); | ||
}, []); | ||
const onInputChange = (event: ChangeEvent<HTMLInputElement>) => { | ||
setEdited(event.target.value); | ||
}; | ||
const onKeyUp = (event: KeyboardEvent<HTMLInputElement>) => { | ||
if (event.key === 'Enter') { | ||
event.preventDefault(); | ||
onComplete(); | ||
} | ||
}; | ||
const value = isEditing ? ( | ||
<input | ||
className="editable-value-x" | ||
autoFocus | ||
maxLength={25} | ||
value={edited} | ||
placeholder={fallback} | ||
onChange={onInputChange} | ||
onKeyUp={onKeyUp} | ||
/> | ||
) : ( | ||
displayName | ||
); | ||
return { value, isEditing, onAbort, onComplete, onEdit }; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/browser-wallet/src/popup/popupX/shared/EditableValue/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './EditableValue'; |
Oops, something went wrong.