Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Cloud Agent Info #3420

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions web/src/components/CodeBlock/CodeBlock.styled.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;