@kolkrabbi/kol-component 0.308.0 → 0.309.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kolkrabbi/kol-component",
3
- "version": "0.308.0",
3
+ "version": "0.309.0",
4
4
  "description": "The core component library",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -38,7 +38,7 @@
38
38
  "react-dom": "^18.3.0 || ^19.0.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@kolkrabbi/kol-icons": "^0.50.0"
41
+ "@kolkrabbi/kol-icons": "^0.51.0"
42
42
  },
43
43
  "files": [
44
44
  "src",
@@ -1,6 +1,8 @@
1
1
  import { useState } from 'react'
2
2
 
3
3
  const SIZE_MAP = {
4
+ /* xs — a rail glyph's 20 (HubAccountRow, kol-fxr 2026-10-28: the signed-in row draws the user where the glyph sits) */
5
+ xs: 'w-5 h-5 kol-helper-10',
4
6
  sm: 'w-8 h-8 kol-helper-12',
5
7
  md: 'w-10 h-10 kol-helper-14',
6
8
  lg: 'w-14 h-14 kol-helper-16',
@@ -21,7 +23,7 @@ const SIZE_MAP = {
21
23
  * @param {string} [src] resolved image src — the consumer resolves it, this
22
24
  * atom never builds a URL
23
25
  * @param {string} [alt=''] photo alt text
24
- * @param {'sm'|'md'|'lg'|'xl'} [size='sm']
26
+ * @param {'xs'|'sm'|'md'|'lg'|'xl'} [size='sm'] `xs` is 20, a rail row's glyph
25
27
  */
26
28
  export default function Avatar({ initial, src, alt = '', size = 'sm', className = '' }) {
27
29
  const sizeCls = SIZE_MAP[size] ?? SIZE_MAP.sm
@@ -23,6 +23,15 @@ import ToggleCheckbox from '../atoms/ToggleCheckbox.jsx'
23
23
  * masks the field (`autoComplete="current-password"`) for the family's sign-in prompts. The
24
24
  * native fallback cannot mask — mount a ModalProvider. `placeholder` sits in the same options.
25
25
  *
26
+ * FORM (HubAccountRow, kol-fxr 2026-10-28 — sign-in asks Email AND Password): `form(title, fields, { okLabel, cancelLabel })`
27
+ * draws one field per `{ id, placeholder, type?, autoComplete?, defaultValue? }` and resolves `{ [id]: value }` on submit,
28
+ * `null` on cancel. The first field takes the focus; Enter in any field submits.
29
+ *
30
+ * THE PAGE HOLDS STILL UNDER THE KEYBOARD (PromptHoldsWithKeyboard, kol-fxr 2026-10-28 — user: *"does the UI have to move
31
+ * upp to show keyboard?"*): every dialog sits in the VISUAL viewport (`visualViewport` resize/scroll), so on an iPhone it
32
+ * rides above the keyboard; a field takes its focus without scrolling (`preventScroll`), and the document's scroll is put
33
+ * back when the keyboard closes and when the dialog does.
34
+ *
26
35
  * KEYBOARD: the dialog opens focused (prompt → its field, confirm/alert → OK), Tab cycles inside
27
36
  * it, and Enter on a focused button presses that button rather than submitting.
28
37
  *
@@ -77,8 +86,12 @@ export function ModalProvider({ children }) {
77
86
  new Promise((resolve) => setState({ kind: 'alert', title, okLabel, resolve })),
78
87
  [])
79
88
 
89
+ const form = useCallback((title, fields = [], { okLabel, cancelLabel } = {}) =>
90
+ new Promise((resolve) => setState({ kind: 'form', title, fields, okLabel, cancelLabel, resolve })),
91
+ [])
92
+
80
93
  return (
81
- <ModalCtx.Provider value={{ prompt, confirm, alert }}>
94
+ <ModalCtx.Provider value={{ prompt, confirm, alert, form }}>
82
95
  {children}
83
96
  {state && typeof document !== 'undefined' && createPortal(
84
97
  <ModalView state={state} closeWith={closeWith} />,
@@ -91,18 +104,47 @@ export function ModalProvider({ children }) {
91
104
  function ModalView({ state, closeWith }) {
92
105
  const [val, setVal] = useState(state.defaultValue ?? '')
93
106
  const [values, setValues] = useState(() => Object.fromEntries((state.options ?? []).map((o) => [o.id, !!o.defaultValue])))
107
+ const [fieldVals, setFieldVals] = useState(() => Object.fromEntries((state.fields ?? []).map((f) => [f.id, f.defaultValue ?? ''])))
94
108
  const inputRef = useRef(null)
95
109
  const dialogRef = useRef(null)
110
+ const overlayRef = useRef(null)
111
+ const typing = state.kind === 'prompt' || state.kind === 'form'
112
+
113
+ /* the visual viewport (PromptHoldsWithKeyboard): the scrim is sized to it, so the dialog centres above the keyboard
114
+ * instead of the browser scrolling the page to clear it; the scroll the page had is restored when the keyboard goes
115
+ * (the visual viewport back to full height) and when the dialog closes */
116
+ useEffect(() => {
117
+ if (typeof window === 'undefined') return undefined
118
+ const y0 = window.scrollY
119
+ const vv = window.visualViewport
120
+ const fit = () => {
121
+ const el = overlayRef.current
122
+ if (!vv || !el) return
123
+ el.style.top = `${vv.offsetTop}px`
124
+ el.style.left = `${vv.offsetLeft}px`
125
+ el.style.width = `${vv.width}px`
126
+ el.style.height = `${vv.height}px`
127
+ if (vv.height >= window.innerHeight - 1 && window.scrollY !== y0) window.scrollTo(0, y0)
128
+ }
129
+ fit()
130
+ vv?.addEventListener('resize', fit)
131
+ vv?.addEventListener('scroll', fit)
132
+ return () => {
133
+ vv?.removeEventListener('resize', fit)
134
+ vv?.removeEventListener('scroll', fit)
135
+ if (window.scrollY !== y0) window.scrollTo(0, y0)
136
+ }
137
+ }, [])
96
138
 
97
139
  /* alert resolves `undefined` whichever way it is dismissed; a confirm with toggles resolves
98
140
  * `{ ok, values }` */
99
141
  const answer = (ok) => (state.options ? { ok, values } : ok)
100
- const submit = () => closeWith(state.kind === 'prompt' ? val : state.kind === 'alert' ? undefined : answer(true))
101
- const cancel = () => closeWith(state.kind === 'prompt' ? null : state.kind === 'alert' ? undefined : answer(false))
142
+ const submit = () => closeWith(state.kind === 'prompt' ? val : state.kind === 'form' ? fieldVals : state.kind === 'alert' ? undefined : answer(true))
143
+ const cancel = () => closeWith(typing ? null : state.kind === 'alert' ? undefined : answer(false))
102
144
 
103
145
  /* focus once on open — the key effect below re-runs per keystroke and would steal it back */
104
146
  useEffect(() => {
105
- if (state.kind === 'prompt') inputRef.current?.focus()
147
+ if (typing) inputRef.current?.focus({ preventScroll: true })
106
148
  else dialogRef.current?.querySelector('[data-modal-ok]')?.focus()
107
149
  }, [state.kind])
108
150
 
@@ -121,10 +163,11 @@ function ModalView({ state, closeWith }) {
121
163
  }
122
164
  window.addEventListener('keydown', onKey)
123
165
  return () => window.removeEventListener('keydown', onKey)
124
- }, [state.kind, val, values, closeWith]) // eslint-disable-line react-hooks/exhaustive-deps
166
+ }, [state.kind, val, values, fieldVals, closeWith]) // eslint-disable-line react-hooks/exhaustive-deps
125
167
 
126
168
  return (
127
169
  <div
170
+ ref={overlayRef}
128
171
  onMouseDown={cancel}
129
172
  /* THE scrim (overlay-scrim-outliers sweep, 2026-09-03): the docs said Modal
130
173
  wore `.kol-overlay-scrim`; the source drew a raw `rgba(0,0,0,0.5)`. The
@@ -137,7 +180,7 @@ function ModalView({ state, closeWith }) {
137
180
  >
138
181
  <div
139
182
  ref={dialogRef}
140
- role={state.kind === 'prompt' ? 'dialog' : 'alertdialog'}
183
+ role={typing ? 'dialog' : 'alertdialog'}
141
184
  aria-modal="true"
142
185
  aria-labelledby="kol-modal-title"
143
186
  onMouseDown={(e) => e.stopPropagation()}
@@ -166,6 +209,21 @@ function ModalView({ state, closeWith }) {
166
209
  className="w-full"
167
210
  />
168
211
  )}
212
+ {state.kind === 'form' && state.fields.map((f, i) => (
213
+ <Input
214
+ key={f.id}
215
+ ref={i === 0 ? inputRef : undefined}
216
+ type={f.type ?? 'text'}
217
+ autoComplete={f.autoComplete}
218
+ placeholder={f.placeholder}
219
+ aria-label={f.placeholder ?? f.id}
220
+ variant="outline"
221
+ size="sm"
222
+ value={fieldVals[f.id]}
223
+ onChange={(e) => setFieldVals((v) => ({ ...v, [f.id]: e.target.value }))}
224
+ className="w-full"
225
+ />
226
+ ))}
169
227
  {state.options && (
170
228
  <div className="flex flex-col gap-3">
171
229
  {state.options.map((o) => (