Skip to content

figma-inspector: added em dash to the sanitizers #8320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tools/figma-inspector/backend/utils/export-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function formatStructName(name: string): string {
.replace(/,\s*/g, "-") // Replace commas (and following spaces) with hyphens
.replace(/\+/g, "-") // Replace + with hyphens (add this line)
.replace(/\:/g, "-") // Replace : with ""
.replace(/—/g, "-") // Replace em dash hyphens
.replace(/([a-z])([A-Z])/g, "$1-$2") // Add hyphens between camelCase
.replace(/\s+/g, "-") // Convert spaces to hyphens
.replace(/--+/g, "-") // Normalize multiple consecutive hyphens to single
Expand All @@ -65,6 +66,7 @@ export function sanitizePropertyName(name: string): string {
.replace(/&/g, "and") // Replace &
.replace(/\(/g, "_") // Replace ( with _
.replace(/\)/g, "_") // Replace ) with _
.replace(/—/g, "_") // Replace em dash with underscore
.replace(/[^a-zA-Z0-9_]/g, "_") // Replace other invalid chars (including -, +, :, etc.) with _
.replace(/__+/g, "_"); // Collapse multiple underscores

Expand Down
59 changes: 41 additions & 18 deletions tools/figma-inspector/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getColorTheme, subscribeColorTheme } from "./utils/bolt-utils";
import CodeSnippet from "./components/snippet/CodeSnippet";
import { ExportType, useInspectorStore } from "./utils/store";
import DialogFrame from "./components/DialogFrame.js";
import { Button, Checkbox, DropdownMenu, Text } from "figma-kit";
import { Text, Button, Checkbox, DropdownMenu } from "figma-kit";
import "./main.css";

export const App = () => {
Expand Down Expand Up @@ -102,40 +102,63 @@ export const App = () => {
/>
</DialogFrame.Content>
<DialogFrame.Footer>
<div className="border border-secondary border-[var(--figma-color-bg-brand)]">
<Text className="text-[var(--figma-color-bg-brand)]">
Welcome to Figma
</Text>
</div>
<Checkbox.Root>
<Checkbox.Input
checked={useVariables}
onChange={(e) => setUseVariables(e.target.checked)}
/>
<Checkbox.Label>Use Figma Variables</Checkbox.Label>
</Checkbox.Root>

Comment on lines +105 to +112
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unrelated. Did you mean to include the changes in this file in the commit, or did you intend to make a separate change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I See, this PR is on top of #8321 . I suggest to either get that in first or rebase this onto master without the changes in #8321 .

<DropdownMenu.Root>
<DropdownMenu.Trigger asChild>
<Button>Export</Button>
<Button
variant={
exportsAreCurrent ? "secondary" : "primary"
}
style={{
visibility: useVariables
? "visible"
: "hidden",
}}
>
Export
</Button>
</DropdownMenu.Trigger>
<DropdownMenu.Content style={{}}>
<DropdownMenu.Content>
<DropdownMenu.Item
onClick={() =>
exportFiles(ExportType.SeparateFiles)
}
>
Separate Files…
Separate Files Per Collection
</DropdownMenu.Item>
<DropdownMenu.Item
onClick={() =>
exportFiles(ExportType.SingleFile)
}
>
Single File…
Singl Design-Tokens File…
</DropdownMenu.Item>
</DropdownMenu.Content>
</DropdownMenu.Root>

<Checkbox.Root>
<Checkbox.Input
checked={useVariables}
onChange={(e) => setUseVariables(e.target.checked)}
/>
<Checkbox.Label>Use Figma Variables</Checkbox.Label>
</Checkbox.Root>
<Text
style={{
color: exportsAreCurrent
? "var(--figma-color-text-disabled)"
: "var(--figma-color-text-primary",
}}
>
{useVariables ? (
exportsAreCurrent ? (
<em>Exports are current</em>
) : (
"Either variables have changed or no export found"
)
) : (
""
)}
</Text>
</DialogFrame.Footer>
</DialogFrame>
</>
Expand Down