From 4170cd0bc867e62ff89594d1b99091afc7761b04 Mon Sep 17 00:00:00 2001
From: rlazarini <remi.lazarini@cea.fr>
Date: Thu, 20 Jun 2024 09:56:55 +0200
Subject: [PATCH] [Ivette] forms : add ButtonField

---
 ivette/src/dome/renderer/layout/forms.tsx | 37 ++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/ivette/src/dome/renderer/layout/forms.tsx b/ivette/src/dome/renderer/layout/forms.tsx
index 7d6f590814e..6992f22f003 100644
--- a/ivette/src/dome/renderer/layout/forms.tsx
+++ b/ivette/src/dome/renderer/layout/forms.tsx
@@ -44,7 +44,12 @@ import React from 'react';
 import * as Dome from 'dome';
 import * as Utils from 'dome/misc/utils';
 import { SVG } from 'dome/controls/icons';
-import { Checkbox, Radio, Select as SelectMenu } from 'dome/controls/buttons';
+import {
+  Checkbox,
+  Radio,
+  Select as SelectMenu,
+  Button
+} from 'dome/controls/buttons';
 import { Label } from 'dome/controls/labels';
 
 export type FieldError =
@@ -1450,6 +1455,36 @@ export function ColorField(props: ColorFieldProps): JSX.Element {
   );
 }
 
+/* --------------------------------------------------------------------------*/
+/* --- Button Field                                                       ---*/
+/* --------------------------------------------------------------------------*/
+/** @category Form Fields */
+export function ButtonField(props: FieldProps<boolean>): JSX.Element | null {
+  const { hidden, disabled } = useContext(props);
+
+  if (hidden) return null;
+
+  const { value, onChanged } = props.state;
+  const { label, title } = props;
+  const css = Utils.classes(
+    'dome-xForm-field dome-text-label',
+    disabled && 'dome-disabled',
+  );
+  const onClick = (): void => {
+    onChanged(!value, undefined, false);
+  };
+  return (
+    <Button
+      className={css}
+      label={label}
+      title={title}
+      disabled={disabled}
+      selected= {value}
+      onClick={onClick}
+    />
+  );
+}
+
 /* --------------------------------------------------------------------------*/
 /* --- Check Box Field                                                    ---*/
 /* --------------------------------------------------------------------------*/
-- 
GitLab