use gpui::{div, prelude::*, px, App, SharedString, StyleRefinement};
use crate::sx::{Sx, SxStyled};
use crate::{component, styles, styles::ApplyStyleOverrides, theme::ActiveTheme};
styles! {
TYPOGRAPHY = {
h1: { text: 36.0, line_height: 10, font: extrabold },
h2: {
padding_bottom: 2,
border_bottom: 1,
border_color: border,
text: 30.0,
line_height: 9,
font: semibold,
},
h3: { text: 24.0, line_height: 8, font: semibold },
h4: { text: 20.0, line_height: 7, font: semibold },
p: { text: base, line_height: 7 },
blockquote: { padding_start: 6, border_start: 2, border_color: border, italic: true },
list: { display: flex, direction: column, gap: 2, padding_start: 6 },
list_item: { display: flex, gap: 2 },
list_marker: { flex: none, min_width: 3 },
inline_code: {
padding_x: 1.25,
padding_y: 0.5,
background: muted,
font_family: mono,
text: sm,
font: semibold,
},
lead: { text: xl, color: muted_foreground },
large: { text: lg, font: semibold },
small: { text: sm, font: medium, line_height: 3.5 },
muted: { text: sm, color: muted_foreground },
}
}
#[component]
pub fn H1(
text: SharedString,
#[style] style_overrides: StyleRefinement,
#[sx] sx: Sx,
) -> impl IntoElement {
div()
.sx((&TYPOGRAPHY.h1, &sx))
.child(crate::components::bidi_text::text(text))
.apply_style_overrides(&style_overrides)
}
#[component]
pub fn H2(
text: SharedString,
#[style] style_overrides: StyleRefinement,
#[sx] sx: Sx,
) -> impl IntoElement {
div()
.sx((&TYPOGRAPHY.h2, &sx))
.child(crate::components::bidi_text::text(text))
.apply_style_overrides(&style_overrides)
}
#[component]
pub fn H3(
text: SharedString,
#[style] style_overrides: StyleRefinement,
#[sx] sx: Sx,
) -> impl IntoElement {
div()
.sx((&TYPOGRAPHY.h3, &sx))
.child(crate::components::bidi_text::text(text))
.apply_style_overrides(&style_overrides)
}
#[component]
pub fn H4(
text: SharedString,
#[style] style_overrides: StyleRefinement,
#[sx] sx: Sx,
) -> impl IntoElement {
div()
.sx((&TYPOGRAPHY.h4, &sx))
.child(crate::components::bidi_text::text(text))
.apply_style_overrides(&style_overrides)
}
#[component]
pub fn P(
text: SharedString,
#[style] style_overrides: StyleRefinement,
#[sx] sx: Sx,
) -> impl IntoElement {
div()
.sx((&TYPOGRAPHY.p, &sx))
.child(crate::components::bidi_text::text(text))
.apply_style_overrides(&style_overrides)
}
#[component]
pub fn Blockquote(
text: SharedString,
#[style] style_overrides: StyleRefinement,
#[sx] sx: Sx,
) -> impl IntoElement {
div()
.sx((&TYPOGRAPHY.blockquote, &sx))
.child(crate::components::bidi_text::text(text))
.apply_style_overrides(&style_overrides)
}
#[component]
pub fn List(
items: Vec<SharedString>,
#[prop(optional)] ordered: bool,
#[style] style_overrides: StyleRefinement,
#[sx] sx: Sx,
) -> impl IntoElement {
div()
.sx((&TYPOGRAPHY.list, &sx))
.children(items.into_iter().enumerate().map(move |(index, item)| {
let marker: SharedString = if ordered {
format!("{}.", index + 1).into()
} else {
"•".into()
};
div()
.sx(&TYPOGRAPHY.list_item)
.child(div().sx(&TYPOGRAPHY.list_marker).child(marker))
.child(item)
}))
.apply_style_overrides(&style_overrides)
}
#[component]
pub fn InlineCode(text: SharedString, cx: &mut App, #[sx] sx: Sx) -> impl IntoElement {
let radius = cx.theme().radius_small().max(px(3.));
div()
.rounded(radius)
.sx((&TYPOGRAPHY.inline_code, &sx))
.child(crate::components::bidi_text::text(text))
}
#[component]
pub fn Lead(text: SharedString, #[sx] sx: Sx) -> impl IntoElement {
div()
.sx((&TYPOGRAPHY.lead, &sx))
.child(crate::components::bidi_text::text(text))
}
#[component]
pub fn Large(text: SharedString, #[sx] sx: Sx) -> impl IntoElement {
div()
.sx((&TYPOGRAPHY.large, &sx))
.child(crate::components::bidi_text::text(text))
}
#[component]
pub fn Small(text: SharedString, #[sx] sx: Sx) -> impl IntoElement {
div()
.sx((&TYPOGRAPHY.small, &sx))
.child(crate::components::bidi_text::text(text))
}
#[component]
pub fn Muted(text: SharedString, #[sx] sx: Sx) -> impl IntoElement {
div()
.sx((&TYPOGRAPHY.muted, &sx))
.child(crate::components::bidi_text::text(text))
}