🎥 Make videos programmatically with React
Elements: Improve search result hierarchy (#10492)
Igor Samokhovetse727c89b9a91
diff --git a/packages/docs/elements-sidebars.ts b/packages/docs/elements-sidebars.tsindex 8b7ceaa4ec..c44ba04bd6 100644--- a/packages/docs/elements-sidebars.ts+++ b/packages/docs/elements-sidebars.ts@@ -19,24 +19,36 @@ const compareStrings = (a: string, b: string) => {const sidebars: SidebarsConfig = {elementsSidebar: [- 'index',- 'contributing',{- type: 'html',- value:- '<hr style="margin-top: 4px; margin-bottom: 4px; border-bottom: none"/>',- defaultStyle: true,- },- ...elementCategories.map(({category, label}) => ({- type: 'category' as const,- label,- link: {type: 'doc' as const, id: `${category}/index`},+ type: 'category',+ label: 'Elements',+ className: 'elements-sidebar-root',+ link: {type: 'doc', id: 'index'},+ collapsible: true,collapsed: false,- items: Object.entries(elementRegistry)- .filter(([, metadata]) => metadata.category === category)- .sort(([, a], [, b]) => compareStrings(a.displayName, b.displayName))- .map(([slug]) => `${slug}/index`),- })),+ items: [+ 'contributing',+ {+ type: 'html',+ value:+ '<hr style="margin-top: 4px; margin-bottom: 4px; border-bottom: none"/>',+ defaultStyle: true,+ },+ ...elementCategories.map(({category, label}) => ({+ type: 'category' as const,+ label,+ link: {type: 'doc' as const, id: `${category}/index`},+ collapsible: true,+ collapsed: false,+ items: Object.entries(elementRegistry)+ .filter(([, metadata]) => metadata.category === category)+ .sort(([, a], [, b]) =>+ compareStrings(a.displayName, b.displayName),+ )+ .map(([slug]) => `${slug}/index`),+ })),+ ],+ },],};diff --git a/packages/docs/src/components/Elements/ElementLibrary.module.css b/packages/docs/src/components/Elements/ElementLibrary.module.cssindex 43b14572c3..1ab03485e2 100644--- a/packages/docs/src/components/Elements/ElementLibrary.module.css+++ b/packages/docs/src/components/Elements/ElementLibrary.module.css@@ -73,6 +73,7 @@}.title {+ display: block;margin: 0;font-size: 1.125rem;font-weight: 500;diff --git a/packages/docs/src/components/Elements/ElementLibrary.tsx b/packages/docs/src/components/Elements/ElementLibrary.tsxindex 253422d478..12aacf0e5f 100644--- a/packages/docs/src/components/Elements/ElementLibrary.tsx+++ b/packages/docs/src/components/Elements/ElementLibrary.tsx@@ -37,17 +37,15 @@ const usePrefersReducedMotion = () => {const ElementCard: React.FC<{readonly definition: ElementDefinition;- readonly headingLevel: 2 | 3;readonly prefersReducedMotion: boolean;readonly sourceCode: string;-}> = ({definition, headingLevel, prefersReducedMotion, sourceCode}) => {+}> = ({definition, prefersReducedMotion, sourceCode}) => {const [isFocused, setIsFocused] = useState(false);const [isPointerOver, setIsPointerOver] = useState(false);const [playbackFailed, setPlaybackFailed] = useState(false);const videoRef = useRef<HTMLVideoElement>(null);const shouldPlay =!prefersReducedMotion && !playbackFailed && (isFocused || isPointerOver);- const Heading = headingLevel === 2 ? 'h2' : 'h3';const elementPayload = useMemo(() => createElementPayloadFromDefinition({definition, sourceCode}),[definition, sourceCode],@@ -135,7 +133,7 @@ const ElementCard: React.FC<{) : null}</div><div className={styles.content}>- <Heading className={styles.title}>{definition.displayName}</Heading>+ <span className={styles.title}>{definition.displayName}</span><p className={styles.description}>{definition.description}</p></div></a>@@ -145,10 +143,9 @@ const ElementCard: React.FC<{const ElementGrid: React.FC<{readonly definitions: readonly ElementDefinition[];- readonly headingLevel: 2 | 3;readonly prefersReducedMotion: boolean;readonly sourceCodeBySlug: Readonly<Record<string, string>>;-}> = ({definitions, headingLevel, prefersReducedMotion, sourceCodeBySlug}) => {+}> = ({definitions, prefersReducedMotion, sourceCodeBySlug}) => {return (<ul className={styles.grid} role="list">{definitions.map((definition) => {@@ -163,7 +160,6 @@ const ElementGrid: React.FC<{<ElementCardkey={definition.slug}definition={definition}- headingLevel={headingLevel}prefersReducedMotion={prefersReducedMotion}sourceCode={sourceCode}/>@@ -192,7 +188,6 @@ export const ElementLibrary: React.FC<{><ElementGriddefinitions={section.definitions}- headingLevel={2}prefersReducedMotion={prefersReducedMotion}sourceCodeBySlug={sourceCodeBySlug}/>@@ -213,7 +208,6 @@ export const ElementLibrary: React.FC<{</h2><ElementGriddefinitions={section.definitions}- headingLevel={3}prefersReducedMotion={prefersReducedMotion}sourceCodeBySlug={sourceCodeBySlug}/>diff --git a/packages/docs/src/css/custom.css b/packages/docs/src/css/custom.cssindex 11084f3193..2ed4d4086b 100644--- a/packages/docs/src/css/custom.css+++ b/packages/docs/src/css/custom.css@@ -77,6 +77,24 @@ h6 {margin-bottom: 0.75rem;}+.elements-sidebar-root > .menu__list {+ padding-left: 0;+}++.elements-sidebar-root > .menu__list-item-collapsible > .menu__caret {+ display: none;+}++.elements-sidebar-root > .menu__list-item-collapsible--active > .menu__link {+ pointer-events: none;+}++.elements-sidebar-root+ > .menu__list-item-collapsible:not(.menu__list-item-collapsible--active)+ > .menu__link--active {+ color: var(--ifm-menu-color);+}+:root {--ifm-color-primary: #0b84f3;--ifm-color-primary-dark: #0a77db;diff --git a/packages/docs/src/test/elements.test.ts b/packages/docs/src/test/elements.test.tsindex cb2be07032..6978675e59 100644--- a/packages/docs/src/test/elements.test.ts+++ b/packages/docs/src/test/elements.test.ts@@ -316,8 +316,10 @@ describe('Element library', () => {for (const definition of elementDefinitionList) {expect(- overviewMarkup.split(`>${definition.displayName}</h3>`),+ overviewMarkup.split(`>${definition.displayName}</span>`),).toHaveLength(2);+ expect(overviewMarkup).not.toContain(`>${definition.displayName}</h2>`);+ expect(overviewMarkup).not.toContain(`>${definition.displayName}</h3>`);expect(overviewMarkup).toContain(definition.description);expect(overviewMarkup).toContain(definition.preview.posterUrl);expect(overviewMarkup).toContain(getElementDocumentationUrl(definition));@@ -449,8 +451,29 @@ describe('Elements sidebar', () => {throw new Error('Elements sidebar must be an array');}- expect(sidebar.slice(0, 3)).toEqual([- 'index',+ expect(sidebar).toHaveLength(1);+ const elementsCategory = sidebar[0];+ if (+ typeof elementsCategory !== 'object' ||+ elementsCategory === null ||+ elementsCategory.type !== 'category'+ ) {+ throw new Error('Elements sidebar must have an Elements root category');+ }++ expect(elementsCategory).toMatchObject({+ type: 'category',+ label: 'Elements',+ className: 'elements-sidebar-root',+ link: {type: 'doc', id: 'index'},+ collapsible: true,+ collapsed: false,+ });+ if (!Array.isArray(elementsCategory.items)) {+ throw new Error('Elements root category must contain sidebar items');+ }++ expect(elementsCategory.items.slice(0, 2)).toEqual(['contributing',{type: 'html',@@ -460,7 +483,7 @@ describe('Elements sidebar', () => {},]);- const categories = sidebar.slice(3);+ const categories = elementsCategory.items.slice(2);const expectedCategories = [{category: 'backgrounds',@@ -544,6 +567,7 @@ describe('Elements sidebar', () => {type: 'category',label,link: {type: 'doc', id: `${category}/index`},+ collapsible: true,collapsed: false,items,})),