|
| 1 | +import { RmgFields, RmgFieldsField } from '@railmapgen/rmg-components'; |
| 2 | +import { MonoColour } from '@railmapgen/rmg-palette-resources'; |
| 3 | +import React from 'react'; |
| 4 | +import { useTranslation } from 'react-i18next'; |
| 5 | +import { AttrsProps, CityCode } from '../../../../constants/constants'; |
| 6 | +import { |
| 7 | + LinePathAttributes, |
| 8 | + LinePathType, |
| 9 | + LineStyle, |
| 10 | + LineStyleComponentProps, |
| 11 | + LineStyleType, |
| 12 | +} from '../../../../constants/lines'; |
| 13 | +import { AttributesWithColor, ColorField } from '../../../panels/details/color-field'; |
| 14 | + |
| 15 | +const ChongqingRTLineBadge = (props: LineStyleComponentProps<ChongqingRTLineBadgeAttributes>) => { |
| 16 | + const { id, path, styleAttrs, newLine, handlePointerDown } = props; |
| 17 | + const { color = defaultChongqingRTLineBadgeAttributes.color } = styleAttrs ?? defaultChongqingRTLineBadgeAttributes; |
| 18 | + |
| 19 | + const onPointerDown = React.useCallback( |
| 20 | + (e: React.PointerEvent<SVGElement>) => handlePointerDown(id, e), |
| 21 | + [id, handlePointerDown] |
| 22 | + ); |
| 23 | + |
| 24 | + return ( |
| 25 | + <path |
| 26 | + id={id} |
| 27 | + d={path} |
| 28 | + fill="none" |
| 29 | + stroke={color[2]} |
| 30 | + strokeWidth="3" |
| 31 | + strokeLinecap="round" |
| 32 | + cursor="pointer" |
| 33 | + onPointerDown={newLine ? undefined : onPointerDown} |
| 34 | + pointerEvents={newLine ? 'none' : undefined} |
| 35 | + /> |
| 36 | + ); |
| 37 | +}; |
| 38 | + |
| 39 | +/** |
| 40 | + * ChongqingRTLineBadge specific props. |
| 41 | + */ |
| 42 | +export interface ChongqingRTLineBadgeAttributes extends LinePathAttributes, AttributesWithColor {} |
| 43 | + |
| 44 | +const defaultChongqingRTLineBadgeAttributes: ChongqingRTLineBadgeAttributes = { |
| 45 | + color: [CityCode.Chongqing, 'cq1', '#E4002B', MonoColour.white], |
| 46 | +}; |
| 47 | + |
| 48 | +const chongqingRTLineBadgeAttrsComponent = (props: AttrsProps<ChongqingRTLineBadgeAttributes>) => { |
| 49 | + const { t } = useTranslation(); |
| 50 | + |
| 51 | + const fields: RmgFieldsField[] = [ |
| 52 | + { |
| 53 | + type: 'custom', |
| 54 | + label: t('color'), |
| 55 | + component: ( |
| 56 | + <ColorField |
| 57 | + type={LineStyleType.ChongqingRTLineBadge} |
| 58 | + defaultTheme={defaultChongqingRTLineBadgeAttributes.color} |
| 59 | + /> |
| 60 | + ), |
| 61 | + }, |
| 62 | + ]; |
| 63 | + |
| 64 | + return <RmgFields fields={fields} />; |
| 65 | +}; |
| 66 | + |
| 67 | +const chongqingRTLineBadge: LineStyle<ChongqingRTLineBadgeAttributes> = { |
| 68 | + component: ChongqingRTLineBadge, |
| 69 | + defaultAttrs: defaultChongqingRTLineBadgeAttributes, |
| 70 | + attrsComponent: chongqingRTLineBadgeAttrsComponent, |
| 71 | + metadata: { |
| 72 | + displayName: 'panel.details.lines.chongqingRTLineBadge.displayName', |
| 73 | + supportLinePathType: [LinePathType.Diagonal, LinePathType.Perpendicular, LinePathType.RotatePerpendicular], |
| 74 | + }, |
| 75 | +}; |
| 76 | + |
| 77 | +export default chongqingRTLineBadge; |
0 commit comments