mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +00:00
Allow markdown readme above the gallery pages (#11103)
This commit is contained in:
parent
e3d78d6dc5
commit
a67799a670
@ -2,6 +2,7 @@
|
|||||||
const gulp = require("gulp");
|
const gulp = require("gulp");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
const marked = require("marked");
|
||||||
|
|
||||||
const env = require("../env");
|
const env = require("../env");
|
||||||
const paths = require("../paths");
|
const paths = require("../paths");
|
||||||
@ -20,19 +21,46 @@ gulp.task("gather-gallery-demos", async function gatherDemos() {
|
|||||||
path.resolve(paths.gallery_dir, "src/demos")
|
path.resolve(paths.gallery_dir, "src/demos")
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const galleryBuild = path.resolve(paths.gallery_dir, "build");
|
||||||
|
fs.mkdirSync(galleryBuild, { recursive: true });
|
||||||
|
|
||||||
let content = "export const DEMOS = {\n";
|
let content = "export const DEMOS = {\n";
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
|
if (!file.endsWith(".ts")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const demoId = path.basename(file, ".ts");
|
const demoId = path.basename(file, ".ts");
|
||||||
const demoPath = "../src/demos/" + demoId;
|
const descriptionFile = path.resolve(
|
||||||
content += ` "${demoId.substring(5)}": () => import("${demoPath}"),\n`;
|
paths.gallery_dir,
|
||||||
|
"src/demos",
|
||||||
|
`${demoId}.markdown`
|
||||||
|
);
|
||||||
|
const hasDescription = fs.existsSync(descriptionFile);
|
||||||
|
if (hasDescription) {
|
||||||
|
const descriptionContent = fs.readFileSync(descriptionFile, "utf-8");
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.resolve(galleryBuild, `${demoId}-description.ts`),
|
||||||
|
`
|
||||||
|
import {html} from "lit";
|
||||||
|
export default html\`${marked(descriptionContent)}\`
|
||||||
|
`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const demoPath = `../src/demos/${demoId}`;
|
||||||
|
const descriptionPath = `./${demoId}-description`;
|
||||||
|
content += ` "${demoId.substring(5)}": {
|
||||||
|
${
|
||||||
|
hasDescription
|
||||||
|
? `description: () => import("${descriptionPath}").then(m => m.default),`
|
||||||
|
: ""
|
||||||
|
}
|
||||||
|
load: () => import("${demoPath}")
|
||||||
|
},\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
content += "};";
|
content += "};";
|
||||||
|
|
||||||
const galleryBuild = path.resolve(paths.gallery_dir, "build");
|
|
||||||
|
|
||||||
fs.mkdirSync(galleryBuild, { recursive: true });
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.resolve(galleryBuild, "import-demos.ts"),
|
path.resolve(galleryBuild, "import-demos.ts"),
|
||||||
content,
|
content,
|
||||||
|
14
gallery/src/demos/demo-ha-alert.markdown
Normal file
14
gallery/src/demos/demo-ha-alert.markdown
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
The `<ha-alert>` element is used to display a message to the user that requires attention.
|
||||||
|
|
||||||
|
The `header` option should not be used without a description.
|
||||||
|
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<ha-alert type="info">Look, an alert!</ha-alert>
|
||||||
|
```
|
||||||
|
|
||||||
|
This will show:
|
||||||
|
|
||||||
|
<ha-alert type="info">Look, an alert!</ha-alert>
|
@ -3,6 +3,7 @@ import "@material/mwc-drawer";
|
|||||||
import "@material/mwc-top-app-bar-fixed";
|
import "@material/mwc-top-app-bar-fixed";
|
||||||
import { html, css, LitElement, PropertyValues } from "lit";
|
import { html, css, LitElement, PropertyValues } from "lit";
|
||||||
import { customElement, property, query } from "lit/decorators";
|
import { customElement, property, query } from "lit/decorators";
|
||||||
|
import { until } from "lit/directives/until";
|
||||||
import "../../src/components/ha-icon-button";
|
import "../../src/components/ha-icon-button";
|
||||||
import "../../src/managers/notification-manager";
|
import "../../src/managers/notification-manager";
|
||||||
import { haStyle } from "../../src/resources/styles";
|
import { haStyle } from "../../src/resources/styles";
|
||||||
@ -99,7 +100,23 @@ class HaGallery extends LitElement {
|
|||||||
|
|
||||||
<div slot="title">${this._demo}</div>
|
<div slot="title">${this._demo}</div>
|
||||||
</mwc-top-app-bar-fixed>
|
</mwc-top-app-bar-fixed>
|
||||||
<div>${dynamicElement(`demo-${this._demo}`)}</div>
|
<div>
|
||||||
|
${DEMOS[this._demo].description
|
||||||
|
? html`
|
||||||
|
${until(
|
||||||
|
DEMOS[this._demo].description().then(
|
||||||
|
(content) => html`
|
||||||
|
<ha-card .header=${this._demo}>
|
||||||
|
<div class="card-content">${content}</div>
|
||||||
|
</ha-card>
|
||||||
|
`
|
||||||
|
),
|
||||||
|
""
|
||||||
|
)}
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
${dynamicElement(`demo-${this._demo}`)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</mwc-drawer>
|
</mwc-drawer>
|
||||||
<notification-manager
|
<notification-manager
|
||||||
@ -145,7 +162,7 @@ class HaGallery extends LitElement {
|
|||||||
updated(changedProps: PropertyValues) {
|
updated(changedProps: PropertyValues) {
|
||||||
super.updated(changedProps);
|
super.updated(changedProps);
|
||||||
if (changedProps.has("_demo") && this._demo) {
|
if (changedProps.has("_demo") && this._demo) {
|
||||||
DEMOS[this._demo]();
|
DEMOS[this._demo].load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,6 +213,11 @@ class HaGallery extends LitElement {
|
|||||||
background-color: var(--sidebar-selected-icon-color);
|
background-color: var(--sidebar-selected-icon-color);
|
||||||
opacity: 0.12;
|
opacity: 0.12;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ha-card {
|
||||||
|
max-width: 600px;
|
||||||
|
margin: 16px auto;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user