cohost/html/common.tsx

58 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-07-12 14:15:53 -04:00
import { Attributes, ComponentChildren, VNode, toChildArray } from "preact";
import { render } from "preact-render-to-string";
import { writeText } from "copy-paste";
2023-07-10 14:52:20 -04:00
2023-07-12 14:15:53 -04:00
export function Main({
children,
...attributes
}: {
children: ComponentChildren;
attributes?: Attributes;
}) {
return (
<div {...attributes} id="main">
{...toChildArray(children)}
</div>
);
}
2023-07-12 07:05:48 -04:00
2023-07-12 14:15:53 -04:00
export const HCenter = ({
children,
...attrs
}: {
children: ComponentChildren;
attrs?: Attributes;
}) => (
2023-07-12 07:05:48 -04:00
<div
2023-07-12 14:15:53 -04:00
{...attrs}
2023-07-12 07:05:48 -04:00
class="hcenter"
style="display: flex; justify-content: center;"
>
2023-07-12 14:15:53 -04:00
{...toChildArray(children)}
2023-07-12 07:05:48 -04:00
</div>
);
2023-07-12 14:15:53 -04:00
export const eggbug_emotions = {
2023-07-12 12:55:08 -04:00
smiling: (
<img
class="eggbug"
src="https://staging.cohostcdn.org/attachment/f33b4285-0455-4128-96b8-117054af40c3/eggbugSquare.png"
alt="eggbug, smiling"
/>
),
2023-07-12 14:15:53 -04:00
} as const;
export const EggbugImg = ({ type }: { type: keyof typeof eggbug_emotions }) =>
eggbug_emotions[type];
2023-07-12 12:55:08 -04:00
2023-07-12 14:15:53 -04:00
export const render_and_copy = (elem: VNode) => {
const rendered = render(elem);
writeText(rendered);
console.log(rendered);
};
2023-07-15 22:53:32 -04:00
export const mk_class_wrapper =
(klass: string) =>
({ children }: { children: ComponentChildren }) =>
<div class="klass">{...toChildArray(children)}</div>;