Skip to content

Commit db4a307

Browse files
committed
Update Accordion component to add optional anchorID and add to MS Teams channel data accordion
1 parent 06825a1 commit db4a307

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

components/ui/Accordion.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Box, Stack } from "@telegraph/layout";
22
import { MenuItem } from "@telegraph/menu";
33
import { Icon } from "@telegraph/icon";
44
import { AnimatePresence, motion } from "framer-motion";
5-
import { useState, useMemo } from "react";
5+
import { useState, useMemo, useLayoutEffect } from "react";
66
import { Text, Code } from "@telegraph/typography";
77
import { ChevronRight } from "lucide-react";
88

@@ -15,11 +15,24 @@ const AccordionGroup = ({ children }) => (
1515
</div>
1616
);
1717

18+
function getHashFragment(): string {
19+
if (typeof window === "undefined") return "";
20+
const { hash } = window.location;
21+
if (!hash || hash === "#") return "";
22+
try {
23+
return decodeURIComponent(hash.slice(1));
24+
} catch {
25+
return hash.slice(1);
26+
}
27+
}
28+
1829
type AccordionProps = {
1930
children: React.ReactNode;
2031
title: string;
2132
description?: string;
2233
defaultOpen?: boolean;
34+
/** When set, this value is used as the element `id` and the accordion opens if the URL hash matches (for deep links). */
35+
anchorId?: string;
2336
};
2437

2538
// Helper function to parse title and split into text and code parts
@@ -68,12 +81,25 @@ const Accordion = ({
6881
title,
6982
description,
7083
defaultOpen = false,
84+
anchorId,
7185
}: AccordionProps) => {
7286
const [open, setOpen] = useState<boolean>(defaultOpen);
7387
const titleParts = useMemo(() => parseTitleWithCode(title), [title]);
7488

89+
useLayoutEffect(() => {
90+
if (!anchorId) return;
91+
const syncFromHash = () => {
92+
if (getHashFragment() === anchorId) {
93+
setOpen(true);
94+
}
95+
};
96+
syncFromHash();
97+
window.addEventListener("hashchange", syncFromHash);
98+
return () => window.removeEventListener("hashchange", syncFromHash);
99+
}, [anchorId]);
100+
75101
return (
76-
<Box role="listitem">
102+
<Box role="listitem" id={anchorId}>
77103
<MenuItem
78104
as="button"
79105
onClick={() => setOpen(!open)}

content/integrations/chat/microsoft-teams/overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ To use TeamsKit, you'll need to configure the API permissions and OAuth redirect
163163

164164
## How to set channel data for a Microsoft Teams integration in Knock
165165

166-
In Knock, the [`ChannelData`](/managing-recipients/setting-channel-data) concept provides you a way of storing recipient-specific connection data for a given integration. If you reference the [channel data requirements for Microsoft Teams](/managing-recipients/setting-channel-data#chat-app-channels), you'll see that there are two different schemas for an `MsTeamsConnection` stored on a [`User`](/concepts/users) or an [`Object`](/concepts/objects) in Knock.
166+
In Knock, the [`ChannelData`](/managing-recipients/setting-channel-data) concept provides you a way of storing recipient-specific connection data for a given integration. If you reference the [channel data requirements for Microsoft Teams](/managing-recipients/setting-channel-data#microsoft-teams-channel-data), you'll see that there are two different schemas for an `MsTeamsConnection` stored on a [`User`](/concepts/users) or an [`Object`](/concepts/objects) in Knock.
167167

168168
Here's an example of setting channel data on an `Object` in Knock.
169169

content/managing-recipients/setting-channel-data.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ The `PushDevice` object is used to optionally set device-level metadata for a pu
241241
| incoming_webhook.url | `string` | The Discord incoming webhook URL (to be used instead of the properties above) |
242242

243243
</Accordion>
244-
<Accordion title ="Microsoft Teams">
244+
<Accordion title ="Microsoft Teams" anchorId="microsoft-teams-channel-data">
245245
| Property | Type | Description |
246246
| ----------- | --------------------- | ---------------------------------- |
247247
| connections | `MsTeamsConnection[]` | One or more connections to MsTeams |

0 commit comments

Comments
 (0)