-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try to fix bootstrap theme and deploy it!
- Loading branch information
Showing
9 changed files
with
250 additions
and
9 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
32 changes: 32 additions & 0 deletions
32
packages/docusaurus-theme-bootstrap/src/theme/MDXPage/index.js
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,32 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import Layout from '@theme/Layout'; | ||
import {MDXProvider} from '@mdx-js/react'; | ||
import MDXComponents from '@theme/MDXComponents'; | ||
|
||
function MDXPage(props) { | ||
const {content: MDXPageContent} = props; | ||
const {frontMatter, metadata} = MDXPageContent; | ||
const {title, description} = frontMatter; | ||
const {permalink} = metadata; | ||
|
||
return ( | ||
<Layout title={title} description={description} permalink={permalink}> | ||
<main> | ||
<div className="container margin-vert--lg padding-vert--lg"> | ||
<MDXProvider components={MDXComponents}> | ||
<MDXPageContent /> | ||
</MDXProvider> | ||
</div> | ||
</main> | ||
</Layout> | ||
); | ||
} | ||
|
||
export default MDXPage; |
14 changes: 14 additions & 0 deletions
14
packages/docusaurus-theme-bootstrap/src/theme/TabItem/index.js
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,14 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
function TabItem(props) { | ||
return <div>{props.children}</div>; | ||
} | ||
|
||
export default TabItem; |
154 changes: 154 additions & 0 deletions
154
packages/docusaurus-theme-bootstrap/src/theme/Tabs/index.js
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,154 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React, {useState, Children, useEffect} from 'react'; | ||
|
||
import clsx from 'clsx'; | ||
|
||
import styles from './styles.module.css'; | ||
|
||
const keys = { | ||
left: 37, | ||
right: 39, | ||
tab: 9, | ||
}; | ||
|
||
// TODO quick fix to make bootstrap theme work | ||
function useUserPreferencesContext() { | ||
const [state, setState] = useState({}); | ||
|
||
return { | ||
tabGroupChoices: state, | ||
setTabGroupChoices: (id, value) => { | ||
setState((s) => ({...s, [id]: value})); | ||
}, | ||
}; | ||
} | ||
|
||
function Tabs(props) { | ||
const {block, children, defaultValue, values, groupId} = props; | ||
|
||
const {tabGroupChoices, setTabGroupChoices} = useUserPreferencesContext(); | ||
|
||
const [selectedValue, setSelectedValue] = useState(defaultValue); | ||
const [keyboardPress, setKeyboardPress] = useState(false); | ||
|
||
if (groupId != null) { | ||
const relevantTabGroupChoice = tabGroupChoices[groupId]; | ||
if ( | ||
relevantTabGroupChoice != null && | ||
relevantTabGroupChoice !== selectedValue && | ||
values.some((value) => value.value === relevantTabGroupChoice) | ||
) { | ||
setSelectedValue(relevantTabGroupChoice); | ||
} | ||
} | ||
|
||
const changeSelectedValue = (newValue) => { | ||
setSelectedValue(newValue); | ||
if (groupId != null) { | ||
setTabGroupChoices(groupId, newValue); | ||
} | ||
}; | ||
|
||
const tabRefs = []; | ||
|
||
const focusNextTab = (tabs, target) => { | ||
const next = tabs.indexOf(target) + 1; | ||
|
||
if (!tabs[next]) { | ||
tabs[0].focus(); | ||
} else { | ||
tabs[next].focus(); | ||
} | ||
}; | ||
|
||
const focusPreviousTab = (tabs, target) => { | ||
const prev = tabs.indexOf(target) - 1; | ||
|
||
if (!tabs[prev]) { | ||
tabs[tabs.length - 1].focus(); | ||
} else { | ||
tabs[prev].focus(); | ||
} | ||
}; | ||
|
||
const handleKeydown = (tabs, target, event) => { | ||
switch (event.keyCode) { | ||
case keys.right: | ||
focusNextTab(tabs, target); | ||
break; | ||
case keys.left: | ||
focusPreviousTab(tabs, target); | ||
break; | ||
default: | ||
break; | ||
} | ||
}; | ||
|
||
const handleKeyboardEvent = (event) => { | ||
if (event.metaKey || event.altKey || event.ctrlKey) { | ||
return; | ||
} | ||
|
||
setKeyboardPress(true); | ||
}; | ||
|
||
const handleMouseEvent = () => { | ||
setKeyboardPress(false); | ||
}; | ||
|
||
useEffect(() => { | ||
window.addEventListener('keydown', handleKeyboardEvent); | ||
window.addEventListener('mousedown', handleMouseEvent); | ||
}, []); | ||
|
||
return ( | ||
<div> | ||
<ul | ||
role="tablist" | ||
aria-orientation="horizontal" | ||
className={clsx('tabs', { | ||
'tabs--block': block, | ||
})}> | ||
{values.map(({value, label}) => ( | ||
<li | ||
role="tab" | ||
tabIndex={0} | ||
aria-selected={selectedValue === value} | ||
className={clsx('tabs__item', styles.tabItem, { | ||
'tabs__item--active': selectedValue === value, | ||
})} | ||
style={keyboardPress ? {} : {outline: 'none'}} | ||
key={value} | ||
ref={(tabControl) => tabRefs.push(tabControl)} | ||
onKeyDown={(event) => { | ||
handleKeydown(tabRefs, event.target, event); | ||
handleKeyboardEvent(event); | ||
}} | ||
onFocus={() => changeSelectedValue(value)} | ||
onClick={() => { | ||
changeSelectedValue(value); | ||
setKeyboardPress(false); | ||
}} | ||
onPointerDown={() => setKeyboardPress(false)}> | ||
{label} | ||
</li> | ||
))} | ||
</ul> | ||
<div role="tabpanel" className="margin-vert--md"> | ||
{ | ||
Children.toArray(children).filter( | ||
(child) => child.props.value === selectedValue, | ||
)[0] | ||
} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default Tabs; |
11 changes: 11 additions & 0 deletions
11
packages/docusaurus-theme-bootstrap/src/theme/Tabs/styles.module.css
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,11 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
.tabItem { | ||
margin-top: 0 !important; | ||
} | ||
|
14 changes: 14 additions & 0 deletions
14
packages/docusaurus-theme-bootstrap/src/theme/hooks/usePrismTheme.js
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,14 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import defaultTheme from 'prism-react-renderer/themes/palenight'; | ||
|
||
const usePrismTheme = () => { | ||
return defaultTheme; | ||
}; | ||
|
||
export default usePrismTheme; |
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
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