Skip to content

Commit 9f2b29f

Browse files
feat: allow to customize style for spectrum info block (#4011)
Closes: zakodium/nmrium#638
1 parent 54426e2 commit 9f2b29f

6 files changed

Lines changed: 50 additions & 33 deletions

File tree

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171
"@tanstack/react-form": "^1.28.3",
7272
"@tanstack/react-table": "^8.21.3",
7373
"@zakodium/nmr-types": "^0.5.1",
74-
"@zakodium/nmrium-core": "^0.6.5",
75-
"@zakodium/nmrium-core-plugins": "^0.6.39",
74+
"@zakodium/nmrium-core": "^0.6.6",
75+
"@zakodium/nmrium-core-plugins": "^0.6.40",
7676
"@zakodium/pdnd-esm": "^1.0.2",
7777
"@zip.js/zip.js": "^2.8.20",
7878
"cheminfo-font": "^1.13.1",

src/component/1d-2d/components/SpectrumInfoBlock.tsx

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { Spectrum } from '@zakodium/nmrium-core';
22
import dlv from 'dlv';
3-
import type { CSSProperties } from 'react';
43
import { useState } from 'react';
54
import { useResizeObserver } from 'react-d3-utils';
65
import { BsArrowsMove } from 'react-icons/bs';
76
import { FaTimes } from 'react-icons/fa';
7+
import { SVGStyledText } from 'react-science/ui';
88

99
import { useIsInset } from '../../1d/inset/InsetProvider.js';
1010
import { useChartData } from '../../context/ChartContext.js';
@@ -22,22 +22,6 @@ const verticalSpace = 5;
2222
const boxPadding = 0;
2323
const dragShiftY = 24;
2424

25-
const styles: Record<'value' | 'label' | 'colorIndicator', CSSProperties> = {
26-
label: {
27-
fontSize: '11px',
28-
fill: 'black',
29-
fontWeight: 'bold',
30-
},
31-
value: {
32-
fontSize: '12px',
33-
fill: 'black',
34-
},
35-
colorIndicator: {
36-
width: '10px',
37-
height: '2px',
38-
},
39-
};
40-
4125
function getInfoValue(
4226
spectrum: Spectrum,
4327
field: { jpath: string[]; format: string },
@@ -81,9 +65,10 @@ function SpectrumInfoBlock() {
8165
x: number;
8266
y: number;
8367
}>(coordinate);
68+
8469
const {
8570
current: {
86-
infoBlock: { visible, fields },
71+
infoBlock: { visible, fields, nameStyle, valueStyle },
8772
},
8873
} = usePreferences();
8974

@@ -95,10 +80,12 @@ function SpectrumInfoBlock() {
9580
: infoFields?.length - (infoFields?.length % 2)
9681
? 2
9782
: 1) || 0);
83+
9884
const [
9985
ref,
10086
{ width: boxWidth, height: boxHeight } = { width: 0, height: 0 },
10187
] = useResizeObserver();
88+
10289
const { onPointerDown } = useDraggable({
10390
position: coordinate,
10491
onChange: (dragEvent) => {
@@ -215,12 +202,13 @@ function SpectrumInfoBlock() {
215202
space={verticalSpace}
216203
key={field.jpath + field.label}
217204
>
218-
<text alignmentBaseline="middle" style={styles.label}>
205+
<SVGStyledText {...nameStyle} alignmentBaseline="middle">
219206
{field.label} :
220-
</text>
221-
<text alignmentBaseline="middle" style={styles.value}>
207+
</SVGStyledText>
208+
209+
<SVGStyledText {...valueStyle} alignmentBaseline="middle">
222210
{getInfoValue(spectrum, field)}
223-
</text>
211+
</SVGStyledText>
224212
</SVGGroup>
225213
);
226214
})}

src/component/modal/setting/tanstack_general_settings/tabs/title_block_tab.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useCallback, useMemo } from 'react';
55
import { FaPlus, FaRegTrashAlt } from 'react-icons/fa';
66
import {
77
Button,
8+
FieldGroupSVGTextStyleFields,
89
TableDragRowHandler,
910
createTableColumnHelper,
1011
withForm,
@@ -42,6 +43,21 @@ export const TitleBlockTab = withForm({
4243
{({ Checkbox }) => <Checkbox label="Display spectrum info block" />}
4344
</AppField>
4445
</Section>
46+
<Section title="Text style color">
47+
<FieldGroupSVGTextStyleFields
48+
form={form}
49+
fields="infoBlock.nameStyle"
50+
label="Name text color"
51+
previewText="Pulse sequence :"
52+
/>
53+
54+
<FieldGroupSVGTextStyleFields
55+
form={form}
56+
fields="infoBlock.valueStyle"
57+
label="Value text color"
58+
previewText="lon1027"
59+
/>
60+
</Section>
4561
<TableSection
4662
title="Fields"
4763
actions={

src/component/modal/setting/tanstack_general_settings/validation/title_block_tab_validation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { svgTextStyleFieldsSchema } from 'react-science/ui';
12
import { z } from 'zod';
23

34
import { jpathCodec } from './utils.ts';
@@ -8,6 +9,7 @@ const infoBlockFieldTabValidation = z.object({
89
visible: z.boolean(),
910
label: z.string(),
1011
});
12+
1113
export const infoBlockFieldTabValidationWithUUID = z.codec(
1214
z.object({ ...infoBlockFieldTabValidation.shape, uuid: z.string() }),
1315
infoBlockFieldTabValidation,
@@ -28,4 +30,6 @@ const infoBlockFieldsTabValidation = z.array(
2830
export const infoBlockTabValidation = z.object({
2931
visible: z.boolean(),
3032
fields: infoBlockFieldsTabValidation,
33+
nameStyle: svgTextStyleFieldsSchema.optional(),
34+
valueStyle: svgTextStyleFieldsSchema.optional(),
3135
});

src/component/workspaces/workspaceDefaultProperties.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ export const workspaceDefaultProperties: Required<WorkspacePreferences> = {
114114
},
115115
infoBlock: {
116116
visible: false,
117+
nameStyle: {
118+
fontSize: 11,
119+
fill: 'black',
120+
fontWeight: 'bold',
121+
},
122+
valueStyle: {
123+
fontSize: 12,
124+
fill: 'black',
125+
},
117126
fields: [
118127
{ label: 'Name', jpath: ['info', 'name'], visible: true, format: '' },
119128
{

0 commit comments

Comments
 (0)