Skip to content

Commit e40980e

Browse files
committed
changes related to the theme switcher and copy code buttons
1 parent f66754e commit e40980e

3 files changed

Lines changed: 57 additions & 4 deletions

File tree

site_jaspr/lib/components/safe_code_block.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:jaspr/dom.dart';
22
import 'package:jaspr/server.dart';
3+
import 'package:jaspr_content/components/_internal/code_block_copy_button.dart';
34
import 'package:jaspr_content/components/code_block.dart';
45
import 'package:jaspr_content/jaspr_content.dart';
56
import 'package:syntax_highlight_lite/syntax_highlight_lite.dart' hide Color;
@@ -100,6 +101,7 @@ class _DualCodeBlock extends StatelessComponent {
100101
@override
101102
Component build(BuildContext context) {
102103
return div(classes: 'code-block', [
104+
CodeBlockCopyButton(),
103105
pre(classes: 'syntax-light', [
104106
code([_buildSpan(lightHighlighter.highlight(source))]),
105107
]),

site_jaspr/lib/main.server.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ void main() {
9999
),
100100
],
101101
),
102-
ThemeToggle(),
103102
],
104103
items: [
105104
SidebarEntry(text: 'Overview', href: '/docs/overview'),

site_jaspr/lib/styles/site_styles.dart

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,54 @@ List<StyleRule> get siteStyles => [
120120
'line-height': 'inherit',
121121
},
122122
),
123+
// Code block copy button: match Docusaurus style.
124+
// Framework sets opacity:0 and position:absolute AFTER our styles,
125+
// so we use !important to override.
126+
css('.code-block button').styles(
127+
display: Display.flex,
128+
padding: Padding.all(0.25.rem),
129+
border: Border.all(color: Color('#dadde1'), width: 1.px),
130+
radius: BorderRadius.circular(0.4.rem),
131+
justifyContent: JustifyContent.center,
132+
alignItems: AlignItems.center,
133+
backgroundColor: Colors.white,
134+
raw: {
135+
'position': 'absolute !important',
136+
'top': '0.5rem',
137+
'right': '0.5rem',
138+
'width': 'auto !important',
139+
'height': 'auto !important',
140+
'opacity': '0 !important',
141+
'color': '#606770 !important',
142+
'cursor': 'pointer',
143+
'transition': 'opacity 0.2s, color 0.2s',
144+
},
145+
),
146+
css('.code-block button svg').styles(
147+
raw: {'width': '18px !important', 'height': '18px !important'},
148+
),
149+
css('.code-block:hover button').styles(
150+
raw: {'opacity': '0.5 !important'},
151+
),
152+
css('.code-block button:hover').styles(
153+
raw: {'opacity': '1 !important', 'color': '#1c1e21 !important'},
154+
),
155+
css('[data-theme="dark"] .code-block button').styles(
156+
border: Border.all(color: Color('#444950'), width: 1.px),
157+
backgroundColor: Color('#1e1e1e'),
158+
raw: {'color': '#a0a0a0 !important'},
159+
),
160+
css('[data-theme="dark"] .code-block button:hover').styles(
161+
raw: {'color': 'white !important'},
162+
),
163+
// Green check icon after successful copy (CheckIcon has no <rect>, CopyIcon does).
164+
// Must also cover :hover state so green wins over hover color.
165+
css('.code-block button:not(:has(svg rect))').styles(
166+
raw: {'color': '#00a86b !important', 'opacity': '1 !important'},
167+
),
168+
css('.code-block button:not(:has(svg rect)):hover').styles(
169+
raw: {'color': '#00a86b !important'},
170+
),
123171
// Content links: primary color, no underline by default (matching original)
124172
css('.content a:not(.workflow-card):not(.page-nav-prev):not(.page-nav-next)').styles(
125173
textDecoration: TextDecoration.none,
@@ -227,11 +275,13 @@ List<StyleRule> get siteStyles => [
227275
// Dark mode: show moon (first span), hide sun (last span).
228276
// ───────────────────────────────────────────────────────────────────────
229277
css('.theme-toggle').styles(
230-
padding: Padding.all(4.px),
231-
radius: BorderRadius.circular(50.percent),
278+
padding: Padding.zero,
279+
justifyContent: JustifyContent.center,
280+
alignItems: AlignItems.center,
232281
raw: {
233282
'width': '32px',
234283
'height': '32px',
284+
'border-radius': '50% !important',
235285
'box-sizing': 'border-box',
236286
'cursor': 'pointer',
237287
},
@@ -243,8 +293,10 @@ List<StyleRule> get siteStyles => [
243293
backgroundColor: Color('rgba(255, 255, 255, 0.1)'),
244294
),
245295
css('.theme-toggle svg').styles(
246-
raw: {'width': '24px', 'height': '24px'},
296+
raw: {'width': '20px', 'height': '20px'},
247297
),
298+
// Reverse icons: show current state (sun in light, moon in dark).
299+
// Framework default: moon in light, sun in dark.
248300
css('[data-theme="light"] .theme-toggle > span:first-child').styles(
249301
raw: {'display': 'none !important'},
250302
),

0 commit comments

Comments
 (0)