Skip to content

chore(): add className to root components in design system, disable t… #200

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

Merged
merged 2 commits into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"only-arrow-functions": false,
"prettier": true,
"react-hooks-nesting": "error",
"import-name": false
"import-name": false,
"jsx-no-lambda:": false
Copy link
Member

Choose a reason for hiding this comment

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

I would keep this for better error tracing and also you don't create a new function each time the element gets rendered

Copy link
Member

@kenshyx kenshyx Nov 1, 2019

Choose a reason for hiding this comment

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

also

Creating new anonymous functions (with either the function syntax or ES2015 arrow syntax) inside the render call stack works against pure component rendering. When doing an equality check between two lambdas, React will always consider them unequal values and force the component to re-render more often than necessary.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

for passing props to a handler in a loop there is no solution that is more efficient, but only for that use case I could disable that rule on that line only, and keep it as a general rule true
discussion about it here:
palantir/tslint-react#96

Copy link
Member

Choose a reason for hiding this comment

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

yes, use disable next-line if there is no other option but keep it on as a general rule :D

},
"rulesDirectory": ["tslint-plugin-prettier"]
}
5 changes: 3 additions & 2 deletions ui/design/src/components/Cards/apps-widget-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SubtitleTextIcon, TextIcon } from '../TextIcon/index';
import { BasicCardBox } from './index';

export interface IAppsWidgetCardProps {
className?: string;
onClick: React.EventHandler<React.SyntheticEvent>;
margin?: MarginInterface;
label: string;
Expand All @@ -22,10 +23,10 @@ export interface IAppsData {
}

const AppsWidgetCard: React.FC<IAppsWidgetCardProps> = props => {
const { onClick, margin, iconType, label, labelColor, dataSource } = props;
const { className, onClick, margin, iconType, label, labelColor, dataSource } = props;

return (
<BasicCardBox>
<BasicCardBox className={className}>
<Box pad="medium" gap="medium">
<TextIcon
iconType={iconType}
Expand Down
4 changes: 3 additions & 1 deletion ui/design/src/components/Cards/entry-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IEntryData } from './entry-box';
import { BasicCardBox, EntryBox } from './index';

export interface IEntryCardProps {
className?: string;
entryData: IEntryData;
onClickAvatar: React.EventHandler<React.SyntheticEvent>;
onClickUpvote: React.EventHandler<React.SyntheticEvent>;
Expand All @@ -26,6 +27,7 @@ export interface IEntryCardProps {

const EntryCard: React.FC<IEntryCardProps> = props => {
const {
className,
entryData,
onClickAvatar,
onClickDownvote,
Expand All @@ -47,7 +49,7 @@ const EntryCard: React.FC<IEntryCardProps> = props => {
} = props;

return (
<BasicCardBox>
<BasicCardBox className={className}>
<EntryBox
entryData={entryData}
onClickAvatar={onClickAvatar}
Expand Down
4 changes: 3 additions & 1 deletion ui/design/src/components/Cards/profile-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface IProfileData {
}

export interface IProfileCardProps {
className?: string;
onClickApps: React.EventHandler<React.SyntheticEvent>;
onClickFollowing: React.EventHandler<React.SyntheticEvent>;
margin?: MarginInterface;
Expand All @@ -45,6 +46,7 @@ export interface IProfileCardProps {

const ProfileCard: React.FC<IProfileCardProps> = props => {
const {
className,
onClickFollowing,
onClickApps,
profileData,
Expand All @@ -63,7 +65,7 @@ const ProfileCard: React.FC<IProfileCardProps> = props => {
const rightSubtitle = profileData.profileType === 'dapp' ? actionsTitle : appsTitle;

return (
<BasicCardBox>
<BasicCardBox className={className}>
<Box
height="144px"
background={profileData.coverImage}
Expand Down
3 changes: 2 additions & 1 deletion ui/design/src/components/IconButton/icon-button.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react';
import StyledIconButton from './styled-icon-button';
interface IIconButtonProps {
className?: string;
icon: React.ReactElement;
label: string;
onClick?: () => void;
Expand All @@ -9,7 +10,7 @@ interface IIconButtonProps {
}

const IconButton = (props: IIconButtonProps) => {
return <StyledIconButton {...props} />;
return <StyledIconButton className={props.className} {...props} />;
};

export default IconButton;
3 changes: 2 additions & 1 deletion ui/design/src/components/IconButton/icon-link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import StyledIconLink from './styled-icon-link';

interface LinkIconButtonProps {
className?: string;
onClick: React.EventHandler<React.SyntheticEvent>;
iconPosition?: 'start' | 'end';
icon: React.ReactElement;
Expand All @@ -11,7 +12,7 @@ interface LinkIconButtonProps {
const LinkIconButton = (props: LinkIconButtonProps) => {
const { iconPosition = 'start', ...other } = props;
const reversed = iconPosition && iconPosition === 'end';
return <StyledIconLink reverse={reversed} {...other} />;
return <StyledIconLink className={props.className} reverse={reversed} {...other} />;
};

export default LinkIconButton;
4 changes: 3 additions & 1 deletion ui/design/src/components/IconButton/vote-icon-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Icon } from '../Icon';
import StyledIconButton from './styled-icon-button';

interface IVoteIconProps {
className?: string;
voteType: 'upvote' | 'downvote';
voteCount: number | string;
onClick: any;
Expand All @@ -14,11 +15,12 @@ const StyledVoteIconButton = styled(StyledIconButton)`
box-sizing: border-box;
`;
const VoteIconButton = (props: IVoteIconProps) => {
const { voteType, voteCount, onClick, voted } = props;
const { className, voteType, voteCount, onClick, voted } = props;
const iconType = voteType === 'upvote' ? 'thumbsUpWhite' : 'thumbsDownWhite';

return (
<StyledVoteIconButton
className={className}
reverse={true}
label={`${voteCount}`}
icon={<Icon type={iconType} />}
Expand Down
5 changes: 3 additions & 2 deletions ui/design/src/components/Input/comment-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Avatar } from '../Avatar/index';
import { Icon } from '../Icon/index';

interface ICommentInput {
className?: string;
avatarImg: any;
placeholderTitle: string;
publishTitle: string;
Expand All @@ -23,7 +24,7 @@ const StyledDiv = styled.div`
`;

const CommentInput: React.FC<ICommentInput> = props => {
const { avatarImg, placeholderTitle, onPublish, publishTitle } = props;
const { avatarImg, className, placeholderTitle, onPublish, publishTitle } = props;
const [inputValue, setInputValue] = useState('');
const [textAreaOpen, setTextAreaOpen] = useState(false);

Expand Down Expand Up @@ -109,7 +110,7 @@ const CommentInput: React.FC<ICommentInput> = props => {
};

return (
<Box direction="row" gap="xsmall" fill="horizontal" pad="none">
<Box direction="row" gap="xsmall" fill="horizontal" pad="none" className={className}>
<div>
<Avatar src={avatarImg} size="md" roundedCorners={true} />
</div>
Expand Down
4 changes: 3 additions & 1 deletion ui/design/src/components/Input/search-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Icon } from '../Icon/index';
import { StyledDrop, StyledSelectBox } from './styled-search-input';

interface ICustomSearchInput {
className?: string;
getData: () => void;
dataSource: any;
placeholder: string;
Expand All @@ -13,7 +14,7 @@ interface ICustomSearchInput {
}

const SearchInput: React.FC<ICustomSearchInput> = props => {
const { dataSource, placeholder, usersTitle, tagsTitle, appsTitle, getData } = props;
const { className, dataSource, placeholder, usersTitle, tagsTitle, appsTitle, getData } = props;
const [inputValue, setInputValue] = useState('');
const [dropOpen, setDropOpen] = useState(false);
const [suggestions, setSuggestions] = useState<any>({ users: [], tags: [], apps: [] });
Expand Down Expand Up @@ -172,6 +173,7 @@ const SearchInput: React.FC<ICustomSearchInput> = props => {
side: 'all',
color: 'border',
}}
className={className}
>
<Icon type="search" />
<TextInput
Expand Down
4 changes: 3 additions & 1 deletion ui/design/src/components/Popovers/basic-popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import * as React from 'react';
import { StyledDrop } from './styled-drop';

interface IBasicPopover {
className?: string;
children: any;
closePopover: () => {};
target: React.RefObject<any>;
gap?: string;
}

const BasicPopover: React.FC<IBasicPopover> = ({ children, ...props }) => {
const { target, closePopover, gap } = props;
const { className, target, closePopover, gap } = props;
return (
<StyledDrop
overflow="hidden"
Expand All @@ -18,6 +19,7 @@ const BasicPopover: React.FC<IBasicPopover> = ({ children, ...props }) => {
align={{ top: 'bottom', right: 'left' }}
onClickOutside={closePopover}
onEsc={closePopover}
className={className}
>
{children}
</StyledDrop>
Expand Down
5 changes: 3 additions & 2 deletions ui/design/src/components/Popovers/notifications-popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import BasicPopover from './basic-popover';
import { StyledListContainer, StyledListElem } from './styled-drop';

interface INotificationsPopover {
className?: string;
onClickNotification: () => void;
dataSource: INotification[];
target: React.RefObject<any>;
Expand All @@ -19,9 +20,9 @@ interface INotification {
}

const NotificationsPopover: React.FC<INotificationsPopover> = props => {
const { closePopover, dataSource, onClickNotification, target } = props;
const { className, closePopover, dataSource, onClickNotification, target } = props;
return (
<BasicPopover closePopover={closePopover} target={target} gap={'-5px'}>
<BasicPopover closePopover={closePopover} target={target} gap={'-5px'} className={className}>
<StyledListContainer pad={{ vertical: 'small', horizontal: 'xxsmall' }} overflow="scroll">
{dataSource &&
dataSource.map((notification, index) => (
Expand Down
4 changes: 3 additions & 1 deletion ui/design/src/components/TextIcon/subtitle-text-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IconType } from '../Icon/icon';
import { IconDiv, StyledBox } from './styled-subtitle-text-icon';

interface ISubtitleTextIcon {
className?: string;
iconType?: IconType;
iconSize?: string;
label: string;
Expand All @@ -18,6 +19,7 @@ interface ISubtitleTextIcon {

const SubtitleTextIcon: React.FC<ISubtitleTextIcon> = props => {
const {
className,
iconType,
iconSize,
label,
Expand All @@ -30,7 +32,7 @@ const SubtitleTextIcon: React.FC<ISubtitleTextIcon> = props => {
} = props;

return (
<StyledBox direction="row" justify="center" onClick={onClick}>
<StyledBox direction="row" justify="center" onClick={onClick} className={className}>
{iconType ? (
<IconDiv iconSize={iconSize}>
<Icon type={iconType} />
Expand Down
3 changes: 3 additions & 0 deletions ui/design/src/components/TextIcon/text-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IconType } from '../Icon/icon';
import { StyledText, StyledTextIcon } from './styled-text-icon';

export interface ITextIconProps {
className?: string;
onClick?: React.EventHandler<React.SyntheticEvent>;
margin?: MarginInterface;
backgroundColor?: string;
Expand Down Expand Up @@ -35,6 +36,7 @@ const actionTypeIcons: {

const TextIcon: React.FC<ITextIconProps> = props => {
const {
className,
onClick,
margin,
backgroundColor,
Expand All @@ -58,6 +60,7 @@ const TextIcon: React.FC<ITextIconProps> = props => {
iconType={iconType}
spacing={spacing}
clickable={clickable}
className={className}
>
<Icon type={actionTypeIcons[actionType]} color={color} />
<StyledText bold={bold}>{actionType}</StyledText>
Expand Down
36 changes: 27 additions & 9 deletions ui/design/src/components/Topbar/topbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const AvatarButton = styled(ProfileAvatarButton)`
`;

interface ITopbarProps {
className?: string;
avatarImage: string;
userName: string;
brandLabel: string | React.ReactElement;
Expand All @@ -27,6 +28,7 @@ const Topbar = (props: ITopbarProps) => {
const {
avatarImage,
brandLabel,
className,
userName,
unreadNotifications,
notificationsData,
Expand All @@ -35,16 +37,37 @@ const Topbar = (props: ITopbarProps) => {
} = props;
const notificationIconRef: React.Ref<any> = React.useRef();
const walletIconRef: React.Ref<any> = React.useRef();

const [notificationsOpen, setNotificationsOpen] = React.useState(false);
const [walletOpen, setWalletOpen] = React.useState(false);

const handleNavigation = (path: string) => (ev: React.SyntheticEvent) => {
if (onNavigation) {
onNavigation(path);
}
};

const handleNotifClick = () => {
setNotificationsOpen(!notificationsOpen);
};

const handleWalletClick = () => {
setWalletOpen(!walletOpen);
};

const closePopover = () => {
setNotificationsOpen(false);
};

return (
<Box direction="row" pad="small" justify="between" align="center" fill={true}>
<Box
direction="row"
pad="small"
justify="between"
align="center"
fill={true}
className={className}
>
<Box direction="row">{brandLabel}</Box>
<Box direction="row">
<Box
Expand All @@ -53,24 +76,19 @@ const Topbar = (props: ITopbarProps) => {
justify="center"
margin={{ horizontal: 'xsmall' }}
>
<Icon
type="notifications"
onClick={() => setNotificationsOpen(!notificationsOpen)}
clickable={true}
default={true}
/>
<Icon type="notifications" onClick={handleNotifClick} clickable={true} default={true} />
</Box>

{notificationIconRef.current && notificationsOpen && notificationsData && (
<NotificationsPopover
target={notificationIconRef.current}
dataSource={notificationsData}
onClickNotification={onNotificationClick}
closePopover={() => setNotificationsOpen(false)}
closePopover={closePopover}
/>
)}
<Box ref={walletIconRef} align="center" justify="center" margin="xsmall">
<Icon type="wallet" onClick={() => setWalletOpen(!walletOpen)} clickable={true} />
<Icon type="wallet" onClick={handleWalletClick} clickable={true} />
</Box>

<Box pad={{ left: 'xsmall' }}>
Expand Down