Skip to content

Commit fda4cb2

Browse files
committed
feat: Add Sentry branding
1 parent 5230bf6 commit fda4cb2

File tree

7 files changed

+96
-4
lines changed

7 files changed

+96
-4
lines changed

packages/feedback/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ The following options can be configured as options to the integration, in `new F
5555
| key | type | default | description |
5656
| --------- | ------- | ------- | ----------- |
5757
| `autoInject` | `boolean` | `true` | Injects the Feedback widget into the application when the integration is added. This is useful to turn off if you bring your own button, or only want to show the widget on certain views. |
58+
| `showBranding` | `boolean` | `true` | Displays the Sentry logo inside of the dialog |
5859
| `colorScheme` | `"system" \| "light" \| "dark"` | `"system"` | The color theme to use. `"system"` will follow your OS colorscheme. |
5960

6061
### User/form Related Configuration

packages/feedback/src/integration.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class Feedback implements Integration {
7272

7373
public constructor({
7474
id = 'sentry-feedback',
75+
showBranding = true,
7576
autoInject = true,
7677
showEmail = true,
7778
showName = true,
@@ -117,6 +118,7 @@ export class Feedback implements Integration {
117118

118119
this.options = {
119120
id,
121+
showBranding,
120122
autoInject,
121123
isAnonymous,
122124
isEmailRequired,

packages/feedback/src/types/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ export interface FeedbackGeneralConfiguration {
5656
*/
5757
id: string;
5858

59+
/**
60+
* Show the Sentry branding
61+
*/
62+
showBranding: boolean;
63+
5964
/**
6065
* Auto-inject default Feedback actor button to the DOM when integration is
6166
* added.

packages/feedback/src/widget/Dialog.css.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ export function createDialogStyles(d: Document): HTMLStyleElement {
5656
}
5757
5858
.dialog__header {
59+
display: flex;
60+
align-items: center;
61+
justify-content: space-between;
5962
font-size: 20px;
6063
font-weight: 600;
6164
padding: 0;

packages/feedback/src/widget/Dialog.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import type { FeedbackComponent } from '../types';
1+
import type { FeedbackComponent, FeedbackInternalOptions } from '../types';
22
import type { FormComponentProps } from './Form';
33
import { Form } from './Form';
4+
import { Logo } from './Logo';
45
import { createElement } from './util/createElement';
56

6-
export interface DialogProps extends FormComponentProps {
7-
formTitle: string;
7+
export interface DialogProps
8+
extends FormComponentProps,
9+
Pick<FeedbackInternalOptions, 'formTitle' | 'showBranding' | 'colorScheme'> {
810
onClosed?: () => void;
911
}
1012

@@ -40,8 +42,10 @@ export interface DialogComponent extends FeedbackComponent<HTMLDialogElement> {
4042
*/
4143
export function Dialog({
4244
formTitle,
45+
showBranding,
4346
showName,
4447
showEmail,
48+
colorScheme,
4549
isAnonymous,
4650
defaultName,
4751
defaultEmail,
@@ -122,7 +126,22 @@ export function Dialog({
122126
e.stopPropagation();
123127
},
124128
},
125-
createElement('h2', { className: 'dialog__header' }, formTitle),
129+
createElement(
130+
'h2',
131+
{ className: 'dialog__header' },
132+
formTitle,
133+
showBranding &&
134+
createElement(
135+
'a',
136+
{
137+
target: '_blank',
138+
href: 'https://sentry.io/welcome/',
139+
title: 'Powered by Sentry',
140+
rel: 'noopener noreferrer',
141+
},
142+
Logo({ colorScheme }).el,
143+
),
144+
),
126145
formEl,
127146
),
128147
);

packages/feedback/src/widget/Logo.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { WINDOW } from '@sentry/browser';
2+
3+
import type { FeedbackInternalOptions } from '../types';
4+
import { setAttributesNS } from '../util/setAttributesNS';
5+
6+
const XMLNS = 'http://www.w3.org/2000/svg';
7+
8+
interface IconReturn {
9+
el: SVGElement;
10+
}
11+
12+
type Props = Pick<FeedbackInternalOptions, 'colorScheme'>;
13+
14+
/**
15+
* Sentry Logo
16+
*/
17+
export function Logo({ colorScheme }: Props): IconReturn {
18+
const createElementNS = <K extends keyof SVGElementTagNameMap>(tagName: K): SVGElementTagNameMap[K] =>
19+
WINDOW.document.createElementNS(XMLNS, tagName);
20+
const svg = setAttributesNS(createElementNS('svg'), {
21+
class: 'sentry-logo',
22+
width: '32',
23+
height: '30',
24+
viewBox: '0 0 72 66',
25+
fill: 'none',
26+
});
27+
28+
const path = setAttributesNS(createElementNS('path'), {
29+
transform: 'translate(11, 11)',
30+
d: 'M29,2.26a4.67,4.67,0,0,0-8,0L14.42,13.53A32.21,32.21,0,0,1,32.17,40.19H27.55A27.68,27.68,0,0,0,12.09,17.47L6,28a15.92,15.92,0,0,1,9.23,12.17H4.62A.76.76,0,0,1,4,39.06l2.94-5a10.74,10.74,0,0,0-3.36-1.9l-2.91,5a4.54,4.54,0,0,0,1.69,6.24A4.66,4.66,0,0,0,4.62,44H19.15a19.4,19.4,0,0,0-8-17.31l2.31-4A23.87,23.87,0,0,1,23.76,44H36.07a35.88,35.88,0,0,0-16.41-31.8l4.67-8a.77.77,0,0,1,1.05-.27c.53.29,20.29,34.77,20.66,35.17a.76.76,0,0,1-.68,1.13H40.6q.09,1.91,0,3.81h4.78A4.59,4.59,0,0,0,50,39.43a4.49,4.49,0,0,0-.62-2.28Z',
31+
});
32+
svg.append(path);
33+
34+
const defs = createElementNS('defs');
35+
const style = createElementNS('style');
36+
37+
if (colorScheme === 'system') {
38+
style.textContent = `
39+
@media (prefers-color-scheme: dark) {
40+
path: {
41+
fill: '#fff';
42+
}
43+
}
44+
`;
45+
}
46+
47+
style.textContent = `
48+
path {
49+
fill: ${colorScheme === 'dark' ? '#fff' : '#362d59'};
50+
}`;
51+
52+
defs.append(style);
53+
svg.append(defs);
54+
55+
return {
56+
get el() {
57+
return svg;
58+
},
59+
};
60+
}

packages/feedback/src/widget/createWidget.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ export function createWidget({ shadow, options, attachTo }: CreateWidgetParams):
134134
const user = scope && scope.getUser();
135135

136136
dialog = Dialog({
137+
colorScheme: options.colorScheme,
138+
showBranding: options.showBranding,
137139
showName: options.showName,
138140
showEmail: options.showEmail,
139141
isAnonymous: options.isAnonymous,

0 commit comments

Comments
 (0)