This repository has been archived by the owner on Nov 17, 2021. It is now read-only.
-
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.
feat(Demo): Add theme contribution modal
- Loading branch information
1 parent
e4ea41e
commit 9bae762
Showing
9 changed files
with
268 additions
and
71 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,93 @@ | ||
// @ts-ignore | ||
import generate from 'project-name-generator' | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import { submitPR, ThemeObject } from '../utils' | ||
|
||
const randomName = (): string => generate().dashed | ||
|
||
interface Props { | ||
baseTheme: ThemeObject | ||
baseThemeName: string | ||
themeOverrides: ThemeObject | ||
} | ||
|
||
interface State { | ||
projectName: string | ||
} | ||
|
||
export class ContributeForm extends React.Component<Props, State> { | ||
private el: HTMLElement | null | ||
|
||
constructor(props: Props) { | ||
super(props) | ||
|
||
this.el = document.getElementById('modalTarget') | ||
|
||
this.state = { | ||
projectName: randomName() | ||
} | ||
} | ||
|
||
setProjectName = (projectName: string): void => { | ||
this.setState({ projectName }) | ||
this.el = document.getElementById('modal') | ||
} | ||
|
||
onNameChange = (e: React.ChangeEvent<HTMLInputElement>): void => { | ||
e.preventDefault() | ||
this.setProjectName(e.currentTarget.value) | ||
} | ||
|
||
onRandomizeName = (e: React.MouseEvent<HTMLButtonElement>): void => { | ||
e.preventDefault() | ||
this.setProjectName(randomName()) | ||
} | ||
|
||
onSubmitTheme = (e: React.MouseEvent<HTMLButtonElement>): void => { | ||
e.preventDefault() | ||
|
||
submitPR( | ||
this.state.projectName, | ||
'', | ||
this.props.themeOverrides, | ||
this.props.baseThemeName, | ||
this.props.baseTheme | ||
) | ||
} | ||
|
||
render(): React.ReactPortal | null { | ||
return this.el === null | ||
? null | ||
: ReactDOM.createPortal( | ||
<div id="contributeModal"> | ||
<div className="modalContents"> | ||
<p> | ||
Name your theme, and submit as a GitHub pull request to share | ||
your theme with others. | ||
</p> | ||
|
||
<form> | ||
<label>Theme Name</label> | ||
|
||
<div className="labelWrapper"> | ||
<input | ||
value={this.state.projectName} | ||
onChange={this.onNameChange} | ||
/> | ||
|
||
<button type="button" onClick={this.onRandomizeName}> | ||
Randomize | ||
</button> | ||
</div> | ||
|
||
<button onClick={this.onSubmitTheme} type="submit"> | ||
Open Pull Request | ||
</button> | ||
</form> | ||
</div> | ||
</div>, | ||
this.el | ||
) | ||
} | ||
} |
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
Oops, something went wrong.