Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(feedback): Simplify public css configuration for feedback #11985

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/feedback/src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { GLOBAL_OBJ } from '@sentry/utils';

export { DEFAULT_THEME } from './theme';

// exporting a separate copy of `WINDOW` rather than exporting the one from `@sentry/browser`
// prevents the browser package from being bundled in the CDN bundle, and avoids a
// circular dependency between the browser and feedback packages
Expand Down Expand Up @@ -29,5 +27,3 @@ export const FEEDBACK_WIDGET_SOURCE = 'widget';
export const FEEDBACK_API_SOURCE = 'api';

export const SUCCESS_MESSAGE_TIMEOUT = 5000;

export const CROP_COLOR = '#ffffff';
58 changes: 0 additions & 58 deletions packages/feedback/src/constants/theme.ts

This file was deleted.

15 changes: 8 additions & 7 deletions packages/feedback/src/core/components/Actor.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export function createActorStyles(): HTMLStyleElement {
line-height: 1.14em;
text-decoration: none;

background-color: var(--trigger-background);
border-radius: var(--trigger-border-radius);
border: var(--border);
box-shadow: var(--box-shadow);
color: var(--foreground);
fill: var(--foreground);
background: var(--actor-background, var(--background));
border-radius: var(--actor-border-radius, 1.7em/50%);
border: var(--actor-border, var(--border));
box-shadow: var(--actor-box-shadow, var(--box-shadow));
color: var(--actor-color, var(--foreground));
fill: var(--actor-color, var(--foreground));
cursor: pointer;
opacity: 1;
transition: transform 0.2s ease-in-out;
Expand All @@ -42,7 +42,8 @@ export function createActorStyles(): HTMLStyleElement {
}

.widget__actor:hover {
background-color: var(--trigger-background-hover);
background: var(--actor-hover-background, var(--background));
filter: var(--interactive-filter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooo what does filter do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it creates the hover effect, the value is set to be brightness(95%).

so people only need to set one color

}

.widget__actor svg {
Expand Down
59 changes: 43 additions & 16 deletions packages/feedback/src/core/createMainStyles.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,50 @@
import type { FeedbackInternalOptions } from '@sentry/types';
import { DOCUMENT } from '../constants';

function getThemedCssVariables(theme: FeedbackInternalOptions['themeLight']): string {
const PURPLE = 'rgba(88, 74, 192, 1)';

interface InternalTheme extends NonNullable<FeedbackInternalOptions['themeLight']> {
border: string;
interactiveFilter: string;
}

const DEFAULT_LIGHT: InternalTheme = {
foreground: '#2b2233',
background: '#ffffff',
accentForeground: 'white',
accentBackground: PURPLE,
successColor: '#268d75',
errorColor: '#df3338',
border: '1.5px solid rgba(41, 35, 47, 0.13)',
boxShadow: '0px 4px 24px 0px rgba(43, 34, 51, 0.12)',
outline: '1px auto var(--accent-background)',
interactiveFilter: 'brightness(95%)',
};
const DEFAULT_DARK: InternalTheme = {
foreground: '#ebe6ef',
background: '#29232f',
accentForeground: 'white',
accentBackground: PURPLE,
successColor: '#2da98c',
errorColor: '#f55459',
border: '1.5px solid rgba(41, 35, 47, 0.5)',
boxShadow: '0px 4px 24px 0px rgba(43, 34, 51, 0.12)',
outline: '1px auto var(--accent-background)',
interactiveFilter: 'brightness(150%)',
};

function getThemedCssVariables(theme: InternalTheme): string {
return `
--foreground: ${theme.foreground};
--success-foreground: ${theme.successForeground};
--error-foreground: ${theme.errorForeground};
--background: ${theme.background};
--accent-foreground: ${theme.accentForeground};
--accent-background: ${theme.accentBackground};
--success-color: ${theme.successColor};
--error-color: ${theme.errorColor};
--border: ${theme.border};
--box-shadow: ${theme.boxShadow};

--button-foreground: ${theme.buttonForeground};
--button-foreground-hover: ${theme.buttonForegroundHover};
--button-background: ${theme.buttonBackground};
--button-background-hover: ${theme.buttonBackgroundHover};
--button-border: ${theme.buttonBorder};
--button-outline-focus: ${theme.buttonOutlineFocus};

--trigger-background: ${theme.triggerBackground};
--trigger-background-hover: ${theme.triggerBackgroundHover};
--trigger-border-radius: ${theme.triggerBorderRadius};
--outline: ${theme.outline};
--interactive-filter: ${theme.interactiveFilter};
`;
}

Expand All @@ -41,15 +66,17 @@ export function createMainStyles({ colorScheme, themeDark, themeLight }: Feedbac
font-family: var(--font-family);
font-size: var(--font-size);

${getThemedCssVariables(colorScheme === 'dark' ? themeDark : themeLight)}
${getThemedCssVariables(
colorScheme === 'dark' ? { ...DEFAULT_DARK, ...themeDark } : { ...DEFAULT_LIGHT, ...themeLight },
)}
}

${
colorScheme === 'system'
? `
@media (prefers-color-scheme: dark) {
:host {
${getThemedCssVariables(themeDark)}
${getThemedCssVariables({ ...DEFAULT_DARK, ...themeDark })}
}
}`
: ''
Expand Down
15 changes: 4 additions & 11 deletions packages/feedback/src/core/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
ADD_SCREENSHOT_LABEL,
CANCEL_BUTTON_LABEL,
CONFIRM_BUTTON_LABEL,
DEFAULT_THEME,
DOCUMENT,
EMAIL_LABEL,
EMAIL_PLACEHOLDER,
Expand Down Expand Up @@ -79,8 +78,8 @@ export const buildFeedbackIntegration = ({

// FeedbackThemeConfiguration
colorScheme = 'system',
themeLight,
themeDark,
themeLight = {},
themeDark = {},

// FeedbackTextConfiguration
addScreenshotButtonLabel = ADD_SCREENSHOT_LABEL,
Expand Down Expand Up @@ -118,14 +117,8 @@ export const buildFeedbackIntegration = ({
useSentryUser,

colorScheme,
themeDark: {
...DEFAULT_THEME.dark,
...themeDark,
},
themeLight: {
...DEFAULT_THEME.light,
...themeLight,
},
themeDark,
themeLight,

triggerLabel,
cancelButtonLabel,
Expand Down
Loading
Loading