mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
docs(icons): correctly render icon imports in examples (#1273)
Fixes #1272
This commit is contained in:
parent
3950496b7e
commit
3f466bc9bc
2 changed files with 13 additions and 6 deletions
|
@ -2,9 +2,6 @@
|
|||
import { InlineNotification, Button } from "carbon-components-svelte";
|
||||
import Add from "carbon-icons-svelte/lib/Add.svelte";
|
||||
import TrashCan from "carbon-icons-svelte/lib/TrashCan.svelte";
|
||||
import TextBold from "carbon-icons-svelte/lib/TextBold.svelte";
|
||||
import TextItalic from "carbon-icons-svelte/lib/TextItalic.svelte";
|
||||
import TextUnderline from "carbon-icons-svelte/lib/TextUnderline.svelte";
|
||||
import Login from "carbon-icons-svelte/lib/Login.svelte";
|
||||
import Preview from "../../components/Preview.svelte";
|
||||
|
||||
|
|
|
@ -5,16 +5,25 @@ const slug = require("remark-slug");
|
|||
const visit = require("unist-util-visit");
|
||||
const { format } = require("prettier");
|
||||
const pkg = require("../package.json");
|
||||
const component_api = require("./src/COMPONENT_API.json");
|
||||
const fs = require("fs");
|
||||
const Prism = require("prismjs");
|
||||
require("prism-svelte");
|
||||
|
||||
const component_api_by_name = component_api.components.reduce((a, c) => {
|
||||
return {
|
||||
...a,
|
||||
[c.moduleName]: true,
|
||||
};
|
||||
}, {});
|
||||
|
||||
function createImports(source) {
|
||||
const inlineComponents = new Set();
|
||||
const icons = new Set();
|
||||
|
||||
// TODO: [refactor] better determine if component is a Carbon icon
|
||||
const isIcon = (text) => text.match(/(16|20|24|32)/);
|
||||
// heuristic to guess if the inline component or expression name is a Carbon icon
|
||||
const isIcon = (text) =>
|
||||
/[A-Z][a-z]*/.test(text) && !(text in component_api_by_name);
|
||||
|
||||
walk(parse(source), {
|
||||
enter(node) {
|
||||
|
@ -48,7 +57,8 @@ function createImports(source) {
|
|||
icons.size > 0
|
||||
? icon_imports
|
||||
.map(
|
||||
(icon) => `import ${icon} from "carbon-icons-svelte/lib/${icon}";`
|
||||
(icon) =>
|
||||
`import ${icon} from "carbon-icons-svelte/lib/${icon}.svelte";`
|
||||
)
|
||||
.join("\n")
|
||||
: ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue