Skip to content

Commit

Permalink
Add strong type #2798 (#2799)
Browse files Browse the repository at this point in the history
* Add strong type #2798

* Adjust list to apply highlight #2798
  • Loading branch information
millianapia authored Feb 4, 2025
1 parent 780c643 commit b9de34d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 18 deletions.
18 changes: 17 additions & 1 deletion web/pageComponents/shared/portableText/Blocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ import {
PortableTextTypeComponent,
} from '@portabletext/react'
import { PortableTextBlock, PortableTextBlockStyle } from '@portabletext/types'
import { FigureWithLayout, Quote, Fact, ExternalLink, InternalLink, BasicIframe, Highlight } from './components'
import {
FigureWithLayout,
Quote,
Fact,
ExternalLink,
InternalLink,
BasicIframe,
Highlight,
BulletList,
NumberedList,
} from './components'
import { twMerge } from 'tailwind-merge'
import { FormattedMessage } from 'react-intl'

Expand Down Expand Up @@ -53,6 +63,11 @@ const defaultSerializers = {
highlight: ({ children }: TypeProps) => {
return <Highlight>{children}</Highlight>
},
strong: ({ children }: any) => <strong className="font-bold text-inherit">{children}</strong>,
},
list: {
bullet: BulletList,
number: NumberedList,
},
}
const footnoteSerializer = {
Expand Down Expand Up @@ -183,6 +198,7 @@ export default function Blocks({
...marksComponents,
...(includeFootnotes && footnoteSerializer),
},
list: { ...defaultSerializers.list },
}}
/>
</div>
Expand Down
28 changes: 19 additions & 9 deletions web/pageComponents/shared/portableText/components/BulletList.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
import { List } from '@components'
import styled from 'styled-components'

const StyledList = styled(List)`
&:not(li > ul) {
margin-bottom: var(--space-medium);
}
`
import * as React from 'react'

export const BulletList = ({ children }: { children?: React.ReactNode }) => {
return <StyledList>{children}</StyledList>
return (
<ul className="list-disc">
{React.Children.map(children, (listItem) => {
if (!React.isValidElement(listItem)) return listItem

const hasHighlight = React.Children.toArray(listItem.props.children).some((child) => {
if (React.isValidElement(child)) {
return child.props?.markType === 'highlight'
}
return false
})

return (
<li className={hasHighlight ? 'marker:text-red-600' : 'marker:text-inherit'}>{listItem.props.children}</li>
)
})}
</ul>
)
}
27 changes: 19 additions & 8 deletions web/pageComponents/shared/portableText/components/NumberedList.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { List } from '@components'
import styled from 'styled-components'
import * as React from 'react'

const StyledList = styled(List)`
&:not(li > ul) {
margin-bottom: var(--space-medium);
}
`
export const NumberedList = ({ children }: { children?: React.ReactNode }) => {
return <StyledList variant="numbered">{children}</StyledList>
return (
<ol className="list-decimal">
{React.Children.map(children, (listItem) => {
if (!React.isValidElement(listItem)) return listItem

const hasHighlight = React.Children.toArray(listItem.props.children).some((child) => {
if (React.isValidElement(child)) {
return child.props?.markType === 'highlight'
}
return false
})

return (
<li className={hasHighlight ? 'marker:text-red-600' : 'marker:text-inherit'}>{listItem.props.children}</li>
)
})}
</ol>
)
}

0 comments on commit b9de34d

Please sign in to comment.