diff --git a/static/packages/scraps/README.md b/static/packages/scraps/README.md index 4c01ef7826d7..0ab4b5f77233 100644 --- a/static/packages/scraps/README.md +++ b/static/packages/scraps/README.md @@ -151,6 +151,49 @@ the theme and a Scraps `Button` at `components/ui/scraps/button.tsx`. Scraps components read their theme from [`ScrapsProvider`](#scrapsprovider), so wrap the app in it before rendering them. +## shadcn/ui components + +Each item installs a re-export of a Scraps component at +`components/ui/scraps/.tsx`. Render them inside `ScrapsProvider`, which the +`scraps/theme-provider` item sets up. + +### Link + +```sh +pnpm dlx shadcn@latest add getsentry/sentry/scraps/link +``` + +Without a router, `Link` renders ``. To navigate client-side, wrap the +app in `LinkBehaviorContextProvider` with a component that renders your router's +link, and pass `replace`, `preventScrollReset`, and `state` on to it. +`useResolveLinkHref` turns a `to` object into an href string. With React Router: + +```tsx +import {Link as RouterLink} from 'react-router'; + +import { + Link, + LinkBehaviorContextProvider, + type LinkProps, + useResolveLinkHref, +} from '@/components/ui/scraps/link'; + +function AppLink({to, ...props}: LinkProps) { + const resolveHref = useResolveLinkHref(); + return ; +} + +const linkBehavior = {component: AppLink, behavior: (props: LinkProps) => props}; + + + Issues +; +``` + +`@sentry/scraps` installs its own `@types/react`. If spreading `LinkProps` onto +your router's link fails with "Types of property 'ref' are incompatible", +override `@types/react` to your app's version so there is only one copy. + ## Date and duration formatting Components and plain formatters share the same presentation options: diff --git a/static/packages/scraps/registry.json b/static/packages/scraps/registry.json index 8d15a86ee4fc..78de4cdeb9e6 100644 --- a/static/packages/scraps/registry.json +++ b/static/packages/scraps/registry.json @@ -157,6 +157,20 @@ } ] }, + { + "name": "scraps/link", + "type": "registry:ui", + "title": "Scraps Link", + "description": "The Link from Sentry's Scraps design system. Render it inside ScrapsProvider from @sentry/scraps/provider. It renders a plain until LinkBehaviorContextProvider routes it through your router's link.", + "dependencies": ["@sentry/scraps@>=0.8.0", "@emotion/react@^11.14.0"], + "files": [ + { + "path": "src/shadcn/ui/link.tsx", + "type": "registry:ui", + "target": "components/ui/scraps/link.tsx" + } + ] + }, { "name": "scraps/theme-provider", "type": "registry:component", diff --git a/static/packages/scraps/src/shadcn/index.ts b/static/packages/scraps/src/shadcn/index.ts index 049e8f41b58f..2c09225cf0c4 100644 --- a/static/packages/scraps/src/shadcn/index.ts +++ b/static/packages/scraps/src/shadcn/index.ts @@ -129,8 +129,24 @@ export function generateShadcnRegistry() { ], }; + const link = { + name: 'scraps/link', + type: 'registry:ui', + title: 'Scraps Link', + description: + "The Link from Sentry's Scraps design system. Render it inside ScrapsProvider from @sentry/scraps/provider. It renders a plain until LinkBehaviorContextProvider routes it through your router's link.", + dependencies: ['@sentry/scraps@>=0.8.0', '@emotion/react@^11.14.0'], + files: [ + { + path: 'src/shadcn/ui/link.tsx', + type: 'registry:ui', + target: 'components/ui/scraps/link.tsx', + }, + ], + }; + return { $schema: 'https://ui.shadcn.com/schema/registry.json', - items: [item, button, themeProvider] as const, + items: [item, button, link, themeProvider] as const, }; } diff --git a/static/packages/scraps/src/shadcn/ui/link.tsx b/static/packages/scraps/src/shadcn/ui/link.tsx new file mode 100644 index 000000000000..93c7bffe5bcc --- /dev/null +++ b/static/packages/scraps/src/shadcn/ui/link.tsx @@ -0,0 +1,6 @@ +export { + Link, + LinkBehaviorContextProvider, + useResolveLinkHref, + type LinkProps, +} from '@sentry/scraps/link';