Skip to content

Commit f79d50f

Browse files
committed
Better link styles
1 parent 9fcdf18 commit f79d50f

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

packages/mdx/src/client/inline-code.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export function InlineCode({
2222
const { theme } = codeConfig
2323
const { lines } = code
2424
const allTokens = lines.flatMap(line => line.tokens)
25+
const foreground = getColor(
26+
theme,
27+
ColorName.CodeForeground
28+
)
2529
return (
2630
<span
2731
className={
@@ -32,11 +36,12 @@ export function InlineCode({
3236
>
3337
<code
3438
style={{
39+
["--ch-code-foreground" as any]: foreground,
3540
background: transparent(
3641
getColor(theme, ColorName.CodeBackground),
3742
0.9
3843
),
39-
color: getColor(theme, ColorName.CodeForeground),
44+
color: foreground,
4045
}}
4146
>
4247
{allTokens.map((token, j) => (

packages/mdx/src/client/section.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export function SectionCode() {
7474
return <InnerCode {...props} onTabClick={onTabClick} />
7575
}
7676

77+
// ---
78+
7779
export function SectionLink({
7880
focus,
7981
file,
@@ -95,14 +97,8 @@ export function SectionLink({
9597

9698
return (
9799
<span
98-
style={{
99-
textDecoration: "underline",
100-
textDecorationStyle: "dotted",
101-
// cursor: "pointer",
102-
backgroundColor: isSelected
103-
? "#bae6fd66"
104-
: undefined,
105-
}}
100+
className="ch-section-link"
101+
data-active={isSelected}
106102
// onClick={handleClick}
107103
children={children}
108104
onMouseOver={() =>
@@ -113,8 +109,6 @@ export function SectionLink({
113109
)
114110
}
115111

116-
// ---
117-
118112
const LinkableContext = React.createContext<{
119113
activate: (x: {
120114
fileName?: string

packages/mdx/src/index.scss

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,17 @@
3232
border-radius: 0.25em;
3333
font-size: 0.9em;
3434
}
35+
36+
.ch-section-link,
37+
.ch-section-link * {
38+
text-decoration: underline;
39+
text-decoration-style: dotted;
40+
text-decoration-color: var(
41+
--ch-code-foreground,
42+
currentColor
43+
);
44+
}
45+
46+
.ch-section-link[data-active="true"] {
47+
background-color: #bae6fd66;
48+
}

packages/playground/content/scrollycoding.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ npm install @next/mdx @mdx-js/loader @code-hike/mdx@next
2222

2323
Create a `next.config.js` file at the root of your project.
2424

25-
Here we use the [_`@next/mdx`_](focus://1,6,8) plugin to set up MDX imports.
25+
Here we use the [_`require("@next/mdx")`_](focus://1,6,8) plugin to set up MDX imports.
2626

2727
Also, make sure you include `"md"` and `"mdx"` on the _`pageExtensions`_ setting.
2828

0 commit comments

Comments
 (0)