Skip to content

Commit

Permalink
348-refactor: Title component refactor (#350)
Browse files Browse the repository at this point in the history
* feat: 348 - add cva package

* feat: 348 - add new size constants

* feat: 348 - delete h2 default margin

* feat: 348 - add widget-title component

* refactor: 348 - Title to WidgetTitle in Parthered

* refactor: 348 - Title to WidgetTitle in General

* refactor: 348 - add fixme anchor for h1 in main

* refactor: 348 - Title to WidgetTitle in About

* refactor: 348 - Title to WidgetTitle in About-Home

* refactor: 348 - Title to WidgetTitle in About-School

* refactor: 348 - Title to WidgetTitle in Alumni

* refactor: 348 - Title to WidgetTitle in Angular-Topics

* refactor: 348 - Title to WidgetTitle in Certification

* refactor: 348 - Title to WidgetTitle in Communication

* refactor: 348 - Title to WidgetTitle in Community

* refactor: 348 - Title to WidgetTitle in Contribute

* refactor: 348 - Title to WidgetTitle in Course-main

* refactor: 348 - Title to WidgetTitle in Courses

* refactor: 348 - remove unsused styles in courses

* refactor: 348 - add widget-title in course-school

* refactor: 348 - Title to WidgetTitle in Events

* refactor: 348 - Title to WidgetTitle in FAQ

* refactor: 348 - Title to WidgetTitle in Main

* refactor: 348 - Title to WidgetTitle in Mentoring

* refactor: 348 - Title to WidgetTitle in Mentors

* refactor: 348 - Title to WidgetTitle in Mentors-wanted

* refactor: 348 - Title to WidgetTitle in Merch

* refactor: 348 - Title to WidgetTitle in Numbers

* refactor: 348 - Title to WidgetTitle in Pictures

* refactor: 348 - Title to WidgetTitle in Principles

* refactor: 348 - Title to WidgetTitle in Required

* refactor: 348 - Title to WidgetTitle in Speakers

* refactor: 348 - Title to WidgetTitle in Study-path

* refactor: 348 - Title to WidgetTitle in Study-with-us

* refactor: 348 - Title to WidgetTitle in Support

* refactor: 348 - Title to WidgetTitle in Trainers

* refactor: 348 - Title to WidgetTitle in Training-program

* refactor: 348 - deletw commented code

* refactor: 348 - add vars for tablet font-size

* refactor: 348 - Title to WidgetTitle in About-video

* refactor: 348 - Add vars for MainTitle

* refactor: 348 - reset default h1 margin

* refactor: 348 - add MainTitle comp

* refactor: 348 - Title to MainTitle in courses/main

* refactor: 348 - delete widget main styles for title

* refactor: 348 - Title to MainTitle in widgets/main

* refactor: 348 - Delete exports in widget-title

* refactor: 348 - update vars for widget-title

* refactor: 348 - update reset for headiang tag

* refactor: 348 - to model and bind classnames

* refactor: 348 - delete h1 margin

* refactor: 348 - add public api for widget-title

* refactor: 348 - update paths /widget-title

* refactor: 348 - add model and bind calssnames for main-title

* refactor: 348 - delete unused &

* refactor: 348 - update classnames name and add to tests

* refactor: 348 - add export for cx and add tests for MainTitle

* feat: 348 - add public api and update paths

* refactor: 348 - delete unused style

* refactor: 348 - delete dublicate style

* refactor: 348 - delete model in widget-title and update naming for bind classnanes

* refactor: 348 - delete model in main-title

* refactro: 348 - delete old Title component

* refactor: 348 - update import into react

* refactor: 348 delete model file for main-title

* fix: 348 - fix after review

* fix: 348 - off eslint issue

---------

Co-authored-by: Dzmitry Yarmoshkin <[email protected]>
Co-authored-by: ansivgit <[email protected]>
  • Loading branch information
3 people authored Jul 4, 2024
1 parent 0addf43 commit 13ed152
Show file tree
Hide file tree
Showing 54 changed files with 322 additions and 229 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default [
'react/prop-types': 'off',
'react/react-in-jsx-scope': 'off',
'react-refresh/only-export-components': [
'warn',
'off',
{ allowConstantExport: true },
],

Expand Down
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"prepare": "husky"
},
"dependencies": {
"class-variance-authority": "^0.7.0",
"classnames": "^2.5.1",
"dayjs": "^1.11.11",
"nextjs-toploader": "^1.6.12",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { AwsLogo, EpamLogo, GithubLogo, JetBrainsLogo } from '@/shared/icons';
import { WidgetTitle } from '@/shared/ui/widget-title';

import './partnered.scss';

export const Partnered = () => (
<div className="partnered container" data-testid="partnered">
<div className="partnered content">
<div className="title">Partnered with</div>
<WidgetTitle size="small">Partnered with</WidgetTitle>
<div className="partners">
<EpamLogo />
<JetBrainsLogo />
Expand Down
4 changes: 4 additions & 0 deletions src/app/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ li {
padding: 0;
}

h2 {
margin: 0;
}

figure {
margin: 0;
padding: 0;
Expand Down
3 changes: 2 additions & 1 deletion src/app/styles/normalize.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ main {
/**
* Correct the font size and margin on `h1` elements within `section` and
* `article` contexts in Chrome, Firefox, and Safari.
* delete h1 margin
*/

h1 {
margin: 0.67em 0;
margin: 0;
font-size: 2em;
}

Expand Down
4 changes: 2 additions & 2 deletions src/entities/courses/ui/general/general.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Link } from 'react-router-dom';
import { Title } from '@/shared/ui/title';
import { WidgetTitle } from '@/shared/ui/widget-title';

import './general.scss';

export const General = () => {
return (
<section className="general container">
<div className="general content">
<Title text="General" />
<WidgetTitle size="small">General</WidgetTitle>
<div className="general-info">
<div className="materials">
<h2 className="title">Materials</h2>
Expand Down
4 changes: 2 additions & 2 deletions src/entities/courses/ui/main/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mentors from '@/shared/assets/mentor-with-his-students.webp';
import Image from '@/shared/ui/image';
import { Title, TitleType } from '@/shared/ui/title';
import { MainTitle } from '@/shared/ui/main-title';

import './main.scss';

Expand All @@ -10,7 +10,7 @@ export const Main = () => {
<div className="courses-main content">
<div className="left">
<div className="title-container">
<Title text="Our Courses" type={TitleType.ExtraBig} />
<MainTitle>Our Courses</MainTitle>
</div>
<h2 className="description">Journey to full stack mastery</h2>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/shared/ui/main-title/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { MainTitle } from './main-title';
11 changes: 11 additions & 0 deletions src/shared/ui/main-title/main-title.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.title {
font-size: 96px;
font-weight: 700;
color: $color-black;
text-align: left;
letter-spacing: -0.04em;

@include media-tablet {
font-size: 60px;
}
}
38 changes: 38 additions & 0 deletions src/shared/ui/main-title/main-title.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { MainTitle, cx } from './main-title';

describe('MainTitle component', () => {
it('renders without crashing', () => {
render(<MainTitle>TestTitle</MainTitle>);
const title = screen.getByText('TestTitle');

expect(title).toBeInTheDocument();
});

it('displays h1 tag', () => {
render(<MainTitle />);
const element = screen.getByRole('heading', { level: 1 });

expect(element).toBeInTheDocument();
});

it('displays styles correctly', () => {
render(<MainTitle />);
const element = screen.getByRole('heading', { level: 1 });

expect(element).toHaveClass(cx('title'));
});

it('renders children correctly', () => {
render(
<MainTitle>
<div>Child element</div>
</MainTitle>,
);

const child = screen.getByText('Child element');

expect(child).toBeInTheDocument();
});
});
22 changes: 22 additions & 0 deletions src/shared/ui/main-title/main-title.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { HTMLAttributes } from 'react';
import { VariantProps, cva } from 'class-variance-authority';
import classNames from 'classnames/bind';

import styles from './main-title.module.scss';

type MainTitleProps = HTMLAttributes<HTMLHeadingElement> & VariantProps<typeof mainTitleVariants>;

export const cx = classNames.bind(styles);

const mainTitleVariants = cva(cx('title'));

export const MainTitle = ({ children, className, ...props }: MainTitleProps) => {
return (
<h1
{...props}
className={mainTitleVariants({ className })}
>
{children}
</h1>
);
};
2 changes: 0 additions & 2 deletions src/shared/ui/title/index.ts

This file was deleted.

58 changes: 0 additions & 58 deletions src/shared/ui/title/title.scss

This file was deleted.

46 changes: 0 additions & 46 deletions src/shared/ui/title/title.test.tsx

This file was deleted.

26 changes: 0 additions & 26 deletions src/shared/ui/title/title.tsx

This file was deleted.

6 changes: 0 additions & 6 deletions src/shared/ui/title/types.ts

This file was deleted.

1 change: 1 addition & 0 deletions src/shared/ui/widget-title/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { WidgetTitle } from './widget-title';
43 changes: 43 additions & 0 deletions src/shared/ui/widget-title/widget-title.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.title {
font-weight: $font-weight-medium;
letter-spacing: -0.04em;

&::before {
margin-right: 8px;
color: $color-red;
}
}

.small {
font-size: 36px;
line-height: 44px;
letter-spacing: 0;
}

.medium {
font-size: 44px;
line-height: 52px;

@include media-tablet {
font-size: 36px;
line-height: 44px;
}
}

.large {
font-size: 52px;
line-height: 64px;

@include media-tablet {
font-size: 36px;
line-height: 44px;
}
}

.lines::before {
content: '';
}

.asterisk::before {
content: '*';
}
Loading

0 comments on commit 13ed152

Please sign in to comment.