Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,45 @@ export const Default = (): React.ReactElement => {
/>
);
};

export const ShortBanner = (): React.ReactElement => {
const [activeItem, setActiveItem] = React.useState<string>('1');
const [checkedIds, setCheckedIds] = React.useState<string[]>([]);
const [, setIsCompleted] = React.useState<boolean>(false);

const handlePrimaryClick = (id: string) => {
setCheckedIds((prev) => [...prev, id]);
setActiveItem((prev) => (parseInt(prev) + 1).toString());

if (checkedIds.length === 4) {
setIsCompleted(true);
}
};

const handleSecondaryClick = (id: string) => setActiveItem(id);

return (
<OnboardingChecklist
title="Here’s your getting started guide"
greetingText="Hello, Tim!"
items={getItems(handlePrimaryClick, handleSecondaryClick)}
activeItemId={activeItem}
completedItemsIds={checkedIds}
onActiveChange={handleSecondaryClick}
isCompleted={true}
completionMessageData={{
title: '',
greetingText: 'Hey Tim, nice work!',
delay: 3000,
placeholder: (
<video
src="https://cdn.livechat-static.com/api/file/lc/img/default/assets/onboarding-success.mp4"
playsInline
muted
autoPlay
/>
),
}}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const OnboardingChecklist: React.FC<IOnboardingChecklistProps> = ({
>(undefined);
const containerRef = React.useRef<HTMLDivElement>(null);
const COMPLETE_CONTAINER_HEIGHT = completionMessageData.height || 96;
const HEIGHT_BUFFER = 50; // Adjust??

const handleButtonClick = () => {
setIsOpen((prev) => !prev);
Expand All @@ -43,7 +44,7 @@ export const OnboardingChecklist: React.FC<IOnboardingChecklistProps> = ({
const delay = completionMessageData.delay || 1500;
const container = containerRef.current;

if (isCompleted && container) {
if (isCompleted && container && !isChecklistCompleted) {
const currentHeight = container.offsetHeight;
setCurrentContainerHeight(currentHeight);

Expand All @@ -56,7 +57,16 @@ export const OnboardingChecklist: React.FC<IOnboardingChecklistProps> = ({
clearTimeout(timeoutId);
};
}
}, [isCompleted]);
}, [isCompleted, isChecklistCompleted]);

React.useEffect(() => {
if (containerRef.current) {
const newHeight = isOpen
? containerRef.current.scrollHeight + HEIGHT_BUFFER
: COMPLETE_CONTAINER_HEIGHT;
setCurrentContainerHeight(newHeight);
}
}, [isOpen, isChecklistCompleted]);

return (
<div
Expand All @@ -69,10 +79,7 @@ export const OnboardingChecklist: React.FC<IOnboardingChecklistProps> = ({
className
)}
style={{
height:
!isChecklistCompleted || isOpen
? currentContainerHeight
: COMPLETE_CONTAINER_HEIGHT,
height: currentContainerHeight,
}}
>
{isOpen && (
Expand Down