|
|
|
@ -9,7 +9,7 @@ import Popout, { managePopout } from './Popout'
|
|
|
|
|
import Button from './Button'
|
|
|
|
|
import Presets from './Presets'
|
|
|
|
|
import { COLORS, DEFAULT_PRESETS } from '../lib/constants'
|
|
|
|
|
import { toggle, getPresets, savePresets, generateId } from '../lib/util'
|
|
|
|
|
import { toggle, getPresets, savePresets, generateId, fileToJSON } from '../lib/util'
|
|
|
|
|
import SettingsIcon from './svg/Settings'
|
|
|
|
|
import * as Arrows from './svg/Arrows'
|
|
|
|
|
|
|
|
|
@ -140,10 +140,42 @@ const TypeSettings = React.memo(
|
|
|
|
|
|
|
|
|
|
const resetButtonStyle = { borderTop: `1px solid ${COLORS.SECONDARY}` }
|
|
|
|
|
|
|
|
|
|
const MiscSettings = React.memo(({ format, reset }) => {
|
|
|
|
|
const MiscSettings = React.memo(({ format, reset, applyPreset, settings }) => {
|
|
|
|
|
const input = React.useRef(null)
|
|
|
|
|
let download
|
|
|
|
|
try {
|
|
|
|
|
download = `data:text/json;charset=utf-8,${encodeURIComponent(JSON.stringify(settings))}`
|
|
|
|
|
} catch (error) {
|
|
|
|
|
// pass
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<div className="settings-content">
|
|
|
|
|
<Button center onClick={format}>
|
|
|
|
|
<div className="row">
|
|
|
|
|
<input
|
|
|
|
|
hidden
|
|
|
|
|
ref={input}
|
|
|
|
|
type="file"
|
|
|
|
|
accept=".json"
|
|
|
|
|
onChange={async e => {
|
|
|
|
|
const json = await fileToJSON(e.target.files[0])
|
|
|
|
|
if (json) {
|
|
|
|
|
applyPreset(json)
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
width="50%"
|
|
|
|
|
center
|
|
|
|
|
style={{ borderRight: `1px solid ${COLORS.SECONDARY}` }}
|
|
|
|
|
onClick={() => input.current.click()}
|
|
|
|
|
>
|
|
|
|
|
Import config
|
|
|
|
|
</Button>
|
|
|
|
|
<Button center Component="a" href={download} download="carbon-config.json">
|
|
|
|
|
Export config
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
<Button center onClick={format} style={resetButtonStyle}>
|
|
|
|
|
Prettify code
|
|
|
|
|
</Button>
|
|
|
|
|
<Button center color={COLORS.RED} onClick={reset} style={resetButtonStyle}>
|
|
|
|
@ -151,10 +183,19 @@ const MiscSettings = React.memo(({ format, reset }) => {
|
|
|
|
|
</Button>
|
|
|
|
|
<style jsx>
|
|
|
|
|
{`
|
|
|
|
|
.row {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex: 1;
|
|
|
|
|
}
|
|
|
|
|
.settings-content {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
}
|
|
|
|
|
.settings-content :global(a) {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex: 1;
|
|
|
|
|
user-drag: none;
|
|
|
|
|
}
|
|
|
|
|
`}
|
|
|
|
|
</style>
|
|
|
|
|
</div>
|
|
|
|
@ -340,8 +381,17 @@ class Settings extends React.PureComponent {
|
|
|
|
|
lineHeight={this.props.lineHeight}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
case 'Misc':
|
|
|
|
|
return <MiscSettings format={this.props.format} reset={this.handleReset} />
|
|
|
|
|
case 'Misc': {
|
|
|
|
|
const settings = this.getSettingsFromProps()
|
|
|
|
|
return (
|
|
|
|
|
<MiscSettings
|
|
|
|
|
format={this.props.format}
|
|
|
|
|
reset={this.handleReset}
|
|
|
|
|
applyPreset={this.props.applyPreset}
|
|
|
|
|
settings={settings}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|