Skip to content

Commit c0bb756

Browse files
authored
docs: highlight component as "new" (#1162)
1 parent e6db3d4 commit c0bb756

File tree

8 files changed

+64
-16
lines changed

8 files changed

+64
-16
lines changed

apps/docs/app/routes/_docs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { defineQuery } from 'groq';
1414

1515
const COMPONENTS_NAVIGATION_QUERY = defineQuery(
1616
// make sure the slug is always a string so we don't have add fallback value in code just to make TypeScript happy
17-
`*[_type == "component"]{ _id, name, 'slug': coalesce(slug.current, '')} | order(name asc)`,
17+
`*[_type == "component"]{ _id, name, 'slug': coalesce(slug.current, ''), highlightAsNew} | order(name asc)`,
1818
);
1919

2020
// This is the shared layout for all the Grunnmuren docs pages that are "public", ie not the Sanity studio

apps/docs/app/routes/_docs/komponenter/$slug.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { sanityFetch } from '@/lib/sanity';
22
import { AnchorHeading } from '@/ui/anchor-heading';
3-
import { Content } from '@/ui/content';
43
import { PropsTable } from '@/ui/props-table';
54
import { ResourceLink, ResourceLinks } from '@/ui/resource-links';
5+
import { SanityContent } from '@/ui/sanity-content';
6+
import { Child } from '@obosbbl/grunnmuren-icons-react';
7+
import { Alertbox, Content } from '@obosbbl/grunnmuren-react';
68
import { createFileRoute, notFound } from '@tanstack/react-router';
79
import type * as props from 'docgen';
810
import { defineQuery } from 'groq';
911

1012
const COMPONENT_QUERY = defineQuery(
11-
`*[_type == "component" && slug.current == $slug][0]{ "content": content[] {..., _type == "image-with-caption" => {...,asset->}}, "name": coalesce(name, ''), propsComponents, resourceLinks }`,
13+
`*[_type == "component" && slug.current == $slug][0]{ "content": content[] {..., _type == "image-with-caption" => {...,asset->}}, "name": coalesce(name, ''), propsComponents, resourceLinks, highlightAsNew }`,
1214
);
1315

1416
export const Route = createFileRoute('/_docs/komponenter/$slug')({
@@ -46,7 +48,24 @@ function Page() {
4648
{ghLink && <ResourceLink type="github" href={ghLink} />}
4749
</ResourceLinks>
4850

49-
<Content className="mb-12" content={data.content ?? []} />
51+
{data.highlightAsNew && (
52+
// biome-ignore lint/a11y/useValidAriaRole: <explanation>
53+
<Alertbox
54+
variant="success"
55+
className="mb-12 w-fit"
56+
icon={Child}
57+
role="none"
58+
>
59+
<Content>
60+
Denne komponenten er ny eller har nylig fått større endringer. Ta
61+
den i bruk og kom gjerne med innspill til oss på{' '}
62+
<a href="https://obos.slack.com/archives/C03FR05FJ9F">Slack</a>{' '}
63+
hvordan du synes den fungerer.
64+
</Content>
65+
</Alertbox>
66+
)}
67+
68+
<SanityContent className="mb-12" content={data.content ?? []} />
5069

5170
{data.propsComponents?.length && (
5271
<AnchorHeading className="heading-m" level={2} id="props">

apps/docs/app/routes/_docs/komponenter/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { sanityFetch } from '@/lib/sanity';
2-
import { Card, CardLink, Heading } from '@obosbbl/grunnmuren-react';
2+
import { Badge, Card, CardLink, Heading } from '@obosbbl/grunnmuren-react';
33
import { createFileRoute } from '@tanstack/react-router';
44
import { defineQuery } from 'groq';
55

66
const COMPONENTS_INDEX_QUERY = defineQuery(
77
// make sure the slug is always a string so we don't have add fallback value in code just to make TypeScript happy
8-
`*[_type == "component"]{ _id, name, 'slug': coalesce(slug.current, '')} | order(name asc)`,
8+
`*[_type == "component"]{ _id, name, 'slug': coalesce(slug.current, ''), highlightAsNew} | order(name asc)`,
99
);
1010

1111
export const Route = createFileRoute('/_docs/komponenter/')({
@@ -33,6 +33,12 @@ function Page() {
3333
<CardLink href={`/komponenter/${component.slug}`}>
3434
{component.name}
3535
</CardLink>
36+
{/* TODO: Figure out better way to highlight this */}
37+
{component.highlightAsNew && (
38+
<Badge className="ml-4" color="mint" size="small">
39+
Ny
40+
</Badge>
41+
)}
3642
</Heading>
3743
</Card>
3844
))}

apps/docs/app/ui/main-nav.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
import { ChevronDown } from '@obosbbl/grunnmuren-icons-react';
2-
import { Heading } from '@obosbbl/grunnmuren-react';
2+
import { Badge, Heading } from '@obosbbl/grunnmuren-react';
33
import { getRouteApi } from '@tanstack/react-router';
44
import { Link } from '@tanstack/react-router';
55
import { Button, Disclosure, DisclosurePanel } from 'react-aria-components';
66

77
type SubNavItemProps = {
88
to: string;
99
title: string;
10+
highlightAsNew?: boolean | null;
1011
};
1112

12-
const SubNavItem = ({ to, title }: SubNavItemProps) => (
13+
const SubNavItem = ({ to, title, highlightAsNew }: SubNavItemProps) => (
1314
<li>
1415
<Link
1516
to={to}
16-
className="description inline-flex items-center gap-2 rounded-md px-3 py-2 focus-visible:outline-focus focus-visible:outline-focus-inset data-[status=active]:font-bold data-[status=active]:no-underline"
17+
className="description flex items-center justify-between gap-2 rounded-md px-3 py-2 focus-visible:outline-focus focus-visible:outline-focus-inset data-[status=active]:font-bold data-[status=active]:no-underline"
1718
>
1819
{title}
20+
{highlightAsNew && (
21+
<Badge className="no-underline" color="mint" size="small">
22+
Ny
23+
</Badge>
24+
)}
1925
</Link>
2026
</li>
2127
);
@@ -71,6 +77,7 @@ export const MainNav = () => {
7177
const componentsNavLinks = data.map((component) => ({
7278
to: `/komponenter/${component.slug}`,
7379
title: component.name as string,
80+
highlightAsNew: component.highlightAsNew,
7481
}));
7582

7683
return (

apps/docs/app/ui/content.tsx renamed to apps/docs/app/ui/sanity-content.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import { ComponentPreview } from './component-preview';
77
import { ImageWithCaption } from './image-with-caption';
88
import { Table, TableBody, TableCell, TableHead, TableRow } from './table';
99

10-
export type ContentProps = Pick<
10+
export type SanityContentProps = Pick<
1111
NonNullable<COMPONENT_QUERYResult>,
1212
'content'
1313
> & {
1414
className?: string;
1515
};
1616

17-
export function Content({ content, className }: ContentProps) {
17+
export function SanityContent({ content, className }: ContentProps) {
1818
return (
1919
<div className={cx('prose', className)}>
2020
<PortableText

apps/docs/sanity.types.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ export type Component = {
194194
slug?: Slug;
195195
content?: Content;
196196
propsComponents?: Array<string>;
197+
highlightAsNew?: boolean;
197198
resourceLinks?: Array<{
198199
linkType?: 'figma' | 'github';
199200
url?: string;
@@ -253,16 +254,17 @@ export type AllSanitySchemaTypes =
253254
export declare const internalGroqTypeReferenceTo: unique symbol;
254255
// Source: ./app/routes/_docs.tsx
255256
// Variable: COMPONENTS_NAVIGATION_QUERY
256-
// Query: *[_type == "component"]{ _id, name, 'slug': coalesce(slug.current, '')} | order(name asc)
257+
// Query: *[_type == "component"]{ _id, name, 'slug': coalesce(slug.current, ''), highlightAsNew} | order(name asc)
257258
export type COMPONENTS_NAVIGATION_QUERYResult = Array<{
258259
_id: string;
259260
name: string | null;
260261
slug: string | '';
262+
highlightAsNew: boolean | null;
261263
}>;
262264

263265
// Source: ./app/routes/_docs/komponenter/$slug.tsx
264266
// Variable: COMPONENT_QUERY
265-
// Query: *[_type == "component" && slug.current == $slug][0]{ "content": content[] {..., _type == "image-with-caption" => {...,asset->}}, "name": coalesce(name, ''), propsComponents, resourceLinks }
267+
// Query: *[_type == "component" && slug.current == $slug][0]{ "content": content[] {..., _type == "image-with-caption" => {...,asset->}}, "name": coalesce(name, ''), propsComponents, resourceLinks, highlightAsNew }
266268
export type COMPONENT_QUERYResult = {
267269
content: Array<
268270
| {
@@ -343,24 +345,26 @@ export type COMPONENT_QUERYResult = {
343345
_type: 'resourceLink';
344346
_key: string;
345347
}> | null;
348+
highlightAsNew: boolean | null;
346349
} | null;
347350

348351
// Source: ./app/routes/_docs/komponenter/index.tsx
349352
// Variable: COMPONENTS_INDEX_QUERY
350-
// Query: *[_type == "component"]{ _id, name, 'slug': coalesce(slug.current, '')} | order(name asc)
353+
// Query: *[_type == "component"]{ _id, name, 'slug': coalesce(slug.current, ''), highlightAsNew} | order(name asc)
351354
export type COMPONENTS_INDEX_QUERYResult = Array<{
352355
_id: string;
353356
name: string | null;
354357
slug: string | '';
358+
highlightAsNew: boolean | null;
355359
}>;
356360

357361
// Query TypeMap
358362
import '@sanity/client';
359363
declare module '@sanity/client' {
360364
interface SanityQueries {
361-
"*[_type == \"component\"]{ _id, name, 'slug': coalesce(slug.current, '')} | order(name asc)":
365+
"*[_type == \"component\"]{ _id, name, 'slug': coalesce(slug.current, ''), highlightAsNew} | order(name asc)":
362366
| COMPONENTS_NAVIGATION_QUERYResult
363367
| COMPONENTS_INDEX_QUERYResult;
364-
'*[_type == "component" && slug.current == $slug][0]{ "content": content[] {..., _type == "image-with-caption" => {...,asset->}}, "name": coalesce(name, \'\'), propsComponents, resourceLinks }': COMPONENT_QUERYResult;
368+
'*[_type == "component" && slug.current == $slug][0]{ "content": content[] {..., _type == "image-with-caption" => {...,asset->}}, "name": coalesce(name, \'\'), propsComponents, resourceLinks, highlightAsNew }': COMPONENT_QUERYResult;
365369
}
366370
}

apps/docs/schema.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,13 @@
11041104
},
11051105
"optional": true
11061106
},
1107+
"highlightAsNew": {
1108+
"type": "objectAttribute",
1109+
"value": {
1110+
"type": "boolean"
1111+
},
1112+
"optional": true
1113+
},
11071114
"resourceLinks": {
11081115
"type": "objectAttribute",
11091116
"value": {

apps/docs/studio/documents/component.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ export default defineType({
3535
}),
3636
],
3737
}),
38+
defineField({
39+
name: 'highlightAsNew',
40+
type: 'boolean',
41+
title: 'Highlight as a new component',
42+
}),
3843
defineField({
3944
name: 'resourceLinks',
4045
title: 'Resource links',

0 commit comments

Comments
 (0)