-
Notifications
You must be signed in to change notification settings - Fork 202
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
Showing
22 changed files
with
406 additions
and
22 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
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
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
50 changes: 50 additions & 0 deletions
50
packages/shared/src/components/cards/survey/FeedSurveyBanner.tsx
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,50 @@ | ||
import React, { ReactElement, useState } from 'react'; | ||
import { RatingStars } from '../../utilities/RatingStars'; | ||
import { Button, ButtonSize, ButtonVariant } from '../../buttons/Button'; | ||
import { useFeedSurvey } from '../../../hooks/feed/useFeedSurvey'; | ||
import { FeedSurveyProps } from './common'; | ||
import { feedSurveyBg, feedSurveyTopBorder } from '../../../styles/custom'; | ||
|
||
export function FeedSurveyBanner({ | ||
max, | ||
title, | ||
lowScore, | ||
postFeedbackMessage = 'Thank you for your feedback!', | ||
}: FeedSurveyProps): ReactElement { | ||
const [score, setScore] = useState(0); | ||
const { submitted, onSubmit, onHide } = useFeedSurvey({ score }); | ||
|
||
return ( | ||
<div className="mb-4 pt-0.5" style={{ background: feedSurveyTopBorder }}> | ||
<div | ||
className="flex flex-col px-4 py-6 tablet:px-6" | ||
style={{ background: feedSurveyBg }} | ||
> | ||
<div className="flex flex-row items-start tablet:items-center"> | ||
<div className="flex flex-1 flex-col items-start justify-between tablet:flex-row tablet:items-center"> | ||
<h3 className="font-bold typo-title3">{title}</h3> | ||
<RatingStars max={max} onStarClick={setScore} /> | ||
</div> | ||
<Button | ||
variant={score > 0 ? ButtonVariant.Primary : ButtonVariant.Float} | ||
size={ButtonSize.Small} | ||
onClick={score > 0 ? onSubmit : onHide} | ||
className="ml-2 w-24" | ||
disabled={submitted} | ||
> | ||
{score > 0 ? 'Submit' : 'Hide'} | ||
</Button> | ||
</div> | ||
{submitted && ( | ||
<div className="mt-6 flex flex-col tablet:flex-row"> | ||
<p className="shrink text-text-secondary typo-body"> | ||
<strong className="mr-1">{postFeedbackMessage}</strong> | ||
{score <= lowScore.value ? lowScore.message : null} | ||
</p> | ||
{score <= lowScore.value && lowScore.cta} | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} |
66 changes: 66 additions & 0 deletions
66
packages/shared/src/components/cards/survey/FeedSurveyCard.tsx
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,66 @@ | ||
import React, { ReactElement, useState } from 'react'; | ||
import classNames from 'classnames'; | ||
import { Card as CardV1 } from '../v1/Card'; | ||
import { Card } from '../Card'; | ||
import { useFeedLayout } from '../../../hooks'; | ||
import { Button, ButtonSize, ButtonVariant } from '../../buttons/Button'; | ||
import { RatingStars } from '../../utilities/RatingStars'; | ||
import { useFeedSurvey } from '../../../hooks/feed/useFeedSurvey'; | ||
import { FeedSurveyProps } from './common'; | ||
import { feedSurveyBg, feedSurveyBorder } from '../../../styles/custom'; | ||
|
||
export function FeedSurveyCard({ | ||
max, | ||
title, | ||
lowScore, | ||
postFeedbackMessage = 'Thank you for your feedback!', | ||
}: FeedSurveyProps): ReactElement { | ||
const [score, setScore] = useState(0); | ||
const { submitted, onSubmit, onHide } = useFeedSurvey({ score }); | ||
const { shouldUseListFeedLayout } = useFeedLayout(); | ||
const CardComponent = shouldUseListFeedLayout ? CardV1 : Card; | ||
|
||
return ( | ||
<div | ||
className="relative rounded-16 p-0.5" | ||
style={{ backgroundImage: feedSurveyBorder }} | ||
> | ||
<CardComponent | ||
className={classNames( | ||
'relative items-center gap-4 overflow-hidden !rounded-14 border-0 shadow-none', | ||
shouldUseListFeedLayout ? '!py-10' : 'pt-20', | ||
)} | ||
style={{ background: feedSurveyBg }} | ||
> | ||
<h3 className="font-bold typo-title3">{title}</h3> | ||
<RatingStars max={max} isDisabled={submitted} onStarClick={setScore} /> | ||
{submitted && ( | ||
<p className="mt-2 text-center text-text-secondary typo-body"> | ||
<span className="font-bold">{postFeedbackMessage}</span> | ||
{score <= lowScore.value && <p>{lowScore.message}</p>} | ||
{score <= lowScore.value && lowScore.cta} | ||
</p> | ||
)} | ||
{score > 0 && !submitted && ( | ||
<Button | ||
variant={ButtonVariant.Primary} | ||
size={ButtonSize.Small} | ||
onClick={onSubmit} | ||
> | ||
Submit | ||
</Button> | ||
)} | ||
{score === 0 && ( | ||
<Button | ||
variant={ButtonVariant.Float} | ||
size={ButtonSize.Small} | ||
className="mb-2 mt-auto" | ||
onClick={onHide} | ||
> | ||
Hide | ||
</Button> | ||
)} | ||
</CardComponent> | ||
</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,12 @@ | ||
import { ReactNode } from 'react'; | ||
|
||
export interface FeedSurveyProps { | ||
title: string; | ||
postFeedbackMessage?: string; | ||
max: number; | ||
lowScore: { | ||
value: number; | ||
message: string; | ||
cta: ReactNode; | ||
}; | ||
} |
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,2 @@ | ||
export * from './FeedSurveyBanner'; | ||
export * from './FeedSurveyCard'; |
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
42 changes: 42 additions & 0 deletions
42
packages/shared/src/components/feeds/FeedSettingsButton.tsx
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,42 @@ | ||
import React, { ReactElement } from 'react'; | ||
import { | ||
Button, | ||
ButtonProps, | ||
ButtonSize, | ||
ButtonVariant, | ||
} from '../buttons/Button'; | ||
import { useAnalyticsContext } from '../../contexts/AnalyticsContext'; | ||
import { AnalyticsEvent } from '../../lib/analytics'; | ||
import { LazyModal } from '../modals/common/types'; | ||
import { useLazyModal } from '../../hooks/useLazyModal'; | ||
import { FilterIcon } from '../icons'; | ||
|
||
export function FeedSettingsButton({ | ||
onClick, | ||
children = 'Feed settings', | ||
...props | ||
}: ButtonProps<'button'>): ReactElement { | ||
const { trackEvent } = useAnalyticsContext(); | ||
const { openModal } = useLazyModal(); | ||
const onButtonClick = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
trackEvent({ event_name: AnalyticsEvent.ManageTags }); | ||
|
||
if (onClick) { | ||
onClick(event); | ||
} else { | ||
openModal({ type: LazyModal.FeedFilters, persistOnRouteChange: true }); | ||
} | ||
}; | ||
|
||
return ( | ||
<Button | ||
variant={ButtonVariant.Primary} | ||
size={ButtonSize.Small} | ||
icon={<FilterIcon />} | ||
{...props} | ||
onClick={onButtonClick} | ||
> | ||
{children} | ||
</Button> | ||
); | ||
} |
Oops, something went wrong.