Skip to content

Commit 7e9264c

Browse files
committed
add popover component, v0.3.0
1 parent 386904a commit 7e9264c

File tree

9 files changed

+124
-27
lines changed

9 files changed

+124
-27
lines changed

app/app.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const links: LinksFunction = () => {
5858
},
5959
...require("~/dataTable.styles").links(),
6060
...require("~/gooeyFileInput.styles").links(),
61+
...require("~/components/GooeyPopover.styles").links(),
6162
{ rel: "stylesheet", href: customStyles },
6263
{ rel: "stylesheet", href: appStyles },
6364
];
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { LinksFunction } from "@remix-run/node";
2+
import tippyAnimStyles from "tippy.js/animations/scale.css";
3+
4+
export const links: LinksFunction = () => {
5+
return [{ rel: "stylesheet", href: tippyAnimStyles }];
6+
};

app/components/GooeyPopover.tsx

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import Tippy from "@tippyjs/react";
2+
import { useState } from "react";
3+
import { OnChange } from "~/app";
4+
import { RenderedChildren, TreeNode } from "~/renderer";
5+
6+
export default function GooeyPopover({
7+
content,
8+
children,
9+
onChange,
10+
state,
11+
...props
12+
}: {
13+
content: Array<TreeNode>;
14+
children: Array<TreeNode>;
15+
onChange: OnChange;
16+
state: Record<string, any>;
17+
}) {
18+
const [visible, setVisible] = useState(false);
19+
20+
return (
21+
<Tippy
22+
visible={visible}
23+
onClickOutside={() => setVisible(false)}
24+
content={
25+
<div onClick={() => setVisible(false)}>
26+
<RenderedChildren
27+
children={content}
28+
onChange={onChange}
29+
state={state}
30+
/>
31+
</div>
32+
}
33+
animation="scale"
34+
{...props}
35+
>
36+
<button
37+
type="button"
38+
className="border-0 bg-transparent"
39+
onClick={() => setVisible(!visible)}
40+
>
41+
<RenderedChildren
42+
children={children}
43+
onChange={onChange}
44+
state={state}
45+
/>
46+
</button>
47+
</Tippy>
48+
);
49+
}

app/renderer.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import { OnChange } from "./app";
1818
import CountdownTimer from "./components/countdown";
1919
import GooeySelect from "./components/GooeySelect";
2020
import { lazyImport } from "./lazyImports";
21+
import Tippy from "@tippyjs/react";
22+
import GooeyPopover from "./components/GooeyPopover";
2123

2224
const { DataTable, DataTableRaw } = lazyImport(() => import("~/dataTable"));
2325

@@ -42,7 +44,7 @@ const Plot = lazyImport(
4244

4345
const CodeEditor = lazyImport(() => import("./components/CodeEditor")).default;
4446

45-
type TreeNode = {
47+
export type TreeNode = {
4648
name: string;
4749
props: Record<string, any>;
4850
children: Array<TreeNode>;
@@ -355,27 +357,16 @@ function RenderedTreeNode({
355357
}
356358
}
357359
case "gui-button": {
358-
const { label, className, ...args } = props;
360+
const { label, ...args } = props;
359361
return (
360-
<button
361-
type="button"
362-
className={`btn btn-theme ${className ?? ""}`}
363-
{...args}
364-
>
362+
<button type="button" {...args}>
365363
<RenderedMarkdown body={label} />
366364
</button>
367365
);
368366
}
369367
case "download-button": {
370-
const { label, className, url, ...args } = props;
371-
return (
372-
<DownloadButton
373-
label={label}
374-
className={className}
375-
url={url}
376-
{...args}
377-
/>
378-
);
368+
const { label, url, ...args } = props;
369+
return <DownloadButton label={label} url={url} {...args} />;
379370
}
380371
case "select":
381372
return <GooeySelect props={props} onChange={onChange} state={state} />;
@@ -439,6 +430,18 @@ function RenderedTreeNode({
439430
const { chart, ...args } = props;
440431
return <Plot {...chart} style={{ width: "100%" }} />;
441432
}
433+
case "popover": {
434+
const { content, ...args } = props;
435+
return (
436+
<GooeyPopover
437+
content={content}
438+
children={children}
439+
onChange={onChange}
440+
state={state}
441+
{...args}
442+
/>
443+
);
444+
}
442445
default:
443446
return (
444447
<div>

app/styles/app.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,3 +292,7 @@ div[id^="react-select-"][id$="-listbox"] {
292292
.gui-input-number input {
293293
padding: 0.5rem;
294294
}
295+
296+
.bg-hover-light:hover {
297+
background-color: var(--bs-gray-200) !important;
298+
}

package-lock.json

Lines changed: 28 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gooey-gui",
3-
"version": "0.2.1",
3+
"version": "0.3.0",
44
"sideEffects": false,
55
"scripts": {
66
"build": "remix build",
@@ -29,6 +29,7 @@
2929
"@sentry/integrations": "^7.73.0",
3030
"@sentry/remix": "^7.73.0",
3131
"@textea/json-viewer": "^3.0.0",
32+
"@tippyjs/react": "^4.2.6",
3233
"@uiw/codemirror-theme-dracula": "^4.23.0",
3334
"@uiw/react-codemirror": "^4.23.0",
3435
"@uppy/audio": "^1.1.1",

py/gooey_gui/components/common.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ def markdown(
115115
)
116116

117117

118-
def _node(name: str, **props):
119-
node = core.RenderTreeNode(name=name, props=props)
118+
def _node(nodename: str, **props):
119+
node = core.RenderTreeNode(name=nodename, props=props)
120120
node.mount()
121121
return core.NestingCtx(node)
122122

@@ -556,7 +556,7 @@ def button(
556556
"""
557557
if not key:
558558
key = core.md5_values("button", label, help, type, props)
559-
className = f"btn-{type} " + props.pop("className", "")
559+
className = f"btn btn-theme btn-{type} " + props.pop("className", "")
560560
core.RenderTreeNode(
561561
name=component,
562562
props=dict(
@@ -1019,6 +1019,17 @@ def plotly_chart(figure_or_data, **kwargs):
10191019
).mount()
10201020

10211021

1022+
def popover(**props) -> tuple[core.NestingCtx, core.NestingCtx]:
1023+
content = core.RenderTreeNode(name="content")
1024+
1025+
popover = core.RenderTreeNode(
1026+
name="popover", props=props | dict(content=content.children)
1027+
)
1028+
popover.mount()
1029+
1030+
return core.NestingCtx(popover), core.NestingCtx(content)
1031+
1032+
10221033
def dedent(text: str | None) -> str | None:
10231034
if not text:
10241035
return text

py/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "gooey-gui"
3-
version = "0.2.1"
3+
version = "0.3.0"
44
description = ""
55
authors = ["Dev Aggarwal <devxpy@gmail.com>"]
66
license = "Apache-2.0"

0 commit comments

Comments
 (0)