-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(edit): change and save title (#1167)
* feat(edit): title can now be changed and saved Signed-off-by: Fredrik Busklein <[email protected]> * chore(edit): added changeTitle action to reducer * chore(edit): addressed proposed changes * fix(edit): optional prop for title * fix(edit): change to state for temporary title * fix(edit):remove onclick from heading * fix(edit): 2 return statements instead of ternary ops * chore(edit): cleanup in edit board title * fix(board): changed to named export --------- Signed-off-by: Fredrik Busklein <[email protected]> Co-authored-by: Natasha Tikhonova <[email protected]>
- Loading branch information
1 parent
deb763c
commit cbe2497
Showing
7 changed files
with
80 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { SecondarySquareButton } from '@entur/button' | ||
import { TextField } from '@entur/form' | ||
import { CheckIcon, CloseIcon, EditIcon } from '@entur/icons' | ||
import { Heading1 } from '@entur/typography' | ||
import { useSettingsDispatch } from 'Admin/utils/contexts' | ||
import { useState } from 'react' | ||
import classes from './styles.module.css' | ||
|
||
function BoardTitle({ title }: { title?: string }) { | ||
const [isEditing, setIsEditing] = useState(false) | ||
const dispatch = useSettingsDispatch() | ||
const boardTitle = title || 'Tavla' | ||
const [tempTitle, setTempTitle] = useState(boardTitle) | ||
|
||
if (!isEditing) { | ||
return ( | ||
<div className={classes.editTitle}> | ||
<Heading1 className={classes.title}>{boardTitle}</Heading1> | ||
<SecondarySquareButton | ||
className={classes.squareButton} | ||
onClick={() => setIsEditing(true)} | ||
> | ||
<EditIcon aria-label="Rediger tittel" /> | ||
</SecondarySquareButton> | ||
</div> | ||
) | ||
} | ||
|
||
return ( | ||
<div className={classes.editTitle}> | ||
<TextField | ||
defaultValue={boardTitle} | ||
size="medium" | ||
label="Navn på tavlen" | ||
onChange={(e) => setTempTitle(e.target.value)} | ||
/> | ||
<SecondarySquareButton | ||
className={classes.squareButton} | ||
onClick={() => { | ||
setIsEditing(false) | ||
dispatch({ | ||
type: 'setTitle', | ||
title: tempTitle, | ||
}) | ||
}} | ||
> | ||
<CheckIcon aria-label="Bekreft tittelendring" /> | ||
</SecondarySquareButton> | ||
<SecondarySquareButton | ||
className={classes.squareButton} | ||
onClick={() => { | ||
setTempTitle(boardTitle) | ||
setIsEditing(false) | ||
}} | ||
> | ||
<CloseIcon aria-label="Avbryt tittelendring" /> | ||
</SecondarySquareButton> | ||
</div> | ||
) | ||
} | ||
|
||
export { BoardTitle } |
11 changes: 11 additions & 0 deletions
11
next-tavla/src/Admin/scenarios/BoardTitle/styles.module.css
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,11 @@ | ||
.editTitle { | ||
display: flex; | ||
height: 3rem; | ||
align-items: center; | ||
gap: 1em; | ||
} | ||
|
||
.title { | ||
margin: auto; | ||
line-height: 3rem; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,3 @@ | |
bottom: 1.25em; | ||
right: 5em; | ||
} | ||
|
||
.saveButton { | ||
font-size: 1em; | ||
font-weight: 400; | ||
} |
Empty file.
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