-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bibdk2021 1324 bookmark work part2 #879
base: main
Are you sure you want to change the base?
Changes from 7 commits
817ad3b
49c15a7
46835a7
3769b69
499b5bb
033f7cc
dd0dc4a
dae661c
eb5e9bc
a8d720e
008b956
bcc19e5
fe35b44
298887f
da87877
0499fda
09778e5
2ec73e9
cbfda29
cd47b62
a4942dd
39e89e7
7778e2e
1e0b4a2
da196a1
f733162
d99baad
136741b
63bd438
44e5a98
9b74ae8
0c1b8ca
9ac9ca4
9cf62b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,6 @@ | |
.basket { | ||
padding-top: var(--pt3); | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
|
||
.info { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,38 +3,73 @@ | |
|
||
.dropdownitem { | ||
display: block; | ||
border-bottom: 1px solid var(--mine-shaft); | ||
padding: var(--pt1) var(--pt2) var(--pt1) var(--pt2); | ||
border-bottom: 1px solid var(--gray); | ||
padding: var(--pt1) var(--pt05) var(--pt1) var(--pt2); | ||
text-decoration: none; | ||
color: var(--mine-shaft); | ||
text-align: inherit; | ||
white-space: nowrap; | ||
cursor: pointer; | ||
} | ||
|
||
.dropdownitem i svg { | ||
display: none; | ||
} | ||
|
||
.bookmark { | ||
margin-left: var(--pt2); | ||
} | ||
|
||
.active { | ||
color: white; | ||
background-color: green; | ||
background-color: var(--blue); | ||
} | ||
|
||
.dropdownitem.active i svg { | ||
display: block; | ||
} | ||
|
||
.active i svg path { | ||
stroke: var(--white); | ||
} | ||
|
||
.itemContainer { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
|
||
.dropdownitem a { | ||
text-decoration: none; | ||
} | ||
|
||
.dropdownitem:focus { | ||
background: linear-gradient(to right, var(--blue) 10px, var(--concrete) 10px); | ||
.dropdownitem:hover { | ||
color: var(--blue); | ||
font-weight: var(--body-font-semibold); | ||
} | ||
|
||
.dropdownitem:hover { | ||
background: linear-gradient(to right, var(--blue) 10px, var(--concrete) 10px); | ||
.dropdownitem:hover i svg { | ||
display: block; | ||
} | ||
|
||
.dropdownitem:hover i svg path { | ||
stroke: var(--blue); | ||
} | ||
|
||
.dropdownitem:focus i svg { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kunne spare nogle linjer ved at duplikere selectore. Fx
Så længe det er den samme styling der skal applies |
||
display: block; | ||
} | ||
|
||
.dropdownitem:focus i svg path { | ||
stroke: var(--blue); | ||
} | ||
|
||
.dropdownwrap :global(.dropdown-toggle::after) { | ||
display: none; | ||
} | ||
|
||
.dropdownmenu { | ||
border: 1px solid var(--blue); | ||
margin-top: var(--pt1_5); | ||
border: 1px solid var(--gray); | ||
background-color: var(--white); | ||
z-index: 1; | ||
/* bootstrap default styles override */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,27 +6,58 @@ import Text from "@/components/base/text/Text"; | |
import React, { useEffect, useState } from "react"; | ||
import { cyKey } from "@/utils/trim"; | ||
import useBookmarks from "@/components/hooks/useBookmarks"; | ||
import Icon from "@/components/base/icon/Icon"; | ||
import BookmarkMedium from "@/public/icons/bookmark_small.svg"; | ||
|
||
export function BookMarkMaterialSelector({ materialTypes, workId }) { | ||
export function BookMarkMaterialSelector({ | ||
materialTypes, | ||
workId, | ||
size = { w: 6, h: 6 }, | ||
}) { | ||
const bookmarkClick = () => {}; | ||
|
||
const { bookmark, setBookmark, isLoading } = useBookmarks(); | ||
|
||
const onSelect = async (material, workId) => { | ||
const item = { key: workId + material, id: workId, materialType: material }; | ||
await setBookmark(item); | ||
const onSelect = (material, workId) => { | ||
const item = { | ||
key: workId + material, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Skal key ikke også bruge material[0] ? |
||
id: workId, | ||
materialType: material[0], | ||
}; | ||
setBookmark(item); | ||
}; | ||
|
||
const [active, setActive] = useState(false); | ||
const options = materialTypes.map((mat) => mat); | ||
|
||
useEffect(() => { | ||
if (!isLoading) { | ||
const bookmarkIndex = bookmark?.findIndex((bookm) => bookm.id === workId); | ||
let bookmarkIndex = -1; | ||
// this one is used to set the overall button to active or not (if one of the materialtypes is selected) | ||
if (options.length > 1) { | ||
bookmarkIndex = bookmark?.findIndex((bookm) => bookm.id === workId); | ||
} else if (options.length === 1) { | ||
// if we have one material only we look for a specific key | ||
bookmarkIndex = bookmark?.findIndex( | ||
(bookm) => bookm.key === workId + options[0] | ||
); | ||
} | ||
setActive(bookmarkIndex !== -1); | ||
} | ||
}, [bookmark]); | ||
|
||
const options = materialTypes.map((mat) => mat); | ||
if (options.length === 1) { | ||
return ( | ||
<Bookmark | ||
size={size} | ||
className={styles.bookmark} | ||
selected={active} | ||
onClick={() => { | ||
onSelect(options[0], workId); | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
return ( | ||
<Dropdown className={`${styles.dropdownwrap} `} align="end"> | ||
|
@@ -36,7 +67,12 @@ export function BookMarkMaterialSelector({ materialTypes, workId }) { | |
variant="success" | ||
id="dropdown-basic" | ||
> | ||
<Bookmark onClick={bookmarkClick} selected={active} /> | ||
<Bookmark | ||
size={{ w: 7, h: 7 }} | ||
onClick={bookmarkClick} | ||
selected={active} | ||
className={styles.bookmark} | ||
/> | ||
</Dropdown.Toggle> | ||
<Dropdown.Menu | ||
className={styles.dropdownmenu} | ||
|
@@ -47,29 +83,27 @@ export function BookMarkMaterialSelector({ materialTypes, workId }) { | |
})} | ||
> | ||
{options.map((material, index) => { | ||
const activeItem = | ||
bookmark?.findIndex((book) => book.key === workId + material[0]) !== | ||
-1; | ||
return ( | ||
<Dropdown.Item | ||
as="div" | ||
tabIndex="-1" | ||
data-cy={`bookmark-${material}-${index}`} | ||
key={`bookmark-${index}`} | ||
className={`${styles.dropdownitem} ${ | ||
bookmark?.findIndex( | ||
(book) => book.key === workId + material | ||
) !== -1 | ||
? styles.active | ||
: "" | ||
activeItem ? styles.active : "" | ||
}`} | ||
onClick={() => { | ||
onSelect(material, workId); | ||
}} | ||
onKeyDown={(e) => { | ||
if (e.key === "Enter") { | ||
onSelect(material, workId); | ||
} | ||
}} | ||
> | ||
<Text type="text3">{material}</Text> | ||
<div className={styles.itemContainer}> | ||
<Text type="text3">{material}</Text> | ||
|
||
<Icon size={{ w: 3, h: 3 }}> | ||
<BookmarkMedium /> | ||
</Icon> | ||
</div> | ||
</Dropdown.Item> | ||
); | ||
})} | ||
|
@@ -78,8 +112,12 @@ export function BookMarkMaterialSelector({ materialTypes, workId }) { | |
); | ||
} | ||
|
||
export default function wrapper({ materialTypes, workId }) { | ||
export default function wrapper({ materialTypes, workId, size }) { | ||
return ( | ||
<BookMarkMaterialSelector materialTypes={materialTypes} workId={workId} /> | ||
<BookMarkMaterialSelector | ||
materialTypes={materialTypes} | ||
workId={workId} | ||
size={size} | ||
/> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nu har vi den opsætning vi nu engang har. Man kan undgå denne lidt grimme css selector hvis man opretter svg'en som et react component, og sætter stroke og path til "currentColor" - så kan farven styres af css "color".
Da vi ikke har gjort dette før, så lad det ligge.
Du kunne evt spare "i" selector ved at give Icon dit classname istedet for at styre det med en parent.