Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
20ca776
Reusable Asciidoc utils
benjaminleonard Dec 6, 2024
06b136b
Delete index.ts
benjaminleonard Dec 6, 2024
4baf24d
Handle empty extensions
benjaminleonard Dec 6, 2024
0829c80
More shared exports
benjaminleonard Dec 6, 2024
af7c6b5
Switch parse source
benjaminleonard Dec 6, 2024
528a130
Move `attrs`
benjaminleonard Dec 6, 2024
58fcbf4
Export `attrs`
benjaminleonard Dec 6, 2024
a28ac36
Shared inline converter and ToC
benjaminleonard Dec 13, 2024
fdd8ab6
Fix icon
benjaminleonard Dec 13, 2024
87d60df
Add mermaid support to listing
benjaminleonard Dec 13, 2024
fc65d31
License
benjaminleonard Dec 13, 2024
c74e439
Export should be listing not mermaid
benjaminleonard Dec 13, 2024
5c25e1b
Undo mermaid listing
benjaminleonard Dec 13, 2024
f6e04f5
Test `renderWithBreaks`
benjaminleonard Dec 16, 2024
2a63c1e
Animated accordion styles
benjaminleonard Dec 16, 2024
23ec093
Hide desktop ToC
benjaminleonard Dec 16, 2024
17b0ec1
Take `className` on ToC instead
benjaminleonard Dec 16, 2024
6a04515
Controlled ToC / autoclose
benjaminleonard Dec 17, 2024
7d38541
Remove unused title
benjaminleonard Dec 17, 2024
2a58f32
ToC padding tweak
benjaminleonard Dec 17, 2024
09651fc
Fix accordion trigger padding
benjaminleonard Dec 17, 2024
95a3aa1
`useDelegatedReactRouterLinks`
benjaminleonard Dec 17, 2024
1e25cdf
Switch let for const
benjaminleonard Dec 17, 2024
25c4f32
Export and add license
benjaminleonard Dec 17, 2024
44f1c04
Tweak license
benjaminleonard Dec 17, 2024
7229a98
Add copyright ignore `use-delegated-links` license
benjaminleonard Dec 17, 2024
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
1 change: 1 addition & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ header:
- '**/dist/*'
- '**/*.md'
- 'LICENSE'
- 'components/src/asciidoc/use-delegated-links.ts'

comment: on-failure
55 changes: 55 additions & 0 deletions components/src/asciidoc/Section.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* Copyright Oxide Computer Company
*/
import { Link16Icon } from '@/icons/react'
import { Content, type SectionBlock, parse } from '@oxide/react-asciidoc'
import cn from 'classnames'
import { createElement } from 'react'

// We need to remove anchors from the section title (and table of contents) because having
// an anchor within an anchor causes a client/server render mismatch
export const stripAnchors = (str: string) => str.replace(/<a[^>]*>(.*?)<\/a>/gi, '$1')

const Section = ({ node }: { node: SectionBlock }) => {
const level = node.level
let title: JSX.Element | string = ''

let sectNum = node.num
sectNum = sectNum === '.' ? '' : sectNum

title = (
<>
<span className="anchor" id={node.id || ''} aria-hidden="true" />
<a className="link group" href={`#${node.id}`}>
{parse(stripAnchors(node.title))}
<Link16Icon className="ml-2 hidden text-accent-secondary group-hover:inline-block" />
</a>
</>
)

if (level === 0) {
return (
<>
<h1 className={cn('sect0', node.role)} data-sectnum={sectNum}>
{title}
</h1>
<Content blocks={node.blocks} />
</>
)
} else {
return (
<div className={cn(`sect${level}`, node.role)}>
{createElement(`h${level + 1}`, { 'data-sectnum': sectNum }, title)}
<div className="sectionbody">
<Content blocks={node.blocks} />
</div>
</div>
)
}
}

export default Section
Loading