devnonla-ui 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,10 @@
1
- import { type AnchorHTMLAttributes, createElement, type HTMLAttributes, type ReactNode } from "react";
1
+ import { type AnchorHTMLAttributes, type CSSProperties, createElement, type HTMLAttributes, type ReactNode } from "react";
2
2
  import { cn } from "../lib/cn";
3
+ import { headingClass, markdownBodyClass, markdownParagraphClass, markdownVariantStyle, pageTitleClass } from "../markdown-editor/markdownScale";
3
4
 
4
5
  export type TypographyType = "secondary" | "success" | "warning" | "danger";
5
6
 
6
- export type TitleLevel = 1 | 2 | 3 | 4 | 5;
7
+ export type TitleLevel = 1 | 2 | 3 | 4 | 5 | 6;
7
8
 
8
9
  type Decorations = {
9
10
  type?: TypographyType;
@@ -17,12 +18,18 @@ type Decorations = {
17
18
  italic?: boolean;
18
19
  };
19
20
 
20
- const TYPE_CLASS: Record<TypographyType, string> = {
21
- secondary: "text-muted-foreground",
22
- success: "text-success",
23
- warning: "text-warn",
24
- danger: "text-destructive",
25
- };
21
+ /** Same ink as MarkdownViewer. Status tones sit on top of that. */
22
+ const INK = {
23
+ title: "var(--md-heading)",
24
+ body: "var(--md-ink)",
25
+ secondary: "var(--nonla-fg-tertiary)",
26
+ quiet: "var(--nonla-fg-quaternary)",
27
+ success: "var(--nonla-success)",
28
+ warning: "var(--nonla-warn)",
29
+ danger: "var(--nonla-danger)",
30
+ } as const;
31
+
32
+ type InkRole = "title" | "body";
26
33
 
27
34
  const TITLE_TAG = {
28
35
  1: "h1",
@@ -30,20 +37,15 @@ const TITLE_TAG = {
30
37
  3: "h3",
31
38
  4: "h4",
32
39
  5: "h5",
40
+ 6: "h6",
33
41
  } as const;
34
42
 
35
- /** Ant Design seed: body 14/22, headings 38/46, 30/38, 24/32, 20/28, 16/24. */
36
- const BODY = "text-[14px] leading-[22px]";
43
+ /** Same scale as MarkdownViewer `docs`. Body 16/24. Inline code reads `--md-inline-size` (14px). */
44
+ const BODY = markdownBodyClass;
37
45
 
38
- const TITLE_CLASS: Record<TitleLevel, string> = {
39
- 1: "text-[38px] leading-[46px] font-bold",
40
- 2: "text-[30px] leading-[38px] font-bold",
41
- 3: "text-[24px] leading-[32px] font-semibold",
42
- 4: "text-[20px] leading-[28px] font-semibold",
43
- 5: "text-[16px] leading-[24px] font-semibold",
44
- };
46
+ const INLINE_CODE = "nonla-inline-code";
45
47
 
46
- const TITLE_SPACE = "nonla-typo m-0";
48
+ const TITLE_SPACE = "nonla-typo";
47
49
 
48
50
  function decorationLine(underline?: boolean, deleted?: boolean) {
49
51
  if (underline && deleted) return "underline line-through";
@@ -55,10 +57,10 @@ function decorationLine(underline?: boolean, deleted?: boolean) {
55
57
  function wrapDecorations(children: ReactNode, props: Decorations) {
56
58
  let node = children;
57
59
  if (props.mark) {
58
- node = <mark className="rounded-sm bg-[color-mix(in_oklab,var(--nonla-yellow)_40%,transparent)] px-0.5 text-inherit">{node}</mark>;
60
+ node = <mark className="rounded-sm bg-[color-mix(in_oklab,var(--nonla-warn)_40%,transparent)] px-0.5 text-inherit">{node}</mark>;
59
61
  }
60
62
  if (props.code) {
61
- node = <code className="rounded-sm bg-secondary px-1 py-px font-mono text-[0.9em] shadow-button-outline">{node}</code>;
63
+ node = <code className={INLINE_CODE}>{node}</code>;
62
64
  }
63
65
  if (props.keyboard) {
64
66
  node = <kbd className="inline-block rounded-md border border-b-2 border-border bg-muted px-1.5 font-mono text-[0.85em] leading-5">{node}</kbd>;
@@ -66,16 +68,24 @@ function wrapDecorations(children: ReactNode, props: Decorations) {
66
68
  return node;
67
69
  }
68
70
 
69
- function toneClass({ type, disabled }: Decorations) {
70
- if (disabled) return "cursor-not-allowed text-quaternary-foreground";
71
- return type ? TYPE_CLASS[type] : undefined;
71
+ function rankColor(role: InkRole, props: Decorations): string | undefined {
72
+ if (props.disabled) return INK.quiet;
73
+ if (props.type === "secondary") return INK.secondary;
74
+ if (props.type === "success") return INK.success;
75
+ if (props.type === "warning") return INK.warning;
76
+ if (props.type === "danger") return INK.danger;
77
+ if (role === "title") return INK.title;
78
+ if (role === "body") return INK.body;
79
+ return undefined;
72
80
  }
73
81
 
74
- function decorated(props: Decorations, children: ReactNode, base: string, className?: string, style?: HTMLAttributes<HTMLElement>["style"]) {
82
+ function decorated(props: Decorations, children: ReactNode, base: string, className?: string, style?: HTMLAttributes<HTMLElement>["style"], role: InkRole = "body") {
75
83
  const line = decorationLine(props.underline, props.delete);
84
+ const color = rankColor(role, props);
85
+ const scale: CSSProperties = { ...markdownVariantStyle("docs"), ...(color ? { color } : null), ...(line ? { textDecorationLine: line } : null), ...style };
76
86
  return {
77
- className: cn(base, toneClass(props), props.strong && "font-semibold", props.italic && "italic", props.underline && "underline-offset-[3px]", className),
78
- style: line ? { textDecorationLine: line, ...style } : style,
87
+ className: cn(base, props.disabled && "cursor-not-allowed", props.strong && "font-(--md-strong-weight,600)", props.italic && "italic", props.underline && "underline-offset-[3px]", className),
88
+ style: scale,
79
89
  children: wrapDecorations(children, props),
80
90
  "aria-disabled": props.disabled || undefined,
81
91
  };
@@ -99,7 +109,7 @@ export type TypographyTextProps = Omit<HTMLAttributes<HTMLSpanElement>, "color">
99
109
 
100
110
  export function Text({ className, style, children, ...props }: TypographyTextProps) {
101
111
  const { decorations, rest } = splitDecorations(props);
102
- return <span {...rest} {...decorated(decorations, children, cn(BODY, "text-foreground"), className, style)} />;
112
+ return <span {...rest} {...decorated(decorations, children, BODY, className, style, "body")} />;
103
113
  }
104
114
 
105
115
  export type TypographyTitleProps = Omit<HTMLAttributes<HTMLHeadingElement>, "color"> & Decorations & {
@@ -109,14 +119,14 @@ export type TypographyTitleProps = Omit<HTMLAttributes<HTMLHeadingElement>, "col
109
119
 
110
120
  export function Title({ level = 1, className, style, children, ...props }: TypographyTitleProps) {
111
121
  const { decorations, rest } = splitDecorations(props);
112
- return createElement(TITLE_TAG[level], { ...rest, ...decorated(decorations, children, cn(TITLE_SPACE, "text-foreground", TITLE_CLASS[level]), className, style) });
122
+ return createElement(TITLE_TAG[level], { ...rest, ...decorated(decorations, children, cn(TITLE_SPACE, level === 1 ? pageTitleClass : headingClass(level)), className, style, "title") });
113
123
  }
114
124
 
115
125
  export type TypographyParagraphProps = Omit<HTMLAttributes<HTMLParagraphElement>, "color"> & Decorations & { children?: ReactNode };
116
126
 
117
127
  export function Paragraph({ className, style, children, ...props }: TypographyParagraphProps) {
118
128
  const { decorations, rest } = splitDecorations(props);
119
- return <p {...rest} {...decorated(decorations, children, "nonla-typo m-0 text-[15px] leading-7 text-foreground [p.nonla-typo+&]:mt-3", className, style)} />;
129
+ return <p {...rest} {...decorated(decorations, children, markdownParagraphClass, className, style, "body")} />;
120
130
  }
121
131
 
122
132
  export type TypographyLinkProps = Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "color"> & Decorations & { children?: ReactNode };
@@ -126,14 +136,10 @@ export function Link({ href, target, rel, className, style, children, onClick, .
126
136
  const view = decorated(
127
137
  decorations,
128
138
  children,
129
- cn(
130
- "cursor-pointer underline-offset-[3px]",
131
- BODY,
132
- decorations.type || decorations.disabled ? undefined : "text-brand hover:text-brand-700",
133
- decorations.disabled || decorations.underline ? undefined : "hover:underline",
134
- ),
139
+ cn("cursor-pointer underline-offset-[3px]", BODY, decorations.disabled || decorations.underline ? undefined : "hover:underline"),
135
140
  className,
136
141
  style,
142
+ "body",
137
143
  );
138
144
 
139
145
  return (