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

🪟 🎨 🧹 Migrate Card component to SCSS and refactor #16407

Merged
merged 23 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import styled from "styled-components";

import ContentCard from "components/ContentCard";
import { Card } from "components/base/Card";

const PaddedCard = styled(ContentCard)`
const PaddedCard = styled(Card)`
width: 100%;
max-width: 600px;
margin-bottom: 8px;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@use "../../scss/colors";

.lightContentCard {
display: flex;
justify-content: space-between;
align-items: center;
flex-direction: row;
padding: 20px 21px 19px;
margin-bottom: 12px;
}

.arrow {
font-size: 29px;
line-height: 29px;
color: colors.$blue-500;
}

.extraBlock {
background: none;
}
35 changes: 8 additions & 27 deletions airbyte-webapp/src/components/ConnectionBlock/ConnectionBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,23 @@
import { faChevronRight } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import classNames from "classnames";
import React from "react";
import styled from "styled-components";

import ContentCard from "../ContentCard";
import { Card } from "../base/Card";
import { ConnectionBlockItem, Content } from "./components/ConnectionBlockItem";
import styles from "./ConnectionBlock.module.scss";

interface IProps {
className?: string;
itemFrom?: { name: string; icon?: string };
itemTo?: { name: string; icon?: string };
}

const LightContentCard = styled(ContentCard)`
display: flex;
justify-content: space-between;
align-items: center;
flex-direction: row;
padding: 20px 21px 19px;
margin-bottom: 12px;
`;

const Arrow = styled(FontAwesomeIcon)`
font-size: 29px;
line-height: 29px;
color: ${({ theme }) => theme.primaryColor};
`;

const ExtraBlock = styled(Content)`
background: none;
`;

const ConnectionBlock: React.FC<IProps> = (props) => (
<LightContentCard className={props.className}>
{props.itemFrom ? <ConnectionBlockItem {...props.itemFrom} /> : <ExtraBlock />}
<Arrow icon={faChevronRight} />
{props.itemTo ? <ConnectionBlockItem {...props.itemTo} /> : <ExtraBlock />}
</LightContentCard>
<Card className={classNames(styles.lightContentCard)}>
{props.itemFrom ? <ConnectionBlockItem {...props.itemFrom} /> : <Content className={styles.extraBlock} />}
<FontAwesomeIcon className={styles.arrow} icon={faChevronRight} />
{props.itemTo ? <ConnectionBlockItem {...props.itemTo} /> : <Content className={styles.extraBlock} />}
</Card>
);

export default ConnectionBlock;
34 changes: 0 additions & 34 deletions airbyte-webapp/src/components/ContentCard/ContentCard.tsx

This file was deleted.

16 changes: 0 additions & 16 deletions airbyte-webapp/src/components/ContentCard/index.stories.tsx

This file was deleted.

4 changes: 0 additions & 4 deletions airbyte-webapp/src/components/ContentCard/index.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import React, { Suspense, useMemo } from "react";
import { FormattedMessage } from "react-intl";

import { Button, ContentCard } from "components";
import { Button, Card } from "components";
import { IDataItem } from "components/base/DropDown/components/Option";
import { JobItem } from "components/JobItem/JobItem";
import LoadingSchema from "components/LoadingSchema";
Expand Down Expand Up @@ -90,10 +90,10 @@ const CreateConnectionContent: React.FC<CreateConnectionContentProps> = ({
if (schemaErrorStatus) {
const job = LogsRequestError.extractJobInfo(schemaErrorStatus);
return (
<ContentCard>
<Card>
<TryAfterErrorBlock onClick={onDiscoverSchema} />
{job && <JobItem job={job} />}
</ContentCard>
</Card>
);
}

Expand Down
5 changes: 3 additions & 2 deletions airbyte-webapp/src/components/DeleteBlock/DeleteBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import { FormattedMessage } from "react-intl";
import styled from "styled-components";

import { Button, H5 } from "components";
import ContentCard from "components/ContentCard";

import { useConfirmationModalService } from "hooks/services/ConfirmationModal";
import useRouter from "hooks/useRouter";

import { Card } from "../base/Card";

interface IProps {
type: "source" | "destination" | "connection";
onDelete: () => Promise<unknown>;
}

const DeleteBlockComponent = styled(ContentCard)`
const DeleteBlockComponent = styled(Card)`
margin-top: 12px;
padding: 19px 20px 20px;
display: flex;
Expand Down
7 changes: 3 additions & 4 deletions airbyte-webapp/src/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { Dialog } from "@headlessui/react";
import classNames from "classnames";
import React, { useState } from "react";

import ContentCard from "components/ContentCard";

import { Card } from "../base/Card";
import styles from "./Modal.module.scss";

export interface ModalProps {
Expand Down Expand Up @@ -38,9 +37,9 @@ const Modal: React.FC<ModalProps> = ({ children, title, size, onClose, clear, te
{clear ? (
children
) : (
<ContentCard title={title} className={classNames(styles.card, size ? cardStyleBySize[size] : undefined)}>
<Card title={title} className={classNames(styles.card, size ? cardStyleBySize[size] : undefined)}>
{children}
</ContentCard>
</Card>
)}
</Dialog.Panel>
</div>
Expand Down
34 changes: 34 additions & 0 deletions airbyte-webapp/src/components/base/Card/Card.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
@use "../../../scss/colors";

.container {
width: auto;
background: colors.$white;
border-radius: 10px;
box-shadow: 0 2px 4px colors.$cardShadowColor;

&.fullWidth {
width: 100%;
}

&.withPadding {
padding: 20px;
}
}

.title {
padding: 25px 25px 22px;
color: colors.$dark-blue;
border-bottom: #e8e8ed 1px solid;
font-weight: 600;
letter-spacing: 0.008em;
border-top-left-radius: 10px;
border-top-right-radius: 10px;

&.lightPadding {
padding: 19px 20px 20px;
}

&.roundedBottom {
border-radius: 10px;
}
}
56 changes: 47 additions & 9 deletions airbyte-webapp/src/components/base/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,48 @@
import styled from "styled-components";
import classNames from "classnames";
import React from "react";

export const Card = styled.div<{ full?: boolean; $withPadding?: boolean }>`
width: ${({ full }) => (full ? "100%" : "auto")};
background: ${({ theme }) => theme.whiteColor};
border-radius: 10px;
box-shadow: 0 2px 4px ${({ theme }) => theme.cardShadowColor};
padding: ${({ $withPadding }) => ($withPadding ? "20px" : undefined)};
//border: 1px solid ${({ theme }) => theme.greyColor20};
`;
import { H5 } from "../Titles";
import styles from "./Card.module.scss";

export interface CardProps {
title?: React.ReactNode;
className?: string;
fullWidth?: boolean;
lightPadding?: boolean;
withPadding?: boolean;
roundedBottom?: boolean;
}

export const Card: React.FC<CardProps> = ({
children,
title,
className,
fullWidth,
lightPadding,
withPadding,
roundedBottom,
}) => {
return (
<div
className={classNames(
className,
styles.container,
fullWidth ? styles.fullWidth : undefined,
withPadding ? styles.withPadding : undefined
)}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
className={classNames(
className,
styles.container,
fullWidth ? styles.fullWidth : undefined,
withPadding ? styles.withPadding : undefined
)}
className={classNames(className, styles.container, {
[styles.fullWidth]: fullWidth,
[styles.withPadding]: withPadding,
})}

>
{title ? (
<H5
className={classNames(
styles.title,
lightPadding || !children ? styles.lightPadding : undefined,
roundedBottom ? styles.roundedBottom : undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

Repeat above object pattern here 👍

)}
>
{title}
</H5>
) : null}
{children}
</div>
);
};
1 change: 0 additions & 1 deletion airbyte-webapp/src/components/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export * from "./base";

export * from "./ArrayOfObjectsEditor";
export * from "./ContentCard";
export * from "./CodeEditor";
export * from "./DefaultLogoCatalog";
export * from "./ImageBlock";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FormattedMessage, useIntl } from "react-intl";
import styled from "styled-components";

import BarChart from "components/BarChart";
import ContentCard from "components/ContentCard";
import { Card } from "components/base/Card";

import { useCurrentWorkspace } from "hooks/services/useWorkspace";
import { useGetUsage } from "packages/cloud/services/workspaces/WorkspacesService";
Expand All @@ -16,7 +16,7 @@ export const ChartWrapper = styled.div`
padding: 0 50px 24px 0;
`;

const CardBlock = styled(ContentCard)`
const CardBlock = styled(Card)`
margin: 10px 0 20px;
`;

Expand Down Expand Up @@ -51,7 +51,7 @@ const CreditsUsage: React.FC = () => {

return (
<>
<ContentCard title={<FormattedMessage id="credits.totalUsage" />} light>
<Card title={<FormattedMessage id="credits.totalUsage" />} lightPadding>
<ChartWrapper>
{data?.creditConsumptionByDay?.length ? (
<BarChart
Expand All @@ -70,9 +70,9 @@ const CreditsUsage: React.FC = () => {
</Empty>
)}
</ChartWrapper>
</ContentCard>
</Card>

<CardBlock title={<FormattedMessage id="credits.usagePerConnection" />} light>
<CardBlock title={<FormattedMessage id="credits.usagePerConnection" />} lightPadding>
{data?.creditConsumptionByConnector?.length ? (
<UsagePerConnectionTable creditConsumption={data.creditConsumptionByConnector} />
) : (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
$white: #fff;
$shadowColor: rgb(26 25 77 / 12%);

.button {
padding: 20px 28px 20px 20px;
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
cursor: pointer;
width: 100%;
background: $white;
border-radius: 10px;
box-shadow: 0 2px 4px $shadowColor;
border: none;
}

.iconColor {
color: #615eff;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

All these free-standing colors make me a touch nervous. Are we sure these colors can't come from _colors.scss?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I might have missed this one, sorry! I was having trouble importing _colors.scss in a few places, will go back and check.

Copy link
Contributor

@krishnaglick krishnaglick Sep 9, 2022

Choose a reason for hiding this comment

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

If you continue to have issues with it, feel free to shoot me a ping! @use is a little weird at first :)

Edit: Looks like you got it figured out 👍

Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
import { faChevronRight } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import React from "react";
import styled from "styled-components";

import { H5, ContentCard } from "components";
import { H5 } from "components";

const Item = styled(ContentCard)`
padding: 20px 28px 20px 20px;
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
cursor: pointer;
`;

const Arrow = styled(FontAwesomeIcon)`
color: ${({ theme }) => theme.primaryColor};
`;
import styles from "./WorkspaceItem.module.scss";

const WorkspaceItem: React.FC<{ onClick: (id: string) => void; id: string }> = (props) => (
<Item onClick={() => props.onClick(props.id)}>
<button className={styles.button} onClick={() => props.onClick(props.id)}>
<H5 bold>{props.children}</H5>
<Arrow icon={faChevronRight} />
</Item>
<FontAwesomeIcon className={styles.iconColor} icon={faChevronRight} />
</button>
);

export default WorkspaceItem;
Loading