From c17cc1e5249b2e7e5446dfca4c6935a6be2dc486 Mon Sep 17 00:00:00 2001 From: tpoisseau <22891227+tpoisseau@users.noreply.github.com> Date: Mon, 15 Dec 2025 12:15:53 +0100 Subject: [PATCH 01/10] feat: add OclReset and improves form css --- src/components/svg/svg_editor.css.ts | 30 ++++++++++++++ src/components/svg/svg_editor.tsx | 47 +++++++++++++--------- src/styling/reset/ocl_reset.tsx | 32 +++++++++++++++ src/styling/reset/ocl_reset_context.tsx | 3 ++ src/styling/reset/ocl_reset_css.ts | 10 +++++ src/styling/use_css.ts | 33 +++++++++++++++ stories/svg_editors/svg_editor.stories.tsx | 10 +++++ 7 files changed, 145 insertions(+), 20 deletions(-) create mode 100644 src/components/svg/svg_editor.css.ts create mode 100644 src/styling/reset/ocl_reset.tsx create mode 100644 src/styling/reset/ocl_reset_context.tsx create mode 100644 src/styling/reset/ocl_reset_css.ts create mode 100644 src/styling/use_css.ts diff --git a/src/components/svg/svg_editor.css.ts b/src/components/svg/svg_editor.css.ts new file mode 100644 index 0000000..293ecb2 --- /dev/null +++ b/src/components/svg/svg_editor.css.ts @@ -0,0 +1,30 @@ +export const atomLabelEditCss = ` +form.react-ocl-atom-label-edit { + position: absolute; + z-index: 1; + display: grid; + grid-template-columns: repeat(4, 1.5em); + align-items: stretch; + gap: 0.25em; + border: 1px solid lightgray; + background-color: white; + padding: 0.25em; +} + +form.react-ocl-atom-label-edit button.react-ocl { + padding: 0.25em; + background-color: #efefef; + border: none; + border-radius: 5px; +} + +form.react-ocl-atom-label-edit input.react-ocl { + padding: 0.25em; + border: solid 1px lightgrey; + border-radius: 3px; +} + +form.react-ocl-atom-label-edit input.react-ocl:focus { + outline: auto; +} +`; diff --git a/src/components/svg/svg_editor.tsx b/src/components/svg/svg_editor.tsx index 8f7f017..685ec82 100644 --- a/src/components/svg/svg_editor.tsx +++ b/src/components/svg/svg_editor.tsx @@ -7,6 +7,7 @@ import type { import { useEffect, useMemo, useReducer, useRef, useState } from 'react'; import { useRefUpToDate } from '../../hooks/use_ref_up_to_date.js'; +import { useCSS } from '../../styling/use_css.ts'; import type { BaseEditorProps } from '../types.js'; import { @@ -22,6 +23,7 @@ import { import type { State } from './editor/reducer.js'; import { stateReducer } from './editor/reducer.js'; import { useHighlight } from './editor/use_highlight.js'; +import { atomLabelEditCss } from './svg_editor.css.ts'; import type { SvgRendererProps } from './svg_renderer.js'; import { SvgRenderer } from './svg_renderer.js'; @@ -275,30 +277,30 @@ function AtomLabelEditForm(props: AtomLabelEditFormProps) { input.focus(); } + useCSS(atomLabelEditCss, 'react-ocl-atom-label-edit-stable'); + useCSS( + ` + form.react-ocl-atom-label-edit { + top: ${formCoords.y}px; + left: ${formCoords.x}px; + grid-template-areas: + "input input input input submit cancel" + "${greeksFirstLine.join(' ')}" + "${greeksLastLine.join(' ')} . ${primeNames.join(' ')}"; + } + `, + 'react-ocl-atom-label-edit-dynamic', + ); + return (