@proteos/ui 0.78.0 → 0.80.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.
@@ -9,7 +9,7 @@ import {
9
9
  Text,
10
10
  } from 'react-aria-components'
11
11
  import { cn } from '../../lib/cn'
12
- import { fieldErrorStyles, fieldHintStyles, fieldLabelStyles } from '../field/field'
12
+ import { type FieldSize, fieldErrorStyles, fieldHintStyles, fieldLabelStyles } from '../field/field'
13
13
 
14
14
  /* =========================================================================
15
15
  RadioGroup — exclusive-choice field. Monolithic API to match Input/Select/
@@ -67,9 +67,11 @@ export function RadioGroup({
67
67
 
68
68
  export type RadioProps = Omit<AriaRadioProps, 'children'> & {
69
69
  children?: ReactNode
70
+ /** `sm` for dense rows. Defaults to `md`. */
71
+ size?: FieldSize
70
72
  }
71
73
 
72
- export function Radio({ children, className, ...props }: RadioProps) {
74
+ export function Radio({ children, className, size = 'md', ...props }: RadioProps) {
73
75
  return (
74
76
  <AriaRadio
75
77
  {...props}
@@ -79,8 +81,9 @@ export function Radio({ children, className, ...props }: RadioProps) {
79
81
  // visually-hidden <input> is absolutely positioned and must resolve
80
82
  // against this radio, not a far-away shell, or focusing it scrolls
81
83
  // the clipped page.
82
- 'group relative inline-flex items-center gap-2.5 cursor-pointer',
83
- 'font-sans text-[14px] text-ink-2 select-none',
84
+ 'group relative inline-flex items-center cursor-pointer',
85
+ size === 'sm' ? 'gap-2 text-[13px]' : 'gap-2.5 text-[14px]',
86
+ 'font-sans text-ink-2 select-none',
84
87
  'data-[disabled]:opacity-45 data-[disabled]:cursor-not-allowed',
85
88
  typeof className === 'function' ? className(renderProps) : className,
86
89
  )
@@ -90,7 +93,8 @@ export function Radio({ children, className, ...props }: RadioProps) {
90
93
  aria-hidden
91
94
  className={cn(
92
95
  'relative inline-flex items-center justify-center shrink-0',
93
- 'size-[18px] rounded-full border bg-surface border-ink-4',
96
+ size === 'sm' ? 'size-4' : 'size-[18px]',
97
+ 'rounded-full border bg-surface border-ink-4',
94
98
  'transition-[border-color,box-shadow] duration-150',
95
99
  'group-data-[hovered]:border-ink',
96
100
  'group-data-[selected]:border-ink',
@@ -99,7 +103,8 @@ export function Radio({ children, className, ...props }: RadioProps) {
99
103
  >
100
104
  <span
101
105
  className={cn(
102
- 'block size-[10px] rounded-full bg-accent',
106
+ size === 'sm' ? 'size-2' : 'size-[10px]',
107
+ 'block rounded-full bg-accent',
103
108
  'transition-opacity duration-150 opacity-0',
104
109
  'group-data-[selected]:opacity-100',
105
110
  )}
@@ -2,7 +2,7 @@ import { type ReactNode, useId } from 'react'
2
2
  import { Switch as AriaSwitch, type SwitchProps as AriaSwitchProps } from 'react-aria-components'
3
3
 
4
4
  import { cn } from '../../lib/cn'
5
- import { fieldHintStyles } from '../field/field'
5
+ import { type FieldSize, fieldHintStyles } from '../field/field'
6
6
 
7
7
  export type SwitchProps = Omit<AriaSwitchProps, 'children'> & {
8
8
  children?: ReactNode
@@ -15,12 +15,15 @@ export type SwitchProps = Omit<AriaSwitchProps, 'children'> & {
15
15
  * wrapping the label; without one the label stays the root, as before.
16
16
  */
17
17
  description?: ReactNode
18
+ /** `sm` for dense rows. Defaults to `md`. */
19
+ size?: FieldSize
18
20
  }
19
21
 
20
22
  export function Switch({
21
23
  children,
22
24
  labelPlacement = 'end',
23
25
  description,
26
+ size = 'md',
24
27
  className,
25
28
  ...props
26
29
  }: SwitchProps) {
@@ -38,8 +41,9 @@ export function Switch({
38
41
  // without a positioned label it escapes an overflow-auto ancestor and
39
42
  // its containing block becomes the page shell, so focusing it (any
40
43
  // press) scrolls the clipped shell and the whole tab goes blank.
41
- 'group relative inline-flex items-center gap-3 cursor-pointer select-none',
42
- 'font-sans text-[14px] text-ink-2',
44
+ 'group relative inline-flex items-center cursor-pointer select-none',
45
+ size === 'sm' ? 'gap-2 text-[13px]' : 'gap-3 text-[14px]',
46
+ 'font-sans text-ink-2',
43
47
  labelPlacement === 'start' && 'flex-row-reverse',
44
48
  'data-[disabled]:opacity-45 data-[disabled]:cursor-not-allowed',
45
49
  typeof className === 'function' ? className(renderProps) : className,
@@ -50,7 +54,8 @@ export function Switch({
50
54
  aria-hidden
51
55
  className={cn(
52
56
  'relative inline-block shrink-0',
53
- 'w-[38px] h-[22px] rounded-pill border',
57
+ size === 'sm' ? 'w-8 h-[18px]' : 'w-[38px] h-[22px]',
58
+ 'rounded-pill border',
54
59
  'bg-surface-3 border-rule',
55
60
  'transition-[background-color,border-color] duration-150',
56
61
  'group-data-[selected]:bg-accent group-data-[selected]:border-accent',
@@ -60,9 +65,11 @@ export function Switch({
60
65
  <span
61
66
  className={cn(
62
67
  'absolute top-[1px] left-[1px]',
63
- 'block size-[18px] rounded-full bg-surface',
68
+ 'block rounded-full bg-surface',
64
69
  'transition-transform duration-200',
65
- 'group-data-[selected]:translate-x-[16px]',
70
+ size === 'sm'
71
+ ? 'size-3.5 group-data-[selected]:translate-x-[14px]'
72
+ : 'size-[18px] group-data-[selected]:translate-x-[16px]',
66
73
  )}
67
74
  />
68
75
  </span>
@@ -78,8 +85,8 @@ export function Switch({
78
85
  className={cn(
79
86
  fieldHintStyles,
80
87
  'leading-[1.45]',
81
- // Track (38px) + gap-3 (12px): the copy starts under the label text.
82
- labelPlacement === 'end' && 'pl-[50px]',
88
+ // Track + gap: the copy starts under the label text.
89
+ labelPlacement === 'end' && (size === 'sm' ? 'pl-10' : 'pl-[50px]'),
83
90
  props.isDisabled && 'opacity-45',
84
91
  )}
85
92
  >
package/src/index.ts CHANGED
@@ -46,7 +46,7 @@ export * from './components/progress-ring'
46
46
  export * from './components/radio-group'
47
47
  export * from './components/recipient-select'
48
48
  export * from './components/record-filter'
49
- export * from './components/record-update'
49
+ export * from './components/ava-action-review'
50
50
  export * from './components/segmented-control'
51
51
  export * from './components/select'
52
52
  export * from './components/separator'
@@ -1,17 +0,0 @@
1
- export type {
2
- RecordUpdateErrorsProps,
3
- RecordUpdateProps,
4
- RecordUpdateRowProps,
5
- RecordUpdateRowState,
6
- RecordUpdateRowVariants,
7
- } from './record-update'
8
- export {
9
- RecordUpdate,
10
- RecordUpdateErrors,
11
- RecordUpdateFooter,
12
- RecordUpdateRow,
13
- RecordUpdateRows,
14
- RecordUpdateSummary,
15
- recordUpdateRowStyles,
16
- recordUpdateStyles,
17
- } from './record-update'
@@ -1,141 +0,0 @@
1
- import type { Meta, StoryObj } from '@storybook/react-vite'
2
- import { type ReactNode, useState } from 'react'
3
-
4
- import { Badge } from '../badge/badge'
5
- import { Button } from '../button/button'
6
- import { Input } from '../input/input'
7
- import { Select } from '../select/select'
8
- import {
9
- RecordUpdate,
10
- RecordUpdateErrors,
11
- RecordUpdateFooter,
12
- RecordUpdateRow,
13
- type RecordUpdateRowState,
14
- RecordUpdateRows,
15
- RecordUpdateSummary,
16
- } from './record-update'
17
-
18
- const meta: Meta<typeof RecordUpdateRow> = {
19
- title: 'Components/RecordUpdate',
20
- component: RecordUpdateRow,
21
- tags: ['autodocs'],
22
- argTypes: {
23
- state: { control: 'radio', options: ['changed', 'unresolved', 'rejected', 'removed'] },
24
- },
25
- }
26
-
27
- export default meta
28
- type Story = StoryObj<typeof RecordUpdateRow>
29
-
30
- const STATUS_OPTIONS = [
31
- { id: 'open', label: 'Open' },
32
- { id: 'won', label: 'Won' },
33
- { id: 'churned', label: 'Churned' },
34
- ] as const
35
-
36
- function ReadOnly({ children }: { children: ReactNode }) {
37
- return (
38
- <div className="flex items-center min-h-9 bg-surface-2 rounded-md px-3 py-2 text-[13.5px] text-ink">
39
- {children}
40
- </div>
41
- )
42
- }
43
-
44
- export const Row: Story = {
45
- args: {
46
- label: 'Status',
47
- from: <ReadOnly>Open</ReadOnly>,
48
- to: <ReadOnly>Churned</ReadOnly>,
49
- state: 'changed',
50
- onRemove: () => {},
51
- onRestore: () => {},
52
- },
53
- }
54
-
55
- export const Review: Story = {
56
- parameters: { controls: { hideNoControlsWarning: true } },
57
- render: () => {
58
- const [status, setStatus] = useState('churned')
59
- const [amount, setAmount] = useState('13200')
60
- const [removed, setRemoved] = useState<Record<string, boolean>>({})
61
- const stateFor = (key: string, fallback: RecordUpdateRowState = 'changed') =>
62
- removed[key] ? 'removed' : fallback
63
- const toggle = (key: string, value: boolean) =>
64
- setRemoved((prev) => ({ ...prev, [key]: value }))
65
- return (
66
- <div className="w-[600px] border border-rule rounded-lg bg-surface">
67
- <RecordUpdate>
68
- <RecordUpdateSummary>
69
- Marks the company as churned and raises the amount by 10%.
70
- </RecordUpdateSummary>
71
- <RecordUpdateRows>
72
- <RecordUpdateRow
73
- label="Status"
74
- state={stateFor('status')}
75
- from={
76
- <ReadOnly>
77
- <Badge>Open</Badge>
78
- </ReadOnly>
79
- }
80
- to={
81
- <Select
82
- aria-label="Status"
83
- options={STATUS_OPTIONS}
84
- selectedKey={status}
85
- onSelectionChange={(key) => setStatus(String(key))}
86
- />
87
- }
88
- onRemove={() => toggle('status', true)}
89
- onRestore={() => toggle('status', false)}
90
- />
91
- <RecordUpdateRow
92
- label="Amount"
93
- state={stateFor('amount')}
94
- from={<ReadOnly>12,000</ReadOnly>}
95
- to={<Input aria-label="Amount" value={amount} onChange={setAmount} />}
96
- onRemove={() => toggle('amount', true)}
97
- onRestore={() => toggle('amount', false)}
98
- />
99
- <RecordUpdateRow
100
- label="Owner"
101
- state={stateFor('owner', 'unresolved')}
102
- from={<ReadOnly>Tonio Knuth</ReadOnly>}
103
- to={<Input aria-label="Owner" placeholder="Pick a user…" />}
104
- hint="“Julia” is a name, not an id — pick the user."
105
- onRemove={() => toggle('owner', true)}
106
- onRestore={() => toggle('owner', false)}
107
- />
108
- <RecordUpdateRow
109
- label="Tier"
110
- state="rejected"
111
- from={
112
- <ReadOnly>
113
- <Badge>Silver</Badge>
114
- </ReadOnly>
115
- }
116
- to={
117
- <span className="text-[13px] text-danger">
118
- “platinum” is not one of the options (silver, gold).
119
- </span>
120
- }
121
- />
122
- <RecordUpdateRow
123
- label="Website"
124
- from={<ReadOnly>—</ReadOnly>}
125
- to={<Input aria-label="Website" value="acme" onChange={() => {}} isInvalid />}
126
- errorMessage="Must be a valid URL"
127
- onRemove={() => {}}
128
- />
129
- </RecordUpdateRows>
130
- <RecordUpdateErrors
131
- errors={['“Created at” is managed by the platform and cannot be changed.']}
132
- />
133
- <RecordUpdateFooter>
134
- <Button variant="ghost">Cancel</Button>
135
- <Button variant="cta">Apply 2 changes</Button>
136
- </RecordUpdateFooter>
137
- </RecordUpdate>
138
- </div>
139
- )
140
- },
141
- }
@@ -1,259 +0,0 @@
1
- import { AlertCircle, ArrowRight, Undo2, X } from 'lucide-react'
2
- import type { HTMLAttributes, ReactNode } from 'react'
3
- import { tv, type VariantProps } from 'tailwind-variants'
4
-
5
- import { cn } from '../../lib/cn'
6
- import { Button } from '../button/button'
7
-
8
- /* =========================================================================
9
- RecordUpdate — a proposed set of field changes to ONE record, laid out
10
- as a mini page: a summary line, one row per field (`from → to`), the
11
- problems the proposer ran into, and a footer with the decision buttons.
12
- Chrome only — the consumer renders the two cells of every row (a
13
- read-only display on the left, an editor on the right), so the same
14
- surface reviews an AI-prepared record update in the command palette, in
15
- a chat client tool, or in a prepared-action popover.
16
-
17
- Slot composition (Card pattern): the root carries no padding; each slot
18
- owns its own spacing so they compose freely.
19
-
20
- <RecordUpdate>
21
- <RecordUpdateSummary>…</RecordUpdateSummary>
22
- <RecordUpdateRows>
23
- <RecordUpdateRow label from to state … />
24
- </RecordUpdateRows>
25
- <RecordUpdateErrors errors={[…]} />
26
- <RecordUpdateFooter>…buttons…</RecordUpdateFooter>
27
- </RecordUpdate>
28
-
29
- Row states:
30
- changed — a value the reviewer can still edit or drop.
31
- unresolved — the proposer knew WHICH field but not the value; the
32
- right cell is expected to be an empty editor and `hint`
33
- says why. Consumers block "apply" while any row is here.
34
- rejected — the proposer could NOT do what was asked for this field
35
- (read-only, no such option …); the right cell carries the
36
- explanation and nothing is applied for the row.
37
- removed — dropped from the change set; collapses to one line with a
38
- restore button so the decision stays reversible.
39
- ========================================================================= */
40
-
41
- export const recordUpdateStyles = tv({
42
- slots: {
43
- root: 'flex flex-col min-w-0 text-ink',
44
- summary: 'px-4 pt-3 pb-1 text-[13px] text-ink-3',
45
- rows: 'flex flex-col px-4 divide-y divide-rule',
46
- errors: [
47
- 'mx-4 my-3 flex gap-2 rounded-md px-3 py-2 text-[13px] text-danger',
48
- 'bg-[color-mix(in_oklab,var(--color-danger)_8%,var(--color-surface))]',
49
- ],
50
- footer: 'flex items-center justify-end gap-2 px-4 py-3',
51
- },
52
- })
53
-
54
- export const recordUpdateRowStyles = tv({
55
- slots: {
56
- // fieldset resets (UA border / padding / min-content width) included.
57
- root: 'flex flex-col gap-1.5 m-0 border-0 px-0 py-2.5 min-w-0',
58
- labelRow: [
59
- 'flex items-center gap-2 min-h-7',
60
- 'font-mono text-[10.5px] uppercase tracking-[0.08em] text-ink-4',
61
- ],
62
- tag: 'normal-case tracking-normal text-[10px] rounded-full px-1.5 py-px',
63
- cells:
64
- 'grid grid-cols-1 sm:grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-center gap-2 sm:gap-3',
65
- from: 'min-w-0 opacity-70',
66
- arrow: 'size-3.5 shrink-0 text-ink-4 rotate-90 sm:rotate-0 justify-self-center',
67
- to: 'min-w-0',
68
- hint: 'text-[12px] text-ink-4',
69
- error: 'text-[12px] text-danger',
70
- removed: 'text-[13px] italic text-ink-4',
71
- },
72
- variants: {
73
- state: {
74
- changed: {},
75
- unresolved: {
76
- tag: 'text-warning bg-[color-mix(in_oklab,var(--color-warning)_12%,var(--color-surface))]',
77
- },
78
- rejected: {
79
- tag: 'text-danger bg-[color-mix(in_oklab,var(--color-danger)_10%,var(--color-surface))]',
80
- },
81
- removed: { labelRow: 'line-through decoration-ink-4/60' },
82
- },
83
- },
84
- defaultVariants: { state: 'changed' },
85
- })
86
-
87
- export type RecordUpdateRowVariants = VariantProps<typeof recordUpdateRowStyles>
88
- export type RecordUpdateRowState = NonNullable<RecordUpdateRowVariants['state']>
89
-
90
- /* ---------- root + slots ---------- */
91
-
92
- export type RecordUpdateProps = HTMLAttributes<HTMLDivElement>
93
-
94
- export function RecordUpdate({ className, children, ...props }: RecordUpdateProps) {
95
- return (
96
- <div {...props} className={cn(recordUpdateStyles().root(), className)}>
97
- {children}
98
- </div>
99
- )
100
- }
101
-
102
- export function RecordUpdateSummary({
103
- className,
104
- children,
105
- ...props
106
- }: HTMLAttributes<HTMLElement>) {
107
- return (
108
- <p {...props} className={cn(recordUpdateStyles().summary(), className)}>
109
- {children}
110
- </p>
111
- )
112
- }
113
-
114
- export function RecordUpdateRows({
115
- className,
116
- children,
117
- ...props
118
- }: HTMLAttributes<HTMLDivElement>) {
119
- return (
120
- <div {...props} className={cn(recordUpdateStyles().rows(), className)}>
121
- {children}
122
- </div>
123
- )
124
- }
125
-
126
- export interface RecordUpdateErrorsProps extends HTMLAttributes<HTMLDivElement> {
127
- /** Problems that are not tied to one field. Renders nothing when empty. */
128
- errors: ReadonlyArray<string>
129
- }
130
-
131
- export function RecordUpdateErrors({ errors, className, ...props }: RecordUpdateErrorsProps) {
132
- if (errors.length === 0) return null
133
- return (
134
- <div {...props} role="alert" className={cn(recordUpdateStyles().errors(), className)}>
135
- <AlertCircle className="size-4 shrink-0 mt-px" aria-hidden />
136
- <ul className="flex flex-col gap-1 min-w-0">
137
- {errors.map((error) => (
138
- <li key={error}>{error}</li>
139
- ))}
140
- </ul>
141
- </div>
142
- )
143
- }
144
-
145
- export function RecordUpdateFooter({
146
- className,
147
- children,
148
- ...props
149
- }: HTMLAttributes<HTMLDivElement>) {
150
- return (
151
- <div {...props} className={cn(recordUpdateStyles().footer(), className)}>
152
- {children}
153
- </div>
154
- )
155
- }
156
-
157
- /* ---------- row ---------- */
158
-
159
- export interface RecordUpdateRowProps
160
- extends Omit<HTMLAttributes<HTMLFieldSetElement>, 'children' | 'className'> {
161
- /** The field's label — rendered in the page-layout field-label style. */
162
- label: ReactNode
163
- /** Current value cell (typically a read-only display). Omit for a value
164
- * that has no "before" — a record being created — and the row shows
165
- * `to` alone, without the arrow. */
166
- from?: ReactNode
167
- /** Proposed value cell (an editor bound to the change, or the rejection text). */
168
- to: ReactNode
169
- state?: RecordUpdateRowState
170
- /** Why the value is unresolved, or any other one-line note under the cells. */
171
- hint?: ReactNode
172
- /** Validation error for the proposed value. */
173
- errorMessage?: string
174
- /** Drop this change. Renders the remove button when given (not in `removed`). */
175
- onRemove?: () => void
176
- /** Bring a removed change back. Renders the restore button in `removed`. */
177
- onRestore?: () => void
178
- /** Accessible names for the two buttons. */
179
- removeLabel?: string
180
- restoreLabel?: string
181
- /** Text of the `unresolved` / `rejected` tags next to the label. */
182
- unresolvedLabel?: string
183
- rejectedLabel?: string
184
- /** Text shown in place of the cells while `removed`. */
185
- removedText?: string
186
- className?: string
187
- }
188
-
189
- export function RecordUpdateRow({
190
- label,
191
- from,
192
- to,
193
- state = 'changed',
194
- hint,
195
- errorMessage,
196
- onRemove,
197
- onRestore,
198
- removeLabel = 'Remove change',
199
- restoreLabel = 'Restore change',
200
- unresolvedLabel = 'needs a value',
201
- rejectedLabel = 'not possible',
202
- removedText = 'Kept as it is',
203
- className,
204
- ...props
205
- }: RecordUpdateRowProps) {
206
- const styles = recordUpdateRowStyles({ state })
207
- const isRemoved = state === 'removed'
208
- // A fieldset: the row IS a group of one field's cells (implicit `group`
209
- // role), reset from the UA's border / padding / min-content width.
210
- return (
211
- <fieldset
212
- {...props}
213
- data-state={state}
214
- {...(errorMessage ? { 'aria-invalid': true } : {})}
215
- className={cn(styles.root(), className)}
216
- >
217
- <div className={styles.labelRow()}>
218
- <span className="truncate">{label}</span>
219
- {state === 'unresolved' ? <span className={styles.tag()}>{unresolvedLabel}</span> : null}
220
- {state === 'rejected' ? <span className={styles.tag()}>{rejectedLabel}</span> : null}
221
- <span className="ml-auto flex items-center">
222
- {isRemoved
223
- ? onRestore && (
224
- <Button
225
- variant="ghost"
226
- size="icon-sm"
227
- aria-label={restoreLabel}
228
- onPress={onRestore}
229
- >
230
- <Undo2 />
231
- </Button>
232
- )
233
- : onRemove && (
234
- <Button variant="ghost" size="icon-sm" aria-label={removeLabel} onPress={onRemove}>
235
- <X />
236
- </Button>
237
- )}
238
- </span>
239
- </div>
240
- {isRemoved ? (
241
- <div className={styles.removed()}>{removedText}</div>
242
- ) : from === undefined ? (
243
- <div className={styles.to()}>{to}</div>
244
- ) : (
245
- <div className={styles.cells()}>
246
- <div className={styles.from()}>{from}</div>
247
- <ArrowRight className={styles.arrow()} aria-hidden />
248
- <div className={styles.to()}>{to}</div>
249
- </div>
250
- )}
251
- {!isRemoved && hint ? <div className={styles.hint()}>{hint}</div> : null}
252
- {!isRemoved && errorMessage ? (
253
- <div className={styles.error()} role="alert">
254
- {errorMessage}
255
- </div>
256
- ) : null}
257
- </fieldset>
258
- )
259
- }