-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathbjsubway-tram.tsx
More file actions
69 lines (59 loc) · 2.35 KB
/
Copy pathbjsubway-tram.tsx
File metadata and controls
69 lines (59 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { RmgFields, RmgFieldsField } from '@railmapgen/rmg-components';
import { MonoColour } from '@railmapgen/rmg-palette-resources';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { AttrsProps, CityCode } from '../../../../constants/constants';
import {
LINE_WIDTH,
LinePathAttributes,
LinePathType,
LineStyle,
LineStyleComponentProps,
LineStyleType,
} from '../../../../constants/lines';
import { ColorAttribute, ColorField } from '../../../panels/details/color-field';
const BjsubwayTram = (props: LineStyleComponentProps<BjsubwayTramAttributes>) => {
const { id, path, styleAttrs, handlePointerDown } = props;
const { color = defaultBjsubwayTramAttributes.color } = styleAttrs ?? defaultBjsubwayTramAttributes;
const onPointerDown = React.useCallback(
(e: React.PointerEvent<SVGElement>) => handlePointerDown(id, e),
[id, handlePointerDown]
);
return (
<g id={id} onPointerDown={onPointerDown} cursor="pointer">
<path d={path} fill="none" stroke={color[2]} strokeWidth={LINE_WIDTH} />
<path d={path} fill="none" stroke="white" strokeWidth={LINE_WIDTH / 3} />
</g>
);
};
/**
* BjsubwayTram specific props.
*/
export interface BjsubwayTramAttributes extends LinePathAttributes, ColorAttribute {}
const defaultBjsubwayTramAttributes: BjsubwayTramAttributes = {
color: [CityCode.Beijing, 'bj1', '#c23a30', MonoColour.white],
};
const BJSubwayTramAttrsComponent = (props: AttrsProps<BjsubwayTramAttributes>) => {
const { id, attrs, handleAttrsUpdate } = props;
const { t } = useTranslation();
const fields: RmgFieldsField[] = [
{
type: 'custom',
label: t('color'),
component: (
<ColorField type={LineStyleType.BjsubwayTram} defaultTheme={defaultBjsubwayTramAttributes.color} />
),
},
];
return <RmgFields fields={fields} />;
};
const bjsubwayTram: LineStyle<BjsubwayTramAttributes> = {
component: BjsubwayTram,
defaultAttrs: defaultBjsubwayTramAttributes,
attrsComponent: BJSubwayTramAttrsComponent,
metadata: {
displayName: 'panel.details.lines.bjsubwayTram.displayName',
supportLinePathType: [LinePathType.Diagonal, LinePathType.Perpendicular, LinePathType.RotatePerpendicular],
},
};
export default bjsubwayTram;