Debian Codegraph @

ivette/src/dome/renderer/controls/displays.tsx

raw
1 /* ************************************************************************ */
2 /* */
3 /* This file is part of Frama-C. */
4 /* */
5 /* Copyright (C) 2007-2022 */
6 /* CEA (Commissariat à l'énergie atomique et aux énergies */
7 /* alternatives) */
8 /* */
9 /* you can redistribute it and/or modify it under the terms of the GNU */
10 /* Lesser General Public License as published by the Free Software */
11 /* Foundation, version 2.1. */
12 /* */
13 /* It is distributed in the hope that it will be useful, */
14 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
15 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
16 /* GNU Lesser General Public License for more details. */
17 /* */
18 /* See the GNU Lesser General Public License version 2.1 */
19 /* for more details (enclosed in the file licenses/LGPLv2.1). */
20 /* */
21 /* ************************************************************************ */
22
23 // --------------------------------------------------------------------------
24 // --- LEDs, LCD, meters, etc.
25 // --------------------------------------------------------------------------
26
27 /**
28 @packageDocumentation
29 @module dome/controls/displays
30 */
31
32 import React from 'react';
33 import { classes } from 'dome/misc/utils';
34 import { Icon } from './icons';
35 import { LabelProps } from './labels';
36 import './style.css';
37
38 // --------------------------------------------------------------------------
39 // --- LCD
40 // --------------------------------------------------------------------------
41
42 /** Button-like label. */
43 export function LCD(props: LabelProps): JSX.Element {
44 const className = classes(
45 'dome-xButton dome-xBoxButton dome-text-code dome-xButton-lcd ',
46 props.className,
47 );
48 return (
49 <label
50 className={className}
51 title={props.title}
52 style={props.style}
53 >
54 {props.icon && <Icon id={props.icon} />}
55 {props.label}
56 {props.children}
57 </label>
58 );
59 }
60
61 // --------------------------------------------------------------------------
62 // --- Led
63 // --------------------------------------------------------------------------
64
65 export type LEDstatus =
66 undefined | 'inactive' | 'active' | 'positive' | 'negative' | 'warning';
67
68 export interface LEDprops {
69 /**
70 Led status:
71 - `'inactive'`: off (default)
72 - `'active'`: blue color
73 - `'positive'`: green color
74 - `'negative'`: red color
75 - `'warning'`: orange color
76 */
77 status?: LEDstatus;
78 /** Blinking Led (default: `false`). */
79 blink?: boolean;
80 /** Tooltip text. */
81 title?: string;
82 /** Additional CSS class. */
83 className?: string;
84 /** Additional CSS style. */
85 style?: React.CSSProperties;
86 }
87
88 export const LED = (props: LEDprops): JSX.Element => {
89 const className = classes(
90 'dome-xButton-led',
91 `dome-xButton-led-${props.status || 'inactive'}`,
92 props.blink && 'dome-xButton-blink',
93 props.className,
94 );
95 return (
96 <div className={className} title={props.title} style={props.style} />
97 );
98 };
99
100 // --------------------------------------------------------------------------
101 // --- Metter
102 // --------------------------------------------------------------------------
103
104 export interface MeterProps {
105 /** Additional CSS class. */
106 className?: string;
107 /** Additional CSS style. */
108 style?: React.CSSProperties;
109 /** Disabled control. */
110 /** Meter value. Undefined means disabled. */
111 value: number; /** default is undefined */
112 min?: number; /** default is 0.0 */
113 low?: number; /** default is 0.0 */
114 high?: number; /** default is 1.0 */
115 max?: number; /** default is 1.0 */
116 optimum?: number | 'LOW' | 'MEDIUM' | 'HIGH'; /** default is undefined */
117 }
118
119 export const Meter = (props: MeterProps): JSX.Element => {
120 const { className, style, value, optimum, ...ms } = props;
121 const min = props.min ?? 0.0;
122 const max = props.max ?? 1.0;
123 const low = props.low ?? min;
124 const hight = props.high ?? max;
125 const theClass = classes('dome-xMeter', className);
126 let opt: number | undefined;
127 if (value !== undefined)
128 switch (optimum) {
129 case 'LOW': opt = (min + low) / 2; break;
130 case 'MEDIUM': opt = (low + hight) / 2; break;
131 case 'HIGH': opt = (hight + max) / 2; break;
132 default: opt = optimum;
133 }
134 const mv = value === undefined ? min : Math.min(max, Math.max(min, value));
135 return (
136 <meter
137 className={theClass}
138 style={style}
139 value={mv}
140 optimum={opt}
141 {...ms} />
142 );
143 };
144
145 // --------------------------------------------------------------------------