-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
125 additions
and
0 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,19 @@ | ||
import React from "react"; | ||
import ReactDOM from "react-dom"; | ||
import Tags from "./Tags"; | ||
|
||
it("renders empty with empty tags", () => { | ||
const div = document.createElement("div"); | ||
ReactDOM.render(<Tags tags={[]} />, div); | ||
expect(div.innerHTML).toBe(""); | ||
ReactDOM.unmountComponentAtNode(div); | ||
}); | ||
|
||
it("renders schema tags", () => { | ||
const div = document.createElement("div"); | ||
const tags = ["salad", "mytag"]; | ||
ReactDOM.render(<Tags tags={tags} />, div); | ||
expect(div.innerHTML.includes("salad")).toBe(true); | ||
expect(div.innerHTML.includes("mytag")).toBe(true); | ||
ReactDOM.unmountComponentAtNode(div); | ||
}); |
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,31 @@ | ||
import React, { Component } from "react"; | ||
import { types } from "@open-rpc/meta-schema"; | ||
import { Chip } from "@material-ui/core"; | ||
const hashColor = require("hash-color-material"); | ||
|
||
interface IProps { | ||
tags?: string[]; | ||
} | ||
|
||
export default class Tags extends Component<IProps> { | ||
public render() { | ||
const { tags } = this.props; | ||
if (!tags || tags.length === 0) { | ||
return null; | ||
} | ||
return ( | ||
<> | ||
{ | ||
tags.map((tag: any, k: number) => { | ||
return ( | ||
<Chip | ||
key={tag} | ||
label={tag} | ||
style={{ backgroundColor: hashColor.getColorFromString(tag, false) }} /> | ||
); | ||
}) | ||
} | ||
</> | ||
); | ||
} | ||
} |
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