Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 88d7805

Browse files
Merge pull request #231 from jjcantu/#222
222: add contributors field on snippet
2 parents d5c276c + c19f379 commit 88d7805

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

‎snippets/javascript/color-manipulation/rgb-to-hex-color.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ tags: color,conversion
99
function rgbToHex(r, g, b) {
1010
const toHex = (n) => {
1111
const hex = n.toString(16);
12-
return hex.length === 1 ? '0' + hex : hex;
12+
return hex.length === 1 ? "0" + hex : hex;
1313
};
14-
15-
return '#' + toHex(r) + toHex(g) + toHex(b);
14+
15+
return "#" + toHex(r) + toHex(g) + toHex(b);
1616
}
1717

1818
// Usage:

‎src/components/SnippetModal.tsx‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const SnippetModal: React.FC<Props> = ({
6868
{snippet.description}
6969
</p>
7070
<p>
71-
Contributed by{" "}
71+
Created by{" "}
7272
<a
7373
href={`https://github.com/${snippet.author}`}
7474
target="_blank"
@@ -78,6 +78,30 @@ const SnippetModal: React.FC<Props> = ({
7878
@{snippet.author}
7979
</a>
8080
</p>
81+
{(snippet.contributors ?? []).length > 0 && (
82+
<div className="contributors">
83+
<span>Contributors: </span>
84+
{snippet.contributors
85+
?.slice(0, 3)
86+
.map((contributor, index, slicedArray) => (
87+
<>
88+
<a
89+
key={contributor}
90+
href={`https://github.com/${contributor}`}
91+
target="_blank"
92+
rel="noopener noreferrer"
93+
className="styled-link"
94+
>
95+
@{contributor}
96+
</a>
97+
{index < slicedArray.length - 1 && ", "}
98+
</>
99+
))}
100+
{(snippet.contributors?.length ?? 0) > 3 && (
101+
<span> & {snippet.contributors!.length - 3} more</span>
102+
)}
103+
</div>
104+
)}
81105
<ul role="list" className="modal__tags">
82106
{snippet.tags.map((tag) => (
83107
<li key={tag} className="modal__tag">

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /