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: custom webfont selection on surveys #1643

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
12 changes: 12 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,15 @@ export const PERSISTENCE_RESERVED_PROPERTIES = [
INITIAL_REFERRER_INFO,
ENABLE_PERSON_PROCESSING,
]

export const WEB_SAFE_FONTS = [
'system-ui',
'Arial',
'Verdana',
'Tahoma',
'Trebuchet MS',
'Helvetica',
'Times New Roman',
'Georgia',
'Courier New',
] as const
12 changes: 6 additions & 6 deletions src/extensions/surveys/surveys-utils.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PostHog } from '../../posthog-core'
import { Survey, SurveyAppearance, MultipleSurveyQuestion, SurveyQuestion } from '../../posthog-surveys-types'
import { window as _window, document as _document } from '../../utils/globals'
import { VNode, cloneElement, createContext } from 'preact'
import { PostHog } from '../../posthog-core'
import { MultipleSurveyQuestion, Survey, SurveyAppearance, SurveyQuestion } from '../../posthog-surveys-types'
import { document as _document, window as _window } from '../../utils/globals'
// We cast the types here which is dangerous but protected by the top level generateSurveys call
const window = _window as Window & typeof globalThis
const document = _document as Document
Expand All @@ -22,7 +22,7 @@ export const style = (appearance: SurveyAppearance | null) => {
bottom: 0px;
color: black;
font-weight: normal;
font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "Roboto", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-family: ${appearance?.fontFamily || '-apple-system'}, BlinkMacSystemFont, "Inter", "Segoe UI", "Roboto", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
text-align: left;
max-width: ${parseInt(appearance?.maxWidth || '300')}px;
width: 100%;
Expand All @@ -36,7 +36,7 @@ export const style = (appearance: SurveyAppearance | null) => {
border-top-right-radius: 10px;
box-shadow: -6px 0 16px -8px rgb(0 0 0 / 8%), -9px 0 28px 0 rgb(0 0 0 / 5%), -12px 0 48px 16px rgb(0 0 0 / 3%);
}

.survey-box, .thank-you-message-container {
padding: 20px 25px 10px;
display: flex;
Expand All @@ -56,7 +56,7 @@ export const style = (appearance: SurveyAppearance | null) => {
.survey-form textarea {
color: #2d2d2d;
font-size: 14px;
font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "Roboto", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
font-family: ${appearance?.fontFamily || '-apple-system'}, BlinkMacSystemFont, "Inter", "Segoe UI", "Roboto", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
background: white;
color: black;
outline: none;
Expand Down
3 changes: 3 additions & 0 deletions src/posthog-surveys-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* See https://github.com/PostHog/posthog-js/issues/698
*/

import { WEB_SAFE_FONTS } from './constants'

export interface SurveyAppearance {
// keep in sync with frontend/src/types.ts -> SurveyAppearance
backgroundColor?: string
Expand Down Expand Up @@ -34,6 +36,7 @@ export interface SurveyAppearance {
widgetSelector?: string
widgetLabel?: string
widgetColor?: string
fontFamily?: (typeof WEB_SAFE_FONTS)[number]
// questionable: Not in frontend/src/types.ts -> SurveyAppearance, but used in site app
maxWidth?: string
zIndex?: string
Expand Down
Loading