fix(docs): restore related showcases and correct CSS customization examples
This commit is contained in:
@@ -0,0 +1,125 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
// Adapted from HeroUI ce90ea3 related-showcases/showcase-item and registry/navigation,
|
||||||
|
// Apache-2.0. Cards link to the upstream React examples; no local showcase runtime.
|
||||||
|
import { computed } from "vue";
|
||||||
|
|
||||||
|
const props = defineProps<{ component: string }>();
|
||||||
|
const cdn =
|
||||||
|
"https://heroui-assets.nyc3.cdn.digitaloceanspaces.com/docs/showcases";
|
||||||
|
const showcases = [
|
||||||
|
{
|
||||||
|
name: "apple-iphone-disclosure",
|
||||||
|
title: "Apple iPhone 17 Pro Disclosure",
|
||||||
|
components: ["DisclosureGroup", "Disclosure", "Button"],
|
||||||
|
asset: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "apple-iphone-camera-zoom",
|
||||||
|
title: "Apple iPhone 17 Pro Camera Zoom",
|
||||||
|
components: ["Tabs"],
|
||||||
|
asset: 2,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
const items = computed(() =>
|
||||||
|
showcases.filter((item) =>
|
||||||
|
item.components.some(
|
||||||
|
(name) => name.toLowerCase() === props.component.toLowerCase(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div v-if="items.length" class="docs-related-showcases not-prose">
|
||||||
|
<a
|
||||||
|
v-for="item in items"
|
||||||
|
:key="item.name"
|
||||||
|
class="showcase-card"
|
||||||
|
:href="`https://heroui.com/cn/showcase/${item.name}`"
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
:aria-label="`${item.title}(上游 React 案例,新窗口)`"
|
||||||
|
>
|
||||||
|
<div class="showcase-media">
|
||||||
|
<span class="showcase-status">new</span>
|
||||||
|
<video
|
||||||
|
autoplay
|
||||||
|
loop
|
||||||
|
muted
|
||||||
|
playsinline
|
||||||
|
preload="none"
|
||||||
|
:poster="`${cdn}/${item.asset}.jpg`"
|
||||||
|
>
|
||||||
|
<source :src="`${cdn}/${item.asset}.mp4`" type="video/mp4" />
|
||||||
|
</video>
|
||||||
|
</div>
|
||||||
|
<span class="showcase-title">{{ item.title }}</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.docs-related-showcases {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 250px));
|
||||||
|
gap: 16px;
|
||||||
|
padding: 8px;
|
||||||
|
margin: 0 -8px;
|
||||||
|
}
|
||||||
|
.showcase-card {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 180px;
|
||||||
|
max-width: 250px;
|
||||||
|
min-width: 0;
|
||||||
|
color: var(--foreground);
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
.showcase-media {
|
||||||
|
position: relative;
|
||||||
|
flex: 1;
|
||||||
|
min-height: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
border-radius: 12px;
|
||||||
|
box-shadow: var(--surface-shadow);
|
||||||
|
transition: transform 250ms ease-out;
|
||||||
|
}
|
||||||
|
.showcase-card:hover .showcase-media {
|
||||||
|
transform: scale(1.02);
|
||||||
|
}
|
||||||
|
.showcase-card:focus-visible {
|
||||||
|
outline: 2px solid var(--focus);
|
||||||
|
outline-offset: 4px;
|
||||||
|
border-radius: 12px;
|
||||||
|
}
|
||||||
|
.showcase-media video {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
.showcase-status {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 1;
|
||||||
|
top: 6px;
|
||||||
|
right: 8px;
|
||||||
|
padding: 2px 6px;
|
||||||
|
border: 1px solid rgb(255 255 255 / 10%);
|
||||||
|
border-radius: 999px;
|
||||||
|
background: rgb(255 255 255 / 10%);
|
||||||
|
color: rgb(255 255 255 / 80%);
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
.showcase-title {
|
||||||
|
margin-top: 12px;
|
||||||
|
padding: 0 4px;
|
||||||
|
font-size: 14px;
|
||||||
|
color: color-mix(in oklab, var(--foreground) 50%, transparent);
|
||||||
|
}
|
||||||
|
@media (prefers-reduced-motion: reduce) {
|
||||||
|
.showcase-media {
|
||||||
|
transition: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -5,6 +5,7 @@ import DocsComponents from "./DocsComponents.vue";
|
|||||||
import DocsColorSection from "./DocsColorSection.vue";
|
import DocsColorSection from "./DocsColorSection.vue";
|
||||||
import Layout from "./Layout.vue";
|
import Layout from "./Layout.vue";
|
||||||
import Demo from "./Demo.vue";
|
import Demo from "./Demo.vue";
|
||||||
|
import DocsRelatedShowcases from "./DocsRelatedShowcases.vue";
|
||||||
import "@heroui-vue/styles/css";
|
import "@heroui-vue/styles/css";
|
||||||
import "./utilities.css";
|
import "./utilities.css";
|
||||||
import "./style.css";
|
import "./style.css";
|
||||||
@@ -13,6 +14,7 @@ export default {
|
|||||||
Layout,
|
Layout,
|
||||||
enhanceApp({ app }) {
|
enhanceApp({ app }) {
|
||||||
app.component("ComponentPreview", Demo);
|
app.component("ComponentPreview", Demo);
|
||||||
|
app.component("DocsRelatedShowcases", DocsRelatedShowcases);
|
||||||
app.component("DocsCopyButton", Button);
|
app.component("DocsCopyButton", Button);
|
||||||
app.component("DocsComponents", DocsComponents);
|
app.component("DocsComponents", DocsComponents);
|
||||||
app.component("DocsColorSection", DocsColorSection);
|
app.component("DocsColorSection", DocsColorSection);
|
||||||
|
|||||||
@@ -187,3 +187,9 @@ Vue 使用 `@click` 和默认作用域插槽。插槽提供 `isPending`、`isPre
|
|||||||
## 相关组件
|
## 相关组件
|
||||||
|
|
||||||
[Popover 弹出框](./popover) · [Tooltip 工具提示](./tooltip) · [Form 表单](./form)
|
[Popover 弹出框](./popover) · [Tooltip 工具提示](./tooltip) · [Form 表单](./form)
|
||||||
|
|
||||||
|
## 相关案例
|
||||||
|
|
||||||
|
以下卡片链接至上游 React 案例(新窗口)。
|
||||||
|
|
||||||
|
<DocsRelatedShowcases component="Button" />
|
||||||
|
|||||||
@@ -112,3 +112,9 @@ import { Disclosure, DisclosureGroup } from "@heroui-vue/components";
|
|||||||
## 相关组件
|
## 相关组件
|
||||||
|
|
||||||
[Accordion 手风琴](./accordion) · [Disclosure 折叠面板](./disclosure) · [Button 按钮](./button)
|
[Accordion 手风琴](./accordion) · [Disclosure 折叠面板](./disclosure) · [Button 按钮](./button)
|
||||||
|
|
||||||
|
## 相关案例
|
||||||
|
|
||||||
|
以下卡片链接至上游 React 案例(新窗口)。
|
||||||
|
|
||||||
|
<DocsRelatedShowcases component="DisclosureGroup" />
|
||||||
|
|||||||
@@ -171,3 +171,9 @@ Body 提供基线内边距与内层包装。Indicator 默认为基线 Chevron
|
|||||||
## 相关组件
|
## 相关组件
|
||||||
|
|
||||||
[Accordion 手风琴](./accordion) · [DisclosureGroup 折叠面板组](./disclosure-group) · [Button 按钮](./button)
|
[Accordion 手风琴](./accordion) · [DisclosureGroup 折叠面板组](./disclosure-group) · [Button 按钮](./button)
|
||||||
|
|
||||||
|
## 相关案例
|
||||||
|
|
||||||
|
以下卡片链接至上游 React 案例(新窗口)。
|
||||||
|
|
||||||
|
<DocsRelatedShowcases component="Disclosure" />
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ InputOTP 组件支持两种视觉变体:
|
|||||||
}
|
}
|
||||||
|
|
||||||
.hv-input-otp__separator {
|
.hv-input-otp__separator {
|
||||||
@apply h-1 w-2 rounded-full bg-border-strong;
|
@apply h-1 w-2 rounded-full bg-separator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -132,11 +132,12 @@ Vue 使用 `asChild` 合并根容器属性,默认插槽必须只有一个自
|
|||||||
```css
|
```css
|
||||||
@layer components {
|
@layer components {
|
||||||
.hv-switch {
|
.hv-switch {
|
||||||
@apply inline-flex items-center gap-3;
|
--switch-control-bg: var(--default);
|
||||||
|
--switch-control-bg-checked: var(--accent);
|
||||||
}
|
}
|
||||||
|
|
||||||
.hv-switch__control {
|
.hv-switch__control {
|
||||||
@apply h-5 w-8 bg-gray-400 data-[selected=true]:bg-blue-500;
|
@apply h-5 w-8;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hv-switch__thumb {
|
.hv-switch__thumb {
|
||||||
@@ -144,7 +145,7 @@ Vue 使用 `asChild` 合并根容器属性,默认插槽必须只有一个自
|
|||||||
}
|
}
|
||||||
|
|
||||||
.hv-switch__content {
|
.hv-switch__content {
|
||||||
@apply flex flex-col gap-1;
|
@apply inline-flex items-center gap-3;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hv-switch__icon {
|
.hv-switch__icon {
|
||||||
@@ -164,7 +165,7 @@ HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态
|
|||||||
Switch 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/switch.css)):
|
Switch 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/switch.css)):
|
||||||
|
|
||||||
- `.hv-switch` - Switch 根容器(字段)
|
- `.hv-switch` - Switch 根容器(字段)
|
||||||
- `.hv-switch__content` - 包裹控件与标签文本的可点击 label
|
- `.hv-switch__content` - 包裹控件与标签文本的 `button[role="switch"]`
|
||||||
- `.hv-switch__control` - Switch 轨道
|
- `.hv-switch__control` - Switch 轨道
|
||||||
- `.hv-switch__thumb` - 可移动的滑块
|
- `.hv-switch__thumb` - 可移动的滑块
|
||||||
- `.hv-switch__icon` - 滑块内可选图标
|
- `.hv-switch__icon` - 滑块内可选图标
|
||||||
|
|||||||
@@ -246,3 +246,9 @@ RAC 的集合 render-prop API 不作逐字复制,列表用 v-for,DOM render
|
|||||||
## 相关组件
|
## 相关组件
|
||||||
|
|
||||||
[Breadcrumbs 面包屑](./breadcrumbs)
|
[Breadcrumbs 面包屑](./breadcrumbs)
|
||||||
|
|
||||||
|
## 相关案例
|
||||||
|
|
||||||
|
以下卡片链接至上游 React 案例(新窗口)。
|
||||||
|
|
||||||
|
<DocsRelatedShowcases component="Tabs" />
|
||||||
|
|||||||
@@ -408,3 +408,26 @@ it("closes the mobile TOC before navigating and focuses the requested heading",
|
|||||||
expect(document.activeElement).toBe(document.getElementById("section"));
|
expect(document.activeElement).toBe(document.getElementById("section"));
|
||||||
expect(document.querySelector(".mobile-toc-content")).toBeNull();
|
expect(document.querySelector(".mobile-toc-content")).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("shows only matching upstream showcase cards and updates without empty placeholders", async () => {
|
||||||
|
const { default: RelatedShowcases } =
|
||||||
|
await import("../apps/docs/.vitepress/theme/DocsRelatedShowcases.vue");
|
||||||
|
const w = mount(RelatedShowcases, { props: { component: "Button" } });
|
||||||
|
wrappers.push(w);
|
||||||
|
const link = w.get("a");
|
||||||
|
expect(link.attributes("href")).toBe(
|
||||||
|
"https://heroui.com/cn/showcase/apple-iphone-disclosure",
|
||||||
|
);
|
||||||
|
expect(link.attributes("aria-label")).toContain("上游 React 案例");
|
||||||
|
expect(link.attributes("rel")).toContain("noopener");
|
||||||
|
expect(w.get("video").attributes("poster")).toMatch(/\/1\.jpg$/);
|
||||||
|
await w.setProps({ component: "tabs" });
|
||||||
|
expect(w.findAll("a")).toHaveLength(1);
|
||||||
|
expect(w.get("a").attributes("href")).toBe(
|
||||||
|
"https://heroui.com/cn/showcase/apple-iphone-camera-zoom",
|
||||||
|
);
|
||||||
|
expect(w.get("source").attributes("src")).toMatch(/\/2\.mp4$/);
|
||||||
|
await w.setProps({ component: "Input" });
|
||||||
|
expect(w.find(".docs-related-showcases").exists()).toBe(false);
|
||||||
|
expect(w.find("a").exists()).toBe(false);
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user