-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@thunderstore/cyberstorm: replace CurrentFilters with CategoryTagCloud
- Connect TagCloud to the data managed by PackageSearch and shared with CategoryMenu - PackageListing is still disconnected from this data source Refs TS-1860
- Loading branch information
Showing
3 changed files
with
113 additions
and
72 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...ages/cyberstorm/src/components/PackageSearch/CategoryTagCloud/CategoryTagCloud.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,41 @@ | ||
.root { | ||
display: flex; | ||
flex-flow: row wrap; | ||
gap: var(--space--8); | ||
list-style: none; | ||
} | ||
|
||
.tag { | ||
display: flex; | ||
flex: none; | ||
gap: var(--gap--4); | ||
align-items: center; | ||
justify-content: center; | ||
padding: var(--space--6) var(--space--8); | ||
border-radius: var(--border-radius--8); | ||
color: var(--text-color); | ||
font-weight: 700; | ||
font-size: var(--font-size--s); | ||
background-color: var(--bg-color); | ||
|
||
--text-color: var(--color-text--default); | ||
--bg-color: var(--color-surface--5); | ||
} | ||
|
||
.tag.exclude { | ||
--text-color: var(--color-red--3); | ||
--bg-color: var(--color-red--10); | ||
} | ||
|
||
.icon { | ||
height: var(--space--16); | ||
color: var(--text-color); | ||
} | ||
|
||
.tag.exclude .icon { | ||
--text-color: var(--color-red--3); | ||
} | ||
|
||
.clearAll { | ||
margin-left: var(--space--4); | ||
} |
64 changes: 64 additions & 0 deletions
64
packages/cyberstorm/src/components/PackageSearch/CategoryTagCloud/CategoryTagCloud.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,64 @@ | ||
import { faXmark } from "@fortawesome/free-solid-svg-icons"; | ||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { Dispatch, SetStateAction } from "react"; | ||
|
||
import styles from "./CategoryTagCloud.module.css"; | ||
import { CategorySelection, CATEGORY_STATES } from "../types"; | ||
import * as Button from "../../Button"; | ||
import { Icon } from "../../Icon/Icon"; | ||
|
||
const OFF = CATEGORY_STATES[0]; | ||
|
||
interface Props { | ||
categories: CategorySelection[]; | ||
setCategories: Dispatch<SetStateAction<CategorySelection[]>>; | ||
} | ||
|
||
/** | ||
* Show currently selected category filters. | ||
*/ | ||
export const CategoryTagCloud = (props: Props) => { | ||
const { categories, setCategories } = props; | ||
const visible = categories.filter((c) => c.selection !== "off"); | ||
|
||
if (!visible.length) { | ||
return null; | ||
} | ||
|
||
const clearCategory = (slug: string) => | ||
setCategories( | ||
categories.map((c) => (c.slug === slug ? { ...c, selection: OFF } : c)) | ||
); | ||
|
||
const clearAll = () => | ||
setCategories(categories.map((c) => ({ ...c, selection: OFF }))); | ||
|
||
return ( | ||
<ol className={styles.root}> | ||
{visible.map((c) => ( | ||
<li key={c.slug} className={`${styles.tag} ${styles[c.selection]}`}> | ||
<span>{c.name}</span> | ||
<Button.Root | ||
onClick={() => clearCategory(c.slug)} | ||
colorScheme="transparentDefault" | ||
paddingSize="none" | ||
> | ||
<Button.ButtonIcon> | ||
<Icon> | ||
<FontAwesomeIcon icon={faXmark} className={styles.icon} /> | ||
</Icon> | ||
</Button.ButtonIcon> | ||
</Button.Root> | ||
</li> | ||
))} | ||
|
||
<li className={styles.clearAll}> | ||
<Button.Root onClick={clearAll} colorScheme="transparentTertiary"> | ||
<Button.ButtonLabel>Clear all</Button.ButtonLabel> | ||
</Button.Root> | ||
</li> | ||
</ol> | ||
); | ||
}; | ||
|
||
CategoryTagCloud.displayName = "CategoryTagCloud"; |
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