@godxjp/ui 5.0.2 → 6.0.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/README.md +101 -142
- package/package.json +124 -128
- package/scripts/ui-audit.mjs +179 -0
- package/src/app/__tests__/app-provider.test.tsx +232 -0
- package/src/app/__tests__/date-format-labels.test.ts +36 -0
- package/src/app/__tests__/date-formats.test.ts +44 -0
- package/src/app/__tests__/timezones.test.ts +65 -0
- package/src/app/app-provider.tsx +227 -0
- package/src/app/date-format-labels.ts +21 -0
- package/src/app/date-formats.ts +30 -0
- package/src/app/index.ts +40 -0
- package/src/app/locales.ts +32 -0
- package/src/app/request-headers.ts +31 -0
- package/src/app/storage.ts +44 -0
- package/src/app/time-format-labels.ts +19 -0
- package/src/app/time-formats.ts +15 -0
- package/src/app/timezones.ts +208 -0
- package/src/app/types.ts +39 -0
- package/src/app/use-formatting.ts +47 -0
- package/src/components/__tests__/accessibility-primitives.test.tsx +65 -0
- package/src/components/__tests__/docs-parity.test.ts +41 -0
- package/src/components/__tests__/shadcn-release-guardrails.test.ts +71 -0
- package/src/components/__tests__/theme-axes-integration.test.tsx +242 -0
- package/src/components/admin/index.ts +76 -0
- package/src/components/data-display/__tests__/card-table.test.tsx +328 -0
- package/src/components/data-display/__tests__/data-display.test.tsx +73 -0
- package/src/components/data-display/__tests__/data-table.test.tsx +84 -0
- package/src/components/data-display/__tests__/popover.test.tsx +92 -0
- package/src/components/data-display/__tests__/scroll-area-collapsible.test.tsx +66 -0
- package/src/components/data-display/badge.tsx +27 -0
- package/src/components/data-display/card.tsx +194 -0
- package/src/components/data-display/code-badge.tsx +28 -0
- package/src/components/data-display/collapsible.tsx +5 -0
- package/src/components/data-display/data-table.tsx +476 -0
- package/src/components/data-display/empty-state.tsx +22 -0
- package/src/components/data-display/index.ts +41 -0
- package/src/components/data-display/key-value-grid.tsx +46 -0
- package/src/components/data-display/popover.tsx +62 -0
- package/src/components/data-display/progress-meter.tsx +20 -0
- package/src/components/data-display/scan-panel.tsx +16 -0
- package/src/components/data-display/scroll-area.tsx +42 -0
- package/src/components/data-display/status-badge.tsx +83 -0
- package/src/components/data-display/table.tsx +59 -0
- package/src/components/data-display/timeline.tsx +42 -0
- package/src/components/data-display/tree-list.tsx +42 -0
- package/src/components/data-entry/__fixtures__/tree-options.ts +80 -0
- package/src/components/data-entry/__tests__/cascader-tree-transfer.test.tsx +417 -0
- package/src/components/data-entry/__tests__/checkbox-group.test.tsx +40 -0
- package/src/components/data-entry/__tests__/checkbox.test.tsx +20 -0
- package/src/components/data-entry/__tests__/date-autocomplete.test.tsx +94 -0
- package/src/components/data-entry/__tests__/form-field.test.tsx +49 -0
- package/src/components/data-entry/__tests__/input-textarea.test.tsx +38 -0
- package/src/components/data-entry/__tests__/label-select.test.tsx +62 -0
- package/src/components/data-entry/__tests__/pickers.test.tsx +74 -0
- package/src/components/data-entry/__tests__/radio.test.tsx +46 -0
- package/src/components/data-entry/__tests__/search-input.test.tsx +32 -0
- package/src/components/data-entry/__tests__/switch-field.test.tsx +52 -0
- package/src/components/data-entry/__tests__/upload.test.tsx +125 -0
- package/src/components/data-entry/autocomplete.tsx +91 -0
- package/src/components/data-entry/calendar.tsx +90 -0
- package/src/components/data-entry/cascader.tsx +305 -0
- package/src/components/data-entry/checkbox-group.tsx +90 -0
- package/src/components/data-entry/checkbox.tsx +30 -0
- package/src/components/data-entry/choice-field.tsx +27 -0
- package/src/components/data-entry/choice-option.ts +20 -0
- package/src/components/data-entry/color-picker.tsx +75 -0
- package/src/components/data-entry/command.tsx +56 -0
- package/src/components/data-entry/country-select.tsx +88 -0
- package/src/components/data-entry/date-picker.tsx +69 -0
- package/src/components/data-entry/date-range-picker.tsx +75 -0
- package/src/components/data-entry/form-field.tsx +59 -0
- package/src/components/data-entry/index.ts +62 -0
- package/src/components/data-entry/input.tsx +26 -0
- package/src/components/data-entry/label.tsx +25 -0
- package/src/components/data-entry/radio.tsx +109 -0
- package/src/components/data-entry/search-input.tsx +103 -0
- package/src/components/data-entry/select.tsx +149 -0
- package/src/components/data-entry/slider.tsx +38 -0
- package/src/components/data-entry/switch-field.tsx +91 -0
- package/src/components/data-entry/switch.tsx +24 -0
- package/src/components/data-entry/textarea.tsx +12 -0
- package/src/components/data-entry/time-picker.tsx +214 -0
- package/src/components/data-entry/transfer.tsx +231 -0
- package/src/components/data-entry/tree-select-strategy.ts +6 -0
- package/src/components/data-entry/tree-select.tsx +279 -0
- package/src/components/data-entry/tree-utils.ts +221 -0
- package/src/components/data-entry/upload-crop-dialog.tsx +109 -0
- package/src/components/data-entry/upload-types.ts +86 -0
- package/src/components/data-entry/upload.tsx +498 -0
- package/src/components/data-entry/use-upload-draft.ts +93 -0
- package/src/components/feedback/__tests__/alert.test.tsx +127 -0
- package/src/components/feedback/__tests__/dialog.test.tsx +290 -0
- package/src/components/feedback/__tests__/sheet.test.tsx +94 -0
- package/src/components/feedback/__tests__/skeleton.test.tsx +25 -0
- package/src/components/feedback/__tests__/toast.test.tsx +52 -0
- package/src/components/feedback/alert.tsx +167 -0
- package/src/components/feedback/dialog.tsx +325 -0
- package/src/components/feedback/index.ts +53 -0
- package/src/components/feedback/sheet.tsx +130 -0
- package/src/components/feedback/skeleton.tsx +95 -0
- package/src/components/feedback/sonner.tsx +54 -0
- package/src/components/feedback/toaster.tsx +1 -0
- package/src/components/feedback/use-toast.ts +62 -0
- package/src/components/general/__tests__/button.test.tsx +71 -0
- package/src/components/general/button.tsx +61 -0
- package/src/components/general/index.ts +2 -0
- package/src/components/layout/__tests__/page-container.test.tsx +69 -0
- package/src/components/layout/__tests__/page-inset.test.tsx +14 -0
- package/src/components/layout/__tests__/stack-inline.test.tsx +39 -0
- package/src/components/layout/app-shell.tsx +42 -0
- package/src/components/layout/breadcrumb.tsx +35 -0
- package/src/components/layout/index.ts +31 -0
- package/src/components/layout/inline.tsx +13 -0
- package/src/components/layout/menu.tsx +34 -0
- package/src/components/layout/mobile-frame.tsx +57 -0
- package/src/components/layout/page-container.tsx +81 -0
- package/src/components/layout/page-inset.tsx +16 -0
- package/src/components/layout/responsive-grid.tsx +14 -0
- package/src/components/layout/shell-app.tsx +30 -0
- package/src/components/layout/sidebar.tsx +98 -0
- package/src/components/layout/split-pane.tsx +16 -0
- package/src/components/layout/stack.tsx +13 -0
- package/src/components/layout/topbar.tsx +108 -0
- package/src/components/navigation/__tests__/app-pickers.test.tsx +118 -0
- package/src/components/navigation/__tests__/dropdown-menu.test.tsx +104 -0
- package/src/components/navigation/__tests__/navigation.test.tsx +61 -0
- package/src/components/navigation/__tests__/pagination-steps-tabs.test.tsx +76 -0
- package/src/components/navigation/date-format-picker.tsx +55 -0
- package/src/components/navigation/dropdown-menu.tsx +190 -0
- package/src/components/navigation/filter-bar.tsx +38 -0
- package/src/components/navigation/index.ts +28 -0
- package/src/components/navigation/locale-picker.tsx +49 -0
- package/src/components/navigation/page-header.tsx +50 -0
- package/src/components/navigation/pagination-utils.ts +35 -0
- package/src/components/navigation/pagination.tsx +168 -0
- package/src/components/navigation/steps.tsx +163 -0
- package/src/components/navigation/tabs-items.tsx +69 -0
- package/src/components/navigation/tabs.tsx +67 -0
- package/src/components/navigation/time-format-picker.tsx +55 -0
- package/src/components/navigation/timezone-picker.tsx +63 -0
- package/src/components/query/__tests__/data-state.test.tsx +214 -0
- package/src/components/query/__tests__/infinite-prefetch.test.tsx +105 -0
- package/src/components/query/__tests__/query-helpers.test.tsx +61 -0
- package/src/components/query/data-state.tsx +58 -0
- package/src/components/query/index.ts +10 -0
- package/src/components/query/infinite-query-state.tsx +99 -0
- package/src/components/query/mutation-feedback.tsx +31 -0
- package/src/components/query/prefetch-link.tsx +45 -0
- package/src/components/query/query-refetch-button.tsx +41 -0
- package/src/components/ui/alert-dialog.tsx +1 -0
- package/src/components/ui/alert.tsx +1 -0
- package/src/components/ui/autocomplete.tsx +1 -0
- package/src/components/ui/badge.tsx +1 -0
- package/src/components/ui/button.tsx +1 -0
- package/src/components/ui/calendar.tsx +1 -0
- package/src/components/ui/card.tsx +1 -0
- package/src/components/ui/checkbox.tsx +1 -0
- package/src/components/ui/color-picker.tsx +1 -0
- package/src/components/ui/command.tsx +1 -0
- package/src/components/ui/date-picker.tsx +1 -0
- package/src/components/ui/date-range-picker.tsx +1 -0
- package/src/components/ui/dialog.tsx +1 -0
- package/src/components/ui/dropdown-menu.tsx +1 -0
- package/src/components/ui/index.tsx +31 -0
- package/src/components/ui/input.tsx +1 -0
- package/src/components/ui/label.tsx +1 -0
- package/src/components/ui/pagination.tsx +1 -0
- package/src/components/ui/popover.tsx +1 -0
- package/src/components/ui/radio.tsx +1 -0
- package/src/components/ui/scroll-area.tsx +1 -0
- package/src/components/ui/select.tsx +1 -0
- package/src/components/ui/sheet.tsx +1 -0
- package/src/components/ui/slider.tsx +1 -0
- package/src/components/ui/sonner.tsx +1 -0
- package/src/components/ui/switch.tsx +1 -0
- package/src/components/ui/table.tsx +1 -0
- package/src/components/ui/tabs-items.tsx +1 -0
- package/src/components/ui/tabs.tsx +1 -0
- package/src/components/ui/textarea.tsx +1 -0
- package/src/components/ui/time-picker.tsx +1 -0
- package/src/components/ui/upload.tsx +1 -0
- package/src/form/__tests__/use-zod-form.test.tsx +97 -0
- package/src/form/form-field-control.tsx +44 -0
- package/src/form/form-root.tsx +29 -0
- package/src/form/index.ts +7 -0
- package/src/form/use-zod-form.ts +29 -0
- package/src/i18n/__tests__/translate.test.ts +23 -0
- package/src/i18n/index.ts +9 -0
- package/src/i18n/messages/en.json +171 -0
- package/src/i18n/messages/ja.json +171 -0
- package/src/i18n/messages/vi.json +171 -0
- package/src/i18n/translate.ts +74 -0
- package/src/i18n/use-translation.ts +53 -0
- package/src/index.ts +3 -0
- package/src/lib/__tests__/control-styles.test.ts +78 -0
- package/src/lib/__tests__/datetime.test.ts +77 -0
- package/src/lib/__tests__/format-date.test.ts +97 -0
- package/src/lib/__tests__/format.test.ts +62 -0
- package/src/lib/__tests__/theme-tokens-audit.test.ts +176 -0
- package/src/lib/__tests__/theme-tokens-css.test.ts +118 -0
- package/src/lib/__tests__/token-governance.test.ts +191 -0
- package/src/lib/__tests__/variants.test.ts +18 -0
- package/src/lib/control-styles.ts +33 -0
- package/src/lib/datetime/detect.ts +25 -0
- package/src/lib/datetime/format-date.ts +100 -0
- package/src/lib/datetime/format.ts +140 -0
- package/src/lib/datetime/index.ts +25 -0
- package/src/lib/datetime/parse.ts +51 -0
- package/src/lib/datetime/sync.ts +48 -0
- package/src/lib/format.ts +114 -0
- package/src/lib/hooks.ts +54 -0
- package/src/lib/utils.ts +6 -0
- package/src/lib/variants.ts +40 -0
- package/src/props/components/app.prop.ts +99 -0
- package/src/props/components/data-display.prop.ts +73 -0
- package/src/props/components/data-entry.prop.ts +334 -0
- package/src/props/components/feedback.prop.ts +80 -0
- package/src/props/components/form.prop.ts +46 -0
- package/src/props/components/general.prop.ts +18 -0
- package/src/props/components/index.ts +99 -0
- package/src/props/components/layout.prop.ts +130 -0
- package/src/props/components/navigation.prop.ts +88 -0
- package/src/props/components/query.prop.ts +94 -0
- package/src/props/index.ts +17 -0
- package/src/props/registry.ts +603 -0
- package/src/props/vocabulary/content.prop.ts +35 -0
- package/src/props/vocabulary/data.prop.ts +46 -0
- package/src/props/vocabulary/index.ts +73 -0
- package/src/props/vocabulary/interaction.prop.ts +42 -0
- package/src/props/vocabulary/layout.prop.ts +25 -0
- package/src/props/vocabulary/navigation.prop.ts +19 -0
- package/src/props/vocabulary/shared.prop.ts +59 -0
- package/src/styles/alert-layout.css +191 -0
- package/src/styles/badge-layout.css +22 -0
- package/src/styles/card-layout.css +373 -0
- package/src/styles/control.css +504 -0
- package/src/styles/data-display-layout.css +246 -0
- package/src/styles/density.css +43 -0
- package/src/styles/dialog-layout.css +84 -0
- package/src/styles/index.css +105 -0
- package/src/styles/layout.css +479 -0
- package/src/styles/shell-layout.css +604 -0
- package/src/styles/table-layout.css +109 -0
- package/src/test/__tests__/render-loop-guard.test.tsx +38 -0
- package/src/test/jest-dom.d.ts +4 -0
- package/src/test/render-loop-guard.tsx +50 -0
- package/src/test/render.tsx +29 -0
- package/src/test/theme-globals.test.ts +77 -0
- package/src/test/theme-globals.ts +134 -0
- package/src/test/theme-test-utils.tsx +67 -0
- package/src/theme/example.service.css +37 -0
- package/src/tokens/base.css +13 -0
- package/src/tokens/foundation.css +151 -0
- package/src/tokens/primitives/badge.css +13 -0
- package/src/tokens/primitives/card.css +29 -0
- package/src/tokens/primitives/control.css +55 -0
- package/src/tokens/primitives/feedback.css +17 -0
- package/src/tokens/primitives/layout.css +20 -0
- package/src/tokens/primitives/navigation.css +13 -0
- package/src/tokens/primitives/table.css +10 -0
- package/BRAND.md +0 -296
- package/CHANGELOG.md +0 -668
- package/config/eslint.js +0 -54
- package/config/prettier.cjs +0 -20
- package/config/tsconfig.base.json +0 -22
- package/config/vitest.base.ts +0 -26
- package/dist/MiniMonth-YAmPGEpC.d.ts +0 -143
- package/dist/Table.types-BbsxoIYE.d.ts +0 -352
- package/dist/color-DO0qqUAb.d.ts +0 -38
- package/dist/components/composites.d.ts +0 -963
- package/dist/components/composites.js +0 -7343
- package/dist/components/composites.js.map +0 -1
- package/dist/components/primitives.d.ts +0 -2744
- package/dist/components/primitives.js +0 -7356
- package/dist/components/primitives.js.map +0 -1
- package/dist/components/shell.d.ts +0 -182
- package/dist/components/shell.js +0 -774
- package/dist/components/shell.js.map +0 -1
- package/dist/hooks.d.ts +0 -100
- package/dist/hooks.js +0 -558
- package/dist/hooks.js.map +0 -1
- package/dist/i18n.d.ts +0 -61
- package/dist/i18n.js +0 -860
- package/dist/i18n.js.map +0 -1
- package/dist/index.d.ts +0 -33
- package/dist/index.js +0 -13062
- package/dist/index.js.map +0 -1
- package/dist/padding-DY0JV5Ja.d.ts +0 -16
- package/dist/preferences.d.ts +0 -132
- package/dist/preferences.js +0 -262
- package/dist/preferences.js.map +0 -1
- package/dist/props.d.ts +0 -86
- package/dist/props.js +0 -16
- package/dist/props.js.map +0 -1
- package/dist/size-CQwNvOWd.d.ts +0 -19
- package/dist/types-LTj-2bl-.d.ts +0 -30
- package/dist/useTableViews-D5NIAJ7h.d.ts +0 -154
- package/src/tokens/tailwind.css +0 -158
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* godxjp-ui audit — the design system's own linter for consumer UI code.
|
|
4
|
+
*
|
|
5
|
+
* Enforces the UI-standardization rules that ship with @godxjp/ui
|
|
6
|
+
* (see the app's .claude/skills/frontend-design/rules/ui-standardization.md):
|
|
7
|
+
* use the design system, never hand-roll. Inspired by `@google/design.md lint`
|
|
8
|
+
* — structured, agent-readable findings.
|
|
9
|
+
*
|
|
10
|
+
* Runs from the CONSUMER's repo root and scans its hand-written UI
|
|
11
|
+
* (components / pages / layouts) — never the framework or generated code.
|
|
12
|
+
*
|
|
13
|
+
* Usage (from the consuming app):
|
|
14
|
+
* node packages/godx-ui/scripts/ui-audit.mjs # human report; exit 1 on error
|
|
15
|
+
* node packages/godx-ui/scripts/ui-audit.mjs --format json
|
|
16
|
+
* node packages/godx-ui/scripts/ui-audit.mjs --quiet # errors only
|
|
17
|
+
* node packages/godx-ui/scripts/ui-audit.mjs src/ui lib/ # custom scan dirs
|
|
18
|
+
*/
|
|
19
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
20
|
+
import { join, relative } from "node:path";
|
|
21
|
+
|
|
22
|
+
const CWD = process.cwd();
|
|
23
|
+
const args = process.argv.slice(2);
|
|
24
|
+
const asJson = args.includes("--format") && args[args.indexOf("--format") + 1] === "json";
|
|
25
|
+
const quiet = args.includes("--quiet");
|
|
26
|
+
const dirArgs = args.filter((a) => !a.startsWith("--") && a !== "json");
|
|
27
|
+
const SCAN_DIRS = dirArgs.length
|
|
28
|
+
? dirArgs
|
|
29
|
+
: ["resources/js/components", "resources/js/pages", "resources/js/layouts"];
|
|
30
|
+
|
|
31
|
+
const PALETTE =
|
|
32
|
+
"red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose|gray|grey|slate|zinc|neutral|stone";
|
|
33
|
+
|
|
34
|
+
/** @type {{id:string, severity:'error'|'warn', test:RegExp, message:string}[]} */
|
|
35
|
+
const RULES = [
|
|
36
|
+
{
|
|
37
|
+
id: "no-space-xy",
|
|
38
|
+
severity: "error",
|
|
39
|
+
test: /\bspace-[xy]-\d/,
|
|
40
|
+
message: "Use <Stack>/<Inline> with gap, not space-x/y-* (rules §5).",
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: "no-raw-palette-color",
|
|
44
|
+
severity: "error",
|
|
45
|
+
test: new RegExp(
|
|
46
|
+
`\\b(bg|text|border|ring|fill|stroke|from|to|via|divide|outline)-(${PALETTE})-\\d`,
|
|
47
|
+
),
|
|
48
|
+
message:
|
|
49
|
+
"Use semantic tokens (bg-primary, text-muted-foreground…), not raw palette colors (rules §4).",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "no-arbitrary-hex",
|
|
53
|
+
severity: "error",
|
|
54
|
+
test: /(bg|text|border|ring|fill|stroke|from|to|via)-\[#[0-9a-fA-F]{3,8}\]/,
|
|
55
|
+
message: "No hardcoded hex colors in className; use design-system tokens (rules §4).",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: "no-raw-select",
|
|
59
|
+
severity: "error",
|
|
60
|
+
test: /<select[\s>]/,
|
|
61
|
+
message: "Use <Select> from @godxjp/ui, not a raw <select> (rules §3).",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "no-raw-table",
|
|
65
|
+
severity: "error",
|
|
66
|
+
test: /<table[\s>]/,
|
|
67
|
+
message: "Use the <Table> family from @godxjp/ui, not a raw <table> (rules §3).",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "no-raw-textarea",
|
|
71
|
+
severity: "warn",
|
|
72
|
+
test: /<textarea[\s>]/,
|
|
73
|
+
message: "Use <Textarea> from @godxjp/ui, not a raw <textarea> (rules §3).",
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
id: "no-dark-color-override",
|
|
77
|
+
severity: "warn",
|
|
78
|
+
test: /\bdark:(bg|text|border|ring|fill|stroke)-/,
|
|
79
|
+
message: "Don't add dark: color overrides — semantic tokens already adapt (rules §4).",
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
id: "manual-field-error",
|
|
83
|
+
severity: "warn",
|
|
84
|
+
test: /<p[^>]*className="[^"]*text-(xs|sm)[^"]*text-destructive/,
|
|
85
|
+
message:
|
|
86
|
+
"Field errors should use <FormField error=…>, not a hand-rolled <p> (rules §1). OK only for checkbox/radio groups.",
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
id: "manual-field-helper",
|
|
90
|
+
severity: "warn",
|
|
91
|
+
test: /<p[^>]*className="text-xs text-muted-foreground"/,
|
|
92
|
+
message:
|
|
93
|
+
"Field helper text should use <FormField helper=…>, not a hand-rolled <p> (rules §1). OK only for checkbox/radio groups.",
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: "raw-white-black",
|
|
97
|
+
severity: "warn",
|
|
98
|
+
test: /\b(bg|text|border)-(white|black)\b/,
|
|
99
|
+
message:
|
|
100
|
+
"Prefer semantic tokens (text-primary-foreground, bg-background…) over raw white/black (rules §4).",
|
|
101
|
+
},
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
function walk(dir, acc = []) {
|
|
105
|
+
let entries;
|
|
106
|
+
try {
|
|
107
|
+
entries = readdirSync(dir);
|
|
108
|
+
} catch {
|
|
109
|
+
return acc;
|
|
110
|
+
}
|
|
111
|
+
for (const name of entries) {
|
|
112
|
+
const full = join(dir, name);
|
|
113
|
+
const st = statSync(full);
|
|
114
|
+
if (st.isDirectory()) {
|
|
115
|
+
walk(full, acc);
|
|
116
|
+
} else if (name.endsWith(".tsx") || name.endsWith(".ts")) {
|
|
117
|
+
acc.push(full);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return acc;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const findings = [];
|
|
124
|
+
for (const dir of SCAN_DIRS) {
|
|
125
|
+
for (const file of walk(join(CWD, dir))) {
|
|
126
|
+
const rel = relative(CWD, file);
|
|
127
|
+
const lines = readFileSync(file, "utf8").split("\n");
|
|
128
|
+
lines.forEach((line, i) => {
|
|
129
|
+
for (const rule of RULES) {
|
|
130
|
+
if (rule.test.test(line)) {
|
|
131
|
+
findings.push({
|
|
132
|
+
file: rel,
|
|
133
|
+
line: i + 1,
|
|
134
|
+
rule: rule.id,
|
|
135
|
+
severity: rule.severity,
|
|
136
|
+
message: rule.message,
|
|
137
|
+
snippet: line.trim().slice(0, 120),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const errors = findings.filter((f) => f.severity === "error");
|
|
146
|
+
const warnings = findings.filter((f) => f.severity === "warn");
|
|
147
|
+
|
|
148
|
+
if (asJson) {
|
|
149
|
+
process.stdout.write(
|
|
150
|
+
JSON.stringify(
|
|
151
|
+
{ summary: { errors: errors.length, warnings: warnings.length }, findings },
|
|
152
|
+
null,
|
|
153
|
+
2,
|
|
154
|
+
) + "\n",
|
|
155
|
+
);
|
|
156
|
+
} else {
|
|
157
|
+
const C = {
|
|
158
|
+
red: "\x1b[31m",
|
|
159
|
+
yellow: "\x1b[33m",
|
|
160
|
+
dim: "\x1b[2m",
|
|
161
|
+
bold: "\x1b[1m",
|
|
162
|
+
reset: "\x1b[0m",
|
|
163
|
+
};
|
|
164
|
+
const shown = quiet ? errors : findings;
|
|
165
|
+
for (const f of shown) {
|
|
166
|
+
const tag = f.severity === "error" ? `${C.red}error${C.reset}` : `${C.yellow}warn ${C.reset}`;
|
|
167
|
+
console.log(`${tag} ${C.bold}${f.file}:${f.line}${C.reset} ${C.dim}[${f.rule}]${C.reset}`);
|
|
168
|
+
console.log(` ${f.message}`);
|
|
169
|
+
console.log(` ${C.dim}${f.snippet}${C.reset}`);
|
|
170
|
+
}
|
|
171
|
+
console.log(
|
|
172
|
+
`\ngodxjp-ui audit: ${C.red}${errors.length} error(s)${C.reset}, ${C.yellow}${warnings.length} warning(s)${C.reset} across ${SCAN_DIRS.join(", ")}.`,
|
|
173
|
+
);
|
|
174
|
+
if (errors.length === 0 && warnings.length === 0) {
|
|
175
|
+
console.log("✓ No UI-standardization violations found.");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
process.exit(errors.length > 0 ? 1 : 0);
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
|
|
2
|
+
import { renderHook, act } from "@testing-library/react";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { AppProvider, useAppContext } from "../app-provider";
|
|
5
|
+
import { getAppRequestHeaders, resetAppRequestHeaders } from "../request-headers";
|
|
6
|
+
import { resetI18nLocale } from "../../i18n/translate";
|
|
7
|
+
import { readStoredPreferences, writeStoredPreferences } from "../storage";
|
|
8
|
+
|
|
9
|
+
const STORAGE_KEY = "godxjp.app.test";
|
|
10
|
+
|
|
11
|
+
function wrapper(props: React.PropsWithChildren<{ persist?: boolean }>) {
|
|
12
|
+
return (
|
|
13
|
+
<AppProvider
|
|
14
|
+
storageKey={STORAGE_KEY}
|
|
15
|
+
persist={props.persist ?? false}
|
|
16
|
+
defaultLocale="vi"
|
|
17
|
+
fallbackLocale="en"
|
|
18
|
+
defaultTimezone="Asia/Tokyo"
|
|
19
|
+
>
|
|
20
|
+
{props.children}
|
|
21
|
+
</AppProvider>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe("AppProvider", () => {
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
resetAppRequestHeaders();
|
|
28
|
+
resetI18nLocale();
|
|
29
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("initializes locale and timezone and syncs request headers", () => {
|
|
37
|
+
const { result } = renderHook(() => useAppContext(), {
|
|
38
|
+
wrapper: ({ children }) => wrapper({ children }),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
expect(result.current.locale).toBe("vi");
|
|
42
|
+
expect(result.current.timezone).toBe("Asia/Tokyo");
|
|
43
|
+
expect(getAppRequestHeaders()).toEqual({
|
|
44
|
+
"x-locale": "vi",
|
|
45
|
+
"x-timezone": "Asia/Tokyo",
|
|
46
|
+
"x-time-format": "24h",
|
|
47
|
+
"x-date-format": "dmy",
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("updates headers when locale and timezone change", () => {
|
|
52
|
+
const { result } = renderHook(() => useAppContext(), {
|
|
53
|
+
wrapper: ({ children }) => wrapper({ children }),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
act(() => {
|
|
57
|
+
result.current.setLocale("ja");
|
|
58
|
+
result.current.setTimezone("Asia/Ho_Chi_Minh");
|
|
59
|
+
result.current.setTimeFormat("12h");
|
|
60
|
+
result.current.setDateFormat("iso");
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(result.current.requestHeaders).toEqual({
|
|
64
|
+
"x-locale": "ja",
|
|
65
|
+
"x-timezone": "Asia/Ho_Chi_Minh",
|
|
66
|
+
"x-time-format": "12h",
|
|
67
|
+
"x-date-format": "iso",
|
|
68
|
+
});
|
|
69
|
+
expect(getAppRequestHeaders()["x-locale"]).toBe("ja");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("persists preferences to localStorage", () => {
|
|
73
|
+
const { result } = renderHook(() => useAppContext(), {
|
|
74
|
+
wrapper: ({ children }) => wrapper({ children, persist: true }),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
act(() => {
|
|
78
|
+
result.current.setLocale("en");
|
|
79
|
+
result.current.setTimezone("UTC");
|
|
80
|
+
result.current.setTimeFormat("12h");
|
|
81
|
+
result.current.setDateFormat("mdy");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
expect(readStoredPreferences(STORAGE_KEY)).toEqual({
|
|
85
|
+
locale: "en",
|
|
86
|
+
timezone: "UTC",
|
|
87
|
+
timeFormat: "12h",
|
|
88
|
+
dateFormat: "mdy",
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("restores persisted preferences on mount", () => {
|
|
93
|
+
writeStoredPreferences(STORAGE_KEY, {
|
|
94
|
+
locale: "ja",
|
|
95
|
+
timezone: "Asia/Singapore",
|
|
96
|
+
timeFormat: "12h",
|
|
97
|
+
dateFormat: "iso",
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const { result } = renderHook(() => useAppContext(), {
|
|
101
|
+
wrapper: ({ children }) => wrapper({ children, persist: true }),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
expect(result.current.locale).toBe("ja");
|
|
105
|
+
expect(result.current.timezone).toBe("Asia/Singapore");
|
|
106
|
+
expect(result.current.timeFormat).toBe("12h");
|
|
107
|
+
expect(result.current.dateFormat).toBe("iso");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("calls onLocaleChange and onTimezoneChange", () => {
|
|
111
|
+
const onLocaleChange = vi.fn();
|
|
112
|
+
const onTimezoneChange = vi.fn();
|
|
113
|
+
|
|
114
|
+
const { result } = renderHook(() => useAppContext(), {
|
|
115
|
+
wrapper: ({ children }) => (
|
|
116
|
+
<AppProvider
|
|
117
|
+
storageKey={STORAGE_KEY}
|
|
118
|
+
persist={false}
|
|
119
|
+
onLocaleChange={onLocaleChange}
|
|
120
|
+
onTimezoneChange={onTimezoneChange}
|
|
121
|
+
>
|
|
122
|
+
{children}
|
|
123
|
+
</AppProvider>
|
|
124
|
+
),
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
act(() => {
|
|
128
|
+
result.current.setLocale("en");
|
|
129
|
+
result.current.setTimezone("UTC");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
expect(onLocaleChange).toHaveBeenCalledWith("en");
|
|
133
|
+
expect(onTimezoneChange).toHaveBeenCalledWith("UTC");
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("derives default time format from locale when defaultTimeFormat is locale", () => {
|
|
137
|
+
const { result: enResult } = renderHook(() => useAppContext(), {
|
|
138
|
+
wrapper: ({ children }) => (
|
|
139
|
+
<AppProvider storageKey={STORAGE_KEY} persist={false} defaultLocale="en">
|
|
140
|
+
{children}
|
|
141
|
+
</AppProvider>
|
|
142
|
+
),
|
|
143
|
+
});
|
|
144
|
+
expect(enResult.current.timeFormat).toBe("12h");
|
|
145
|
+
|
|
146
|
+
const { result: viResult } = renderHook(() => useAppContext(), {
|
|
147
|
+
wrapper: ({ children }) => (
|
|
148
|
+
<AppProvider storageKey={STORAGE_KEY} persist={false} defaultLocale="vi">
|
|
149
|
+
{children}
|
|
150
|
+
</AppProvider>
|
|
151
|
+
),
|
|
152
|
+
});
|
|
153
|
+
expect(viResult.current.timeFormat).toBe("24h");
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("derives default date format from locale when defaultDateFormat is locale", () => {
|
|
157
|
+
const { result: enResult } = renderHook(() => useAppContext(), {
|
|
158
|
+
wrapper: ({ children }) => (
|
|
159
|
+
<AppProvider storageKey={STORAGE_KEY} persist={false} defaultLocale="en">
|
|
160
|
+
{children}
|
|
161
|
+
</AppProvider>
|
|
162
|
+
),
|
|
163
|
+
});
|
|
164
|
+
expect(enResult.current.dateFormat).toBe("mdy");
|
|
165
|
+
|
|
166
|
+
const { result: viResult } = renderHook(() => useAppContext(), {
|
|
167
|
+
wrapper: ({ children }) => (
|
|
168
|
+
<AppProvider storageKey={STORAGE_KEY} persist={false} defaultLocale="vi">
|
|
169
|
+
{children}
|
|
170
|
+
</AppProvider>
|
|
171
|
+
),
|
|
172
|
+
});
|
|
173
|
+
expect(viResult.current.dateFormat).toBe("dmy");
|
|
174
|
+
|
|
175
|
+
const { result: jaResult } = renderHook(() => useAppContext(), {
|
|
176
|
+
wrapper: ({ children }) => (
|
|
177
|
+
<AppProvider storageKey={STORAGE_KEY} persist={false} defaultLocale="ja">
|
|
178
|
+
{children}
|
|
179
|
+
</AppProvider>
|
|
180
|
+
),
|
|
181
|
+
});
|
|
182
|
+
expect(jaResult.current.dateFormat).toBe("iso");
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("throws outside AppProvider", () => {
|
|
186
|
+
expect(() => renderHook(() => useAppContext())).toThrow(/AppProvider/);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("exposes timezoneOptions on context when configured", () => {
|
|
190
|
+
const zones = ["Asia/Tokyo", "Asia/Ho_Chi_Minh"] as const;
|
|
191
|
+
const { result } = renderHook(() => useAppContext(), {
|
|
192
|
+
wrapper: ({ children }) => (
|
|
193
|
+
<AppProvider storageKey={STORAGE_KEY} persist={false} timezoneOptions={zones}>
|
|
194
|
+
{children}
|
|
195
|
+
</AppProvider>
|
|
196
|
+
),
|
|
197
|
+
});
|
|
198
|
+
expect(result.current.timezoneOptions).toEqual(zones);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("timezoneOptions undefined means full IANA list in picker", () => {
|
|
202
|
+
const { result } = renderHook(() => useAppContext(), {
|
|
203
|
+
wrapper: ({ children }) => (
|
|
204
|
+
<AppProvider storageKey={STORAGE_KEY} persist={false}>
|
|
205
|
+
{children}
|
|
206
|
+
</AppProvider>
|
|
207
|
+
),
|
|
208
|
+
});
|
|
209
|
+
expect(result.current.timezoneOptions).toBeUndefined();
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("calls onDateFormatChange when date format updates", () => {
|
|
213
|
+
const onDateFormatChange = vi.fn();
|
|
214
|
+
const { result } = renderHook(() => useAppContext(), {
|
|
215
|
+
wrapper: ({ children }) => (
|
|
216
|
+
<AppProvider
|
|
217
|
+
storageKey={STORAGE_KEY}
|
|
218
|
+
persist={false}
|
|
219
|
+
onDateFormatChange={onDateFormatChange}
|
|
220
|
+
>
|
|
221
|
+
{children}
|
|
222
|
+
</AppProvider>
|
|
223
|
+
),
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
act(() => {
|
|
227
|
+
result.current.setDateFormat("iso");
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
expect(onDateFormatChange).toHaveBeenCalledWith("iso");
|
|
231
|
+
});
|
|
232
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
APP_DATE_FORMAT_OPTIONS,
|
|
4
|
+
getDateFormatLabel,
|
|
5
|
+
resolveDefaultDateFormat,
|
|
6
|
+
} from "../date-format-labels";
|
|
7
|
+
|
|
8
|
+
describe("date-format-labels", () => {
|
|
9
|
+
describe("resolveDefaultDateFormat", () => {
|
|
10
|
+
it.each([
|
|
11
|
+
["vi", "dmy"],
|
|
12
|
+
["ja", "iso"],
|
|
13
|
+
["en", "mdy"],
|
|
14
|
+
] as const)("locale %s → %s", (locale, expected) => {
|
|
15
|
+
expect(resolveDefaultDateFormat(locale)).toBe(expected);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe("getDateFormatLabel", () => {
|
|
20
|
+
it("returns Vietnamese label for dmy", () => {
|
|
21
|
+
expect(getDateFormatLabel("dmy", "vi", "en")).toMatch(/Ngày|Tháng|Năm/);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("returns Japanese ISO label", () => {
|
|
25
|
+
expect(getDateFormatLabel("iso", "ja", "en")).toMatch(/YYYY-MM-DD/);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("returns English label when locale is en", () => {
|
|
29
|
+
expect(getDateFormatLabel("mdy", "en", "vi")).toMatch(/Month|Day|Year/i);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("exports option list for pickers", () => {
|
|
34
|
+
expect(APP_DATE_FORMAT_OPTIONS.map((o) => o.value)).toEqual(["iso", "dmy", "mdy"]);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
APP_DATE_FORMATS,
|
|
4
|
+
getDatePattern,
|
|
5
|
+
getDateTimePattern,
|
|
6
|
+
isAppDateFormat,
|
|
7
|
+
} from "../date-formats";
|
|
8
|
+
|
|
9
|
+
describe("date-formats", () => {
|
|
10
|
+
describe("getDatePattern", () => {
|
|
11
|
+
it.each([
|
|
12
|
+
["iso", "yyyy-MM-dd"],
|
|
13
|
+
["dmy", "dd/MM/yyyy"],
|
|
14
|
+
["mdy", "MM/dd/yyyy"],
|
|
15
|
+
] as const)("maps %s → %s", (format, pattern) => {
|
|
16
|
+
expect(getDatePattern(format)).toBe(pattern);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
describe("getDateTimePattern", () => {
|
|
21
|
+
it("combines date pattern + 24h time", () => {
|
|
22
|
+
expect(getDateTimePattern("24h", "iso")).toBe("yyyy-MM-dd HH:mm");
|
|
23
|
+
expect(getDateTimePattern("24h", "dmy")).toBe("dd/MM/yyyy HH:mm");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("combines date pattern + 12h time", () => {
|
|
27
|
+
expect(getDateTimePattern("12h", "mdy")).toBe("MM/dd/yyyy h:mm a");
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("isAppDateFormat", () => {
|
|
32
|
+
it("accepts known presets", () => {
|
|
33
|
+
for (const format of APP_DATE_FORMATS) {
|
|
34
|
+
expect(isAppDateFormat(format)).toBe(true);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("rejects unknown values", () => {
|
|
39
|
+
expect(isAppDateFormat("ymd")).toBe(false);
|
|
40
|
+
expect(isAppDateFormat(null)).toBe(false);
|
|
41
|
+
expect(isAppDateFormat("")).toBe(false);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
APP_TIMEZONE_PRESET,
|
|
4
|
+
formatTimezoneDisplayLabel,
|
|
5
|
+
getAllIanaTimezones,
|
|
6
|
+
getTimezoneLabel,
|
|
7
|
+
getTimezoneOffsetLabel,
|
|
8
|
+
isValidIanaTimezone,
|
|
9
|
+
resolveTimezonePickerOptions,
|
|
10
|
+
} from "../timezones";
|
|
11
|
+
|
|
12
|
+
describe("timezones", () => {
|
|
13
|
+
it("exposes full IANA list by default", () => {
|
|
14
|
+
const all = getAllIanaTimezones();
|
|
15
|
+
expect(all.length).toBeGreaterThan(100);
|
|
16
|
+
expect(all).toContain("Asia/Ho_Chi_Minh");
|
|
17
|
+
expect(all).toContain("Asia/Tokyo");
|
|
18
|
+
expect(all).toContain("Europe/Paris");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("preset covers cross-border hubs", () => {
|
|
22
|
+
expect(APP_TIMEZONE_PRESET).toContain("Asia/Ho_Chi_Minh");
|
|
23
|
+
expect(APP_TIMEZONE_PRESET).toContain("Australia/Sydney");
|
|
24
|
+
expect(APP_TIMEZONE_PRESET.length).toBeGreaterThanOrEqual(40);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("resolveTimezonePickerOptions uses full list when unconfigured", () => {
|
|
28
|
+
const options = resolveTimezonePickerOptions(undefined, "Asia/Tokyo");
|
|
29
|
+
expect(options.length).toBeGreaterThan(100);
|
|
30
|
+
expect(options).toContain("Asia/Tokyo");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("resolveTimezonePickerOptions respects AppProvider config", () => {
|
|
34
|
+
const configured = ["Asia/Tokyo", "Asia/Ho_Chi_Minh"] as const;
|
|
35
|
+
const options = resolveTimezonePickerOptions(configured, "Asia/Tokyo");
|
|
36
|
+
expect(options).toEqual(["Asia/Tokyo", "Asia/Ho_Chi_Minh"]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("prepends current timezone when missing from configured list", () => {
|
|
40
|
+
const options = resolveTimezonePickerOptions(["Asia/Tokyo"], "Europe/Paris");
|
|
41
|
+
expect(options[0]).toBe("Europe/Paris");
|
|
42
|
+
expect(options).toContain("Asia/Tokyo");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("uses i18n label for curated zones", () => {
|
|
46
|
+
expect(getTimezoneLabel("Asia/Ho_Chi_Minh", "vi", "en")).toBe("Việt Nam (HCM)");
|
|
47
|
+
expect(getTimezoneLabel("Asia/Tokyo", "ja", "en")).toMatch(/日本|Tokyo/);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("falls back to city + UTC offset for zones without i18n", () => {
|
|
51
|
+
const label = getTimezoneLabel("Europe/Paris", "en", "en");
|
|
52
|
+
expect(label).toMatch(/Paris/);
|
|
53
|
+
expect(label).toMatch(/GMT|UTC|[+-]\d/);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("formats offset via Intl", () => {
|
|
57
|
+
expect(getTimezoneOffsetLabel("Asia/Ho_Chi_Minh", "en")).toMatch(/GMT|UTC|[+-]\d/);
|
|
58
|
+
expect(formatTimezoneDisplayLabel("Asia/Ho_Chi_Minh", "en")).toMatch(/Ho Chi Minh/);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("validates IANA ids against full list", () => {
|
|
62
|
+
expect(isValidIanaTimezone("Asia/Jakarta")).toBe(true);
|
|
63
|
+
expect(isValidIanaTimezone("Not/A/Zone")).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
});
|