-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adjust companion to new designs (#3650)
* adjust first components to new designs * feat: adjust input alignment * feat: adjusted code panels, implemented syntax highlighting * temporarily uninstall packages * reinstall packages * directly use ui5 color for styling messages * feat: add copy to clipboard functionality * fix: adjust disclaimer
- Loading branch information
Showing
15 changed files
with
688 additions
and
108 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 14 additions & 14 deletions
28
src/components/KymaCompanion/components/Chat/messages/CodePanel.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
.code-response { | ||
background-color: #484848; | ||
color: white; | ||
background-color: var(--sapBaseColor); | ||
padding: 0.75rem; | ||
border-radius: 4px; | ||
position: relative; | ||
|
||
.text { | ||
color: white; | ||
#copy-icon { | ||
position: absolute; | ||
top: 0.5rem; | ||
right: 0.75rem; | ||
} | ||
|
||
#code-text { | ||
white-space: pre-wrap; | ||
} | ||
} | ||
|
||
.code-panel::part(header) { | ||
background-color: #484848; | ||
color: white; | ||
background-color: var(--sapBaseColor); | ||
border-radius: 4px 4px 0 0; | ||
font-size: 0.9rem; | ||
padding: 0.5rem 0.75rem !important; | ||
} | ||
|
||
.code-panel::part(content) { | ||
background-color: #484848; | ||
background-color: var(--sapBaseColor); | ||
border-radius: 0 0 4px 4px; | ||
} | ||
|
||
.code-panel { | ||
.text { | ||
color: white; | ||
} | ||
padding: 0; | ||
} |
85 changes: 80 additions & 5 deletions
85
src/components/KymaCompanion/components/Chat/messages/CodePanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,95 @@ | ||
import { Text, Panel } from '@ui5/webcomponents-react'; | ||
import { Text, Panel, Title, Icon, FlexBox } from '@ui5/webcomponents-react'; | ||
import { formatCodeSegment } from 'components/KymaCompanion/utils/formatMarkdown'; | ||
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { | ||
isCurrentThemeDark, | ||
Theme, | ||
themeState, | ||
} from 'state/preferences/themeAtom'; | ||
import copyToCliboard from 'copy-to-clipboard'; | ||
import './CodePanel.scss'; | ||
|
||
function getCustomTheme(theme: Theme) { | ||
const isDark = isCurrentThemeDark(theme); | ||
const monacoEditorKeyColorLight = '#008080'; | ||
const monacoEditorKeyColorDark = '#3dc9b0'; | ||
const monacoEditorTextColorLight = '#0451a5'; | ||
const monacoEditorTextColorDark = '#ce9178'; | ||
|
||
return { | ||
'code[class*="language-"]': { | ||
color: isDark ? monacoEditorTextColorDark : monacoEditorTextColorLight, | ||
background: 'var(--sapBaseColor)', | ||
fontFamily: 'var(--sapFontFamily)', | ||
fontSize: '14px', | ||
}, | ||
'pre[class*="language-"]': { | ||
background: 'var(--sapBaseColor)', | ||
padding: '0 0.75rem', | ||
margin: '0.5rem 0', | ||
borderRadius: '8px', | ||
}, | ||
comment: { | ||
color: isDark ? 'var(--sapLinkColor)' : monacoEditorTextColorDark, | ||
}, | ||
keyword: { | ||
color: isDark ? monacoEditorKeyColorDark : monacoEditorKeyColorLight, | ||
}, | ||
key: { | ||
color: isDark ? monacoEditorKeyColorDark : monacoEditorKeyColorLight, | ||
}, | ||
punctuation: { | ||
color: 'var(--sapTextColor)', | ||
}, | ||
operator: { color: 'var(--sapTextColor)' }, | ||
function: { color: 'var(--sapChart_OrderedColor_4)' }, | ||
number: { | ||
color: 'var(--sapChart_OrderedColor_4)', | ||
}, | ||
}; | ||
} | ||
|
||
interface CodePanelProps { | ||
text: string; | ||
} | ||
|
||
export default function CodePanel({ text }: CodePanelProps): JSX.Element { | ||
const theme = useRecoilValue(themeState); | ||
const syntaxTheme = getCustomTheme(theme); | ||
const { language, code } = formatCodeSegment(text); | ||
return !language ? ( | ||
<div className="code-response"> | ||
<Text className="text">{code}</Text> | ||
<div className="code-response sap-margin-y-small"> | ||
<Icon | ||
id="copy-icon" | ||
mode="Interactive" | ||
name="copy" | ||
design="Information" | ||
onClick={() => copyToCliboard(code)} | ||
/> | ||
<Text id="code-text">{code}</Text> | ||
</div> | ||
) : ( | ||
<Panel headerText={language} className="code-panel" fixed> | ||
<Text className="text">{code}</Text> | ||
<Panel | ||
className="code-panel sap-margin-y-small" | ||
header={ | ||
<FlexBox alignItems="Center" fitContainer justifyContent="SpaceBetween"> | ||
<Title level="H6" size="H6"> | ||
{language} | ||
</Title> | ||
<Icon | ||
mode="Interactive" | ||
name="copy" | ||
design="Information" | ||
onClick={() => copyToCliboard(code)} | ||
/> | ||
</FlexBox> | ||
} | ||
fixed | ||
> | ||
<SyntaxHighlighter language={language} style={syntaxTheme} wrapLongLines> | ||
{code} | ||
</SyntaxHighlighter> | ||
</Panel> | ||
); | ||
} |
Oops, something went wrong.