fix up custom theme name input

main
Mike Fix 6 years ago committed by Michael Fix
parent 0db4a89e72
commit 47c30c1b7f

@ -391,7 +391,7 @@ Editor.defaultProps = {
onReset: () => {} onReset: () => {}
} }
function ThemesContainer(props) { function EditorContainer(props) {
const [themes, updateThemes] = React.useState(THEMES) const [themes, updateThemes] = React.useState(THEMES)
React.useEffect(() => { React.useEffect(() => {
@ -408,4 +408,4 @@ function ThemesContainer(props) {
return <Editor {...props} themes={themes} updateThemes={updateThemes} /> return <Editor {...props} themes={themes} updateThemes={updateThemes} />
} }
export default ThemesContainer export default EditorContainer

@ -47,16 +47,18 @@ const HighlightPicker = ({ title, onChange, color }) => (
</div> </div>
) )
const getCustomName = themes => const ThemeCreate = ({
`Custom Theme ${themes.filter(({ name }) => name.startsWith('Custom Theme')).length + 1}` theme,
themes,
const ThemeCreate = ({ theme, themes, highlights, create, updateHighlights }) => { highlights,
create,
updateHighlights,
name,
onInputChange
}) => {
const [preset, updatePreset] = React.useState(theme.id) const [preset, updatePreset] = React.useState(theme.id)
const [highlight, selectHighlight] = React.useState() const [highlight, selectHighlight] = React.useState()
// TODO consider using an uncontrolled input
const [name, updateName] = React.useState(getCustomName(themes))
return ( return (
<Popout pointerLeft="15px" style={{ display: 'flex' }}> <Popout pointerLeft="15px" style={{ display: 'flex' }}>
<div className="theme-settings"> <div className="theme-settings">
@ -67,7 +69,7 @@ const ThemeCreate = ({ theme, themes, highlights, create, updateHighlights }) =>
name="name" name="name"
placeholder="Custom Theme" placeholder="Custom Theme"
value={name} value={name}
onChange={({ target: { value } }) => updateName(value)} onChange={onInputChange}
maxLength="32" maxLength="32"
/> />
</div> </div>

@ -48,13 +48,16 @@ const ThemeItem = ({ children, item, isSelected, remove }) => (
const themeIcon = <ThemeIcon /> const themeIcon = <ThemeIcon />
const getCustomName = themes =>
`Custom Theme ${themes.filter(({ name }) => name.startsWith('Custom Theme')).length + 1}`
class Themes extends React.PureComponent { class Themes extends React.PureComponent {
state = { state = {
highlights: {} highlights: {},
name: ''
} }
componentDidMount() { componentDidMount() {
// TODO consider just using withRouter directly
const { queryState } = getRouteState(this.props.router) const { queryState } = getRouteState(this.props.router)
if (queryState.highlights) { if (queryState.highlights) {
@ -66,11 +69,11 @@ class Themes extends React.PureComponent {
static getDerivedStateFromProps(props) { static getDerivedStateFromProps(props) {
if (!props.isVisible) { if (!props.isVisible) {
// TODO use shared function for this next line
const themeConfig = const themeConfig =
(props.themes && props.themes.find(t => t.id === props.theme)) || DEFAULT_THEME (props.themes && props.themes.find(t => t.id === props.theme)) || DEFAULT_THEME
return { return {
highlights: themeConfig.highlights highlights: themeConfig.highlights,
name: getCustomName(props.themes)
} }
} }
return null return null
@ -107,7 +110,7 @@ class Themes extends React.PureComponent {
const themeConfig = themes.find(t => t.id === theme) || DEFAULT_THEME const themeConfig = themes.find(t => t.id === theme) || DEFAULT_THEME
const dropdownValue = isVisible ? { name: '' } : { id: themeConfig.id, name: themeConfig.name } const dropdownValue = isVisible ? { name: this.state.name } : themeConfig
const dropdownList = [ const dropdownList = [
{ {
@ -123,7 +126,6 @@ class Themes extends React.PureComponent {
innerRef={this.dropdown} innerRef={this.dropdown}
icon={themeIcon} icon={themeIcon}
disableInput={isVisible} disableInput={isVisible}
inputValue={dropdownValue}
selected={dropdownValue} selected={dropdownValue}
list={dropdownList} list={dropdownList}
itemWrapper={this.itemWrapper} itemWrapper={this.itemWrapper}
@ -137,6 +139,8 @@ class Themes extends React.PureComponent {
highlights={highlights} highlights={highlights}
create={this.create} create={this.create}
updateHighlights={this.updateHighlights} updateHighlights={this.updateHighlights}
name={this.state.name}
onInputChange={e => this.setState({ name: e.target.value })}
/> />
)} )}
<style jsx> <style jsx>

Loading…
Cancel
Save