From 37ebd3d4786b6daea76bc0cae758a3437c6a1088 Mon Sep 17 00:00:00 2001 From: Venessa Kuchenik Date: Tue, 22 Jul 2025 11:58:10 -0700 Subject: [PATCH] widgets are bound to container figured out how to set bounds so widgets don't go off screen! --- client/src/App.jsx | 2 +- .../src/components/layout/Canvas/Widget.jsx | 33 +++++++++++-------- .../layout/Canvas/views/WidgetCanvas.jsx | 18 ++++++---- client/src/theme.js | 21 ++++++++++++ 4 files changed, 52 insertions(+), 22 deletions(-) diff --git a/client/src/App.jsx b/client/src/App.jsx index b98cd78..29a907e 100644 --- a/client/src/App.jsx +++ b/client/src/App.jsx @@ -21,7 +21,7 @@ function App() { - + diff --git a/client/src/components/layout/Canvas/Widget.jsx b/client/src/components/layout/Canvas/Widget.jsx index 489c98c..e17e2fb 100644 --- a/client/src/components/layout/Canvas/Widget.jsx +++ b/client/src/components/layout/Canvas/Widget.jsx @@ -1,16 +1,21 @@ +import { useSlotRecipe, chakra } from "@chakra-ui/react" + export default function Widget({ title }) { - return ( - <> -
- {title} -
-
- This is the widget content - drag or resize me! -
- - ); - } + const recipe = useSlotRecipe({ key: "widget" }); + const styles = recipe(); + + return ( + + + {title} + + + This is the widget content - drag or resize me! + + + ); +} diff --git a/client/src/components/layout/Canvas/views/WidgetCanvas.jsx b/client/src/components/layout/Canvas/views/WidgetCanvas.jsx index 2395ae8..a6611b3 100644 --- a/client/src/components/layout/Canvas/views/WidgetCanvas.jsx +++ b/client/src/components/layout/Canvas/views/WidgetCanvas.jsx @@ -3,13 +3,17 @@ // Content not included, must be populated using custom charts plots and notifications import { useState } from 'react'; -import GridLayout from 'react-grid-layout'; +import GridLayout, { WidthProvider } from 'react-grid-layout'; import Widget from '../Widget.jsx'; -import { Box } from '@chakra-ui/react'; +import { useSlotRecipe, chakra } from '@chakra-ui/react'; export default function WidgetCanvas() { // Define widgets initial position and size // TODO Add dynamic adding/deleting of widgets via options button + const recipe = useSlotRecipe({ key: "widget" }); + const styles = recipe(); + const ResponsiveGridLayout = WidthProvider(GridLayout); + const [layout, setLayout] = useState([ { i: 'myWidget1', x: 0, y: 0, w: 3, h: 3, minH: 3, static: false }, { i: 'myWidget2', x: 3, y: 0, w: 3, h: 3, minH: 3, static: false }, @@ -22,21 +26,21 @@ export default function WidgetCanvas() { }; return ( - {layout.map((item) => ( -
+ -
+ ))} -
+ ); } diff --git a/client/src/theme.js b/client/src/theme.js index f4954bd..d214c25 100644 --- a/client/src/theme.js +++ b/client/src/theme.js @@ -49,6 +49,26 @@ const sidebarRecipe = defineSlotRecipe({ } }); +const widgetRecipe = defineSlotRecipe({ + slots: ["root", "header", "canvas"], + base: { + root: { + bg: "base100", + borderRadius: "md", + p: "1" + }, + header: { + bg: "base100", + cursor: "move", + borderRadius: "md" + }, + canvas: { + bg: "base100", + cursor: "default" + } + } +}); + const config = defineConfig({ theme: { semanticTokens: { @@ -82,6 +102,7 @@ const config = defineConfig({ }, slotRecipes: { sidebar: sidebarRecipe, + widget: widgetRecipe, } }, });