# Connect

> Connecting a service.

Pattern · Pro kit · [Live page](https://ui.twentyfirst.media/pro/patterns/ConnectScreen/)

Connecting a service. For Gmail: every permission with its level (read only, can act) and whether
the assistant asks first, where the data is stored and for how long, then the provider's sign-in.
For Apple Health: pairing through the phone app with a QR code, because the data lives on the
iPhone.

## Code

```tsx
import * as React from "react";
import {
  Button,
  ConsentList,
  Icon,
  KeyValue,
  Panel,
  QrCode,
  ServiceMark,
} from "@twentyfirstmedia/pro";
import type { ConsentConnector } from "@twentyfirstmedia/pro";
import "./_connectors";

/**
 * Connecting a service: what the assistant may do (each permission with its level and whether it
 * asks first), where the data stays, then the provider's sign-in. Apple Health connects through
 * the phone app instead.
 */
export default function Preview() {
  const [gmail, setGmail] = React.useState<ConsentConnector>({
    id: "gmail",
    name: "Gmail",
    icon: "brandGmail",
    purpose: "Finds bills, deadlines and travel plans in your mail and drafts replies for you.",
    scopes: [
      { id: "read", label: "Read messages", granted: true, required: true, level: "read" },
      { id: "label", label: "Sort and label", granted: true, level: "act" },
      {
        id: "draft",
        label: "Draft replies",
        description: "Saved as drafts; nothing is sent",
        granted: true,
        level: "act",
      },
      {
        id: "send",
        label: "Send on your behalf",
        description: "Each message waits for your OK",
        granted: false,
        level: "act",
        asksFirst: true,
      },
    ],
  });
  return (
    <div
      className="tf-grid"
      style={
        {
          "--cols": "minmax(0, 3fr) minmax(0, 2fr)",
          "--cols-sm": "1fr",
          gap: 16,
          alignItems: "start",
        } as React.CSSProperties
      }
    >
      <Panel title="Connect Gmail" subtitle="Life asks for these permissions">
        <div className="tf-row" style={{ gap: 10 }} aria-hidden>
          <ServiceMark name="Life" icon="sparkle" tint="lilac" size="lg" decorative />
          <Icon name="link" size={16} />
          <ServiceMark name="Gmail" icon="brandGmail" size="lg" decorative />
        </div>
        <ConsentList
          connectors={[gmail]}
          label="Gmail permissions"
          onScopeChange={(_, s, granted) =>
            setGmail((g) => ({
              ...g,
              scopes: g.scopes.map((x) => (x.id === s ? { ...x, granted } : x)),
            }))
          }
        />
        <KeyValue
          items={[
            ["Stored", "In the EU, encrypted"],
            ["Kept", "90 days, then summaries only"],
            ["Used for training", "Never"],
            ["Revoke", "Any time under Data access"],
          ]}
        />
        <div className="tf-row" style={{ justifyContent: "flex-end" }}>
          <Button variant="secondary">Cancel</Button>
          <Button icon="brandGoogle">Continue with Google</Button>
        </div>
      </Panel>
      <Panel
        title="Connect Apple Health"
        subtitle="Health data stays on your iPhone until you share it"
      >
        <ServiceMark name="Apple Health" icon="brandApplehealth" size="lg" />
        <p style={{ margin: 0 }}>
          Open the Life app on your iPhone and scan this code. It asks iOS for steps, sleep, heart
          rate and workouts; you pick each type there.
        </p>
        <div style={{ maxWidth: 200 }}>
          <QrCode value="https://life.example/pair/7KQ-48D" />
        </div>
        <KeyValue items={[["Pairing code", "7KQ-48D", true]]} />
      </Panel>
    </div>
  );
}
```

## Props

### ConsentList

| Prop | Type | Notes |
| --- | --- | --- |
| `surface?` | `Surface` | `"glass"`: translucent glass over a backdrop (`Ambient`, a photo, a map); `"solid"` opts out inside a glass `UIProvider`. |
| `connectors` | `ConsentConnector[]` | Required |
| `onScopeChange?` | `(connectorId: string, scopeId: string, granted: boolean) => void` |  |
| `onRevoke?` | `(connectorId: string) => void` |  |
| `label?` | `string` | Accessible name (default "Data access"). |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### KeyValue

| Prop | Type | Notes |
| --- | --- | --- |
| `items` | `KeyValueItem[]` | Required |
| `dense?` | `boolean` |  |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### Panel

| Prop | Type | Notes |
| --- | --- | --- |
| `side?` | `boolean` |  |
| `title?` | `string` |  |
| `subtitle?` | `string` |  |
| `action?` | `ReactNode` |  |
| `children?` | `ReactNode` |  |
| `surface?` | `Surface` | `"glass"`: translucent glass over what is behind (maps, 3D, video, photos); `"solid"` opts out inside a glass `UIProvider`. |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### QrCode

| Prop | Type | Notes |
| --- | --- | --- |
| `value` | `string` | The text to encode: an otpauth:// link, a URL … |
| `level?` | `"L" \| "M" \| "Q" \| "H"` | Error correction: L, M (default), Q or H. |
| `size?` | `number \| string` | Width and height (default: the width of its container). |
| `quiet?` | `number` | Light modules around the code (default 4, the standard quiet zone). |
| `label?` | `string` | Accessible name (default "QR code"). |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |

### ServiceMark

| Prop | Type | Notes |
| --- | --- | --- |
| `name` | `string` | The service's name: the accessible name, and the monogram when there is no icon or logo. |
| `icon?` | `IconName` | A brand logo (`brandGmail` …) or a line icon. |
| `logo?` | `ReactNode` | Your own logo (an `<img>` or `<svg>`) instead of the icon. |
| `monogram?` | `string` | Letters for the monogram (default: the initials of `name`). |
| `size?` | `"sm" \| "md" \| "lg"` | 24, 36 (default) or 48 px. |
| `tint?` | `Tint \| "plain"` |  |
| `status?` | `ServiceState` | A dot in the corner with the state in words for screen readers. |
| `decorative?` | `boolean` | Hidden from screen readers when the name is written next to it. |
| `className?` | `string` | Extra class on the root element. |
| `style?` | `CSSProperties` | Inline style on the root element. |
