-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Video embed, Accordion, added icons, updated React
- Loading branch information
Showing
8 changed files
with
539 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"paths": { | ||
"@site/*": ["./*"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React, {useContext, useEffect, useId, useState} from 'react'; | ||
import { Icon } from '@iconify/react'; | ||
|
||
const AccordionContext = React.createContext({ | ||
group: false, | ||
openedId: null, | ||
setOpenedId(id) {} | ||
}); | ||
|
||
export function Accordion(props) { | ||
const [openedId, setOpenedId] = useState(null); | ||
|
||
const context = { group: props.grouped ?? false, openedId, setOpenedId }; | ||
return <AccordionContext.Provider value={context}> | ||
<p> | ||
{props.children ?? null} | ||
</p> | ||
</AccordionContext.Provider> | ||
} | ||
|
||
export function AccordionItem(props) { | ||
const context = useContext(AccordionContext); | ||
const id = useId(); | ||
|
||
const [openedState, setOpenedState] = useState(props.opened ?? false); | ||
const opened = context.group ? context.openedId === id : openedState; | ||
const setOpened = context.group ? (state) => { | ||
if (state) context.setOpenedId(id); | ||
else if (context.openedId === id) context.setOpenedId(null); | ||
} : setOpenedState; | ||
|
||
useEffect(() => { | ||
if (context.group && props.opened) | ||
context.setOpenedId(id); | ||
}, []); | ||
|
||
return <div className="accordionItem"> | ||
<h3 className="heading" onClick={() => setOpened(!opened)}> | ||
{props.header} | ||
<Icon icon="akar-icons:triangle-up-fill" vFlip={!opened} /> | ||
</h3> | ||
{opened && <div className="content"> | ||
{props.children ?? null} | ||
</div>} | ||
</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, {useState} from "react"; | ||
import Admonition from '@theme/Admonition'; | ||
|
||
function Video(props) { | ||
|
||
const url = new URL(props.url); | ||
|
||
if (url.host === 'youtu.be' || url.hostname === 'youtube.com' || url.host === 'www.youtube.com') { | ||
const code = url.pathname.match(/([A-Za-z0-9_\-]+)\/?$/); | ||
if (!code[1]) { | ||
return <Admonition type="caution" title="Something went wrong...">Failed to parse YouTube URL: {props.url}</Admonition> | ||
} | ||
|
||
const query = new URLSearchParams; | ||
|
||
if (url.searchParams.has('t')) | ||
query.set('start', url.searchParams.get('t')); | ||
|
||
return <iframe width="560" height="315" src={"https://www.youtube-nocookie.com/embed/" + code[1] + '?' + query} | ||
title="YouTube video player" frameBorder="0" className="youtube-video" | ||
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" | ||
allowFullScreen></iframe> | ||
} else { | ||
|
||
return <Admonition type="caution" title="Something went wrong...">Unsupported video URL: {url}</Admonition> | ||
} | ||
} | ||
|
||
export default Video; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
// Import the original mapper | ||
import MDXComponents from '@theme-original/MDXComponents'; | ||
import { Icon } from '@iconify/react'; // Import the entire Iconify library. | ||
|
||
export default { | ||
// Re-use the default mapping | ||
...MDXComponents, | ||
icon: Icon, // Make the iconify Icon component available in MDX as <icon />. | ||
}; |
Oops, something went wrong.