Skip to content

Commit

Permalink
added more comments and modified html and css files
Browse files Browse the repository at this point in the history
  • Loading branch information
xkeshav committed May 31, 2024
1 parent efde569 commit cd95d1b
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 221 deletions.
16 changes: 16 additions & 0 deletions .github/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": true,
"printWidth": 120,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"trailingComma": "all",
"useTabs": false
}
16 changes: 16 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": true,
"printWidth": 120,
"proseWrap": "always",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": false,
"trailingComma": "all",
"useTabs": false
}
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Here are few examples with honojs
- use of `c.header()` and `c.body()`
- endpoint: `/welcome`

### Multiple paths
### Multiple paths

- multiple path return same page; no redirect logic
- endpoint: `/hello` or `/hey` or `/hi`
Expand All @@ -35,7 +35,7 @@ Here are few examples with honojs
- use of `c.json()`
- endpoint: `/json/list`

### HTML response
### HTML response

- use of `c.html()`
- endpoint: `/html/list`
Expand All @@ -48,8 +48,8 @@ Here are few examples with honojs

### Path Params and Query Params

- add any valid color in place of *white* as a path params
- endpoint: `/color/white`
- add any valid color in place of _white_ as a path params
- endpoint: `/color/white`

---

Expand All @@ -61,7 +61,6 @@ Here are few examples with honojs
- use of reusable component like react
- endpoint: `/alphabet`


## Author

Keshav Mohta | [@xkeshav](https://www.xkeshav.com)
Keshav Mohta | [@xkeshav](https://www.xkeshav.com)
6 changes: 5 additions & 1 deletion hono.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
"titleBar.inactiveBackground": "#78459699",
"titleBar.inactiveForeground": "#e7e7e799"
},
"peacock.color": "#784596"
"peacock.color": "#784596",
"files.exclude": {
".github/**": true,
".vscode/**": true
}
}
}
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"private": false,
"publisher": "@xkeshav",
"description": " example for honojs learning; used in talks",
"description": "basic learning pad for hono.js; used this example in a talk",
"scripts": {
"dev": "tsx watch src/index.tsx"
},
Expand All @@ -16,16 +16,21 @@
"@types/node": "^20.11.17",
"tsx": "^3.12.2"
},
"keywords": ["honojs", "hono", "server", "typescript"],
"keywords": [
"honojs",
"hono",
"server",
"typescript"
],
"author": {
"name": "Keshav Mohta",
"email" : "xkeshav@gmail.com"
"email": "xkeshav@gmail.com"
},
"contributors": [],
"license": "see LICENSE in LICENSE",
"repository": {
"type": "git",
"url": "https://github.com/xkeshav/to_ho_no.git"
"url": "https://github.com/xkeshav/o_ho_no.git"
},
"bugs": {
"url": "https://github.com/xkeshav/o_ho_no/issues",
Expand Down
44 changes: 26 additions & 18 deletions src/Alphabet.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,42 @@
import { css } from 'hono/css';
import { FC } from 'hono/jsx';
import { Layout } from './Layout';
import { alphabet } from "@xkeshav/alphabet";
import { css } from "hono/css";
import { FC } from "hono/jsx";

import { alphabet } from '@xkeshav/alphabet';
import { Layout } from "./Layout";

const parentContainer = css`
display:grid;
display: grid;
grid-gap: 4px;
grid-template-columns: repeat(5,1fr);
`
grid-template-columns: repeat(5, 1fr);
`;
const itemClass = css`
display: grid;
height: 10rem;
color: var(--text, white);
background-color: hwb(var(--hue) 0% 0%);
place-content: center;
font-size: 4rem;
border:2px solid grey;
border: 2px solid grey;
box-shadow: rgb(38, 57, 77) 0px 20px 30px -10px;
}
`
`;

const Letter:FC = ({what, idx}) => (<div class={itemClass} style={{ "--hue": idx*10 + 20, "--text": idx < 20 ? '#000': '#af0'}}>{what}</div>)
const Letter: FC = ({ what, idx }) => (
<div
class={itemClass}
style={{ "--hue": idx * 10 + 20, "--text": idx < 20 ? "#000" : "#af0" }}
>
{what}
</div>
);

// MARK: JSX Support
export const Alphabet: FC = () => (
<Layout>
<h1>Alphabets</h1>
<div class={parentContainer}>
{alphabet.map(((item,idx) => <Letter idx={idx} what={item} />))}
</div>
</Layout>
<Layout>
<h1>Alphabets</h1>
<div class={parentContainer}>
{alphabet.map((item, idx) => (
<Letter idx={idx} what={item} />
))}
</div>
</Layout>
);

104 changes: 104 additions & 0 deletions src/Color.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { Hono } from "hono";
import { css, cx, Style } from "hono/css";

// MARK: HTML and CSS support syntax
const colorRoute = new Hono();

const headerClass = css`
background-color: hsl(250 100% 50%);
color: white;
padding: 1rem;
`;


const ColorHome = () => <><Style/><p class={headerClass}>type path /rainbow</p></>;

colorRoute.get("/", (c) => c.html(<ColorHome/>));

colorRoute.get("/rainbow", (c) => {
// css as object
const listClass = css`
background-color: #5d7065e0;
list-style-type: none;
display: grid;
grid-auto-flow: row;
gap: 0.5rem;
padding: 0.5rem;
& li {
font-size: 2rem;
margin: 0.5rem;
border-bottom: 1px solid white;
padding-inline: 0.5rem;
letter-spacing: 0.25ch;
}
`;

const borderClass = css`
border: 4px solid black;
border-radius: 0.5rem;
`;
// MARK: use of React Fragment
return c.html(
<html>
<Style /> {/*this is must to insert*/}
<div>
{/* using cx to join classes */}
<h1 class={cx(headerClass, borderClass)}>Rainbow Colors</h1>
<ul class={listClass}>
<li style={{ color: "violet" }}>Violet</li>
<li style={{ color: "indigo" }}>Indigo</li>
<li style={{ color: "blue" }}>Blue</li>
<li style={{ color: "green" }}>Green</li>
<li style={{ color: "yellow" }}>Yellow</li>
<li style={{ color: "orange" }}>Orange</li>
<li style={{ color: "red" }}>Red</li>
</ul>
</div>
</html>
);
});

// path params read
colorRoute.get("/:what", (c) => {
const { what } = c.req.param(); // const what = c.req.param('what');
const { sz } = c.req.query();
// console.log({ what, sz });
// MARK: CSS within <Style>
return c.html(
<html>
<head>
<Style>
{css`
main {
background: linear-gradient(45deg, ${what} 24%, pink 10%);
color: black;
text-align: center;
font-size: ${sz ?? 2}rem;
mix-blend-mode: difference;
padding: 1rem;
margin: 2rem;
height: 30vh;
border: 2px dashed grey;
display: grid;
place-content: center;
box-shadow: rgba(0, 0, 0, 0.24) 0px 3px 8px;
& span {
border: 2px dashed pink;
padding: 0.5rem 1rem;
}
}
`}
</Style>
</head>
<body>
<main>
<p>
Path param value is:<span>{what}</span>
</p>
</main>
</body>
</html>
);
});

export default colorRoute;
64 changes: 37 additions & 27 deletions src/Element.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
import { css, Style } from 'hono/css';
import { FC } from 'hono/jsx';
type Item = {name: string; emoji: string; id: number;};
type ElementProps = { list : Item[]};
import { css, Style } from "hono/css";
import { FC } from "hono/jsx";

const main = css`
display:grid;
// MARK: Types
type Item = { name: string; emoji: string; id: number };
type ElementProps = { list: Item[] };

// extend classes
const common = css`
color: var(--text, white);
background-color: hwb(var(--hue, 40) 10% 60%);
font-size: 4rem;
`;
const main__container = css`
display: grid;
grid-gap: 4px;
grid-template-columns: repeat(2,1fr);
`
const element = css`
grid-template-columns: repeat(2, 1fr);
`;
const element__item = css`
${common}
display: grid;
height: 10rem;
color: var(--text, white);
background-color: hwb(var(--hue, 40) 10% 60%);
place-content: center;
font-size: 4rem;
}
`
export const Element: FC<ElementProps> = ({list}) => {
return (
<html>
<body>
<Style/>
<h1>Element List : HTML supported</h1>
<main class={main}>
{list.map((item) => <div class={element}>{item.name} : {item.emoji} </div>)}
</main>
</body>
</html>
);
}
`;

const Element: FC<ElementProps> = ({ list }) => (
<html>
<body>
<Style />
<h1>Five Elements</h1>
<main class={main__container}>
{list.map((item) => (
<div class={element__item}>
{item.name} : {item.emoji}{" "}
</div>
))}
</main>
</body>
</html>
);

export { Element, ElementProps };
11 changes: 7 additions & 4 deletions src/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Style, css } from 'hono/css';
import { FC } from 'hono/jsx';

export const Layout: FC = (props) => {
return (
const Layout: FC = (props) => (
<html>
<head>
<Style>{
css`
html {
font-family: Arial, Helvetica, sans-serif;
background-color: greenyellow;
font-size: 16px;
}
:root {
--hue: 10;
Expand All @@ -18,5 +19,7 @@ export const Layout: FC = (props) => {
</head>
<body>{props.children}</body>
</html>
)
};
);

export { Layout };

Loading

0 comments on commit cd95d1b

Please sign in to comment.