Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions packages/feedback/src/screenshot/components/PenIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { VNode, h as hType } from 'preact';

interface FactoryParams {
h: typeof hType;
}

export default function PenIconFactory({
h, // eslint-disable-line @typescript-eslint/no-unused-vars
}: FactoryParams) {
return function PenIcon({ isAnnotating, onClick }: { isAnnotating: boolean; onClick: (e: Event) => void }): VNode {
return (
<button
class="editor__pen-tool"
style={{
background: isAnnotating
? 'var(--button-primary-background, var(--accent-background))'
: 'var(--button-background, var(--background))',
color: isAnnotating
? 'var(--button-primary-foreground, var(--accent-foreground))'
: 'var(--button-foreground, var(--foreground))',
}}
onClick={onClick}
>
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M8.5 12L12 8.5L14 11L11 14L8.5 12Z"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M12 8.5L11 3.5L2 2L3.5 11L8.5 12L12 8.5Z"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path d="M2 2L7.5 7.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
</svg>
</button>
);
};
}
19 changes: 11 additions & 8 deletions packages/feedback/src/screenshot/components/ScreenshotEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { h } from 'preact'; // eslint-disable-line @typescript-eslint/no-unused-
import type * as Hooks from 'preact/hooks';
import { DOCUMENT, WINDOW } from '../../constants';
import CropCornerFactory from './CropCorner';
import PenIconFactory from './PenIcon';
import { createScreenshotInputStyles } from './ScreenshotInput.css';
import { useTakeScreenshotFactory } from './useTakeScreenshot';

Expand Down Expand Up @@ -76,6 +77,7 @@ export function ScreenshotEditorFactory({
return function ScreenshotEditor({ onError }: Props): VNode {
const styles = hooks.useMemo(() => ({ __html: createScreenshotInputStyles(options.styleNonce).innerText }), []);
const CropCorner = CropCornerFactory({ h });
const PenIcon = PenIconFactory({ h });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move these two lines up above the line return function ScreenshotEditor....

They should be in the same spot as the line const useTakeScreenshot = useTakeScreenshotFactory({ hooks });


const canvasContainerRef = hooks.useRef<HTMLDivElement>(null);
const cropContainerRef = hooks.useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -393,14 +395,15 @@ export function ScreenshotEditorFactory({
<div class="editor">
<style nonce={options.styleNonce} dangerouslySetInnerHTML={styles} />
{options._experiments.annotations && (
<button
class="editor__pen-tool"
style={{ background: isAnnotating ? 'red' : 'white' }}
onClick={e => {
e.preventDefault();
setIsAnnotating(!isAnnotating);
}}
></button>
<div class="editor__tool-container">
<PenIcon
isAnnotating={isAnnotating}
onClick={e => {
e.preventDefault();
setIsAnnotating(!isAnnotating);
}}
/>
</div>
)}
<div class="editor__canvas-container" ref={canvasContainerRef}>
<div class="editor__crop-container" style={{ zIndex: isAnnotating ? 1 : 2 }} ref={cropContainerRef}>
Expand Down
14 changes: 12 additions & 2 deletions packages/feedback/src/screenshot/components/ScreenshotInput.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function createScreenshotInputStyles(styleNonce?: string): HTMLStyleEleme
padding-top: 65px;
padding-bottom: 65px;
flex-grow: 1;
position: relative;

background-color: ${surface200};
background-image: repeating-linear-gradient(
Expand Down Expand Up @@ -55,7 +56,7 @@ export function createScreenshotInputStyles(styleNonce?: string): HTMLStyleEleme
padding: 8px;
gap: 8px;
border-radius: var(--menu-border-radius, 6px);
background: var(--button-primary-background, var(--background));
background: var(--button-background, var(--background));
width: 175px;
position: absolute;
}
Expand Down Expand Up @@ -88,9 +89,18 @@ export function createScreenshotInputStyles(styleNonce?: string): HTMLStyleEleme
border-left: none;
border-top: none;
}
.editor__tool-container {
position: absolute;
padding: 10px 0px;
top: 0;
}
.editor__pen-tool {
width: 30px;
height: 30px;
display: flex;
justify-content: center;
align-items: center;
border: var(--button-border, var(--border));
border-radius: var(--button-border-radius, 6px);
}
`;

Expand Down
Loading