Skip to content

Commit

Permalink
start to make tutorial (#50)
Browse files Browse the repository at this point in the history
* code sendbox 추가

* reactive

* layout

* monaco reactive layout

* 얼개 잡음

* 얼개

* gogo

* auto refresh not on app.js

* 중간 저장

* stack positioned

* good

* asdf
  • Loading branch information
Moon-DaeSeung authored May 25, 2024
1 parent 7faf6a2 commit 8d94492
Show file tree
Hide file tree
Showing 28 changed files with 1,401 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ package
/playwright-report/
/blob-report/
/playwright/.cache/
packages/*/dist/
packages/*/package/

2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"astro",
"astrojs",
"autodocs",
"codesandbox",
"egjs",
"flutterjs",
"lerp",
Expand All @@ -16,6 +17,7 @@
"publint",
"renderobject",
"rgba",
"sandpack",
"Shiki",
"tailwindcss",
"tsup",
Expand Down
476 changes: 469 additions & 7 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/docs/astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default defineConfig({
integrations: [react(), svelte(), tailwind(), mdx()],
redirects: {
"/docs": "/docs/introduction",
"/tutorial": "/tutorial/introduction",
},
markdown: {
shikiConfig: {
Expand Down
3 changes: 3 additions & 0 deletions packages/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
"@astrojs/react": "^3.0.10",
"@astrojs/svelte": "^5.2.0",
"@astrojs/tailwind": "^5.1.0",
"@codesandbox/sandpack-react": "^2.13.10",
"@egjs/react-flicking": "^4.11.2",
"@meursyphus/flitter-chart": "^0.0.3",
"@monaco-editor/react": "^4.6.0",
"@tailwindcss/typography": "^0.5.10",
"@types/react": "^18.2.64",
"@types/react-dom": "^18.2.21",
"astro": "^4.4.15",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-markdown": "^9.0.1",
"svelte": "^4.2.12",
"tailwindcss": "^3.4.1",
"typescript": "^5.4.2"
Expand Down
14 changes: 11 additions & 3 deletions packages/docs/src/components/ui/Header.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
---
const url = new URL(Astro.request.url);
const pathname = url.pathname; // 현재 페이지의 경로
let current: "docs" | "tutorial" | "none" = pathname.startsWith("/docs")
? "docs"
: pathname.startsWith("/tutorial")
? "tutorial"
: "none";
---

<header
Expand All @@ -15,13 +21,15 @@ const pathname = url.pathname; // 현재 페이지의 경로

<div class="justify-start items-start gap-8 flex">
<a
class={`${pathname.startsWith("/docs") ? "active" : ""} text-gray-600 text-base leading-normal`}
class={`${current === "docs" ? "active" : ""} text-gray-600 text-base leading-normal`}
href="/docs">docs</a
>
<div class="justify-center items-center gap-1 flex">
<div class="text-black text-base leading-normal">
<span class="opacity-50 select-none" title="comming soon"
>tutorial</span
<a
class={`${current === "tutorial" ? "active" : ""} select-none`}
title="comming soon"
href="/tutorial">tutorial</a
>
</div>
<div class="w-6 h-6 relative"></div>
Expand Down
13 changes: 11 additions & 2 deletions packages/docs/src/content/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineCollection, z } from "astro:content";

const docs = defineCollection({
type: "content",
type: "content",
schema: z.object({
nav_group: z.string(),
nav_group_order: z.number(),
Expand All @@ -11,9 +11,18 @@ const docs = defineCollection({
description: z.string().optional(),
tags: z.array(z.string()).optional(),
image: z.string().optional(),
})
}),
});

const tutorial = defineCollection({
type: "content",
schema: z.object({
files: z.record(z.string()),
title: z.string(),
}),
});

export const collections = {
docs: docs,
tutorial: tutorial,
};
60 changes: 60 additions & 0 deletions packages/docs/src/content/tutorial/000_introduction.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
category: How to start
title: "Introduction"
files:
App.js: |
import { useEffect, useRef } from "react";
import {
Alignment,
AppRunner,
Container,
Text,
} from "@meursyphus/flitter";
export default function App() {
let runner
const svgRef = useRef(null);
const widget = Container({
width: Infinity,
height: Infinity,
alignment: Alignment.center,
color: "red",
child: Text("Hello World")
});
useEffect(() => {
runner = new AppRunner({
view: svgRef.current
});
runner.onMount({
resizeTarget: svgRef.current
});
runner.runApp(widget);
return () => {
runner.dispose();
};
}, []);
return (
<svg style={{ width: "200px", height: "200px" }} ref={svgRef} />
);
}
---

# Introduction

```bash
npm install @meursyphus/flitter
```

This example demonstrates how to render widgets using the `AppRunner` class. `AppRunner` is initialized with an SVG element as the `view` property, which is referenced through React's `useRef`. The widget is created using the `Container` function, which includes a `Text` widget as a child.

Within the `useEffect` hook, an `AppRunner` instance is created, and a resize event is set up through the `onMount` method. Afterwards, the `runApp` method is called to render the widget. When the component unmounts, the `dispose` method is called to clean up resources.

Through this process, the widget defined within the SVG element is rendered, and the layout is automatically updated according to screen size adjustments. This is handled by the `AppRunner`'s `handleViewResize` method.

Using the `@meursyphus/flitter` library in this way allows for declarative and reactive data visualization without complex DOM manipulation.
37 changes: 37 additions & 0 deletions packages/docs/src/content/tutorial/001_react-helper.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
category: How to start
title: Flitter-React
files:
App.js: |
import {Text,Container,Alignment} from '@meursyphus/flitter'
import Widget from '@meursyphus/flitter-react'
export default function App() {
return (
<Widget
height="200px"
width="200px"
/*
The renderer can be set to either "svg" or "canvas".
The default is "svg".
*/
// renderer="canvas"
widget={
Container({
width: Infinity,
height: Infinity,
alignment: Alignment.center,
color: "red",
child: Text("Hello World")
})
}
/>
);
}
---

# Flitter-React

Flitter-React is a library that facilitates the easy use of Flitter widgets in a React environment.
Through this, developers can integrate Flitter's widgets into their React projects without complex configurations.
The example below demonstrates how to implement a simple widget as a React component using Flitter-React.
67 changes: 67 additions & 0 deletions packages/docs/src/content/tutorial/002_container-text.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
category: Basic
title: Container Text
files:
App.js: |
import {
Text,
Container,
Alignment,
EdgesInset,
Border,
BoxDecoration,
BorderRadius,
TextStyle
} from '@meursyphus/flitter'
import Widget from '@meursyphus/flitter-react'
export default function App() {
return (
<Widget
height="400px"
width="100%"
/*
The renderer can be set to either "svg" or "canvas".
The default is "svg".
*/
// renderer="canvas"
widget={
Container({
alignment: Alignment.center,
decoration: new BoxDecoration({
border: Border.all({color: "black", width: 3}),
borderRadius: BorderRadius.circular(10),
color: "yellow"
}),
child: Text("Hello World", {
style: new TextStyle({
color: "blue",
fontSize: 30
})
})
})
}
/>
);
}
---

# Container Text

The descriptions of each prop used in this example are as follows:

`Container` widget props:

- `alignment`: Sets the alignment of child elements within the container. `Alignment.center` positions the child elements at the center.
- `decoration`: Defines the style of the container. `BoxDecoration` is used to set the background color, border, and the style of the border's edges.
- `border`: `Border.all` is used to apply a border to all sides. The color is "black", and the width is 3px.
- `borderRadius`: `BorderRadius.circular(10)` is used to round the edges. The value in the parentheses represents the radius of the corners.
- `color`: Sets the background color. In this example, it is set to "yellow".

`Text` widget props:

- `style`: Defines the style of the text. `TextStyle` is used to set the text color and font size.
- `color`: Sets the color of the text. In this example, it is set to "blue".
- `fontSize`: Sets the size of the text. In this example, it is set to 30.

These settings allow users to freely adjust the appearance and layout of the widget.
107 changes: 107 additions & 0 deletions packages/docs/src/content/tutorial/003_column-row.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
category: Basic
title: Container Text
files:
App.js: |
import {
Column,
Row,
Container,
Text,
Alignment,
Flexible,
CrossAxisAlignment,
MainAxisAlignment,
SizedBox
} from '@meursyphus/flitter';
import Widget from '@meursyphus/flitter-react';
export default function App() {
return (
<Widget
height="400px"
width="100%"
widget={
Column({
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row({
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container({
width: 200,
height: 100,
color: 'red',
alignment: Alignment.center,
child: Text("Row 1, Column 1")
}),
Container({
width: 200,
height: 100,
color: 'blue',
alignment: Alignment.center,
child: Text("Row 1, Column 2")
})
]
}),
Row({
children: [
Flexible({
flex: 1,
child: Container({
height: 100,
alignment: Alignment.center,
color: 'green',
child: Text("Row 2, Column 1")
})
}),
SizedBox({
width: 100,
}),
Flexible({
flex: 2,
child: Container({
height: 100,
alignment: Alignment.center,
color: 'purple',
child: Text("Row 2, Column 1")
})
}),
]
})
]
})
}
/>
);
}
---

# Column Row

The descriptions of each prop used in this example are as follows:
`Row` and `Container` widget prop descriptions:

`Row` widget props:

- `children`: This array defines the child widgets that will be included within the `Row`. Each child can be a `Flexible` widget.
- `mainAxis`: Defines the main axis of the `Row` widget, along which the child widgets will be arranged. It is horizontal by default.
- `crossAxis`: Defines the cross axis of the `Row` widget, determining how the child widgets will be aligned along this axis. For example, `crossAxisAlignment: CrossAxisAlignment.center` positions the children at the center of the cross axis.

`Column` widget props:

- `children`: This array defines the child widgets that will be included within the `Column`. Each child can be a `Flexible` widget.
- `mainAxis`: Defines the main axis of the `Column` widget, along which the child widgets will be arranged. It is vertical by default.
- `crossAxis`: Defines the cross axis of the `Column` widget, determining how the child widgets will be aligned along this axis. For example, `crossAxisAlignment: CrossAxisAlignment.center` positions the children at the center of the cross axis.

`Flexible` widget props:

- `flex`: Defines the proportion of space this widget will occupy within the `Row`. For example, `flex: 1` indicates a size relative to other `flex` values.
- `child`: The child element to be included within the `Flexible`, typically a `Container`.

Layout description:

- The first `Row` contains two `Container` children, each with a background color of red and blue respectively, and dimensions of 200x100.
- The second `Row` uses `Flexible` widgets to provide a flexible layout. The first `Flexible` has a `flex: 1` value, and the second has a `flex: 2` value. This means the second container occupies twice the space of the first. Each contains a container with heights of 100 and backgrounds of green and purple respectively.

This configuration allows users to flexibly arrange containers of various sizes and colors, and easily adjust text alignment.
Loading

0 comments on commit 8d94492

Please sign in to comment.