Post Stats
Post Stats component
Install
npx ui8kit add post-statsPulls in: compose, group, kit-box, kit-text, lucide-icon, post-card, post-split, text, utils
Preview
6 min read
12.8K views
892 likes
Code
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework svelte --dir src --registry-url https://registry.buildy.tw/svelte --strict-cdnnpx ui8kit add post-stats<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!-- The reading figures of a post: minutes to read, views and likes, each with its glyph. -->
<script lang="ts" module>
import type { Snippet } from "svelte";
import type { Post } from "../blocks/post-card.types";
import type { PostExtras, PostSplitLabels } from "../blocks/post-split.types";
export type PostStatsProps = {
post: Post;
extras: PostExtras;
labels: PostSplitLabels;
align?: "start" | "center";
};
</script>
<script lang="ts">
import Group from "../compose/Group.svelte";
import LucideIcon from "../icons/LucideIcon.svelte";
import Text from "../compose/Text.svelte";
import { tpl } from "../utils";
let { post, extras, labels, align = "start" }: PostStatsProps = $props();
</script>
<Group gap="4" align="center" justify={align} class="flex-wrap text-muted-foreground" data-slot="post-stats">
<Group gap="2" align="center">
<LucideIcon name="clock" size={16} />
<Text size="sm">
{tpl(labels.minutes, post.minutes)}
</Text>
</Group>
<Group gap="2" align="center">
<LucideIcon name="eye" size={16} />
<Text size="sm">
{tpl(labels.views, extras.views)}
</Text>
</Group>
<Group gap="2" align="center">
<LucideIcon name="heart" size={16} />
<Text size="sm">
{tpl(labels.likes, extras.likes)}
</Text>
</Group>
</Group>
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework react --dir src --registry-url https://registry.buildy.tw/react --strict-cdnnpx ui8kit add post-stats// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/** The reading figures of a post: minutes to read, views and likes, each with its glyph. */
import { type ReactNode } from "react";
import { Group, Text } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { tpl } from "../utils";
import type { Post } from "../blocks/post-card.types";
import type { PostExtras, PostSplitLabels } from "../blocks/post-split.types";
export type PostStatsProps = {
post: Post;
extras: PostExtras;
labels: PostSplitLabels;
align?: "start" | "center";
};
export function PostStats({ post, extras, labels, align = "start" }: PostStatsProps) {
return (
<Group
gap="4"
align="center"
justify={align}
className="flex-wrap text-muted-foreground"
data-slot="post-stats"
>
<Group gap="2" align="center">
<LucideIcon name="clock" size={16} />
<Text size="sm">
{tpl(labels.minutes, post.minutes)}
</Text>
</Group>
<Group gap="2" align="center">
<LucideIcon name="eye" size={16} />
<Text size="sm">
{tpl(labels.views, extras.views)}
</Text>
</Group>
<Group gap="2" align="center">
<LucideIcon name="heart" size={16} />
<Text size="sm">
{tpl(labels.likes, extras.likes)}
</Text>
</Group>
</Group>
);
}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework vue --dir src --registry-url https://registry.buildy.tw/vue --strict-cdnnpx ui8kit add post-stats<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!-- The reading figures of a post: minutes to read, views and likes, each with its glyph. -->
<script lang="ts">
import type { Post } from "../blocks/post-card.types";
import type { PostExtras, PostSplitLabels } from "../blocks/post-split.types";
export type PostStatsProps = {
post: Post;
extras: PostExtras;
labels: PostSplitLabels;
align?: "start" | "center";
};
</script>
<script setup lang="ts">
import Group from "../compose/Group.vue";
import LucideIcon from "../icons/LucideIcon.vue";
import Text from "../compose/Text.vue";
import { tpl } from "../utils";
const { post, extras, labels, align = "start" } = defineProps<PostStatsProps>();
</script>
<template>
<Group gap="4" align="center" :justify="align" class="flex-wrap text-muted-foreground" data-slot="post-stats">
<Group gap="2" align="center">
<LucideIcon name="clock" :size="16" />
<Text size="sm">
{{ tpl(labels.minutes, post.minutes) }}
</Text>
</Group>
<Group gap="2" align="center">
<LucideIcon name="eye" :size="16" />
<Text size="sm">
{{ tpl(labels.views, extras.views) }}
</Text>
</Group>
<Group gap="2" align="center">
<LucideIcon name="heart" :size="16" />
<Text size="sm">
{{ tpl(labels.likes, extras.likes) }}
</Text>
</Group>
</Group>
</template>
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework solid --dir src --registry-url https://registry.buildy.tw/solid --strict-cdnnpx ui8kit add post-stats// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/** The reading figures of a post: minutes to read, views and likes, each with its glyph. */
import { type JSX } from "solid-js";
import { Group, Text } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { tpl } from "../utils";
import type { Post } from "../blocks/post-card.types";
import type { PostExtras, PostSplitLabels } from "../blocks/post-split.types";
export type PostStatsProps = {
post: Post;
extras: PostExtras;
labels: PostSplitLabels;
align?: "start" | "center";
};
export function PostStats({ post, extras, labels, align = "start" }: PostStatsProps) {
return (
<Group gap="4" align="center" justify={align} class="flex-wrap text-muted-foreground" data-slot="post-stats">
<Group gap="2" align="center">
<LucideIcon name="clock" size={16} />
<Text size="sm">
{tpl(labels.minutes, post.minutes)}
</Text>
</Group>
<Group gap="2" align="center">
<LucideIcon name="eye" size={16} />
<Text size="sm">
{tpl(labels.views, extras.views)}
</Text>
</Group>
<Group gap="2" align="center">
<LucideIcon name="heart" size={16} />
<Text size="sm">
{tpl(labels.likes, extras.likes)}
</Text>
</Group>
</Group>
);
}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework templ --dir src --registry-url https://registry.buildy.tw/templ --strict-cdnnpx ui8kit add post-stats// Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Source: packages/compose-gen/specs/organisms/post-stats.json
package blocks
import (
"github.com/ui8kit/codegen/generated/templ/ui/box"
"github.com/ui8kit/codegen/generated/templ/compose"
"github.com/ui8kit/codegen/generated/templ/icons"
"github.com/ui8kit/codegen/generated/templ/ui/text"
uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)
// PostStatsProps are the props of PostStats; the values are the JSON shapes of the TypeScript props.
type PostStatsProps struct {
Post any `json:"post"`
Extras any `json:"extras"`
Labels any `json:"labels"`
Align any `json:"align"`
}
// The reading figures of a post: minutes to read, views and likes, each with its glyph.
templ PostStats(p PostStatsProps) {
{{ vPost := p.Post }}
{{ vExtras := p.Extras }}
{{ vLabels := p.Labels }}
{{ vAlign := uiutils.Def(p.Align, "start") }}
@compose.Group(compose.GroupProps{Gap: "4", Align: "center", Justify: uiutils.S(vAlign), BoxProps: box.BoxProps{Class: "flex-wrap text-muted-foreground", Attrs: uiutils.Attrs("data-slot", "post-stats")}}) {
@compose.Group(compose.GroupProps{Gap: "2", Align: "center", BoxProps: box.BoxProps{}}) {
@icons.LucideIcon(icons.LucideIconProps{Name: "clock", Size: 16})
@compose.Text(compose.TextProps{Size: "sm", TextProps: text.TextProps{}}) {
{ uiutils.Text(uiutils.Tpl(uiutils.Get(vLabels, "minutes"), uiutils.Get(vPost, "minutes"))) }
}
}
@compose.Group(compose.GroupProps{Gap: "2", Align: "center", BoxProps: box.BoxProps{}}) {
@icons.LucideIcon(icons.LucideIconProps{Name: "eye", Size: 16})
@compose.Text(compose.TextProps{Size: "sm", TextProps: text.TextProps{}}) {
{ uiutils.Text(uiutils.Tpl(uiutils.Get(vLabels, "views"), uiutils.Get(vExtras, "views"))) }
}
}
@compose.Group(compose.GroupProps{Gap: "2", Align: "center", BoxProps: box.BoxProps{}}) {
@icons.LucideIcon(icons.LucideIconProps{Name: "heart", Size: 16})
@compose.Text(compose.TextProps{Size: "sm", TextProps: text.TextProps{}}) {
{ uiutils.Text(uiutils.Tpl(uiutils.Get(vLabels, "likes"), uiutils.Get(vExtras, "likes"))) }
}
}
}
}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework twig --dir src --registry-url https://registry.buildy.tw/twig --strict-cdnnpx ui8kit add post-stats{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/organisms/post-stats.json
The reading figures of a post: minutes to read, views and likes, each with its glyph.
Props (p): post, extras, labels, align. -#}
{%- set v_post = (p.post ?? null) -%}
{%- set v_extras = (p.extras ?? null) -%}
{%- set v_labels = (p.labels ?? null) -%}
{%- set v_align = (p.align ?? 'start') -%}
{%- set c_7 -%}
{%- set c_2 -%}
{{ include('icons/LucideIcon.html.twig', {'name': 'clock', 'size': 16}, with_context = false) }}
{%- set c_1 -%}
{{ og_text(og_tpl(og_get(v_labels, ['minutes']), [og_get(v_post, ['minutes'])])) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'size': 'sm', 'children': c_1}, with_context = false) }}
{%- endset -%}
{{ include('compose/Group.html.twig', {'gap': '2', 'align': 'center', 'children': c_2}, with_context = false) }}
{%- set c_4 -%}
{{ include('icons/LucideIcon.html.twig', {'name': 'eye', 'size': 16}, with_context = false) }}
{%- set c_3 -%}
{{ og_text(og_tpl(og_get(v_labels, ['views']), [og_get(v_extras, ['views'])])) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'size': 'sm', 'children': c_3}, with_context = false) }}
{%- endset -%}
{{ include('compose/Group.html.twig', {'gap': '2', 'align': 'center', 'children': c_4}, with_context = false) }}
{%- set c_6 -%}
{{ include('icons/LucideIcon.html.twig', {'name': 'heart', 'size': 16}, with_context = false) }}
{%- set c_5 -%}
{{ og_text(og_tpl(og_get(v_labels, ['likes']), [og_get(v_extras, ['likes'])])) }}
{%- endset -%}
{{ include('compose/Text.html.twig', {'size': 'sm', 'children': c_5}, with_context = false) }}
{%- endset -%}
{{ include('compose/Group.html.twig', {'gap': '2', 'align': 'center', 'children': c_6}, with_context = false) }}
{%- endset -%}
{{ include('compose/Group.html.twig', {'gap': '4', 'align': 'center', 'justify': og_s(v_align), 'class': 'flex-wrap text-muted-foreground', 'attrs': og_attrs(['data-slot', 'post-stats']), 'children': c_7}, with_context = false) }}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework latte --dir src --registry-url https://registry.buildy.tw/latte --strict-cdnnpx ui8kit add post-stats{* Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/organisms/post-stats.json
The reading figures of a post: minutes to read, views and likes, each with its glyph.
Props (p): post, extras, labels, align. *}
{var $v_post = ($p['post'] ?? null)}
{var $v_extras = ($p['extras'] ?? null)}
{var $v_labels = ($p['labels'] ?? null)}
{var $v_align = ($p['align'] ?? 'start')}
{capture $c_7}
{capture $c_2}
{=og_include('icons/LucideIcon.latte', ['name' => 'clock', 'size' => 16])|noescape}
{capture $c_1}
{=og_text(og_tpl(og_get($v_labels, ['minutes']), [og_get($v_post, ['minutes'])]))}
{/capture}
{=og_include('compose/Text.latte', ['size' => 'sm', 'children' => (string) $c_1])|noescape}
{/capture}
{=og_include('compose/Group.latte', ['gap' => '2', 'align' => 'center', 'children' => (string) $c_2])|noescape}
{capture $c_4}
{=og_include('icons/LucideIcon.latte', ['name' => 'eye', 'size' => 16])|noescape}
{capture $c_3}
{=og_text(og_tpl(og_get($v_labels, ['views']), [og_get($v_extras, ['views'])]))}
{/capture}
{=og_include('compose/Text.latte', ['size' => 'sm', 'children' => (string) $c_3])|noescape}
{/capture}
{=og_include('compose/Group.latte', ['gap' => '2', 'align' => 'center', 'children' => (string) $c_4])|noescape}
{capture $c_6}
{=og_include('icons/LucideIcon.latte', ['name' => 'heart', 'size' => 16])|noescape}
{capture $c_5}
{=og_text(og_tpl(og_get($v_labels, ['likes']), [og_get($v_extras, ['likes'])]))}
{/capture}
{=og_include('compose/Text.latte', ['size' => 'sm', 'children' => (string) $c_5])|noescape}
{/capture}
{=og_include('compose/Group.latte', ['gap' => '2', 'align' => 'center', 'children' => (string) $c_6])|noescape}
{/capture}
{=og_include('compose/Group.latte', ['gap' => '4', 'align' => 'center', 'justify' => og_s($v_align), 'class' => 'flex-wrap text-muted-foreground', 'attrs' => og_attrs(['data-slot', 'post-stats']), 'children' => (string) $c_7])|noescape}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework jinja2 --dir src --registry-url https://registry.buildy.tw/jinja2 --strict-cdnnpx ui8kit add post-stats{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/organisms/post-stats.json
The reading figures of a post: minutes to read, views and likes, each with its glyph.
Props (p): post, extras, labels, align. -#}
{%- set v_post = og_def(p['post'], none) -%}
{%- set v_extras = og_def(p['extras'], none) -%}
{%- set v_labels = og_def(p['labels'], none) -%}
{%- set v_align = og_def(p['align'], 'start') -%}
{%- set c_7 -%}
{%- set c_2 -%}
{{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': 'clock', 'Size': 16}}) }}
{%- set c_1 -%}
{{ og_text(og_tpl(og_get(v_labels, ['minutes']), [og_get(v_post, ['minutes'])])) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Size': 'sm'}, 'children': c_1}) }}
{%- endset -%}
{{ og_include('compose/group.html.j2', {'p': {'Gap': '2', 'Align': 'center'}, 'children': c_2}) }}
{%- set c_4 -%}
{{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': 'eye', 'Size': 16}}) }}
{%- set c_3 -%}
{{ og_text(og_tpl(og_get(v_labels, ['views']), [og_get(v_extras, ['views'])])) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Size': 'sm'}, 'children': c_3}) }}
{%- endset -%}
{{ og_include('compose/group.html.j2', {'p': {'Gap': '2', 'Align': 'center'}, 'children': c_4}) }}
{%- set c_6 -%}
{{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': 'heart', 'Size': 16}}) }}
{%- set c_5 -%}
{{ og_text(og_tpl(og_get(v_labels, ['likes']), [og_get(v_extras, ['likes'])])) }}
{%- endset -%}
{{ og_include('compose/text.html.j2', {'p': {'Size': 'sm'}, 'children': c_5}) }}
{%- endset -%}
{{ og_include('compose/group.html.j2', {'p': {'Gap': '2', 'Align': 'center'}, 'children': c_6}) }}
{%- endset -%}
{{ og_include('compose/group.html.j2', {'p': {'Gap': '4', 'Align': 'center', 'Justify': og_s(v_align), 'Class': 'flex-wrap text-muted-foreground', 'Attrs': og_attrs(['data-slot', 'post-stats'])}, 'children': c_7}) }}
Props
Names and types come from the xgen specs of the source. Standard HTML attributes (id, role, tabIndex, aria-*) pass through to the root element; the class prop is className in React.
The reading figures of a post: minutes to read, views and likes, each with its glyph.
| Prop | Type | Default | Description |
|---|---|---|---|
| post (required) | Post | - | |
| extras (required) | PostExtras | - | the author's role and bio, the reading figures, the tags and the outline |
| labels (required) | PostSplitLabels | - | |
| align | "start" | "center" | "start" |