@behavioral-agentic-design-system/core 0.42.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/package.json +38 -8
- package/scripts/a11y-lint.cjs +101 -14
- package/scripts/bads-sync.mjs +1 -1
- package/scripts/build-tokens.cjs +122 -7
- package/scripts/check-dark-contrast.mjs +204 -0
- package/scripts/check-flush-edges.mjs +245 -0
- package/scripts/check-spec.mjs +73 -0
- package/scripts/deal-directions.mjs +186 -0
- package/scripts/design-system-advisory/README.md +239 -0
- package/scripts/design-system-advisory/check-copy-punctuation.mjs +44 -0
- package/scripts/design-system-advisory/check-even-padding.mjs +35 -0
- package/scripts/design-system-advisory/check-hand-built-button.mjs +46 -0
- package/scripts/design-system-advisory/check-html-nesting.mjs +51 -0
- package/scripts/design-system-advisory/check-icon-sizing.mjs +79 -0
- package/scripts/design-system-advisory/check-label-case.mjs +92 -0
- package/scripts/design-system-advisory/check-native-form-controls.mjs +53 -0
- package/scripts/design-system-advisory/check-radius.mjs +56 -0
- package/scripts/design-system-advisory/check-raw-values.mjs +61 -0
- package/scripts/design-system-advisory/check-small-text.mjs +72 -0
- package/scripts/design-system-advisory/check-tap-target.mjs +70 -0
- package/scripts/design-system-advisory/defaults.mjs +90 -0
- package/scripts/design-system-advisory/fixtures/clean.tsx.fixture +12 -0
- package/scripts/design-system-advisory/fixtures/violations.tsx.fixture +19 -0
- package/scripts/design-system-advisory/lib.mjs +255 -0
- package/scripts/design-system-advisory/run.mjs +189 -0
- package/scripts/design-system-advisory/workflow.yml +82 -0
- package/scripts/health-report.mjs +20 -14
- package/scripts/lib/copy-strings.mjs +146 -0
- package/scripts/lib/counted-lint.mjs +100 -0
- package/scripts/lib/dark-contrast.mjs +120 -0
- package/scripts/lib/flush-edges.mjs +294 -0
- package/scripts/lib/lab-lint.mjs +62 -0
- package/scripts/lib/marketing-library.mjs +129 -0
- package/scripts/lib/mount-page.mjs +25 -0
- package/scripts/lib/on-system.mjs +249 -0
- package/scripts/lib/random.mjs +22 -0
- package/scripts/lib/source-scan.mjs +173 -0
- package/scripts/lib/spec-parse.d.mts +25 -0
- package/scripts/lib/spec-parse.mjs +188 -0
- package/scripts/lib/tells.mjs +366 -0
- package/scripts/lint-arbitrary-tokens.mjs +47 -0
- package/scripts/lint-component-token-refs.mjs +63 -0
- package/scripts/lint-content-hierarchy.mjs +114 -0
- package/scripts/lint-control-baseline.mjs +72 -0
- package/scripts/lint-copy-punctuation.mjs +60 -0
- package/scripts/lint-css-vars.mjs +175 -0
- package/scripts/lint-even-padding.mjs +58 -0
- package/scripts/lint-html-nesting.mjs +116 -0
- package/scripts/lint-label-case.mjs +219 -0
- package/scripts/lint-live-ctas.mjs +138 -0
- package/scripts/lint-microanimation.mjs +2 -2
- package/scripts/lint-proximity.mjs +181 -0
- package/scripts/lint-slop.mjs +1 -1
- package/scripts/lint-spacing-scale.mjs +78 -0
- package/scripts/lint-target-size.cjs +132 -0
- package/scripts/lint-token-primitives.mjs +307 -0
- package/scripts/on-system-score.mjs +95 -0
- package/scripts/size-audit.cjs +2 -2
- package/scripts/slop-rules.mjs +1 -1
- package/scripts/source-images.mjs +180 -0
- package/scripts/ux-tells.mjs +80 -0
- package/scripts/wcag-audit.cjs +25 -4
- package/src/api/brand-colors.ts +3 -0
- package/src/api/brand-fonts.ts +3 -0
- package/src/api/brand-mark.ts +6 -1
- package/src/api/dev-write-guard.ts +53 -0
- package/src/api/layers/file.ts +9 -4
- package/src/api/onboarding-extract.ts +85 -30
- package/src/api/onboarding.ts +3 -0
- package/src/api/save-tokens.ts +3 -0
- package/src/api/site-auth.ts +14 -2
- package/src/app/layout.tsx +6 -0
- package/src/app/preview/canvas/page.tsx +12 -0
- package/src/app/preview/components/page.tsx +828 -14
- package/src/app/preview/sticker-sheet/page.tsx +329 -0
- package/src/app/preview/sticker-sheet/specimens.tsx +296 -0
- package/src/app/preview/studio/blank-screen.tsx +143 -0
- package/src/app/preview/studio/page.tsx +7 -0
- package/src/app/shell.tsx +164 -47
- package/src/components/Foundations/Colors.stories.tsx +119 -8
- package/src/components/canvas/canvas.tsx +458 -0
- package/src/components/canvas/layout.ts +72 -0
- package/src/components/canvas/parse-canvas.ts +32 -0
- package/src/components/canvas/sample.ts +90 -0
- package/src/components/canvas/spec-frame.tsx +43 -0
- package/src/components/canvas/types.ts +33 -0
- package/src/components/docs-tab.tsx +7 -7
- package/src/components/home-recent.tsx +73 -0
- package/src/components/home-tab.tsx +19 -14
- package/src/components/layers-tab.tsx +2 -2
- package/src/components/markdown-preview.tsx +60 -12
- package/src/components/onboarding-wizard.tsx +1 -1
- package/src/components/studio/control-panel.tsx +299 -0
- package/src/components/studio/control-row.tsx +77 -0
- package/src/components/studio/preview-frame.tsx +165 -0
- package/src/components/studio/preview-pane.tsx +247 -0
- package/src/components/studio/studio.tsx +133 -128
- package/src/components/studio/types.ts +218 -0
- package/src/components/studio/use-studio-tweaks.ts +128 -0
- package/src/components/studio/use-studio-view-state.ts +72 -0
- package/src/components/ui/autocomplete.tsx +1 -1
- package/src/components/ui/avatar.tsx +4 -0
- package/src/components/ui/chart.tsx +134 -42
- package/src/components/ui/checkbox-group.tsx +1 -1
- package/src/components/ui/checkbox.tsx +1 -1
- package/src/components/ui/color-picker.tsx +20 -4
- package/src/components/ui/combobox.tsx +1 -0
- package/src/components/ui/command.tsx +1 -1
- package/src/components/ui/data-table.tsx +64 -3
- package/src/components/ui/date-field.tsx +1 -1
- package/src/components/ui/date-picker.tsx +2 -0
- package/src/components/ui/date-range-picker.tsx +4 -0
- package/src/components/ui/editable.tsx +1 -0
- package/src/components/ui/faceted-filter.tsx +187 -0
- package/src/components/ui/file-upload.tsx +21 -2
- package/src/components/ui/gauge-chart.tsx +18 -4
- package/src/components/ui/heatmap.tsx +3 -1
- package/src/components/ui/inline-edit.tsx +175 -0
- package/src/components/ui/input-group.tsx +5 -2
- package/src/components/ui/month-picker.tsx +1 -1
- package/src/components/ui/multi-select.tsx +1 -0
- package/src/components/ui/number-input.tsx +28 -5
- package/src/components/ui/otp-input.tsx +208 -0
- package/src/components/ui/phone-input.tsx +274 -0
- package/src/components/ui/radio-group.tsx +2 -2
- package/src/components/ui/search-input.tsx +1 -1
- package/src/components/ui/sparkline.tsx +33 -4
- package/src/components/ui/spinner.tsx +23 -4
- package/src/components/ui/table.tsx +9 -0
- package/src/components/ui/tags-input.tsx +1 -1
- package/src/components/ui/timer.tsx +1 -0
- package/src/components/ui/transfer-list.tsx +13 -26
- package/src/components/ui/week-picker.tsx +1 -13
- package/src/components/ui/year-picker.tsx +1 -1
- package/src/data/component-added.json +966 -0
- package/src/data/docs-index.ts +35 -2
- package/src/data/history.json +161 -161
- package/src/data/sticker-sheet.json +9244 -0
- package/src/docs-trace-globs.json +1 -0
- package/src/hooks/use-global-mono-font.ts +1 -0
- package/src/hooks/use-global-primary-color.ts +1 -0
- package/src/hooks/use-global-sans-font.ts +1 -0
- package/src/hooks/use-global-serif-font.ts +1 -0
- package/src/hooks/use-global-type-scale.ts +17 -2
- package/src/hooks/use-mobile.ts +2 -0
- package/src/hooks/use-sync-type-scale.ts +7 -11
- package/src/lib/chart-motion.ts +41 -0
- package/src/lib/get-icon-color.ts +1 -1
- package/src/lib/spec-parse.ts +4 -0
- package/src/lib/svg-sanitize.ts +19 -9
- package/src/stories/Accordion.stories.tsx +7 -0
- package/src/stories/ActionBar.stories.tsx +5 -0
- package/src/stories/Affix.stories.tsx +4 -0
- package/src/stories/AiBadge.stories.tsx +9 -7
- package/src/stories/Alert.stories.tsx +13 -0
- package/src/stories/AlertDialog.stories.tsx +4 -0
- package/src/stories/Anchor.stories.tsx +5 -0
- package/src/stories/AngleSlider.stories.tsx +6 -3
- package/src/stories/AspectRatio.stories.tsx +4 -0
- package/src/stories/Autocomplete.stories.tsx +8 -0
- package/src/stories/Avatar.stories.tsx +10 -0
- package/src/stories/Badge.stories.tsx +14 -6
- package/src/stories/Blockquote.stories.tsx +6 -0
- package/src/stories/BottomNavigation.stories.tsx +4 -0
- package/src/stories/Breadcrumb.stories.tsx +3 -0
- package/src/stories/Burger.stories.tsx +1 -0
- package/src/stories/Button.stories.tsx +24 -0
- package/src/stories/ButtonGroup.stories.tsx +9 -0
- package/src/stories/Calendar.stories.tsx +3 -0
- package/src/stories/Canvas.stories.tsx +45 -0
- package/src/stories/Card.stories.tsx +4 -0
- package/src/stories/Carousel.stories.tsx +6 -0
- package/src/stories/Cascader.stories.tsx +4 -0
- package/src/stories/Chart.stories.tsx +46 -1
- package/src/stories/ChatBubble.stories.tsx +8 -2
- package/src/stories/ChatMarker.stories.tsx +1 -0
- package/src/stories/Checkbox.stories.tsx +40 -0
- package/src/stories/CheckboxCard.stories.tsx +8 -0
- package/src/stories/CheckboxGroup.stories.tsx +19 -0
- package/src/stories/Chip.stories.tsx +10 -19
- package/src/stories/CircularProgress.stories.tsx +13 -27
- package/src/stories/Clipboard.stories.tsx +6 -0
- package/src/stories/CloseButton.stories.tsx +6 -4
- package/src/stories/Code.stories.tsx +8 -1
- package/src/stories/Collapsible.stories.tsx +2 -0
- package/src/stories/ColorPicker.stories.tsx +46 -0
- package/src/stories/ColorSwatch.stories.tsx +1 -0
- package/src/stories/Combobox.stories.tsx +9 -0
- package/src/stories/Command.stories.tsx +2 -0
- package/src/stories/Container.stories.tsx +8 -0
- package/src/stories/ContextMenu.stories.tsx +9 -0
- package/src/stories/CopyButton.stories.tsx +12 -36
- package/src/stories/DataList.stories.tsx +8 -0
- package/src/stories/DataTable.stories.tsx +39 -0
- package/src/stories/DateField.stories.tsx +28 -0
- package/src/stories/DatePicker.stories.tsx +34 -0
- package/src/stories/DateRangePicker.stories.tsx +32 -0
- package/src/stories/Dialog.stories.tsx +8 -0
- package/src/stories/Drawer.stories.tsx +6 -0
- package/src/stories/DropdownMenu.stories.tsx +2 -0
- package/src/stories/Editable.stories.tsx +12 -0
- package/src/stories/EmptyState.stories.tsx +9 -0
- package/src/stories/FacetedFilter.stories.tsx +197 -0
- package/src/stories/Field.stories.tsx +7 -0
- package/src/stories/Fieldset.stories.tsx +8 -0
- package/src/stories/FileButton.stories.tsx +4 -0
- package/src/stories/FileUpload.stories.tsx +16 -17
- package/src/stories/FloatLabel.stories.tsx +3 -8
- package/src/stories/FloatingActionButton.stories.tsx +10 -0
- package/src/stories/FloatingIndicator.stories.tsx +4 -0
- package/src/stories/FloatingPanel.stories.tsx +6 -0
- package/src/stories/FocusTrap.stories.tsx +5 -0
- package/src/stories/FormatByte.stories.tsx +6 -0
- package/src/stories/FormatDate.stories.tsx +8 -0
- package/src/stories/FormatNumber.stories.tsx +9 -0
- package/src/stories/GaugeChart.stories.tsx +9 -3
- package/src/stories/Heatmap.stories.tsx +11 -0
- package/src/stories/Highlight.stories.tsx +6 -0
- package/src/stories/HoverCard.stories.tsx +4 -0
- package/src/stories/Image.stories.tsx +9 -0
- package/src/stories/Indicator.stories.tsx +19 -0
- package/src/stories/InlineEdit.stories.tsx +106 -0
- package/src/stories/Input.stories.tsx +7 -0
- package/src/stories/InputClearButton.stories.tsx +3 -0
- package/src/stories/InputGroup.stories.tsx +40 -0
- package/src/stories/Kbd.stories.tsx +7 -1
- package/src/stories/KeyboardShortcut.stories.tsx +2 -0
- package/src/stories/Label.stories.tsx +2 -0
- package/src/stories/Link.stories.tsx +9 -0
- package/src/stories/List.stories.tsx +8 -0
- package/src/stories/Listbox.stories.tsx +1 -0
- package/src/stories/LoadingDots.stories.tsx +5 -3
- package/src/stories/LoadingOverlay.stories.tsx +5 -1
- package/src/stories/Mark.stories.tsx +5 -0
- package/src/stories/MarkdownPreview.stories.tsx +53 -0
- package/src/stories/Marquee.stories.tsx +4 -0
- package/src/stories/Masonry.stories.tsx +5 -0
- package/src/stories/Menubar.stories.tsx +3 -0
- package/src/stories/Meter.stories.tsx +11 -17
- package/src/stories/MonthPicker.stories.tsx +26 -1
- package/src/stories/MotionToggle.stories.tsx +1 -0
- package/src/stories/MultiSelect.stories.tsx +9 -0
- package/src/stories/NativeSelect.stories.tsx +1 -0
- package/src/stories/NavLink.stories.tsx +7 -0
- package/src/stories/NavigationMenu.stories.tsx +5 -0
- package/src/stories/NavigationRail.stories.tsx +10 -0
- package/src/stories/Notification.stories.tsx +13 -34
- package/src/stories/NumberInput.stories.tsx +33 -1
- package/src/stories/OtpInput.stories.tsx +110 -0
- package/src/stories/Overlay.stories.tsx +5 -1
- package/src/stories/Pagination.stories.tsx +8 -0
- package/src/stories/PasswordInput.stories.tsx +2 -0
- package/src/stories/PhoneInput.stories.tsx +127 -0
- package/src/stories/PinInput.stories.tsx +9 -2
- package/src/stories/Popover.stories.tsx +2 -0
- package/src/stories/Progress.stories.tsx +6 -1
- package/src/stories/Prose.stories.tsx +8 -0
- package/src/stories/QrCode.stories.tsx +2 -0
- package/src/stories/Questionnaire.stories.tsx +7 -0
- package/src/stories/RadioGroup.stories.tsx +40 -0
- package/src/stories/RatingGroup.stories.tsx +8 -4
- package/src/stories/Resizable.stories.tsx +4 -2
- package/src/stories/Result.stories.tsx +3 -0
- package/src/stories/Reveal.stories.tsx +2 -0
- package/src/stories/RollingNumber.stories.tsx +5 -0
- package/src/stories/ScrollArea.stories.tsx +3 -1
- package/src/stories/SearchInput.stories.tsx +10 -6
- package/src/stories/SegmentedControl.stories.tsx +11 -0
- package/src/stories/Select.stories.tsx +7 -0
- package/src/stories/Separator.stories.tsx +6 -0
- package/src/stories/Sheet.stories.tsx +5 -0
- package/src/stories/Sidebar.stories.tsx +40 -1
- package/src/stories/SimpleGrid.stories.tsx +5 -0
- package/src/stories/Skeleton.stories.tsx +8 -0
- package/src/stories/SkeletonTable.stories.tsx +6 -5
- package/src/stories/SkipLink.stories.tsx +3 -0
- package/src/stories/Slider.stories.tsx +2 -1
- package/src/stories/Sonner.stories.tsx +7 -0
- package/src/stories/Sparkline.stories.tsx +14 -1
- package/src/stories/Spinner.stories.tsx +20 -10
- package/src/stories/Spoiler.stories.tsx +5 -0
- package/src/stories/Squircle.stories.tsx +7 -0
- package/src/stories/Stack.stories.tsx +7 -0
- package/src/stories/StatusBadge.stories.tsx +12 -6
- package/src/stories/Stepper.stories.tsx +5 -0
- package/src/stories/Switch.stories.tsx +4 -0
- package/src/stories/Table.stories.tsx +10 -1
- package/src/stories/Tabs.stories.tsx +8 -0
- package/src/stories/Tag.stories.tsx +13 -5
- package/src/stories/TagsInput.stories.tsx +15 -0
- package/src/stories/Text.stories.tsx +12 -0
- package/src/stories/Textarea.stories.tsx +9 -0
- package/src/stories/ThemeIcon.stories.tsx +6 -3
- package/src/stories/TimePicker.stories.tsx +2 -0
- package/src/stories/Timeline.stories.tsx +12 -0
- package/src/stories/Timer.stories.tsx +30 -0
- package/src/stories/Toggle.stories.tsx +7 -5
- package/src/stories/ToggleGroup.stories.tsx +5 -0
- package/src/stories/ToggleTip.stories.tsx +4 -0
- package/src/stories/Toolbar.stories.tsx +6 -0
- package/src/stories/Tooltip.stories.tsx +3 -0
- package/src/stories/Tour.stories.tsx +3 -0
- package/src/stories/TransferList.stories.tsx +7 -0
- package/src/stories/TreeSelect.stories.tsx +4 -0
- package/src/stories/TreeView.stories.tsx +5 -0
- package/src/stories/TypingIndicator.stories.tsx +4 -0
- package/src/stories/VisuallyHidden.stories.tsx +3 -0
- package/src/stories/Watermark.stories.tsx +6 -0
- package/src/stories/WeekPicker.stories.tsx +25 -1
- package/src/stories/WordRotate.stories.tsx +5 -0
- package/src/stories/YearPicker.stories.tsx +26 -11
- package/src/stories/story-groups.json +22 -16
- package/src/styles.css +50 -2
- package/src/tokens.json +86 -58
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Icon sizing. Flags a size class on an icon that ignores `className`.
|
|
3
|
+
*
|
|
4
|
+
* Some icon components never read `className`. A size class on one does nothing, and the icon
|
|
5
|
+
* draws at its own size. This check reads the icon files to learn which icons ignore `className`,
|
|
6
|
+
* then flags `size-N`, `h-N` or `w-N` on them. A defect in an icon is fixed in the design system,
|
|
7
|
+
* not in the app that uses it.
|
|
8
|
+
*
|
|
9
|
+
* Settings: `iconDirs`, the folders of icon components. With none (the default) the check reports
|
|
10
|
+
* nothing.
|
|
11
|
+
*
|
|
12
|
+
* Mark an intended exception with `icon-size-ok: <why>` on the line or the line above.
|
|
13
|
+
*/
|
|
14
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
15
|
+
import { join, resolve } from "node:path";
|
|
16
|
+
import { settingsFor } from "./lib.mjs";
|
|
17
|
+
|
|
18
|
+
const ID = "icon-sizing";
|
|
19
|
+
const SIZE = /(?<![\w-])(?:size|h|w)-(?:\d+(?:\.\d+)?|\[[^\]\s]+\])(?![\w./[-])/;
|
|
20
|
+
const cache = new Map();
|
|
21
|
+
|
|
22
|
+
function walk(dir) {
|
|
23
|
+
const out = [];
|
|
24
|
+
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
25
|
+
const path = join(dir, entry.name);
|
|
26
|
+
if (entry.isDirectory()) out.push(...walk(path));
|
|
27
|
+
else if (/\.tsx$/.test(entry.name)) out.push(path);
|
|
28
|
+
}
|
|
29
|
+
return out;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Names of icons whose file never takes `className` as a prop, across the given folders. */
|
|
33
|
+
export function iconsThatIgnoreClassName(iconDirs = [], root = ".") {
|
|
34
|
+
const names = new Set();
|
|
35
|
+
for (const dir of iconDirs) {
|
|
36
|
+
let files = [];
|
|
37
|
+
try {
|
|
38
|
+
files = walk(resolve(root, dir));
|
|
39
|
+
} catch {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
for (const file of files) {
|
|
43
|
+
const source = readFileSync(file, "utf8");
|
|
44
|
+
if (/\bclassName\b(?!\s*=)/.test(source)) continue;
|
|
45
|
+
for (const m of source.matchAll(/export\s+(?:default\s+)?(?:const|function)\s+([A-Z]\w*)/g)) {
|
|
46
|
+
names.add(m[1]);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return names;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const iconSizing = {
|
|
54
|
+
id: ID,
|
|
55
|
+
title: "Icon size class ignored",
|
|
56
|
+
marker: "icon-size-ok",
|
|
57
|
+
order: 90,
|
|
58
|
+
scanFile({ lines, settings }) {
|
|
59
|
+
const { iconDirs = [] } = settingsFor(settings, ID);
|
|
60
|
+
if (iconDirs.length === 0) return [];
|
|
61
|
+
const key = JSON.stringify([process.cwd(), iconDirs]);
|
|
62
|
+
if (!cache.has(key)) cache.set(key, iconsThatIgnoreClassName(iconDirs));
|
|
63
|
+
const deaf = cache.get(key);
|
|
64
|
+
if (deaf.size === 0) return [];
|
|
65
|
+
const hits = [];
|
|
66
|
+
for (const { n, text } of lines) {
|
|
67
|
+
for (const m of text.matchAll(/<([A-Z]\w*)\b([^>]*)/g)) {
|
|
68
|
+
if (!deaf.has(m[1]) || !SIZE.test(m[2])) continue;
|
|
69
|
+
hits.push({
|
|
70
|
+
line: n,
|
|
71
|
+
found: `<${m[1]}>`,
|
|
72
|
+
message: `\`${m[1]}\` never reads \`className\`, so the size class does nothing.`,
|
|
73
|
+
fix: "Pick a sibling icon that accepts `className`, or wrap it in a box that sizes the parent. Fix the icon in the design system. If the size is deliberate, flag it with `icon-size-ok: <why>`.",
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return hits;
|
|
78
|
+
},
|
|
79
|
+
};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentence-case labels. Flags Title Case in a button's words and in label props.
|
|
3
|
+
*
|
|
4
|
+
* Capitalize the first word and proper nouns. Nothing else. Acronyms in capitals pass.
|
|
5
|
+
* This check reads one line. It does not read headings or prose, where names cause false flags.
|
|
6
|
+
*
|
|
7
|
+
* Settings: `properNouns` (added to the built-in list in defaults.mjs), `properNounsFile` (a JSON
|
|
8
|
+
* file `{ "properNouns": [...] }` at the repo root, `label-case-nouns.json` by default, the same
|
|
9
|
+
* file `bads-lint-label-case` reads), and `props` (the prop and key names read as labels). A noun
|
|
10
|
+
* of more than one word, such as "Night Shift", passes only as the whole phrase.
|
|
11
|
+
*
|
|
12
|
+
* Mark a label copied from production with `label-case-ok: <why>` on the line or the line above.
|
|
13
|
+
*/
|
|
14
|
+
import { readFileSync } from "node:fs";
|
|
15
|
+
import { BUILT_IN_PROPER_NOUNS } from "./defaults.mjs";
|
|
16
|
+
import { settingsFor } from "./lib.mjs";
|
|
17
|
+
|
|
18
|
+
const ID = "label-case";
|
|
19
|
+
const BUTTON_TEXT = /<(?:button|Button)\b[^>]*>\s*([A-Za-z][^<>{}\n]*?)\s*<\/(?:button|Button)>/g;
|
|
20
|
+
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
21
|
+
|
|
22
|
+
const fileNounCache = new Map();
|
|
23
|
+
function fileNouns(path) {
|
|
24
|
+
if (!path) return [];
|
|
25
|
+
if (fileNounCache.has(path)) return fileNounCache.get(path);
|
|
26
|
+
let nouns = [];
|
|
27
|
+
try {
|
|
28
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
29
|
+
if (Array.isArray(parsed.properNouns)) nouns = parsed.properNouns.filter((n) => typeof n === "string");
|
|
30
|
+
} catch {
|
|
31
|
+
nouns = [];
|
|
32
|
+
}
|
|
33
|
+
fileNounCache.set(path, nouns);
|
|
34
|
+
return nouns;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const nounCache = new Map();
|
|
38
|
+
function nounsFor({ properNouns = [], properNounsFile }) {
|
|
39
|
+
const key = JSON.stringify([properNouns, properNounsFile]);
|
|
40
|
+
if (!nounCache.has(key)) {
|
|
41
|
+
const all = [...BUILT_IN_PROPER_NOUNS, ...properNouns, ...fileNouns(properNounsFile)];
|
|
42
|
+
const words = new Set(all.filter((n) => !/\s/.test(n)));
|
|
43
|
+
/* Longest first, so "Night Shift Report" masks before "Night Shift". */
|
|
44
|
+
const phrases = all.filter((n) => /\s/.test(n)).sort((a, b) => b.length - a.length);
|
|
45
|
+
nounCache.set(key, { words, phrases });
|
|
46
|
+
}
|
|
47
|
+
return nounCache.get(key);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const propPattern = (props) =>
|
|
51
|
+
new RegExp(`(?<![\\w-])(?:${props.map(escape).join("|")})\\s*[=:]\\s*["'\`]([^"'\`\\n\${}]+)["'\`]`, "g");
|
|
52
|
+
|
|
53
|
+
function titleCased(phrase, { words: proper, phrases }) {
|
|
54
|
+
/* A proper noun of several words is lower-cased as a whole phrase, so its words never flag. */
|
|
55
|
+
let masked = phrase;
|
|
56
|
+
for (const noun of phrases) masked = masked.split(noun).join(noun.toLowerCase());
|
|
57
|
+
const words = masked.split(/\s+/).filter(Boolean);
|
|
58
|
+
if (words.length < 2) return null;
|
|
59
|
+
for (const [w, word] of words.entries()) {
|
|
60
|
+
for (const [q, part] of word.split("-").entries()) {
|
|
61
|
+
if (w === 0 && q === 0) continue;
|
|
62
|
+
if (!/^[A-Z][a-z]/.test(part)) continue;
|
|
63
|
+
if (proper.has(part.replace(/['’]s$/, ""))) continue;
|
|
64
|
+
return part;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const labelCase = {
|
|
71
|
+
id: ID,
|
|
72
|
+
title: "Title Case label",
|
|
73
|
+
marker: "label-case-ok",
|
|
74
|
+
order: 60,
|
|
75
|
+
scanLine(text, own) {
|
|
76
|
+
const settings = settingsFor(own, ID);
|
|
77
|
+
const nouns = nounsFor(settings);
|
|
78
|
+
const hits = [];
|
|
79
|
+
for (const re of [BUTTON_TEXT, propPattern(settings.props)]) {
|
|
80
|
+
for (const m of text.matchAll(re)) {
|
|
81
|
+
const word = titleCased(m[1], nouns);
|
|
82
|
+
if (!word) continue;
|
|
83
|
+
hits.push({
|
|
84
|
+
found: m[1],
|
|
85
|
+
message: `"${m[1]}" is Title Case. "${word}" should be lower case.`,
|
|
86
|
+
fix: `Write the label in sentence case. Add a real proper noun to \`${settings.properNounsFile ?? "properNouns"}\`. If a label is copied from production, flag it with \`label-case-ok: <why>\`.`,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return hits;
|
|
91
|
+
},
|
|
92
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native form control. Flags a native `input`, `select` or `textarea` that the design system
|
|
3
|
+
* already ships.
|
|
4
|
+
*
|
|
5
|
+
* The design system's input, text area, select, checkbox and radio carry the label, error state,
|
|
6
|
+
* focus ring and tap target. A native control is a second copy that drifts from them. Hidden and
|
|
7
|
+
* file inputs have no design-system version, so they pass. The folder that holds the real controls
|
|
8
|
+
* (`atomsPath`) is skipped: those files are the real controls.
|
|
9
|
+
*
|
|
10
|
+
* Settings: `components.Input`, `TextArea`, `Select`, `Checkbox` and `Radio` (`{ name, importPath }`)
|
|
11
|
+
* and `atomsPath` (a regular expression for the folder of real controls).
|
|
12
|
+
*
|
|
13
|
+
* Mark an intended exception with `native-control-ok: <why>` on the line or the line above.
|
|
14
|
+
*/
|
|
15
|
+
import { isCommentLine, settingsFor } from "./lib.mjs";
|
|
16
|
+
|
|
17
|
+
const ID = "native-form-control";
|
|
18
|
+
const CONTROL = /<(input|select|textarea)(?=[\s/>]|$)/g;
|
|
19
|
+
const NO_COMPONENT = /\btype=["'](?:hidden|file)["']/;
|
|
20
|
+
const ROLE = { select: "Select", textarea: "TextArea", input: "Input" };
|
|
21
|
+
|
|
22
|
+
function roleFor(tag, text) {
|
|
23
|
+
if (tag !== "input") return ROLE[tag];
|
|
24
|
+
if (/\btype=["']checkbox["']/.test(text)) return "Checkbox";
|
|
25
|
+
if (/\btype=["']radio["']/.test(text)) return "Radio";
|
|
26
|
+
return ROLE.input;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const nativeFormControl = {
|
|
30
|
+
id: ID,
|
|
31
|
+
title: "Native form control",
|
|
32
|
+
marker: "native-control-ok",
|
|
33
|
+
order: 40,
|
|
34
|
+
scanFile({ file, lines, settings }) {
|
|
35
|
+
const { components, atomsPath } = settingsFor(settings, ID).$all;
|
|
36
|
+
if (atomsPath && new RegExp(atomsPath).test(file)) return [];
|
|
37
|
+
const hits = [];
|
|
38
|
+
for (const { n, text } of lines) {
|
|
39
|
+
if (isCommentLine(text)) continue;
|
|
40
|
+
for (const m of text.matchAll(CONTROL)) {
|
|
41
|
+
if (m[1] === "input" && NO_COMPONENT.test(text)) continue;
|
|
42
|
+
const { name, importPath } = components[roleFor(m[1], text)];
|
|
43
|
+
hits.push({
|
|
44
|
+
line: n,
|
|
45
|
+
found: `<${m[1]}>`,
|
|
46
|
+
message: `A native \`${m[1]}\` is a hand-built copy of \`${name}\`.`,
|
|
47
|
+
fix: `Use \`${name}\` from \`${importPath}\`. If the design system has no variant you need, flag it with \`native-control-ok: <why>\`.`,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return hits;
|
|
52
|
+
},
|
|
53
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Corner radius by role. Flags a button with words on it that is `rounded-full`, and an
|
|
3
|
+
* undeclared radius variable.
|
|
4
|
+
*
|
|
5
|
+
* A button with a word on it is not a pill. Pills are for things you choose or read. An icon-only
|
|
6
|
+
* round button passes. `rounded-[var(--...)]` computes to square corners when nothing declares
|
|
7
|
+
* the variable.
|
|
8
|
+
*
|
|
9
|
+
* Settings: `buttonRadius` (the radius the fix suggests for a button) and `utilities` (the radius
|
|
10
|
+
* classes the fix lists in place of a variable).
|
|
11
|
+
*
|
|
12
|
+
* Mark an intended exception with `radius-ok: <role>` on the line or the line above.
|
|
13
|
+
*/
|
|
14
|
+
import { settingsFor } from "./lib.mjs";
|
|
15
|
+
|
|
16
|
+
const ID = "radius";
|
|
17
|
+
const LOOK_AHEAD = 8;
|
|
18
|
+
const OPENING = /<(?:button|Button)\b/;
|
|
19
|
+
const PILL = /(?<![\w-])rounded-full(?![\w-])/;
|
|
20
|
+
const VAR_RADIUS = /(?<![\w-])rounded(?:-[a-z]+)?-\[var\(--/;
|
|
21
|
+
|
|
22
|
+
export const radius = {
|
|
23
|
+
id: ID,
|
|
24
|
+
title: "Corner radius",
|
|
25
|
+
marker: "radius-ok",
|
|
26
|
+
order: 80,
|
|
27
|
+
scanFile({ lines, text, settings }) {
|
|
28
|
+
if (text === null) return [];
|
|
29
|
+
const { buttonRadius, utilities } = settingsFor(settings, ID);
|
|
30
|
+
const all = text.split("\n");
|
|
31
|
+
const hits = [];
|
|
32
|
+
for (const { n, text: line } of lines) {
|
|
33
|
+
if (VAR_RADIUS.test(line)) {
|
|
34
|
+
hits.push({
|
|
35
|
+
line: n,
|
|
36
|
+
found: "rounded-[var(--…)]",
|
|
37
|
+
message: "An undeclared CSS variable computes to 0px, so the corners come out square.",
|
|
38
|
+
fix: `Use a radius utility: ${utilities}.`,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
if (!OPENING.test(line)) continue;
|
|
42
|
+
const chunk = all.slice(n - 1, n - 1 + LOOK_AHEAD).join("\n");
|
|
43
|
+
const element = chunk.match(/<(?:button|Button)\b((?:=>|[^>])*)>([\s\S]*?)<\/(?:button|Button)>/);
|
|
44
|
+
if (!element || !PILL.test(element[1])) continue;
|
|
45
|
+
const words = element[2].replace(/<[^>]*>/g, "").replace(/\{[^}]*\}/g, "");
|
|
46
|
+
if (!/[A-Za-z]{2,}/.test(words)) continue;
|
|
47
|
+
hits.push({
|
|
48
|
+
line: n,
|
|
49
|
+
found: "rounded-full",
|
|
50
|
+
message: "A button with words on it is not a pill.",
|
|
51
|
+
fix: `Use ${buttonRadius}. If this is a chip or a toggle you choose, flag it with \`radius-ok: <role>\`.`,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
return hits;
|
|
55
|
+
},
|
|
56
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw values. Flags hex colors, rgb()/hsl() and arbitrary pixel or rem sizes on added lines.
|
|
3
|
+
* Use semantic tokens and the Tailwind scale.
|
|
4
|
+
*
|
|
5
|
+
* Text sizes under the floor belong to the small-text check, so `text-[..]` is skipped here.
|
|
6
|
+
* Media query variants (`min-[640px]:`) and border widths are not sizes on the spacing scale, so
|
|
7
|
+
* they are skipped too.
|
|
8
|
+
*
|
|
9
|
+
* Settings: `tokenExamples` and `opacityExample`, the token classes the fix text names.
|
|
10
|
+
*
|
|
11
|
+
* Mark an intentional exception with `raw-value-ok: <why>` on the line or the line above.
|
|
12
|
+
*/
|
|
13
|
+
import { settingsFor } from "./lib.mjs";
|
|
14
|
+
|
|
15
|
+
const ID = "raw-values";
|
|
16
|
+
const ARBITRARY_HEX = /(?<![\w-])[a-z][a-z-]*-\[#[0-9a-fA-F]{3,8}\]/g;
|
|
17
|
+
const ARBITRARY_FUNC = /(?<![\w-])[a-z][a-z-]*-\[(?:rgba?|hsla?)\([^\]]*\]/g;
|
|
18
|
+
const ARBITRARY_SIZE =
|
|
19
|
+
/(?<![\w-])(?!text-|(?:min|max)-\[|border(?:-[a-z]+)?-\[)[a-z][a-z-]*-\[-?\d*\.?\d+(?:px|rem)\]/g;
|
|
20
|
+
const STYLE_COLOR =
|
|
21
|
+
/\b(?:color|background|backgroundColor|borderColor|outlineColor|fill|stroke|boxShadow)\s*:\s*["'`][^"'`]*?(?:#[0-9a-fA-F]{3,8}\b|\brgba?\(|\bhsla?\()/g;
|
|
22
|
+
|
|
23
|
+
export const rawValues = {
|
|
24
|
+
id: ID,
|
|
25
|
+
title: "Raw values",
|
|
26
|
+
marker: "raw-value-ok",
|
|
27
|
+
order: 20,
|
|
28
|
+
scanLine(text, own) {
|
|
29
|
+
const { tokenExamples, opacityExample } = settingsFor(own, ID);
|
|
30
|
+
const hits = [];
|
|
31
|
+
for (const m of text.matchAll(ARBITRARY_HEX)) {
|
|
32
|
+
hits.push({
|
|
33
|
+
found: m[0],
|
|
34
|
+
message: `${m[0]} hardcodes a hex color.`,
|
|
35
|
+
fix: `Use a semantic token such as ${tokenExamples}. If none fits, propose a token in the PR. Never edit a brand value to pass a check.`,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
for (const m of text.matchAll(ARBITRARY_FUNC)) {
|
|
39
|
+
hits.push({
|
|
40
|
+
found: m[0],
|
|
41
|
+
message: `${m[0]} hardcodes a color function.`,
|
|
42
|
+
fix: `Use a semantic token, or a Tailwind opacity modifier on one (${opacityExample}).`,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
for (const m of text.matchAll(STYLE_COLOR)) {
|
|
46
|
+
hits.push({
|
|
47
|
+
found: m[0].trim(),
|
|
48
|
+
message: "Inline style hardcodes a color.",
|
|
49
|
+
fix: "Use a semantic token class. If the value must be a CSS variable, reference it with var(--token).",
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
for (const m of text.matchAll(ARBITRARY_SIZE)) {
|
|
53
|
+
hits.push({
|
|
54
|
+
found: m[0],
|
|
55
|
+
message: `${m[0]} is an arbitrary size off the spacing scale.`,
|
|
56
|
+
fix: "Use the Tailwind scale (w-12, p-4, gap-2). If the scale lacks a value you need, raise it in the PR.",
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return hits;
|
|
60
|
+
},
|
|
61
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small text. Flags text under the floor on added lines.
|
|
3
|
+
*
|
|
4
|
+
* The floor is a soft one for new text (`floorPx`, 14 by default). If a person chooses a smaller
|
|
5
|
+
* size it is still built, but the line is flagged: mark it with
|
|
6
|
+
* `type-scale-ok: <who chose this size and why>`.
|
|
7
|
+
*
|
|
8
|
+
* Settings: `floorPx`, `namedSizes` (a named class such as `text-xs` and its size in px; Tailwind's
|
|
9
|
+
* stock `text-xs` is 12px, so set it to your theme's value), and `suggest` (the class the fix names).
|
|
10
|
+
*/
|
|
11
|
+
import { settingsFor } from "./lib.mjs";
|
|
12
|
+
|
|
13
|
+
const ID = "small-text";
|
|
14
|
+
const ARBITRARY_CLASS = /(?<![\w-])text-\[(\d*\.?\d+)(px|rem|em)\]/g;
|
|
15
|
+
const STYLE_NUMBER = /\bfontSize\s*:\s*(\d*\.?\d+)\s*(?=[,}\s]|$)/g;
|
|
16
|
+
const STYLE_STRING = /\bfontSize\s*:\s*["'`](\d*\.?\d+)(px|rem|em)["'`]/g;
|
|
17
|
+
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
18
|
+
|
|
19
|
+
function toPx(value, unit) {
|
|
20
|
+
const n = Number(value);
|
|
21
|
+
return unit === "px" || !unit ? n : n * 16;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const smallText = {
|
|
25
|
+
id: ID,
|
|
26
|
+
title: "Small text",
|
|
27
|
+
marker: "type-scale-ok",
|
|
28
|
+
order: 10,
|
|
29
|
+
scanLine(text, own) {
|
|
30
|
+
const { floorPx, namedSizes = {}, suggest } = settingsFor(own, ID);
|
|
31
|
+
const hits = [];
|
|
32
|
+
for (const [name, px] of Object.entries(namedSizes)) {
|
|
33
|
+
if (!(px < floorPx)) continue;
|
|
34
|
+
if (!new RegExp(`(?<![\\w-])${escape(name)}(?![\\w-])`).test(text)) continue;
|
|
35
|
+
hits.push({
|
|
36
|
+
found: name,
|
|
37
|
+
message: `${name} is ${px}px, under the ${floorPx}px floor.`,
|
|
38
|
+
fix: `${floorPx}px is the floor and ${px}px should be avoided: use ${suggest}. If a person chose ${px}px, flag it with \`type-scale-ok: <who chose this and why>\` in a comment on this line or the line above.`,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
for (const m of text.matchAll(ARBITRARY_CLASS)) {
|
|
42
|
+
const px = toPx(m[1], m[2]);
|
|
43
|
+
if (px < floorPx) {
|
|
44
|
+
hits.push({
|
|
45
|
+
found: m[0],
|
|
46
|
+
message: `${m[0]} is ${px}px, under the ${floorPx}px floor and not a step on the type scale.`,
|
|
47
|
+
fix: `${floorPx}px is the floor: use a step from the scale (${suggest} and up). If a person chose this size, flag it with \`type-scale-ok: <who chose this and why>\`.`,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
for (const m of text.matchAll(STYLE_NUMBER)) {
|
|
52
|
+
if (Number(m[1]) < floorPx) {
|
|
53
|
+
hits.push({
|
|
54
|
+
found: m[0].trim(),
|
|
55
|
+
message: `fontSize ${m[1]} is under the ${floorPx}px floor.`,
|
|
56
|
+
fix: `${floorPx}px is the floor: use a type-scale class instead of an inline size. If a person chose this size, flag it with \`type-scale-ok: <who chose this and why>\`.`,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (const m of text.matchAll(STYLE_STRING)) {
|
|
61
|
+
const px = toPx(m[1], m[2]);
|
|
62
|
+
if (px < floorPx) {
|
|
63
|
+
hits.push({
|
|
64
|
+
found: m[0].trim(),
|
|
65
|
+
message: `fontSize ${m[1]}${m[2]} is ${px}px, under the ${floorPx}px floor.`,
|
|
66
|
+
fix: `${floorPx}px is the floor: use a type-scale class instead of an inline size. If a person chose this size, flag it with \`type-scale-ok: <who chose this and why>\`.`,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return hits;
|
|
71
|
+
},
|
|
72
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tap target. Flags a control that the page gives a fixed size under the floor.
|
|
3
|
+
*
|
|
4
|
+
* 44 by 44px is the floor for anything a person presses (WCAG 2.5.5), and a small control is hard
|
|
5
|
+
* to hit. The check reads the opening tag of a `button`, `Button`, `IconButton` or a tag with
|
|
6
|
+
* `onClick`, and flags a fixed `h-`, `w-` or `size-` class under the floor (44px / 4px = 11 units)
|
|
7
|
+
* on a line the PR added. A `min-h-11` or `min-w-11` class on the same tag clears it.
|
|
8
|
+
*
|
|
9
|
+
* It sees only sizes written as classes. A size that a component prop sets (`size="sm"`) is not read.
|
|
10
|
+
*
|
|
11
|
+
* Settings: `minPx` (the floor; when unset, the top-level `minTargetPx` in `.bads-lint.json`, then
|
|
12
|
+
* 44) and `unitPx` (px per spacing unit, 4). The unit floor is `minPx / unitPx`.
|
|
13
|
+
*
|
|
14
|
+
* Mark an intended exception with `tap-target-ok: <why>` on the line or the line above.
|
|
15
|
+
*/
|
|
16
|
+
import { DEFAULT_MIN_TARGET_PX } from "./defaults.mjs";
|
|
17
|
+
import { settingsFor } from "./lib.mjs";
|
|
18
|
+
|
|
19
|
+
const ID = "tap-target";
|
|
20
|
+
const FIXED_SIZE = /(?<![\w-])(?:h|w|size)-(\d+(?:\.\d+)?)(?![\w./[-])/g;
|
|
21
|
+
/* Two-digit whole units only, as before: `min-h-11.5` and `min-h-100` do not clear the tag. */
|
|
22
|
+
const MIN_SIZE = /(?<![\w-])min-(?:h|w)-(\d{1,2})(?![\w./[-])/g;
|
|
23
|
+
const TAG_START = /<(button|Button|IconButton|[A-Za-z]+)\b/;
|
|
24
|
+
const LOOK_BACK = 8;
|
|
25
|
+
|
|
26
|
+
function openingTag(all, index) {
|
|
27
|
+
for (let i = index; i >= Math.max(0, index - LOOK_BACK); i--) {
|
|
28
|
+
const start = all[i].match(TAG_START);
|
|
29
|
+
if (!start) continue;
|
|
30
|
+
const text = all.slice(i, index + 1).join("\n");
|
|
31
|
+
return { name: start[1], text };
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const isControl = ({ name, text }) =>
|
|
37
|
+
/^(button|Button|IconButton)$/.test(name) || /\bonClick=/.test(text);
|
|
38
|
+
|
|
39
|
+
export const tapTarget = {
|
|
40
|
+
id: ID,
|
|
41
|
+
title: "Tap target",
|
|
42
|
+
marker: "tap-target-ok",
|
|
43
|
+
order: 20,
|
|
44
|
+
scanFile({ lines, text, settings }) {
|
|
45
|
+
if (text === null) return [];
|
|
46
|
+
const own = settingsFor(settings, ID);
|
|
47
|
+
const minPx = own.minPx ?? DEFAULT_MIN_TARGET_PX;
|
|
48
|
+
const unitPx = own.unitPx ?? 4;
|
|
49
|
+
const minUnits = minPx / unitPx;
|
|
50
|
+
const shown = Number.isInteger(minUnits) ? minUnits : Math.ceil(minUnits);
|
|
51
|
+
const all = text.split("\n");
|
|
52
|
+
const hits = [];
|
|
53
|
+
for (const { n, text: line } of lines) {
|
|
54
|
+
if (/^\s*(\/\/|\/\*|\*)/.test(line)) continue;
|
|
55
|
+
const sizes = [...line.matchAll(FIXED_SIZE)].filter((m) => Number(m[1]) < minUnits);
|
|
56
|
+
if (sizes.length === 0) continue;
|
|
57
|
+
const tag = openingTag(all, n - 1);
|
|
58
|
+
if (!tag || !isControl(tag)) continue;
|
|
59
|
+
if ([...tag.text.matchAll(MIN_SIZE)].some((m) => Number(m[1]) >= minUnits)) continue;
|
|
60
|
+
const m = sizes[0];
|
|
61
|
+
hits.push({
|
|
62
|
+
line: n,
|
|
63
|
+
found: m[0],
|
|
64
|
+
message: `${m[0]} is ${Number(m[1]) * unitPx}px on a control, under the ${minPx}px floor.`,
|
|
65
|
+
fix: `A control should be at least ${minPx} by ${minPx}px. Add \`min-h-${shown} min-w-${shown}\`, or grow the hit area with padding. If a person chose a smaller size, flag it with \`tap-target-ok: <who chose this and why>\`.`,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return hits;
|
|
69
|
+
},
|
|
70
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default settings for the advisory design system checks.
|
|
3
|
+
*
|
|
4
|
+
* A project changes them under the `designSystemAdvisory` key of `.bads-lint.json` at its repo
|
|
5
|
+
* root, or in the file that `--config=<file>` names. Flags win over the file, and the file wins over
|
|
6
|
+
* these defaults. Objects merge key by key. An array in the file replaces the default array, with
|
|
7
|
+
* one exception: `checks["label-case"].properNouns` adds to `BUILT_IN_PROPER_NOUNS`.
|
|
8
|
+
*
|
|
9
|
+
* The defaults fit upstream BADS. A client points `include`, `components`, `atomsPath` and the
|
|
10
|
+
* icon folders at its own code. See README.md in this folder.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const CORE_UI = "@behavioral-agentic-design-system/core/components/ui";
|
|
14
|
+
|
|
15
|
+
export const DEFAULTS = {
|
|
16
|
+
/* Regular expressions, tested against the repo-relative path. A file is scanned when it matches one `include` and no `exclude`. */
|
|
17
|
+
include: ["^(app|components|packages/core/src)/.+\\.(tsx|jsx|ts)$"],
|
|
18
|
+
exclude: [
|
|
19
|
+
"\\.d\\.ts$",
|
|
20
|
+
"\\.test\\.",
|
|
21
|
+
"\\.spec\\.",
|
|
22
|
+
"\\.stories\\.",
|
|
23
|
+
"/__tests__/",
|
|
24
|
+
"/__mocks__/",
|
|
25
|
+
"/tests?/",
|
|
26
|
+
"/e2e/",
|
|
27
|
+
"/__snapshots__/",
|
|
28
|
+
"/generated/",
|
|
29
|
+
],
|
|
30
|
+
/* The branch a PR is compared with when you pass no `--base`. */
|
|
31
|
+
baseRef: "origin/main",
|
|
32
|
+
/* Shown in the PR comment. `rulesDoc: null` leaves the rules link out. */
|
|
33
|
+
rulesDoc: null,
|
|
34
|
+
readmePath: "node_modules/@behavioral-agentic-design-system/core/scripts/design-system-advisory/README.md",
|
|
35
|
+
/* What a hand-built control is replaced with. The fix text names these. */
|
|
36
|
+
components: {
|
|
37
|
+
Button: { name: "Button", importPath: `${CORE_UI}/button` },
|
|
38
|
+
Input: { name: "Input", importPath: `${CORE_UI}/input` },
|
|
39
|
+
TextArea: { name: "Textarea", importPath: `${CORE_UI}/textarea` },
|
|
40
|
+
Select: { name: "NativeSelect", importPath: `${CORE_UI}/native-select` },
|
|
41
|
+
Checkbox: { name: "Checkbox", importPath: `${CORE_UI}/checkbox` },
|
|
42
|
+
Radio: { name: "RadioGroup", importPath: `${CORE_UI}/radio-group` },
|
|
43
|
+
},
|
|
44
|
+
/* Folders `listComponents()` reads. `importPrefix` plus the path under `dir` is the import path. */
|
|
45
|
+
componentRoots: [{ dir: "packages/core/src/components/ui", importPrefix: CORE_UI, layer: "ui" }],
|
|
46
|
+
/* A regular expression for the folder that holds the real controls. native-form-control skips it. */
|
|
47
|
+
atomsPath: "packages/core/src/components/ui/",
|
|
48
|
+
/* Per check: `false` switches the check off, an object changes its settings. */
|
|
49
|
+
checks: {
|
|
50
|
+
"small-text": {
|
|
51
|
+
floorPx: 14,
|
|
52
|
+
/* Named text classes and their size in px. Tailwind's stock `text-xs` is 12px. */
|
|
53
|
+
namedSizes: { "text-xs": 12 },
|
|
54
|
+
suggest: "text-sm",
|
|
55
|
+
},
|
|
56
|
+
"raw-values": {
|
|
57
|
+
tokenExamples: "bg-background or text-destructive",
|
|
58
|
+
opacityExample: "bg-foreground/50",
|
|
59
|
+
},
|
|
60
|
+
"tap-target": {
|
|
61
|
+
/* When unset, the top-level `minTargetPx` in `.bads-lint.json` is used, then 44. */
|
|
62
|
+
minPx: undefined,
|
|
63
|
+
unitPx: 4,
|
|
64
|
+
},
|
|
65
|
+
"label-case": {
|
|
66
|
+
properNouns: [],
|
|
67
|
+
properNounsFile: "label-case-nouns.json",
|
|
68
|
+
props: ["label", "cta", "title", "ctaLabel", "buttonText"],
|
|
69
|
+
},
|
|
70
|
+
radius: {
|
|
71
|
+
buttonRadius: "`rounded-md`, the radius `Button` uses",
|
|
72
|
+
utilities: "`rounded`, `rounded-sm`, `rounded-md`, `rounded-lg` or `rounded-full`",
|
|
73
|
+
},
|
|
74
|
+
"icon-sizing": {
|
|
75
|
+
/* Folders of icon components. Empty means the check reports nothing. */
|
|
76
|
+
iconDirs: [],
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const DEFAULT_MIN_TARGET_PX = 44;
|
|
82
|
+
|
|
83
|
+
/** Words that are capitalized in sentence case. A project adds its own in `properNouns` or `properNounsFile`. */
|
|
84
|
+
export const BUILT_IN_PROPER_NOUNS = [
|
|
85
|
+
"Google", "Apple", "Facebook", "Stripe", "PayPal", "Venmo", "Zelle", "Visa", "Mastercard",
|
|
86
|
+
"Discover", "American", "Express", "Meta", "Instagram", "Drive", "Pay", "Wallet", "Maps",
|
|
87
|
+
"January", "February", "March", "April", "May", "June", "July", "August", "September",
|
|
88
|
+
"October", "November", "December", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
|
|
89
|
+
"Saturday", "Sunday", "I", "US", "USA",
|
|
90
|
+
];
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Nothing below should produce a finding.
|
|
2
|
+
export function Clean() {
|
|
3
|
+
return (
|
|
4
|
+
<div className="bg-background text-muted-foreground p-4 gap-2 w-12">
|
|
5
|
+
<p className="text-sm">14px text</p>
|
|
6
|
+
<p className="text-base">16px text</p>
|
|
7
|
+
<p className="w-[50%] h-[calc(100%-1rem)] bg-[var(--surface)]">percent, calc and var are fine</p>
|
|
8
|
+
<p className="text-[length:var(--size)]">variable text size</p>
|
|
9
|
+
<svg fill="#1d4ed8" />
|
|
10
|
+
</div>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Every line below should produce a finding, except the ones marked OK.
|
|
2
|
+
export function Violations() {
|
|
3
|
+
return (
|
|
4
|
+
<div>
|
|
5
|
+
<p className="text-xs">12px text</p>
|
|
6
|
+
<p className="text-[11px]">11px arbitrary</p>
|
|
7
|
+
<p className="sm:text-xs">responsive 12px</p>
|
|
8
|
+
<p style={{ fontSize: 12 }}>inline number</p>
|
|
9
|
+
<p style={{ fontSize: "0.75rem" }}>inline rem</p>
|
|
10
|
+
<div className="bg-[#1d4ed8] text-[rgb(10,20,30)]">hex and rgb classes</div>
|
|
11
|
+
<div style={{ color: "#ff0000" }}>inline color</div>
|
|
12
|
+
<div className="w-[437px] p-[13px] top-[98px]">arbitrary sizes</div>
|
|
13
|
+
{/* type-scale-ok: hint under a field, the designer chose 12px */}
|
|
14
|
+
<p className="text-xs">OK: marked small text</p>
|
|
15
|
+
{/* raw-value-ok: sticky offset matches the header height */}
|
|
16
|
+
<div className="top-[98px]">OK: marked raw value</div>
|
|
17
|
+
</div>
|
|
18
|
+
);
|
|
19
|
+
}
|