Skip to content

Commit 40f01e4

Browse files
committed
Commit bunch of changes
1 parent e67d5fe commit 40f01e4

File tree

26 files changed

+383
-114
lines changed

26 files changed

+383
-114
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"start": "env NODE_ENV=development ts-node -r tsconfig-paths/register devServer.ts"
1515
},
1616
"dependencies": {
17-
"@date-fns/docs": "0.22.0",
17+
"@date-fns/docs": "0.24.0",
1818
"@sentry/browser": "^5.30.0",
1919
"@sentry/tracing": "^5.30.0",
2020
"@switcher/preact": "2.3.0",

src/ui/components/DocDescription/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ interface DocDescriptionProps {
66
description: string
77
scope?: string
88
header?: 'h2' | 'h3'
9+
skipHeader?: boolean
910
}
1011

1112
export const DocDescription: FunctionComponent<DocDescriptionProps> = ({
1213
description,
1314
header,
1415
scope,
16+
skipHeader,
1517
}) => (
1618
<section>
17-
<SectionHeader header="Description" scope={scope} tag={header} />
19+
{!skipHeader && (
20+
<SectionHeader header="Description" scope={scope} tag={header} />
21+
)}
1822
<Markdown value={description} />
1923
</section>
2024
)

src/ui/components/HighlightQuery/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as styles from './styles.css'
55

66
interface HighlightQueryProps {
77
text: string
8-
query: string
8+
query: string | undefined
99
}
1010

1111
export const HighlightQuery: FunctionComponent<HighlightQueryProps> = ({
@@ -33,7 +33,7 @@ interface Chunk {
3333
type: 'chunk' | 'query'
3434
}
3535

36-
function highlightText(text: string, query: string): Chunk[] {
36+
function highlightText(text: string, query: string | undefined): Chunk[] {
3737
if (!text || !query) return [{ text, type: 'chunk' }]
3838

3939
const chunks: Chunk[] = []

src/ui/components/IdHighlight/index.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { match } from 'assert'
22
import { FunctionComponent, h } from 'preact'
33
import { useEffect, useRef } from 'preact/hooks'
4+
import { isInViewport } from '~/utils/dom'
45
import * as styles from './styles.css'
56

67
interface IdHightlightProps {
@@ -62,14 +63,3 @@ export const IdHightlight: FunctionComponent<IdHightlightProps> = ({
6263
</span>
6364
)
6465
}
65-
66-
function isInViewport(element: HTMLElement): boolean {
67-
const rect = element.getBoundingClientRect()
68-
return (
69-
rect.top >= 0 &&
70-
rect.left >= 0 &&
71-
rect.bottom <=
72-
(window.innerHeight || document.documentElement.clientHeight) &&
73-
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
74-
)
75-
}

src/ui/components/Item/index.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,45 @@
11
import classNames from 'classnames'
22
import { Fragment, FunctionComponent, h } from 'preact'
3+
import { Ref } from 'preact/hooks'
4+
import { highlightMarkdown } from '~/utils/docs'
5+
import { HighlightQuery } from '../HighlightQuery'
6+
import { Markdown } from '../Markdown'
7+
import { RichText } from '../RichText'
38
import * as styles from './styles.css'
49

510
interface Props {
611
title: string
712
summary: string | undefined
8-
selected: boolean
13+
active: boolean
914
code: boolean
15+
query?: string
16+
activeRef?: Ref<HTMLDivElement>
1017
}
1118

1219
export const Item: FunctionComponent<Props> = ({
1320
title,
1421
summary,
15-
selected,
22+
active,
1623
code,
24+
query,
25+
activeRef,
1726
}) => (
18-
<div class={classNames(styles.item, selected && styles.selected)}>
27+
<div
28+
class={classNames(styles.item, active && styles.active)}
29+
ref={(active && activeRef) || undefined}
30+
>
1931
<div>
2032
<h4 class={classNames(styles.title, code && styles.codeTitle)}>
21-
{title}
33+
<HighlightQuery text={title} query={query} />
2234
</h4>
2335

24-
{styles.summary && <p class={styles.summary}>{summary}</p>}
36+
{summary && (
37+
<p class={styles.summary}>
38+
<RichText>
39+
<Markdown value={highlightMarkdown(summary, query)} />
40+
</RichText>
41+
</p>
42+
)}
2543
</div>
2644

2745
<div class={styles.icon} />

src/ui/components/Item/styles.css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const icon = style({
2424
marginLeft: '10px',
2525
})
2626

27-
export const selected = style({
27+
export const active = style({
2828
backgroundColor: '#fff0f3',
2929

3030
':hover': {
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
import classNames from 'classnames'
21
import { Fragment, FunctionComponent, h } from 'preact'
3-
import { useMemo } from 'preact/hooks'
2+
import { RichText } from '../RichText'
43
import * as styles from './styles.css'
54

65
interface NoSearchResultsProps {
76
noun: string
8-
query: string
9-
setQuery: (query: string) => void
7+
query: [string, (query: string) => void]
108
}
119

1210
export const NoSearchResults: FunctionComponent<NoSearchResultsProps> = ({
1311
noun,
14-
query,
15-
setQuery,
12+
query: [query, setQuery],
1613
}) => {
1714
return (
18-
<div>
15+
<RichText>
1916
No {noun} found for <span class={styles.query}>{query}</span>.{' '}
2017
<a
2118
href="#"
@@ -26,6 +23,6 @@ export const NoSearchResults: FunctionComponent<NoSearchResultsProps> = ({
2623
>
2724
Clear query
2825
</a>
29-
</div>
26+
</RichText>
3027
)
3128
}

src/ui/components/RichText/styles.css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { style, globalStyle } from '@vanilla-extract/css'
22

33
export const content = style({
44
fontSize: '1rem',
5-
lineHeight: '1.6em',
5+
lineHeight: '1.6',
66
})
77

88
globalStyle(`${content} a`, {

src/ui/components/Search/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
import { FunctionComponent, h } from 'preact'
22
// import { trackAction } from 'app/acts/tracking_acts'
33
import debounce from 'lodash/debounce'
4-
import { StateUpdater, useCallback } from 'preact/hooks'
4+
import { Ref, StateUpdater, useCallback } from 'preact/hooks'
55
import * as styles from './styles.css'
66
import classNames from 'classnames'
77

88
interface SearchProps {
9-
query: [string, StateUpdater<string>]
9+
query: [string, (query: string) => void]
1010
bordered?: boolean
11+
inputRef?: Ref<HTMLInputElement>
1112
}
1213

1314
export const Search: FunctionComponent<SearchProps> = ({
1415
query: [query, setQuery],
1516
bordered,
17+
inputRef,
1618
}) => {
1719
const trackSearch = useCallback(
1820
debounce((newQuery: string) => {
@@ -36,6 +38,7 @@ export const Search: FunctionComponent<SearchProps> = ({
3638
trackSearch(newQuery)
3739
setQuery(newQuery)
3840
}}
41+
ref={inputRef}
3942
/>
4043

4144
{query.trim().length > 0 && <Cancel setQuery={setQuery} />}

src/ui/components/Search/styles.css.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const cancel = style({
2828
backgroundImage: `url('${cancelURL}')`,
2929
backgroundSize: '16px',
3030
position: 'absolute',
31-
right: '1.5rem',
31+
right: '1rem',
3232
})
3333

3434
export const input = style({

0 commit comments

Comments
 (0)