You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
363 lines
9.1 KiB
363 lines
9.1 KiB
import type { Morfo } from '../types';
|
|
import { v } from '../types';
|
|
|
|
/**
|
|
* DateRangePicker — composite popover containing a DateRangeField (segmented
|
|
* inputs) + RangeCalendar. The morfo declares the picker's own surface
|
|
* (trigger + calendar shell + dismissal events); cell-level events and
|
|
* range tracking are owned by the `range-calendar` morfo.
|
|
*/
|
|
export const dateRangePickerMorfo = {
|
|
name: 'DateRangePicker',
|
|
kebab: 'date-range-picker',
|
|
scope: ['soma', 'sema'],
|
|
expression: "delegated",
|
|
apg: 'https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/',
|
|
texts: {
|
|
label: '#?components.date-range-picker.label|Date range picker',
|
|
trigger: '#?components.date-range-picker.trigger|Open range calendar',
|
|
calendar: '#?components.date-range-picker.calendar|Date range calendar'
|
|
},
|
|
|
|
events: [
|
|
{
|
|
name: 'open',
|
|
semantic: {
|
|
family: 'emerge',
|
|
verb: 'open',
|
|
target: v.partRef('calendar'),
|
|
sequence: 'pre',
|
|
intent: {
|
|
fromProp: 'intent',
|
|
default: 'neutral',
|
|
supported: ['neutral', 'affirm', 'risk']
|
|
}
|
|
},
|
|
commits: {
|
|
part: v.partRef('calendar'),
|
|
attr: 'data-state',
|
|
value: 'open'
|
|
}
|
|
},
|
|
{
|
|
// Polymorphic close (book §5.3). Provider-set `data-last-action`
|
|
// values: 'range-committed' (Save when range complete) /
|
|
// 'cancelled' (Cancel button) / 'dismissed' (Escape) /
|
|
// 'dismissed-outside' (click outside).
|
|
name: 'close',
|
|
semantic: {
|
|
family: 'emerge',
|
|
verb: 'close',
|
|
target: v.partRef('calendar'),
|
|
sequence: 'pre',
|
|
persistence: 'transient',
|
|
allowedFamilies: ['emerge', 'commit', 'signal']
|
|
},
|
|
regime: 'lock',
|
|
commits: {
|
|
part: v.partRef('calendar'),
|
|
attr: 'data-state',
|
|
value: 'closed'
|
|
}
|
|
},
|
|
{
|
|
// User cleared the range (explicit clear button or backspace).
|
|
name: 'commit-reset',
|
|
semantic: {
|
|
family: 'commit',
|
|
verb: 'reset',
|
|
target: v.partRef('calendar'),
|
|
sequence: 'post',
|
|
intent: 'neutral'
|
|
}
|
|
}
|
|
],
|
|
|
|
focus: {
|
|
initial: 'first-focusable',
|
|
trap: true,
|
|
return: 'trigger',
|
|
restore: true
|
|
},
|
|
|
|
parts: [
|
|
{
|
|
name: 'Provider',
|
|
kebab: 'provider',
|
|
archetype: 'provider',
|
|
kind: 'public',
|
|
defaultElement: 'div',
|
|
optional: false,
|
|
states: ['open', 'closed'],
|
|
data: [
|
|
{ attr: 'data-state', values: ['open', 'closed'], value: v.stateRef('open') },
|
|
{ attr: 'data-disabled', value: v.propRef('disabled'), severity: 'optional' },
|
|
{ attr: 'data-readonly', value: v.propRef('readonly'), severity: 'optional' },
|
|
{ attr: 'data-required', value: v.propRef('required'), severity: 'optional' },
|
|
{ attr: 'data-invalid', value: v.propRef('invalid'), severity: 'optional' }
|
|
],
|
|
aria: [
|
|
{ attr: 'aria-disabled', value: v.propRef('disabled'), severity: 'optional' },
|
|
{ attr: 'aria-readonly', value: v.propRef('readonly'), severity: 'optional' },
|
|
{ attr: 'aria-required', value: v.propRef('required'), severity: 'optional' }
|
|
]
|
|
},
|
|
{
|
|
name: 'Trigger',
|
|
kebab: 'trigger',
|
|
archetype: 'trigger',
|
|
kind: 'public',
|
|
defaultElement: 'button',
|
|
role: 'button',
|
|
optional: false,
|
|
states: ['open', 'closed'],
|
|
data: [{ attr: 'data-state', values: ['open', 'closed'], value: v.stateRef('open') }],
|
|
aria: [
|
|
{ attr: 'type', value: v.literal('button') },
|
|
{ attr: 'aria-haspopup', value: v.literal('dialog') },
|
|
{ attr: 'aria-expanded', value: v.stateRef('open') },
|
|
{
|
|
attr: 'aria-controls',
|
|
value: v.partRef('calendar'),
|
|
condition: { when: 'part-present', part: 'calendar' },
|
|
severity: 'recommended'
|
|
},
|
|
{
|
|
attr: 'aria-label',
|
|
value: v.translationRef('#?components.date-range-picker.trigger|Open range calendar'),
|
|
severity: 'recommended'
|
|
}
|
|
],
|
|
keyboard: [
|
|
{ key: 'Enter', action: 'open' },
|
|
{ key: ' ', action: 'open' }
|
|
]
|
|
},
|
|
{
|
|
name: 'Calendar',
|
|
kebab: 'calendar',
|
|
archetype: 'content',
|
|
kind: 'public',
|
|
defaultElement: 'div',
|
|
role: 'dialog',
|
|
optional: false,
|
|
states: ['open', 'closed'],
|
|
data: [
|
|
{ attr: 'data-state', values: ['open', 'closed'], value: v.stateRef('open') },
|
|
{
|
|
/**
|
|
* Causal exit reason — mirror of dialog's `data-last-action`.
|
|
* Updated by `prewrite` BEFORE `data-state` flips to `closed`,
|
|
* so Sema can tint the exit animation per-action.
|
|
*/
|
|
attr: 'data-last-action',
|
|
values: ['range-committed', 'cancelled', 'dismissed', 'dismissed-outside'],
|
|
severity: 'optional'
|
|
},
|
|
{
|
|
attr: 'data-starting-style',
|
|
severity: 'optional',
|
|
condition: { when: 'state-equals', state: 'open', value: 'starting' }
|
|
},
|
|
{
|
|
attr: 'data-ending-style',
|
|
severity: 'optional',
|
|
condition: { when: 'state-equals', state: 'closed', value: 'ending' }
|
|
}
|
|
],
|
|
aria: [
|
|
{
|
|
attr: 'aria-label',
|
|
value: v.translationRef('#?components.date-range-picker.calendar|Date range calendar'),
|
|
severity: 'recommended'
|
|
}
|
|
],
|
|
keyboard: [
|
|
{ key: 'Escape', action: 'close' },
|
|
{ key: 'Tab', action: 'focus-next' },
|
|
{ key: 'Shift+Tab', action: 'focus-prev' }
|
|
]
|
|
},
|
|
{
|
|
// Month-view range bridge for `kind='month'`. Owns the range
|
|
// selection state machine (empty / pending / complete) + year
|
|
// stepper. Visual chrome painted by eidos via the snippet.
|
|
name: 'MonthView',
|
|
kebab: 'month-view',
|
|
archetype: 'group',
|
|
kind: 'public',
|
|
defaultElement: 'div',
|
|
role: 'grid',
|
|
optional: true,
|
|
data: [],
|
|
aria: [
|
|
{
|
|
attr: 'aria-label',
|
|
value: v.literal('Select month range'),
|
|
severity: 'optional'
|
|
}
|
|
]
|
|
},
|
|
// MonthView internal layout slots — stamped by soma, targeted
|
|
// by eidos CSS. Flat in the morfo per `month-view-*` namespacing.
|
|
{
|
|
name: 'MonthViewHeader',
|
|
kebab: 'month-view-header',
|
|
archetype: 'header',
|
|
kind: 'public',
|
|
defaultElement: 'div',
|
|
optional: true,
|
|
data: [],
|
|
aria: []
|
|
},
|
|
{
|
|
name: 'MonthViewPrev',
|
|
kebab: 'month-view-prev',
|
|
archetype: 'trigger',
|
|
kind: 'public',
|
|
defaultElement: 'button',
|
|
role: 'button',
|
|
optional: true,
|
|
data: [],
|
|
aria: [{ attr: 'type', value: v.literal('button') }]
|
|
},
|
|
{
|
|
name: 'MonthViewHeading',
|
|
kebab: 'month-view-heading',
|
|
archetype: 'label',
|
|
kind: 'public',
|
|
defaultElement: 'span',
|
|
optional: true,
|
|
data: [],
|
|
aria: []
|
|
},
|
|
{
|
|
name: 'MonthViewNext',
|
|
kebab: 'month-view-next',
|
|
archetype: 'trigger',
|
|
kind: 'public',
|
|
defaultElement: 'button',
|
|
role: 'button',
|
|
optional: true,
|
|
data: [],
|
|
aria: [{ attr: 'type', value: v.literal('button') }]
|
|
},
|
|
{
|
|
name: 'MonthViewGrid',
|
|
kebab: 'month-view-grid',
|
|
archetype: 'group',
|
|
kind: 'public',
|
|
defaultElement: 'div',
|
|
optional: true,
|
|
data: [],
|
|
aria: []
|
|
},
|
|
{
|
|
name: 'MonthViewCell',
|
|
kebab: 'month-view-cell',
|
|
archetype: 'item',
|
|
kind: 'public',
|
|
defaultElement: 'button',
|
|
role: 'button',
|
|
optional: true,
|
|
data: [
|
|
{ attr: 'data-range-start', severity: 'optional' },
|
|
{ attr: 'data-range-end', severity: 'optional' },
|
|
{ attr: 'data-in-range', severity: 'optional' }
|
|
],
|
|
aria: [{ attr: 'type', value: v.literal('button') }]
|
|
},
|
|
{
|
|
// Year-view range bridge for `kind='year'`. Symmetric to the
|
|
// MonthView but with decade pagination.
|
|
name: 'YearView',
|
|
kebab: 'year-view',
|
|
archetype: 'group',
|
|
kind: 'public',
|
|
defaultElement: 'div',
|
|
role: 'grid',
|
|
optional: true,
|
|
data: [],
|
|
aria: [
|
|
{
|
|
attr: 'aria-label',
|
|
value: v.literal('Select year range'),
|
|
severity: 'optional'
|
|
}
|
|
]
|
|
},
|
|
// YearView internal layout slots — same shape as MonthView's, with
|
|
// decade navigation labels.
|
|
{
|
|
name: 'YearViewHeader',
|
|
kebab: 'year-view-header',
|
|
archetype: 'header',
|
|
kind: 'public',
|
|
defaultElement: 'div',
|
|
optional: true,
|
|
data: [],
|
|
aria: []
|
|
},
|
|
{
|
|
name: 'YearViewPrev',
|
|
kebab: 'year-view-prev',
|
|
archetype: 'trigger',
|
|
kind: 'public',
|
|
defaultElement: 'button',
|
|
role: 'button',
|
|
optional: true,
|
|
data: [],
|
|
aria: [{ attr: 'type', value: v.literal('button') }]
|
|
},
|
|
{
|
|
name: 'YearViewHeading',
|
|
kebab: 'year-view-heading',
|
|
archetype: 'label',
|
|
kind: 'public',
|
|
defaultElement: 'span',
|
|
optional: true,
|
|
data: [],
|
|
aria: []
|
|
},
|
|
{
|
|
name: 'YearViewNext',
|
|
kebab: 'year-view-next',
|
|
archetype: 'trigger',
|
|
kind: 'public',
|
|
defaultElement: 'button',
|
|
role: 'button',
|
|
optional: true,
|
|
data: [],
|
|
aria: [{ attr: 'type', value: v.literal('button') }]
|
|
},
|
|
{
|
|
name: 'YearViewGrid',
|
|
kebab: 'year-view-grid',
|
|
archetype: 'group',
|
|
kind: 'public',
|
|
defaultElement: 'div',
|
|
optional: true,
|
|
data: [],
|
|
aria: []
|
|
},
|
|
{
|
|
name: 'YearViewCell',
|
|
kebab: 'year-view-cell',
|
|
archetype: 'item',
|
|
kind: 'public',
|
|
defaultElement: 'button',
|
|
role: 'button',
|
|
optional: true,
|
|
data: [
|
|
{ attr: 'data-range-start', severity: 'optional' },
|
|
{ attr: 'data-range-end', severity: 'optional' },
|
|
{ attr: 'data-in-range', severity: 'optional' }
|
|
],
|
|
aria: [{ attr: 'type', value: v.literal('button') }]
|
|
}
|
|
// Footer / Clear / Cancel / Close — chrome shared via picker-shell;
|
|
// not declared here. Eidos `<DateRangePicker.Footer/Clear/Cancel/
|
|
// Close>` re-exports the `<PickerShell.…>` parts.
|
|
]
|
|
} as const satisfies Morfo;
|