Skip to content

Commit b2416a0

Browse files
committed
added UI changes
1 parent b4f6a7d commit b2416a0

5 files changed

Lines changed: 694 additions & 448 deletions

File tree

src/components/Document/helper.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,19 @@ export const customizeDocContent = () => {
7979
langSpan.innerText = rawLang;
8080
header.appendChild(langSpan);
8181

82-
/* Copy button (right) */
82+
/* Right group: CTA + copy button */
83+
const rightGroup = document.createElement('div');
84+
rightGroup.classList.add('code-block-header-actions');
85+
86+
const ctaLink = document.createElement('a');
87+
ctaLink.classList.add('ctaButton');
88+
ctaLink.href = 'https://try.thoughtspot.com';
89+
ctaLink.target = '_blank';
90+
ctaLink.rel = 'noopener noreferrer';
91+
ctaLink.innerText = 'Ask SpotterCode';
92+
rightGroup.appendChild(ctaLink);
93+
94+
/* Copy button */
8395
const buttonElement = document.createElement('button');
8496
buttonElement.setAttribute('class', 'copyButton');
8597
buttonElement.setAttribute('aria-label', t('CODE_COPY_BTN_HOVER_TEXT'));
@@ -90,7 +102,9 @@ export const customizeDocContent = () => {
90102
buttonElement.appendChild(imageElement);
91103

92104
enableCopyToClipboard(buttonElement, copySource);
93-
header.appendChild(buttonElement);
105+
rightGroup.appendChild(buttonElement);
106+
107+
header.appendChild(rightGroup);
94108

95109
/* ── Wrap pre in code-block-wrapper ── */
96110
const wrapper = document.createElement('div');

src/components/Document/index.scss

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,48 @@
33
@import '../../assets/styles/admonition.scss';
44
@import '../../assets/styles/grid.scss';
55

6+
.selection-cta-button {
7+
position: fixed;
8+
z-index: 1000;
9+
display: inline-flex;
10+
align-items: center;
11+
gap: 6px;
12+
padding: 8px;
13+
font-size: 13px;
14+
font-weight: 500;
15+
color: #fff;
16+
background: #2770ef;
17+
border-radius: 8px;
18+
text-decoration: none;
19+
white-space: nowrap;
20+
pointer-events: all;
21+
box-shadow:
22+
0 0 8px 0 rgba(25, 35, 49, 0.10),
23+
0 2px 4px 0 rgba(25, 35, 49, 0.04);
24+
transition: background 0.15s ease, box-shadow 0.15s ease;
25+
26+
&::before {
27+
content: '';
28+
display: inline-block;
29+
width: 14px;
30+
height: 14px;
31+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='15 18 9 12 15 6'/%3E%3C/svg%3E");
32+
background-size: contain;
33+
background-repeat: no-repeat;
34+
background-position: center;
35+
flex-shrink: 0;
36+
}
37+
38+
&:hover {
39+
background: #1a5ccc;
40+
color: #fff;
41+
text-decoration: none;
42+
box-shadow:
43+
0 0 12px 0 rgba(25, 35, 49, 0.15),
44+
0 4px 8px 0 rgba(25, 35, 49, 0.08);
45+
}
46+
}
47+
648
.documentWrapper {
749
width: calc(98%);
850
color: var(--primary-color);
@@ -102,6 +144,27 @@
102144
font-family: $font-family-code;
103145
}
104146

147+
.code-block-header-actions {
148+
display: flex;
149+
align-items: center;
150+
gap: 8px;
151+
}
152+
153+
.ctaButton {
154+
display: inline-flex;
155+
align-items: center;
156+
padding: 4px 10px;
157+
font-size: 12px;
158+
font-weight: 500;
159+
color: #2770ef;
160+
border: none;
161+
border-radius: 5px;
162+
cursor: pointer;
163+
text-decoration: none;
164+
white-space: nowrap;
165+
transition: background 0.15s ease;
166+
}
167+
105168
.copyButton {
106169
display: inline-flex;
107170
align-items: center;

src/components/Document/index.tsx

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect } from 'react';
1+
import React, { useEffect, useState, useRef } from 'react';
22
import './index.scss';
33
import { customizeDocContent, addScrollListener } from './helper';
44
import Footer from '../Footer';
@@ -18,6 +18,52 @@ const Document = (props: {
1818
breadcrumsData: any;
1919
markdownBody?: string;
2020
}) => {
21+
const [selectionPos, setSelectionPos] = useState<{ top: number; left: number } | null>(null);
22+
const selectionRef = useRef<string>('');
23+
24+
useEffect(() => {
25+
let mouseDownX = 0;
26+
let mouseDownY = 0;
27+
28+
const handleMouseUp = (e: MouseEvent) => {
29+
const target = e.target as HTMLElement;
30+
if (target.closest('.selection-cta-button')) return;
31+
32+
// If mouse didn't move (plain click, not a drag-select), don't re-show
33+
const moved = Math.abs(e.clientX - mouseDownX) > 3 || Math.abs(e.clientY - mouseDownY) > 3;
34+
if (!moved) return;
35+
36+
const selection = window.getSelection();
37+
const text = selection?.toString().trim() || '';
38+
if (!text) {
39+
setSelectionPos(null);
40+
return;
41+
}
42+
const range = selection!.getRangeAt(0);
43+
const rect = range.getBoundingClientRect();
44+
selectionRef.current = text;
45+
const HEADER_HEIGHT = 108; // main header (60) + secondary header (48)
46+
const rawTop = rect.top - 36;
47+
setSelectionPos({
48+
top: Math.max(HEADER_HEIGHT + 4, rawTop),
49+
left: rect.left,
50+
});
51+
};
52+
53+
const handleMouseDown = (e: MouseEvent) => {
54+
mouseDownX = e.clientX;
55+
mouseDownY = e.clientY;
56+
setSelectionPos(null);
57+
};
58+
59+
document.addEventListener('mouseup', handleMouseUp);
60+
document.addEventListener('mousedown', handleMouseDown);
61+
return () => {
62+
document.removeEventListener('mouseup', handleMouseUp);
63+
document.removeEventListener('mousedown', handleMouseDown);
64+
};
65+
}, []);
66+
2167
useEffect(() => {
2268
customizeDocContent();
2369
}, [props.docContent]);
@@ -131,6 +177,17 @@ const Document = (props: {
131177
className="documentWrapper"
132178
style={!props.shouldShowRightNav ? { width: '100%' } : undefined}
133179
>
180+
{selectionPos && (
181+
<a
182+
className="selection-cta-button"
183+
href="https://try.thoughtspot.com"
184+
target="_blank"
185+
rel="noopener noreferrer"
186+
style={{ top: selectionPos.top, left: selectionPos.left }}
187+
>
188+
Ask SpotterCode
189+
</a>
190+
)}
134191
{!isHomePage && (
135192
<Breadcrums
136193
breadcrumsData={props.breadcrumsData}

0 commit comments

Comments
 (0)