Skip to content

Commit

Permalink
initial addition of crossword player
Browse files Browse the repository at this point in the history
this is a first pass, it needs work
  • Loading branch information
sndrs committed Dec 9, 2024
1 parent 97c4202 commit 3fe07f7
Show file tree
Hide file tree
Showing 19 changed files with 1,041 additions and 27 deletions.
3 changes: 3 additions & 0 deletions dotcom-rendering/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// 3rd party type declarations //
// ------------------------------

type GuardianCrossword =
import('@guardian/react-crossword-next').CrosswordProps['data'];

declare module 'chromatic/isChromatic';

declare module 'dynamic-import-polyfill' {
Expand Down
1 change: 1 addition & 0 deletions dotcom-rendering/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@guardian/libs": "19.2.1",
"@guardian/ophan-tracker-js": "2.2.5",
"@guardian/react-crossword": "2.0.2",
"@guardian/react-crossword-next": "npm:@guardian/[email protected]",
"@guardian/shimport": "1.0.2",
"@guardian/source": "8.0.0",
"@guardian/source-development-kitchen": "12.0.0",
Expand Down
22 changes: 18 additions & 4 deletions dotcom-rendering/scripts/env/check-deps.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,24 @@ if (pkg.devDependencies) {
process.exit(1);
}

const mismatches = Object.entries(pkg.dependencies).filter(
([, version]) =>
!semver.valid(version) && !version.startsWith('workspace:'),
);
/**
* We don't check packages that are not semver-compatible
* @type {RegExp[]}
*/
const exceptions = /** @type {const} */ ([
/npm:@guardian\/[email protected]/,
]);

const mismatches = Object.entries(pkg.dependencies)
.filter(
([, version]) =>
!exceptions.some((exception) => exception.test(version)),
)

.filter(
([, version]) =>
!semver.valid(version) && !version.startsWith('workspace:'),
);

if (mismatches.length !== 0) {
warn('dotcom-rendering dependencies should be pinned.');
Expand Down
3 changes: 3 additions & 0 deletions dotcom-rendering/src/components/ArticleContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const articleWidth = (format: ArticleFormat) => {
}
`;
}
case ArticleDesign.Crossword:
/* The crossword player manages its own width; */
return null;
case ArticleDesign.Video:
case ArticleDesign.Audio:
return css`
Expand Down
5 changes: 5 additions & 0 deletions dotcom-rendering/src/components/BylineLink.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { isString } from '@guardian/libs';
import { Hide } from '@guardian/source/react-components';
import { DottedLines } from '@guardian/source-development-kitchen/react-components';
import { Fragment } from 'react';
import { ArticleDesign, type ArticleFormat } from '../lib/articleFormat';
import {
getBylineComponentsFromTokens,
Expand Down Expand Up @@ -160,6 +161,10 @@ const getRenderedTokens = (
);
}

if (design === ArticleDesign.Crossword && renderedTokens.length > 0) {
return [<Fragment key="set-by">Set by: </Fragment>, ...renderedTokens];
}

return renderedTokens;
};

Expand Down
6 changes: 6 additions & 0 deletions dotcom-rendering/src/components/Crossword.importable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Crossword as ReactCrossword } from '@guardian/react-crossword-next';
import type { CrosswordProps } from '@guardian/react-crossword-next';

export const Crossword = ({ data }: CrosswordProps) => (
<ReactCrossword data={data} clueMinWidth={150} />
);
28 changes: 28 additions & 0 deletions dotcom-rendering/src/components/CrosswordInstructions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { css } from '@emotion/react';
import {
textEgyptian17,
textEgyptianBold17,
} from '@guardian/source/foundations';

const instructionsStyles = css`
${textEgyptian17};
white-space: pre-line;
`;

const headerStyles = css`
${textEgyptianBold17};
white-space: pre-line;
`;

export const CrosswordInstructions = ({
instructions,
className,
}: {
instructions: string;
className?: string;
}) => (
<div css={instructionsStyles} className={className}>
<strong css={headerStyles}>Special instructions: </strong>
{instructions}
</div>
);
34 changes: 34 additions & 0 deletions dotcom-rendering/src/components/CrosswordLinks.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { css } from '@emotion/react';
import { isUndefined } from '@guardian/libs';
import { textSans15 } from '@guardian/source/foundations';
import { palette } from '../palette';

const crosswordLinkStyles = css`
${textSans15};
a {
color: ${palette('--standfirst-link-text')};
text-decoration: none;
:hover {
border-bottom: 1px solid ${palette('--standfirst-link-border')};
}
}
`;

export const CrosswordLinks = ({
crossword,
className,
}: {
crossword: GuardianCrossword;
className?: string;
}) => {
return (
isUndefined(crossword.pdf) || (
<span css={crosswordLinkStyles} className={className}>
<a target="_blank" href={crossword.pdf} rel="noreferrer">
PDF version
</a>
</span>
)
);
};
Loading

0 comments on commit 3fe07f7

Please sign in to comment.