Skip to content

Commit e2c4aac

Browse files
Customize caret icons for each provider (#148)
1 parent 36576b8 commit e2c4aac

File tree

3 files changed

+80
-9
lines changed

3 files changed

+80
-9
lines changed

.eslintrc.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010
"sourceType": "module"
1111
},
1212
"plugins": ["@typescript-eslint", "react"],
13-
"rules": {}
13+
"rules": {
14+
"react/react-in-jsx-scope": "off"
15+
}
1416
}

src/button/CaretForProvider.tsx

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import classNames from "classnames";
2+
3+
import type { SupportedApplication } from "./button-contributions";
4+
5+
const BitbucketCaret = () => {
6+
return (
7+
<svg width="24" height="24" viewBox="0 0 24 24" role="presentation">
8+
<path
9+
d="M8.292 10.293a1.009 1.009 0 000 1.419l2.939 2.965c.218.215.5.322.779.322s.556-.107.769-.322l2.93-2.955a1.01 1.01 0 000-1.419.987.987 0 00-1.406 0l-2.298 2.317-2.307-2.327a.99.99 0 00-1.406 0z"
10+
fill="currentColor"
11+
fillRule="evenodd"
12+
></path>
13+
</svg>
14+
);
15+
};
16+
17+
const GitHubCaret = () => {
18+
return (
19+
<svg
20+
aria-hidden="true"
21+
focusable="false"
22+
className="octicon octicon-triangle-down chevron-icon"
23+
viewBox="0 0 16 16"
24+
width="16"
25+
height="16"
26+
fill="currentColor"
27+
>
28+
<path d="m4.427 7.427 3.396 3.396a.25.25 0 0 0 .354 0l3.396-3.396A.25.25 0 0 0 11.396 7H4.604a.25.25 0 0 0-.177.427Z"></path>
29+
</svg>
30+
);
31+
};
32+
33+
const GitLabCaret = () => {
34+
return (
35+
<svg
36+
className="s16 gl-icon gl-mr-0!"
37+
width="16"
38+
height="16"
39+
viewBox="0 0 16 16"
40+
xmlns="http://www.w3.org/2000/svg"
41+
>
42+
<path
43+
fillRule="evenodd"
44+
clipRule="evenodd"
45+
d="M4.22 6.22a.75.75 0 0 1 1.06 0L8 8.94l2.72-2.72a.75.75 0 1 1 1.06 1.06l-3.25 3.25a.75.75 0 0 1-1.06 0L4.22 7.28a.75.75 0 0 1 0-1.06Z"
46+
fill="currentColor"
47+
/>
48+
</svg>
49+
);
50+
};
51+
52+
type Props = {
53+
provider: SupportedApplication;
54+
};
55+
export const CaretForProvider = ({ provider }: Props) => {
56+
switch (provider) {
57+
case "github":
58+
return <GitHubCaret />;
59+
case "bitbucket":
60+
case "bitbucket-server":
61+
return <BitbucketCaret />;
62+
case "gitlab":
63+
return <GitLabCaret />;
64+
default:
65+
return (
66+
<svg width="16" viewBox="0 0 24 24" className={classNames("chevron-icon")}>
67+
<path d="M7 10L12 15L17 10H7Z"></path>
68+
</svg>
69+
);
70+
}
71+
};

src/button/button.tsx

+6-8
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import { DEFAULT_GITPOD_ENDPOINT, EVENT_CURRENT_URL_CHANGED } from "~constants";
99
import { STORAGE_KEY_ADDRESS, STORAGE_KEY_ALWAYS_OPTIONS, STORAGE_KEY_NEW_TAB } from "~storage";
1010

1111
import type { SupportedApplication } from "./button-contributions";
12+
import { BitbucketCaret, CaretForProvider, GitHubCaret } from "./CaretForProvider";
1213

13-
export interface GitpodButtonProps {
14+
type Props = {
1415
application: SupportedApplication;
1516
additionalClassNames?: string[];
16-
}
17-
18-
export const GitpodButton = ({ application, additionalClassNames }: GitpodButtonProps) => {
17+
};
18+
export const GitpodButton = ({ application, additionalClassNames }: Props) => {
1919
const [address] = useStorage<string>(STORAGE_KEY_ADDRESS, DEFAULT_GITPOD_ENDPOINT);
2020
const [openInNewTab] = useStorage<boolean>(STORAGE_KEY_NEW_TAB, true);
2121
const [disableAutostart] = useStorage<boolean>(STORAGE_KEY_ALWAYS_OPTIONS, false);
@@ -83,7 +83,7 @@ export const GitpodButton = ({ application, additionalClassNames }: GitpodButton
8383
<div
8484
id="gitpod-btn-nav"
8585
title="Gitpod"
86-
className={classNames("gitpod-button", application, ...(additionalClassNames || []))}
86+
className={classNames("gitpod-button", application, ...(additionalClassNames ?? []))}
8787
>
8888
<div className={classNames("button")}>
8989
<a
@@ -106,9 +106,7 @@ export const GitpodButton = ({ application, additionalClassNames }: GitpodButton
106106
toggleDropdown();
107107
}}
108108
>
109-
<svg width="18" viewBox="0 0 24 24" className={classNames("chevron-icon")}>
110-
<path d="M7 10L12 15L17 10H7Z"></path>
111-
</svg>
109+
<CaretForProvider provider={application} />
112110
</button>
113111
)}
114112
</div>

0 commit comments

Comments
 (0)