Liesten ProCon
This commit is contained in:
1 parent
d9962e22b8
commit
0de185c014
54 files changed
+1105
-392
No files matched your search
@@ -0,0 +1,31 @@
|
||||
'use client';
|
||||
import { useState } from 'react';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { usePlacementScene } from './usePlacementScene';
|
||||
import AnalogSyncDialog from '@/components/sensoren/analogSyncDialog';
|
||||
import { api_saveAnalog } from '@/actions/sensoren/api-analog';
|
||||
import { analogSlots, analogLabels, type AnalogTable } from '@/types/sensoren/analog';
|
||||
|
||||
export function useAnalogScene(initial: AnalogTable, options: { disabled: boolean; snap: boolean; step: number; showHidden: boolean }) {
|
||||
const [previewValue, setPreviewValue] = useState(50);
|
||||
return usePlacementScene(initial, { ...options, title: 'Sensoren Analog', link: '/rk2/sensoren-analog', scope: 'analog', saveData: api_saveAnalog,
|
||||
baseSlots: ['grundbild'], previewOptions: [{ value: 'grundbild', label: 'Grundbild + Wertanzeige' },
|
||||
...analogSlots.filter(slot => slot !== 'grundbild').map(slot => ({ value: slot, label: analogLabels[slot] + ' + Grundbild' }))],
|
||||
renderSync: (id, onDone, onClose) => <AnalogSyncDialog id={id} onDone={onDone} onClose={onClose} />,
|
||||
extraControls: <label className="text-xs">Vorschauwert (kein SPS-Livewert)<Input type="number" min={0} max={100} className="w-24" value={previewValue}
|
||||
onChange={e => { const value = e.target.valueAsNumber; if (Number.isFinite(value)) setPreviewValue(Math.max(0, Math.min(100, value))); }} /></label>,
|
||||
renderValue: (row, placement) => {
|
||||
if (row.valuePlacementId !== placement.id) return null;
|
||||
const fontSize = Math.max(6, Math.min(14, placement.height / 4));
|
||||
return <g pointerEvents="none">
|
||||
{row.prozentkasten && <>
|
||||
<rect x={placement.x + 1} y={placement.y + 1} width={Math.max(0, placement.width - 2)} height={Math.max(0, placement.height - 2)} fill="white" stroke="#334155" vectorEffect="non-scaling-stroke" />
|
||||
<rect x={placement.x + 2} y={placement.y + placement.height * (1 - previewValue / 100)} width={Math.max(0, placement.width - 4)} height={Math.max(0, placement.height * previewValue / 100 - 2)} fill="#94a3b8" />
|
||||
<text x={placement.x + 3} y={placement.y + fontSize} fontSize={fontSize * 0.8}>100</text>
|
||||
<text x={placement.x + 3} y={placement.y + placement.height - 3} fontSize={fontSize * 0.8}>0</text>
|
||||
</>}
|
||||
<text x={placement.x + placement.width / 2} y={placement.y + placement.height / 2} dominantBaseline="middle" textAnchor="middle" fontSize={fontSize} fill="#0f172a">{previewValue} {row.einheit}</text>
|
||||
</g>;
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user