Skip to content

Commit 1826dda

Browse files
committed
#901 Update single and dual color to attrsComponent
1 parent 9160fbd commit 1826dda

File tree

2 files changed

+50
-60
lines changed

2 files changed

+50
-60
lines changed

src/components/svgs/lines/styles/dual-color.tsx

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { IconButton } from '@chakra-ui/react';
2+
import { RmgFields, RmgFieldsField } from '@railmapgen/rmg-components';
23
import { MonoColour } from '@railmapgen/rmg-palette-resources';
34
import React from 'react';
45
import { useTranslation } from 'react-i18next';
56
import { MdOutlineSwapVert } from 'react-icons/md';
6-
import { CityCode, Theme } from '../../../../constants/constants';
7+
import { AttrsProps, CityCode, Theme } from '../../../../constants/constants';
78
import {
89
LinePathAttributes,
910
LinePathType,
@@ -15,10 +16,6 @@ import { useRootDispatch, useRootSelector } from '../../../../redux';
1516
import { saveGraph } from '../../../../redux/param/param-slice';
1617
import { refreshEdgesThunk } from '../../../../redux/runtime/runtime-slice';
1718
import { makeShortPathParallel } from '../../../../util/bezier-parallel';
18-
import {
19-
RmgFieldsFieldDetail,
20-
RmgFieldsFieldSpecificAttributes,
21-
} from '../../../panels/details/rmg-field-specific-attrs';
2219
import { ColorField } from '../../../panels/details/color-field';
2320

2421
const DualColor = (props: LineStyleComponentProps<DualColorAttributes>) => {
@@ -90,47 +87,44 @@ const DualColorSwitch = () => {
9087
);
9188
};
9289

93-
const dualColorFields = [
94-
{
95-
type: 'custom',
96-
label: 'panel.details.lines.dualColor.swap',
97-
component: <DualColorSwitch />,
98-
},
99-
{
100-
type: 'custom',
101-
label: 'panel.details.lines.dualColor.colorA',
102-
component: (
103-
<ColorField
104-
type={LineStyleType.DualColor}
105-
colorKey="colorA"
106-
defaultTheme={defaultDualColorAttributes.colorA}
107-
/>
108-
),
109-
},
110-
{
111-
type: 'custom',
112-
label: 'panel.details.lines.dualColor.colorB',
113-
component: (
114-
<ColorField
115-
type={LineStyleType.DualColor}
116-
colorKey="colorB"
117-
defaultTheme={defaultDualColorAttributes.colorB}
118-
/>
119-
),
120-
},
121-
];
90+
const dualColorAttrsComponent = (props: AttrsProps<DualColorAttributes>) => {
91+
const fields: RmgFieldsField[] = [
92+
{
93+
type: 'custom',
94+
label: 'panel.details.lines.dualColor.swap',
95+
component: <DualColorSwitch />,
96+
},
97+
{
98+
type: 'custom',
99+
label: 'panel.details.lines.dualColor.colorA',
100+
component: (
101+
<ColorField
102+
type={LineStyleType.DualColor}
103+
colorKey="colorA"
104+
defaultTheme={defaultDualColorAttributes.colorA}
105+
/>
106+
),
107+
},
108+
{
109+
type: 'custom',
110+
label: 'panel.details.lines.dualColor.colorB',
111+
component: (
112+
<ColorField
113+
type={LineStyleType.DualColor}
114+
colorKey="colorB"
115+
defaultTheme={defaultDualColorAttributes.colorB}
116+
/>
117+
),
118+
},
119+
];
122120

123-
const attrsComponent = () => (
124-
<RmgFieldsFieldSpecificAttributes
125-
fields={dualColorFields as RmgFieldsFieldDetail<DualColorAttributes>}
126-
type="style"
127-
/>
128-
);
121+
return <RmgFields fields={fields} />;
122+
};
129123

130124
const dualColor: LineStyle<DualColorAttributes> = {
131125
component: DualColor,
132126
defaultAttrs: defaultDualColorAttributes,
133-
attrsComponent,
127+
attrsComponent: dualColorAttrsComponent,
134128
metadata: {
135129
displayName: 'panel.details.lines.dualColor.displayName',
136130
supportLinePathType: [LinePathType.Diagonal, LinePathType.Perpendicular, LinePathType.RotatePerpendicular],

src/components/svgs/lines/styles/single-color.tsx

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import { RmgFields, RmgFieldsField } from '@railmapgen/rmg-components';
12
import { MonoColour } from '@railmapgen/rmg-palette-resources';
23
import React from 'react';
4+
import { AttrsProps, CityCode } from '../../../../constants/constants';
35
import {
46
LinePathAttributes,
57
LinePathType,
@@ -8,11 +10,6 @@ import {
810
LineStyleType,
911
} from '../../../../constants/lines';
1012
import { AttributesWithColor, ColorField } from '../../../panels/details/color-field';
11-
import {
12-
RmgFieldsFieldDetail,
13-
RmgFieldsFieldSpecificAttributes,
14-
} from '../../../panels/details/rmg-field-specific-attrs';
15-
import { CityCode } from '../../../../constants/constants';
1613

1714
const SingleColor = (props: LineStyleComponentProps<SingleColorAttributes>) => {
1815
const { id, path, styleAttrs, newLine, handlePointerDown } = props;
@@ -47,25 +44,24 @@ const defaultSingleColorAttributes: SingleColorAttributes = {
4744
color: [CityCode.Shanghai, 'sh1', '#E4002B', MonoColour.white],
4845
};
4946

50-
const singleColorFields = [
51-
{
52-
type: 'custom',
53-
label: 'color',
54-
component: <ColorField type={LineStyleType.SingleColor} defaultTheme={defaultSingleColorAttributes.color} />,
55-
},
56-
];
47+
const singleColorAttrsComponent = (props: AttrsProps<SingleColorAttributes>) => {
48+
const fields: RmgFieldsField[] = [
49+
{
50+
type: 'custom',
51+
label: 'color',
52+
component: (
53+
<ColorField type={LineStyleType.SingleColor} defaultTheme={defaultSingleColorAttributes.color} />
54+
),
55+
},
56+
];
5757

58-
const attrsComponent = () => (
59-
<RmgFieldsFieldSpecificAttributes
60-
fields={singleColorFields as RmgFieldsFieldDetail<SingleColorAttributes>}
61-
type="style"
62-
/>
63-
);
58+
return <RmgFields fields={fields} />;
59+
};
6460

6561
const singleColor: LineStyle<SingleColorAttributes> = {
6662
component: SingleColor,
6763
defaultAttrs: defaultSingleColorAttributes,
68-
attrsComponent,
64+
attrsComponent: singleColorAttrsComponent,
6965
metadata: {
7066
displayName: 'panel.details.lines.singleColor.displayName',
7167
supportLinePathType: [LinePathType.Diagonal, LinePathType.Perpendicular, LinePathType.RotatePerpendicular],

0 commit comments

Comments
 (0)