|
1 | 1 | import { forwardRef, memo, useCallback, useMemo } from 'react'; |
2 | | -import { useForm } from 'react-hook-form'; |
| 2 | +import { useForm, useWatch } from 'react-hook-form'; |
3 | 3 |
|
4 | 4 | import { usePreferences } from '../../context/PreferencesContext.js'; |
| 5 | +import { fieldLabelStyle } from '../../elements/FormatField.tsx'; |
| 6 | +import { GroupPane } from '../../elements/GroupPane.tsx'; |
| 7 | +import Label from '../../elements/Label.tsx'; |
| 8 | +import { NumberInput2Controller } from '../../elements/NumberInput2Controller.tsx'; |
| 9 | +import { Select2Controller } from '../../elements/Select2Controller.tsx'; |
5 | 10 | import useNucleus from '../../hooks/useNucleus.js'; |
6 | 11 | import { usePanelPreferencesByNuclei } from '../../hooks/usePanelPreferences.js'; |
| 12 | +import { PEAKS_SHAPES } from '../../modal/EditPeakShapeModal.tsx'; |
7 | 13 | import { getUniqueNuclei } from '../../utility/getUniqueNuclei.js'; |
8 | 14 | import type { NucleusPreferenceField } from '../extra/preferences/NucleusPreferences.js'; |
9 | 15 | import { NucleusPreferences } from '../extra/preferences/NucleusPreferences.js'; |
@@ -101,17 +107,75 @@ export default memo( |
101 | 107 | }); |
102 | 108 |
|
103 | 109 | useSettingImperativeHandle(ref, handleSubmit, saveHandler); |
| 110 | + const currentPreferences = useWatch({ control, name: 'nuclei' }); |
104 | 111 |
|
105 | 112 | return ( |
106 | 113 | <PreferencesContainer> |
107 | | - {nuclei?.map((n) => ( |
108 | | - <NucleusPreferences |
109 | | - control={control} |
110 | | - key={n} |
111 | | - nucleus={n} |
112 | | - fields={formatFields} |
113 | | - /> |
114 | | - ))} |
| 114 | + {nuclei?.map((n) => { |
| 115 | + const kind = currentPreferences?.[n].defaultPeakShape?.kind; |
| 116 | + return ( |
| 117 | + <NucleusPreferences |
| 118 | + control={control} |
| 119 | + key={n} |
| 120 | + nucleus={n} |
| 121 | + fields={formatFields} |
| 122 | + renderBottom={() => ( |
| 123 | + <GroupPane |
| 124 | + text="Default peak shape" |
| 125 | + style={{ header: { color: '#005d9e' } }} |
| 126 | + > |
| 127 | + <Label title="Kind:" style={fieldLabelStyle}> |
| 128 | + <Select2Controller |
| 129 | + items={PEAKS_SHAPES} |
| 130 | + control={control} |
| 131 | + name={`nuclei.${n}.defaultPeakShape.kind`} |
| 132 | + /> |
| 133 | + </Label> |
| 134 | + |
| 135 | + <Label title="FWHM:" style={fieldLabelStyle}> |
| 136 | + <NumberInput2Controller |
| 137 | + min={0} |
| 138 | + control={control} |
| 139 | + name={`nuclei.${n}.defaultPeakShape.fwhm`} |
| 140 | + controllerProps={{ |
| 141 | + rules: { required: true }, |
| 142 | + defaultValue: 1, |
| 143 | + }} |
| 144 | + /> |
| 145 | + </Label> |
| 146 | + |
| 147 | + {kind === 'pseudoVoigt' && ( |
| 148 | + <Label title="Mu:" style={fieldLabelStyle}> |
| 149 | + <NumberInput2Controller |
| 150 | + min={0} |
| 151 | + control={control} |
| 152 | + name={`nuclei.${n}.defaultPeakShape.mu`} |
| 153 | + controllerProps={{ |
| 154 | + rules: { required: true }, |
| 155 | + defaultValue: 0.5, |
| 156 | + }} |
| 157 | + /> |
| 158 | + </Label> |
| 159 | + )} |
| 160 | + {kind === 'generalizedLorentzian' && ( |
| 161 | + <Label title="Gamma:" style={fieldLabelStyle}> |
| 162 | + <NumberInput2Controller |
| 163 | + min={-1} |
| 164 | + max={2} |
| 165 | + control={control} |
| 166 | + name={`nuclei.${n}.defaultPeakShape.gamma`} |
| 167 | + controllerProps={{ |
| 168 | + rules: { required: true }, |
| 169 | + defaultValue: 0.5, |
| 170 | + }} |
| 171 | + /> |
| 172 | + </Label> |
| 173 | + )} |
| 174 | + </GroupPane> |
| 175 | + )} |
| 176 | + /> |
| 177 | + ); |
| 178 | + })} |
115 | 179 | </PreferencesContainer> |
116 | 180 | ); |
117 | 181 | }), |
|
0 commit comments