Skip to content

Commit

Permalink
chore: Cloud Agent Info (#3420)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoscar committed Dec 4, 2023
1 parent d2efc8b commit 823b712
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
11 changes: 8 additions & 3 deletions web/src/components/CodeBlock/CodeBlock.styled.ts
Expand Up @@ -3,13 +3,13 @@ import styled from 'styled-components';

export const CodeContainer = styled.div<{$maxHeight: string; $minHeight: string}>`
position: relative;
border: ${({theme}) => `1px solid ${theme.color.border}`};
min-height: ${({$minHeight}) => $minHeight || '370px'};
pre {
margin: 0;
padding: 13px 16px !important;
min-height: inherit;
border: ${({theme}) => `1px solid ${theme.color.border}`};
max-height: ${({$maxHeight}) => $maxHeight || '340px'};
background: ${({theme}) => theme.color.background} !important;
Expand All @@ -19,7 +19,9 @@ export const CodeContainer = styled.div<{$maxHeight: string; $minHeight: string}
}
`;

export const FrameContainer = styled.div``;
export const FrameContainer = styled.div`
position: relative;
`;
export const FrameHeader = styled.div`
display: flex;
justify-content: space-between;
Expand All @@ -36,9 +38,12 @@ export const FrameTitle = styled(Typography.Paragraph)`
}
`;

export const CopyButton = styled(Button)`
export const CopyButton = styled(Button).attrs({
size: 'small',
})`
&& {
padding: 0 8px;
width: 80px;
background: ${({theme}) => theme.color.white};
font-weight: 600;
Expand Down
5 changes: 3 additions & 2 deletions web/src/components/CodeBlock/CodeBlock.tsx
Expand Up @@ -10,6 +10,7 @@ export interface IProps {
mimeType?: string;
maxHeight?: string;
minHeight?: string;
className?: string;
}

const getLanguage = (mimeType: string): LanguageName | undefined => {
Expand All @@ -32,7 +33,7 @@ const formatValue = (value: string, lang?: string): string => {
}
};

const CodeBlock = ({value, language, mimeType = '', maxHeight = '', minHeight = ''}: IProps) => {
const CodeBlock = ({value, language, mimeType = '', maxHeight = '', minHeight = '', className = ''}: IProps) => {
const lang = useMemo(() => language || getLanguage(mimeType), [language, mimeType]);

// SyntaxHighlighter has a performance problem, so we need to memoize it
Expand All @@ -47,7 +48,7 @@ const CodeBlock = ({value, language, mimeType = '', maxHeight = '', minHeight =
);

return (
<S.CodeContainer data-cy="code-block" $maxHeight={maxHeight} $minHeight={minHeight}>
<S.CodeContainer className={className} data-cy="code-block" $maxHeight={maxHeight} $minHeight={minHeight}>
{memoizedHighlighter}
</S.CodeContainer>
);
Expand Down
21 changes: 21 additions & 0 deletions web/src/components/CodeBlock/UrlCodeBlock.styled.ts
@@ -0,0 +1,21 @@
import styled from 'styled-components';
import DefaultCodeBlock from './CodeBlock';
import * as S from './CodeBlock.styled';

export const CodeBlock = styled(DefaultCodeBlock)`
&& {
pre {
padding: 5px 10px !important;
border-radius: 4px;
}
}
`;

export const CopyButton = styled(S.CopyButton)`
&& {
position: absolute;
top: 5px;
right: 15px;
z-index: 1;
}
`;
19 changes: 19 additions & 0 deletions web/src/components/CodeBlock/UrlCodeBlock.tsx
@@ -0,0 +1,19 @@
import * as S from './CodeBlock.styled';
import * as U from './UrlCodeBlock.styled';
import {IProps} from './CodeBlock';
import useCopy from '../../hooks/useCopy';

const UrlCodeBlock = ({...props}: IProps) => {
const copy = useCopy();

return (
<S.FrameContainer>
<U.CopyButton ghost type="primary" onClick={() => copy(props.value)}>
Copy
</U.CopyButton>
<U.CodeBlock {...props} />
</S.FrameContainer>
);
};

export default UrlCodeBlock;

0 comments on commit 823b712

Please sign in to comment.