@podoba/react 0.0.52 → 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.
Files changed (35) hide show
  1. package/package.json +4 -4
  2. package/src/components/asset-selection-surface.tsx +264 -67
  3. package/src/components/citation.examples.tsx +14 -0
  4. package/src/components/citation.tsx +27 -0
  5. package/src/components/column-layout.examples.tsx +34 -0
  6. package/src/components/column-layout.tsx +36 -0
  7. package/src/components/combobox.tsx +9 -4
  8. package/src/components/compact-settings-dialog.tsx +80 -21
  9. package/src/components/date-picker.tsx +49 -8
  10. package/src/components/delivery/send-to-print-modal.tsx +191 -225
  11. package/src/components/field-appearance.ts +11 -1
  12. package/src/components/field-autofocus.ts +23 -0
  13. package/src/components/icon-button.examples.tsx +16 -0
  14. package/src/components/icon-button.tsx +20 -0
  15. package/src/components/input.tsx +37 -21
  16. package/src/components/island-toolbar.examples.tsx +27 -0
  17. package/src/components/island-toolbar.tsx +39 -0
  18. package/src/components/media-asset-panel.examples.tsx +44 -5
  19. package/src/components/media-asset-panel.tsx +339 -28
  20. package/src/components/media-collection.examples.tsx +18 -0
  21. package/src/components/media-collection.tsx +206 -0
  22. package/src/components/number-field.tsx +18 -9
  23. package/src/components/preview-error.examples.tsx +20 -0
  24. package/src/components/preview-error.tsx +29 -0
  25. package/src/components/preview-metadata-card.examples.tsx +32 -0
  26. package/src/components/preview-metadata-card.tsx +112 -0
  27. package/src/components/search-field.tsx +27 -7
  28. package/src/components/select.tsx +81 -50
  29. package/src/components/settings-dialog-surface.tsx +560 -114
  30. package/src/components/template-catalog-card.tsx +309 -78
  31. package/src/components/textarea.tsx +174 -23
  32. package/src/components/tile.tsx +30 -16
  33. package/src/components/zoomable-image.examples.tsx +33 -0
  34. package/src/components/zoomable-image.tsx +185 -0
  35. package/src/index.ts +96 -78
@@ -0,0 +1,206 @@
1
+ import { useState, type ReactNode } from 'react'
2
+ import { Button as RACButton } from 'react-aria-components'
3
+ import { Button } from './button'
4
+ import { MediaReadableText, type MediaTextAppearance } from './media-asset-panel'
5
+ import { IslandToolbar, IslandToolbarButton } from './island-toolbar'
6
+ import { ModalOverlay, ModalSurface, ModalDialog } from './dialog'
7
+ import { uic } from '../utils/uic'
8
+
9
+ export const MediaPreviewScene = uic('div', {
10
+ displayName: 'MediaPreviewScene',
11
+ baseClass: 'relative grid min-h-0 min-w-0 place-items-center overflow-hidden p-5',
12
+ style: {
13
+ background:
14
+ 'radial-gradient(circle at 50% 42%, color-mix(in srgb, var(--color-surface) 8%, transparent) 0, transparent 42%), color-mix(in srgb, var(--color-fg) 84%, var(--color-surface))',
15
+ },
16
+ })
17
+ const Panel = uic(RACButton, {
18
+ displayName: 'MediaPanelCard',
19
+ baseClass:
20
+ 'relative isolate flex min-h-60 w-full cursor-pointer flex-col justify-between overflow-hidden rounded-lg bg-surface-card p-5 text-start outline-none data-[focus-visible]:ring-2 data-[focus-visible]:ring-ring',
21
+ })
22
+ /** Asset-dashboard panel composition. Text and crop are measured together. */
23
+ export function MediaPanelCard({
24
+ title,
25
+ caption,
26
+ preview,
27
+ onOpen,
28
+ textAppearance,
29
+ }: {
30
+ title: string
31
+ caption?: string
32
+ textAppearance?: { title?: MediaTextAppearance; caption?: MediaTextAppearance }
33
+ preview: ReactNode
34
+ onOpen: () => void
35
+ }) {
36
+ return (
37
+ <Panel onPress={onOpen} aria-label={title} data-media-readability>
38
+ <div aria-hidden="true" className="absolute inset-0 -z-20">
39
+ {preview}
40
+ </div>
41
+ <MediaReadableText appearance={textAppearance?.title}>
42
+ <strong className="text-panel-heading font-medium">{title}</strong>
43
+ </MediaReadableText>
44
+ {caption ? (
45
+ <MediaReadableText secondary appearance={textAppearance?.caption}>
46
+ <span className="text-label font-normal">{caption}</span>
47
+ </MediaReadableText>
48
+ ) : null}
49
+ </Panel>
50
+ )
51
+ }
52
+ export interface MediaCarouselItem {
53
+ id: string
54
+ title: string
55
+ caption?: string
56
+ preview: ReactNode
57
+ }
58
+ export function MediaCarousel({
59
+ items,
60
+ label,
61
+ previousLabel,
62
+ nextLabel,
63
+ onOpen,
64
+ }: {
65
+ items: readonly MediaCarouselItem[]
66
+ label: string
67
+ previousLabel: string
68
+ nextLabel: string
69
+ onOpen?: (index: number) => void
70
+ }) {
71
+ const [picked, setPicked] = useState(0),
72
+ index = Math.min(picked, Math.max(0, items.length - 1)),
73
+ item = items[index]
74
+ if (!item) return null
75
+ const go = (next: number) => setPicked(Math.max(0, Math.min(items.length - 1, next)))
76
+ return (
77
+ <div
78
+ role="group"
79
+ aria-label={label}
80
+ tabIndex={0}
81
+ className="relative overflow-hidden rounded-lg bg-surface-muted outline-none focus-visible:ring-2 focus-visible:ring-ring"
82
+ onKeyDown={(event) => {
83
+ if (event.key === 'ArrowLeft') {
84
+ event.preventDefault()
85
+ go(index - 1)
86
+ }
87
+ if (event.key === 'ArrowRight') {
88
+ event.preventDefault()
89
+ go(index + 1)
90
+ }
91
+ }}
92
+ >
93
+ <div className="grid aspect-3/2 min-w-0 place-items-center px-12 py-8">
94
+ {onOpen ? (
95
+ <Button
96
+ variant="ghost"
97
+ aria-label={item.title}
98
+ onPress={() => onOpen(index)}
99
+ className="h-full min-h-0 w-full p-0 hover:bg-transparent"
100
+ >
101
+ {item.preview}
102
+ </Button>
103
+ ) : (
104
+ item.preview
105
+ )}
106
+ </div>
107
+ <div className="pointer-events-none absolute bottom-5 start-5 max-w-3/4 rounded-lg bg-surface p-4 text-fg">
108
+ <p className="m-0 text-label font-normal text-fg-muted">{item.caption ?? label}</p>
109
+ <p className="m-0 mt-2 text-small font-medium">{item.title}</p>
110
+ <p className="m-0 mt-2 text-label text-fg-muted" aria-live="polite">
111
+ {index + 1} / {items.length}
112
+ </p>
113
+ </div>
114
+ {index > 0 ? (
115
+ <Button
116
+ variant="ghost"
117
+ aria-label={previousLabel}
118
+ onPress={() => go(index - 1)}
119
+ className="absolute start-3 top-1/2 h-7 w-7 -translate-y-1/2 rounded-full bg-surface p-0 text-fg-muted shadow-md"
120
+ >
121
+ ‹
122
+ </Button>
123
+ ) : null}
124
+ {index < items.length - 1 ? (
125
+ <Button
126
+ variant="ghost"
127
+ aria-label={nextLabel}
128
+ onPress={() => go(index + 1)}
129
+ className="absolute end-3 top-1/2 h-7 w-7 -translate-y-1/2 rounded-full bg-surface p-0 text-fg-muted shadow-md"
130
+ >
131
+ ›
132
+ </Button>
133
+ ) : null}
134
+ </div>
135
+ )
136
+ }
137
+ export function MediaLightbox({
138
+ isOpen,
139
+ onOpenChange,
140
+ title,
141
+ caption,
142
+ preview,
143
+ index,
144
+ total,
145
+ onPrevious,
146
+ onNext,
147
+ previousLabel,
148
+ nextLabel,
149
+ closeLabel,
150
+ }: {
151
+ isOpen: boolean
152
+ onOpenChange: (open: boolean) => void
153
+ title: string
154
+ caption?: string
155
+ preview: ReactNode
156
+ index: number
157
+ total: number
158
+ onPrevious: () => void
159
+ onNext: () => void
160
+ previousLabel: string
161
+ nextLabel: string
162
+ closeLabel: string
163
+ }) {
164
+ return (
165
+ <ModalOverlay isOpen={isOpen} onOpenChange={onOpenChange} isDismissable>
166
+ <ModalSurface className="h-[90dvh] w-24/25 max-w-360 overflow-hidden p-0">
167
+ <ModalDialog aria-label={title} className="relative h-full outline-none">
168
+ <MediaPreviewScene className="h-full px-6 pb-32 pt-6">{preview}</MediaPreviewScene>
169
+ <div className="absolute bottom-6 start-6 max-w-3/4 rounded-lg bg-surface p-4 text-fg">
170
+ <p className="m-0 text-label text-fg-muted">
171
+ {index + 1} / {total}
172
+ </p>
173
+ <p className="m-0 mt-2 text-panel-heading font-medium">{title}</p>
174
+ {caption ? <p className="m-0 mt-2 text-label">{caption}</p> : null}
175
+ </div>
176
+ <div className="absolute end-6 top-6 flex items-center gap-2">
177
+ {total > 1 ? (
178
+ <IslandToolbar aria-label={title}>
179
+ <IslandToolbarButton
180
+ label={previousLabel}
181
+ icon={<span>‹</span>}
182
+ isDisabled={index === 0}
183
+ onPress={onPrevious}
184
+ />
185
+ <IslandToolbarButton
186
+ label={nextLabel}
187
+ icon={<span>›</span>}
188
+ isDisabled={index === total - 1}
189
+ onPress={onNext}
190
+ />
191
+ </IslandToolbar>
192
+ ) : null}
193
+ <Button
194
+ variant="ghost"
195
+ className="h-9 w-9 rounded-full bg-surface-inverted p-0 text-fg-inverted"
196
+ aria-label={closeLabel}
197
+ onPress={() => onOpenChange(false)}
198
+ >
199
+ ×
200
+ </Button>
201
+ </div>
202
+ </ModalDialog>
203
+ </ModalSurface>
204
+ </ModalOverlay>
205
+ )
206
+ }
@@ -11,11 +11,12 @@ import {
11
11
  } from 'react-aria-components'
12
12
  import {
13
13
  fieldDescriptionClass,
14
+ fieldControlClasses,
15
+ type FieldAppearance,
14
16
  fieldErrorClass,
15
- fieldLabelClass,
16
- fieldSizeClasses,
17
+ fieldLabelClasses,
18
+ type FieldLabelSize,
17
19
  fieldStackClass,
18
- outlinedFieldClasses,
19
20
  type FieldSize,
20
21
  } from './field-appearance'
21
22
 
@@ -30,6 +31,8 @@ const stepper =
30
31
 
31
32
  export type NumberFieldProps = RACNumberFieldProps & {
32
33
  /** Visible label (required for accessibility). */
34
+ appearance?: FieldAppearance
35
+ labelSize?: FieldLabelSize
33
36
  label: ReactNode
34
37
  description?: ReactNode
35
38
  errorMessage?: string
@@ -38,14 +41,20 @@ export type NumberFieldProps = RACNumberFieldProps & {
38
41
  size?: FieldSize
39
42
  }
40
43
 
41
- export const NumberField = ({ label, description, errorMessage, placeholder, size = 'md', ...props }: NumberFieldProps) => (
44
+ export const NumberField = ({
45
+ label,
46
+ labelSize = 'default',
47
+ appearance = 'outlined',
48
+ description,
49
+ errorMessage,
50
+ placeholder,
51
+ size = 'md',
52
+ ...props
53
+ }: NumberFieldProps) => (
42
54
  <RACNumberField {...props} className={`group ${fieldStackClass}`}>
43
- <Label className={fieldLabelClass}>{label}</Label>
55
+ <Label className={fieldLabelClasses[labelSize]}>{label}</Label>
44
56
  <Group
45
- className={
46
- `flex w-full items-center overflow-hidden rounded-lg ${fieldSizeClasses[size]} ` +
47
- outlinedFieldClasses({ focus: 'within', invalid: 'group' })
48
- }
57
+ className={`flex w-full items-center overflow-hidden rounded-lg ${fieldControlClasses(appearance, size, true)}`}
49
58
  >
50
59
  <RACButton slot="decrement" className={`${stepper} border-r border-border`}>
51
60
  –
@@ -0,0 +1,20 @@
1
+ import { PreviewError } from './preview-error'
2
+ export const examples = {
3
+ default: () => (
4
+ <PreviewError title="Preview unavailable" description="Please try again." retryLabel="Retry" onRetry={() => {}} />
5
+ ),
6
+ variants: () => <PreviewError title="Document unavailable" description="You do not have access to this document." />,
7
+ states: () => (
8
+ <PreviewError
9
+ title="Preview unavailable"
10
+ description="Please try again."
11
+ retryLabel="Retry"
12
+ onRetry={() => {}}
13
+ isPending
14
+ />
15
+ ),
16
+ }
17
+ export const meta = {
18
+ category: 'Composite',
19
+ description: 'Compact load error with an optional retry; no retry for unavailable access.',
20
+ }
@@ -0,0 +1,29 @@
1
+ import { Button } from './button'
2
+
3
+ export function PreviewError({
4
+ title,
5
+ description,
6
+ retryLabel,
7
+ onRetry,
8
+ isPending = false,
9
+ }: {
10
+ title: string
11
+ description: string
12
+ retryLabel?: string
13
+ onRetry?: () => void
14
+ isPending?: boolean
15
+ }) {
16
+ return (
17
+ <div className="flex max-w-72 flex-col items-start py-3">
18
+ <h3 className="m-0 text-small font-medium text-fg">{title}</h3>
19
+ <p role="alert" className="mb-0 mt-2 text-label font-normal text-danger">
20
+ {description}
21
+ </p>
22
+ {onRetry && retryLabel ? (
23
+ <Button variant="secondary" size="sm" className="mt-5 self-start" onPress={onRetry} isPending={isPending}>
24
+ {retryLabel}
25
+ </Button>
26
+ ) : null}
27
+ </div>
28
+ )
29
+ }
@@ -0,0 +1,32 @@
1
+ import { PreviewMetadataCard, PropertyTable, ColorSwatch } from './preview-metadata-card'
2
+ const metadata = (
3
+ <PropertyTable
4
+ label="Typography details"
5
+ rows={[
6
+ { label: 'Family', value: 'System' },
7
+ { label: 'Role', value: 'Heading' },
8
+ ]}
9
+ />
10
+ )
11
+ export const examples = {
12
+ default: () => (
13
+ <PreviewMetadataCard title="Heading" preview="A clear idea">
14
+ {metadata}
15
+ </PreviewMetadataCard>
16
+ ),
17
+ variants: () => (
18
+ <PreviewMetadataCard title="Heading" preview="A clear idea" collapsible toggleLabel="Show typography details">
19
+ {metadata}
20
+ </PreviewMetadataCard>
21
+ ),
22
+ states: () => (
23
+ <div className="flex gap-4">
24
+ <ColorSwatch color="#ffffff" label="White" />
25
+ <ColorSwatch color="#242423" label="Black" />
26
+ </div>
27
+ ),
28
+ }
29
+ export const meta = {
30
+ category: 'Composite',
31
+ description: 'Preview panel with compact, optionally collapsed property table.',
32
+ }
@@ -0,0 +1,112 @@
1
+ import type { ReactNode } from 'react'
2
+ import { IconButton } from './icon-button'
3
+ import { Disclosure, DisclosurePanel } from './disclosure'
4
+ import { uic } from '../utils/uic'
5
+
6
+ const Surface = uic('section', {
7
+ displayName: 'PreviewMetadataCard',
8
+ baseClass: 'min-w-0 overflow-hidden rounded-lg border border-border bg-surface',
9
+ })
10
+ /** A preview stays visible while its metadata may collapse independently. */
11
+ export function PreviewMetadataCard({
12
+ title,
13
+ preview,
14
+ children,
15
+ collapsible = false,
16
+ toggleLabel,
17
+ previewClassName = 'h-60',
18
+ actions,
19
+ }: {
20
+ title: ReactNode
21
+ preview: ReactNode
22
+ children: ReactNode
23
+ collapsible?: boolean
24
+ toggleLabel?: string
25
+ previewClassName?: string
26
+ actions?: ReactNode
27
+ }) {
28
+ const heading = (
29
+ <div className="flex min-w-0 items-center justify-between gap-3">
30
+ <h3 className="m-0 min-w-0 text-panel-heading font-medium text-fg">{title}</h3>
31
+ {actions}
32
+ {collapsible ? (
33
+ <IconButton slot="trigger" className="h-9 w-9 shrink-0 p-0" label={toggleLabel ?? ''}>
34
+ <svg
35
+ aria-hidden="true"
36
+ viewBox="0 0 24 24"
37
+ className="size-4 group-data-[expanded]/preview-metadata:rotate-180"
38
+ fill="none"
39
+ stroke="currentColor"
40
+ strokeWidth="1.5"
41
+ >
42
+ <path d="m6 9 6 6 6-6" />
43
+ </svg>
44
+ </IconButton>
45
+ ) : null}
46
+ </div>
47
+ )
48
+ return (
49
+ <Surface>
50
+ <div
51
+ className={`relative flex min-w-0 items-center justify-center overflow-hidden bg-surface-muted p-5 ${previewClassName}`}
52
+ >
53
+ {preview}
54
+ </div>
55
+ {collapsible ? (
56
+ <Disclosure className="group/preview-metadata p-5">
57
+ {heading}
58
+ <DisclosurePanel className="mt-3">{children}</DisclosurePanel>
59
+ </Disclosure>
60
+ ) : (
61
+ <div className="p-5">
62
+ {heading}
63
+ <div className="mt-4">{children}</div>
64
+ </div>
65
+ )}
66
+ </Surface>
67
+ )
68
+ }
69
+ export function PropertyTable({
70
+ rows,
71
+ label,
72
+ }: {
73
+ rows: readonly { label: ReactNode; value: ReactNode }[]
74
+ label: string
75
+ }) {
76
+ return (
77
+ <table aria-label={label} className="w-full border-collapse text-label font-normal text-fg">
78
+ <tbody>
79
+ {rows.map((row, index) => (
80
+ <tr key={index} className="border-b border-border last:border-b-0">
81
+ <th scope="row" className="w-1/2 py-3 pe-3 text-start font-normal text-fg-muted">
82
+ {row.label}
83
+ </th>
84
+ <td className="border-s border-border py-3 ps-3 text-start font-normal">{row.value}</td>
85
+ </tr>
86
+ ))}
87
+ </tbody>
88
+ </table>
89
+ )
90
+ }
91
+ export function ColorSwatch({ color, label }: { color: string; label: string }) {
92
+ const hex = color.replace('#', ''),
93
+ full = hex.length === 3 ? [...hex].map((value) => value + value).join('') : hex
94
+ const rgb = /^[a-f\d]{6}$/i.test(full)
95
+ ? [0, 2, 4].map((index) => parseInt(full.slice(index, index + 2), 16) / 255)
96
+ : [0, 0, 0]
97
+ const luminance = rgb.reduce(
98
+ (sum, value, index) =>
99
+ sum +
100
+ (0.2126 * (index === 0 ? 1 : 0) + 0.7152 * (index === 1 ? 1 : 0) + 0.0722 * (index === 2 ? 1 : 0)) *
101
+ (value <= 0.04045 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4),
102
+ 0,
103
+ )
104
+ return (
105
+ <span
106
+ role="img"
107
+ aria-label={label}
108
+ className={`block size-5 shrink-0 rounded-full ${luminance > 0.8 ? 'border border-border' : ''}`}
109
+ style={{ backgroundColor: color }}
110
+ />
111
+ )
112
+ }
@@ -9,10 +9,11 @@ import {
9
9
  } from 'react-aria-components'
10
10
  import {
11
11
  fieldDescriptionClass,
12
- fieldLabelClass,
13
- fieldSizeClasses,
12
+ fieldControlClasses,
13
+ type FieldAppearance,
14
+ fieldLabelClasses,
15
+ type FieldLabelSize,
14
16
  fieldStackClass,
15
- outlinedFieldClasses,
16
17
  type FieldSize,
17
18
  } from './field-appearance'
18
19
 
@@ -39,6 +40,8 @@ const SearchGlyph = () => (
39
40
  )
40
41
 
41
42
  export type SearchFieldProps = RACSearchFieldProps & {
43
+ appearance?: FieldAppearance
44
+ labelSize?: FieldLabelSize
42
45
  label?: ReactNode
43
46
  description?: ReactNode
44
47
  placeholder?: string
@@ -46,21 +49,38 @@ export type SearchFieldProps = RACSearchFieldProps & {
46
49
  size?: FieldSize
47
50
  }
48
51
 
49
- export const SearchField = ({ label, description, placeholder, size = 'md', ...props }: SearchFieldProps) => (
52
+ export const SearchField = ({
53
+ label,
54
+ labelSize = 'default',
55
+ appearance = 'outlined',
56
+ description,
57
+ placeholder,
58
+ size = 'md',
59
+ ...props
60
+ }: SearchFieldProps) => (
50
61
  <RACSearchField {...props} className={`group ${fieldStackClass}`}>
51
- {label ? <Label className={fieldLabelClass}>{label}</Label> : null}
62
+ {label ? <Label className={fieldLabelClasses[labelSize]}>{label}</Label> : null}
52
63
  <div className="relative flex items-center">
53
64
  <SearchGlyph />
54
65
  <RACInput
55
66
  placeholder={placeholder}
56
67
  className={
57
- `w-full rounded-lg pl-10 pr-10 ${fieldSizeClasses[size]} ${outlinedFieldClasses()} ` +
68
+ `w-full rounded-lg pl-10 pr-10 ${fieldControlClasses(appearance, size)} ` +
58
69
  '[&::-webkit-search-cancel-button]:hidden'
59
70
  }
60
71
  />
61
72
  {/* RAC hides this automatically when the field is empty. */}
62
73
  <RACButton className="absolute right-2 flex h-7 w-7 cursor-pointer data-[disabled]:cursor-not-allowed items-center justify-center rounded-md text-fg-subtle outline-none transition-colors hover:bg-surface-muted hover:text-fg group-data-[empty]:hidden data-[focus-visible]:ring-2 data-[focus-visible]:ring-ring">
63
- <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" aria-hidden="true">
74
+ <svg
75
+ width="14"
76
+ height="14"
77
+ viewBox="0 0 24 24"
78
+ fill="none"
79
+ stroke="currentColor"
80
+ strokeWidth="2"
81
+ strokeLinecap="round"
82
+ aria-hidden="true"
83
+ >
64
84
  <path d="M6 6l12 12M18 6 6 18" />
65
85
  </svg>
66
86
  </RACButton>