Feat/272 syntax highlighter from explorer to ui-toolkit and feat/216 added light theme and feat/283 add to token (#286)
* Moved syntax highlighter from explorer to ui-toolkit * Update libs/ui-toolkit/src/components/syntax-highlighter/syntax-highlighter.stories.tsx Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com> * Added a light theme for syntax highlighter, added the styling for syntax highlighter to our custom classes * Suboptimal but successful way of ensuring styling is applied to syntax highlighter * Styling syntax highlighter with scss * Fix failing test * Back to applying styling via custom plugin, but with a wrapper on the syntax highlighter ensuring Tailwind doesn't cull the classes * Preferred class name * prettier formatting Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com> Co-authored-by: Joe <joe@vega.xyz>
This commit is contained in:
parent
de4c5499b9
commit
2b910aa04c
@ -53,7 +53,7 @@ export default class TransactionsPage extends BasePage {
|
|||||||
.each(($propertyName) => {
|
.each(($propertyName) => {
|
||||||
cy.wrap($propertyName).should('not.be.empty');
|
cy.wrap($propertyName).should('not.be.empty');
|
||||||
});
|
});
|
||||||
cy.get('span[style*="color"]')
|
cy.get('.hljs-string')
|
||||||
.should('have.length.at.least', 8)
|
.should('have.length.at.least', 8)
|
||||||
.each(($propertyValue) => {
|
.each(($propertyValue) => {
|
||||||
cy.wrap($propertyValue).should('not.be.empty');
|
cy.wrap($propertyValue).should('not.be.empty');
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
import Highlighter from 'react-syntax-highlighter';
|
|
||||||
|
|
||||||
const vegaJsonTheme = {
|
|
||||||
hljs: {
|
|
||||||
fontSize: '1rem',
|
|
||||||
fontFamily: "Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace",
|
|
||||||
display: 'block',
|
|
||||||
overflowX: 'auto',
|
|
||||||
padding: '1em',
|
|
||||||
color: '#26ff8a',
|
|
||||||
background: '#2C2C2C',
|
|
||||||
border: '1px solid #696969',
|
|
||||||
},
|
|
||||||
'hljs-literal': {
|
|
||||||
color: '#ff2d5e',
|
|
||||||
},
|
|
||||||
'hljs-number': {
|
|
||||||
color: '#ff7a1a',
|
|
||||||
},
|
|
||||||
'hljs-string': {
|
|
||||||
color: '#48aff0',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const SyntaxHighlighter = ({ data }: { data: unknown }) => {
|
|
||||||
return (
|
|
||||||
<Highlighter language="json" style={vegaJsonTheme}>
|
|
||||||
{JSON.stringify(data, null, ' ')}
|
|
||||||
</Highlighter>
|
|
||||||
);
|
|
||||||
};
|
|
@ -3,7 +3,7 @@ import { t } from '@vegaprotocol/react-helpers';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { RouteTitle } from '../../components/route-title';
|
import { RouteTitle } from '../../components/route-title';
|
||||||
import { SubHeading } from '../../components/sub-heading';
|
import { SubHeading } from '../../components/sub-heading';
|
||||||
import { SyntaxHighlighter } from '../../components/syntax-highlighter';
|
import { SyntaxHighlighter } from '@vegaprotocol/ui-toolkit';
|
||||||
import type { AssetsQuery } from './__generated__/AssetsQuery';
|
import type { AssetsQuery } from './__generated__/AssetsQuery';
|
||||||
|
|
||||||
export const ASSETS_QUERY = gql`
|
export const ASSETS_QUERY = gql`
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { t } from '@vegaprotocol/react-helpers';
|
import { t } from '@vegaprotocol/react-helpers';
|
||||||
import { RouteTitle } from '../../components/route-title';
|
import { RouteTitle } from '../../components/route-title';
|
||||||
import { SyntaxHighlighter } from '../../components/syntax-highlighter';
|
import { SyntaxHighlighter } from '@vegaprotocol/ui-toolkit';
|
||||||
import { DATA_SOURCES } from '../../config';
|
import { DATA_SOURCES } from '../../config';
|
||||||
import useFetch from '../../hooks/use-fetch';
|
import useFetch from '../../hooks/use-fetch';
|
||||||
import type { TendermintGenesisResponse } from './tendermint-genesis-response';
|
import type { TendermintGenesisResponse } from './tendermint-genesis-response';
|
||||||
|
@ -3,7 +3,7 @@ import { t } from '@vegaprotocol/react-helpers';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { RouteTitle } from '../../components/route-title';
|
import { RouteTitle } from '../../components/route-title';
|
||||||
import { SubHeading } from '../../components/sub-heading';
|
import { SubHeading } from '../../components/sub-heading';
|
||||||
import { SyntaxHighlighter } from '../../components/syntax-highlighter';
|
import { SyntaxHighlighter } from '@vegaprotocol/ui-toolkit';
|
||||||
import type {
|
import type {
|
||||||
ProposalsQuery,
|
ProposalsQuery,
|
||||||
ProposalsQuery_proposals_terms_change,
|
ProposalsQuery_proposals_terms_change,
|
||||||
|
@ -2,7 +2,7 @@ import { gql, useQuery } from '@apollo/client';
|
|||||||
import type { MarketsQuery } from './__generated__/MarketsQuery';
|
import type { MarketsQuery } from './__generated__/MarketsQuery';
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { SyntaxHighlighter } from '../../components/syntax-highlighter';
|
import { SyntaxHighlighter } from '@vegaprotocol/ui-toolkit';
|
||||||
import { RouteTitle } from '../../components/route-title';
|
import { RouteTitle } from '../../components/route-title';
|
||||||
import { SubHeading } from '../../components/sub-heading';
|
import { SubHeading } from '../../components/sub-heading';
|
||||||
import { t } from '@vegaprotocol/react-helpers';
|
import { t } from '@vegaprotocol/react-helpers';
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { gql, useQuery } from '@apollo/client';
|
import { gql, useQuery } from '@apollo/client';
|
||||||
import { RouteTitle } from '../../components/route-title';
|
import { RouteTitle } from '../../components/route-title';
|
||||||
import type { NetworkParametersQuery } from './__generated__/NetworkParametersQuery';
|
import type { NetworkParametersQuery } from './__generated__/NetworkParametersQuery';
|
||||||
import { SyntaxHighlighter } from '../../components/syntax-highlighter';
|
import { SyntaxHighlighter } from '@vegaprotocol/ui-toolkit';
|
||||||
import { t } from '@vegaprotocol/react-helpers';
|
import { t } from '@vegaprotocol/react-helpers';
|
||||||
|
|
||||||
export const NETWORK_PARAMETERS_QUERY = gql`
|
export const NETWORK_PARAMETERS_QUERY = gql`
|
||||||
|
@ -5,7 +5,7 @@ import React from 'react';
|
|||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import { RouteTitle } from '../../../components/route-title';
|
import { RouteTitle } from '../../../components/route-title';
|
||||||
import { SubHeading } from '../../../components/sub-heading';
|
import { SubHeading } from '../../../components/sub-heading';
|
||||||
import { SyntaxHighlighter } from '../../../components/syntax-highlighter';
|
import { SyntaxHighlighter } from '@vegaprotocol/ui-toolkit';
|
||||||
import { DATA_SOURCES } from '../../../config';
|
import { DATA_SOURCES } from '../../../config';
|
||||||
import useFetch from '../../../hooks/use-fetch';
|
import useFetch from '../../../hooks/use-fetch';
|
||||||
import type { TendermintSearchTransactionResponse } from '../tendermint-transaction-response';
|
import type { TendermintSearchTransactionResponse } from '../tendermint-transaction-response';
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { t } from '@vegaprotocol/react-helpers';
|
import { t } from '@vegaprotocol/react-helpers';
|
||||||
import { StatusMessage } from '../../../components/status-message';
|
import { StatusMessage } from '../../../components/status-message';
|
||||||
import { SyntaxHighlighter } from '../../../components/syntax-highlighter';
|
import { SyntaxHighlighter } from '@vegaprotocol/ui-toolkit';
|
||||||
import {
|
import {
|
||||||
TableWithTbody,
|
TableWithTbody,
|
||||||
TableCell,
|
TableCell,
|
||||||
|
@ -3,7 +3,7 @@ import { t } from '@vegaprotocol/react-helpers';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { RouteTitle } from '../../components/route-title';
|
import { RouteTitle } from '../../components/route-title';
|
||||||
import { SubHeading } from '../../components/sub-heading';
|
import { SubHeading } from '../../components/sub-heading';
|
||||||
import { SyntaxHighlighter } from '../../components/syntax-highlighter';
|
import { SyntaxHighlighter } from '@vegaprotocol/ui-toolkit';
|
||||||
import { DATA_SOURCES } from '../../config';
|
import { DATA_SOURCES } from '../../config';
|
||||||
import useFetch from '../../hooks/use-fetch';
|
import useFetch from '../../hooks/use-fetch';
|
||||||
import type { TendermintValidatorsResponse } from './tendermint-validator-response';
|
import type { TendermintValidatorsResponse } from './tendermint-validator-response';
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
@import '../../styles/colors';
|
@import '../../styles/colors';
|
||||||
|
|
||||||
.nav {
|
.nav {
|
||||||
padding: 20px;
|
|
||||||
padding: 10px !important;
|
padding: 10px !important;
|
||||||
border-bottom: 1px solid $white;
|
border-bottom: 1px solid $white;
|
||||||
position: sticky;
|
position: sticky;
|
||||||
|
@ -1 +0,0 @@
|
|||||||
export { SyntaxHighlighter } from './syntax-highlighter';
|
|
@ -1,11 +0,0 @@
|
|||||||
import { render, screen } from '@testing-library/react';
|
|
||||||
|
|
||||||
import { SyntaxHighlighter } from './syntax-highlighter';
|
|
||||||
|
|
||||||
it('Renders test id and content', () => {
|
|
||||||
const data = {};
|
|
||||||
render(<SyntaxHighlighter data={data} />);
|
|
||||||
expect(screen.getByTestId('syntax-highlighter')).toHaveTextContent(
|
|
||||||
JSON.stringify(data, null, 2)
|
|
||||||
);
|
|
||||||
});
|
|
@ -1,36 +0,0 @@
|
|||||||
// TODO: Move to ui-toolkit https://github.com/vegaprotocol/frontend-monorepo/issues/272
|
|
||||||
import Highlighter from 'react-syntax-highlighter';
|
|
||||||
|
|
||||||
const vegaJsonTheme = {
|
|
||||||
hljs: {
|
|
||||||
fontSize: '1rem',
|
|
||||||
fontFamily: "Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace",
|
|
||||||
display: 'block',
|
|
||||||
overflowX: 'auto',
|
|
||||||
padding: '1em',
|
|
||||||
color: '#26ff8a',
|
|
||||||
background: '#2C2C2C',
|
|
||||||
border: '1px solid #696969',
|
|
||||||
},
|
|
||||||
'hljs-literal': {
|
|
||||||
color: '#ff2d5e',
|
|
||||||
},
|
|
||||||
'hljs-number': {
|
|
||||||
color: '#ff7a1a',
|
|
||||||
},
|
|
||||||
'hljs-string': {
|
|
||||||
color: '#48aff0',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export const SyntaxHighlighter = ({ data }: { data: object }) => {
|
|
||||||
return (
|
|
||||||
<Highlighter
|
|
||||||
language="json"
|
|
||||||
style={vegaJsonTheme}
|
|
||||||
data-testid="syntax-highlighter"
|
|
||||||
>
|
|
||||||
{JSON.stringify(data, null, 2)}
|
|
||||||
</Highlighter>
|
|
||||||
);
|
|
||||||
};
|
|
@ -19,8 +19,7 @@ export const useEthereumConfig = () => {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const [configJson] = ethereumConfigJSON;
|
const [configJson] = ethereumConfigJSON;
|
||||||
const config = JSON.parse(configJson);
|
return JSON.parse(configJson);
|
||||||
return config;
|
|
||||||
} catch {
|
} catch {
|
||||||
Sentry.captureMessage('Ethereum config JSON is invalid');
|
Sentry.captureMessage('Ethereum config JSON is invalid');
|
||||||
return null;
|
return null;
|
||||||
|
@ -5,9 +5,7 @@ import { useContracts } from '../contexts/contracts/contracts-context';
|
|||||||
export const usePendingTransactions = () => {
|
export const usePendingTransactions = () => {
|
||||||
const { transactions } = useContracts();
|
const { transactions } = useContracts();
|
||||||
|
|
||||||
const pending = React.useMemo(() => {
|
return React.useMemo(() => {
|
||||||
return transactions.some((tx) => tx.pending);
|
return transactions.some((tx) => tx.pending);
|
||||||
}, [transactions]);
|
}, [transactions]);
|
||||||
|
|
||||||
return pending;
|
|
||||||
};
|
};
|
||||||
|
@ -10,7 +10,7 @@ export function useRefreshAssociatedBalances() {
|
|||||||
const { appDispatch } = useAppState();
|
const { appDispatch } = useAppState();
|
||||||
const { staking, vesting } = useContracts();
|
const { staking, vesting } = useContracts();
|
||||||
|
|
||||||
const refresh = React.useCallback(
|
return React.useCallback(
|
||||||
async (ethAddress: string, vegaKey: string) => {
|
async (ethAddress: string, vegaKey: string) => {
|
||||||
const [walletAssociatedBalance, vestingAssociatedBalance] =
|
const [walletAssociatedBalance, vestingAssociatedBalance] =
|
||||||
await Promise.all([
|
await Promise.all([
|
||||||
@ -26,6 +26,4 @@ export function useRefreshAssociatedBalances() {
|
|||||||
},
|
},
|
||||||
[staking, vesting, appDispatch]
|
[staking, vesting, appDispatch]
|
||||||
);
|
);
|
||||||
|
|
||||||
return refresh;
|
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,7 @@ const IgnoreCodes = {
|
|||||||
* and thus not capture in Sentry
|
* and thus not capture in Sentry
|
||||||
*/
|
*/
|
||||||
export const isUnexpectedError = (error: Error | TxError) => {
|
export const isUnexpectedError = (error: Error | TxError) => {
|
||||||
if ('code' in error && Object.values(IgnoreCodes).includes(error.code)) {
|
return !('code' in error && Object.values(IgnoreCodes).includes(error.code));
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,10 +25,7 @@ export const isUnexpectedError = (error: Error | TxError) => {
|
|||||||
* a transaction confirmation prompt
|
* a transaction confirmation prompt
|
||||||
*/
|
*/
|
||||||
export const isUserRejection = (error: Error | TxError) => {
|
export const isUserRejection = (error: Error | TxError) => {
|
||||||
if ('code' in error && error.code === IgnoreCodes.USER_REJECTED) {
|
return 'code' in error && error.code === IgnoreCodes.USER_REJECTED;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,8 +33,5 @@ export const isUserRejection = (error: Error | TxError) => {
|
|||||||
* a transaction confirmation prompt
|
* a transaction confirmation prompt
|
||||||
*/
|
*/
|
||||||
export const isAlreadyProcessing = (error: Error | TxError) => {
|
export const isAlreadyProcessing = (error: Error | TxError) => {
|
||||||
if ('code' in error && error.code === IgnoreCodes.ALREADY_PROCESSING) {
|
return 'code' in error && error.code === IgnoreCodes.ALREADY_PROCESSING;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Trans, useTranslation } from 'react-i18next';
|
import { Trans, useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import { Colors } from '../../config/colors';
|
import { Colors } from '../../config';
|
||||||
|
|
||||||
interface TargetAddressMismatchProps {
|
interface TargetAddressMismatchProps {
|
||||||
connectedAddress: string;
|
connectedAddress: string;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { SyntaxHighlighter } from '../../../../components/syntax-highlighter';
|
import { SyntaxHighlighter } from '@vegaprotocol/ui-toolkit';
|
||||||
import type { RestProposalResponse } from '../../proposal/proposal-container';
|
import type { RestProposalResponse } from '../../proposal/proposal-container';
|
||||||
|
|
||||||
export const ProposalTermsJson = ({
|
export const ProposalTermsJson = ({
|
||||||
|
@ -75,6 +75,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&__set_to {
|
&__set_to {
|
||||||
margin-bottom: 0px;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,34 @@
|
|||||||
const plugin = require('tailwindcss/plugin');
|
const plugin = require('tailwindcss/plugin');
|
||||||
|
const theme = require('./theme');
|
||||||
|
|
||||||
const vegaCustomClasses = plugin(function ({ addUtilities }) {
|
const vegaCustomClasses = plugin(function ({ addUtilities }) {
|
||||||
addUtilities({
|
addUtilities({
|
||||||
'.calt': {
|
'.calt': {
|
||||||
fontFeatureSettings: "'calt'",
|
fontFeatureSettings: "'calt'",
|
||||||
},
|
},
|
||||||
|
'.syntax-highlighter-wrapper .hljs': {
|
||||||
|
fontSize: '1rem',
|
||||||
|
fontFamily: "Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace",
|
||||||
|
display: 'block',
|
||||||
|
overflowX: 'auto',
|
||||||
|
padding: '1em',
|
||||||
|
background: theme.colors.white.DEFAULT,
|
||||||
|
color: theme.colors.intent.help,
|
||||||
|
border: '1px solid #696969',
|
||||||
|
},
|
||||||
|
'.dark .syntax-highlighter-wrapper .hljs': {
|
||||||
|
background: '#2C2C2C',
|
||||||
|
color: theme.colors.vega.green,
|
||||||
|
},
|
||||||
|
'.syntax-highlighter-wrapper .hljs-literal': {
|
||||||
|
color: theme.colors.vega.pink,
|
||||||
|
},
|
||||||
|
'.syntax-highlighter-wrapper .hljs-number': {
|
||||||
|
color: theme.colors.intent.warning,
|
||||||
|
},
|
||||||
|
'.syntax-highlighter-wrapper .hljs-string': {
|
||||||
|
color: theme.colors.blue,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
export * from './syntax-highlighter';
|
@ -0,0 +1,14 @@
|
|||||||
|
import { render, screen } from '@testing-library/react';
|
||||||
|
|
||||||
|
import { SyntaxHighlighter } from './syntax-highlighter';
|
||||||
|
|
||||||
|
describe('Syntax highlighter', () => {
|
||||||
|
it('should render data successfully', () => {
|
||||||
|
const testData = {
|
||||||
|
name: 'test of highlighter',
|
||||||
|
};
|
||||||
|
|
||||||
|
render(<SyntaxHighlighter data={testData} />);
|
||||||
|
expect(screen.getByText('"test of highlighter"')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,20 @@
|
|||||||
|
import type { Story, Meta } from '@storybook/react';
|
||||||
|
import { SyntaxHighlighter } from './syntax-highlighter';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
component: SyntaxHighlighter,
|
||||||
|
title: 'Syntax Highlighter',
|
||||||
|
} as Meta;
|
||||||
|
|
||||||
|
const data = {
|
||||||
|
name: 'Level one',
|
||||||
|
undefinedProp: undefined,
|
||||||
|
nullProp: null,
|
||||||
|
level: 1,
|
||||||
|
nestedData: {
|
||||||
|
name: 'Level two',
|
||||||
|
level: 2,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Default: Story = () => <SyntaxHighlighter data={data} />;
|
@ -0,0 +1,11 @@
|
|||||||
|
import Highlighter from 'react-syntax-highlighter';
|
||||||
|
|
||||||
|
export const SyntaxHighlighter = ({ data }: { data: unknown }) => {
|
||||||
|
return (
|
||||||
|
<div className="syntax-highlighter-wrapper">
|
||||||
|
<Highlighter language="json" useInlineStyles={false}>
|
||||||
|
{JSON.stringify(data, null, ' ')}
|
||||||
|
</Highlighter>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
@ -21,6 +21,7 @@ export { VegaLogo } from './components/vega-logo';
|
|||||||
export { Tooltip } from './components/tooltip';
|
export { Tooltip } from './components/tooltip';
|
||||||
export { Indicator } from './components/indicator';
|
export { Indicator } from './components/indicator';
|
||||||
export { Card } from './components/card';
|
export { Card } from './components/card';
|
||||||
|
export { SyntaxHighlighter } from './components/syntax-highlighter';
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
export * from './utils/intent';
|
export * from './utils/intent';
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
const { join } = require('path');
|
const { join } = require('path');
|
||||||
const { createGlobPatternsForDependencies } = require('@nrwl/next/tailwind');
|
const { createGlobPatternsForDependencies } = require('@nrwl/next/tailwind');
|
||||||
const theme = require('../tailwindcss-config/src/theme');
|
const theme = require('../tailwindcss-config/src/theme');
|
||||||
|
const vegaCustomClasses = require('../tailwindcss-config/src/vega-custom-classes');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
content: [
|
content: [
|
||||||
@ -12,5 +13,5 @@ module.exports = {
|
|||||||
theme: {
|
theme: {
|
||||||
extend: theme,
|
extend: theme,
|
||||||
},
|
},
|
||||||
plugins: [],
|
plugins: [vegaCustomClasses],
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user