import { BREAKPOINT, tokens } from '@preply/ds-core'; import { getTokenVar } from '@preply/ds-web-core'; import React, { FC, ReactNode, useEffect, useState } from 'react'; /** * Inline previews and demos for the "Conventions/Responsive and shorthand * values" page. Components carry only the visuals; the token/breakpoint * data lives as static markdown in the MDX, so the page stays readable in * the generated LLM docs. */ function useActiveBreakpoint(): string | null { const [active, setActive] = useState(null); useEffect(() => { const update = () => { const width = window.innerWidth; let name = '_'; for (const [key, min] of Object.entries(BREAKPOINT).sort((a, b) => a[1] - b[1])) { if (width >= min) name = key; } setActive(name); }; update(); window.addEventListener('resize', update); return () => window.removeEventListener('resize', update); }, []); return active; } /** * A framed area for live responsive examples. Shows which breakpoint is * currently active, updating as the viewport is resized. */ export const ResponsiveDemo: FC<{ children: ReactNode }> = ({ children }) => { const active = useActiveBreakpoint(); return (
{children} {active !== null && ( active breakpoint: {active} )}
); }; /** A content box wrapped in a colored padding area set from shorthand values. */ export const PaddingDemo: FC<{ values: string | string[] }> = ({ values }) => { const padding = (Array.isArray(values) ? values : [values]).map(v => `${v}px`).join(' '); return ( ); };