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

feat: replace style-components with emotion #41

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SPACEX_URL=https://spacex-production.up.railway.app/
SPACEX_URL=https://spacex-production.up.railway.app/
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
SPACEX_URL=https://spacex-production.up.railway.app/

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
node-version: [18.x]

steps:
- uses: actions/checkout@v2
Expand Down
15 changes: 12 additions & 3 deletions .stylelintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
{
"processors": ["stylelint-processor-styled-components"],
"extends": [
"stylelint-config-recommended",
"stylelint-config-styled-components"
"stylelint-config-recommended"
],
"overrides": [
{
"files": [
"**/*.js"
],
"customSyntax": "@stylelint/postcss-css-in-js",
"rules": {
"string-quotes": "single"
}
}
]
}
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,18 @@ An enterprise react template application showcasing - Testing strategies, Global
- [app/utils/graphqlUtils.ts](app/utils/graphqlUtils.ts)
- [app/containers/HomeContainer/saga.ts](app/containers/HomeContainer/saga.ts)

## Styling using styled-components
## Styling using emotion

- Styling components using [Styled Components](https://styled-components.com)
- Styling components using [Emotion](https://emotion.sh/)

Take a look at the following files

- [app/components/T/index.tsx](app/components/T/index.tsx)
- [app/containers/HomeContainer/index.tsx](app/containers/HomeContainer/index.tsx)

## Using antd as the component library
## Using Material UI as the component library

- Reusing components from [Ant design](https://ant.design)
- Reusing components from [Material UI](https://mui.com)

Take a look at the following files

Expand Down Expand Up @@ -201,7 +201,6 @@ An enterprise react template application showcasing - Testing strategies, Global
- [app/services/tests/repoApi.test.ts](app/services/tests/repoApi.test.ts)
- [app/components/T/tests/index.test.tsx](app/components/T/tests/index.test.tsx)


## Misc

### Aliasing
Expand Down
2 changes: 1 addition & 1 deletion app/components/Clickable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import styled from '@emotion/styled';
import T from '@components/T';

const StyledClickable = styled.div`
Expand Down
17 changes: 15 additions & 2 deletions app/components/Clickable/tests/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Clickable /> component tests should render and match the snapshot 1`] = `
.emotion-0 {
color: #1890ff;
}

.emotion-0:hover {
cursor: pointer;
}

.emotion-2.emotion-2 {
font-size: 1rem;
font-weight: normal;
}

<body>
<div>
<div
class="Clickable__StyledClickable-sc-1vn3tbu-0 mgTtM"
class="emotion-0 emotion-1"
data-testid="clickable"
>
<p
class="T__StyledText-znbtqz-0 TmgHn"
class="emotion-2 emotion-3"
data-testid="t"
>
List of launches
Expand Down
8 changes: 5 additions & 3 deletions app/components/ErrorHandler/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { Card } from 'antd';
import styled from '@emotion/styled';
import { Card } from '@mui/material';
import { T, If } from '@components';

const CustomCard = styled(Card)`
&& {
margin: 20px 0;
padding: 20px;
padding-top: 0;
color: ${(props) => props.color};
}
`;
Expand All @@ -20,7 +22,7 @@ export function ErrorHandler({ loading, launchListError }: ErrorHandlerTypes) {
if (!loading) {
return (
<If condition={launchListError} otherwise={<T data-testid="default-message" id={launchListError} />}>
<CustomCard data-testid="error-card">
<CustomCard data-testid="error-card" variant="outlined">
<T data-testid="error-message" text={launchListError} />
</CustomCard>
</If>
Expand Down
37 changes: 27 additions & 10 deletions app/components/ErrorHandler/tests/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<ErrorHandler /> should render and match the snapshot 1`] = `
.emotion-1 {
background-color: #fff;
color: rgba(0, 0, 0, 0.87);
-webkit-transition: box-shadow 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
transition: box-shadow 300ms cubic-bezier(0.4, 0, 0.2, 1) 0ms;
border-radius: 4px;
border: 1px solid rgba(0, 0, 0, 0.12);
overflow: hidden;
}

.emotion-1.emotion-1 {
margin: 20px 0;
padding: 20px;
padding-top: 0;
}

.emotion-2.emotion-2 {
font-size: 1rem;
font-weight: normal;
}

<body>
<div>
<div
class="ant-card ant-card-bordered ErrorHandler__CustomCard-sc-1rh55w4-0 eOLbNC"
class="MuiPaper-root MuiPaper-outlined MuiPaper-rounded MuiCard-root emotion-0 emotion-1"
data-testid="error-card"
>
<div
class="ant-card-body"
<p
class="emotion-2 emotion-3"
data-testid="error-message"
>
<p
class="T__StyledText-znbtqz-0 TmgHn"
data-testid="error-message"
>
something_went_wrong
</p>
</div>
something_went_wrong
</p>
</div>
</div>
</body>
Expand Down
2 changes: 1 addition & 1 deletion app/components/For/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React, { PropsWithChildren } from 'react';
import Proptypes from 'prop-types';
import styled from 'styled-components';
import styled from '@emotion/styled';
import { Property } from 'csstype';

type FlexContainerProps = {
Expand Down
48 changes: 24 additions & 24 deletions app/components/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,24 @@
*
*/
import React from 'react';
import { Layout } from 'antd';
import styled from 'styled-components';
import { fonts, colors, media } from '@themes/index';
import styled from '@emotion/styled';
import { AppBar, Toolbar } from '@mui/material';
import { Link } from 'react-router-dom';
import { fonts, colors } from '@themes/index';
import T from '@components/T';
import logo from '@images/icon-512x512.png';
import { Link } from 'react-router-dom';

const StyledHeader = styled(Layout.Header)`
const StyledHeader = styled(AppBar)`
&& {
&.ant-layout-header {
padding: 0 1rem;
height: ${(props) => props.theme.headerHeight};
align-items: center;
justify-content: center;
background-color: ${colors.primary};
gap: 1rem;
${media.lessThan('mobile')`
padding-left: ${(props) => props.theme.sidebarWidth}
`}
}
padding: 0 1rem;
height: ${({ theme }: any) => theme.baseLayout.headerHeight};
align-items: center;
justify-content: center;
background-color: ${colors.primary};
gap: 1rem;
${({ theme }: any) => `${theme.breakpoints.down('sm')} {
padding-left: ${({ theme }: any) => theme.baseLayout.sidebarWidth};
}`};
display: flex;
}
`;
Expand All @@ -32,14 +30,14 @@ const Logo = styled.img`
height: 5rem;
width: auto;
object-fit: contain;
${media.lessThan('tablet')`
${({ theme }: any) => `${theme.breakpoints.down('sm')} {
height: 4rem;
`}
}`};
`;

const Title = styled(T)`
&& {
margin-bottom: 0;
margin: 0;
${fonts.dynamicFontSize(fonts.size.xRegular, 1, 0.5)};
display: flex;
align-self: center;
Expand All @@ -49,11 +47,13 @@ const Title = styled(T)`

const Header: React.FC = () => {
return (
<StyledHeader data-testid="header">
<Link to="/">
<Logo alt="logo" src={logo} />
</Link>
<Title type="heading" id="wednesday_solutions" />
<StyledHeader data-testid="header" position="static">
<Toolbar sx={{ display: 'flex', gap: '1rem' }}>
<Link to="/">
<Logo alt="logo" src={logo} />
</Link>
<Title type="heading" id="wednesday_solutions" />
</Toolbar>
</StyledHeader>
);
};
Expand Down
Loading