@djangocfg/ui-core 2.1.638 → 2.1.640
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 +10 -2
- package/package.json +7 -7
- package/src/components/forms/button/index.tsx +1 -1
- package/src/components/forms/control-size.ts +14 -8
- package/src/components/forms/input/index.tsx +2 -2
- package/src/components/navigation/tabs/index.tsx +6 -0
- package/src/components/select/select.tsx +3 -1
- package/src/hooks/media/index.ts +1 -0
- package/src/hooks/media/scrollReset.ts +66 -0
- package/src/lib/env.ts +3 -3
- package/src/providers/UiProviders.tsx +3 -0
package/README.md
CHANGED
|
@@ -75,12 +75,20 @@ size. Never write `h-9` / `h-10` on a control: read the map, or pass the size.
|
|
|
75
75
|
| `lg` | 44px (`h-11`) | yes | yes | yes |
|
|
76
76
|
| `huge` | 56px (`h-14`) | yes | no | no |
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
On a coarse pointer (a finger) every rung except `huge` rises to a 44px floor
|
|
79
|
+
(`pointer-coarse:min-h-11`, carried by the rung itself, so `Button`, `Input`,
|
|
80
|
+
`SelectTrigger` and the date fields stay level with each other on a phone); the
|
|
81
|
+
icon `Button` is 44px wide too, and `TabsTrigger` is 44px tall (its `TabsList`
|
|
82
|
+
track grows to 48px around it). A mouse keeps the heights in the table. Text
|
|
83
|
+
fields type 16px on a phone and 14px from `md` (`text-base md:text-sm`): `Input`
|
|
84
|
+
at its default size, `Textarea` and `SelectTrigger`.
|
|
85
|
+
|
|
86
|
+
`Button` also has `icon` (36px square with a mouse). Triggers built on `Button`
|
|
79
87
|
(`Combobox`, `LanguageSelect`, `DatePicker`) take their height from the Button
|
|
80
88
|
size; the multi-select triggers use `minHeight` so chips can wrap but never
|
|
81
89
|
sit under the fixed control. Not on the ladder, on purpose: `FilterButton`
|
|
82
90
|
(its `FilterBar` sets the height), OTP / segmented cells (square code cells),
|
|
83
|
-
and `Textarea` (multi-line).
|
|
91
|
+
and `Textarea` (multi-line, `min-h-[60px]`).
|
|
84
92
|
`control-size.test.tsx` fails if `Button`, `Input` or `SelectTrigger` stop
|
|
85
93
|
agreeing; the Storybook story `Controls / Alignment` draws the guide lines.
|
|
86
94
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/ui-core",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.640",
|
|
4
4
|
"description": "Pure React UI component library without Next.js dependencies - for Electron, Vite, CRA apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ui-components",
|
|
@@ -139,8 +139,8 @@
|
|
|
139
139
|
"check:docs": "node scripts/check-docs.mjs"
|
|
140
140
|
},
|
|
141
141
|
"peerDependencies": {
|
|
142
|
-
"@djangocfg/api": "^2.1.
|
|
143
|
-
"@djangocfg/i18n": "^2.1.
|
|
142
|
+
"@djangocfg/api": "^2.1.640",
|
|
143
|
+
"@djangocfg/i18n": "^2.1.640",
|
|
144
144
|
"consola": "^3.4.2",
|
|
145
145
|
"lucide-react": "^1.68.0",
|
|
146
146
|
"moment": "^2.30.1",
|
|
@@ -215,10 +215,10 @@
|
|
|
215
215
|
"vaul": "1.1.2"
|
|
216
216
|
},
|
|
217
217
|
"devDependencies": {
|
|
218
|
-
"@djangocfg/api": "^2.1.
|
|
219
|
-
"@djangocfg/eslint-config": "^2.1.
|
|
220
|
-
"@djangocfg/i18n": "^2.1.
|
|
221
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
218
|
+
"@djangocfg/api": "^2.1.640",
|
|
219
|
+
"@djangocfg/eslint-config": "^2.1.640",
|
|
220
|
+
"@djangocfg/i18n": "^2.1.640",
|
|
221
|
+
"@djangocfg/typescript-config": "^2.1.640",
|
|
222
222
|
"@storybook/react-vite": "^10.6.5",
|
|
223
223
|
"@types/node": "^24.13.3",
|
|
224
224
|
"@types/react": "19.3.0",
|
|
@@ -41,7 +41,7 @@ const buttonVariants = cva(
|
|
|
41
41
|
xs: cn(buttonSizeClass('xs'), "rounded-[var(--radius-sm)]"),
|
|
42
42
|
lg: cn(buttonSizeClass('lg'), "rounded-[var(--radius)]"),
|
|
43
43
|
huge: cn(buttonSizeClass('huge'), "rounded-[var(--radius)]"),
|
|
44
|
-
icon: cn(CONTROL_SIZE.default.height, "w-(--control-h-default)"),
|
|
44
|
+
icon: cn(CONTROL_SIZE.default.height, "w-(--control-h-default) pointer-coarse:min-w-11"),
|
|
45
45
|
},
|
|
46
46
|
// Most variants ship a baked-in `shadow`/`shadow-sm` for a lifted look.
|
|
47
47
|
// `elevated={false}` flattens that (e.g. controls grouped inside a card —
|
|
@@ -14,6 +14,12 @@ import { cn } from '../../lib/utils';
|
|
|
14
14
|
* - `height` / `minHeight`: the shared token. `minHeight` is for triggers that
|
|
15
15
|
* grow with their content (chips, tags) and must still never be shorter than
|
|
16
16
|
* the fixed control of the same size.
|
|
17
|
+
* - Touch floor: every rung except `huge` also carries `pointer-coarse:min-h-11`
|
|
18
|
+
* (44px), so a finger gets a 44px control at any size while a mouse keeps the
|
|
19
|
+
* dense ladder. It is a utility on the control, not a token override: presets
|
|
20
|
+
* redefine `--control-h-*` unlayered and would win over a token override in
|
|
21
|
+
* the base layer. `min-height` beats `height`, so every rung rises together
|
|
22
|
+
* and a row of `Input` / `Select` / `Button` still lines up on a phone.
|
|
17
23
|
* - `button`: horizontal padding and type size of a `Button` at this size.
|
|
18
24
|
* - `field`: horizontal and vertical padding and type size of a text field.
|
|
19
25
|
* `default` keeps `text-base md:text-sm` so a phone does not zoom on focus.
|
|
@@ -22,26 +28,26 @@ import { cn } from '../../lib/utils';
|
|
|
22
28
|
*/
|
|
23
29
|
export const CONTROL_SIZE = {
|
|
24
30
|
xs: {
|
|
25
|
-
height: 'h-(--control-h-xs)',
|
|
26
|
-
minHeight: 'min-h-(--control-h-xs)',
|
|
31
|
+
height: 'h-(--control-h-xs) pointer-coarse:min-h-11',
|
|
32
|
+
minHeight: 'min-h-(--control-h-xs) pointer-coarse:min-h-11',
|
|
27
33
|
button: 'px-2 py-1 text-xs',
|
|
28
34
|
field: 'px-2 py-0.5 text-xs',
|
|
29
35
|
},
|
|
30
36
|
sm: {
|
|
31
|
-
height: 'h-(--control-h-sm)',
|
|
32
|
-
minHeight: 'min-h-(--control-h-sm)',
|
|
37
|
+
height: 'h-(--control-h-sm) pointer-coarse:min-h-11',
|
|
38
|
+
minHeight: 'min-h-(--control-h-sm) pointer-coarse:min-h-11',
|
|
33
39
|
button: 'px-3 text-sm',
|
|
34
40
|
field: 'px-2.5 py-1 text-sm',
|
|
35
41
|
},
|
|
36
42
|
default: {
|
|
37
|
-
height: 'h-(--control-h-default)',
|
|
38
|
-
minHeight: 'min-h-(--control-h-default)',
|
|
43
|
+
height: 'h-(--control-h-default) pointer-coarse:min-h-11',
|
|
44
|
+
minHeight: 'min-h-(--control-h-default) pointer-coarse:min-h-11',
|
|
39
45
|
button: 'px-4 py-2',
|
|
40
46
|
field: 'px-3 py-1 text-base md:text-sm',
|
|
41
47
|
},
|
|
42
48
|
lg: {
|
|
43
|
-
height: 'h-(--control-h-lg)',
|
|
44
|
-
minHeight: 'min-h-(--control-h-lg)',
|
|
49
|
+
height: 'h-(--control-h-lg) pointer-coarse:min-h-11',
|
|
50
|
+
minHeight: 'min-h-(--control-h-lg) pointer-coarse:min-h-11',
|
|
45
51
|
button: 'px-8',
|
|
46
52
|
field: 'px-4 py-2 text-base',
|
|
47
53
|
},
|
|
@@ -99,10 +99,10 @@ export const INPUT_CLASS = inputClass('default');
|
|
|
99
99
|
* Textarea styling — shares the SAME border/surface/focus base as inputs (one
|
|
100
100
|
* source of truth) with multi-line height/padding instead of a fixed height.
|
|
101
101
|
*/
|
|
102
|
-
export const TEXTAREA_CLASS = cn(INPUT_BASE, 'min-h-[60px] px-3 py-2 text-sm');
|
|
102
|
+
export const TEXTAREA_CLASS = cn(INPUT_BASE, 'min-h-[60px] px-3 py-2 text-base md:text-sm');
|
|
103
103
|
|
|
104
104
|
/** `TEXTAREA_CLASS` without the field's own edge — for use inside `InputGroup`. */
|
|
105
|
-
export const TEXTAREA_BARE_CLASS = cn(INPUT_CORE, 'min-h-[60px] py-3 text-sm');
|
|
105
|
+
export const TEXTAREA_BARE_CLASS = cn(INPUT_CORE, 'min-h-[60px] py-3 text-base md:text-sm');
|
|
106
106
|
|
|
107
107
|
const Input = React.forwardRef<HTMLInputElement, InputProps>(
|
|
108
108
|
({ className, type, storageKey, storageType, storageTtl, inputSize = 'default', bare = false, onChange, defaultValue, value, ...props }, ref) => {
|
|
@@ -284,6 +284,9 @@ const TabsList = React.forwardRef<
|
|
|
284
284
|
const sizing = resolvedSize === 'sm'
|
|
285
285
|
? { track: 'h-8 p-0.5', gap: 'gap-0.5', inset: '0.125rem' }
|
|
286
286
|
: { track: 'h-9 p-1', gap: 'gap-1', inset: '0.25rem' }
|
|
287
|
+
// A finger needs a 44px trigger. The track grows around it (44px + 2px padding each side) instead of the trigger
|
|
288
|
+
// being squeezed to what a 28-36px track leaves.
|
|
289
|
+
const touchTrack = 'pointer-coarse:h-12 pointer-coarse:p-0.5'
|
|
287
290
|
|
|
288
291
|
const listCls = cn(
|
|
289
292
|
isUnderline
|
|
@@ -291,6 +294,7 @@ const TabsList = React.forwardRef<
|
|
|
291
294
|
: cn(
|
|
292
295
|
"inline-flex items-center justify-center bg-muted text-muted-foreground",
|
|
293
296
|
sizing.track,
|
|
297
|
+
touchTrack,
|
|
294
298
|
sizing.gap,
|
|
295
299
|
isPill ? "rounded-full" : "rounded-[var(--radius)]",
|
|
296
300
|
isPill && "tabs-sliding",
|
|
@@ -396,6 +400,8 @@ const TabsTrigger = React.forwardRef<
|
|
|
396
400
|
? "relative rounded-full bg-transparent transition-colors duration-150 hover:text-foreground/80 data-[state=active]:bg-transparent data-[state=active]:shadow-none"
|
|
397
401
|
: "rounded-[var(--radius-sm)] transition-all data-[state=active]:bg-background data-[state=active]:shadow",
|
|
398
402
|
].join(" "),
|
|
403
|
+
// Touch: 44px tall for every variant (`TabsList` leaves room for it).
|
|
404
|
+
"pointer-coarse:min-h-11",
|
|
399
405
|
flexEqual && "flex-1",
|
|
400
406
|
className
|
|
401
407
|
)}
|
|
@@ -71,7 +71,9 @@ const SelectTrigger = React.forwardRef<
|
|
|
71
71
|
<SelectPrimitive.Trigger
|
|
72
72
|
ref={ref}
|
|
73
73
|
className={cn(
|
|
74
|
-
"flex items-center justify-between whitespace-nowrap
|
|
74
|
+
"flex items-center justify-between whitespace-nowrap ring-offset-background data-[placeholder]:text-muted-foreground focus:outline-none disabled:cursor-not-allowed disabled:opacity-50",
|
|
75
|
+
// Same type size as `Input`: 16px on a phone (no iOS zoom, same line as the field beside it), 14px from `md`.
|
|
76
|
+
variant === "default" ? "text-base md:text-sm" : "text-sm",
|
|
75
77
|
variant === "default" &&
|
|
76
78
|
cn(
|
|
77
79
|
CONTROL_SIZE[size].height,
|
package/src/hooks/media/index.ts
CHANGED
|
@@ -9,4 +9,5 @@ export { useDisplayMode, useIsPwa } from './useDisplayMode';
|
|
|
9
9
|
export { detectDisplayMode, syncDisplayModeAttribute } from './displayMode';
|
|
10
10
|
export type { DisplayMode } from './displayMode';
|
|
11
11
|
export { syncAppHeight, measureAppHeight } from './appHeight';
|
|
12
|
+
export { syncScrollReset, resetShellScroll } from './scrollReset';
|
|
12
13
|
export { useBlockGestureZoom } from './useBlockGestureZoom';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Brings a locked app shell back to scroll 0 once the on-screen keyboard is gone.
|
|
3
|
+
*
|
|
4
|
+
* Why: `PrivateLayout` locks the document (`overflow: hidden`, `data-private-shell`) and sizes itself from `--app-height`,
|
|
5
|
+
* which in an installed iOS app is deliberately taller than `window.innerHeight` (see `appHeight.ts`). `overflow: hidden`
|
|
6
|
+
* stops the finger, not the browser: focusing a field makes iOS scroll the layout viewport (and any clipped ancestor) so
|
|
7
|
+
* the field clears the keyboard, and after the keyboard closes it does not scroll back. The top bar is then left above
|
|
8
|
+
* the screen with nothing the reader can drag to reach it. While the keyboard is up the offset is how iOS shows the
|
|
9
|
+
* field, so it is left alone; once it is down (focus left a field, or the visual viewport is whole again) it is reset.
|
|
10
|
+
* A pinch-zoomed page (`visualViewport.scale > 1`) is the reader's own offset and is never touched.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { detectDisplayMode, isInstalledMode } from './displayMode';
|
|
14
|
+
|
|
15
|
+
/** Elements that clip the shell and can be scrolled by focus although the reader cannot: `[data-app-shell]`. */
|
|
16
|
+
const SHELL = '[data-app-shell]';
|
|
17
|
+
|
|
18
|
+
function locked(): boolean {
|
|
19
|
+
return document.documentElement.hasAttribute('data-private-shell') && isInstalledMode(detectDisplayMode());
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function editable(el: Element | null): boolean {
|
|
23
|
+
if (!el) return false;
|
|
24
|
+
if (el instanceof HTMLElement && el.isContentEditable) return true;
|
|
25
|
+
return el instanceof HTMLTextAreaElement || el instanceof HTMLSelectElement || (el instanceof HTMLInputElement && !/^(checkbox|radio|button|submit|reset|range|file|color|image)$/.test(el.type));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** True while the keyboard (or any other inset) is covering part of the layout viewport. */
|
|
29
|
+
function keyboardUp(): boolean {
|
|
30
|
+
const vv = window.visualViewport;
|
|
31
|
+
return Boolean(vv) && window.innerHeight - vv!.height > 80;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function resetShellScroll(): void {
|
|
35
|
+
if (!locked() || keyboardUp()) return;
|
|
36
|
+
if (window.visualViewport && window.visualViewport.scale > 1.01) return;
|
|
37
|
+
if (window.scrollX || window.scrollY) window.scrollTo(0, 0);
|
|
38
|
+
for (const el of document.querySelectorAll<HTMLElement>(SHELL)) {
|
|
39
|
+
if (el.scrollTop) el.scrollTop = 0;
|
|
40
|
+
if (el.scrollLeft) el.scrollLeft = 0;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Installs the reset on focus-out and on visual-viewport changes. Returns a cleanup. */
|
|
45
|
+
export function syncScrollReset(): () => void {
|
|
46
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') return () => {};
|
|
47
|
+
const timers: number[] = [];
|
|
48
|
+
// The keyboard takes ~250-400ms to go down and iOS reports the final size late: look again as it settles.
|
|
49
|
+
const settle = () => {
|
|
50
|
+
resetShellScroll();
|
|
51
|
+
timers.push(window.setTimeout(resetShellScroll, 150), window.setTimeout(resetShellScroll, 450));
|
|
52
|
+
};
|
|
53
|
+
const onFocusOut = (event: FocusEvent) => {
|
|
54
|
+
if (editable(event.target as Element | null) && !editable(event.relatedTarget as Element | null)) settle();
|
|
55
|
+
};
|
|
56
|
+
const vv = window.visualViewport;
|
|
57
|
+
document.addEventListener('focusout', onFocusOut);
|
|
58
|
+
vv?.addEventListener('resize', settle);
|
|
59
|
+
window.addEventListener('orientationchange', settle);
|
|
60
|
+
return () => {
|
|
61
|
+
document.removeEventListener('focusout', onFocusOut);
|
|
62
|
+
vv?.removeEventListener('resize', settle);
|
|
63
|
+
window.removeEventListener('orientationchange', settle);
|
|
64
|
+
timers.forEach((t) => window.clearTimeout(t));
|
|
65
|
+
};
|
|
66
|
+
}
|
package/src/lib/env.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
* Pure environment constants — shared across all @djangocfg UI packages.
|
|
3
3
|
*
|
|
4
4
|
* Keep this to framework-agnostic env primitives only. Feature flags that carry
|
|
5
|
-
* domain meaning (e.g.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* domain meaning (e.g. static-build behaviour) live in the package that owns
|
|
6
|
+
* them — `isStaticBuild` is exported from `@djangocfg/api` (the lowest shared
|
|
7
|
+
* package).
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
export const nodeEnv = process.env.NODE_ENV || 'development';
|
|
@@ -8,6 +8,7 @@ import { Toaster } from '../components/feedback/sonner';
|
|
|
8
8
|
import { Boundary, type BoundaryProps } from '../components/boundary';
|
|
9
9
|
import { syncDisplayModeAttribute } from '../hooks/media/displayMode';
|
|
10
10
|
import { syncAppHeight } from '../hooks/media/appHeight';
|
|
11
|
+
import { syncScrollReset } from '../hooks/media/scrollReset';
|
|
11
12
|
import { installChunkReloadListeners } from '../lib/chunk-reload';
|
|
12
13
|
import { DialogProvider } from '../lib/dialog-service/DialogProvider';
|
|
13
14
|
|
|
@@ -91,6 +92,8 @@ export function UiProviders({
|
|
|
91
92
|
React.useEffect(() => syncDisplayModeAttribute(), []);
|
|
92
93
|
// `--app-height` measured in an installed app (iOS standalone reports dvh/100% short; see hooks/media/appHeight).
|
|
93
94
|
React.useEffect(() => syncAppHeight(), []);
|
|
95
|
+
// A locked app shell is scrolled by iOS to clear the keyboard and not scrolled back; put it back once the keyboard is down.
|
|
96
|
+
React.useEffect(() => syncScrollReset(), []);
|
|
94
97
|
// No SSR-skip on purpose: any nested library component that renders
|
|
95
98
|
// `<Tooltip>` on its first paint expects to find `<TooltipProvider>`
|
|
96
99
|
// already in the tree. Skipping the provider during SSR caused
|