made the course card clickable everywhere on the body
This commit is contained in:
@@ -111,3 +111,42 @@ describe('getWidgetEmbedCode', () => {
|
|||||||
expect(embedCode).toMatch(/^<div[^>]+><\/div>\n<script[^>]+><\/script>$/);
|
expect(embedCode).toMatch(/^<div[^>]+><\/div>\n<script[^>]+><\/script>$/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// describe('formatCourseForWidget price', () => {
|
||||||
|
// const baseCourse = {
|
||||||
|
// id: 'course-1',
|
||||||
|
// slug: 'my-course',
|
||||||
|
// title: 'My Course',
|
||||||
|
// description: 'A course',
|
||||||
|
// bannerImage: null,
|
||||||
|
// logo: null,
|
||||||
|
// isPublished: true,
|
||||||
|
// currency: 'USD',
|
||||||
|
// lessonCount: 10,
|
||||||
|
// exerciseCount: 5,
|
||||||
|
// type: 'PUBLIC',
|
||||||
|
// createdAt: new Date().toISOString()
|
||||||
|
// };
|
||||||
|
|
||||||
|
// function format(overrides: Record<string, unknown>) {
|
||||||
|
// const course = { ...baseCourse, ...overrides } as Parameters<typeof formatCourseForWidget>[0];
|
||||||
|
// return formatCourseForWidget(course, []);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// it('renders the price for a paid course', () => {
|
||||||
|
// expect(format({ cost: 100, metadata: { paymentEnabled: true } }).price).toBe('USD 100');
|
||||||
|
// });
|
||||||
|
|
||||||
|
// it('renders the price when paymentEnabled is absent but the cost is positive', () => {
|
||||||
|
// expect(format({ cost: 100, metadata: {} }).price).toBe('USD 100');
|
||||||
|
// });
|
||||||
|
|
||||||
|
// it('renders Free for a free course', () => {
|
||||||
|
// expect(format({ cost: 0, metadata: { paymentEnabled: false } }).price).toBe('Free');
|
||||||
|
// expect(format({ cost: 0, metadata: {} }).price).toBe('Free');
|
||||||
|
// });
|
||||||
|
|
||||||
|
// it('renders Free when a paid course has a zero cost (state blocked by API validation)', () => {
|
||||||
|
// expect(format({ cost: 0, metadata: { paymentEnabled: true } }).price).toBe('Free');
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
|||||||
@@ -166,6 +166,8 @@
|
|||||||
return `/courses/${id}${isLMS ? '/lessons?next=true' : ''}`;
|
return `/courses/${id}${isLMS ? '/lessons?next=true' : ''}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const isExploreClickable = $derived(!!(isExplore && onExploreClick));
|
||||||
|
|
||||||
const typeBadge = $derived(
|
const typeBadge = $derived(
|
||||||
type && COURSE_TAG[type]
|
type && COURSE_TAG[type]
|
||||||
? {
|
? {
|
||||||
@@ -221,10 +223,23 @@
|
|||||||
dateStyle: 'medium'
|
dateStyle: 'medium'
|
||||||
}).format(date);
|
}).format(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleExploreCardKeydown(event: KeyboardEvent) {
|
||||||
|
if (event.key !== 'Enter' && event.key !== ' ') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.preventDefault();
|
||||||
|
onExploreClick?.();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<CourseCard
|
<CourseCard
|
||||||
href={courseUrl ? resolve(courseUrl, {}) : undefined}
|
href={courseUrl ? resolve(courseUrl, {}) : undefined}
|
||||||
|
onclick={isExploreClickable ? onExploreClick : undefined}
|
||||||
|
onkeydown={isExploreClickable ? handleExploreCardKeydown : undefined}
|
||||||
|
role={isExploreClickable ? 'button' : undefined}
|
||||||
|
tabindex={isExploreClickable ? 0 : undefined}
|
||||||
{title}
|
{title}
|
||||||
{description}
|
{description}
|
||||||
{typeBadge}
|
{typeBadge}
|
||||||
@@ -318,7 +333,15 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{#if isLMS}
|
{#if isLMS}
|
||||||
<Button variant="outline" onclick={isExplore && onExploreClick ? onExploreClick : undefined}>
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onclick={(event) => {
|
||||||
|
if (isExploreClickable) {
|
||||||
|
event.stopPropagation();
|
||||||
|
onExploreClick?.();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
{isCertificateView
|
{isCertificateView
|
||||||
? $t('certificates.view_certificate')
|
? $t('certificates.view_certificate')
|
||||||
: isExplore
|
: isExplore
|
||||||
|
|||||||
@@ -25,6 +25,12 @@
|
|||||||
iconClass?: string;
|
iconClass?: string;
|
||||||
};
|
};
|
||||||
class?: string;
|
class?: string;
|
||||||
|
/** Click handler for the card wrapper (e.g. opening a preview modal when `href` is absent) */
|
||||||
|
onclick?: (event: MouseEvent) => void;
|
||||||
|
/** Keyboard handler for the card wrapper when it acts as a clickable region */
|
||||||
|
onkeydown?: (event: KeyboardEvent) => void;
|
||||||
|
role?: string;
|
||||||
|
tabindex?: number;
|
||||||
/** Custom banner area (e.g. optimized `Image`); overrides `bannerImage` */
|
/** Custom banner area (e.g. optimized `Image`); overrides `bannerImage` */
|
||||||
media?: Snippet;
|
media?: Snippet;
|
||||||
/** Optional overlay inside the link (e.g. dropdown), typically absolutely positioned */
|
/** Optional overlay inside the link (e.g. dropdown), typically absolutely positioned */
|
||||||
@@ -42,6 +48,10 @@
|
|||||||
typeBadge,
|
typeBadge,
|
||||||
visibilityBadge,
|
visibilityBadge,
|
||||||
class: className = '',
|
class: className = '',
|
||||||
|
onclick,
|
||||||
|
onkeydown,
|
||||||
|
role,
|
||||||
|
tabindex,
|
||||||
media,
|
media,
|
||||||
overlay,
|
overlay,
|
||||||
tags,
|
tags,
|
||||||
@@ -51,7 +61,14 @@
|
|||||||
const resolvedBannerImage = $derived(bannerImage?.trim() ? bannerImage : DEFAULT_COURSE_BANNER_IMAGE);
|
const resolvedBannerImage = $derived(bannerImage?.trim() ? bannerImage : DEFAULT_COURSE_BANNER_IMAGE);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Item.Root variant="outline" class={cn('ui:group ui:relative ui:max-w-[320px] ui:p-3!', className)}>
|
<Item.Root
|
||||||
|
variant="outline"
|
||||||
|
class={cn('ui:group ui:relative ui:max-w-[320px] ui:p-3!', className)}
|
||||||
|
{onclick}
|
||||||
|
{onkeydown}
|
||||||
|
{role}
|
||||||
|
{tabindex}
|
||||||
|
>
|
||||||
{#snippet child({ props })}
|
{#snippet child({ props })}
|
||||||
{#if href}
|
{#if href}
|
||||||
<a {href} {...props} class={cn('ui:block', props.class as string)}>
|
<a {href} {...props} class={cn('ui:block', props.class as string)}>
|
||||||
|
|||||||
@@ -12,4 +12,3 @@ export * from './compliance';
|
|||||||
export * from './public-course';
|
export * from './public-course';
|
||||||
export * from './section';
|
export * from './section';
|
||||||
export * from './invite';
|
export * from './invite';
|
||||||
export { ZCourseGetParam, type TCourseGetParam } from './course';
|
|
||||||
|
|||||||
Reference in New Issue
Block a user