Skip to content

Commit

Permalink
Merge pull request #1 from RobinNagpal/theme_and_menu
Browse files Browse the repository at this point in the history
Theme and menu
  • Loading branch information
RobinNagpal committed Oct 27, 2021
2 parents 9cbfb6f + de95c1b commit e48bf32
Show file tree
Hide file tree
Showing 23 changed files with 733 additions and 248 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
React Image Annotation(TypeScript)
=========================

This is a fork of https://github.com/Secretmapper/react-image-annotation

Since the original project was inactive, only option was to fork and update the code.

![Annotation demo](https://raw.githubusercontent.com/RobinNagpal/react-image-annotation-ts/HEAD/demo.gif)

## Installation
Expand Down
40 changes: 40 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"typescript": "^4.4.4"
},
"dependencies": {
"@szhsin/react-menu": "^2.2.0",
"styled-components": "^5.3.3",
"types": "^0.1.1"
},
Expand Down
70 changes: 0 additions & 70 deletions src/components/Annotation.stories.tsx

This file was deleted.

45 changes: 6 additions & 39 deletions src/components/Annotation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ const Container = styled.div<{ allowTouch?: boolean }>`
touch-action: ${({ allowTouch }) => (allowTouch ? 'pinch-zoom' : 'auto')};
`;

const Items = styled.div`
const ItemsDiv = styled.div`
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
`;

const Target = Items;

export type AnnotationPropsOptional = {
[K in keyof AnnotationProps]?: AnnotationProps[K]; // so that it retains the types
};
Expand Down Expand Up @@ -214,26 +212,10 @@ const Annotation: ComponentType<AnnotationPropsOptional> = compose(
}
};

shouldAnnotationBeActive = (
annotation: IAnnotation,
top: IAnnotation | undefined
) => {
if (this.props.activeAnnotations) {
const isActive = !!this.props.activeAnnotations.find((active) =>
this.props.activeAnnotationComparator(annotation, active)
);

return isActive || top === annotation;
} else {
return top === annotation;
}
};

render() {
const { props } = this;
const {
renderHighlight,
renderContent,
renderSelector,
renderEditor,
renderOverlay,
Expand All @@ -244,11 +226,6 @@ const Annotation: ComponentType<AnnotationPropsOptional> = compose(
src,
} = props;

const topAnnotationAtMouse = this.getTopAnnotationAt(
this.props.relativeMousePos.x,
this.props.relativeMousePos.y
);

return (
<Container
style={props.style}
Expand All @@ -264,25 +241,23 @@ const Annotation: ComponentType<AnnotationPropsOptional> = compose(
draggable={false}
setInnerRef={this.setInnerRef}
/>
<Items>
<ItemsDiv>
{props.annotations.map((annotation) =>
renderHighlight({
key: annotation.data.id,
annotation,
active: this.shouldAnnotationBeActive(
annotation,
topAnnotationAtMouse
),
renderContent: props.renderContent,
})
)}
{!props.disableSelector &&
props.value &&
props.value.geometry &&
renderSelector({
annotation: props.value,
renderContent: props.renderContent,
})}
</Items>
<Target
</ItemsDiv>
<ItemsDiv
onClick={this.onClick}
onMouseUp={this.onMouseUp}
onMouseDown={this.onMouseDown}
Expand All @@ -294,14 +269,6 @@ const Annotation: ComponentType<AnnotationPropsOptional> = compose(
type: props.type,
annotation: props.value!,
})}
{props.annotations.map(
(annotation) =>
this.shouldAnnotationBeActive(annotation, topAnnotationAtMouse) &&
renderContent({
key: annotation.data.id,
annotation: annotation,
})
)}
{!props.disableEditor &&
props.value &&
props.value.selection &&
Expand Down
1 change: 1 addition & 0 deletions src/components/Content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Container = styled.div`
padding: 8px 16px;
margin-top: 8px;
margin-left: 8px;
z-index: 2;
`;

export interface ContentProps {
Expand Down
5 changes: 0 additions & 5 deletions src/components/FancyRectangle/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,4 @@ function FancyRectangle(props: FancyRectangleProps) {
);
}

FancyRectangle.defaultProps = {
className: '',
style: {},
};

export default FancyRectangle;
39 changes: 0 additions & 39 deletions src/components/Oval/index.tsx

This file was deleted.

44 changes: 44 additions & 0 deletions src/components/Shapes/Oval.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React from 'react';
import { withShapeWrapper } from './withShapeWrapper';
import styled from 'styled-components';
import { ShapeProps } from '../../types/index';

const Container = styled.div`
border-radius: 100%;
box-shadow: 0 0 1px 1px white inset;
box-sizing: border-box;
transition: box-shadow 0.21s ease-in-out;
z-index: 1;
cursor: pointer;
`;

function Oval(props: ShapeProps) {
const {
annotation: { geometry },
isMouseOver,
onMouseEnter,
onMouseLeave,
} = props;
if (!geometry) return null;

return (
<Container
style={{
position: 'absolute',
left: `${geometry.x}%`,
top: `${geometry.y}%`,
height: `${geometry.height}%`,
width: `${geometry.width}%`,
border: isMouseOver ? 'solid 1px black' : 'dashed 2px black',
boxShadow: isMouseOver ? '0 0 1px 1px black inset' : '',
backgroundColor: isMouseOver
? 'rgba(128, 128, 128, 0.3)'
: 'rgba(128, 128, 128, 0.05)',
}}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
/>
);
}

export default withShapeWrapper(Oval);
Loading

0 comments on commit e48bf32

Please sign in to comment.