File tree Expand file tree Collapse file tree 3 files changed +42
-5
lines changed
packages/scrollycoding/src Expand file tree Collapse file tree 3 files changed +42
-5
lines changed Original file line number Diff line number Diff line change @@ -13,10 +13,13 @@ export interface FocusProps {
13
13
file ?: string
14
14
}
15
15
16
- export function Focus ( { children, ...props } : FocusProps ) {
16
+ export function Focus ( {
17
+ children,
18
+ ...props
19
+ } : FocusProps ) : JSX . Element {
17
20
const hikeContext = useHikeContext ( )
18
21
return hikeContext . layout === "fixed" ? (
19
- children
22
+ ( children as JSX . Element )
20
23
) : (
21
24
< FocusButton
22
25
context = { hikeContext }
@@ -91,3 +94,31 @@ function Icon({ isFocused }: { isFocused: boolean }) {
91
94
</ svg >
92
95
)
93
96
}
97
+
98
+ export function withFocusHandler ( type : any = "a" ) {
99
+ function AnchorWithFocus ( props : any ) {
100
+ return < AnchorOrFocus type = { type } { ...props } />
101
+ }
102
+ return AnchorWithFocus
103
+ }
104
+
105
+ export function AnchorOrFocus ( {
106
+ type = "a" ,
107
+ href,
108
+ ...props
109
+ } : any ) {
110
+ if ( ! href . startsWith ( "focus://" ) ) {
111
+ return React . createElement ( type , { href, ...props } )
112
+ }
113
+
114
+ const [ firstPart , secondPart ] = decodeURI ( href )
115
+ . substr ( "focus://" . length )
116
+ . split ( "#" )
117
+ const hasFile = Boolean ( secondPart )
118
+
119
+ return hasFile ? (
120
+ < Focus on = { secondPart } file = { firstPart } { ...props } />
121
+ ) : (
122
+ < Focus on = { firstPart } { ...props } />
123
+ )
124
+ }
Original file line number Diff line number Diff line change @@ -2,7 +2,11 @@ import * as React from "react"
2
2
import "./index.scss"
3
3
import { Hike } from "./hike"
4
4
5
- import { Focus } from "./focus"
5
+ import {
6
+ Focus ,
7
+ AnchorOrFocus ,
8
+ withFocusHandler ,
9
+ } from "./focus"
6
10
import { CodeSlot , PreviewSlot } from "./fixed-layout"
7
11
import { useMdxSteps , StepHead } from "./mdx-steps"
8
12
import {
@@ -21,4 +25,6 @@ export {
21
25
PreviewProps ,
22
26
useMdxSteps ,
23
27
StepHead ,
28
+ AnchorOrFocus ,
29
+ withFocusHandler ,
24
30
}
Original file line number Diff line number Diff line change @@ -16,8 +16,8 @@ export interface StepHeadProps {
16
16
previewProps ?: Partial < PreviewProps >
17
17
}
18
18
19
- function StepHead ( props : StepHeadProps ) {
20
- return null
19
+ function StepHead ( props : StepHeadProps ) : JSX . Element {
20
+ return ( null as any ) as JSX . Element
21
21
}
22
22
23
23
interface Step {
You can’t perform that action at this time.
0 commit comments