1- import { ReactNode , useState } from 'react' ;
1+ import { ReactNode , useMemo , useState } from 'react' ;
22import copy from 'clipboard-copy' ;
33
44import { Action , Button } from '../../actions' ;
55import { Card , CubeCardProps } from '../Card/Card' ;
6- import { Styles , tasty } from '../../../tasty' ;
6+ import { tasty } from '../../../tasty' ;
77import {
88 CubePrismCodeProps ,
99 PrismCode ,
@@ -24,16 +24,21 @@ const ActionElement = tasty(Action, {
2424const StyledBlock = tasty ( {
2525 styles : {
2626 position : 'relative' ,
27- overflow : {
28- '' : 'hidden' ,
29- scroll : 'auto hidden' ,
30- } ,
27+ overflow : 'auto' ,
3128 maxWidth : '100%' ,
3229 whiteSpace : {
3330 '' : 'initial' ,
3431 nowrap : 'nowrap' ,
3532 } ,
3633 styledScrollbar : true ,
34+ padding : {
35+ '' : '1x 1.5x 0 1x' ,
36+ multiline : '1x 1.5x' ,
37+ } ,
38+ fade : {
39+ '' : 'right 2x' ,
40+ multiline : false ,
41+ } ,
3742
3843 '& code' : {
3944 font : {
@@ -47,42 +52,45 @@ const StyledBlock = tasty({
4752const ButtonContainer = tasty ( {
4853 styles : {
4954 position : 'relative' ,
50- display : 'grid' ,
51- gridAutoFlow : 'column' ,
52- margin : '(-1x - 1bw) -1.5x (-1x - 1bw) -1x' ,
55+ display : 'flex' ,
56+ flow : {
57+ '' : 'row-reverse' ,
58+ multiline : 'column' ,
59+ } ,
60+ placeContent : 'start' ,
5361
54- '&::after' : {
55- display : {
56- '' : 'none' ,
57- overlay : 'block' ,
58- } ,
59- content : '""' ,
60- width : '2x' ,
61- position : 'absolute' ,
62- left : '-1x' ,
63- top : 0 ,
64- bottom : 0 ,
65- backgroundImage :
66- 'linear-gradient(to right,rgba(var(--context-fill-color-rgb),0),rgba(var(--context-fill-color-rgb),1))' ,
62+ '@button-size' : {
63+ '' : '5x' ,
64+ multiline : '4x' ,
6765 } ,
66+
67+ '@button-radius' : {
68+ '' : '0' ,
69+ multiline : '1r' ,
70+ } ,
71+
72+ // border: 'left',
6873 } ,
6974} ) ;
7075
7176const CopySnippetElement = tasty ( Card , {
7277 qa : 'CopySnippet' ,
7378 styles : {
74- display : 'block' ,
79+ display : 'grid' ,
80+ gridRows : 'minmax(0, 1fr)' ,
7581 fill : '#grey-light' ,
76- radius : '@large-radius' ,
7782 border : 0 ,
7883 padding : 0 ,
84+ preset : 'default' ,
85+ radius : '1r' ,
7986
8087 Grid : {
8188 display : 'grid' ,
8289 flow : 'row' ,
8390 gridColumns : 'minmax(0, 1fr) auto' ,
91+ gridRows : 'minmax(0, 1fr)' ,
8492 width : 'min 20x' ,
85- radius : '@large-radius ' ,
93+ radius : '1r ' ,
8694 position : 'relative' ,
8795 overflow : 'hidden' ,
8896 } ,
@@ -92,40 +100,34 @@ const CopySnippetElement = tasty(Card, {
92100const ActionButton = tasty ( Button , {
93101 type : 'clear' ,
94102 styles : {
95- padding : '1x 1.5x' ,
96- radius : 0 ,
97- placeSelf : {
98- '' : 'none' ,
99- '!multiline & !with-scroll' : 'stretch' ,
100- } ,
103+ width : '4x' ,
104+ padding : 0 ,
105+ placeSelf : 'stretch' ,
101106 border : '#clear' ,
102107 outline : {
103108 '' : '#purple-03.0' ,
104109 'focused & focus-visible' : '#purple-03 inset' ,
105110 } ,
111+ height : '@button-size' ,
112+ radius : {
113+ '' : '0' ,
114+ ':last-child' : '0 0 0 @button-radius' ,
115+ ':first-child' : '0 @button-radius 0 0' ,
116+ ':last-child & :first-child' : '0 @button-radius 0 @button-radius' ,
117+ } ,
106118 } ,
107119} ) ;
108120
109121const CopyButton = tasty ( ActionButton , {
110122 icon : < CopyIcon /> ,
111123 'aria-label' : 'Copy to clipboard' ,
112- styles : {
113- radius : {
114- '' : '0 1r 1r 0' ,
115- 'multiline | with-scroll' : '0 1r 0 0' ,
116- } ,
117- } ,
118124} ) ;
119125
120126const ShowButton = tasty ( ActionButton , {
121127 'aria-label' : 'Show hidden parts' ,
122- styles : {
123- radius : 0 ,
124- } ,
125128} ) ;
126129
127130export interface CubeCopySnippetProps extends CubeCardProps {
128- padding ?: Styles [ 'padding' ] ;
129131 /** The code snippet */
130132 code : string ;
131133 /** The title of the snippet */
@@ -138,10 +140,6 @@ export interface CubeCopySnippetProps extends CubeCardProps {
138140 language ?: CubePrismCodeProps [ 'language' ] ;
139141 /** Whether the snippet uses a serif font */
140142 serif ?: boolean ;
141- /** Whether the snippet uses overlay on the edge */
142- showOverlay ?: boolean ;
143- /** Whether the snippet is scrollable */
144- showScroll ?: boolean ;
145143 /** Whether to show the tooltip with the full content */
146144 showTooltip ?: boolean ;
147145 hideText ?: string [ ] | string | boolean ;
@@ -162,13 +160,9 @@ function CopySnippet(allProps: CubeCopySnippetProps) {
162160 nowrap,
163161 prefix = '' ,
164162 language,
165- showScroll = true ,
166163 serif,
167164 actions,
168- padding = '1.125x 1.5x' ,
169- showOverlay = true ,
170165 showTooltip = false ,
171- styles,
172166 hideText,
173167 ...props
174168 } = allProps ;
@@ -210,36 +204,34 @@ function CopySnippet(allProps: CubeCopySnippetProps) {
210204 }
211205 }
212206
207+ const mods = useMemo ( ( ) => {
208+ return {
209+ nowrap,
210+ multiline,
211+ serif,
212+ hidden : ! ! hideText ,
213+ } ;
214+ } , [ nowrap , multiline , hideText , serif ] ) ;
215+
213216 const Snippet = (
214- < CopySnippetElement styles = { { preset : 'default' , ... styles } } { ...props } >
217+ < CopySnippetElement mods = { mods } { ...props } >
215218 < div data-element = "Grid" >
216- < StyledBlock
217- mods = { { nowrap, multiline, scroll : showScroll , serif } }
218- styles = { { padding } }
219- >
219+ < StyledBlock mods = { mods } >
220220 < PrismCode
221221 style = { { margin : 0 , overflow : 'visible' } }
222222 code = { formattedCode }
223223 language = { language || 'javascript' }
224224 />
225225 </ StyledBlock >
226- < ButtonContainer
227- styles = { { padding } as Styles }
228- mods = { { overlay : showOverlay } }
229- >
230- { actions }
226+ < ButtonContainer mods = { mods } >
227+ < CopyButton aria-label = { `Copy ${ title } ` } onPress = { onCopy } />
231228 { hideText && (
232229 < ShowButton
233230 icon = { showHidden ? < EyeInvisibleIcon /> : < EyeIcon /> }
234- mods = { { multiline, withScroll : showScroll } }
235231 onPress = { ( ) => setShowHidden ( ! showHidden ) }
236232 />
237233 ) }
238- < CopyButton
239- aria-label = { `Copy ${ title } ` }
240- mods = { { multiline, withScroll : showScroll , hidden : ! ! hideText } }
241- onPress = { onCopy }
242- />
234+ { actions }
243235 </ ButtonContainer >
244236 </ div >
245237 </ CopySnippetElement >
0 commit comments