feat(places): colour tags, tabs for the texts and opening hours on the phone

Tags on the place form are pills in their own colour, with a palette under
the dot that recolours a tag for the whole trip (PUT /trips/:id/tags/:id was
there already, the client now reaches it through repo and store) and a
custom colour field of its own instead of the system picker. A new tag is
made in a colour picked the same way.

Description, notes and the note for one day's visit sit in one card under a
switch, each with a line on where the text shows up; the day tab is named
after its day and is only there with one visit in context. Nothing about the
three fields changes underneath.

Opening hours get a switch for open around the clock next to closed. Google
writes a place open all week as one period on Sunday that never closes; it
read as Sunday open and every other day closed, and now opens every day.

The phone form follows the desktop: category as one field with a list, tags
in one field, the texts switch, and phone, e-mail and opening hours, which it
did not have. The hours and the text tabs are shared hooks (usePlaceHours,
usePlaceTextTabs). Files and costs on the phone sheets are drawn as fields
like the rest, and the paste hint, a keyboard shortcut a phone has no use
for, is gone with its key.
This commit is contained in:
Maurice
2026-11-17 08:44:05 +01:00
parent 33d074c786
commit a3f6635633
100 changed files with 2538 additions and 510 deletions
@@ -40,7 +40,6 @@ export default function MBookingFilesCosts({
files={pendingFiles}
onAdd={files => setPendingFiles(prev => [...prev, ...files])}
onRemove={idx => setPendingFiles(prev => prev.filter((_, i) => i !== idx))}
hideHint
canAttach={canUploadFiles}
attached={bookingFiles.attached}
linkable={bookingFiles.linkable}
@@ -1,5 +1,5 @@
import { useState } from 'react'
import { ChevronRight, Link2, Link2Off, Plus, Search, Trash2 } from 'lucide-react'
import { ChevronRight, Link2, Link2Off, Receipt, Search, Trash2 } from 'lucide-react'
import { useTranslation } from '../../../../i18n'
import { useTripStore } from '../../../../store/tripStore'
import { useSettingsStore } from '../../../../store/settingsStore'
@@ -8,10 +8,8 @@ import { formatMoney } from '../../../../utils/formatters'
import { catMeta } from '../../../../components/Budget/costsCategories'
import { useExpenseLinks } from '../../../../components/Planner/useRecordLinks'
import type { BudgetItem } from '../../../../types'
import { Eyebrow } from './PlSheetChrome'
import { AddFieldButton, Eyebrow } from './PlSheetChrome'
const PILL_CLS =
'flex w-full items-center justify-center gap-[6px] rounded-[13px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] py-[11px] text-[0.78125rem] font-semibold text-m-ink disabled:opacity-40'
const ROW_ICON_BTN_CLS = 'flex h-8 w-8 flex-none items-center justify-center rounded-full text-m-faint active:bg-[color:var(--m-ic)]'
// Past this many the list gets a search field, a trip can collect a lot of expenses.
const SEARCH_FROM = 6
@@ -88,16 +86,10 @@ export default function MLinkedCosts({ reservationId = null, placeId = null, hin
)}
<div className={`grid gap-2 ${targetId ? 'grid-cols-2' : 'grid-cols-1'}`}>
<button type="button" onClick={onCreate} disabled={createDisabled} className={PILL_CLS}>
<Plus size={13} strokeWidth={2.2} />
{t('reservations.createExpense')}
</button>
<AddFieldButton icon={Receipt} label={t('reservations.createExpense')} onClick={onCreate} disabled={createDisabled} />
{/* Linking needs the record to exist, so it waits for the first save. */}
{targetId !== null && (
<button type="button" onClick={() => setPicking(v => !v)} aria-expanded={picking} className={`${PILL_CLS} ${picking ? '!bg-m-act !text-m-actfg' : ''}`}>
<Link2 size={13} strokeWidth={2.2} />
{t('files.link')}
</button>
<AddFieldButton icon={Link2} label={t('files.link')} onClick={() => setPicking(v => !v)} pressed={picking} ariaExpanded={picking} />
)}
</div>
@@ -133,7 +125,7 @@ export default function MLinkedCosts({ reservationId = null, placeId = null, hin
</div>
)}
{linked.length === 0 && <div className="mt-[5px] font-geist text-[0.625rem] text-m-faint">{t(hintKey)}</div>}
{linked.length === 0 && <p className="m-0 mt-[5px] px-[6px] font-geist text-[0.65625rem] leading-snug text-m-faint">{t(hintKey)}</p>}
</>
)
}
@@ -1,5 +1,5 @@
import { useEffect, useMemo, useRef, useState, type ClipboardEvent } from 'react'
import { MapPin, MapPinOff } from 'lucide-react'
import { Globe, MapPin, MapPinOff } from 'lucide-react'
import MSheet from '../../../components/MSheet'
import {
DEFAULT_FORM,
@@ -14,12 +14,16 @@ import {
import { usePlaceForm } from '../../../../components/Planner/usePlaceForm'
import { usePlaceTags } from '../../../../components/Planner/usePlaceTags'
import { addressWithoutCoordinates } from '../../../../components/Planner/placeCoordinates'
import { Eyebrow, FIELD_AREA_CLS, FIELD_CLS, FormSheetBody, FormSheetFooter, FormSheetHeader } from './PlSheetChrome'
import { AMOUNT_FIELD_CLS, Eyebrow, FIELD_CLS, FormSheetBody, FormSheetFooter, FormSheetHeader } from './PlSheetChrome'
import { useAddonStore } from '../../../../store/addonStore'
import type { BookingExpenseRequest } from '../../../../components/Planner/BookingCostsSection.types'
import PlPlaceSearch, { type PlSearchPick } from './PlPlaceSearch'
import PlCategoryPicker from './PlCategoryPicker'
import { PlTagPicker } from './PlTags'
import { PlPlaceTexts } from './PlPlaceTexts'
import { PlContactFields } from './PlContactFields'
import { weekFromPeriods } from '../../../../components/Planner/placeHours'
import type { PlaceOpeningHours } from '@trek/shared'
import PlTimeFields from './PlTimeFields'
import PlFileAttach from './PlFileAttach'
import MLinkedCosts from './MLinkedCosts'
@@ -83,6 +87,8 @@ export default function MPlaceEditSheet({ planner, onOpenExpense }: MPlaceEditSh
place: editingPlace, imageUrl: form.image_url, pendingImage, canUploadFiles, stageUpload, stageAttached, removeImage,
})
const [resolvingPick, setResolvingPick] = useState(false)
// The hours the details looked up, offered to the hours editor as on the desktop.
const [detailsHours, setDetailsHours] = useState<PlaceOpeningHours | null>(null)
const isBudgetEnabled = useAddonStore(s => s.isEnabled('budget'))
// Set right before submit: the place has to exist before an expense can point
// at it, exactly like MReservationSheet does it.
@@ -129,6 +135,7 @@ export default function MPlaceEditSheet({ planner, onOpenExpense }: MPlaceEditSh
else if (prefillCoords) next = prefillForm(prefillCoords)
else next = DEFAULT_FORM
openForm(next, editingPlace, prefillCoords)
setDetailsHours(null)
setDeleteArmed(false)
// storedAssignments is a fresh map each load, so it is read at open time only.
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -181,6 +188,9 @@ export default function MPlaceEditSheet({ planner, onOpenExpense }: MPlaceEditSh
}
}
// The day the visit under edit is on, to name its note's tab after it.
const dayNumber = ctxAssignment ? planner.days.find(d => d.id === ctxAssignment.day_id)?.day_number ?? null : null
// End before start blocks the save — tied to the values, not to which entry
// point opened the sheet.
const hasTimeError = endsBeforeStart(form.place_time, form.end_time)
@@ -265,6 +275,7 @@ export default function MPlaceEditSheet({ planner, onOpenExpense }: MPlaceEditSh
onPickImage={pickImage}
image={image}
onAdoptDescription={adoptDescription}
onHours={hours => setDetailsHours(weekFromPeriods(hours.periods))}
hasDescription={!!form.description.trim()}
language={language}
timeFormat={timeFormat}
@@ -289,25 +300,6 @@ export default function MPlaceEditSheet({ planner, onOpenExpense }: MPlaceEditSh
className={`${FIELD_CLS} ${resolvingPick ? 'opacity-60' : ''}`}
/>
<Eyebrow className="mb-[5px] mt-3 uppercase">{t('places.formDescription')}</Eyebrow>
<textarea
value={form.description}
onChange={e => handleChange('description', e.target.value)}
rows={2}
placeholder={t('places.formDescriptionPlaceholder')}
className={FIELD_AREA_CLS}
/>
<Eyebrow className="mb-[5px] mt-3 uppercase">{t('places.formNotes')}</Eyebrow>
<textarea
value={form.notes}
onChange={e => handleChange('notes', e.target.value)}
rows={2}
maxLength={2000}
placeholder={t('places.formNotesPlaceholder')}
className={FIELD_AREA_CLS}
/>
<Eyebrow className="mb-[5px] mt-3 uppercase">{t('places.formAddress')}</Eyebrow>
<input
type="text"
@@ -323,7 +315,7 @@ export default function MPlaceEditSheet({ planner, onOpenExpense }: MPlaceEditSh
value={form.lat}
onChange={e => handleChange('lat', e.target.value.replace(/[^0-9.-]/g, ''))}
onPaste={handleCoordPaste}
placeholder={t('places.formLat')}
placeholder={t('places.formLatLabel')}
className={`${FIELD_CLS} flex-1 text-[0.8125rem] [font-variant-numeric:tabular-nums]`}
/>
<input
@@ -331,7 +323,7 @@ export default function MPlaceEditSheet({ planner, onOpenExpense }: MPlaceEditSh
inputMode="decimal"
value={form.lng}
onChange={e => handleChange('lng', e.target.value.replace(/[^0-9.-]/g, ''))}
placeholder={t('places.formLng')}
placeholder={t('places.formLngLabel')}
className={`${FIELD_CLS} flex-1 text-[0.8125rem] [font-variant-numeric:tabular-nums]`}
/>
</div>
@@ -343,42 +335,56 @@ export default function MPlaceEditSheet({ planner, onOpenExpense }: MPlaceEditSh
</p>
)}
<Eyebrow className="mb-[6px] mt-3 uppercase">{t('places.formCategory')}</Eyebrow>
<Eyebrow className="mb-[5px] mt-3 uppercase">{t('places.formCategory')}</Eyebrow>
<PlCategoryPicker planner={planner} value={form.category_id} onChange={id => handleChange('category_id', id)} />
<PlTagPicker tags={tagField} t={t} />
{/* Times live per day-assignment — only editable when one is in context.
Same for the day-specific note (#2163). */}
{/* Times live per day-assignment, only editable when one is in context (#2163). */}
{sheetPlace && sheetAssignmentId && (
<>
<PlTimeFields
planner={planner}
startTime={form.place_time}
endTime={form.end_time}
onChange={handleChange}
assignmentId={sheetAssignmentId}
dayAssignments={dayAssignments}
hasTimeError={hasTimeError}
/>
<Eyebrow className="mb-[5px] mt-3 uppercase">{t('places.assignmentNotes')}</Eyebrow>
<textarea
value={form.assignment_notes ?? ''}
onChange={e => handleChange('assignment_notes', e.target.value)}
rows={2}
placeholder={t('places.assignmentNotesPlaceholder')}
className={FIELD_AREA_CLS}
/>
</>
<PlTimeFields
planner={planner}
startTime={form.place_time}
endTime={form.end_time}
onChange={handleChange}
assignmentId={sheetAssignmentId}
dayAssignments={dayAssignments}
hasTimeError={hasTimeError}
/>
)}
{/* Description, notes and the note for this visit, one at a time; the day's
tab follows the times and is only there with a visit in context. */}
<PlPlaceTexts
description={form.description}
notes={form.notes}
dayNotes={sheetPlace && sheetAssignmentId ? (form.assignment_notes ?? '') : null}
dayNumber={dayNumber}
onChange={(field, value) => handleChange(field, value)}
t={t}
/>
<Eyebrow className="mb-[5px] mt-3 uppercase">{t('places.formWebsite')}</Eyebrow>
<input
type="url"
dir="ltr"
value={form.website}
onChange={e => handleChange('website', e.target.value)}
placeholder="https://"
className={FIELD_CLS}
<label className={AMOUNT_FIELD_CLS}>
<Globe size={14} strokeWidth={2} aria-hidden="true" className="flex-none text-m-faint" />
<input
type="url"
dir="ltr"
value={form.website}
onChange={e => handleChange('website', e.target.value)}
placeholder="https://"
aria-label={t('places.formWebsite')}
className="min-w-0 flex-1 bg-transparent font-[inherit] text-[0.84375rem] font-medium text-m-ink outline-none placeholder:text-m-faint"
/>
</label>
<PlContactFields
phone={form.phone ?? ''}
email={form.email ?? ''}
openingHours={form.opening_hours ?? ''}
suggestedHours={detailsHours}
onChange={(field, value, origin) => handleChange(field, value, origin)}
locale={locale}
t={t}
/>
{canUploadFiles && (
@@ -1,7 +1,8 @@
import { Ban, Check, Plus } from 'lucide-react'
import { useState } from 'react'
import { Ban, Check, ChevronDown, Plus, X } from 'lucide-react'
import { getCategoryIcon } from '../../../../components/shared/categoryIcons'
import { useNewCategory } from '../../../../components/Planner/usePlaceForm'
import { FIELD_CLS } from './PlSheetChrome'
import { FIELD_CLS, SELECT_FIELD_CLS } from './PlSheetChrome'
import type { TripPlanner } from '../MTripShell'
interface PlCategoryPickerProps {
@@ -11,89 +12,107 @@ interface PlCategoryPickerProps {
onChange: (categoryId: string) => void
}
const PILL_BASE =
'flex flex-none items-center gap-[5px] rounded-full px-[11px] py-[6px] text-[0.71875rem] font-semibold'
const LIST = 'mt-[6px] max-h-[264px] overflow-y-auto overscroll-contain rounded-2xl border border-[color:var(--m-rowbr)] bg-[color:var(--m-glass)]'
const ROW = 'flex w-full items-center gap-[10px] border-b border-[color:var(--m-rowbr)] px-[13px] py-[11px] text-start last:border-b-0'
const ROW_TEXT = 'min-w-0 flex-1 truncate text-[0.84375rem]'
/**
* Category pills of the place form: "no category" + every trip category, plus
* an inline create flow (dashed pill → name input) the demo leaves out but the
* desktop form has — new categories are selected right away.
* The category of the place form on the phone: one field that opens the list,
* the way the cost sheet picks its category, instead of a pill for every
* category, which took half the sheet on a trip with many. "No category" leads
* the list and a new category is made at its foot, picked straight away like on
* the desktop.
*/
export default function PlCategoryPicker({ planner, value, onChange }: PlCategoryPickerProps) {
const { t, toast, categories, tripActions } = planner
const [open, setOpen] = useState(false)
const pick = (id: string) => {
onChange(id)
setOpen(false)
}
const {
open: creating, setOpen: setCreating, name: newName, setName: setNewName, saving, submit: handleCreate,
} = useNewCategory({ variant: 'sheet', create: tripActions.addCategory, onCreated: onChange, t, toast })
} = useNewCategory({ variant: 'sheet', create: tripActions.addCategory, onCreated: pick, t, toast })
const current = (categories || []).find(cat => String(cat.id) === value)
const CurrentIcon = current ? getCategoryIcon(current.icon) : Ban
return (
<div className="flex flex-wrap gap-[6px]">
<div>
<button
type="button"
onClick={() => onChange('')}
className={`${PILL_BASE} ${value === '' ? 'bg-m-act text-m-actfg' : 'bg-[color:var(--m-ic)] text-m-muted'}`}
aria-expanded={open}
aria-label={`${t('places.formCategory')}: ${current ? current.name : t('places.noCategory')}`}
onClick={() => setOpen(v => !v)}
className={`${SELECT_FIELD_CLS} gap-[10px] text-start`}
>
<Ban size={13} strokeWidth={2} />
{t('places.noCategory')}
<CurrentIcon size={15} strokeWidth={2} className="flex-none" style={current?.color ? { color: current.color } : undefined} />
<span className={`${ROW_TEXT} font-medium ${current ? 'text-m-ink' : 'text-m-faint'}`}>
{current ? current.name : t('places.noCategory')}
</span>
<ChevronDown size={14} strokeWidth={2} className={`flex-none text-m-faint transition-transform duration-200 ${open ? 'rotate-180' : ''}`} />
</button>
{(categories || []).map(cat => {
const active = value === String(cat.id)
const Icon = getCategoryIcon(cat.icon)
return (
<button
key={cat.id}
type="button"
onClick={() => onChange(String(cat.id))}
className={`${PILL_BASE} ${active ? 'bg-m-act text-m-actfg' : 'bg-[color:var(--m-ic)] text-m-muted'}`}
>
<Icon size={13} strokeWidth={2} />
{cat.name}
</button>
)
})}
{!creating ? (
<button
type="button"
onClick={() => setCreating(true)}
className={`${PILL_BASE} border-[1.5px] border-dashed border-[color:var(--m-trackoff)] text-m-muted`}
>
<Plus size={13} strokeWidth={2.2} />
{t('mobileTrip.newCategory')}
</button>
) : (
<div className="mt-1 flex w-full items-center gap-2">
<input
type="text"
value={newName}
onChange={e => setNewName(e.target.value)}
onKeyDown={e => {
if (e.key === 'Enter') {
e.preventDefault()
void handleCreate()
}
}}
placeholder={t('places.categoryNamePlaceholder')}
autoFocus
className={`${FIELD_CLS} flex-1`}
/>
<button
type="button"
onClick={handleCreate}
disabled={!newName.trim() || saving}
aria-label={t('common.add')}
className="flex h-10 w-10 flex-none items-center justify-center rounded-[12px] bg-m-act text-m-actfg disabled:opacity-40"
>
<Check size={15} strokeWidth={2.4} />
</button>
<button
type="button"
onClick={() => {
setCreating(false)
setNewName('')
}}
className="flex-none text-[0.78125rem] font-semibold text-m-muted"
>
{t('common.cancel')}
{open && (
<div className={LIST}>
<button type="button" aria-pressed={value === ''} onClick={() => pick('')} className={ROW}>
<Ban size={14} strokeWidth={2} className="flex-none text-m-muted" />
<span className={`${ROW_TEXT} ${value === '' ? 'font-semibold text-m-ink' : 'text-m-muted'}`}>{t('places.noCategory')}</span>
{value === '' && <Check size={14} strokeWidth={2.4} className="flex-none text-m-ink" />}
</button>
{(categories || []).map(cat => {
const on = value === String(cat.id)
const Icon = getCategoryIcon(cat.icon)
return (
<button key={cat.id} type="button" aria-pressed={on} onClick={() => pick(String(cat.id))} className={ROW}>
<Icon size={14} strokeWidth={2} className="flex-none" style={cat.color ? { color: cat.color } : undefined} />
<span className={`${ROW_TEXT} ${on ? 'font-semibold text-m-ink' : 'text-m-ink'}`}>{cat.name}</span>
{on && <Check size={14} strokeWidth={2.4} className="flex-none text-m-ink" />}
</button>
)
})}
{!creating ? (
<button type="button" onClick={() => setCreating(true)} className={ROW}>
<Plus size={14} strokeWidth={2.2} className="flex-none text-m-muted" />
<span className={`${ROW_TEXT} font-semibold text-m-muted`}>{t('mobileTrip.newCategory')}</span>
</button>
) : (
<div className="flex items-center gap-2 px-[10px] py-[8px]">
<input
type="text"
value={newName}
onChange={e => setNewName(e.target.value)}
onKeyDown={e => {
if (e.key === 'Enter') {
e.preventDefault()
void handleCreate()
}
}}
placeholder={t('places.categoryNamePlaceholder')}
autoFocus
className={`${FIELD_CLS} flex-1`}
/>
<button
type="button"
onClick={handleCreate}
disabled={!newName.trim() || saving}
aria-label={t('common.add')}
className="flex h-10 w-10 flex-none items-center justify-center rounded-full bg-m-act text-m-actfg disabled:opacity-40"
>
<Check size={15} strokeWidth={2.4} />
</button>
<button
type="button"
onClick={() => {
setCreating(false)
setNewName('')
}}
aria-label={t('common.cancel')}
className="flex h-10 w-10 flex-none items-center justify-center rounded-full text-m-muted"
>
<X size={15} strokeWidth={2.2} />
</button>
</div>
)}
</div>
)}
</div>
@@ -0,0 +1,65 @@
// FE-MOB-PLCONTACT-001 to FE-MOB-PLCONTACT-003: phone, e-mail and opening hours on the phone.
import { useState } from 'react';
import { describe, expect, it, vi } from 'vitest';
import { fireEvent, render, screen } from '../../../../../tests/helpers/render';
import { PlContactFields } from './PlContactFields';
const t = (key: string, params?: Record<string, string | number>) =>
params ? `${key}:${Object.values(params).join(',')}` : key;
function Harness({ onChange, start = '' }: { onChange: (field: string, value: string) => void; start?: string }) {
const [state, setState] = useState({ phone: '', email: '', opening_hours: start });
return (
<PlContactFields
phone={state.phone}
email={state.email}
openingHours={state.opening_hours}
locale="en"
t={t}
onChange={(field, value) => {
onChange(field, value);
setState((s) => ({ ...s, [field]: value }));
}}
/>
);
}
describe('PlContactFields', () => {
it('FE-MOB-PLCONTACT-001: phone and e-mail are fields of their own', () => {
const onChange = vi.fn();
render(<Harness onChange={onChange} />);
fireEvent.change(screen.getByLabelText('places.formPhone'), { target: { value: '+1 555' } });
expect(onChange).toHaveBeenLastCalledWith('phone', '+1 555');
fireEvent.change(screen.getByLabelText('places.formEmail'), { target: { value: 'a@b.co' } });
expect(onChange).toHaveBeenLastCalledWith('email', 'a@b.co');
expect(screen.getByLabelText('places.formEmail')).toHaveAttribute('type', 'email');
});
it('FE-MOB-PLCONTACT-002: the week unfolds from one field, and a day opens around the clock or closes', () => {
const onChange = vi.fn();
render(<Harness onChange={onChange} />);
expect(screen.queryByRole('switch', { name: 'Monday: places.hoursAllDay' })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: 'places.hoursAdd' }));
fireEvent.click(screen.getByRole('switch', { name: 'Monday: places.hoursAllDay' }));
expect(JSON.parse(onChange.mock.lastCall![1])[0]).toEqual({ closed: false, open: '00:00', close: '23:59' });
expect(screen.getByRole('switch', { name: 'Monday: places.hoursAllDay' })).toHaveAttribute('aria-checked', 'true');
fireEvent.click(screen.getByRole('switch', { name: 'Tuesday: places.hoursClosed' }));
expect(JSON.parse(onChange.mock.lastCall![1])[1]).toEqual({ closed: true });
expect(screen.getByText('places.hoursClosed')).toBeInTheDocument();
});
it('FE-MOB-PLCONTACT-003: Monday goes to every day, and the week folds away again', () => {
const onChange = vi.fn();
render(<Harness onChange={onChange} />);
fireEvent.click(screen.getByRole('button', { name: 'places.hoursAdd' }));
fireEvent.click(screen.getByRole('switch', { name: 'Monday: places.hoursClosed' }));
fireEvent.click(screen.getByRole('button', { name: 'places.hoursCopyFirst:Monday' }));
expect(JSON.parse(onChange.mock.lastCall![1]).every((d: { closed: boolean }) => d.closed)).toBe(true);
fireEvent.click(screen.getByRole('button', { name: 'places.hoursRemove' }));
expect(onChange).toHaveBeenLastCalledWith('opening_hours', '');
expect(screen.getByRole('button', { name: 'places.hoursAdd' })).toBeInTheDocument();
});
});
@@ -0,0 +1,186 @@
import type { PlaceClientOrigin, PlaceOpeningHours } from '@trek/shared';
import { Clock, Copy, DoorClosed, Mail, Phone, RotateCcw, X } from 'lucide-react';
import { isAllDay, weekdayNames } from '../../../../components/Planner/placeHours';
import { usePlaceHours } from '../../../../components/Planner/usePlaceHours';
import CustomTimePicker from '../../../../components/shared/CustomTimePicker';
import { NO_AUTOFILL } from '../../../../utils/noAutofill';
import { AddFieldButton, AMOUNT_FIELD_CLS, Eyebrow, FORM_PAIR_CLS } from './PlSheetChrome';
type Translate = (key: string, params?: Record<string, string | number>) => string;
const LABEL = 'mb-[5px] mt-3 uppercase';
const BARE_INPUT =
'min-w-0 flex-1 bg-transparent font-[inherit] text-[0.84375rem] font-medium text-m-ink outline-none placeholder:text-m-faint';
const HEAD_BUTTON = 'grid h-[28px] w-[28px] place-items-center rounded-full text-m-muted active:bg-[color:var(--m-ic)]';
const WEEK = 'overflow-hidden rounded-[18px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)]';
const DAY_ROW =
'grid grid-cols-[22px_minmax(0,1fr)_auto] items-center gap-[6px] border-b border-[color:var(--m-rowbr)] px-[8px] py-[6px] last:border-b-0';
/** A closed or all-day day says so where its two times would be. */
const DAY_STATE = 'flex h-[38px] items-center px-[4px] text-[0.78125rem] font-medium text-m-muted';
/** The two switches after the times: round, as tall as a time field. */
const DAY_BUTTON = 'grid h-[30px] w-[30px] flex-none place-items-center rounded-full text-[0.6875rem] font-bold';
const DAY_BUTTON_OFF = 'bg-[color:var(--m-card)] text-m-muted';
const DAY_BUTTON_ON = 'bg-m-act text-m-actfg';
/**
* Phone, e-mail and opening hours on the phone (#2472), as on the desktop. The
* week stays folded behind one row until someone wants it; each day then has
* its two times, a switch for open around the clock and one for closed. The
* hours are usePlaceHours', shared with the desktop dialog.
*/
export function PlContactFields({
phone,
email,
openingHours,
suggestedHours,
onChange,
locale,
t,
}: {
phone: string;
email: string;
openingHours: string;
suggestedHours?: PlaceOpeningHours | null;
onChange: (field: 'phone' | 'email' | 'opening_hours', value: string, origin?: PlaceClientOrigin) => void;
locale: string | undefined;
t: Translate;
}) {
const hours = usePlaceHours({
openingHours,
suggestedHours,
onChange: (value, origin) => onChange('opening_hours', value, origin),
});
const names = weekdayNames(locale, 'short');
const longNames = weekdayNames(locale, 'long');
return (
<>
<div className={`${FORM_PAIR_CLS} mt-3`}>
<div>
<Eyebrow className="mb-[5px] uppercase">{t('places.formPhone')}</Eyebrow>
<label className={AMOUNT_FIELD_CLS}>
<Phone size={14} strokeWidth={2} aria-hidden="true" className="flex-none text-m-faint" />
<input
type="tel"
value={phone}
onChange={(e) => onChange('phone', e.target.value)}
maxLength={50}
placeholder="+49 …"
aria-label={t('places.formPhone')}
className={BARE_INPUT}
{...NO_AUTOFILL}
/>
</label>
</div>
<div>
<Eyebrow className="mb-[5px] uppercase">{t('places.formEmail')}</Eyebrow>
<label className={AMOUNT_FIELD_CLS}>
<Mail size={14} strokeWidth={2} aria-hidden="true" className="flex-none text-m-faint" />
<input
type="email"
dir="ltr"
value={email}
onChange={(e) => onChange('email', e.target.value)}
maxLength={254}
placeholder="info@…"
aria-label={t('places.formEmail')}
className={BARE_INPUT}
{...NO_AUTOFILL}
/>
</label>
</div>
</div>
<div className={`${LABEL} flex items-center`}>
<Eyebrow className="uppercase">{t('inspector.openingHours')}</Eyebrow>
{hours.editing && (
<span className="-my-[6px] ms-auto flex items-center">
{hours.canTakeOver && (
<button
type="button"
onClick={hours.takeOver}
aria-label={t('places.hoursFromDetails')}
className={HEAD_BUTTON}
>
<RotateCcw size={13} strokeWidth={2} />
</button>
)}
<button
type="button"
onClick={hours.copyFirstToAll}
aria-label={t('places.hoursCopyFirst', { day: longNames[0] })}
className={HEAD_BUTTON}
>
<Copy size={13} strokeWidth={2} />
</button>
<button
type="button"
onClick={hours.clearHours}
aria-label={t('places.hoursRemove')}
className={HEAD_BUTTON}
>
<X size={14} strokeWidth={2.2} />
</button>
</span>
)}
</div>
{hours.editing ? (
<div className={WEEK}>
{hours.week.map((day, i) => {
const allDay = isAllDay(day);
return (
<div key={i} className={DAY_ROW}>
<span className="text-[0.71875rem] font-semibold text-m-ink">{names[i]}</span>
{day.closed || allDay ? (
<span className={DAY_STATE}>{day.closed ? t('places.hoursClosed') : t('places.hoursAllDay')}</span>
) : (
<div className="flex min-w-0 items-center gap-[3px]">
<div className="min-w-0 flex-1">
<CustomTimePicker
value={day.open ?? ''}
onChange={(v) => hours.setDay(i, { open: v || undefined })}
aria-label={`${longNames[i]} ${t('places.hoursOpens')}`}
/>
</div>
<div className="min-w-0 flex-1">
<CustomTimePicker
value={day.close ?? ''}
onChange={(v) => hours.setDay(i, { close: v || undefined })}
aria-label={`${longNames[i]} ${t('places.hoursCloses')}`}
/>
</div>
</div>
)}
<div className="flex items-center gap-[3px]">
<button
type="button"
role="switch"
aria-checked={allDay}
aria-label={`${longNames[i]}: ${t('places.hoursAllDay')}`}
onClick={() => hours.toggleAllDay(i)}
className={`${DAY_BUTTON} ${allDay ? DAY_BUTTON_ON : DAY_BUTTON_OFF}`}
>
24h
</button>
<button
type="button"
role="switch"
aria-checked={day.closed}
aria-label={`${longNames[i]}: ${t('places.hoursClosed')}`}
onClick={() => hours.toggleClosed(i)}
className={`${DAY_BUTTON} ${day.closed ? DAY_BUTTON_ON : DAY_BUTTON_OFF}`}
>
<DoorClosed size={14} strokeWidth={2} />
</button>
</div>
</div>
);
})}
</div>
) : (
<AddFieldButton icon={Clock} label={t('places.hoursAdd')} onClick={() => hours.setEditing(true)} />
)}
</>
);
}
@@ -4,14 +4,13 @@ import { openFile } from '../../../../utils/fileDownload'
import { isWalletPass } from '../../../../components/Files/FileManager.helpers'
import type { TripFile } from '../../../../types'
import type { TripPlanner } from '../MTripShell'
import { AddFieldButton, Eyebrow } from './PlSheetChrome'
interface PlFileAttachProps {
planner: TripPlanner
files: File[]
onAdd: (files: File[]) => void
onRemove: (index: number) => void
/** Hide the "you can also paste…" subline (booking/transport sheets keep it terse). */
hideHint?: boolean
/** False hides the picker pill (no upload permission); the row still lists and links files. */
canAttach?: boolean
/** Files already on the record, listed above the pending ones and opened on tap. */
@@ -31,41 +30,23 @@ const ITEM_CLS = 'flex w-full items-center gap-2 rounded-[10px] bg-[color:var(--
* Clipboard paste is handled by the sheet's onPaste so it works from any
* focused field.
*/
export default function PlFileAttach({ planner, files, onAdd, onRemove, hideHint = false, canAttach = true, attached = [], linkable = [], onLink }: PlFileAttachProps) {
export default function PlFileAttach({ planner, files, onAdd, onRemove, canAttach = true, attached = [], linkable = [], onLink }: PlFileAttachProps) {
const { t } = planner
const inputRef = useRef<HTMLInputElement>(null)
const [picking, setPicking] = useState(false)
const canLink = !!onLink && linkable.length > 0
return (
<div className="mt-3 rounded-[13px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] px-3 py-[10px]">
<div className="flex items-center gap-[10px]">
<div className="min-w-0 flex-1">
<div className="text-[0.78125rem] font-semibold text-m-ink">{t('files.title')}</div>
{!hideHint && <div className="truncate font-geist text-[0.65625rem] text-m-faint">{t('files.pasteHint')}</div>}
<div>
<Eyebrow className="mb-[5px] mt-3 uppercase">{t('files.title')}</Eyebrow>
{(canAttach || canLink) && (
<div className={`grid gap-2 ${canAttach && canLink ? 'grid-cols-2' : 'grid-cols-1'}`}>
{canAttach && <AddFieldButton icon={Paperclip} label={t('files.attach')} onClick={() => inputRef.current?.click()} />}
{canLink && (
<AddFieldButton icon={Link2} label={t('files.link')} onClick={() => setPicking(v => !v)} pressed={picking} ariaExpanded={picking} />
)}
</div>
{canLink && (
<button
type="button"
onClick={() => setPicking(v => !v)}
aria-expanded={picking}
className={`flex flex-none items-center gap-[5px] rounded-full border px-3 py-[5px] text-[0.6875rem] font-semibold ${picking ? 'border-transparent bg-m-act text-m-actfg' : 'border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] text-m-ink'}`}
>
<Link2 size={12} strokeWidth={2.2} />
{t('files.link')}
</button>
)}
{canAttach && (
<button
type="button"
onClick={() => inputRef.current?.click()}
className="flex flex-none items-center gap-[5px] rounded-full bg-m-act px-3 py-[6px] text-[0.6875rem] font-semibold text-m-actfg"
>
<Paperclip size={12} strokeWidth={2.2} />
{t('files.attach')}
</button>
)}
</div>
)}
<input
ref={inputRef}
type="file"
@@ -0,0 +1,48 @@
// FE-MOB-PLTEXTS-001 to FE-MOB-PLTEXTS-003: the place's three texts on the phone, one at a time.
import { describe, expect, it, vi } from 'vitest';
import { fireEvent, render, screen } from '../../../../../tests/helpers/render';
import { PlPlaceTexts } from './PlPlaceTexts';
const t = (key: string, params?: Record<string, string | number>) =>
params ? `${key}:${Object.values(params).join(',')}` : key;
function setup(overrides: Partial<Parameters<typeof PlPlaceTexts>[0]> = {}) {
const onChange = vi.fn();
render(<PlPlaceTexts description="A tower" notes="" dayNotes={null} onChange={onChange} t={t} {...overrides} />);
return onChange;
}
describe('PlPlaceTexts', () => {
it('FE-MOB-PLTEXTS-001: heads the texts and shows the description first, with where it appears', () => {
setup();
expect(screen.getByText('places.textsLabel')).toBeInTheDocument();
expect(screen.getByRole('tab', { name: 'places.notesTabAbout' })).toHaveAttribute('aria-selected', 'true');
expect(screen.getByLabelText('places.formDescription')).toBeVisible();
expect(screen.getByLabelText('places.formNotes')).not.toBeVisible();
expect(screen.getByText('places.notesHintDescription')).toBeVisible();
});
it('FE-MOB-PLTEXTS-002: a tab switches the field, and each text writes its own', () => {
const onChange = setup({ notes: 'Cash only' });
fireEvent.click(screen.getByRole('tab', { name: 'places.formNotes' }));
expect(screen.getByLabelText('places.formNotes')).toBeVisible();
expect(screen.getByLabelText('places.formNotes')).toHaveValue('Cash only');
fireEvent.change(screen.getByLabelText('places.formNotes'), { target: { value: 'Cards too' } });
expect(onChange).toHaveBeenLastCalledWith('notes', 'Cards too');
fireEvent.change(screen.getByLabelText('places.formDescription'), { target: { value: 'A tall tower' } });
expect(onChange).toHaveBeenLastCalledWith('description', 'A tall tower');
});
it('FE-MOB-PLTEXTS-003: the day note has a tab of its own only with a visit, named after its day', () => {
const { unmount } = render(<PlPlaceTexts description="" notes="" dayNotes={null} onChange={vi.fn()} t={t} />);
expect(screen.getAllByRole('tab')).toHaveLength(2);
unmount();
const onChange = setup({ dayNotes: 'Meet at 9', dayNumber: 2 });
fireEvent.click(screen.getByRole('tab', { name: 'places.notesTabDayN:2' }));
expect(screen.getByLabelText('places.assignmentNotes')).toHaveValue('Meet at 9');
fireEvent.change(screen.getByLabelText('places.assignmentNotes'), { target: { value: 'Meet at 10' } });
expect(onChange).toHaveBeenLastCalledWith('assignment_notes', 'Meet at 10');
});
});
@@ -0,0 +1,65 @@
import { usePlaceTextTabs, type PlaceTextField } from '../../../../components/Planner/usePlaceTextTabs';
import MSegmented from '../../../components/MSegmented';
import { Eyebrow, FIELD_AREA_CLS } from './PlSheetChrome';
type Translate = (key: string, params?: Record<string, string | number>) => string;
const DOT = 'ms-[5px] inline-block h-[5px] w-[5px] rounded-full bg-current align-middle opacity-60';
/**
* The place's three texts on the phone, as on the desktop: what the place is,
* notes on it, and the note for this day's visit, one at a time under a switch,
* with a line on where the text shows up. The others stay mounted and only
* hidden, so each keeps what was typed; a dot marks a tab that holds text. The
* tabs are usePlaceTextTabs', shared with the desktop card.
*/
export function PlPlaceTexts({
description,
notes,
dayNotes,
dayNumber = null,
onChange,
t,
}: {
description: string;
notes: string;
/** null when no single day-assignment is in context. */
dayNotes: string | null;
dayNumber?: number | null;
onChange: (field: PlaceTextField, value: string) => void;
t: Translate;
}) {
const { tabs, shown, setActive } = usePlaceTextTabs({ description, notes, dayNotes, dayNumber, t });
return (
<div className="flex flex-col gap-2">
<Eyebrow className="-mb-[3px] mt-3 uppercase">{t('places.textsLabel')}</Eyebrow>
<MSegmented
value={shown.field}
onChange={setActive}
options={tabs.map((tab) => ({
value: tab.field,
label: (
<>
{tab.label}
{tab.value.trim() && <span aria-hidden="true" className={DOT} />}
</>
),
}))}
/>
{tabs.map((tab) => (
<div key={tab.field} hidden={tab.field !== shown.field}>
<textarea
value={tab.value}
onChange={(e) => onChange(tab.field, e.target.value)}
rows={3}
maxLength={tab.maxLength}
aria-label={tab.aria}
className={FIELD_AREA_CLS}
/>
<p className="m-0 mt-[5px] px-[6px] font-geist text-[0.65625rem] leading-snug text-m-faint">{tab.hint}</p>
</div>
))}
</div>
);
}
@@ -1,5 +1,5 @@
import { ComponentProps, HTMLAttributes, ReactNode, useState } from 'react'
import { Trash2, X } from 'lucide-react'
import { Plus, Trash2, X } from 'lucide-react'
import type { LucideIcon } from 'lucide-react'
import MIconBtn from '../../../components/MIconBtn'
import { edgeFadeClass, useEdgeFade } from '../../../components/useEdgeFade'
@@ -35,6 +35,35 @@ export const FORM_PAIR_CLS = 'grid grid-cols-1 gap-2 [@container(min-width:400px
export const SELECT_FIELD_CLS =
'flex h-[42px] w-full min-w-0 items-center overflow-hidden rounded-full border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] px-[14px]'
/**
* A button that adds something (opening hours, a file, an expense), drawn as an
* empty field of the form: its icon, the action in the placeholder's grey and a
* plus at the end, so it reads as one more field and not as a card of its own.
*/
export function AddFieldButton({ icon: Icon, label, onClick, disabled, pressed, ariaExpanded }: {
icon: LucideIcon
label: string
onClick: () => void
disabled?: boolean
/** Drawn as switched on, for a button that opens a list under it. */
pressed?: boolean
ariaExpanded?: boolean
}) {
return (
<button
type="button"
onClick={onClick}
disabled={disabled}
aria-expanded={ariaExpanded}
className={`${SELECT_FIELD_CLS} gap-[10px] text-start disabled:opacity-40 ${pressed ? '!border-transparent !bg-m-act text-m-actfg' : 'text-m-faint'}`}
>
<Icon size={14} strokeWidth={2} aria-hidden="true" className="flex-none" />
<span className="min-w-0 flex-1 truncate text-[0.84375rem] font-medium">{label}</span>
<Plus size={14} strokeWidth={2.2} aria-hidden="true" className="flex-none" />
</button>
)
}
export const FIELD_AREA_CLS =
'w-full box-border resize-none rounded-[18px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] px-[14px] py-[10px] font-geist text-[0.78125rem] leading-[1.5] text-m-ink outline-none placeholder:text-m-faint'
@@ -1,4 +1,4 @@
// FE-MOB-PLTAGS-001 to FE-MOB-PLTAGS-005: the phone's tag markup, which is the picker of the
// FE-MOB-PLTAGS-001 to FE-MOB-PLTAGS-007: the phone's tag markup, which is the picker of the
// place form (its state is usePlaceTags', tested on its own) and the chips of the place sheet.
import { describe, expect, it, vi } from 'vitest';
@@ -17,6 +17,9 @@ function field(overrides: Partial<PlaceTagsField> = {}): PlaceTagsField {
toggle: vi.fn(),
name: '',
setName: vi.fn(),
newColor: '#ec4899',
setNewColor: vi.fn(),
recolor: vi.fn(() => Promise.resolve()),
saving: false,
canAdd: false,
addNew: vi.fn(() => Promise.resolve()),
@@ -61,6 +64,29 @@ describe('PlTagPicker', () => {
});
});
describe('PlTagPicker colours', () => {
it("FE-MOB-PLTAGS-006: a chip's dot opens the palette in the sheet, and a swatch recolours that tag", () => {
const tags = field();
render(<PlTagPicker tags={tags} t={t} />);
const dot = screen.getAllByRole('button', { name: 'places.tagColor' })[1];
fireEvent.click(dot);
expect(dot).toHaveAttribute('aria-expanded', 'true');
fireEvent.click(screen.getByRole('button', { name: '#10b981' }));
expect(tags.recolor).toHaveBeenCalledWith(8, '#10b981');
expect(screen.queryByRole('button', { name: '#10b981' })).not.toBeInTheDocument();
});
it('FE-MOB-PLTAGS-007: the dot in front of the new tag picks its colour, and the add button takes it on', () => {
const tags = field({ name: 'Food', canAdd: true });
render(<PlTagPicker tags={tags} t={t} />);
fireEvent.click(screen.getByRole('button', { name: 'places.newTagColor' }));
fireEvent.click(screen.getByRole('button', { name: '#f97316' }));
expect(tags.setNewColor).toHaveBeenCalledWith('#f97316');
expect(tags.recolor).not.toHaveBeenCalled();
expect(screen.getByRole('button', { name: 'places.addTag' }).style.background).toContain('236, 72, 153');
});
});
describe('PlTagChips', () => {
it('FE-MOB-PLTAGS-004: shows the tags a place carries, each once and by name', () => {
const { container } = render(
+141 -44
View File
@@ -1,65 +1,162 @@
import { TRIP_TAG_NAME_MAX } from '@trek/shared';
import { Check, Tag as TagIcon } from 'lucide-react';
import { Check, Plus, Tag as TagIcon } from 'lucide-react';
import { useState } from 'react';
import { TagColorPopover } from '../../../../components/Planner/TagColorPopover';
import type { PlaceTagsField } from '../../../../components/Planner/usePlaceTags';
import type { Place } from '../../../../types';
import { tagChoices } from '../../../../utils/placeTags';
import MChip from '../../../components/MChip';
import { Eyebrow, FIELD_CLS } from './PlSheetChrome';
import { Eyebrow } from './PlSheetChrome';
type Translate = (key: string, params?: Record<string, string | number>) => string;
const LABEL = 'mb-[6px] mt-3 uppercase';
const PICKER = 'flex flex-wrap gap-[6px]';
const NEW_TAG = 'mt-2 flex items-center gap-2';
const CONFIRM =
'flex h-10 w-10 flex-none items-center justify-center rounded-[12px] bg-m-act text-m-actfg disabled:opacity-40';
const CHIPS = 'mt-[6px] flex flex-wrap gap-1';
const LABEL = 'mb-[5px] mt-3 uppercase';
/** The one field the tags live in: their chips, then where a new one is typed. */
const FIELD =
'flex min-h-[42px] w-full flex-wrap items-center gap-[5px] rounded-[21px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] p-[5px]';
/** One tag: its colour dot and its name, two buttons in one chip. */
const CHIP =
'inline-flex h-[30px] min-w-0 max-w-full items-center rounded-full border transition-[background-color,border-color] duration-150';
const CHIP_OFF = 'border-[color:var(--m-rowbr)] bg-[color:var(--m-card)]';
const DOT_BUTTON = 'grid h-[30px] w-[26px] flex-none place-items-center ps-[3px]';
const DOT = 'h-[12px] w-[12px] rounded-full ring-1 ring-inset ring-[color:var(--m-rowbr)]';
const NAME_BUTTON = 'inline-flex h-full min-w-0 items-center gap-[5px] text-[0.75rem] font-semibold';
/** The tick of a picked tag, in a round white badge. */
const TICK =
'me-[3px] grid h-[22px] w-[22px] flex-none place-items-center rounded-full bg-[color:var(--m-card)] shadow-sm';
/** Where a new tag is typed: the rest of the field's line, at least wide enough for a short name. */
const NEW_TAG = 'flex h-[30px] min-w-[9rem] flex-1 items-center gap-[6px]';
const NEW_INPUT =
'min-w-0 flex-1 bg-transparent font-[inherit] text-[0.75rem] font-semibold text-m-ink outline-none placeholder:font-medium placeholder:text-m-faint';
const ADD_BUTTON = 'grid h-[30px] w-[30px] flex-none place-items-center rounded-full';
/** The palette laid into the sheet under the field, in the sheet's own surface. */
const PALETTE =
'mt-2 flex w-full flex-col gap-2.5 rounded-[18px] border border-[color:var(--m-rowbr)] bg-[color:var(--m-ic)] p-3';
const CHIPS = 'mt-[6px] flex flex-wrap gap-1';
const SHEET_CHIP =
'inline-flex max-w-full items-center gap-1 rounded-full border border-[color:var(--m-faint)] px-2 py-[2px] font-geist text-caption font-semibold text-m-muted';
const FALLBACK_COLOR = 'var(--m-faint)';
const tint = (color: string, percent: number) => `color-mix(in srgb, ${color} ${percent}%, var(--m-card))`;
/**
* The tags of the place form on the phone: its label, every tag on offer as a chip to
* switch on or off, and a field that adds a new one to the trip. The state is
* The tags of the place form on the phone, in one field like the sheet's others:
* every tag on offer is a chip in its own colour inside it (the name ticks it,
* the dot opens the palette that recolours it for the whole trip), and the rest
* of the field takes a new tag, in a colour picked by the dot in front of it. The
* palette opens into the sheet under the field rather than floating. The state is
* usePlaceTags', run by the sheet; this is its markup.
*/
export function PlTagPicker({ tags, t }: { tags: PlaceTagsField; t: Translate }) {
const [palette, setPalette] = useState<number | 'new' | null>(null);
const [preview, setPreview] = useState<{ id: number; color: string } | null>(null);
const closePalette = () => {
setPalette(null);
setPreview(null);
};
const toggle = (which: number | 'new') => (palette === which ? closePalette() : setPalette(which));
const open = typeof palette === 'number' ? tags.options.find((tag) => tag.id === palette) : undefined;
return (
<>
<Eyebrow className={LABEL}>{t('places.tags')}</Eyebrow>
<div role="group" aria-label={t('places.tags')} className={PICKER}>
{tags.options.map((tag) => (
<MChip key={tag.id} pressable active={tag.on} onClick={() => tags.toggle(tag.id)}>
<TagIcon
size={12}
strokeWidth={2.2}
className="flex-none"
style={{ color: tag.on ? undefined : tag.color }}
<div>
<div role="group" aria-label={t('places.tags')} className={FIELD}>
{tags.options.map((tag) => {
const color = (preview?.id === tag.id ? preview.color : tag.color) ?? FALLBACK_COLOR;
return (
<span
key={tag.id}
className={`${CHIP} ${tag.on ? '' : CHIP_OFF}`}
style={tag.on ? { background: tint(color, 22), borderColor: tint(color, 55) } : undefined}
>
<button
type="button"
aria-label={t('places.tagColor', { name: tag.name })}
aria-expanded={palette === tag.id}
onClick={() => toggle(tag.id)}
className={DOT_BUTTON}
>
<span aria-hidden="true" className={DOT} style={{ background: color }} />
</button>
<button
type="button"
aria-pressed={tag.on}
onClick={() => tags.toggle(tag.id)}
className={`${NAME_BUTTON} ${tag.on ? 'ps-[2px] text-m-ink' : 'pe-[11px] ps-[2px] text-m-muted'}`}
>
<span dir="auto" className="truncate">
{tag.name}
</span>
{tag.on && (
<span aria-hidden="true" className={TICK}>
<Check size={12} strokeWidth={3.2} style={{ color }} />
</span>
)}
</button>
</span>
);
})}
<span className={`${NEW_TAG} ${tags.options.length ? 'ps-[4px]' : 'ps-[8px]'}`}>
<button
type="button"
aria-label={t('places.newTagColor')}
aria-expanded={palette === 'new'}
onClick={() => toggle('new')}
className="grid h-[30px] w-[18px] flex-none place-items-center"
>
<span
aria-hidden="true"
className="h-[14px] w-[14px] rounded-full ring-1 ring-inset ring-[color:var(--m-rowbr)]"
style={{ background: tags.newColor }}
/>
</button>
<input
type="text"
value={tags.name}
onChange={(e) => tags.setName(e.target.value)}
onKeyDown={tags.handleNameKey}
maxLength={TRIP_TAG_NAME_MAX}
aria-label={t('places.newTag')}
placeholder={t('places.newTag')}
enterKeyHint="done"
className={NEW_INPUT}
/>
{tag.name}
</MChip>
))}
</div>
<div className={NEW_TAG}>
<input
type="text"
value={tags.name}
onChange={(e) => tags.setName(e.target.value)}
onKeyDown={tags.handleNameKey}
maxLength={TRIP_TAG_NAME_MAX}
aria-label={t('places.newTag')}
placeholder={t('places.newTag')}
className={FIELD_CLS}
/>
<button
type="button"
onClick={() => void tags.addNew()}
disabled={!tags.canAdd}
aria-label={t('places.addTag')}
className={CONFIRM}
>
<Check size={15} strokeWidth={2.4} />
</button>
<button
type="button"
onClick={() => void tags.addNew()}
disabled={!tags.canAdd}
aria-label={t('places.addTag')}
className={`${ADD_BUTTON} ${tags.canAdd ? '' : 'text-m-faint'}`}
style={tags.canAdd ? { background: tags.newColor, color: 'var(--m-card)' } : undefined}
>
<Plus size={15} strokeWidth={2.6} />
</button>
</span>
</div>
{open && (
<TagColorPopover
key={open.id}
label={t('places.tagColor', { name: open.name })}
value={open.color ?? null}
onPick={(next) => void tags.recolor(open.id, next)}
onPreview={(next) => setPreview({ id: open.id, color: next })}
onClose={closePalette}
className={PALETTE}
t={t}
/>
)}
{palette === 'new' && (
<TagColorPopover
label={t('places.newTagColor')}
value={tags.newColor}
onPick={tags.setNewColor}
onPreview={tags.setNewColor}
onClose={closePalette}
className={PALETTE}
t={t}
/>
)}
</div>
</>
);
@@ -72,7 +169,7 @@ export function PlTagChips({ tags }: { tags: Place['tags'] }) {
return (
<div className={CHIPS}>
{shown.map((tag) => (
<span key={tag.id} className={CHIP}>
<span key={tag.id} className={SHEET_CHIP}>
<TagIcon size={10} strokeWidth={2} className="flex-none" style={{ color: tag.color }} />
<span dir="auto" className="truncate">
{tag.name}