Refactor selector
This commit is contained in:
parent
6958513dd3
commit
7ad866fc94
3 changed files with 74 additions and 69 deletions
54
src/Components/SVG/Elements/Selector/Selector.tsx
Normal file
54
src/Components/SVG/Elements/Selector/Selector.tsx
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
import '../Selector.scss';
|
||||||
|
import * as React from 'react';
|
||||||
|
import { SHOW_SELECTOR_TEXT } from '../../../../utils/default';
|
||||||
|
|
||||||
|
interface ISelectorProps {
|
||||||
|
text: string
|
||||||
|
x: number
|
||||||
|
y: number
|
||||||
|
width: number
|
||||||
|
height: number
|
||||||
|
scale: number
|
||||||
|
style?: React.CSSProperties
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Selector({ text, x, y, width, height, scale, style: overrideStyle }: ISelectorProps): JSX.Element {
|
||||||
|
const xText = x + width / 2;
|
||||||
|
const yText = y + height / 2;
|
||||||
|
|
||||||
|
const style: React.CSSProperties = {
|
||||||
|
stroke: '#3B82F6',
|
||||||
|
strokeWidth: 4 / scale,
|
||||||
|
fillOpacity: 0,
|
||||||
|
transitionProperty: 'all',
|
||||||
|
transitionTimingFunction: 'cubic-bezier(0.4, 0, 0.2, 1)',
|
||||||
|
transitionDuration: '150ms',
|
||||||
|
animation: 'fadein 750ms ease-in alternate infinite',
|
||||||
|
...overrideStyle
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<rect
|
||||||
|
x={x}
|
||||||
|
y={y}
|
||||||
|
width={width}
|
||||||
|
height={height}
|
||||||
|
style={style}
|
||||||
|
>
|
||||||
|
</rect>
|
||||||
|
{SHOW_SELECTOR_TEXT
|
||||||
|
? <text
|
||||||
|
x={xText}
|
||||||
|
y={yText}
|
||||||
|
style={{
|
||||||
|
transform: `scale(${1 / scale}) translateX(-50%)`,
|
||||||
|
transformBox: 'fill-box'
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{ text }
|
||||||
|
</text>
|
||||||
|
: null}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
|
@ -1,9 +1,9 @@
|
||||||
import '../Selector.scss';
|
import '../Selector.scss';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { type IContainerModel } from '../../../../Interfaces/IContainerModel';
|
import { type IContainerModel } from '../../../../Interfaces/IContainerModel';
|
||||||
import { SHOW_SELECTOR_TEXT } from '../../../../utils/default';
|
|
||||||
import { GetAbsolutePosition } from '../../../../utils/itertools';
|
import { GetAbsolutePosition } from '../../../../utils/itertools';
|
||||||
import { RemoveMargin } from '../../../../utils/svg';
|
import { RemoveMargin } from '../../../../utils/svg';
|
||||||
|
import { Selector } from '../Selector/Selector';
|
||||||
|
|
||||||
interface ISelectorContainerProps {
|
interface ISelectorContainerProps {
|
||||||
containers: Map<string, IContainerModel>
|
containers: Map<string, IContainerModel>
|
||||||
|
@ -33,41 +33,14 @@ export function SelectorContainer(props: ISelectorContainerProps): JSX.Element {
|
||||||
props.selected.properties.margin.right
|
props.selected.properties.margin.right
|
||||||
));
|
));
|
||||||
|
|
||||||
const xText = x + width / 2;
|
|
||||||
const yText = y + height / 2;
|
|
||||||
|
|
||||||
const style: React.CSSProperties = {
|
|
||||||
stroke: '#3B82F6',
|
|
||||||
strokeWidth: 4 / scale,
|
|
||||||
fillOpacity: 0,
|
|
||||||
transitionProperty: 'all',
|
|
||||||
transitionTimingFunction: 'cubic-bezier(0.4, 0, 0.2, 1)',
|
|
||||||
transitionDuration: '150ms',
|
|
||||||
animation: 'fadein 750ms ease-in alternate infinite'
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<Selector
|
||||||
<rect
|
text={props.selected.properties.displayedText}
|
||||||
x={x}
|
x={x}
|
||||||
y={y}
|
y={y}
|
||||||
width={width}
|
width={width}
|
||||||
height={height}
|
height={height}
|
||||||
style={style}
|
scale={scale}
|
||||||
>
|
/>
|
||||||
</rect>
|
|
||||||
{SHOW_SELECTOR_TEXT
|
|
||||||
? <text
|
|
||||||
x={xText}
|
|
||||||
y={yText}
|
|
||||||
style={{
|
|
||||||
transform: `scale(${1 / scale}) translateX(-50%)`,
|
|
||||||
transformBox: 'fill-box'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{props.selected.properties.displayedText}
|
|
||||||
</text>
|
|
||||||
: null}
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import '../Selector.scss';
|
import '../Selector.scss';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { SHOW_SELECTOR_TEXT, SYMBOL_MARGIN } from '../../../../utils/default';
|
import { SYMBOL_MARGIN } from '../../../../utils/default';
|
||||||
import { type ISymbolModel } from '../../../../Interfaces/ISymbolModel';
|
import { type ISymbolModel } from '../../../../Interfaces/ISymbolModel';
|
||||||
|
import { Selector } from '../Selector/Selector';
|
||||||
|
|
||||||
interface ISelectorSymbolProps {
|
interface ISelectorSymbolProps {
|
||||||
symbols: Map<string, ISymbolModel>
|
symbols: Map<string, ISymbolModel>
|
||||||
|
@ -27,43 +28,20 @@ export function SelectorSymbol(props: ISelectorSymbolProps): JSX.Element {
|
||||||
props.selected.x + props.selected.width / 2,
|
props.selected.x + props.selected.width / 2,
|
||||||
-SYMBOL_MARGIN - height];
|
-SYMBOL_MARGIN - height];
|
||||||
|
|
||||||
const xText = x + width / 2;
|
|
||||||
const yText = y + height / 2;
|
|
||||||
|
|
||||||
const style: React.CSSProperties = {
|
const style: React.CSSProperties = {
|
||||||
stroke: '#3B82F6',
|
|
||||||
strokeWidth: 4 / scale,
|
|
||||||
fillOpacity: 0,
|
|
||||||
transitionProperty: 'all',
|
|
||||||
transitionTimingFunction: 'cubic-bezier(0.4, 0, 0.2, 1)',
|
|
||||||
transitionDuration: '150ms',
|
|
||||||
animation: 'fadein 750ms ease-in alternate infinite',
|
|
||||||
transform: 'translateX(-50%)',
|
transform: 'translateX(-50%)',
|
||||||
transformBox: 'fill-box'
|
transformBox: 'fill-box'
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<Selector
|
||||||
<rect
|
text={props.selected.displayedText}
|
||||||
x={x}
|
x={x}
|
||||||
y={y}
|
y={y}
|
||||||
width={width}
|
width={width}
|
||||||
height={height}
|
height={height}
|
||||||
style={style}
|
scale={scale}
|
||||||
>
|
style={style}
|
||||||
</rect>
|
/>
|
||||||
{SHOW_SELECTOR_TEXT
|
|
||||||
? <text
|
|
||||||
x={xText}
|
|
||||||
y={yText}
|
|
||||||
style={{
|
|
||||||
transform: `scale(${1 / scale}) translateX(-50%)`,
|
|
||||||
transformBox: 'fill-box'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{props.selected.displayedText}
|
|
||||||
</text>
|
|
||||||
: null}
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue