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 (
- + > + ✔️ + - + {Object.entries(greekLetters).map(([charName, greekChar]) => ( - + ))} {Object.entries(primes).map(([primeName, primeChar]) => ( - + ))} -
+ ); } From 4dc18a29ae940b63b3d2568d51a253d32376289c Mon Sep 17 00:00:00 2001 From: tpoisseau <22891227+tpoisseau@users.noreply.github.com> Date: Fri, 19 Dec 2025 12:31:35 +0100 Subject: [PATCH 09/10] refactor: remove styling helpers --- src/styling/css.ts | 12 ------------ src/styling/inline_stylesheet.tsx | 23 ----------------------- stories/reset/ocl_reset.tsx | 8 +++++--- stories/reset/ocl_reset_css.ts | 15 +++++++++++++-- 4 files changed, 18 insertions(+), 40 deletions(-) delete mode 100644 src/styling/css.ts delete mode 100644 src/styling/inline_stylesheet.tsx diff --git a/src/styling/css.ts b/src/styling/css.ts deleted file mode 100644 index 724b720..0000000 --- a/src/styling/css.ts +++ /dev/null @@ -1,12 +0,0 @@ -// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw#building_an_identity_tag -// eslint-disable-next-line @typescript-eslint/no-explicit-any -export const css = (strings: TemplateStringsArray, ...values: any[]) => - String.raw({ raw: strings }, ...values); - -/** - * To get CSS autocomplete in css tagged template literal: - * - * WebStorm: - * Settings | Editor | Language Injections - * Click on the little import button and select `CSS_template_literal.xml` file. - */ diff --git a/src/styling/inline_stylesheet.tsx b/src/styling/inline_stylesheet.tsx deleted file mode 100644 index 8c9a6b0..0000000 --- a/src/styling/inline_stylesheet.tsx +++ /dev/null @@ -1,23 +0,0 @@ -export interface InlineStylesheetProps { - /** - * Bound to `href` props of the ` - ); -} diff --git a/stories/reset/ocl_reset.tsx b/stories/reset/ocl_reset.tsx index 25f3e68..467b4c8 100644 --- a/stories/reset/ocl_reset.tsx +++ b/stories/reset/ocl_reset.tsx @@ -1,8 +1,10 @@ -import { InlineStylesheet } from '../../src/styling/inline_stylesheet.tsx'; - import { resetCss } from './ocl_reset_css.ts'; // eslint-disable-next-line jsdoc/require-jsdoc export function OclReset() { - return {resetCss}; + return ( + + ); } diff --git a/stories/reset/ocl_reset_css.ts b/stories/reset/ocl_reset_css.ts index 55da1a8..fb1135c 100644 --- a/stories/reset/ocl_reset_css.ts +++ b/stories/reset/ocl_reset_css.ts @@ -1,8 +1,19 @@ -import { css } from '../../src/styling/css.ts'; +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw#building_an_identity_tag +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export const css = (strings: TemplateStringsArray, ...values: any[]) => + String.raw({ raw: strings }, ...values); + +/** + * To get "CSS autocomplete" in CSS tagged template literal: + * + * WebStorm: + * Settings | Editor | Language Injections + * Click on the little import button and select `CSS_template_literal.xml` file. + */ /** * Took from https://github.com/zakodium-oss/react-science/blob/02df0e0b21142bcd99f4a664552e3e757fc35f8c/styles/preflight.css - * Only for test in storybook some component styling without and with css reset stylesheet. + * Only for test in storybook some component styling without and with CSS reset stylesheet. */ export const resetCss = css` /* From ab54cffd2c11de6bbf68adad7635a5a3bb92c3a4 Mon Sep 17 00:00:00 2001 From: tpoisseau <22891227+tpoisseau@users.noreply.github.com> Date: Fri, 19 Dec 2025 13:40:10 +0100 Subject: [PATCH 10/10] chore: remove is-prop-valid because it's not needed * move dependencies above devDependencies Refs: https://github.com/zakodium-oss/react-ocl/pull/75#discussion_r2634857376 Refs: https://github.com/zakodium-oss/react-ocl/pull/75#discussion_r2634861827 --- package-lock.json | 1 - package.json | 7 +++---- src/components/svg/svg_editor.styled.ts | 5 +---- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index a2de3e8..ca4cefe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "8.4.0", "license": "MIT", "dependencies": { - "@emotion/is-prop-valid": "^1.4.0", "@emotion/styled": "^11.14.1" }, "devDependencies": { diff --git a/package.json b/package.json index b46fac2..474ca9b 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,9 @@ "react": ">=18", "react-dom": ">=18" }, + "dependencies": { + "@emotion/styled": "^11.14.1" + }, "devDependencies": { "@storybook/addon-vitest": "^9.1.16", "@storybook/react-vite": "^9.1.16", @@ -72,9 +75,5 @@ "homepage": "https://github.com/zakodium-oss/react-ocl#readme", "volta": { "node": "24.11.0" - }, - "dependencies": { - "@emotion/is-prop-valid": "^1.4.0", - "@emotion/styled": "^11.14.1" } } diff --git a/src/components/svg/svg_editor.styled.ts b/src/components/svg/svg_editor.styled.ts index f2b77c7..765d570 100644 --- a/src/components/svg/svg_editor.styled.ts +++ b/src/components/svg/svg_editor.styled.ts @@ -1,4 +1,3 @@ -import isPropValid from '@emotion/is-prop-valid'; import styled from '@emotion/styled'; export const greekLetters = { @@ -58,9 +57,7 @@ export const AtomLabelEditInputStyled = styled.input` } `; -export const AtomLabelEditButtonStyled = styled('button', { - shouldForwardProp: (prop) => isPropValid(prop) && prop !== 'area', -})<{ area: string }>` +export const AtomLabelEditButtonStyled = styled.button<{ area: string }>` grid-area: ${(props) => props.area}; padding: 0.25em;