Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
SamyPesse committed Dec 21, 2024
1 parent 818260c commit 837cabd
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function InlineLink(props: InlineProps<DocumentInlineLink>) {
className="underline underline-offset-2 text-primary hover:text-primary-700 transition-colors"
insights={{
target: inline.data.ref,
position: 'content'
position: 'content',
}}
>
<Inlines
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ContentRef, DocumentTableViewCards } from '@gitbook/api';
import React from 'react';

import { Link } from '@/components/primitives';
import { Image } from '@/components/utils';
import { ClassValue, tcls } from '@/lib/tailwind';

import { RecordColumnValue } from './RecordColumnValue';
import { TableRecordKV, TableViewProps } from './Table';
import { getRecordValue } from './utils';
import { Link } from '@/components/primitives';

export async function RecordCard(
props: TableViewProps<DocumentTableViewCards> & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,17 @@ export async function RecordColumnValue<Tag extends React.ElementType = 'div'>(
href={ref.href}
target="_blank"
style={['flex', 'flex-row', 'items-center', 'gap-2']}
insights={ref.file ?{
target: {
kind: 'file',
file: ref.file.id,
},
position: 'content',
}
: undefined}
insights={
ref.file
? {
target: {
kind: 'file',
file: ref.file.id,
},
position: 'content',
}
: undefined
}
>
{contentType === 'image' ? (
<Image
Expand Down Expand Up @@ -202,10 +205,14 @@ export async function RecordColumnValue<Tag extends React.ElementType = 'div'>(
{resolved ? (
<StyledLink
href={resolved.href}
insights={contentRef ? {
target: contentRef,
position: 'content',
} : undefined}
insights={
contentRef
? {
target: contentRef,
position: 'content',
}
: undefined
}
>
{resolved.text}
</StyledLink>
Expand All @@ -219,26 +226,27 @@ export async function RecordColumnValue<Tag extends React.ElementType = 'div'>(
const contentRef: ContentRefUser = {
kind: 'user',
user: userId,
}
};
const resolved = await context.resolveContentRef(contentRef);
if (!resolved) {
return null;
}

return [
contentRef,
resolved,
] as const;
return [contentRef, resolved] as const;
}),
);

return (
<Tag className={tcls('text-base')} aria-labelledby={ariaLabelledBy}>
{resolved.filter(filterOutNullable).map(([contentRef, resolved], index) => (
<StyledLink key={index} href={resolved.href} insights={{
target: contentRef,
position: 'content',
}}>
<StyledLink
key={index}
href={resolved.href}
insights={{
target: contentRef,
position: 'content',
}}
>
{resolved.text}
</StyledLink>
))}
Expand Down
14 changes: 8 additions & 6 deletions packages/gitbook/src/components/Header/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@ export function DropdownMenu(props: { children: React.ReactNode }) {
/**
* Menu item in a dropdown.
*/
export function DropdownMenuItem(props: {
href: string | null;
active?: boolean;
className?: ClassValue;
children: React.ReactNode;
} & LinkInsightsProps) {
export function DropdownMenuItem(
props: {
href: string | null;
active?: boolean;
className?: ClassValue;
children: React.ReactNode;
} & LinkInsightsProps,
) {
const { children, active = false, href, className, insights } = props;

if (href) {
Expand Down
12 changes: 8 additions & 4 deletions packages/gitbook/src/components/Header/HeaderLinkMore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@ async function MoreMenuLink(props: {
)}
<DropdownMenuItem
href={target?.href ?? null}
insights={link.to ? {
target: link.to,
position: 'header',
} : undefined}
insights={
link.to
? {
target: link.to,
position: 'header',
}
: undefined
}
>
{link.title}
</DropdownMenuItem>
Expand Down
11 changes: 7 additions & 4 deletions packages/gitbook/src/components/Insights/InsightsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,13 @@ export function InsightsProvider(props: InsightsProviderProps) {
eventsRef.current[pathname] = {
pageContext: previous?.pageContext ?? ctx,
url: previous?.url ?? window.location.href,
events: [...(previous?.events ?? []), {
...event,
timestamp: new Date().toISOString(),
}],
events: [
...(previous?.events ?? []),
{
...event,
timestamp: new Date().toISOString(),
},
],
context,
};

Expand Down
3 changes: 2 additions & 1 deletion packages/gitbook/src/components/primitives/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ type ButtonProps = {
variant?: 'primary' | 'secondary';
size?: 'default' | 'medium' | 'small';
className?: ClassValue;
} & LinkInsightsProps & HTMLAttributes<HTMLElement>;
} & LinkInsightsProps &
HTMLAttributes<HTMLElement>;

export function Button({
href,
Expand Down
18 changes: 10 additions & 8 deletions packages/gitbook/src/components/primitives/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { ClassValue, tcls } from '@/lib/tailwind';

import { Link, LinkInsightsProps } from './Link';

export async function Card(props: {
href: string;
leadingIcon?: React.ReactNode;
preTitle?: string;
title: string;
postTitle?: string;
style?: ClassValue;
} & LinkInsightsProps) {
export async function Card(
props: {
href: string;
leadingIcon?: React.ReactNode;
preTitle?: string;
title: string;
postTitle?: string;
style?: ClassValue;
} & LinkInsightsProps,
) {
const { title, leadingIcon, href, preTitle, postTitle, style, insights } = props;

return (
Expand Down
12 changes: 7 additions & 5 deletions packages/gitbook/src/components/primitives/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as api from '@gitbook/api';
import NextLink, { LinkProps as NextLinkProps } from 'next/link';
import React from 'react';

import { useTrackEvent } from '../Insights';

// Props from Next, which includes NextLinkProps and all the things anchor elements support.
Expand All @@ -14,13 +15,14 @@ type BaseLinkProps = Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof N
export type LinkInsightsProps = {
/** Target of the link, for insights. */
insights?: api.SiteInsightsEventLinkClick['link'];
}

export type LinkProps = Omit<BaseLinkProps, 'href'> & LinkInsightsProps & {
/** Enforce href is passed as a string (not a URL). */
href: string;
};

export type LinkProps = Omit<BaseLinkProps, 'href'> &
LinkInsightsProps & {
/** Enforce href is passed as a string (not a URL). */
href: string;
};

/**
* Low-level Link component that handles navigation to external urls.
* It does not contain any styling.
Expand Down

0 comments on commit 837cabd

Please sign in to comment.