@seanyeh77/ui 0.46.0 → 0.47.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.
- package/dist/bundle.js +16 -16
- package/dist/components/Badge/Badge.d.ts +4 -4
- package/dist/components/Badge/Badge.js +7 -1
- package/dist/components/Badge/Badge.js.map +1 -1
- package/dist/components/Breadcrumb/Breadcrumb.js +1 -0
- package/dist/components/Breadcrumb/Breadcrumb.js.map +1 -1
- package/dist/components/DataTable/DataTable.js +12 -3
- package/dist/components/DataTable/DataTable.js.map +1 -1
- package/dist/components/EmptyState/EmptyState.js +19 -1
- package/dist/components/EmptyState/EmptyState.js.map +1 -1
- package/dist/components/InlineCode/InlineCode.js +1 -1
- package/dist/components/InlineCode/InlineCode.js.map +1 -1
- package/dist/components/KpiCard/KpiCard.d.ts +2 -2
- package/dist/components/KpiCard/KpiCard.js +1 -1
- package/dist/components/KpiCard/KpiCard.js.map +1 -1
- package/dist/components/LayerGraph/LayerGraph.js +5 -5
- package/dist/components/LayerGraph/LayerGraph.js.map +1 -1
- package/dist/components/MultiSelect/MultiSelect.js +1 -0
- package/dist/components/MultiSelect/MultiSelect.js.map +1 -1
- package/dist/components/SettingsLayout/SettingsLayout.js +3 -1
- package/dist/components/SettingsLayout/SettingsLayout.js.map +1 -1
- package/dist/components/TextField/TextField.d.ts +8 -2
- package/dist/components/TextField/TextField.js +59 -13
- package/dist/components/TextField/TextField.js.map +1 -1
- package/dist/css/Alert.css +9 -1
- package/dist/css/DataTable.css +27 -2
- package/dist/css/EmptyState.css +4 -4
- package/dist/css/EventTimeline.css +3 -1
- package/dist/css/LayerGraph.css +1 -1
- package/dist/css/LoadingBar.css +4 -1
- package/dist/css/MobileTabBar.css +6 -4
- package/dist/css/SettingsLayout.css +1 -0
- package/dist/css/Tabs.css +15 -2
- package/dist/css/base.css +86 -3
- package/dist/css/end.css +3 -1
- package/dist/i18n.js +1 -0
- package/dist/i18n.js.map +1 -1
- package/dist/icons/Icon.d.ts +2 -1
- package/dist/icons/Icon.js +4 -3
- package/dist/icons/Icon.js.map +1 -1
- package/dist/icons/store.d.ts +3 -1
- package/dist/icons/store.js +17 -12
- package/dist/icons/store.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/internal/util.js +4 -3
- package/dist/internal/util.js.map +1 -1
- package/dist/styles.css +248 -109
- package/dist/theme.d.ts +7 -0
- package/dist/theme.js +39 -15
- package/dist/theme.js.map +1 -1
- package/docs/Badge.md +2 -1
- package/docs/EmptyState.md +1 -1
- package/docs/EventTimeline.md +1 -1
- package/docs/Graph.md +1 -1
- package/docs/KpiCard.md +1 -1
- package/docs/LoadingBar.md +1 -1
- package/docs/MobileTabBar.md +1 -1
- package/docs/MultiSelect.md +1 -1
- package/docs/Tabs.md +10 -9
- package/docs/TextField.md +2 -0
- package/docs/agents.md +6 -6
- package/docs/theme.md +5 -2
- package/package.json +2 -2
|
@@ -1,17 +1,35 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { codeText } from "../InlineCode/InlineCode.js";
|
|
3
|
+
import { cx, resizeObserver } from "../../internal/util.js";
|
|
4
|
+
import * as React from "react";
|
|
3
5
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
6
|
// src/components/EmptyState/EmptyState.tsx
|
|
5
7
|
/** What a list or page shows when it has nothing yet: what is missing and the first step. */
|
|
6
8
|
function EmptyState({ title, description, steps = [], current = 0, action }) {
|
|
9
|
+
const descRef = React.useRef(null);
|
|
10
|
+
const [long, setLong] = React.useState(false);
|
|
11
|
+
React.useLayoutEffect(() => {
|
|
12
|
+
const el = descRef.current;
|
|
13
|
+
if (!el) return;
|
|
14
|
+
const measure = () => {
|
|
15
|
+
const line = parseFloat(getComputedStyle(el).lineHeight);
|
|
16
|
+
const h = el.getBoundingClientRect().height;
|
|
17
|
+
setLong(line > 0 && h > 0 && Math.round(h / line) > 2);
|
|
18
|
+
};
|
|
19
|
+
measure();
|
|
20
|
+
const ro = resizeObserver(measure);
|
|
21
|
+
ro?.observe(el);
|
|
22
|
+
return () => ro?.disconnect();
|
|
23
|
+
}, [description]);
|
|
7
24
|
return /* @__PURE__ */ jsxs("div", {
|
|
8
|
-
className: "ui-empty",
|
|
25
|
+
className: cx("ui-empty", long && "is-long"),
|
|
9
26
|
children: [
|
|
10
27
|
/* @__PURE__ */ jsx("div", {
|
|
11
28
|
className: "ui-empty-title",
|
|
12
29
|
children: title
|
|
13
30
|
}),
|
|
14
31
|
description ? /* @__PURE__ */ jsx("p", {
|
|
32
|
+
ref: descRef,
|
|
15
33
|
className: "ui-empty-desc",
|
|
16
34
|
children: codeText(description)
|
|
17
35
|
}) : null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmptyState.js","names":[],"sources":["../../../src/components/EmptyState/EmptyState.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"EmptyState.js","names":[],"sources":["../../../src/components/EmptyState/EmptyState.tsx"],"sourcesContent":["import * as React from 'react';\nimport { codeText } from '../InlineCode/InlineCode';\nimport { cx, resizeObserver } from '../../internal/util';\n\nexport interface EmptyStateProps {\n /** What is empty, stated: 「還沒有專案」. */\n title: string;\n /** One sentence on what to do; `backticks` are code. */\n description?: string;\n /** Numbered first steps; `backticks` are code. */\n steps?: string[];\n /** Index of the current step. Default 0. */\n current?: number;\n /** The one button that starts the first step. */\n action?: React.ReactNode;\n}\n\n/** What a list or page shows when it has nothing yet: what is missing and the first step. */\nexport function EmptyState({ title, description, steps = [], current = 0, action }: EmptyStateProps) {\n // A description longer than 2 lines: on a phone the whole block reads from the left (CSS applies it under 600 px).\n const descRef = React.useRef<HTMLParagraphElement>(null);\n const [long, setLong] = React.useState(false);\n React.useLayoutEffect(() => {\n const el = descRef.current;\n if (!el) return;\n const measure = () => {\n const line = parseFloat(getComputedStyle(el).lineHeight);\n const h = el.getBoundingClientRect().height;\n setLong(line > 0 && h > 0 && Math.round(h / line) > 2);\n };\n measure();\n const ro = resizeObserver(measure);\n ro?.observe(el);\n return () => ro?.disconnect();\n }, [description]);\n return (\n <div className={cx('ui-empty', long && 'is-long')}>\n <div className=\"ui-empty-title\">{title}</div>\n {description ? (\n <p ref={descRef} className=\"ui-empty-desc\">\n {codeText(description)}\n </p>\n ) : null}\n {steps.length ? (\n <ol className=\"ui-steps\">\n {steps.map((s, i) => (\n <li key={i} className={i === current ? 'is-current' : undefined} aria-current={i === current ? 'step' : undefined}>\n <span className=\"ui-step-num\">{i + 1}</span>\n <span>{codeText(s)}</span>\n </li>\n ))}\n </ol>\n ) : null}\n {action ?? null}\n </div>\n );\n}\n"],"mappings":";;;;;;;AAkBA,SAAgB,WAAW,EAAE,OAAO,aAAa,QAAQ,CAAC,GAAG,UAAU,GAAG,UAA2B;CAEnG,MAAM,UAAU,MAAM,OAA6B,IAAI;CACvD,MAAM,CAAC,MAAM,WAAW,MAAM,SAAS,KAAK;CAC5C,MAAM,sBAAsB;EAC1B,MAAM,KAAK,QAAQ;EACnB,IAAI,CAAC,IAAI;EACT,MAAM,gBAAgB;GACpB,MAAM,OAAO,WAAW,iBAAiB,EAAE,CAAC,CAAC,UAAU;GACvD,MAAM,IAAI,GAAG,sBAAsB,CAAC,CAAC;GACrC,QAAQ,OAAO,KAAK,IAAI,KAAK,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC;EACvD;EACA,QAAQ;EACR,MAAM,KAAK,eAAe,OAAO;EACjC,IAAI,QAAQ,EAAE;EACd,aAAa,IAAI,WAAW;CAC9B,GAAG,CAAC,WAAW,CAAC;CAChB,OACE,qBAAC,OAAD;EAAK,WAAW,GAAG,YAAY,QAAQ,SAAS;EAAhD,UAAA;GACE,oBAAC,OAAD;IAAK,WAAU;IAAkB,UAAA;GAAW,CAAA;GAC3C,cACC,oBAAC,KAAD;IAAG,KAAK;IAAS,WAAU;IACxB,UAAA,SAAS,WAAW;GACpB,CAAA,IACD;GACH,MAAM,SACL,oBAAC,MAAD;IAAI,WAAU;IACX,UAAA,MAAM,KAAK,GAAG,MACb,qBAAC,MAAD;KAAY,WAAW,MAAM,UAAU,eAAe,KAAA;KAAW,gBAAc,MAAM,UAAU,SAAS,KAAA;KAAxG,UAAA,CACE,oBAAC,QAAD;MAAM,WAAU;MAAe,UAAA,IAAI;KAAQ,CAAA,GAC3C,oBAAC,QAAD,EAAA,UAAO,SAAS,CAAC,EAAQ,CAAA,CACvB;IAHK,GAAA,CAGL,CACL;GACC,CAAA,IACF;GACH,UAAU;EACR;;AAET"}
|
|
@@ -41,7 +41,7 @@ function CodeText({ text, refHref, onRef, isRef = isCodeRef, as: Tag = "span", c
|
|
|
41
41
|
return /* @__PURE__ */ jsx(Tag, {
|
|
42
42
|
className,
|
|
43
43
|
children: codeSpans(text).map(({ code, text: v }, i) => {
|
|
44
|
-
if (!code) return v;
|
|
44
|
+
if (!code) return keepUnits(v);
|
|
45
45
|
const href = refHref && isRef(v) ? refHref(v) || void 0 : void 0;
|
|
46
46
|
if (!(isRef(v) && (refHref ? !!href : !!onRef))) return /* @__PURE__ */ jsx(InlineCode, { children: v }, i);
|
|
47
47
|
const click = onRef ? (e) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InlineCode.js","names":[],"sources":["../../../src/components/InlineCode/InlineCode.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cx, keepUnits } from '../../internal/util';\nimport { codeSpans, hasCodeSpan } from '../../internal/codeSpans';\n\ninterface InlineCodeBase {\n /** The code, path or ID. */\n children?: React.ReactNode;\n /** Extra class on the root element. */\n className?: string;\n}\ntype Target =\n | { /** Makes it a link. */ href: string; onClick?: (e: React.MouseEvent<HTMLElement>) => void }\n | { href?: undefined; onClick: (e: React.MouseEvent<HTMLElement>) => void };\n\nexport type InlineCodeProps = InlineCodeBase &\n (\n | {\n /** 'chip' (default): monospace on a light gray chip; with href or onClick an underlined accent link. */\n look?: 'chip';\n /** Makes it a link. */\n href?: string;\n /** Makes it a button-like link that runs this. */\n onClick?: (e: React.MouseEvent<HTMLElement>) => void;\n }\n | ({\n /** 'name': a function, class or variable that opens its definition. Accent monospace without a chip, underlined\n * on hover and keyboard focus. 'location': a file and line (src/app.c:86), gray and one step smaller, accent\n * and underlined on hover and focus. Both need href or onClick: text that points nowhere keeps the chip. */\n look: 'name' | 'location';\n } & Target)\n );\n\n/** Code inside a sentence: monospace on a light gray chip. A span that points somewhere is a link; `look` turns a\n * link into a name or a location. */\nexport function InlineCode({ children, href, onClick, className, look = 'chip' }: InlineCodeProps) {\n // Like Term: a link inside a sentence (text beside it) keeps its line height; on its own it gets the 48 px touch area.\n const [inline, setInline] = React.useState(false);\n const link = React.useCallback((el: HTMLElement | null) => {\n const par = el?.parentNode;\n setInline(!!par && Array.from(par.childNodes).some((n) => n.nodeType === 3 && !!n.textContent?.trim()));\n }, []);\n const isLink = !!(href || onClick);\n const cls = cx(\n 'ui-code',\n isLink && 'is-link',\n isLink && inline && 'is-inline',\n isLink && look !== 'chip' && `is-${look}`,\n typeof children === 'string' && children.length <= 24 && 'is-short',\n className,\n );\n if (href)\n return (\n <a ref={link} className={cls} href={href} onClick={onClick}>\n {children}\n </a>\n );\n if (onClick)\n return (\n <button ref={link} type=\"button\" className={cls} onClick={onClick}>\n {children}\n </button>\n );\n return <code className={cls}>{children}</code>;\n}\n\n/** Returns the link of a reference such as src/app.c:86, or undefined when it has no target. */\nexport type RefHref = (ref: string) => string | undefined | null;\n/** Called on a plain click on a reference; the default navigation is prevented. */\nexport type OnRef = (ref: string, e: React.MouseEvent<HTMLElement>) => void;\n\n/** A file and line, such as src/app.c:86 or main.py:12-20. */\nconst CODE_REF = /^[\\w./-]+\\.[A-Za-z0-9]+:\\d+(-\\d+)?$/;\nexport const isCodeRef = (span: string): boolean => CODE_REF.test(span);\n\nexport interface CodeTextProps {\n /** Text with `backtick` spans, as written in Markdown. */\n text: string;\n /** Spans that look like file.c:86 become links; return undefined when the reference has no target. */\n refHref?: RefHref;\n /** Called when a reference is pressed, for apps that open it themselves. */\n onRef?: OnRef;\n /** Which spans are references. Default: a file name with a line number. */\n isRef?: (span: string) => boolean;\n /** The element to render. Default span. */\n as?: 'span' | 'p' | 'div' | 'li';\n /** Extra class on the root element. */\n className?: string;\n}\n\n/** Text with `backtick` spans: renders them as InlineCode, never as raw backticks. */\nexport function CodeText({ text, refHref, onRef, isRef = isCodeRef, as: Tag = 'span', className }: CodeTextProps) {\n return (\n <Tag className={className}>\n {codeSpans(text).map(({ code, text: v }, i) => {\n if (!code) return v;\n const href = refHref && isRef(v) ? refHref(v) || undefined : undefined;\n const link = isRef(v) && (refHref ? !!href : !!onRef);\n if (!link) return <InlineCode key={i}>{v}</InlineCode>;\n // A reference that points somewhere is a location: gray, one step smaller.\n const click = onRef\n ? (e: React.MouseEvent<HTMLElement>) => {\n // A plain click goes to onRef; Ctrl, ⌘, Shift or the middle button still opens href in a new tab.\n if (href && (e.metaKey || e.ctrlKey || e.shiftKey || e.button === 1)) return;\n e.preventDefault();\n onRef(v, e);\n }\n : undefined;\n if (href)\n return (\n <InlineCode key={i} look=\"location\" href={href} onClick={click}>\n {v}\n </InlineCode>\n );\n if (click)\n return (\n <InlineCode key={i} look=\"location\" onClick={click}>\n {v}\n </InlineCode>\n );\n return <InlineCode key={i}>{v}</InlineCode>;\n })}\n </Tag>\n );\n}\n\n/** A sentence prop that takes a string: `backtick` spans become InlineCode, the backticks are not shown; a number and its\n * unit outside them never break apart (「100 MB」). Anything that is not a string (an element) is left alone. */\nexport function codeText(text: React.ReactNode): React.ReactNode {\n if (typeof text !== 'string') return text;\n if (!hasCodeSpan(text)) return keepUnits(text);\n return codeSpans(text).map((s, i) => (s.code ? <InlineCode key={i}>{s.text}</InlineCode> : keepUnits(s.text)));\n}\n"],"mappings":";;;;;;;;AAkCA,SAAgB,WAAW,EAAE,UAAU,MAAM,SAAS,WAAW,OAAO,UAA2B;CAEjG,MAAM,CAAC,QAAQ,aAAa,MAAM,SAAS,KAAK;CAChD,MAAM,OAAO,MAAM,aAAa,OAA2B;EACzD,MAAM,MAAM,IAAI;EAChB,UAAU,CAAC,CAAC,OAAO,MAAM,KAAK,IAAI,UAAU,CAAC,CAAC,MAAM,MAAM,EAAE,aAAa,KAAK,CAAC,CAAC,EAAE,aAAa,KAAK,CAAC,CAAC;CACxG,GAAG,CAAC,CAAC;CACL,MAAM,SAAS,CAAC,EAAE,QAAQ;CAC1B,MAAM,MAAM,GACV,WACA,UAAU,WACV,UAAU,UAAU,aACpB,UAAU,SAAS,UAAU,MAAM,QACnC,OAAO,aAAa,YAAY,SAAS,UAAU,MAAM,YACzD,SACF;CACA,IAAI,MACF,OACE,oBAAC,KAAD;EAAG,KAAK;EAAM,WAAW;EAAW;EAAe;EAChD;CACA,CAAA;CAEP,IAAI,SACF,OACE,oBAAC,UAAD;EAAQ,KAAK;EAAM,MAAK;EAAS,WAAW;EAAc;EACvD;CACK,CAAA;CAEZ,OAAO,oBAAC,QAAD;EAAM,WAAW;EAAM;CAAe,CAAA;AAC/C;;AAQA,MAAM,WAAW;AACjB,MAAa,aAAa,SAA0B,SAAS,KAAK,IAAI;;AAkBtE,SAAgB,SAAS,EAAE,MAAM,SAAS,OAAO,QAAQ,WAAW,IAAI,MAAM,QAAQ,aAA4B;CAChH,OACE,oBAAC,KAAD;EAAgB;EACb,UAAA,UAAU,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,MAAM,KAAK,MAAM;GAC7C,IAAI,CAAC,MAAM,OAAO;
|
|
1
|
+
{"version":3,"file":"InlineCode.js","names":[],"sources":["../../../src/components/InlineCode/InlineCode.tsx"],"sourcesContent":["import * as React from 'react';\nimport { cx, keepUnits } from '../../internal/util';\nimport { codeSpans, hasCodeSpan } from '../../internal/codeSpans';\n\ninterface InlineCodeBase {\n /** The code, path or ID. */\n children?: React.ReactNode;\n /** Extra class on the root element. */\n className?: string;\n}\ntype Target =\n | { /** Makes it a link. */ href: string; onClick?: (e: React.MouseEvent<HTMLElement>) => void }\n | { href?: undefined; onClick: (e: React.MouseEvent<HTMLElement>) => void };\n\nexport type InlineCodeProps = InlineCodeBase &\n (\n | {\n /** 'chip' (default): monospace on a light gray chip; with href or onClick an underlined accent link. */\n look?: 'chip';\n /** Makes it a link. */\n href?: string;\n /** Makes it a button-like link that runs this. */\n onClick?: (e: React.MouseEvent<HTMLElement>) => void;\n }\n | ({\n /** 'name': a function, class or variable that opens its definition. Accent monospace without a chip, underlined\n * on hover and keyboard focus. 'location': a file and line (src/app.c:86), gray and one step smaller, accent\n * and underlined on hover and focus. Both need href or onClick: text that points nowhere keeps the chip. */\n look: 'name' | 'location';\n } & Target)\n );\n\n/** Code inside a sentence: monospace on a light gray chip. A span that points somewhere is a link; `look` turns a\n * link into a name or a location. */\nexport function InlineCode({ children, href, onClick, className, look = 'chip' }: InlineCodeProps) {\n // Like Term: a link inside a sentence (text beside it) keeps its line height; on its own it gets the 48 px touch area.\n const [inline, setInline] = React.useState(false);\n const link = React.useCallback((el: HTMLElement | null) => {\n const par = el?.parentNode;\n setInline(!!par && Array.from(par.childNodes).some((n) => n.nodeType === 3 && !!n.textContent?.trim()));\n }, []);\n const isLink = !!(href || onClick);\n const cls = cx(\n 'ui-code',\n isLink && 'is-link',\n isLink && inline && 'is-inline',\n isLink && look !== 'chip' && `is-${look}`,\n typeof children === 'string' && children.length <= 24 && 'is-short',\n className,\n );\n if (href)\n return (\n <a ref={link} className={cls} href={href} onClick={onClick}>\n {children}\n </a>\n );\n if (onClick)\n return (\n <button ref={link} type=\"button\" className={cls} onClick={onClick}>\n {children}\n </button>\n );\n return <code className={cls}>{children}</code>;\n}\n\n/** Returns the link of a reference such as src/app.c:86, or undefined when it has no target. */\nexport type RefHref = (ref: string) => string | undefined | null;\n/** Called on a plain click on a reference; the default navigation is prevented. */\nexport type OnRef = (ref: string, e: React.MouseEvent<HTMLElement>) => void;\n\n/** A file and line, such as src/app.c:86 or main.py:12-20. */\nconst CODE_REF = /^[\\w./-]+\\.[A-Za-z0-9]+:\\d+(-\\d+)?$/;\nexport const isCodeRef = (span: string): boolean => CODE_REF.test(span);\n\nexport interface CodeTextProps {\n /** Text with `backtick` spans, as written in Markdown. */\n text: string;\n /** Spans that look like file.c:86 become links; return undefined when the reference has no target. */\n refHref?: RefHref;\n /** Called when a reference is pressed, for apps that open it themselves. */\n onRef?: OnRef;\n /** Which spans are references. Default: a file name with a line number. */\n isRef?: (span: string) => boolean;\n /** The element to render. Default span. */\n as?: 'span' | 'p' | 'div' | 'li';\n /** Extra class on the root element. */\n className?: string;\n}\n\n/** Text with `backtick` spans: renders them as InlineCode, never as raw backticks. */\nexport function CodeText({ text, refHref, onRef, isRef = isCodeRef, as: Tag = 'span', className }: CodeTextProps) {\n return (\n <Tag className={className}>\n {codeSpans(text).map(({ code, text: v }, i) => {\n if (!code) return keepUnits(v);\n const href = refHref && isRef(v) ? refHref(v) || undefined : undefined;\n const link = isRef(v) && (refHref ? !!href : !!onRef);\n if (!link) return <InlineCode key={i}>{v}</InlineCode>;\n // A reference that points somewhere is a location: gray, one step smaller.\n const click = onRef\n ? (e: React.MouseEvent<HTMLElement>) => {\n // A plain click goes to onRef; Ctrl, ⌘, Shift or the middle button still opens href in a new tab.\n if (href && (e.metaKey || e.ctrlKey || e.shiftKey || e.button === 1)) return;\n e.preventDefault();\n onRef(v, e);\n }\n : undefined;\n if (href)\n return (\n <InlineCode key={i} look=\"location\" href={href} onClick={click}>\n {v}\n </InlineCode>\n );\n if (click)\n return (\n <InlineCode key={i} look=\"location\" onClick={click}>\n {v}\n </InlineCode>\n );\n return <InlineCode key={i}>{v}</InlineCode>;\n })}\n </Tag>\n );\n}\n\n/** A sentence prop that takes a string: `backtick` spans become InlineCode, the backticks are not shown; a number and its\n * unit outside them never break apart (「100 MB」). Anything that is not a string (an element) is left alone. */\nexport function codeText(text: React.ReactNode): React.ReactNode {\n if (typeof text !== 'string') return text;\n if (!hasCodeSpan(text)) return keepUnits(text);\n return codeSpans(text).map((s, i) => (s.code ? <InlineCode key={i}>{s.text}</InlineCode> : keepUnits(s.text)));\n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AO,oBAAC,YAAD,EAAA,UAAqB,EAAc,GAAlB,CAAkB;GAErD,MAAM,QAAQ,SACT,MAAqC;IAEpC,IAAI,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,IAAI;IACtE,EAAE,eAAe;IACjB,MAAM,GAAG,CAAC;GACZ,IACA,KAAA;GACJ,IAAI,MACF,OACE,oBAAC,YAAD;IAAoB,MAAK;IAAiB;IAAM,SAAS;IACtD,UAAA;GACS,GAFK,CAEL;GAEhB,IAAI,OACF,OACE,oBAAC,YAAD;IAAoB,MAAK;IAAW,SAAS;IAC1C,UAAA;GACS,GAFK,CAEL;GAEhB,OAAO,oBAAC,YAAD,EAAA,UAAqB,EAAc,GAAlB,CAAkB;EAC5C,CAAC;CACE,CAAA;AAET;;;AAIA,SAAgB,SAAS,MAAwC;CAC/D,IAAI,OAAO,SAAS,UAAU,OAAO;CACrC,IAAI,CAAC,YAAY,IAAI,GAAG,OAAO,UAAU,IAAI;CAC7C,OAAO,UAAU,IAAI,CAAC,CAAC,KAAK,GAAG,MAAO,EAAE,OAAO,oBAAC,YAAD,EAAA,UAAqB,EAAE,KAAiB,GAAvB,CAAuB,IAAI,UAAU,EAAE,IAAI,CAAE;AAC/G"}
|
|
@@ -12,8 +12,8 @@ export interface KpiCardProps {
|
|
|
12
12
|
compact?: boolean;
|
|
13
13
|
/** Written after the number: 元, 人, ms, %. */
|
|
14
14
|
unit?: string;
|
|
15
|
-
/** Digits after the decimal point, for the figure and its change (delta). Default 0 for the figure
|
|
16
|
-
* keeps 1 (%) or 2 (pt). */
|
|
15
|
+
/** Digits after the decimal point, for the figure and its change (delta). Default 0 for the figure, 1 with unit="%"
|
|
16
|
+
* (a percentage has 1 decimal); the change then keeps 1 (%) or 2 (pt). */
|
|
17
17
|
decimals?: number;
|
|
18
18
|
/** Change versus the comparison period. */
|
|
19
19
|
delta?: number;
|
|
@@ -18,7 +18,7 @@ function sansCjk(text) {
|
|
|
18
18
|
}
|
|
19
19
|
/** One figure with its change and a sparkline. It is a card: put several in a grid, not inside another Card. */
|
|
20
20
|
function KpiCard(props) {
|
|
21
|
-
const { label, value, unit, decimals = 0, delta, deltaUnit, direction = "up", good, spark, compareLabel, size = "default", verdict, target, className } = props;
|
|
21
|
+
const { label, value, unit, decimals = unit === "%" ? 1 : 0, delta, deltaUnit, direction = "up", good, spark, compareLabel, size = "default", verdict, target, className } = props;
|
|
22
22
|
const compact = size === "compact";
|
|
23
23
|
devWarn(compact && !!spark, "KpiCard", "size=\"compact\" draws no sparkline, so spark is ignored. Drop spark, or use the default size.");
|
|
24
24
|
devWarn(props.format === "percent" && !unit, "KpiCard", "format='percent' shows the number only; pass unit=\"%\" for the smaller % after it.");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KpiCard.js","names":[],"sources":["../../../src/components/KpiCard/KpiCard.tsx"],"sourcesContent":["import * as React from 'react';\nimport { format } from '../../format';\nimport { devWarn } from '../../internal/dev';\nimport { I18N, tr } from '../../i18n';\nimport { kpiText, smoothPath, useCountUp, useFitText, type Point } from '../../internal/chart';\nimport { cx, digits } from '../../internal/util';\nimport { codeText } from '../InlineCode/InlineCode';\n\nexport interface KpiCardProps {\n /** What is measured: 「本月營收」. */\n label: string;\n /** The figure, as a number (counts up from 0 when it appears). */\n value: number;\n /** 'money' shows NT$ 1,280; 'percent' 1 decimal without the % sign: pass unit=\"%\" (same as DataTable). Default 'number'. */\n format?: 'number' | 'money' | 'percent';\n /** For money. Default: the locale's currency (TWD). */\n currency?: string;\n /** Abbreviate from 1 萬 (default true). The only place numbers are abbreviated. */\n compact?: boolean;\n /** Written after the number: 元, 人, ms, %. */\n unit?: string;\n /** Digits after the decimal point, for the figure and its change (delta). Default 0 for the figure
|
|
1
|
+
{"version":3,"file":"KpiCard.js","names":[],"sources":["../../../src/components/KpiCard/KpiCard.tsx"],"sourcesContent":["import * as React from 'react';\nimport { format } from '../../format';\nimport { devWarn } from '../../internal/dev';\nimport { I18N, tr } from '../../i18n';\nimport { kpiText, smoothPath, useCountUp, useFitText, type Point } from '../../internal/chart';\nimport { cx, digits } from '../../internal/util';\nimport { codeText } from '../InlineCode/InlineCode';\n\nexport interface KpiCardProps {\n /** What is measured: 「本月營收」. */\n label: string;\n /** The figure, as a number (counts up from 0 when it appears). */\n value: number;\n /** 'money' shows NT$ 1,280; 'percent' 1 decimal without the % sign: pass unit=\"%\" (same as DataTable). Default 'number'. */\n format?: 'number' | 'money' | 'percent';\n /** For money. Default: the locale's currency (TWD). */\n currency?: string;\n /** Abbreviate from 1 萬 (default true). The only place numbers are abbreviated. */\n compact?: boolean;\n /** Written after the number: 元, 人, ms, %. */\n unit?: string;\n /** Digits after the decimal point, for the figure and its change (delta). Default 0 for the figure, 1 with unit=\"%\"\n * (a percentage has 1 decimal); the change then keeps 1 (%) or 2 (pt). */\n decimals?: number;\n /** Change versus the comparison period. */\n delta?: number;\n /** '%' (default) or 'pt' for percentage points. */\n deltaUnit?: '%' | 'pt';\n /** Which way is better: 'up' (default; revenue, users) or 'down' (error rate, response time, cost). Sets good or bad from delta's sign. */\n direction?: 'up' | 'down';\n /** Overrides direction: whether this change is good (true) or bad (false), whatever its sign. */\n good?: boolean;\n /** Recent values for the sparkline. */\n spark?: number[];\n /** The comparison period after the change. Default 「較上週」. */\n compareLabel?: string;\n /** Its own class names. */\n className?: string;\n /** `compact`: a 22 px number for a top bar, no sparkline; with verdict and target below. Default 'default' (31 px). */\n size?: 'default' | 'compact';\n /** How the figure is judged, in words: 「預測準確」(success), 「偏差變大」(warning), 「需要校正」(danger). Shown only\n * when it is not success, in place of the target line and in its color; screen readers always hear it. `backticks` are code. */\n verdict?: { tone: 'success' | 'warning' | 'danger'; text: string };\n /** One gray line under the number, e.g. 「目標 ≤ 0.5 °C(示意)」; `backticks` are code. */\n target?: string;\n}\n\n/** Chinese in a figure (the 萬 and 億 of an abbreviated number) in the text font and drawn like the unit (smaller,\n * muted); Geist Mono stays on the digits. */\nfunction sansCjk(text: string): React.ReactNode[] {\n // The space before 萬 is the unit's margin (CSS), not a space as wide as a Geist Mono digit.\n return text.split(/\\s*([\\u2e80-\\u9fff\\uff00-\\uffef]+)/).map((t, i) =>\n i % 2 ? (\n <span key={i} className=\"ui-kpi-cjk\">\n {t}\n </span>\n ) : (\n t\n ),\n );\n}\n\n/** One figure with its change and a sparkline. It is a card: put several in a grid, not inside another Card. */\nexport function KpiCard(props: KpiCardProps) {\n const {\n label,\n value,\n unit,\n decimals = unit === '%' ? 1 : 0,\n delta,\n deltaUnit,\n direction = 'up',\n good,\n spark,\n compareLabel,\n size = 'default',\n verdict,\n target,\n className,\n } = props;\n const compact = size === 'compact';\n devWarn(compact && !!spark, 'KpiCard', 'size=\"compact\" draws no sparkline, so spark is ignored. Drop spark, or use the default size.');\n devWarn(props.format === 'percent' && !unit, 'KpiCard', 'format=\\'percent\\' shows the number only; pass unit=\"%\" for the smaller % after it.');\n const t = useCountUp(value, 900);\n const valRef = React.useRef<HTMLDivElement>(null);\n useFitText(valRef, [value, props.format, unit, decimals, props.compact, props.currency, I18N.locale]);\n const hasDelta = typeof delta === 'number';\n const up = hasDelta && delta > 0;\n const flat = hasDelta && delta === 0;\n // No change is neither good nor bad: no arrow, no word, muted.\n const isGood = good ?? (direction === 'down' ? hasDelta && delta < 0 : up);\n // The change follows decimals when it is given (decimals={1}: 「0.4 個百分點」, not 「0.40」).\n const dTxt = hasDelta\n ? deltaUnit === 'pt'\n ? tr('{n} 個百分點', { n: format.number(Math.abs(delta), props.decimals ?? 2) })\n : format.percent(Math.abs(delta), props.decimals ?? 1)\n : '';\n let sparkD: string | null = null;\n if (!compact && spark && spark.length > 1) {\n const mx = Math.max(...spark);\n const mn = Math.min(...spark);\n sparkD = smoothPath(spark.map((v, i): Point => [(i * 160) / (spark.length - 1), 32 - ((v - mn) / (mx - mn || 1)) * 28]));\n }\n const showUnit = unit && props.format !== 'money';\n return (\n <section className={cx('ui-kpi', compact && 'is-compact', className)}>\n <div className=\"ui-kpi-label\">{label}</div>\n <div ref={valRef} className=\"ui-kpi-value\">\n {/* The final figure for screen readers, as text (an aria-label on a div without a role is not read); the\n counting figure is hidden from them. */}\n <span className=\"ui-visually-hidden\">{kpiText(value, props, decimals) + (showUnit ? ' ' + unit : '')}</span>\n <span className=\"ui-kpi-num\" aria-hidden=\"true\">\n <span className=\"ui-kpi-sizer\">{sansCjk(kpiText(value, props, decimals))}</span>\n <span className=\"ui-kpi-live\">{sansCjk(kpiText(value * t, props, decimals))}</span>\n </span>\n {showUnit ? (\n <span className=\"ui-kpi-unit\" aria-hidden=\"true\">\n {unit}\n </span>\n ) : null}\n </div>\n {sparkD ? (\n <svg className=\"ui-kpi-spark\" width=\"100%\" height={36} viewBox=\"0 0 160 36\" preserveAspectRatio=\"none\" aria-hidden=\"true\">\n <path d={sparkD} fill=\"none\" stroke=\"var(--chart-1)\" strokeWidth={2} strokeLinecap=\"round\" vectorEffect=\"non-scaling-stroke\" />\n </svg>\n ) : null}\n {hasDelta ? (\n <div className=\"ui-kpi-delta\">\n <span className={cx('ui-kpi-change', flat ? 'is-flat' : isGood ? 'is-good' : 'is-bad')}>\n {flat ? '' : up ? '▲ ' : '▼ '}\n {digits(dTxt)}\n </span>\n {/* Good or bad is not only a colour (WCAG 1.4.1): the word follows the comparison period, muted. */}\n <span className=\"ui-kpi-note\">{(compareLabel || tr('較上週')) + (flat ? '' : isGood ? tr('(改善)') : tr('(變差)'))}</span>\n </div>\n ) : null}\n {verdict || target ? (\n verdict && verdict.tone !== 'success' ? (\n <div className={'ui-kpi-target ui-kpi-verdict is-' + verdict.tone}>\n {codeText(target ? tr('{v}({t})', { v: verdict.text, t: target }) : verdict.text)}\n </div>\n ) : (\n <div className=\"ui-kpi-target\">\n {verdict ? <span className=\"ui-visually-hidden\">{codeText(verdict.text + tr(','))}</span> : null}\n {codeText(target)}\n </div>\n )\n ) : null}\n </section>\n );\n}\n"],"mappings":";;;;;;;;;;;;AAiDA,SAAS,QAAQ,MAAiC;CAEhD,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AI,GAAG,MAAM;IAAS,CAAA,CAC/G;GACH,CAAA,IAAA;GACH,WAAW,SACV,WAAW,QAAQ,SAAS,YAC1B,oBAAC,OAAD;IAAK,WAAW,qCAAqC,QAAQ;IAC1D,UAAA,SAAS,SAAS,GAAG,YAAY;KAAE,GAAG,QAAQ;KAAM,GAAG;IAAO,CAAC,IAAI,QAAQ,IAAI;GAC7E,CAAA,IAEL,qBAAC,OAAD;IAAK,WAAU;IAAf,UAAA,CACG,UAAU,oBAAC,QAAD;KAAM,WAAU;KAAsB,UAAA,SAAS,QAAQ,OAAO,GAAG,GAAG,CAAC;IAAQ,CAAA,IAAI,MAC3F,SAAS,MAAM,CACb;GAEL,CAAA,IAAA;EACG;;AAEb"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { GraphLegend } from "../Graph/Graph.js";
|
|
3
|
-
import {
|
|
3
|
+
import { SegmentedControl } from "../SegmentedControl/SegmentedControl.js";
|
|
4
4
|
import { IconButton } from "../IconButton/IconButton.js";
|
|
5
5
|
import { Switch } from "../Switch/Switch.js";
|
|
6
6
|
import { tr } from "../../i18n.js";
|
|
@@ -1624,15 +1624,15 @@ function LayerGraph(props) {
|
|
|
1624
1624
|
children: tr("線上文字")
|
|
1625
1625
|
})]
|
|
1626
1626
|
}) : null,
|
|
1627
|
-
p.listView === false ? null : /* @__PURE__ */ jsx(
|
|
1627
|
+
p.listView === false ? null : /* @__PURE__ */ jsx(SegmentedControl, {
|
|
1628
1628
|
label: tr("顯示方式"),
|
|
1629
1629
|
value: view,
|
|
1630
1630
|
onChange: setView,
|
|
1631
|
-
|
|
1632
|
-
|
|
1631
|
+
options: [{
|
|
1632
|
+
value: "graph",
|
|
1633
1633
|
label: tr("圖")
|
|
1634
1634
|
}, {
|
|
1635
|
-
|
|
1635
|
+
value: "list",
|
|
1636
1636
|
label: tr("清單")
|
|
1637
1637
|
}]
|
|
1638
1638
|
})
|