Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions static/packages/scraps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name>.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 `<a href>`. 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 <RouterLink {...props} to={resolveHref(to)} />;
}

const linkBehavior = {component: AppLink, behavior: (props: LinkProps) => props};

<LinkBehaviorContextProvider value={linkBehavior}>
<Link to={{pathname: '/issues/', query: {query: 'is:unresolved'}}}>Issues</Link>
</LinkBehaviorContextProvider>;
```

`@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:
Expand Down
14 changes: 14 additions & 0 deletions static/packages/scraps/registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href> 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",
Expand Down
18 changes: 17 additions & 1 deletion static/packages/scraps/src/shadcn/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href> 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,
};
}
6 changes: 6 additions & 0 deletions static/packages/scraps/src/shadcn/ui/link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export {
Link,
LinkBehaviorContextProvider,
useResolveLinkHref,
type LinkProps,
} from '@sentry/scraps/link';
Loading