-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Rebuild Support for custom Markdown on Configuration page #2564
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
839c548
Works for one element
montogeek 1a59d67
uh
montogeek 50c08bf
Almost
montogeek 027fa0e
Works, but not for nested details
montogeek ab99ba6
it works
montogeek a13773a
It works
montogeek 21272f6
Integration with our infra
montogeek f994546
Removed commented code
montogeek 2de395d
Reestructure
montogeek 80f9ba2
It is all React
montogeek faa80c4
Cute cards
montogeek 7423ed1
chore(config) Remove files
montogeek 10e3105
chore(ux) Added arrow
montogeek 7e09ab5
Merge branch 'rebuild' into rebuild-details-details
montogeek 0489210
Remove frontmatter information
montogeek fc38d62
Add support for inline links in comments
montogeek 31bc91c
chore(site): Removed files, clean components
montogeek 4928360
chore(ux): Added comments, remove dead code
montogeek e9f2288
Update src/components/Configuration/Configuration.jsx
EugeneHlushko 768f5cc
Update src/components/Configuration/Configuration.jsx
EugeneHlushko ac78cae
Update src/components/Configuration/Configuration.jsx
EugeneHlushko 6aabf0d
fix(ux) Use correct Array.includes function
montogeek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,39 @@ | ||
import React from "react"; | ||
import ReactMarkdown from "react-markdown"; | ||
import { Details } from "./components"; | ||
|
||
const detailComponentsList = ['link', 'mode', 'entry', 'filename', 'publicPath', 'advancedOutput', 'expert', 'advancedModule', 'alias', 'advancedResolve', 'hints', 'devtool', 'target', 'externals', 'stats', 'advanced', 'libraryTarget']; | ||
|
||
const Pre = props => { | ||
const newChildren = React.Children.map(props.children.props.children, child => { | ||
if (React.isValidElement(child)) { | ||
if (child.props.props.className.includes("keyword")) { | ||
if (!detailComponentsList.includes(child.props.props.componentname)) return child; | ||
|
||
return <Details children={child.props.children.slice(4, React.Children.count(child.props.children) - 4)} url={child.props.props.url} />; | ||
} | ||
|
||
if (child.props.props.className.includes("comment")) { | ||
return <ReactMarkdown source={child.props.children} disallowedTypes={["paragraph"]} unwrapDisallowed />; | ||
} | ||
} | ||
|
||
return child; | ||
}); | ||
|
||
const newProps = { | ||
children: newChildren | ||
}; | ||
|
||
return ( | ||
<pre> | ||
<code {...newProps} /> | ||
</pre> | ||
); | ||
}; | ||
|
||
export default { | ||
components: { | ||
pre: Pre | ||
} | ||
}; |
This file contains hidden or 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 @@ | ||
.shadow { | ||
overflow: visible; | ||
border-radius: 4px; | ||
box-shadow: -1px 1px 10px 0 rgba(255, 255, 255, 0.44); | ||
} | ||
|
||
.inline { | ||
padding-right: 15px !important; | ||
margin: 0 !important; | ||
} |
This file contains hidden or 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,98 @@ | ||
import React from 'react'; | ||
import Popover from 'react-tiny-popover'; | ||
import './Configuration.scss'; | ||
import { timeout } from 'q'; | ||
|
||
const DEFAULT_CHILDREN_SIZE = 4; | ||
|
||
const isFirstChild = child => typeof child === 'string' && child !== ' '; | ||
montogeek marked this conversation as resolved.
Show resolved
Hide resolved
EugeneHlushko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const removeSpaces = child => (isFirstChild(child) ? child.trim() : child); | ||
|
||
const addLink = (child, i, url) => { | ||
return isFirstChild(child) ? ( | ||
<a href={url} key={i}> | ||
{child} | ||
</a> | ||
) : ( | ||
child | ||
); | ||
}; | ||
|
||
const Card = ({ body }) => { | ||
return ( | ||
<div className="markdown"> | ||
<pre className="inline"> | ||
<code>{body}</code> | ||
</pre> | ||
</div> | ||
); | ||
}; | ||
|
||
export class Details extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
open: false, | ||
summary: null, | ||
content: null | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
const { children, url } = this.props; | ||
|
||
// Find the index of </default> | ||
const closeDefaultTagIndex = children.findIndex(child => { | ||
if (React.isValidElement(child)) { | ||
return ( | ||
child.props.props.className.includes('tag') && | ||
child.props.children.length === DEFAULT_CHILDREN_SIZE | ||
); | ||
} | ||
}); | ||
|
||
// Summary is the part of the snippet that would be shown in the code snippet, | ||
// to get it we need to cut the <default></default> enclosing tags | ||
const summary = children | ||
.splice(2, closeDefaultTagIndex - 3) | ||
.map(removeSpaces) | ||
.map((child, i) => addLink(child, i, url)); | ||
|
||
children.splice(0, DEFAULT_CHILDREN_SIZE); // Remove <default></default> information | ||
|
||
this.setState({ | ||
summary, | ||
content: children | ||
}); | ||
} | ||
|
||
clickOutsideHandler = () => { | ||
this.setState({ open: false }); | ||
}; | ||
|
||
toggleVisibility = () => { | ||
this.setState({ open: !this.state.open }); | ||
}; | ||
|
||
render() { | ||
const { open, summary, content } = this.state; | ||
return ( | ||
<Popover | ||
isOpen={open} | ||
position={['right', 'top']} | ||
padding={0} | ||
onClickOutside={this.clickOutsideHandler} | ||
containerClassName={'shadow'} | ||
content={<Card body={content} />} | ||
> | ||
<span | ||
className='code-details-summary-span' | ||
onClick={this.toggleVisibility} | ||
> | ||
{summary} | ||
</span> | ||
</Popover> | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.