Search

Change Event

Interactions

Keep timeline state synchronized with any changes.

View live example →

Double-click entities on the timeline to focus them.

By listening to the onTimelineChange event, an app can track updates to the timeline's state caused by the user's actions and incorporate these into its own state.

Here, the app is controlling which entities are focused by using the focus prop. If the user double-clicks to focus an entity, an onTimelineChange event is fired to notify the app, which then replaces its list of focused entities with the new list and passes this to the focus prop.

The app can also make its own changes to the focus state - try pressing the "Clear Focus" button.

See Also

import React, { useState } from "react";
import { createRoot } from "react-dom/client";
import Timeline from "kronograph/react/Timeline";
import data from "./data";

const { events, entities } = data;

export const Demo = () => {
  const [focused, setFocused] = useState([]);
  return (
    <div className="story">
      <Timeline
        className="story__timeline"
        entities={entities}
        events={events}
        focus={focused}
        onTimelineChange={(change) => {
          if (change.focus) {
            setFocused(change.focus);
          }
        }}
      />
      <div
        id="timeline-controls"
        className="story__controls story__controls--row"
        style={{ justifyContent: "center" }}
      >
        <div className="stack" style={{ alignItems: "center" }}>
          <span>
            {focused.length
              ? `The focused entity is ${entities[focused[0]].label}`
              : "No entity focused"}
          </span>
          <button className="button button--neutral" onClick={() => setFocused([])}>
            Clear Focus
          </button>
        </div>
      </div>
    </div>
  );
};

const root = createRoot(document.getElementById("my-timeline"));
root.render(<Demo />);
const data = {
  entities: {
    "smith-johnathan-151": {
      label: "John Smith",
    },
    "west-josephine-126": {
      label: "Josephine West",
    },
    "roberts-nathaniel-023": {
      label: "Nathan Roberts",
    },
    "baxter-eleanor-004": {
      label: "Ella Baxter",
    },
  },
  events: {
    "email 1": {
      entityIds: ["smith-johnathan-151", "roberts-nathaniel-023"],
      time: new Date(2025, 7, 14, 8, 49),
      data: {
        from: "[email protected]",
        to: "[email protected]",
      },
    },
    "email 2": {
      entityIds: ["smith-johnathan-151", "baxter-eleanor-004"],
      time: new Date(2025, 7, 14, 8, 56),
      data: {
        from: "[email protected]",
        to: "[email protected]",
      },
    },
    "email 3": {
      entityIds: ["smith-johnathan-151", "west-josephine-126"],
      time: new Date(2025, 7, 14, 9, 2),
      data: {
        from: "[email protected]",
        to: "[email protected]",
      },
    },
    "email 4": {
      entityIds: ["smith-johnathan-151", "west-josephine-126"],
      time: new Date(2025, 7, 14, 9, 27),
      data: {
        from: "[email protected]",
        to: "[email protected]",
      },
    },
    "email 5": {
      entityIds: ["baxter-eleanor-004", "roberts-nathaniel-023"],
      time: new Date(2025, 7, 14, 10, 20),
      data: {
        from: "[email protected]",
        to: "[email protected]",
      },
    },
    "email 6": {
      entityIds: ["roberts-nathaniel-023", "smith-johnathan-151"],
      time: new Date(2025, 7, 14, 10, 30),
      data: {
        from: "[email protected]",
        to: "[email protected]",
      },
    },
    "email 7": {
      entityIds: ["smith-johnathan-151", "west-josephine-126"],
      time: new Date(2025, 7, 14, 10, 34),
      data: {
        from: "[email protected]",
        to: "[email protected]",
      },
    },
    "email 8": {
      entityIds: ["west-josephine-126", "smith-johnathan-151"],
      time: new Date(2025, 7, 14, 10, 40),
      data: {
        from: "[email protected]",
        to: "[email protected]",
      },
    },
    "email 9": {
      entityIds: ["smith-johnathan-151", "west-josephine-126"],
      time: new Date(2025, 7, 14, 10, 51),
      data: {
        from: "[email protected]",
        to: "[email protected]",
      },
    },
    "email 10": {
      entityIds: ["west-josephine-126", "smith-johnathan-151"],
      time: new Date(2025, 7, 14, 12, 5),
      data: {
        from: "[email protected]",
        to: "[email protected]",
      },
    },
    "email 11": {
      entityIds: ["smith-johnathan-151", "west-josephine-126"],
      time: new Date(2025, 7, 14, 14, 37),
      data: {
        from: "[email protected]",
        to: "[email protected]",
      },
    },
    "email 12": {
      entityIds: ["baxter-eleanor-004", "west-josephine-126"],
      time: new Date(2025, 7, 14, 16, 7),
      data: {
        from: "[email protected]",
        to: "[email protected]",
      },
    },
    "email 13": {
      entityIds: ["west-josephine-126", "roberts-nathaniel-023"],
      time: new Date(2025, 7, 14, 17, 42),
      data: {
        from: "[email protected]",
        to: "[email protected]",
      },
    },
  },
};

export default data;
<!doctype html>
<html>
  <head>
    <link rel="stylesheet" href="@ci/theme/kg/css/examples.css" />
  </head>
  <body>
    <div id="my-timeline" style="height: 100vh"></div>
    <script type="module" src="./code.jsx"></script>
  </body>
</html>

Terms of use

These terms do not alter or supersede any existing agreements between you (or your employer) and us.

By accessing or using any Content you agree to be bound by these Terms of Use. Please review these terms carefully before using the website.

The contents of this website, including but not limited to any text, code samples, API references, schemas, interactive tools, and other materials (collectively, the 'Content'), are made available for informational and internal evaluation purposes only. All intellectual property rights in the Content are reserved. No licence is granted to use the Content for any commercial purpose, or to copy, distribute, modify, reverse-engineer, or incorporate any part of the Content into any product or service, without our prior written consent.

This Content is provided “as is” and “as available,” without any representations, warranties, or guarantees of any kind, whether express or implied, including but not limited to implied warranties of merchantability, fitness for a particular purpose, non-infringement, or accuracy. To the fullest extent permitted by applicable law, we expressly exclude and disclaim all implied warranties, conditions, and other terms that might otherwise be implied.

We disclaim all liability for any loss or damage, whether direct, indirect, incidental, consequential, or otherwise, arising from any reliance placed on the Content or from your use of it, to the fullest extent permitted by applicable law. By continuing to access or use the Content, you acknowledge and agree to these terms.