Skip to content

Commit d1bd5df

Browse files
feat: add links to mdn documentation inside tooltips for sections and properties (#4416)
## Description fixes #4383 Tweaked the `__generated__/properties.ts` that is generated at build time to store `mdn_url` in it. And use these url's to show on the tooltips for the properties and sections. ## Steps for reproduction - Open any property, and the tooltip opens - Inside the tooltip, you should be able to click on the external link icon. - The link should take you to a mdn link of the same. ![external-links](https://github.com/user-attachments/assets/9b81d2da-7d5f-4d7f-abdb-e0eaa5902a14) ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) ## Before requesting a review - [x] made a self-review ## Before merging - [x] tested locally and on preview environment (preview dev login: 5de6)
1 parent ad04a72 commit d1bd5df

File tree

7 files changed

+423
-3
lines changed

7 files changed

+423
-3
lines changed

apps/builder/app/builder/features/style-panel/property-label.tsx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
Text,
1818
theme,
1919
Tooltip,
20+
IconLink,
2021
} from "@webstudio-is/design-system";
2122
import { humanizeString } from "~/shared/string-utils";
2223
import {
@@ -34,6 +35,7 @@ import { useComputedStyles } from "./shared/model";
3435
import { StyleSourceBadge } from "./style-source";
3536
import { createBatchUpdate } from "./shared/use-style-data";
3637
import { $virtualInstances } from "~/shared/awareness";
38+
import { styleConfigByName } from "./shared/configs";
3739

3840
const $isAltPressed = atom(false);
3941
if (typeof window !== "undefined") {
@@ -67,12 +69,14 @@ const renderCss = (styles: ComputedStyleDecl[], isComputed: boolean) => {
6769
export const PropertyInfo = ({
6870
title,
6971
code,
72+
link,
7073
description,
7174
styles,
7275
onReset,
7376
}: {
7477
title: string;
7578
code?: string;
79+
link?: string;
7680
description: ReactNode;
7781
styles: ComputedStyleDecl[];
7882
onReset: () => void;
@@ -133,7 +137,21 @@ export const PropertyInfo = ({
133137

134138
return (
135139
<Flex direction="column" gap="2" css={{ maxWidth: theme.spacing[28] }}>
136-
<Text variant="titles">{title}</Text>
140+
<Flex justify="between">
141+
<Text variant="titles" truncate>
142+
{title}
143+
</Text>
144+
{link && (
145+
<IconLink
146+
href={link}
147+
target="_blank"
148+
rel="noreferrer"
149+
color="inherit"
150+
variant="inherit"
151+
size={13}
152+
/>
153+
)}
154+
</Flex>
137155
<Text
138156
variant="monoBold"
139157
color="moreSubtle"
@@ -232,6 +250,8 @@ export const PropertyLabel = ({
232250
}
233251
batch.publish();
234252
};
253+
const styleConfig = styleConfigByName(properties[0]);
254+
235255
return (
236256
<Flex align="center">
237257
<Tooltip
@@ -258,6 +278,7 @@ export const PropertyLabel = ({
258278
resetProperty();
259279
setIsOpen(false);
260280
}}
281+
link={styleConfig?.mdnUrl}
261282
/>
262283
}
263284
>
@@ -290,6 +311,8 @@ export const PropertySectionLabel = ({
290311
}
291312
batch.publish();
292313
};
314+
const styleConfig = styleConfigByName(properties[0]);
315+
293316
return (
294317
<Flex align="center">
295318
<Tooltip
@@ -316,6 +339,7 @@ export const PropertySectionLabel = ({
316339
resetProperty();
317340
setIsOpen(false);
318341
}}
342+
link={styleConfig?.mdnUrl}
319343
/>
320344
}
321345
>
@@ -414,6 +438,8 @@ export const PropertyValueTooltip = ({
414438
}
415439
batch.publish();
416440
};
441+
const styleConfig = styleConfigByName(properties[0]);
442+
417443
return (
418444
<Tooltip
419445
open={isOpen}
@@ -448,6 +474,7 @@ export const PropertyValueTooltip = ({
448474
resetProperty();
449475
setIsOpen(false);
450476
}}
477+
link={styleConfig?.mdnUrl}
451478
/>
452479
}
453480
>

apps/builder/app/builder/features/style-panel/sections/transforms/transforms.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ const advancedProperties = [
6969
] satisfies [StyleProperty, ...StyleProperty[]];
7070

7171
export const properties = [
72+
"transform",
7273
"translate",
7374
"scale",
74-
"transform",
7575
...advancedProperties,
7676
] satisfies [StyleProperty, ...StyleProperty[]];
7777

apps/builder/app/builder/features/style-panel/shared/configs.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import type { StyleProperty } from "@webstudio-is/css-engine";
2-
import { keywordValues } from "@webstudio-is/css-data";
2+
import { keywordValues, properties } from "@webstudio-is/css-data";
33
import { humanizeString } from "~/shared/string-utils";
44
import type * as Controls from "../controls";
55

66
type BaseStyleConfig = {
77
label: string;
88
property: StyleProperty;
9+
mdnUrl?: string;
910
};
1011

1112
export type Control = keyof typeof Controls;
@@ -53,12 +54,14 @@ export const styleConfigByName = (propertyName: StyleProperty): StyleConfig => {
5354

5455
const keywords = keywordValues[property] || [];
5556
const label = humanizeString(property);
57+
const propertyData = properties[property];
5658

5759
const result = {
5860
label,
5961
property,
6062
control: getControl(property),
6163
items: keywords.map((keyword) => ({ label: keyword, name: keyword })),
64+
...("mdnUrl" in propertyData && { mdnUrl: propertyData.mdnUrl }),
6265
};
6366

6467
styleConfigCache.set(propertyName, result);

packages/css-data/bin/mdn-data.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ for (property in filteredProperties) {
330330
unitGroups: Array.from(unitGroups),
331331
inherited: config.inherited,
332332
initial: parseInitialValue(property, config.initial, unitGroups),
333+
...("mdn_url" in config && { mdnUrl: config.mdn_url }),
333334
};
334335
}
335336

0 commit comments

Comments
 (0)