Skip to content

Commit de95f98

Browse files
committed
Merge branch 'next' of https://github.com/code-hike/codehike into slideshow-auto
# Conflicts: # packages/mdx/src/mdx-client/slideshow.tsx
2 parents 4b6ed5c + dcc6e91 commit de95f98

File tree

10 files changed

+156
-17
lines changed

10 files changed

+156
-17
lines changed

.github/workflows/bundle_analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: 'Bundle Analysis'
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
push:
66
branches:
77
- next # change this if your default branch is named differently

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
node_modules
2+
.DS_Store
23
.next
34
todo.md
45
current.md
@@ -10,6 +11,7 @@ yarn-error.log
1011
storybook-static
1112
packages/playground/out
1213
packages/starter
14+
packages/mdx/components.d.ts
1315

1416
# Contentlayer
1517
.contentlayer
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Slideshow with controls autofocus
2+
3+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Praesent elementum facilisis leo vel fringilla est ullamcorper eget. At imperdiet dui accumsan sit amet nulla facilities morbi tempus. Praesent elementum facilisis leo vel fringilla. Congue mauris rhoncus aenean vel. Egestas sed tempus urna et pharetra pharetra massa massa ultricies.
4+
5+
<CH.Slideshow preset="https://codesandbox.io/s/w5wfe" autoFocus={true}>
6+
7+
Lorem ipsum dolor sit amet, consectetur adipiscing something about points, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
8+
9+
```jsx src/App.js
10+
import { motion } from "framer-motion"
11+
12+
const transition = { duration: 1 }
13+
14+
export default function App() {
15+
const bg = "hsl(20, 100%, 50%)"
16+
return (
17+
<div className="container">
18+
<motion.div
19+
className="swatch"
20+
animate={{
21+
backgroundColor: bg,
22+
}}
23+
transition={transition}
24+
/>
25+
</div>
26+
)
27+
}
28+
```
29+
30+
---
31+
32+
## Step 2
33+
34+
Velit euismod in pellentesque massa placerat. Mi bibendum neque egestas congue quisque egestas diam in arcu. Nisi lacus sed viverra tellus in.
35+
36+
```jsx src/App.js focus=1,6,9:15
37+
import { motion } from "framer-motion"
38+
39+
const transition = { duration: 1 }
40+
41+
export default function App() {
42+
const bg = "hsl(110, 100%, 50%)"
43+
return (
44+
<div className="container">
45+
<motion.div
46+
className="swatch"
47+
animate={{
48+
backgroundColor: bg,
49+
}}
50+
transition={transition}
51+
/>
52+
</div>
53+
)
54+
}
55+
```
56+
57+
---
58+
59+
## Step 3
60+
61+
Id aliquet risus feugiat in ante metus dictum at tempor. Sed blandit libero volutpat sed cras.
62+
63+
```jsx src/App.js focus=1,6,9:15
64+
import { motion } from "framer-motion"
65+
66+
const transition = { duration: 1 }
67+
68+
export default function App() {
69+
const bg = "hsl(200, 100%, 50%)"
70+
return (
71+
<div className="container">
72+
<motion.div
73+
className="swatch"
74+
animate={{
75+
backgroundColor: bg,
76+
}}
77+
transition={transition}
78+
/>
79+
</div>
80+
)
81+
}
82+
```
83+
84+
---
85+
86+
## Step 4
87+
88+
Velit euismod in pellentesque massa placerat. Mi bibendum neque egestas congue quisque egestas diam in arcu.
89+
90+
```jsx src/App.js focus=1,6,9:15
91+
import { motion } from "framer-motion"
92+
93+
const transition = { duration: 1 }
94+
95+
export default function App() {
96+
const bg = "hsl(290, 100%, 50%)"
97+
return (
98+
<div className="container">
99+
<motion.div
100+
className="swatch"
101+
animate={{
102+
backgroundColor: bg,
103+
}}
104+
transition={transition}
105+
/>
106+
</div>
107+
)
108+
}
109+
```
110+
111+
</CH.Slideshow>

packages/mdx/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22
"name": "@code-hike/mdx",
33
"version": "0.7.2",
44
"files": [
5-
"dist"
5+
"dist",
6+
"components.d.ts"
67
],
78
"main": "./dist/index.cjs.js",
89
"module": "./dist/index.esm.mjs",
910
"types": "./dist/index.d.ts",
1011
"exports": {
1112
".": {
13+
"types": "./dist/index.d.ts",
1214
"import": "./dist/index.esm.mjs",
1315
"require": "./dist/index.cjs.js",
1416
"style": "./dist/index.css"
1517
},
1618
"./components": {
19+
"types": "./dist/components.d.ts",
1720
"import": "./dist/components.esm.mjs",
1821
"require": "./dist/components.cjs.js",
1922
"default": "./dist/components.cjs.js"
@@ -23,6 +26,7 @@
2326
"./styles.css": "./dist/index.css",
2427
"./dist/index.css": "./dist/index.css",
2528
"./dist/components.cjs.js": {
29+
"types": "./dist/components.d.ts",
2630
"import": "./dist/components.esm.mjs",
2731
"require": "./dist/components.cjs.js",
2832
"default": "./dist/components.cjs.js"

packages/mdx/rollup.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ export default function makeConfig(commandOptions) {
136136
input: `src/components.tsx`,
137137
output: [
138138
{ file: `./dist/components.d.ts`, format: "es" },
139+
// because of typescript not following package.json exports sometimes
140+
{ file: `./components.d.ts`, format: "es" },
139141
],
140142
external: clientExternal,
141143
plugins: [dts()],

packages/mdx/src/components.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from "./mdx-client/annotations"
1515
import { Preview } from "./mdx-client/preview"
1616
import { InlineCode } from "./mdx-client/inline-code"
17+
import type { MDXComponents } from "mdx/types"
1718

1819
export {
1920
Code,
@@ -31,7 +32,7 @@ export {
3132
PreviewSlot,
3233
}
3334

34-
export const CH = {
35+
export const CH: MDXComponents = {
3536
Code,
3637
Section,
3738
SectionLink,

packages/mdx/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export { transform as remarkCodeHike } from "./remark/transform"
1+
export { attacher as remarkCodeHike } from "./remark/transform"
22

33
export { highlight } from "./highlighter"

packages/mdx/src/mdx-client/annotations.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import { CodeAnnotation } from "../smooth-code"
33
import { getColor, transparent, ColorName } from "../utils"
44

55
export function Annotation() {
6-
return "error: code hike remark plugin not running or annotation isn't at the right place"
6+
return (
7+
<div>
8+
"error: code hike remark plugin not running or
9+
annotation isn't at the right place"
10+
</div>
11+
)
712
}
813

914
export const annotationsMap: Record<

packages/mdx/src/mdx-client/slideshow.tsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,37 @@ import { AnimatePresence } from "framer-motion"
77

88
export function Slideshow({
99
children,
10-
editorSteps,
10+
className,
11+
code,
1112
codeConfig,
13+
editorSteps,
14+
autoFocus,
15+
hasPreviewSteps,
1216
presetConfig,
13-
code,
14-
className,
1517
style,
16-
hasPreviewSteps,
1718
autoPlay,
1819
autoPlayLoop = false,
1920
...rest
2021
}: {
2122
children: React.ReactNode
22-
editorSteps: EditorStep[]
23+
className?: string
24+
code?: EditorProps["codeConfig"]
2325
codeConfig: EditorProps["codeConfig"]
26+
editorSteps: EditorStep[]
27+
hasPreviewSteps?: boolean
28+
autoFocus?: boolean
2429
presetConfig?: PresetConfig
25-
code?: EditorProps["codeConfig"]
26-
className?: string
2730
style?: React.CSSProperties
28-
hasPreviewSteps?: boolean
2931
autoPlay?: number
3032
autoPlayLoop?: boolean
3133
}) {
34+
const controlsRef = React.useRef(null)
35+
36+
React.useEffect(() => {
37+
// Only set focus on controls input if we have configured to do so
38+
autoFocus && controlsRef.current.focus()
39+
}, [])
40+
3241
const { stepsChildren, previewChildren } =
3342
extractPreviewSteps(children, hasPreviewSteps)
3443
const withPreview = presetConfig || hasPreviewSteps
@@ -163,17 +172,19 @@ export function Slideshow({
163172
Prev
164173
</button>
165174
<input
166-
type="range"
167-
min={0}
168175
max={maxSteps}
169-
value={state.stepIndex}
176+
min={0}
177+
ref={controlsRef}
170178
step={1}
179+
type="range"
180+
value={state.stepIndex}
171181
onChange={e =>
172182
setState({
173183
stepIndex: +e.target.value,
174184
step: editorSteps[+e.target.value],
175185
})
176186
}
187+
autoFocus={autoFocus}
177188
/>
178189
<button
179190
onClick={() => slideNext()}

packages/mdx/src/remark/transform.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { valueToEstree } from "./to-estree"
1010
import { CH_CODE_CONFIG_VAR_NAME } from "./unist-utils"
1111
import { JsxNode, SuperNode, visit } from "./nodes"
1212
import { addConfigDefaults, CodeHikeConfig } from "./config"
13+
import { Attacher } from "unified"
1314

1415
const transforms = [
1516
transformPreviews,
@@ -20,7 +21,9 @@ const transforms = [
2021
transformInlineCodes,
2122
transformCodes,
2223
]
23-
export function transform(unsafeConfig: CodeHikeConfig) {
24+
export const attacher: Attacher<
25+
[CodeHikeConfig?]
26+
> = unsafeConfig => {
2427
return async (tree: SuperNode, file: any) => {
2528
const config = addConfigDefaults(
2629
unsafeConfig,

0 commit comments

Comments
 (0)