Skip to content

Commit 26d7601

Browse files
authored
feat(user feedback): Create pen tool button for uf annotations (#15102)
Adds a proper pen tool button. The icon for the button is from the hackweek project Unselected: <img width="1192" alt="image" src="https://github.com/user-attachments/assets/4d8ba719-ff93-4108-98a4-560296ef5890" /> Selected: <img width="1192" alt="image" src="https://github.com/user-attachments/assets/7bd24ef2-6877-47a3-bcf1-e871caa4f91b" /> Relates to #15064
1 parent fa65a20 commit 26d7601

File tree

3 files changed

+65
-11
lines changed

3 files changed

+65
-11
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { VNode, h as hType } from 'preact';
2+
3+
interface FactoryParams {
4+
h: typeof hType;
5+
}
6+
7+
export default function PenIconFactory({
8+
h, // eslint-disable-line @typescript-eslint/no-unused-vars
9+
}: FactoryParams) {
10+
return function PenIcon(): VNode {
11+
return (
12+
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
13+
<path
14+
d="M8.5 12L12 8.5L14 11L11 14L8.5 12Z"
15+
stroke="currentColor"
16+
strokeWidth="1.5"
17+
strokeLinecap="round"
18+
strokeLinejoin="round"
19+
/>
20+
<path
21+
d="M12 8.5L11 3.5L2 2L3.5 11L8.5 12L12 8.5Z"
22+
stroke="currentColor"
23+
strokeWidth="1.5"
24+
strokeLinecap="round"
25+
strokeLinejoin="round"
26+
/>
27+
<path d="M2 2L7.5 7.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
28+
</svg>
29+
);
30+
};
31+
}

packages/feedback/src/screenshot/components/ScreenshotEditor.tsx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { h } from 'preact'; // eslint-disable-line @typescript-eslint/no-unused-
66
import type * as Hooks from 'preact/hooks';
77
import { DOCUMENT, WINDOW } from '../../constants';
88
import CropCornerFactory from './CropCorner';
9+
import PenIconFactory from './PenIcon';
910
import { createScreenshotInputStyles } from './ScreenshotInput.css';
1011
import { useTakeScreenshotFactory } from './useTakeScreenshot';
1112

@@ -72,10 +73,11 @@ export function ScreenshotEditorFactory({
7273
options,
7374
}: FactoryParams): ComponentType<Props> {
7475
const useTakeScreenshot = useTakeScreenshotFactory({ hooks });
76+
const CropCorner = CropCornerFactory({ h });
77+
const PenIcon = PenIconFactory({ h });
7578

7679
return function ScreenshotEditor({ onError }: Props): VNode {
7780
const styles = hooks.useMemo(() => ({ __html: createScreenshotInputStyles(options.styleNonce).innerText }), []);
78-
const CropCorner = CropCornerFactory({ h });
7981

8082
const canvasContainerRef = hooks.useRef<HTMLDivElement>(null);
8183
const cropContainerRef = hooks.useRef<HTMLDivElement>(null);
@@ -397,14 +399,25 @@ export function ScreenshotEditorFactory({
397399
<div class="editor">
398400
<style nonce={options.styleNonce} dangerouslySetInnerHTML={styles} />
399401
{options._experiments.annotations && (
400-
<button
401-
class="editor__pen-tool"
402-
style={{ background: isAnnotating ? 'red' : 'white' }}
403-
onClick={e => {
404-
e.preventDefault();
405-
setIsAnnotating(!isAnnotating);
406-
}}
407-
></button>
402+
<div class="editor__tool-container">
403+
<button
404+
class="editor__pen-tool"
405+
style={{
406+
background: isAnnotating
407+
? 'var(--button-primary-background, var(--accent-background))'
408+
: 'var(--button-background, var(--background))',
409+
color: isAnnotating
410+
? 'var(--button-primary-foreground, var(--accent-foreground))'
411+
: 'var(--button-foreground, var(--foreground))',
412+
}}
413+
onClick={e => {
414+
e.preventDefault();
415+
setIsAnnotating(!isAnnotating);
416+
}}
417+
>
418+
<PenIcon />
419+
</button>
420+
</div>
408421
)}
409422
<div class="editor__canvas-container" ref={canvasContainerRef}>
410423
<div class="editor__crop-container" style={{ zIndex: isAnnotating ? 1 : 2 }} ref={cropContainerRef}>

packages/feedback/src/screenshot/components/ScreenshotInput.css.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export function createScreenshotInputStyles(styleNonce?: string): HTMLStyleEleme
1515
padding-top: 65px;
1616
padding-bottom: 65px;
1717
flex-grow: 1;
18+
position: relative;
1819
1920
background-color: ${surface200};
2021
background-image: repeating-linear-gradient(
@@ -55,7 +56,7 @@ export function createScreenshotInputStyles(styleNonce?: string): HTMLStyleEleme
5556
padding: 8px;
5657
gap: 8px;
5758
border-radius: var(--menu-border-radius, 6px);
58-
background: var(--button-primary-background, var(--background));
59+
background: var(--button-background, var(--background));
5960
width: 175px;
6061
position: absolute;
6162
}
@@ -88,9 +89,18 @@ export function createScreenshotInputStyles(styleNonce?: string): HTMLStyleEleme
8889
border-left: none;
8990
border-top: none;
9091
}
92+
.editor__tool-container {
93+
position: absolute;
94+
padding: 10px 0px;
95+
top: 0;
96+
}
9197
.editor__pen-tool {
92-
width: 30px;
9398
height: 30px;
99+
display: flex;
100+
justify-content: center;
101+
align-items: center;
102+
border: var(--button-border, var(--border));
103+
border-radius: var(--button-border-radius, 6px);
94104
}
95105
`;
96106

0 commit comments

Comments
 (0)