Commit 5616a3eb authored by tom goriunov's avatar tom goriunov Committed by GitHub

customize scroll bar in snippets (#1053)

* custom styles for scrollbar

* style scrollbar for search suggest on home page

* change overflow for search suggest

* fix error screen when API error payload is string

e.g. "Internal server error"

* add resizer img and styles for FF

* update screenshots

* update icon for dark theme
parent 7fee6df6
...@@ -2,7 +2,8 @@ import type { ResourceError } from 'lib/api/resources'; ...@@ -2,7 +2,8 @@ import type { ResourceError } from 'lib/api/resources';
import getErrorCause from './getErrorCause'; import getErrorCause from './getErrorCause';
export default function getResourceErrorPayload<Payload = Record<string, unknown>>(error: Error | undefined): ResourceError<Payload>['payload'] | undefined { export default function getResourceErrorPayload<Payload = Record<string, unknown> | string>(error: Error | undefined):
ResourceError<Payload>['payload'] | undefined {
const cause = getErrorCause(error); const cause = getErrorCause(error);
return cause && 'payload' in cause ? cause.payload as ResourceError<Payload>['payload'] : undefined; return cause && 'payload' in cause ? cause.payload as ResourceError<Payload>['payload'] : undefined;
} }
...@@ -58,10 +58,10 @@ const sizes = { ...@@ -58,10 +58,10 @@ const sizes = {
return { return {
fontSize: 'md', fontSize: 'md',
lineHeight: '24px', lineHeight: '24px',
padding: '28px 24px', padding: '28px 4px 28px 24px',
right: '26px', right: '22px',
_focusWithin: { _focusWithin: {
padding: '16px 24px 2px 24px', padding: '16px 0 2px 24px',
}, },
'&[data-fancy=true]': { '&[data-fancy=true]': {
right: '36px', right: '36px',
...@@ -76,10 +76,10 @@ const sizes = { ...@@ -76,10 +76,10 @@ const sizes = {
return { return {
fontSize: 'md', fontSize: 'md',
lineHeight: '20px', lineHeight: '20px',
padding: '18px 16px', padding: '18px 4px 18px 16px',
right: '18px', right: '22px',
_focusWithin: { _focusWithin: {
padding: '10px 16px 2px 16px', padding: '10px 0 2px 16px',
}, },
'&[data-fancy=true]': { '&[data-fancy=true]': {
right: '36px', right: '36px',
......
import { getCSSVar } from '@chakra-ui/styled-system';
import { mode } from '@chakra-ui/theme-tools';
import type { StyleFunctionProps } from '@chakra-ui/theme-tools';
const scrollbar = (props: StyleFunctionProps) => {
const bgColor = mode('blackAlpha.300', 'whiteAlpha.300')(props);
const resizerUrl = mode('url(/static/resizer_light.png)', 'url(/static/resizer_dark.png)')(props);
return {
'body *::-webkit-scrollbar': {
width: '20px',
},
'body *::-webkit-scrollbar-track': {
backgroundColor: 'transparent',
},
'body *::-webkit-scrollbar-thumb': {
backgroundColor: bgColor,
borderRadius: '20px',
border: `8px solid rgba(0,0,0,0)`,
backgroundClip: 'content-box',
minHeight: '32px',
},
'body *::-webkit-scrollbar-button': {
display: 'none',
},
'body *::-webkit-scrollbar-corner': {
backgroundColor: 'transparent',
},
'body *::-webkit-resizer': {
backgroundImage: resizerUrl,
backgroundSize: '20px',
},
'body *': {
scrollbarWidth: 'thin',
scrollbarColor: `${ getCSSVar(props.theme, 'colors', bgColor) } transparent`,
},
};
};
export default scrollbar;
import type { StyleFunctionProps } from '@chakra-ui/theme-tools'; import type { StyleFunctionProps } from '@chakra-ui/theme-tools';
import { mode } from '@chakra-ui/theme-tools'; import { mode } from '@chakra-ui/theme-tools';
import scrollbar from './foundations/scrollbar';
import getDefaultTransitionProps from './utils/getDefaultTransitionProps'; import getDefaultTransitionProps from './utils/getDefaultTransitionProps';
const global = (props: StyleFunctionProps) => ({ const global = (props: StyleFunctionProps) => ({
...@@ -21,6 +22,7 @@ const global = (props: StyleFunctionProps) => ({ ...@@ -21,6 +22,7 @@ const global = (props: StyleFunctionProps) => ({
form: { form: {
w: '100%', w: '100%',
}, },
...scrollbar(props),
}); });
export default global; export default global;
...@@ -39,7 +39,11 @@ const Page = ({ ...@@ -39,7 +39,11 @@ const Page = ({
const renderErrorScreen = React.useCallback((error?: Error) => { const renderErrorScreen = React.useCallback((error?: Error) => {
const statusCode = getErrorCauseStatusCode(error) || 500; const statusCode = getErrorCauseStatusCode(error) || 500;
const resourceErrorPayload = getResourceErrorPayload(error); const resourceErrorPayload = getResourceErrorPayload(error);
const messageInPayload = resourceErrorPayload && 'message' in resourceErrorPayload && typeof resourceErrorPayload.message === 'string' ? const messageInPayload =
resourceErrorPayload &&
typeof resourceErrorPayload === 'object' &&
'message' in resourceErrorPayload &&
typeof resourceErrorPayload.message === 'string' ?
resourceErrorPayload.message : resourceErrorPayload.message :
undefined; undefined;
...@@ -51,7 +55,11 @@ const Page = ({ ...@@ -51,7 +55,11 @@ const Page = ({
} }
if (isBlockConsensus) { if (isBlockConsensus) {
const hash = resourceErrorPayload && 'hash' in resourceErrorPayload && typeof resourceErrorPayload.hash === 'string' ? const hash =
resourceErrorPayload &&
typeof resourceErrorPayload === 'object' &&
'hash' in resourceErrorPayload &&
typeof resourceErrorPayload.hash === 'string' ?
resourceErrorPayload.hash : resourceErrorPayload.hash :
undefined; undefined;
return <PageContent isHomePage={ isHomePage }><AppErrorBlockConsensus hash={ hash } mt="50px"/></PageContent>; return <PageContent isHomePage={ isHomePage }><AppErrorBlockConsensus hash={ hash } mt="50px"/></PageContent>;
......
...@@ -128,14 +128,22 @@ const SearchBar = ({ isHomepage }: Props) => { ...@@ -128,14 +128,22 @@ const SearchBar = ({ isHomepage }: Props) => {
w={ `${ menuWidth.current }px` } w={ `${ menuWidth.current }px` }
ref={ menuRef } ref={ menuRef }
> >
<PopoverBody p={ 0 } color="chakra-body-text"> <PopoverBody
p={ 0 }
color="chakra-body-text"
sx={
isHomepage ? {
mark: { bgColor: 'green.100' },
'*::-webkit-scrollbar-thumb': { backgroundColor: 'blackAlpha.300' },
} : {}
}
>
<Box <Box
maxH="50vh" maxH="50vh"
overflowY="scroll" overflowY="auto"
id={ SCROLL_CONTAINER_ID } id={ SCROLL_CONTAINER_ID }
ref={ scrollRef } ref={ scrollRef }
as={ Element } as={ Element }
sx={ isHomepage ? { mark: { bgColor: 'green.100' } } : {} }
px={ 4 } px={ 4 }
> >
{ searchTerm.trim().length === 0 && recentSearchKeywords.length > 0 && ( { searchTerm.trim().length === 0 && recentSearchKeywords.length > 0 && (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment