-
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.
- Loading branch information
Showing
5 changed files
with
114 additions
and
26 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,38 @@ | ||
import TagList from "./index"; | ||
|
||
const tags = [ | ||
{ name: "Static Tag" }, | ||
{ name: "Linked Tag", destination: "https://rubinobservatory.org" }, | ||
]; | ||
|
||
describe("<TagList>", () => { | ||
it("should render an unordered list", () => { | ||
cy.mount(<TagList />); | ||
cy.get("ul").should("exist"); | ||
}); | ||
|
||
it("should render tag names with a pound symbol by default", () => { | ||
cy.mount(<TagList tags={tags} />); | ||
cy.get("ul > li").each(($el, i) => { | ||
cy.wrap($el).contains(`#${tags[i].name}`); | ||
}); | ||
}); | ||
|
||
it("should omit pound symbol if specified", () => { | ||
cy.mount(<TagList tags={tags} showPound={false} />); | ||
cy.get("ul > li").each(($el, i) => { | ||
cy.wrap($el).contains(tags[i].name); | ||
}); | ||
}); | ||
|
||
it("should render links if provided", () => { | ||
cy.mount(<TagList tags={tags} />); | ||
cy.get("ul > li").each(($el, i) => { | ||
if (tags[i].destination) { | ||
cy.wrap($el).children("a").should("exist"); | ||
} else { | ||
cy.wrap($el).children("a").should("not.exist"); | ||
} | ||
}); | ||
}); | ||
}); |
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,49 @@ | ||
import { FunctionComponent } from "react"; | ||
import classNames from "classnames"; | ||
import Link from "next/link"; | ||
import styles from "./styles.module.css"; | ||
|
||
export type Tag = { | ||
name: string; | ||
destination?: string; | ||
}; | ||
interface TagListProps { | ||
tags: Array<Tag>; | ||
showPound?: boolean; | ||
withLinebreaks?: boolean; | ||
className?: string; | ||
} | ||
|
||
const TagList: FunctionComponent<TagListProps> = ({ | ||
tags = [], | ||
showPound = true, | ||
withLinebreaks = false, | ||
className, | ||
}) => { | ||
return ( | ||
<ul | ||
data-no-break={!withLinebreaks} | ||
className={classNames(styles.tagList, className)} | ||
> | ||
{tags.map(({ name, destination }) => { | ||
const tagName = showPound ? `#${name}` : name; | ||
|
||
return ( | ||
<li className={styles.tag} data-no-break={!withLinebreaks} key={name}> | ||
{destination ? ( | ||
<Link href={destination} rel="tag"> | ||
{tagName} | ||
</Link> | ||
) : ( | ||
tagName | ||
)} | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
); | ||
}; | ||
|
||
TagList.displayName = "Molecule.TagList"; | ||
|
||
export default TagList; |
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,18 @@ | ||
.tagList { | ||
&[data-no-break="true"] { | ||
display: flex; | ||
flex-wrap: wrap; | ||
column-gap: 1ex; | ||
} | ||
} | ||
|
||
.tag { | ||
& a { | ||
color: var(--color-font-accent); | ||
} | ||
|
||
&[data-no-break="true"] { | ||
display: inline-block; | ||
white-space: nowrap; | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.