Skip to content

Commit a06a48e

Browse files
talissoncostaclaude
andcommitted
refactor(components): import Button in Highlight/CodeHelp; extract getRawHtml
Import the Button component instead of relying on the global, and pull Highlight's nested raw-html selection into a named getRawHtml method. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 1768e87 commit a06a48e

2 files changed

Lines changed: 13 additions & 24 deletions

File tree

‎frontend/web/components/CodeHelp.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Constants from 'common/constants'
55
import Utils from 'common/utils/utils'
66
import Icon from './icons/Icon'
77
import CalloutBar from './CalloutBar'
8+
import Button from './base/forms/Button'
89

910
type Snippets = Record<string, string>
1011

‎frontend/web/components/Highlight.js‎

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import hljs from 'highlight.js'
3+
import Button from './base/forms/Button'
34

45
function escapeHtml(unsafe) {
56
if (!unsafe || !unsafe.__html) return unsafe
@@ -103,14 +104,16 @@ class Highlight extends React.Component {
103104
this.props.onBlur?.()
104105
}
105106

107+
// The value to render before escaping: the live edit while focused, the
108+
// current value when there's content, otherwise a disabled/empty placeholder.
109+
getRawHtml = () => {
110+
if (this.state.focus) return this.state.value
111+
if (this.props.children) return { ...this.state.value }
112+
return this.props.disabled ? defaultDisabledValue : defaultValue
113+
}
114+
106115
render() {
107-
const {
108-
children,
109-
className,
110-
disabled,
111-
element: Element,
112-
innerHTML,
113-
} = this.props
116+
const { children, className, element: Element, innerHTML } = this.props
114117
const props = { className, ref: this.setEl }
115118

116119
if (innerHTML) {
@@ -125,23 +128,8 @@ class Highlight extends React.Component {
125128
return <Element {...props}>{children}</Element>
126129
}
127130

128-
const html = this.props.preventEscape
129-
? this.state.focus
130-
? this.state.value
131-
: this.props.children
132-
? { ...this.state.value }
133-
: disabled
134-
? defaultDisabledValue
135-
: defaultValue
136-
: escapeHtml(
137-
this.state.focus
138-
? this.state.value
139-
: this.props.children
140-
? { ...this.state.value }
141-
: disabled
142-
? defaultDisabledValue
143-
: defaultValue,
144-
)
131+
const raw = this.getRawHtml()
132+
const html = this.props.preventEscape ? raw : escapeHtml(raw)
145133
return (
146134
<div className={this.state.expandable ? 'expandable' : ''}>
147135
<pre

0 commit comments

Comments
 (0)