1
1
import { MonoColour } from '@railmapgen/rmg-palette-resources' ;
2
2
import React from 'react' ;
3
- import { CityCode } from '../../../constants/constants' ;
3
+ import { useTranslation } from 'react-i18next' ;
4
+ import { RmgFields , RmgFieldsField } from '@railmapgen/rmg-components' ;
5
+ import { AttrsProps , CityCode } from '../../../constants/constants' ;
4
6
import { MiscNodeType , Node , NodeComponentProps } from '../../../constants/nodes' ;
5
7
import { AttributesWithColor , ColorField } from '../../panels/details/color-field' ;
6
- import { RmgFieldsFieldDetail , RmgFieldsFieldSpecificAttributes } from '../../panels/details/rmg-field-specific-attrs' ;
7
8
import { MultilineText } from '../common/multiline-text' ;
8
9
9
10
const ChongqingRT2021TextLineBadge = ( props : NodeComponentProps < ChongqingRT2021TextLineBadgeAttributes > ) => {
@@ -82,7 +83,7 @@ const ChongqingRT2021TextLineBadge = (props: NodeComponentProps<ChongqingRT2021T
82
83
} ;
83
84
84
85
/**
85
- * BerlinUBahnLineBadge specific props.
86
+ * ChongqingRT2021NumLineBadge specific props.
86
87
*/
87
88
export interface ChongqingRT2021TextLineBadgeAttributes extends AttributesWithColor {
88
89
names : [ string , string ] ;
@@ -95,68 +96,55 @@ const defaultChongqingRT2021TextLineBadgeAttributes: ChongqingRT2021TextLineBadg
95
96
isRapid : false ,
96
97
} ;
97
98
98
- const chongqingRT2021TextLineBadgeFields = [
99
- {
100
- type : 'input' ,
101
- label : 'panel.details.nodes.common.nameZh' ,
102
- value : ( attrs ?: ChongqingRT2021TextLineBadgeAttributes ) =>
103
- ( attrs ?? defaultChongqingRT2021TextLineBadgeAttributes ) . names [ 0 ] ,
104
- onChange : ( val : string | number , attrs_ : ChongqingRT2021TextLineBadgeAttributes | undefined ) => {
105
- // set default value if switched from another type
106
- const attrs = attrs_ ?? defaultChongqingRT2021TextLineBadgeAttributes ;
107
- // set value
108
- attrs . names [ 0 ] = val . toString ( ) ;
109
- // return modified attrs
110
- return attrs ;
99
+ const ChongqingRT2021NumLineBadgeAttrsComponent = ( props : AttrsProps < ChongqingRT2021TextLineBadgeAttributes > ) => {
100
+ const { id , attrs , handleAttrsUpdate } = props ;
101
+ const { t } = useTranslation ( ) ;
102
+ const fields : RmgFieldsField [ ] = [
103
+ {
104
+ type : 'input' ,
105
+ label : t ( 'panel.details.nodes.common.nameZh' ) ,
106
+ value : ( attrs ?? defaultChongqingRT2021TextLineBadgeAttributes ) . names [ 0 ] ,
107
+ onChange : ( val : string | number ) => {
108
+ attrs . names [ 0 ] = val . toString ( ) ;
109
+ handleAttrsUpdate ( id , attrs ) ;
110
+ } ,
111
+ minW : 'full' ,
111
112
} ,
112
- } ,
113
- {
114
- type : 'textarea' ,
115
- label : 'panel.details.nodes.common.nameEn' ,
116
- value : ( attrs ?: ChongqingRT2021TextLineBadgeAttributes ) =>
117
- ( attrs ?? defaultChongqingRT2021TextLineBadgeAttributes ) . names [ 1 ] ,
118
- onChange : ( val : string | number , attrs_ : ChongqingRT2021TextLineBadgeAttributes | undefined ) => {
119
- // set default value if switched from another type
120
- const attrs = attrs_ ?? defaultChongqingRT2021TextLineBadgeAttributes ;
121
- // return if invalid
122
- // set value
123
- attrs . names [ 1 ] = val . toString ( ) ;
124
- // return modified attrs
125
- return attrs ;
113
+ {
114
+ type : 'textarea' ,
115
+ label : t ( 'panel.details.nodes.common.nameEn' ) ,
116
+ value : ( attrs ?? defaultChongqingRT2021TextLineBadgeAttributes ) . names [ 1 ] ,
117
+ onChange : ( val : string | number ) => {
118
+ attrs . names [ 1 ] = val . toString ( ) ;
119
+ handleAttrsUpdate ( id , attrs ) ;
120
+ } ,
121
+ minW : 'full' ,
126
122
} ,
127
- } ,
128
- {
129
- type : 'custom' ,
130
- label : 'color' ,
131
- component : (
132
- < ColorField
133
- type = { MiscNodeType . ChongqingRT2021TextLineBadge }
134
- defaultTheme = { defaultChongqingRT2021TextLineBadgeAttributes . color }
135
- />
136
- ) ,
137
- } ,
138
- {
139
- type : 'switch' ,
140
- label : 'panel.details.nodes.chongqingRT2021TextLineBadge.isRapid' ,
141
- value : ( attrs ?: ChongqingRT2021TextLineBadgeAttributes ) =>
142
- ( attrs ?? defaultChongqingRT2021TextLineBadgeAttributes ) . isRapid ,
143
- onChange : ( val : boolean , attrs_ : ChongqingRT2021TextLineBadgeAttributes | undefined ) => {
144
- // set default value if switched from another type
145
- const attrs = attrs_ ?? defaultChongqingRT2021TextLineBadgeAttributes ;
146
- // set value
147
- attrs . isRapid = val ;
148
- // return modified attrs
149
- return attrs ;
123
+ {
124
+ type : 'custom' ,
125
+ label : t ( 'color' ) ,
126
+ component : (
127
+ < ColorField
128
+ type = { MiscNodeType . ChongqingRT2021TextLineBadge }
129
+ defaultTheme = { defaultChongqingRT2021TextLineBadgeAttributes . color }
130
+ />
131
+ ) ,
132
+ minW : 'full' ,
150
133
} ,
151
- oneLine : true ,
152
- } ,
153
- ] ;
154
-
155
- const attrsComponent = ( ) => (
156
- < RmgFieldsFieldSpecificAttributes
157
- fields = { chongqingRT2021TextLineBadgeFields as RmgFieldsFieldDetail < ChongqingRT2021TextLineBadgeAttributes > }
158
- />
159
- ) ;
134
+ {
135
+ type : 'switch' ,
136
+ label : t ( 'panel.details.nodes.chongqingRT2021TextLineBadge.isRapid' ) ,
137
+ isChecked : ( attrs ?? defaultChongqingRT2021TextLineBadgeAttributes ) . isRapid ,
138
+ onChange : ( val : boolean ) => {
139
+ attrs . isRapid = val ;
140
+ handleAttrsUpdate ( id , attrs ) ;
141
+ } ,
142
+ oneLine : true ,
143
+ minW : 'full' ,
144
+ } ,
145
+ ] ;
146
+ return < RmgFields fields = { fields } /> ;
147
+ } ;
160
148
161
149
const chongqingRT2021TextLineBadgeIcon = (
162
150
< svg viewBox = "0 0 21 21" height = { 40 } width = { 40 } focusable = { false } style = { { padding : 3 } } >
@@ -183,7 +171,7 @@ const chongqingRT2021TextLineBadge: Node<ChongqingRT2021TextLineBadgeAttributes>
183
171
component : ChongqingRT2021TextLineBadge ,
184
172
icon : chongqingRT2021TextLineBadgeIcon ,
185
173
defaultAttrs : defaultChongqingRT2021TextLineBadgeAttributes ,
186
- attrsComponent,
174
+ attrsComponent : ChongqingRT2021NumLineBadgeAttrsComponent ,
187
175
metadata : {
188
176
displayName : 'panel.details.nodes.chongqingRT2021TextLineBadge.displayName' ,
189
177
tags : [ ] ,
0 commit comments