Skip to content

Commit b064b9a

Browse files
committed
add changeset
1 parent 55eebe5 commit b064b9a

5 files changed

Lines changed: 48 additions & 15 deletions

File tree

.changeset/legal-pigs-tan.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
'@braid-design-system/docs-ui': minor
3+
---
4+
5+
**TitleLink:** Added new component for rendering linkable headings with an optional copy-to-clipboard interaction. Should be wrapped in your required typographic component.
6+
7+
8+
**EXAMPLE:**
9+
```jsx
10+
<Heading level="2">
11+
<TitleLink>Getting started</TitleLink>
12+
</Heading>
13+
```
14+
15+
With copy-to-clipboard:
16+
```jsx
17+
<CategoryHeading component="h3">
18+
<TitleLink copyable>Appearance</TitleLink>
19+
</CategoryHeading>
20+
```
21+
22+
---
23+
24+
**CategoryHeading:** Added new component for rendering category-style navigation headings.
25+
26+
**EXAMPLE USAGE:**
27+
```jsx
28+
<CategoryHeading component="h2">Layout</CategoryHeading>
29+
```

packages/docs-ui/src/components/CategoryHeading/CategoryHeading.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Box, Text } from 'braid-design-system';
2-
import type { ComponentProps } from 'react';
2+
import type { ComponentProps, ReactNode } from 'react';
33

44
type CategoryHeadingProps = {
5-
children: React.ReactNode;
5+
children: ReactNode;
66
component?: ComponentProps<typeof Text>['component'];
77
};
88

packages/docs-ui/src/components/TitleLink/TitleLink.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,18 @@ export const TitleLink = ({ copyable = false, ...restProps }: TitleLink) => {
7979
onCopyClick(url);
8080
};
8181

82+
if (!copyable) {
83+
return <TitleLinkAnchor slug={slug}>{restProps.children}</TitleLinkAnchor>;
84+
}
85+
8286
return (
8387
<TooltipRenderer placement="right" tooltip={<Text>Copy to clipboard</Text>}>
8488
{({ triggerProps }) => (
8589
<TitleLinkAnchor
8690
slug={slug}
87-
onClick={copyable ? handleClick : undefined}
88-
triggerProps={copyable ? triggerProps : undefined}
89-
copying={copyable ? copying : undefined}
91+
onClick={handleClick}
92+
triggerProps={triggerProps}
93+
copying={copying}
9094
>
9195
{restProps.children}
9296
</TitleLinkAnchor>

packages/docs-ui/src/utils/useCopy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ export const useCopy = () => {
55

66
useEffect(() => {
77
if (copying) {
8-
setTimeout(() => {
8+
const timer = setTimeout(() => {
99
setCopying(false);
1010
}, 2000);
11+
return () => clearTimeout(timer);
1112
}
1213
}, [copying]);
1314

1415
const onCopyClick = async (content: string) => {
1516
if (!copying) {
1617
setCopying(true);
17-
const clipboardItem = new ClipboardItem({ 'text/plain': content });
18-
await navigator.clipboard.write([clipboardItem]);
18+
await navigator.clipboard.writeText(content);
1919
}
2020
};
2121

site/src/App/DocNavigation/DocDetails.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,13 @@ export const DocDetails = () => {
209209
.filter(([, docSectionChildren]) =>
210210
docSectionChildren.some(hasContent),
211211
)
212-
.map(([sectionKey, docSectionChildren]) => (
212+
.map(([sectionKey, docSectionChildren]) => {
213+
const heading = getSectionHeading(sectionKey);
214+
return (
213215
<Stack key={sectionKey} space="medium">
214216
<CategoryHeading component="h2">
215-
<TitleLink
216-
copyable
217-
label={getSectionHeading(sectionKey)}
218-
>
219-
{getSectionHeading(sectionKey)}
217+
<TitleLink copyable label={heading}>
218+
{heading}
220219
</TitleLink>
221220
</CategoryHeading>
222221

@@ -257,7 +256,8 @@ export const DocDetails = () => {
257256
) : null}
258257
</Stack>
259258
</Stack>
260-
))}
259+
);
260+
})}
261261

262262
{(docs.additional || []).map((example, index) => (
263263
<DocSection

0 commit comments

Comments
 (0)