Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SUM-253 | add heading size option #66

Merged
merged 17 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
23 changes: 22 additions & 1 deletion src/components/paragraphs/stanford-card/card-paragraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ type Props = HtmlHTMLAttributes<HTMLDivElement> & {
paragraph: ParagraphStanfordCard
}

const adjustHeadingType = (size: "larger" | "smaller" | "default" | undefined, heading: string): string => {
rebeccahongsf marked this conversation as resolved.
Show resolved Hide resolved
const headingTypes: {[key: string]: number} = {
rebeccahongsf marked this conversation as resolved.
Show resolved Hide resolved
h2: 4,
h3: 3,
h4: 2,
}
if (!headingTypes[heading] || !size || size === "default") return ""
rebeccahongsf marked this conversation as resolved.
Show resolved Hide resolved
let type = headingTypes[heading]
if (size === "larger") {
type += 1
} else if (size === "smaller") {
type -= 1
}
rebeccahongsf marked this conversation as resolved.
Show resolved Hide resolved

return `type-${type}`
rebeccahongsf marked this conversation as resolved.
Show resolved Hide resolved
}

const CardParagraph = ({paragraph, ...props}: Props) => {
const behaviors = getParagraphBehaviors(paragraph)

Expand All @@ -22,8 +39,12 @@ const CardParagraph = ({paragraph, ...props}: Props) => {
paragraph.suCardMedia?.__typename === "MediaVideo" ? paragraph.suCardMedia.mediaOembedVideo : undefined

const headerTagChoice = (behaviors.su_card_styles?.heading || "h2").split(".", 2)
const headerSize = behaviors.su_card_styles?.sum_card_heading_size
const headerTag = headerTagChoice[0]
const headerClasses = headerTagChoice[1]?.replace(".", " ").replace("su-font-splash", "type-3 mb-12") || "mb-12"
const headerClasses = twMerge(
Copy link
Contributor

Choose a reason for hiding this comment

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

this is greatly increasing complexity, I think we advise against this in the future.

headerTagChoice[1]?.replace(".", " ").replace("su-font-splash", "type-3 mb-12") || "mb-12",
adjustHeadingType(headerSize, headerTag)
)
const cardVariant = behaviors.su_card_styles?.sum_card_variant
const hasBgColor = behaviors.su_card_styles?.sum_card_bg_color_variant
const cardBgColor = cardVariant === "pill" ? behaviors.su_card_styles?.sum_card_pill_bg_color_variant : undefined
Expand Down
1 change: 1 addition & 0 deletions src/lib/drupal/drupal-jsonapi.d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type CardParagraphBehaviors = {
heading?: "h2" | "h3" | "h4" | "div.su-splash-font"
hide_heading?: boolean
link_style?: "action" | "button"
sum_card_heading_size?: "default" | "larger" | "smaller"
rebeccahongsf marked this conversation as resolved.
Show resolved Hide resolved
sum_card_bg_color_variant?: boolean
sum_card_variant?: "pill"
sum_card_pill_bg_color_variant?:
Expand Down