Skip to content

Commit

Permalink
implement titleBar query support
Browse files Browse the repository at this point in the history
  • Loading branch information
mfix22 committed Jun 12, 2022
1 parent f23e9b0 commit f0cb962
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions components/Carbon.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ class Carbon extends React.PureComponent {
<div className="container">
{config.windowControls ? (
<WindowControls
titleBar={this.props.titleBar}
onTitleBarChange={this.props.onTitleBarChange}
theme={config.windowTheme}
code={this.props.children}
copyable={this.props.copyable}
Expand Down
6 changes: 5 additions & 1 deletion components/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const SnippetToolbar = dynamic(() => import('./SnippetToolbar'), {
loading: () => null,
})

const getConfig = omit(['code'])
const getConfig = omit(['code', 'titleBar'])
const unsplashPhotographerCredit = /\n\n\/\/ Photo by.+?on Unsplash/

class Editor extends React.Component {
Expand Down Expand Up @@ -91,6 +91,7 @@ class Editor extends React.Component {
updateState = updates => this.setState(updates, () => this.onUpdate(this.state))

updateCode = code => this.updateState({ code })
updateTitleBar = titleBar => this.updateState({ titleBar })
updateWidth = width => this.setState({ widthAdjustment: false, width })

getCarbonImage = async (
Expand Down Expand Up @@ -322,6 +323,7 @@ class Editor extends React.Component {
backgroundMode,
code,
exportSize,
titleBar,
} = this.state

const config = getConfig(this.state)
Expand Down Expand Up @@ -399,6 +401,8 @@ class Editor extends React.Component {
updateWidth={this.updateWidth}
loading={this.state.loading}
theme={theme}
titleBar={titleBar}
onTitleBarChange={this.updateTitleBar}
>
{code != null ? code : DEFAULT_CODE}
</Carbon>
Expand Down
17 changes: 15 additions & 2 deletions components/WindowControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,25 @@ const CopyButton = React.memo(function CopyButton({ text }) {

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 (
<div className="window-controls">
{WINDOW_THEMES_MAP[theme] || <Controls />}
<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>
{copyable && (
<div className="copy-button">
Expand Down
2 changes: 2 additions & 0 deletions lib/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const readMappings = [
{ field: 'id' },
{ field: 'highlights', type: 'parse' },
{ field: 'code', type: 'decode' },
{ field: 'tb:titleBar', type: 'decode' },
]

const writeMappings = [
Expand All @@ -106,6 +107,7 @@ const writeMappings = [
{ field: 'exportSize:es' },
{ field: 'watermark:wm', type: 'bool' },
{ field: 'code', type: 'encode' },
{ field: 'titleBar:tb', type: 'encode' },
]

export const serializeState = state => {
Expand Down

0 comments on commit f0cb962

Please sign in to comment.