Skip to content
Open
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
38 changes: 38 additions & 0 deletions website/src/components/wordpress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,44 @@ const parseOptions: HTMLReactParserOptions = {
{domToReact(node.children, parseOptions)}
</Button>
)
} else if (node.name === "img") {
const props = attributesToProps(node.attribs)
return (
<img
{...props}
title="Click to view full size"
className={css.wordpressImage}
onClick={(e) => {
// Open image in new tab for full view
window.open(e.currentTarget.src, "_blank")
}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like the click-to-enlarge feature for images! We could also consider adding an accessibility note (like alt text or a tooltip) so users know the image can be enlarged?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added a title tag saying "click to view full size". I thought about adding a caption that only shows on mobile but I don't think that's possible from the code end because the page comes from wordpress.

/>
)
} else if (node.name === "video") {
const props = attributesToProps(node.attribs)
return (
<video {...props} className={css.wordpressVideo} controls>
{domToReact(node.children, parseOptions)}
</video>
)
} else if (
node.name === "div" &&
node.attribs["class"]?.includes("video")
) {
const props = attributesToProps(node.attribs)
return (
<div
{...props}
style={{
position: "relative",
width: "100%",
maxWidth: "100%",
overflow: "hidden",
}}
>
{domToReact(node.children, parseOptions)}
</div>
)
} else if (
node.name === "div" &&
node.attribs["class"]?.includes("wpTabs")
Expand Down
3 changes: 3 additions & 0 deletions website/src/pages/cwkw/cwkw-layout.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export const contentContainer = style([
])

export const leftMargin = style({
width: "100%",
maxWidth: "100%",
marginLeft: 0, // No margin on mobile.
"@media": {
[mediaQueries.medium]: {
marginLeft: drawerWidth,
Expand Down
14 changes: 14 additions & 0 deletions website/src/pages/documents/document.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,17 @@ export const noScrollTop = style({
visibility: "hidden",
opacity: 0,
})

export const wordpressImage = style({
maxWidth: "100%",
height: "auto",
imageRendering: "-webkit-optimize-contrast",
cursor: "pointer",
width: "auto",
})

export const wordpressVideo = style({
maxWidth: "100%",
height: "auto",
width: "100%",
})
92 changes: 91 additions & 1 deletion website/src/pages/edited-collections/chapter.css.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way you could deduplicate some of the styling in this file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed some stylings that are handled at the container level like for tables, but I left the width and maxwidth styles to maintain the sizing more explicitly incase on wordpress it might send in something different.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { style } from "@vanilla-extract/css"
import { globalStyle, style } from "@vanilla-extract/css"
import { hspace, mediaQueries } from "src/style/constants"
import { paddingX, paddingY } from "src/style/utils"
import { std } from "src/style/utils.css"
Expand All @@ -13,3 +13,93 @@ export const docHeader = style([
},
},
])

export const wordpressContentFix = style({
width: "100%",
maxWidth: "100%",
overflow: "hidden",
overflowX: "auto",
WebkitOverflowScrolling: "touch",
})

// Use globalStyle for child element targeting:
globalStyle(
`${wordpressContentFix} h1, ${wordpressContentFix} h2, ${wordpressContentFix} h3, ${wordpressContentFix} h4, ${wordpressContentFix} h5, ${wordpressContentFix} h6`,
{
clear: "both",
width: "100%",
float: "none",
display: "block",
marginBottom: "1rem",
}
)

globalStyle(`${wordpressContentFix} p, ${wordpressContentFix} div`, {
clear: "both",
width: "100%",
float: "none",
maxWidth: "100%",
paddingLeft: "min(var(--padding-left, 0px), 2rem) !important",
paddingRight: "min(var(--padding-right, 0px), 2rem) !important",
})

globalStyle(`${wordpressContentFix} img`, {
maxWidth: "100%",
height: "auto",
float: "none",
display: "block",
margin: "0 auto 1rem auto",
})

globalStyle(`${wordpressContentFix} table`, {
width: "100%",
maxWidth: "100%",
tableLayout: "auto",
wordWrap: "break-word",
fontSize: "0.8rem",
})

globalStyle(
`${wordpressContentFix} table td, ${wordpressContentFix} table th`,
{
padding: "0.4rem 0.2rem",
overflow: "hidden",
verticalAlign: "top",
width: "auto",
minWidth: "0px",
maxWidth: "calc(50vw - 2rem)",
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could change the fixed maxWidth to a variable or theme token so it’s easier to tweak later

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to half the width of the screen.

)

globalStyle(`${wordpressContentFix} table th`, {
fontWeight: "bold",
})

globalStyle(`${wordpressContentFix} table td`, {
lineHeight: "1.2",
})

globalStyle(`${wordpressContentFix} table td img`, {
width: "auto !important", // Override inline width="300"
height: "auto !important", // Override inline height="300"
minWidth: "calc(25vw) !important",
display: "inline-block !important",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 120px minWidth could cause layout issues on small screens. Have we tested this on smaller devices?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to quarter width of the screens so that it stays more consistent. Though if an image really is too small for a particular device then it probably makes sense for the user to click to enlarge anyways.

verticalAlign: "top !important",
})

// Specific rules for tables with many columns (eg. 5 or more) making them scrollable
// Compromise between readability and usability
globalStyle(`${wordpressContentFix} table:has(tr td:nth-child(5))`, {
minWidth: "max-content", // Wide tables can go as wide as needed
whiteSpace: "nowrap",
})

globalStyle(`${wordpressContentFix} pre`, {
whiteSpace: "pre-wrap",
wordWrap: "break-word",
overflowX: "auto",
maxWidth: "100%",
margin: "0 0 1rem 0",
padding: "0.5rem",
fontSize: "0.85rem",
})
12 changes: 11 additions & 1 deletion website/src/pages/edited-collections/chapter.page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from "react"
import { Helmet } from "react-helmet"
import { Breadcrumbs, Link, WordpressPage } from "src/components"
import { useMediaQuery } from "src/custom-hooks"
import * as Dailp from "src/graphql/dailp"
import { chapterRoute, collectionRoute } from "src/routes"
import { mediaQueries } from "src/style/constants"
import * as util from "src/style/utils.css"
import CWKWLayout from "../cwkw/cwkw-layout"
import * as css from "../cwkw/cwkw-layout.css"
Expand All @@ -21,6 +23,8 @@ const ChapterPage = (props: {
},
})

const isDesktop = useMediaQuery(mediaQueries.medium)

const dialog = useDialog()

const subchapters = useSubchapters(props.chapterSlug)
Expand Down Expand Up @@ -64,7 +68,13 @@ const ChapterPage = (props: {
)}
</Breadcrumbs>
</header>
<WordpressPage slug={`/${chapter.slug.replace(/_/g, "-")}`} />
{isDesktop ? (
<WordpressPage slug={`/${chapter.slug.replace(/_/g, "-")}`} />
) : (
<div className={chapterStyle.wordpressContentFix}>
<WordpressPage slug={`/${chapter.slug.replace(/_/g, "-")}`} />
</div>
)}
</>
) : null}

Expand Down