# Compose modal

Source: https://ecosphere.dev/docs/feedback/compose-modal (Ecosphere 1.5). Install `vue-ecosphere` for Vue 3 or `react-ecosphere` for React 18.2+/19: same components, props, markup and stylesheet.

The centred new-message window for long-form composition: To with Cc and Bcc, Subject, the message, formatting, and Send.

`import { EcoComposeModal } from "vue-ecosphere"`

## Compose

Fill in To and a message to enable Send. The font button shows the formatting bar; the chevron schedules.

Vue (vue-ecosphere):

```vue
<EcoButton variant="primary" icon="edit-line" @click="open = true">New message</EcoButton>

<EcoComposeModal
  v-model:open="open" v-model:to="to" v-model:subject="subject" v-model:body="body"
  :when="when" @send="send" @schedule="when = 'Tomorrow, 09:00'" @format="(k) => …" @discard="…"
/>
```

React (react-ecosphere):

```tsx
const [open, setOpen] = useState(false);
const [to, setTo] = useState("");
const [subject, setSubject] = useState("");
const [body, setBody] = useState("");

<EcoButton variant="primary" icon="edit-line" onClick={() => setOpen(true)}>New message</EcoButton>

<EcoComposeModal
  open={open} onOpenChange={setOpen} to={to} onToChange={setTo}
  subject={subject} onSubjectChange={setSubject} body={body} onBodyChange={setBody}
  when={when} onSend={send} onSchedule={() => setWhen("Tomorrow, 09:00")} onFormat={(k) => …} onDiscard={…}
/>
```

## With a record rail

Context about the recipient beside the draft.

Vue (vue-ecosphere):

```vue
<EcoComposeModal v-model:open="open" to="grace.kim@example.com">
  <template #rail>
    <dl class="kv">…</dl>
  </template>
</EcoComposeModal>
```

React (react-ecosphere):

```tsx
<EcoComposeModal open={open} onOpenChange={setOpen} defaultTo="grace.kim@example.com"
  rail={
    <dl className="kv">…</dl>
  }
/>
```

## API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `v-model:open` | `boolean` | false | Shows cmodal and cscrim (teleported to body). Escape and × close it; focus is trapped and returns. |
| `v-model:to / cc / bcc / subject / body` | `string` | "" | The fields. Cc and Bcc rows appear when their toggle is pressed. |
| `title` | `string` | "New message" | cmodal__t. |
| `sendLabel` | `string` | "Send" | Primary action. Disabled until To and a subject or message are filled (or sendEnabled). |
| `schedulable` | `boolean` | true | Shows the split-btn chevron (emits schedule). |
| `sendLoading` | `boolean` | false | The send is running: Send shows a spinner and ignores clicks, and ×, Discard and Escape do nothing. Close it yourself on success; clear it on failure so the draft stays. |
| `when` | `string` | — | Scheduled time shown in the footer (cwhen). |
| `dismissible` | `boolean` | false | Close on a scrim click (off: a stray click should not throw away a draft). |
| `#to` | `slot` | — | Replace the To input (e.g. a recipient picker). |
| `#rail` | `slot` | — | Record context in the crail side panel (cmodal.has-rail). |
| `@send / @schedule / @attach / @discard / @format / @close` | `events` | — | send carries { to, cc, bcc, subject, body }; format carries b \| i \| u \| ul \| ol \| quote \| link \| clear. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `open / onOpenChange` | `boolean` | false | Shows cmodal and cscrim (portalled to body). Escape and × close it; focus is trapped and returns. Or defaultOpen, uncontrolled. |
| `to / cc / bcc / subject / body` | `string` | "" | The fields, each with its onToChange, onCcChange… (or defaultTo, defaultCc… uncontrolled). Cc and Bcc rows appear when their toggle is pressed. |
| `title` | `string` | "New message" | cmodal__t. |
| `sendLabel` | `string` | "Send" | Primary action. Disabled until To and a subject or message are filled (or sendEnabled). |
| `schedulable` | `boolean` | true | Shows the split-btn chevron (emits schedule). |
| `sendLoading` | `boolean` | false | The send is running: Send shows a spinner and ignores clicks, and ×, Discard and Escape do nothing. Close it yourself on success; clear it on failure so the draft stays. |
| `when` | `string` | — | Scheduled time shown in the footer (cwhen). |
| `dismissible` | `boolean` | false | Close on a scrim click (off: a stray click should not throw away a draft). |
| `toField` | `ReactNode` | — | Replace the To input (e.g. a recipient picker). |
| `rail` | `ReactNode` | — | Record context in the crail side panel (cmodal.has-rail). |
| `onSend / onSchedule / onAttach / onDiscard / onFormat / onClose` | `events` | — | send carries { to, cc, bcc, subject, body }; format carries b \| i \| u \| ul \| ol \| quote \| link \| clear. |
