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

[Refact/Fix] typescript styled components #219

Merged
merged 20 commits into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion packages/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"@testing-library/react-hooks": "^7.0.2",
"@types/lodash-es": "^4.17.5",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its the same

"@types/react-router-dom": "^5.3.1",
"@types/styled-components": "^5.1.15",
"@types/styled-components": "^5.1.25",
"babel-eslint": "^10.1.0",
"babel-plugin-styled-components": "^1.10.6",
"babel-plugin-transform-class-properties": "^6.24.1",
Expand Down
6 changes: 4 additions & 2 deletions packages/react-app/src/assets/quest-logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ type Props = {
animated?: boolean;
};

const DivStyled = styled.div`
const DivStyled = styled.div<{
animated?: boolean;
}>`
@keyframes textScale1 {
0% {
transform: scale(1);
Expand All @@ -18,7 +20,7 @@ const DivStyled = styled.div`
transform: scale(1);
}
}
${({ animated }: any) => animated && `animation: textScale1 1.15s infinite;`}
${({ animated }) => animated && `animation: textScale1 1.15s infinite;`}
margin-bottom: ${GUpx()};
`;

Expand Down
11 changes: 8 additions & 3 deletions packages/react-app/src/components/account/account-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ import HeaderModule from '../header/header-module';

// #region StyledComponents

const AccountButtonBackgroundStyled = styled.div`
interface AccountButtonBackgroundStyledProps {
background: any;
borderColor: any;
}

const AccountButtonBackgroundStyled = styled.div<AccountButtonBackgroundStyledProps>`
position: absolute;
bottom: -3px;
right: -3px;
width: 10px;
height: 10px;
background: ${({ background }: any) => background};
border: 2px solid ${({ borderColor }: any) => borderColor};
background: ${({ background }) => background};
border: 2px solid ${({ borderColor }) => borderColor};
border-radius: 50%;
`;

Expand Down
4 changes: 2 additions & 2 deletions packages/react-app/src/components/dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GU, useTheme, textStyle } from '@1hive/1hive-ui';
import { useTheme, textStyle } from '@1hive/1hive-ui';
import { useEffect, useState } from 'react';
import { ENUM_QUEST_VIEW_MODE } from 'src/constants';
import { DashboardModel } from 'src/models/dashboard.model';
Expand Down Expand Up @@ -52,7 +52,7 @@ export default function Dashboard() {
}, []);

return (
<BoxStyled padding={2 * GU} theme={theme}>
Corantin marked this conversation as resolved.
Show resolved Hide resolved
<BoxStyled theme={theme}>
<ChildSpacer justify="space-around" align="center">
<FieldInput
label={<LabelStyled>Bounty Pool</LabelStyled>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { TextInput, EthIdenticon, AddressField } from '@1hive/1hive-ui';

import { noop } from 'lodash-es';
import React from 'react';
import styled from 'styled-components';
import styled, { css } from 'styled-components';
import { FieldInput } from './field-input';

// #region Styled
Expand All @@ -19,10 +19,18 @@ const EthIdenticonStyled = styled(EthIdenticon)`
height: 38.4px;
`;

const WrapperStyled = styled.div`
interface WrapperStyledProps {
wide?: boolean;
}
const WrapperStyled = styled.div<WrapperStyledProps>`
display: flex;
flex-wrap: nowrap;
${(props: any) => (props.wide ? 'width:100%;' : '')}
${(props) =>
props.wide &&
css`
width: 100%;
`}

max-width: 100%;
input {
cursor: default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ const TokenBadgeStyled = styled(TokenBadge)`
width: fit-content;
`;

const AutoCompleteWrapperStyled = styled.div`
const AutoCompleteWrapperStyled = styled.div<{ wide?: boolean }>`
flex-grow: 3;
input {
& + div {
pointer-events: none;
${({ wide }: any) => (wide ? 'justify-content: end;' : '')}
${({ wide }) => (wide ? 'justify-content: end;' : '')}
}
}
ul[role='listbox'] {
Expand All @@ -60,13 +60,16 @@ const LineStyled = styled.div`
display: flex;
justify-content: space-between;
`;

const AmountTokenWrapperStyled = styled.div`
interface AmountTokenWrapperStyledProps {
isEdit?: boolean;
wide?: boolean;
}
const AmountTokenWrapperStyled = styled.div<AmountTokenWrapperStyledProps>`
display: flex;
justify-content: flex-end;
align-items: center;
${({ wide, isEdit }: any) => (wide && isEdit ? '' : `padding-right:${GUpx()};`)}
${({ wide }: any) => (wide ? `width:100%;` : 'max-width:100%;')}
${({ wide, isEdit }) => (wide && isEdit ? '' : `padding-right:${GUpx()};`)}
${({ wide }) => (wide ? `width:100%;` : 'max-width:100%;')}
`;

const IconEditStyled = styled(IconEdit)`
Expand Down
32 changes: 23 additions & 9 deletions packages/react-app/src/components/field-input/date-field-input.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
import { useTheme } from '@1hive/1hive-ui';
import { connect } from 'formik';
import { noop } from 'lodash-es';
import { CSSProperties, ReactNode } from 'react';
import { CSSProperties, FocusEventHandler, ReactNode } from 'react';
import { GUpx, isDarkTheme } from 'src/utils/style.util';
import styled from 'styled-components';
import styled, { css as _css } from 'styled-components';
Corantin marked this conversation as resolved.
Show resolved Hide resolved
import { addTime, dateFormat, ONE_HOUR_IN_MS } from '../../utils/date.utils';
import { FieldInput } from './field-input';

// #region StyledComponents

const InputStyled = styled.input`
${(props: any) => (props.wide ? 'width:100%;' : '')}
border: 1px solid ${(props: any) => props.borderColor};
const InputStyled = styled.input<{
borderColor?: string;
focusBorderColor?: string;
background?: string;
wide?: boolean;
isDarkTheme?: boolean;
Corantin marked this conversation as resolved.
Show resolved Hide resolved
}>`
${(props: any) =>
props.wide &&
_css`
width: 100%;
`}
border: 1px solid ${(props) => props.borderColor};
border-radius: 12px;
background-color: ${({ background }: any) => background};
background-color: ${({ background }) => background};
height: 40px;
padding: ${GUpx()};
font-size: 14px;
&:focus-visible {
border: 1px solid ${(props: any) => props.focusBorderColor};
border: 1px solid ${(props) => props.focusBorderColor};
outline: none;
}
&::-webkit-calendar-picker-indicator {
${(props: any) => (props.isDarkTheme ? 'filter: invert();' : '')};
${(props) =>
props.isDarkTheme &&
_css`
filter: invert();
`};
}
`;

Expand All @@ -41,7 +55,7 @@ type Props = {
compact?: boolean;
wide?: boolean;
formik?: any;
onBlur?: Function;
onBlur?: FocusEventHandler<HTMLInputElement> & Function;
error?: string | false;
};

Expand Down
27 changes: 19 additions & 8 deletions packages/react-app/src/components/field-input/field-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ import { GUpx } from 'src/utils/style.util';
import styled from 'styled-components';
import { IconTooltip } from './icon-tooltip';

const FieldStyled = styled.div`
${({ compact }: any) => (!compact ? `margin-bottom:${GUpx(1)}` : '')};
${({ isLoading, wide }: any) => (isLoading || wide ? `width: 100%;` : 'max-width: 100%;')};
const FieldStyled = styled.div<{
compact?: boolean;
isLoading?: boolean;
wide?: boolean;
}>`
${({ compact }) => (!compact ? `margin-bottom:${GUpx(1)}` : '')};
${({ isLoading, wide }) => (isLoading || wide ? `width: 100%;` : 'max-width: 100%;')};
`;

const ErrorStyled = styled.span`
color: ${(props: any) => props.theme.negative};
font-size: small;
margin-left: ${GUpx(2)};
font-style: italic;
`;

const LabelStyled = styled.label`
color: ${(props: any) => props.color};
font-size: 12px;
Expand All @@ -33,16 +39,21 @@ const LineStyled = styled.div`
margin-top: ${GUpx(0.5)};
`;

const ContentWrapperStyled = styled.div`
const ContentWrapperStyled = styled.div<{
compact?: boolean;
wide?: boolean;
align: string;
direction: string;
}>`
display: flex;
align-items: ${({ align }: any) => align};
${(props: any) => (!props.compact ? 'min-height: 45px;' : '')}
align-items: ${({ align }) => align};
${(props) => (!props.compact ? 'min-height: 45px;' : '')}
& > div {
input {
${({ wide }: any) => (wide ? `max-width:none;` : '')}
${({ wide }) => (wide ? `max-width:none;` : '')}
}
}
flex-direction: ${({ direction }: any) => direction};
flex-direction: ${({ direction }) => direction};
padding-left: ${GUpx(0.5)};
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { FieldInput } from './field-input';

// #region Styled

const MaxLineStyled = styled.div`
const MaxLineStyled = styled.div<{ maxLine: number }>`
margin-bottom: ${GUpx()};
display: -webkit-box;
-webkit-line-clamp: ${(props: any) => props.maxLine};
-webkit-line-clamp: ${(props) => props.maxLine};
-webkit-box-orient: vertical;
overflow: hidden;
overflow-wrap: anywhere;
Expand All @@ -21,8 +21,8 @@ const MaxLineStyled = styled.div`
}
`;

const BlockStyled = styled.div`
${({ wide }: any) => wide && 'width: 100%;'}
const BlockStyled = styled.div<{ wide?: boolean }>`
${({ wide }) => wide && 'width: 100%;'}
`;

// #endregion
Expand Down
33 changes: 23 additions & 10 deletions packages/react-app/src/components/filter.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, SearchInput, DropDown, useTheme, useViewport } from '@1hive/1hive-ui';
import { useFilterContext } from 'src/contexts/filter.context';
import { GUpx } from 'src/utils/style.util';
import styled from 'styled-components';
import styled, { css } from 'styled-components';
import { DEFAULT_FILTER, ENUM_QUEST_STATE } from '../constants';
import DateFieldInput from './field-input/date-field-input';
import { FieldInput } from './field-input/field-input';
Expand All @@ -12,23 +12,36 @@ const StatusDropdownStyled = styled(DropDown)`
border: 1px solid ${(props: any) => props.borderColor};
`;

const FilterWrapperStyled = styled.div`
const FilterWrapperStyled = styled.div<{
colDisplay?: boolean;
isSmallResolution?: boolean;
}>`
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
flex-wrap: ${({ colDisplay }: any) => (colDisplay ? 'wrap' : 'no-wrap')};

flex-wrap: ${({ colDisplay }) => (colDisplay ? 'wrap' : 'no-wrap')};

padding: 0 ${GUpx(2)};
${({ isSmallResolution }: any) =>

${({ isSmallResolution }) =>
isSmallResolution
? `
margin-right: 20px;
padding-bottom: ${GUpx(2)};
`
: 'height:80px;'} // Size of scrollbar because parent is 100% + 20px
? css`
margin-right: 20px;
padding-bottom: ${GUpx(2)};
`
: css`
height: 80px;
`} // Size of scrollbar because parent is 100% + 20px

// Each filter having a sibling
& > div + div {
${({ isSmallResolution }: any) => !isSmallResolution && `margin-left: ${GUpx()};`}
${({ isSmallResolution }) =>
!isSmallResolution &&
css`
margin-left: ${GUpx()};
`}
}
`;

Expand Down
6 changes: 3 additions & 3 deletions packages/react-app/src/components/footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import QuestModal from './modals/quest-modal';

// #region StyledComponent

const FooterContainerStyled = styled.div`
const FooterContainerStyled = styled.div<{ color: string }>`
margin: auto;
box-shadow: rgb(0 0 0 / 5%) 3px -2px 0px;
display: flex;
flex-wrap: wrap;
justify-content: space-between;

a {
color: ${({ color }: any) => color} !important;
color: ${({ color }) => color} !important;
}

padding: ${GUpx(8)};
Expand Down Expand Up @@ -83,7 +83,7 @@ export default function footer() {
const year = new Date().getFullYear();

return (
<FooterContainerStyled background={theme.surface} color={theme.contentSecondary}>
Corantin marked this conversation as resolved.
Show resolved Hide resolved
<FooterContainerStyled color={theme.contentSecondary}>
<FooterContainerStyledSide>
<FooterColumnStyled>
<TitleLinkStyled href="#" external={false}>
Expand Down
3 changes: 2 additions & 1 deletion packages/react-app/src/components/header/header-title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { noop } from 'lodash';
import { Link } from 'react-router-dom';
import { GUpx } from 'src/utils/style.util';
import styled from 'styled-components';
import { MouseEventHandler } from 'react';
import { ENUM_PAGES } from '../../constants';
import { LogoTitle } from '../../assets/logo-title';

Expand All @@ -22,7 +23,7 @@ const TitleLinkWrapperStyled = styled.div`
// #endregion

type Props = {
onClick?: Function;
onClick?: MouseEventHandler<HTMLAnchorElement>;
};

export default function HeaderTitle({ onClick = noop }: Props) {
Expand Down
9 changes: 6 additions & 3 deletions packages/react-app/src/components/main-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ const HeaderWrapperStyled = styled.div`
width: 100%;
`;

const ContentWrapperStyled = styled.div`
padding: ${({ isSmallResolution }: any) => (isSmallResolution ? GUpx() : GUpx(4))};
const ContentWrapperStyled = styled.div<{
isSmallResolution?: boolean;
top?: number;
}>`
padding: ${({ isSmallResolution }) => (isSmallResolution ? GUpx() : GUpx(4))};
`;

const ScrollViewStyled = styled.div`
Expand Down Expand Up @@ -89,7 +92,7 @@ function MainView({ children }: Props) {
)}
</Header>
</HeaderWrapperStyled>
<ScrollViewStyled id="scroll-view" theme={currentTheme} isSmallResolution={below('medium')}>
Corantin marked this conversation as resolved.
Show resolved Hide resolved
<ScrollViewStyled id="scroll-view" theme={currentTheme}>
<ContentWrapperStyled
isSmallResolution={below('medium')}
top={headerRef.current?.clientHeight}
Expand Down