Debian Codegraph @

frontend/js/views/add-child-page/PrimaryFieldRow.tsx

raw
1 import React, { SetStateAction } from "react";
2 import { formatUserLabel } from "../../userLabel";
3 import { getWidgetComponentWithFallback } from "../../widgets";
4 import { Field } from "../../widgets/types";
5
6 /**
7 * The input to change the primary field value for the new child page.
8 */
9 export default function PrimaryField({
10 primary,
11 field,
12 setPrimary,
13 }: {
14 primary: string;
15 setPrimary: (s: SetStateAction<string>) => void;
16 field: Field;
17 }): JSX.Element {
18 const Widget = getWidgetComponentWithFallback(field.type);
19 const value = Widget.deserializeValue
20 ? Widget.deserializeValue(primary, field.type)
21 : primary;
22
23 return (
24 <div className="row field-row">
25 <div className="col-md-12">
26 <dl className="field">
27 <dt>{formatUserLabel(field.label_i18n)}</dt>
28 <dd>
29 <Widget
30 value={value}
31 onChange={setPrimary}
32 type={field.type}
33 field={field}
34 />
35 </dd>
36 </dl>
37 </div>
38 </div>
39 );
40 }