|
| 1 | +import {useThemeValue} from '@gravity-ui/uikit'; |
| 2 | +import {materialLight, vscDarkPlus} from 'react-syntax-highlighter/dist/esm/styles/prism'; |
| 3 | + |
| 4 | +export const lightTransparent = { |
| 5 | + ...materialLight, |
| 6 | + 'pre[class*="language-"]': { |
| 7 | + ...materialLight['pre[class*="language-"]'], |
| 8 | + background: 'transparent', |
| 9 | + margin: 0, |
| 10 | + }, |
| 11 | + 'code[class*="language-"]': { |
| 12 | + ...materialLight['code[class*="language-"]'], |
| 13 | + background: 'transparent', |
| 14 | + color: 'var(--g-color-text-primary)', |
| 15 | + whiteSpace: 'pre-wrap' as const, |
| 16 | + }, |
| 17 | + comment: { |
| 18 | + color: '#969896', |
| 19 | + }, |
| 20 | + string: { |
| 21 | + color: '#a31515', |
| 22 | + }, |
| 23 | + tablepath: { |
| 24 | + color: '#338186', |
| 25 | + }, |
| 26 | + function: { |
| 27 | + color: '#7a3e9d', |
| 28 | + }, |
| 29 | + udf: { |
| 30 | + color: '#7a3e9d', |
| 31 | + }, |
| 32 | + type: { |
| 33 | + color: '#4d932d', |
| 34 | + }, |
| 35 | + boolean: { |
| 36 | + color: '#608b4e', |
| 37 | + }, |
| 38 | + constant: { |
| 39 | + color: '#608b4e', |
| 40 | + }, |
| 41 | + variable: { |
| 42 | + color: '#001188', |
| 43 | + }, |
| 44 | +}; |
| 45 | + |
| 46 | +export const darkTransparent = { |
| 47 | + ...vscDarkPlus, |
| 48 | + 'pre[class*="language-"]': { |
| 49 | + ...vscDarkPlus['pre[class*="language-"]'], |
| 50 | + background: 'transparent', |
| 51 | + margin: 0, |
| 52 | + }, |
| 53 | + 'code[class*="language-"]': { |
| 54 | + ...vscDarkPlus['code[class*="language-"]'], |
| 55 | + background: 'transparent', |
| 56 | + color: 'var(--g-color-text-primary)', |
| 57 | + whiteSpace: 'pre-wrap' as const, |
| 58 | + }, |
| 59 | + comment: { |
| 60 | + color: '#969896', |
| 61 | + }, |
| 62 | + string: { |
| 63 | + color: '#ce9178', |
| 64 | + }, |
| 65 | + tablepath: { |
| 66 | + color: '#338186', |
| 67 | + }, |
| 68 | + function: { |
| 69 | + color: '#9e7bb0', |
| 70 | + }, |
| 71 | + udf: { |
| 72 | + color: '#9e7bb0', |
| 73 | + }, |
| 74 | + type: { |
| 75 | + color: '#6A8759', |
| 76 | + }, |
| 77 | + boolean: { |
| 78 | + color: '#608b4e', |
| 79 | + }, |
| 80 | + constant: { |
| 81 | + color: '#608b4e', |
| 82 | + }, |
| 83 | + variable: { |
| 84 | + color: '#74b0df', |
| 85 | + }, |
| 86 | +}; |
| 87 | + |
| 88 | +const dark: Record<string, React.CSSProperties> = { |
| 89 | + ...darkTransparent, |
| 90 | + 'pre[class*="language-"]': { |
| 91 | + ...darkTransparent['pre[class*="language-"]'], |
| 92 | + background: vscDarkPlus['pre[class*="language-"]'].background, |
| 93 | + scrollbarColor: `var(--g-color-scroll-handle) transparent`, |
| 94 | + }, |
| 95 | + 'code[class*="language-"]': { |
| 96 | + ...darkTransparent['code[class*="language-"]'], |
| 97 | + whiteSpace: 'pre', |
| 98 | + }, |
| 99 | +}; |
| 100 | + |
| 101 | +const light: Record<string, React.CSSProperties> = { |
| 102 | + ...lightTransparent, |
| 103 | + 'pre[class*="language-"]': { |
| 104 | + ...lightTransparent['pre[class*="language-"]'], |
| 105 | + background: 'var(--g-color-base-misc-light)', |
| 106 | + scrollbarColor: `var(--g-color-scroll-handle) transparent`, |
| 107 | + }, |
| 108 | + 'code[class*="language-"]': { |
| 109 | + ...lightTransparent['code[class*="language-"]'], |
| 110 | + whiteSpace: 'pre', |
| 111 | + }, |
| 112 | +}; |
| 113 | + |
| 114 | +export function useSyntaxHighlighterStyle(transparentBackground?: boolean) { |
| 115 | + const themeValue = useThemeValue(); |
| 116 | + const isDark = themeValue === 'dark' || themeValue === 'dark-hc'; |
| 117 | + |
| 118 | + if (transparentBackground) { |
| 119 | + return isDark ? darkTransparent : lightTransparent; |
| 120 | + } |
| 121 | + |
| 122 | + return isDark ? dark : light; |
| 123 | +} |
0 commit comments