-
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.
Merge pull request #556 from Concordium/x-id-cards
Hook up IdCards page with actual data
- Loading branch information
Showing
13 changed files
with
243 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
3 changes: 3 additions & 0 deletions
3
packages/browser-wallet/src/popup/popupX/pages/IdCards/IdCards.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 |
---|---|---|
@@ -1,2 +1,5 @@ | ||
.id-cards-x { | ||
.page__main { | ||
gap: rem(16px); | ||
} | ||
} |
107 changes: 90 additions & 17 deletions
107
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); | ||
}, [current]); | ||
const onComplete = useCallback(() => { | ||
onNewValue(edited.trim()); | ||
setIsEditing(false); | ||
}, [edited]); | ||
const onEdit = useCallback(() => { | ||
setEdited(current); | ||
setIsEditing(true); | ||
}, [current]); | ||
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.