implement titleBar query support

main
Mike Fix 3 years ago
parent f23e9b0984
commit f0cb962933

@ -201,6 +201,8 @@ class Carbon extends React.PureComponent {
<div className="container"> <div className="container">
{config.windowControls ? ( {config.windowControls ? (
<WindowControls <WindowControls
titleBar={this.props.titleBar}
onTitleBarChange={this.props.onTitleBarChange}
theme={config.windowTheme} theme={config.windowTheme}
code={this.props.children} code={this.props.children}
copyable={this.props.copyable} copyable={this.props.copyable}

@ -42,7 +42,7 @@ const SnippetToolbar = dynamic(() => import('./SnippetToolbar'), {
loading: () => null, loading: () => null,
}) })
const getConfig = omit(['code']) const getConfig = omit(['code', 'titleBar'])
const unsplashPhotographerCredit = /\n\n\/\/ Photo by.+?on Unsplash/ const unsplashPhotographerCredit = /\n\n\/\/ Photo by.+?on Unsplash/
class Editor extends React.Component { class Editor extends React.Component {
@ -91,6 +91,7 @@ class Editor extends React.Component {
updateState = updates => this.setState(updates, () => this.onUpdate(this.state)) updateState = updates => this.setState(updates, () => this.onUpdate(this.state))
updateCode = code => this.updateState({ code }) updateCode = code => this.updateState({ code })
updateTitleBar = titleBar => this.updateState({ titleBar })
updateWidth = width => this.setState({ widthAdjustment: false, width }) updateWidth = width => this.setState({ widthAdjustment: false, width })
getCarbonImage = async ( getCarbonImage = async (
@ -322,6 +323,7 @@ class Editor extends React.Component {
backgroundMode, backgroundMode,
code, code,
exportSize, exportSize,
titleBar,
} = this.state } = this.state
const config = getConfig(this.state) const config = getConfig(this.state)
@ -399,6 +401,8 @@ class Editor extends React.Component {
updateWidth={this.updateWidth} updateWidth={this.updateWidth}
loading={this.state.loading} loading={this.state.loading}
theme={theme} theme={theme}
titleBar={titleBar}
onTitleBarChange={this.updateTitleBar}
> >
{code != null ? code : DEFAULT_CODE} {code != null ? code : DEFAULT_CODE}
</Carbon> </Carbon>

@ -38,12 +38,25 @@ const CopyButton = React.memo(function CopyButton({ text }) {
const WINDOW_THEMES_MAP = { bw: <ControlsBW />, boxy: <ControlsBoxy /> } const WINDOW_THEMES_MAP = { bw: <ControlsBW />, boxy: <ControlsBoxy /> }
export default function WindowControls({ theme, copyable, code, light }) { export default function WindowControls({
theme,
copyable,
code,
light,
titleBar,
onTitleBarChange,
}) {
return ( return (
<div className="window-controls"> <div className="window-controls">
{WINDOW_THEMES_MAP[theme] || <Controls />} {WINDOW_THEMES_MAP[theme] || <Controls />}
<div className="window-title-container"> <div className="window-title-container">
<input aria-label="Image Title" type="text" spellCheck="false" /> <input
aria-label="Image title"
type="text"
spellCheck="false"
value={titleBar || ''}
onChange={e => onTitleBarChange(e.target.value)}
/>
</div> </div>
{copyable && ( {copyable && (
<div className="copy-button"> <div className="copy-button">

@ -82,6 +82,7 @@ const readMappings = [
{ field: 'id' }, { field: 'id' },
{ field: 'highlights', type: 'parse' }, { field: 'highlights', type: 'parse' },
{ field: 'code', type: 'decode' }, { field: 'code', type: 'decode' },
{ field: 'tb:titleBar', type: 'decode' },
] ]
const writeMappings = [ const writeMappings = [
@ -106,6 +107,7 @@ const writeMappings = [
{ field: 'exportSize:es' }, { field: 'exportSize:es' },
{ field: 'watermark:wm', type: 'bool' }, { field: 'watermark:wm', type: 'bool' },
{ field: 'code', type: 'encode' }, { field: 'code', type: 'encode' },
{ field: 'titleBar:tb', type: 'encode' },
] ]
export const serializeState = state => { export const serializeState = state => {

Loading…
Cancel
Save