-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DPSTAT-947] Nytt innholdsside i Dapla Ctrl (#272)
* Add page for creating new teams * Add proxy for klass API * Implement ItemSelection component This is useful for selecting multiple items from a list. The component isn't in use right now, but it will be later when we add support for selecting 'features' from the create team page. * update create team button only let dapla admins create teams for now
- Loading branch information
Showing
16 changed files
with
782 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,50 @@ | ||
import { useMemo, useState } from 'react' | ||
import { Tag } from '@statisticsnorway/ssb-component-library' | ||
import styles from './itemSelection.module.scss' | ||
|
||
export interface Item { | ||
readonly id: number | ||
readonly text: string | ||
} | ||
|
||
interface ItemSelectionProps { | ||
readonly header: string | ||
readonly items: Item[] | ||
readonly onSelectionChange: (selectedItems: Item[]) => void | ||
} | ||
function ItemSelection({ header, items, onSelectionChange }: ItemSelectionProps) { | ||
const [selectedItems, setSelectedItems] = useState<Item[]>([]) | ||
|
||
const selectedItemIds = useMemo(() => selectedItems.map((item) => item.id), [selectedItems]) | ||
|
||
const selectItem = (selectedItem: Item) => { | ||
const newSelectedItems = selectedItemIds.includes(selectedItem.id) | ||
? selectedItems.filter((item) => item.id !== selectedItem.id) | ||
: [...selectedItems, selectedItem] | ||
|
||
setSelectedItems(newSelectedItems) | ||
onSelectionChange(newSelectedItems) | ||
} | ||
|
||
return ( | ||
<div className={styles.rootComponent}> | ||
<div className={styles.header}>{header}</div> | ||
<div className={styles.itemSelection}> | ||
{items.map(({ id, text }) => ( | ||
<Tag | ||
key={id} | ||
onClick={(event: Event) => { | ||
selectItem({ id, text }) | ||
event.preventDefault() | ||
}} | ||
className={selectedItemIds.includes(id) ? styles.selectedItem : ''} | ||
> | ||
{text} | ||
</Tag> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default ItemSelection |
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,24 @@ | ||
.rootComponent { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 2.5rem; | ||
font-family: 'Roboto', sans-serif; | ||
font-stretch: normal; | ||
} | ||
|
||
.header { | ||
font-size: 1.5rem; | ||
font-weight: bold; | ||
margin-bottom: 8px; | ||
} | ||
|
||
.itemSelection { | ||
display: flex; | ||
flex-flow: row wrap; | ||
justify-content: flex-start; | ||
gap: 1.3rem; | ||
} | ||
.selectedItem { | ||
background-color: #00824d; | ||
color: white; | ||
} |
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
Oops, something went wrong.