@@ -16,7 +16,7 @@ export function registerDocumentationDetailStyles(
1616 registerComponentHeaderStyles ( article , palette , colors )
1717 registerExampleFrameStyles ( article , colors )
1818 registerCodeFrameStyles ( article , colors )
19- registerCopyControlStyles ( article , colors )
19+ registerCopyControlStyles ( article , palette , colors )
2020 registerTableFrameStyles ( article , colors )
2121 registerAdjacentPageCardStyles ( article , colors )
2222 registerAdjacentPageControlStyles ( article , palette , colors )
@@ -194,25 +194,70 @@ function registerCodeFrameStyles(article: Style, colors: DocumentationColors) {
194194
195195function registerCopyControlStyles (
196196 article : Style ,
197+ palette : ThemePalette ,
197198 colors : DocumentationColors ,
198199) {
199- const { heading, control, border } = colors
200+ const button =
201+ ':is(:scope > pre, :scope > .tabs .tabs__panel-body > pre, .api-property__content pre, .api-contract pre) > .code-copy-button'
202+ const idle = `${ button } :not(.is-copied, .is-error)`
203+ const { muted, surface, border } = colors
200204
201205 article
202- . select (
203- ':scope > pre > .code-copy-button, .api-property__content > pre > .code-copy-button, .api-contract > pre > .code-copy-button' ,
204- )
205- . opacity ( '0.65' )
206- . pointerEvents ( 'auto' )
207- . color ( heading )
208- . background ( control )
209- . borderColor ( border )
206+ . select ( button )
207+ . width ( '2.25rem' )
208+ . height ( '2.25rem' )
209+ . padding ( '0.5rem' )
210+ . borderRadius ( '0.625rem' )
211+ . boxShadow ( 'none' )
210212
211213 article
212- . select (
213- ':scope > pre:is(:hover, :focus-within) > .code-copy-button, .api-property__content > pre:is(:hover, :focus-within) > .code-copy-button, .api-contract > pre:is(:hover, :focus-within) > .code-copy-button' ,
214- )
215- . opacity ( '1' )
214+ . select ( idle )
215+ . color ( muted )
216+ . background ( surface )
217+ . border ( `1px solid ${ border } ` )
218+
219+ article . select ( `${ button } > svg` ) . width ( '1.125rem' ) . height ( '1.125rem' )
220+ registerCopyControlInteractionStyles ( article , idle , palette , colors )
221+ registerCopyControlFeedbackStyles ( article , button , palette )
222+ }
223+
224+ function registerCopyControlInteractionStyles (
225+ article : Style ,
226+ button : string ,
227+ palette : ThemePalette ,
228+ colors : DocumentationColors ,
229+ ) {
230+ const accent = palette . semanticTone . accent
231+ article
232+ . select ( `${ button } :is(:hover, :focus-visible)` )
233+ . background ( colors . tint )
234+ . borderColor ( accent . border . default )
235+ . color ( accent . text . default )
236+ . boxShadow ( `0 2px 8px ${ colors . shadow } ` )
237+
238+ article
239+ . select ( `${ button } :focus-visible` )
240+ . outline ( `2px solid ${ accent . border . focus } ` )
241+ . outlineOffset ( '3px' )
242+
243+ article . select ( `${ button } :active` ) . transform ( 'scale(0.96)' )
244+ }
245+
246+ function registerCopyControlFeedbackStyles (
247+ article : Style ,
248+ button : string ,
249+ palette : ThemePalette ,
250+ ) {
251+ for ( const [ state , tone ] of [
252+ [ 'is-copied' , palette . semanticTone . success ] ,
253+ [ 'is-error' , palette . semanticTone . danger ] ,
254+ ] as const ) {
255+ article
256+ . select ( `${ button } .${ state } ` )
257+ . background ( tone . surface . rest . background )
258+ . borderColor ( tone . border . default )
259+ . color ( tone . surface . rest . text )
260+ }
216261}
217262
218263function registerTableFrameStyles ( article : Style , colors : DocumentationColors ) {
0 commit comments