Skip to content

Commit

Permalink
fix(docs) changelog pages (#2185)
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans committed May 28, 2024
1 parent 57517a7 commit 8b759a2
Show file tree
Hide file tree
Showing 27 changed files with 1,026 additions and 747 deletions.
2 changes: 2 additions & 0 deletions .changeset/funny-buses-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
1 change: 1 addition & 0 deletions packages/apps/docs/src/changelog.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface IRepo {
repoName: string;
}
interface IChangelogPackage extends IRepo {
versionCount?: number;
content: Record<string, IChangelogPackageVersion>;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/apps/docs/src/components/Changelog/Changelog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const Changelog: FC<IProps> = ({ changelogs }) => {
return (
<Stack flexDirection="column" gap="xxxl">
{packages.map((pkg) => (
<Package key={pkg.repoName} pkg={pkg} />
<Package key={pkg.repoName} pkg={pkg} isFullPage={false} />
))}
</Stack>
);
Expand Down
10 changes: 8 additions & 2 deletions packages/apps/docs/src/components/Changelog/CommitItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Stack } from '@kadena/react-ui';
import { Stack, Text } from '@kadena/react-ui';
import type { FC } from 'react';
import React, { useMemo } from 'react';
import ReactMarkdown from 'react-markdown';
import rehypeRaw from 'rehype-raw';
import { CommitTag } from './CommitTag';
import {
commitListItemClass,
Expand Down Expand Up @@ -29,7 +31,11 @@ export const CommitItem: FC<IProps> = ({ commit }) => {
return (
<Stack as="li" className={commitListItemClass}>
<Stack flex={1} className={commitListItemTitleClass}>
{commit.label}
<Text as="span">
<ReactMarkdown rehypePlugins={[rehypeRaw] as any}>
{commit.label}
</ReactMarkdown>
</Text>
</Stack>
{ids.length > 0 && (
<Stack flexWrap="wrap" className={tagContainerClass}>
Expand Down
111 changes: 88 additions & 23 deletions packages/apps/docs/src/components/Changelog/Package.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,48 @@
import { getVersions } from '@/scripts/importChangelogs/utils/misc';
import { Heading, Stack } from '@kadena/react-ui';
import { MonoKeyboardArrowRight, MonoList } from '@kadena/react-icons/system';
import { Button, Heading, Stack, Text } from '@kadena/react-ui';
import classNames from 'classnames';
import Link from 'next/link';
import type { FC } from 'react';
import React from 'react';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { Version } from './Version';
import { VersionMeta } from './VersionMeta';
import {
backgroundClass,
togglePackageButtonClass,
togglePackageIconClass,
togglePackageIconOpenClass,
versionWrapperClass,
versionWrapperOpenClass,
versionsSectionClass,
versionsSectionMetaClass,
} from './styles.css';

interface IProps {
pkg: IChangelogPackage;
isFullPage?: boolean;
}

export const Package: FC<IProps> = ({ pkg }) => {
export const Package: FC<IProps> = ({ pkg, isFullPage = true }) => {
const [isOpen, setIsOpen] = useState(true);
const ref = useRef<HTMLDivElement>(null);

useEffect(() => {
if (!ref.current || isFullPage) return;

ref.current.style.maxHeight = isOpen
? `${ref.current.scrollHeight + 1000}px`
: '0';
}, [ref.current, isOpen, isFullPage]);

const versions = useMemo(() => {
return getVersions(pkg);
}, [pkg.content]);

const handleOpen = (): void => {
if (isFullPage) return;
setIsOpen((v) => !v);
};
return (
<Stack
as="section"
Expand All @@ -23,31 +51,68 @@ export const Package: FC<IProps> = ({ pkg }) => {
flexDirection="column"
paddingBlock="xxxl"
paddingInline={{ xs: 'md', md: 'xl', lg: 'xxxl' }}
gap="lg"
>
<Heading as="h2">{pkg.name}</Heading>
{getVersions(pkg).map((version) => (
<Stack key={version.label} flexDirection={{ xs: 'column', lg: 'row' }}>
<Stack alignItems="center" width="100%" justifyContent="space-between">
{!isFullPage ? (
<button onClick={handleOpen} className={togglePackageButtonClass}>
<Heading as="h2">{pkg.name}</Heading>

<Text
className={classNames(togglePackageIconClass, {
[togglePackageIconOpenClass]: isOpen,
})}
>
<MonoKeyboardArrowRight />
</Text>
</button>
) : (
<Heading as="h2">{pkg.name}</Heading>
)}
</Stack>
<Stack
ref={ref}
flexDirection="column"
gap="lg"
className={classNames(versionWrapperClass, {
[versionWrapperOpenClass]: !isOpen,
})}
>
{versions.map((version) => (
<Stack
paddingBlock="lg"
className={versionsSectionMetaClass}
paddingInlineEnd={{ xs: 'no', lg: 'xl' }}
key={version.label}
flexDirection={{ xs: 'column', lg: 'row' }}
paddingBlockStart="lg"
>
<VersionMeta version={version} />
<Stack
paddingBlock="lg"
className={versionsSectionMetaClass}
paddingInlineEnd={{ xs: 'no', lg: 'xl' }}
>
<VersionMeta version={version} />
</Stack>
<Stack
flex={1}
className={versionsSectionClass}
paddingInlineStart={{ xs: 'md', xl: 'xxxl' }}
paddingInlineEnd="md"
paddingBlock="lg"
flexDirection="column"
gap="lg"
>
<Version version={version} />
</Stack>
</Stack>
<Stack
flex={1}
className={versionsSectionClass}
paddingInlineStart={{ xs: 'md', xl: 'xxxl' }}
paddingInlineEnd="md"
paddingBlock="lg"
flexDirection="column"
gap="lg"
>
<Version version={version} />
))}
{!isFullPage && (pkg.versionCount ?? 0) > versions.length && (
<Stack width="100%" justifyContent="flex-start">
<Link href={`/changelogs/${pkg.slug}`} passHref legacyBehavior>
<Button variant="info" endVisual={<MonoList />}>
See all logs
</Button>
</Link>
</Stack>
</Stack>
))}
)}
</Stack>
</Stack>
);
};
40 changes: 40 additions & 0 deletions packages/apps/docs/src/components/Changelog/styles.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const commitListItemTitleClass = style([
selectors: {
'&::before': {
content: '•',
color: tokens.kda.foundation.color.text.base.default,
paddingInlineEnd: tokens.kda.foundation.spacing.sm,
},
},
Expand Down Expand Up @@ -120,7 +121,17 @@ export const tagContainerClass = style([
paddingBlockEnd: 'md',
}),
{
alignSelf: 'flex-start',
...responsiveStyle({
xs: {
width: '100%',
},
sm: {
width: '100px',
},
md: {
width: '100%',
},
lg: {
paddingInlineStart: 0,
paddingBlockStart: 0,
Expand Down Expand Up @@ -191,3 +202,32 @@ globalStyle(
color: tokens.kda.foundation.color.text.base.inverse['@init'],
},
);

export const togglePackageButtonClass = style([
atoms({
display: 'flex',
justifyContent: 'space-between',
width: '100%',
gap: 'sm',
alignItems: 'center',
background: 'none',
border: 'none',
marginInline: 'no',
paddingInlineStart: 'no',
cursor: 'pointer',
}),
]);

export const togglePackageIconClass = style({
transition: 'transform .5s ease',
});
export const togglePackageIconOpenClass = style({
transform: 'rotate(90deg)',
});

export const versionWrapperClass = style({
overflow: 'hidden',
willChange: 'maxHeight',
transition: 'max-height 1s ease-in-out',
});
export const versionWrapperOpenClass = style({});
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export const Footer: FC = () => {
Code of Conduct
</FooterLink>
</Link>
<Link href="/changelogs" passHref legacyBehavior>
<FooterLink href="/changelogs">Changelogs</FooterLink>
</Link>
</Stack>
<Stack
justifyContent="space-around"
Expand Down
3 changes: 0 additions & 3 deletions packages/apps/docs/src/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,3 @@ pages:
jsbindings:
file: /reference/chainweb/chainwebjs.md
url: /js-bindings
# changelogs:
# url: /changelogs
# file: /changelogs/index.tsx
Loading

0 comments on commit 8b759a2

Please sign in to comment.