From 4c61e79d0d1cc273da7e249ea250df3a4e712e00 Mon Sep 17 00:00:00 2001 From: Maofeng Date: Mon, 21 Sep 2026 17:27:45 +0800 Subject: [PATCH] docs(ui): expand bilingual component guides --- packages/ui/docs/en-US/advanced/hooks.mdx | 85 +++++++++++-- .../ui/docs/en-US/advanced/localization.mdx | 76 +++++++++--- .../en-US/advanced/workspace-adaptations.mdx | 67 +++++++++++ .../docs/en-US/examples/anchored-popover.mdx | 66 ++++++++++ .../ui/docs/en-US/examples/composition.mdx | 101 ++++++++++++---- .../ui/docs/en-US/examples/message-thread.mdx | 58 +++++++++ packages/ui/docs/en-US/guide/components.mdx | 101 +++++++++++++--- packages/ui/docs/en-US/guide/feedback.mdx | 95 +++++++++++++++ packages/ui/docs/en-US/guide/overlays.mdx | 113 ++++++++++++++++++ packages/ui/docs/en-US/guide/setup.mdx | 106 +++++++++++----- packages/ui/docs/en-US/overview.mdx | 49 ++++++-- packages/ui/docs/zh-Hans/advanced/hooks.mdx | 85 +++++++++++-- .../ui/docs/zh-Hans/advanced/localization.mdx | 76 +++++++++--- .../advanced/workspace-adaptations.mdx | 67 +++++++++++ .../zh-Hans/examples/anchored-popover.mdx | 64 ++++++++++ .../ui/docs/zh-Hans/examples/composition.mdx | 99 +++++++++++---- .../docs/zh-Hans/examples/message-thread.mdx | 58 +++++++++ packages/ui/docs/zh-Hans/guide/components.mdx | 99 ++++++++++++--- packages/ui/docs/zh-Hans/guide/feedback.mdx | 95 +++++++++++++++ packages/ui/docs/zh-Hans/guide/overlays.mdx | 113 ++++++++++++++++++ packages/ui/docs/zh-Hans/guide/setup.mdx | 106 +++++++++++----- packages/ui/docs/zh-Hans/overview.mdx | 49 ++++++-- 22 files changed, 1636 insertions(+), 192 deletions(-) create mode 100644 packages/ui/docs/en-US/advanced/workspace-adaptations.mdx create mode 100644 packages/ui/docs/en-US/examples/anchored-popover.mdx create mode 100644 packages/ui/docs/en-US/examples/message-thread.mdx create mode 100644 packages/ui/docs/en-US/guide/feedback.mdx create mode 100644 packages/ui/docs/en-US/guide/overlays.mdx create mode 100644 packages/ui/docs/zh-Hans/advanced/workspace-adaptations.mdx create mode 100644 packages/ui/docs/zh-Hans/examples/anchored-popover.mdx create mode 100644 packages/ui/docs/zh-Hans/examples/message-thread.mdx create mode 100644 packages/ui/docs/zh-Hans/guide/feedback.mdx create mode 100644 packages/ui/docs/zh-Hans/guide/overlays.mdx diff --git a/packages/ui/docs/en-US/advanced/hooks.mdx b/packages/ui/docs/en-US/advanced/hooks.mdx index b6bd3f8..2160b48 100644 --- a/packages/ui/docs/en-US/advanced/hooks.mdx +++ b/packages/ui/docs/en-US/advanced/hooks.mdx @@ -1,31 +1,98 @@ --- -title: Add responsive behavior -description: Use shared breakpoint and interaction hooks when CSS alone cannot express the behavior. +title: Responsive and interaction hooks +description: Synchronize breakpoints when behavior must follow the viewport and add ripple feedback to custom controls. order: 20 toc: - - id: breakpoints - title: Breakpoints + - id: breakpoint-contract + title: Breakpoint contract + - id: reading-breakpoints + title: Read breakpoints + - id: root-classes + title: Root classes - id: server-rendering title: Server rendering - id: ripple title: Ripple interaction --- -## Breakpoints {#breakpoints} +## Breakpoint contract {#breakpoint-contract} + +The shared breakpoint splits the viewport into three ranges: + +| Value | Range | +| --------- | -------------------- | +| `mobile` | Below 768px | +| `tablet` | 768px through 1023px | +| `desktop` | 1024px and above | + +Prefer CSS for visual changes. Read a breakpoint during rendering only when mounted content, interaction behavior, or data volume must change. + +## Read breakpoints {#reading-breakpoints} ```tsx -import { useBreakpoint, useIsMobile } from "@workspace/ui/hooks/use-breakpoint" +import { + useBreakpoint, + useIsDesktop, + useIsMobile, + useIsTablet, + useOnBreakpoint, +} from "@workspace/ui/hooks/use-breakpoint" const breakpoint = useBreakpoint() const isMobile = useIsMobile() ``` -Prefer CSS responsive variants for visual changes. Use these hooks only when component behavior or mounted content must change. +Every hook subscribes to the same pair of `matchMedia` queries through `useSyncExternalStore`. `useOnBreakpoint(listener)` runs only after the breakpoint changes; it does not report the initial value as a change. + +## Root classes {#root-classes} + +After mounting `BreakpointReactor`, the document root has exactly one of `.ui:mobile`, `.ui:tablet`, or `.ui:desktop`: + +```tsx +import { BreakpointReactor } from "@workspace/ui/hooks/use-breakpoint" + +;<> + + + +``` + +`globals.css` registers these as the custom `mobile:`, `tablet:`, and `desktop:` variants, allowing CSS and behavioral code to share the same three-range definition. ## Server rendering {#server-rendering} -The breakpoint store uses a deterministic desktop server snapshot. `getBreakpointInitializationScript` can assign the matching root class before hydration when the application needs CSS and behavioral breakpoints to agree immediately. +The server snapshot is fixed to `desktop` so SSR remains deterministic. To write the real class before hydration, place the result of `getBreakpointInitializationScript()` in an inline script in the document head: + +```tsx +import { getBreakpointInitializationScript } from "@workspace/ui/hooks/use-breakpoint" + +;