@podoba/react 0.0.53 → 0.0.54
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": "@podoba/react",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.54",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "podoba React components — React Aria Components + Tailwind primitives + layout, built with uic.",
|
|
6
6
|
"repository": {
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"typecheck": "tsc --build"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@podoba/tokens": "^0.0.
|
|
32
|
-
"@podoba/tailwind": "^0.0.
|
|
31
|
+
"@podoba/tokens": "^0.0.54",
|
|
32
|
+
"@podoba/tailwind": "^0.0.54",
|
|
33
33
|
"react-aria-components": "1.20.0",
|
|
34
34
|
"class-variance-authority": "0.7.1",
|
|
35
35
|
"clsx": "2.1.1",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react'
|
|
2
|
+
|
|
3
|
+
/** Wait until dialog focus scopes and slotted controls have mounted. */
|
|
4
|
+
export function useFieldAutoFocus(autoFocus: boolean | undefined) {
|
|
5
|
+
const ref = useRef<HTMLDivElement>(null)
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!autoFocus) return
|
|
8
|
+
const frame = requestAnimationFrame(() => {
|
|
9
|
+
const control = ref.current?.querySelector<HTMLInputElement | HTMLTextAreaElement>('input, textarea')
|
|
10
|
+
if (!control || control.disabled) return
|
|
11
|
+
const active = control.ownerDocument.activeElement
|
|
12
|
+
// Do not steal focus if the user or another field has already claimed it.
|
|
13
|
+
if (
|
|
14
|
+
active === control.ownerDocument.body ||
|
|
15
|
+
active === control.closest('[role="dialog"], [role="alertdialog"]')
|
|
16
|
+
) {
|
|
17
|
+
control.focus({ preventScroll: true })
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
return () => cancelAnimationFrame(frame)
|
|
21
|
+
}, [autoFocus])
|
|
22
|
+
return ref
|
|
23
|
+
}
|
package/src/components/input.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useFieldAutoFocus } from './field-autofocus'
|
|
1
2
|
import type { ReactNode } from 'react'
|
|
2
3
|
import { FieldError, Input as RACInput, Label, Text, TextField, type TextFieldProps } from 'react-aria-components'
|
|
3
4
|
import { uic } from '../utils/uic'
|
|
@@ -79,21 +80,23 @@ export const Input = ({
|
|
|
79
80
|
inputClassName,
|
|
80
81
|
autoFocus,
|
|
81
82
|
...props
|
|
82
|
-
}: InputProps) =>
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
<
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
{
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
83
|
+
}: InputProps) => {
|
|
84
|
+
const fieldRef = useFieldAutoFocus(autoFocus)
|
|
85
|
+
return (
|
|
86
|
+
<TextField {...props} ref={fieldRef} className={`${fieldStackClass} w-full ${rootClassName ?? ''}`}>
|
|
87
|
+
<Label className={fieldLabelClasses[labelSize]}>{label}</Label>
|
|
88
|
+
<StyledInput
|
|
89
|
+
className={inputClassName}
|
|
90
|
+
placeholder={placeholder}
|
|
91
|
+
appearance={appearance}
|
|
92
|
+
fieldSize={size ?? (appearance === 'filled' ? 'filled' : undefined)}
|
|
93
|
+
/>
|
|
94
|
+
{description ? (
|
|
95
|
+
<Text slot="description" className={fieldDescriptionClass}>
|
|
96
|
+
{description}
|
|
97
|
+
</Text>
|
|
98
|
+
) : null}
|
|
99
|
+
<FieldError className={fieldErrorClass}>{errorMessage}</FieldError>
|
|
100
|
+
</TextField>
|
|
101
|
+
)
|
|
102
|
+
}
|
|
@@ -290,6 +290,7 @@ export function WizardFormDialog({
|
|
|
290
290
|
isPending = false,
|
|
291
291
|
isExpanded = false,
|
|
292
292
|
title,
|
|
293
|
+
ariaLabel,
|
|
293
294
|
closeLabel,
|
|
294
295
|
children,
|
|
295
296
|
footer,
|
|
@@ -299,6 +300,8 @@ export function WizardFormDialog({
|
|
|
299
300
|
isPending?: boolean
|
|
300
301
|
isExpanded?: boolean
|
|
301
302
|
title: ReactNode
|
|
303
|
+
/** Stable accessible name when the visual heading changes between steps. */
|
|
304
|
+
ariaLabel?: string
|
|
302
305
|
closeLabel: string
|
|
303
306
|
children: ReactNode
|
|
304
307
|
footer: ReactNode
|
|
@@ -318,7 +321,11 @@ export function WizardFormDialog({
|
|
|
318
321
|
data-wizard-expanded={isExpanded}
|
|
319
322
|
className={`h-23/25 max-h-23/25 w-24/25 max-w-24/25 min-[901px]:h-9/10 min-[901px]:max-h-288 min-[901px]:w-9/10 ${isExpanded ? 'min-[901px]:max-w-432' : 'min-[901px]:max-w-204'}`}
|
|
320
323
|
>
|
|
321
|
-
<Layout
|
|
324
|
+
<Layout
|
|
325
|
+
aria-label={ariaLabel}
|
|
326
|
+
aria-labelledby={ariaLabel ? undefined : titleId}
|
|
327
|
+
className="gap-8 py-6 min-[901px]:gap-10 min-[901px]:py-10"
|
|
328
|
+
>
|
|
322
329
|
<Button
|
|
323
330
|
variant="ghost"
|
|
324
331
|
aria-label={closeLabel}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useFieldAutoFocus } from './field-autofocus'
|
|
1
2
|
import {
|
|
2
3
|
useId,
|
|
3
4
|
useRef,
|
|
@@ -80,29 +81,31 @@ export const Textarea = ({
|
|
|
80
81
|
appearance = 'outlined',
|
|
81
82
|
autoFocus,
|
|
82
83
|
...props
|
|
83
|
-
}: TextareaProps) =>
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
<
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
{
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
84
|
+
}: TextareaProps) => {
|
|
85
|
+
const fieldRef = useFieldAutoFocus(autoFocus)
|
|
86
|
+
return (
|
|
87
|
+
// Label and gap match `Input` in both appearances (gs 17px/20px field label,
|
|
88
|
+
// 12px to the control), so a Title + Description pair reads as one form.
|
|
89
|
+
<TextField {...props} ref={fieldRef} className={`${fieldStackClass} w-full`}>
|
|
90
|
+
<Label className={fieldLabelClasses[labelSize]}>{label}</Label>
|
|
91
|
+
<StyledTextArea
|
|
92
|
+
ref={textAreaRef}
|
|
93
|
+
onKeyDown={onTextAreaKeyDown}
|
|
94
|
+
onInput={onTextAreaInput}
|
|
95
|
+
className={textAreaClassName}
|
|
96
|
+
placeholder={placeholder}
|
|
97
|
+
rows={rows}
|
|
98
|
+
appearance={appearance}
|
|
99
|
+
/>
|
|
100
|
+
{description ? (
|
|
101
|
+
<Text slot="description" className={fieldDescriptionClass}>
|
|
102
|
+
{description}
|
|
103
|
+
</Text>
|
|
104
|
+
) : null}
|
|
105
|
+
<FieldError className={fieldErrorClass}>{errorMessage}</FieldError>
|
|
106
|
+
</TextField>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
106
109
|
|
|
107
110
|
export interface MentionTextareaProps {
|
|
108
111
|
id?: string
|