From f3b3d09567d973ffccb4f5fdb7902f20f3816bd5 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Sat, 18 Nov 2023 22:52:31 +0000 Subject: [PATCH] create fastui-bootstrap --- Makefile | 2 +- package-lock.json | 15 +++++++-- package.json | 2 +- packages/fastui-bootstrap/package.json | 18 ++++++++++ packages/fastui-bootstrap/src/index.tsx | 27 +++++++++++++++ .../src/main.scss | 0 packages/fastui-bootstrap/tsconfig.json | 10 ++++++ packages/fastui/package.json | 1 - packages/vanilla/package.json | 2 -- packages/vanilla/src/App.tsx | 31 ++--------------- packages/vanilla/src/main.tsx | 2 +- packages/vanilla/tsconfig.json | 3 +- packages/vanilla/vite.config.ts | 1 + python/demo/__init__.py | 0 .../vanilla/server.py => python/demo/main.py | 33 ++++++++++--------- 15 files changed, 94 insertions(+), 53 deletions(-) create mode 100644 packages/fastui-bootstrap/package.json create mode 100644 packages/fastui-bootstrap/src/index.tsx rename packages/{vanilla => fastui-bootstrap}/src/main.scss (100%) create mode 100644 packages/fastui-bootstrap/tsconfig.json create mode 100644 python/demo/__init__.py rename packages/vanilla/server.py => python/demo/main.py (82%) diff --git a/Makefile b/Makefile index c51da711..305db535 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ testcov: test .PHONY: dev dev: - uvicorn demo.server:app --reload + uvicorn python.demo.main:app --reload .PHONY: all all: testcov lint diff --git a/package-lock.json b/package-lock.json index c2b298fe..4db32857 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2323,6 +2323,10 @@ "resolved": "packages/fastui", "link": true }, + "node_modules/fastui-bootstrap": { + "resolved": "packages/fastui-bootstrap", + "link": true + }, "node_modules/file-entry-cache": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", @@ -4469,11 +4473,18 @@ "react-dom": "^18.2.0" } }, + "packages/fastui-bootstrap": { + "version": "0.0.0", + "dependencies": { + "bootstrap": "^5.3.2", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "sass": "^1.69.5" + } + }, "packages/vanilla": { "dependencies": { "@vitejs/plugin-react-swc": "^3.3.2", - "bootstrap": "^5.3.2", - "sass": "^1.69.5", "vite": "^4.4.5" } }, diff --git a/package.json b/package.json index bc6d392b..c77bf985 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ ], "scripts": { "dev": "npm run --workspace=vanilla dev", - "build": "rm -rf packages-dist && npm run --workspaces build", + "build": "rm -rf packages-dist && npm run build --workspaces --if-present", "typecheck": "npm run --workspaces typecheck", "lint": "eslint packages --ext .ts,.tsx --report-unused-disable-directives --max-warnings 0", "lint-fix": "npm run lint -- --fix", diff --git a/packages/fastui-bootstrap/package.json b/packages/fastui-bootstrap/package.json new file mode 100644 index 00000000..e94afbeb --- /dev/null +++ b/packages/fastui-bootstrap/package.json @@ -0,0 +1,18 @@ +{ + "name": "fastui-bootstrap", + "version": "0.0.0", + "scripts": { + "build": "tsc", + "typecheck": "tsc --noEmit", + "typewatch": "tsc --noEmit --watch" + }, + "dependencies": { + "bootstrap": "^5.3.2", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "sass": "^1.69.5" + }, + "peerDependencies": { + "fastui": "0.0.0" + } +} diff --git a/packages/fastui-bootstrap/src/index.tsx b/packages/fastui-bootstrap/src/index.tsx new file mode 100644 index 00000000..6f13c97d --- /dev/null +++ b/packages/fastui-bootstrap/src/index.tsx @@ -0,0 +1,27 @@ +import { ClassNameGenerator, CustomRender } from 'fastui' + +export const customRender: CustomRender = (props) => { + const { type } = props + if (type === 'DisplayPrimitive') { + const { value } = props + if (typeof value === 'boolean') { + return () => <>{value ? '👍' : '👎'} + } + } +} + +export const classNameGenerator: ClassNameGenerator = (props) => { + const { type } = props + switch (type) { + case 'Page': + return 'container py-4' + case 'Row': + return 'row' + case 'Col': + return 'col' + case 'Button': + return 'btn btn-primary' + case 'Table': + return 'table table-striped' + } +} diff --git a/packages/vanilla/src/main.scss b/packages/fastui-bootstrap/src/main.scss similarity index 100% rename from packages/vanilla/src/main.scss rename to packages/fastui-bootstrap/src/main.scss diff --git a/packages/fastui-bootstrap/tsconfig.json b/packages/fastui-bootstrap/tsconfig.json new file mode 100644 index 00000000..54855eec --- /dev/null +++ b/packages/fastui-bootstrap/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "../../packages-dist", + "paths": { + "fastui": ["../fastui/src"] + } + }, + "include": ["src"] +} diff --git a/packages/fastui/package.json b/packages/fastui/package.json index b15a529d..b6b81059 100644 --- a/packages/fastui/package.json +++ b/packages/fastui/package.json @@ -2,7 +2,6 @@ "name": "fastui", "version": "0.0.0", "scripts": { - "build": "tsc", "typecheck": "tsc --noEmit", "typewatch": "tsc --noEmit --watch" }, diff --git a/packages/vanilla/package.json b/packages/vanilla/package.json index 3affcc20..c632aad1 100644 --- a/packages/vanilla/package.json +++ b/packages/vanilla/package.json @@ -8,8 +8,6 @@ }, "dependencies": { "@vitejs/plugin-react-swc": "^3.3.2", - "bootstrap": "^5.3.2", - "sass": "^1.69.5", "vite": "^4.4.5" } } diff --git a/packages/vanilla/src/App.tsx b/packages/vanilla/src/App.tsx index fc1d584a..0544fdb7 100644 --- a/packages/vanilla/src/App.tsx +++ b/packages/vanilla/src/App.tsx @@ -1,35 +1,10 @@ -import { FastUI, ClassNameGenerator, CustomRender } from 'fastui' +import { FastUI } from 'fastui' +import * as bootstrap from 'fastui-bootstrap' export default function App() { return (
- +
) } - -const customRender: CustomRender = (props) => { - const { type } = props - if (type === 'DisplayPrimitive') { - const { value } = props - if (typeof value === 'boolean') { - return () => <>{value ? '👍' : '👎'} - } - } -} - -const bootstrapClassName: ClassNameGenerator = (props) => { - const { type } = props - switch (type) { - case 'Page': - return 'container py-4' - case 'Row': - return 'row' - case 'Col': - return 'col' - case 'Button': - return 'btn btn-primary' - case 'Table': - return 'table table-striped' - } -} diff --git a/packages/vanilla/src/main.tsx b/packages/vanilla/src/main.tsx index 0a75e0ae..8b76e990 100644 --- a/packages/vanilla/src/main.tsx +++ b/packages/vanilla/src/main.tsx @@ -2,7 +2,7 @@ import React from 'react' import ReactDOM from 'react-dom/client' import App from './App' -import './main.scss' +import 'fastui-bootstrap/main.scss' ReactDOM.createRoot(document.getElementById('root')!).render( diff --git a/packages/vanilla/tsconfig.json b/packages/vanilla/tsconfig.json index 5ca9e112..602f00d9 100644 --- a/packages/vanilla/tsconfig.json +++ b/packages/vanilla/tsconfig.json @@ -2,7 +2,8 @@ "extends": "../../tsconfig.json", "compilerOptions": { "paths": { - "fastui": ["../fastui/src"] + "fastui": ["../fastui/src"], + "fastui-bootstrap": ["../fastui-bootstrap/src"] } }, "include": ["src"], diff --git a/packages/vanilla/vite.config.ts b/packages/vanilla/vite.config.ts index bbcf1be5..0ebb08a0 100644 --- a/packages/vanilla/vite.config.ts +++ b/packages/vanilla/vite.config.ts @@ -19,6 +19,7 @@ export default () => { alias: { '@': path.resolve(__dirname, './src'), fastui: path.resolve(__dirname, '../fastui/src'), + 'fastui-bootstrap': path.resolve(__dirname, '../fastui-bootstrap/src'), }, }, server: serverConfig, diff --git a/python/demo/__init__.py b/python/demo/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/packages/vanilla/server.py b/python/demo/main.py similarity index 82% rename from packages/vanilla/server.py rename to python/demo/main.py index d8f86243..8cff32ab 100644 --- a/packages/vanilla/server.py +++ b/python/demo/main.py @@ -4,14 +4,13 @@ from enum import StrEnum from typing import Annotated, Literal -from fastapi import FastAPI, UploadFile -from pydantic import BaseModel, Field - +from fastapi import UploadFile +from fastui import AnyComponent, FastUI, dev_fastapi_app from fastui import components as c -from fastui import FastUI, AnyComponent, dev_fastapi_app -from fastui.forms import fastui_form, FormResponse, FormFile from fastui.display import Display -from fastui.events import PageEvent, GoToEvent +from fastui.events import GoToEvent, PageEvent +from fastui.forms import FormFile, FormResponse, fastui_form +from pydantic import BaseModel, Field # app = FastAPI() app = dev_fastapi_app() @@ -22,12 +21,14 @@ def read_root() -> AnyComponent: return c.Page( children=[ c.Heading(text='Hello World'), - c.Row(children=[ - c.Col(children=[c.Text(text='Hello World')]), - c.Col(children=[c.Button(text='Show Modal', on_click=PageEvent(name='modal'))]), - c.Col(children=[c.Button(text='View Table', on_click=GoToEvent(url='/table'))]), - c.Col(children=[c.Button(text='Form', on_click=GoToEvent(url='/form'))]), - ]), + c.Row( + children=[ + c.Col(children=[c.Text(text='Hello World')]), + c.Col(children=[c.Button(text='Show Modal', on_click=PageEvent(name='modal'))]), + c.Col(children=[c.Button(text='View Table', on_click=GoToEvent(url='/table'))]), + c.Col(children=[c.Button(text='Form', on_click=GoToEvent(url='/form'))]), + ] + ), c.Modal( title='Modal Title', body=[c.Text(text='Modal Content')], @@ -35,7 +36,7 @@ def read_root() -> AnyComponent: open_trigger=PageEvent(name='modal'), ), ], - class_name='+ mt-4' + class_name='+ mt-4', ) @@ -61,8 +62,8 @@ def table_view() -> AnyComponent: c.TableColumn(field='name', on_click=GoToEvent(url='/more/{id}/')), c.TableColumn(field='dob', display=Display.date), c.TableColumn(field='enabled'), - ] - ) + ], + ), ] ) @@ -107,7 +108,7 @@ def form_view() -> AnyComponent: # c.Button(text='Cancel', on_click=GoToEvent(url='/')), # c.Button(text='Submit', html_type='submit'), # ] - ) + ), ] ) debug(f)