-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93964d5
commit 293f64b
Showing
6 changed files
with
196 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as Preact from 'preact' | ||
import { window } from '../../../utils/globals' | ||
|
||
import { SurveyAppearance } from '../../../posthog-surveys-types' | ||
|
||
import { useContrastingTextColor } from '../hooks/useContrastingTextColor' | ||
import { PostHogLogo } from './PostHogLogo' | ||
|
||
export function BottomSection({ | ||
text, | ||
submitDisabled, | ||
appearance, | ||
onSubmit, | ||
link, | ||
}: { | ||
text: string | ||
submitDisabled: boolean | ||
appearance: SurveyAppearance | ||
onSubmit: () => void | ||
link?: string | null | ||
}) { | ||
const { textColor, ref } = useContrastingTextColor({ appearance }) | ||
|
||
return ( | ||
<div className="bottom-section"> | ||
<div className="buttons"> | ||
<button | ||
className="form-submit" | ||
ref={ref as Preact.RefObject<HTMLButtonElement>} | ||
disabled={submitDisabled} | ||
type="button" | ||
style={{ color: textColor }} | ||
onClick={() => { | ||
if (link) { | ||
window?.open(link) | ||
} | ||
onSubmit() | ||
}} | ||
> | ||
{text} | ||
</button> | ||
</div> | ||
{!appearance.whiteLabel && <PostHogLogo backgroundColor={appearance.backgroundColor || '#FF'} />} | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { useContrastingTextColor } from '../hooks/useContrastingTextColor' | ||
import * as Preact from 'preact' | ||
import { IconPosthogLogo } from '../icons' | ||
|
||
export function PostHogLogo({ backgroundColor }: { backgroundColor?: string }) { | ||
const { textColor, ref } = useContrastingTextColor({ appearance: { backgroundColor } }) | ||
|
||
return ( | ||
<a | ||
href="https://posthog.com" | ||
target="_blank" | ||
rel="noopener" | ||
ref={ref as Preact.RefObject<HTMLAnchorElement>} | ||
style={{ backgroundColor: backgroundColor, color: textColor }} | ||
className="footer-branding" | ||
> | ||
Survey by {IconPosthogLogo} | ||
</a> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useEffect, useRef, useState } from 'preact/hooks' | ||
import { SurveyAppearance } from '../../../posthog-surveys-types' | ||
import * as Preact from 'preact' | ||
import { getTextColor } from '../surveys-utils' | ||
|
||
export function useContrastingTextColor(options: { appearance: SurveyAppearance; defaultTextColor?: string }): { | ||
ref: Preact.RefObject<HTMLElement> | ||
textColor: string | ||
} { | ||
const ref = useRef<HTMLElement>(null) | ||
const [textColor, setTextColor] = useState(options.defaultTextColor ?? 'white') | ||
|
||
// TODO: useContext to get the background colors instead of querying the DOM | ||
useEffect(() => { | ||
if (ref.current) { | ||
const color = getTextColor(ref.current) | ||
setTextColor(color) | ||
} | ||
}, [options.appearance]) | ||
|
||
return { | ||
ref, | ||
textColor, | ||
} | ||
} |
Oops, something went wrong.