|
| 1 | +import type { Instance } from "@nutrient-sdk/viewer"; |
| 2 | +import { baseOptions } from "../../shared/base-options"; |
| 3 | + |
| 4 | +let instance: Instance | null = null; |
| 5 | + |
| 6 | +const item = { |
| 7 | + type: "custom", |
| 8 | + id: "add-radio-group", |
| 9 | + title: "Add Radio Group", |
| 10 | + onPress: async () => { |
| 11 | + const radioWidget1 = new window.NutrientViewer.Annotations.WidgetAnnotation( |
| 12 | + { |
| 13 | + id: window.NutrientViewer.generateInstantId(), |
| 14 | + pageIndex: 0, |
| 15 | + formFieldName: "MyFormField", |
| 16 | + boundingBox: new window.NutrientViewer.Geometry.Rect({ |
| 17 | + left: 100, |
| 18 | + top: 100, |
| 19 | + width: 20, |
| 20 | + height: 20, |
| 21 | + }), |
| 22 | + }, |
| 23 | + ); |
| 24 | + const radioWidget2 = new window.NutrientViewer.Annotations.WidgetAnnotation( |
| 25 | + { |
| 26 | + id: window.NutrientViewer.generateInstantId(), |
| 27 | + pageIndex: 0, |
| 28 | + formFieldName: "MyFormField", |
| 29 | + boundingBox: new window.NutrientViewer.Geometry.Rect({ |
| 30 | + left: 130, |
| 31 | + top: 100, |
| 32 | + width: 20, |
| 33 | + height: 20, |
| 34 | + }), |
| 35 | + }, |
| 36 | + ); |
| 37 | + const formField = new window.NutrientViewer.FormFields.RadioButtonFormField( |
| 38 | + { |
| 39 | + name: "MyFormField", |
| 40 | + annotationIds: new window.NutrientViewer.Immutable.List([ |
| 41 | + radioWidget1.id, |
| 42 | + radioWidget2.id, |
| 43 | + ]), |
| 44 | + options: new window.NutrientViewer.Immutable.List([ |
| 45 | + new window.NutrientViewer.FormOption({ |
| 46 | + label: "Option 1", |
| 47 | + value: "1", |
| 48 | + }), |
| 49 | + new window.NutrientViewer.FormOption({ |
| 50 | + label: "Option 2", |
| 51 | + value: "2", |
| 52 | + }), |
| 53 | + ]), |
| 54 | + defaultValue: "1", |
| 55 | + }, |
| 56 | + ); |
| 57 | + await instance!.create([radioWidget1, radioWidget2, formField]); |
| 58 | + }, |
| 59 | +}; |
| 60 | + |
| 61 | +window.NutrientViewer.load({ |
| 62 | + ...baseOptions, |
| 63 | + theme: window.NutrientViewer.Theme.DARK, |
| 64 | + toolbarItems: [ |
| 65 | + ...window.NutrientViewer.defaultToolbarItems, |
| 66 | + { type: "form-creator" }, |
| 67 | + ], |
| 68 | +}).then((_instance: Instance) => { |
| 69 | + instance = _instance; |
| 70 | + instance.setToolbarItems((items) => [...items, item]); |
| 71 | +}); |
0 commit comments