Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 1655b04

Browse files
committed
fix(plugins/plugin-client-common): avoid super-tall action buttons in code blocks
Right now, the code block action buttons have a hover effect that makes them appear to be as tall as the code block input area -- which, with wrapping, is unboundedly tall.
1 parent e5dd107 commit 1655b04

File tree

2 files changed

+66
-28
lines changed

2 files changed

+66
-28
lines changed

plugins/plugin-client-common/src/components/Views/Terminal/Block/Inputv2.tsx

Lines changed: 64 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import Scalar from '../../../Content/Scalar'
4040
import { MutabilityContext, MutabilityState, MutabilityStateOffline } from '../../../Client/MutabilityContext'
4141

4242
import Tooltip from '../../../spi/Tooltip'
43+
import { SupportedIcon } from '../../../spi/Icons'
4344
import TwoFaceIcon from '../../../spi/Icons/TwoFaceIcon'
4445

4546
import { emitGetCodeBlockReadiness, onCodeBlockReadiness, offCodeBlockReadiness } from './CodeBlockEvents'
@@ -561,31 +562,70 @@ export default class CodeBlock<T1, T2, T3> extends StreamingConsumer<Props<T1, T
561562
}
562563
}
563564

564-
type RunProps = Pick<Props, 'optional'> &
565-
Pick<State, 'execution' | 'ready'> & {
566-
onRun: () => void | Promise<void>
565+
abstract class ActionButton<Props> extends React.PureComponent<Props> {
566+
protected abstract get icon(): SupportedIcon
567+
protected abstract get onClick(): () => void
568+
protected abstract get tooltip(): string
569+
protected abstract get className(): string
570+
571+
protected classNameOf(cls: string) {
572+
return `kui--block-action ${cls}`
567573
}
568574

569-
class Cleanup extends React.PureComponent<{ onCleanup: () => void }> {
570575
public render() {
571576
return (
572-
<Tooltip content="Clean up the effects of this code block" position="bottom-end">
573-
<TwoFaceIcon
574-
a="Trash"
575-
b="Checkmark"
576-
delay={4000}
577-
onClick={this.props.onCleanup}
578-
classNameB="green-text"
579-
className="kui--block-action kui--block-action-cleanup"
580-
/>
577+
<Tooltip content={this.tooltip} position="bottom-end">
578+
<div className="flex-layout">
579+
<TwoFaceIcon
580+
a={this.icon}
581+
b="Checkmark"
582+
delay={4000}
583+
onClick={this.onClick}
584+
classNameB="green-text"
585+
className={this.className}
586+
/>
587+
</div>
581588
</Tooltip>
582589
)
583590
}
584591
}
585592

586-
class Run extends React.PureComponent<RunProps> {
587-
public render() {
588-
const tooltip = strings(
593+
/** The Code Block Trash button */
594+
class Cleanup extends ActionButton<{ onCleanup: () => void }> {
595+
private readonly _className = this.classNameOf('kui--block-action-cleanup')
596+
597+
protected get className() {
598+
return this._className
599+
}
600+
601+
protected get tooltip() {
602+
return 'Clean up the effects of this code block'
603+
}
604+
605+
protected get icon(): SupportedIcon {
606+
return 'Trash'
607+
}
608+
609+
protected get onClick() {
610+
return this.props.onCleanup
611+
}
612+
}
613+
614+
type RunProps = Pick<Props, 'optional'> &
615+
Pick<State, 'execution' | 'ready'> & {
616+
onRun: () => void | Promise<void>
617+
}
618+
619+
/** The Code Block Run button */
620+
class Run extends ActionButton<RunProps> {
621+
private readonly _className = this.classNameOf('kui--block-action-run')
622+
623+
protected get className() {
624+
return this._className
625+
}
626+
627+
protected get tooltip() {
628+
return strings(
589629
!this.props.ready && this.props.execution !== 'done' && this.props.execution !== 'error'
590630
? 'Execute with caution! The pre-requisites for this code block have not yet been satisfied.'
591631
: this.props.execution === 'done'
@@ -594,17 +634,13 @@ class Run extends React.PureComponent<RunProps> {
594634
? 'Execution of this command is optional'
595635
: 'Execute this command'
596636
)
597-
return (
598-
<Tooltip content={tooltip} position="bottom-end">
599-
<TwoFaceIcon
600-
a="Play"
601-
b="Checkmark"
602-
delay={4000}
603-
onClick={this.props.onRun}
604-
classNameB="green-text"
605-
className="kui--block-action kui--block-action-run"
606-
/>
607-
</Tooltip>
608-
)
637+
}
638+
639+
protected get icon(): SupportedIcon {
640+
return 'Play'
641+
}
642+
643+
protected get onClick() {
644+
return this.props.onRun
609645
}
610646
}

plugins/plugin-client-common/web/scss/components/Terminal/Commentary.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,8 @@ pre {
694694
width: calc(2em * $action-size);
695695
}
696696
@include BlockAction {
697+
width: auto;
698+
padding: 8px;
697699
font-size: $action-size + em;
698700
color: var(--color-for-guidebook-block-actions);
699701
}

0 commit comments

Comments
 (0)