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

Feature/layout #20

Merged
merged 4 commits into from
Jan 7, 2024
Merged
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
53 changes: 29 additions & 24 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ module.exports = {
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: [
'react',
'@typescript-eslint',
'i18next',
],
plugins: ['react', '@typescript-eslint', 'i18next'],
rules: {
indent: [2, 4],

Expand All @@ -31,29 +27,38 @@ module.exports = {
'react/react-in-jsx-scope': 'off',
'react/require-default-props': 'off',
'react/jsx-props-no-spreading': 'warn',
'react/jsx-filename-extension': [2, {
extensions: ['tsx', '.jsx'],
}],
'react/function-component-definition': [2, {
namedComponents: 'arrow-function',
}],
'react/jsx-filename-extension': [
2,
{
extensions: ['tsx', '.jsx'],
},
],
'react/function-component-definition': [
2,
{
namedComponents: 'arrow-function',
},
],

'import/extensions': 'off',
'import/no-unresolved': 'off',
'import/prefer-default-export': 'off',
'import/order': ['error', {
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
'type',
],
'newlines-between': 'always',
}],
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
'object',
'type',
],
'newlines-between': 'always-and-inside-groups',
},
],

'linebreak-style': ['warn', 'windows'],
'i18next/no-literal-string': ['error', { markupOnly: true }],
Expand Down
Binary file modified .loki/reference/chrome_iphone7_Page_AboutPage_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_Page_MainPage_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_Page_NotFoundPage_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_Shared_AppLink_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_Shared_Button_Clear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_Shared_Button_Outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_Shared_Button_Primary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_Widgets_Layout_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_Widgets_Navbar_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_Widgets_PageError_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_Widgets_Sidebar_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_laptop_Page_AboutPage_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_laptop_Page_MainPage_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_laptop_Page_NotFoundPage_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_laptop_Shared_AppLink_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_laptop_Shared_Button_Clear.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_laptop_Shared_Button_Outline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_laptop_Shared_Button_Primary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_laptop_Widgets_Layout_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_laptop_Widgets_Navbar_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_laptop_Widgets_PageError_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_laptop_Widgets_Sidebar_Default.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 13 additions & 10 deletions config/storybook/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,37 @@ import svgBuildLoader from '../build/loaders/svgBuildLoader';
import cssBuildLoader from '../build/loaders/cssBuildLoader';

type Props = {
config:webpack.Configuration
config: webpack.Configuration
}

type ArrayElement<ArrayType> =
ArrayType extends readonly (infer ElementType)[] ? ElementType : never;

const isRuleSet = (
arg:webpack.ModuleOptions['rules'][number],
arg: ArrayElement<webpack.ModuleOptions['rules']>,
): arg is webpack.RuleSetRule => {
if (!arg) return false;

return typeof arg === 'object' && 'test' in arg;
};

const isRegExp = (arg:webpack.RuleSetRule['test']):arg is RegExp => arg instanceof RegExp;
const isRegExp = (arg: webpack.RuleSetRule['test']): arg is RegExp => arg instanceof RegExp;

export default ({ config }:Props) => {
export default ({ config }: Props) => {
const src = path.resolve(__dirname, '..', '..', 'src');
const isDev = true;

const fileLoaderRule = config.module.rules.find(
const fileLoaderRule = config.module?.rules?.find(
(rule) => isRuleSet(rule) && isRegExp(rule.test) && rule.test.test('.svg'),
);

if (isRuleSet(fileLoaderRule)) { fileLoaderRule.exclude = /\.svg$/; }

config.resolve.modules.push(src);
config.resolve.modules.push('node_modules');
config.resolve.extensions.push('ts', 'tsx');
config.module.rules.push(svgBuildLoader());
config.module.rules.push(cssBuildLoader(isDev));
config.resolve?.modules?.push(src);
config.resolve?.modules?.push('node_modules');
config.resolve?.extensions?.push('ts', 'tsx');
config.module?.rules?.push(svgBuildLoader());
config.module?.rules?.push(cssBuildLoader(isDev));

return config;
};
17 changes: 9 additions & 8 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"mainPage": "Main Page",
"lang": "English",
"main": "Main",
"about": "About",
"loading": "Loading",
"NotFoundPage": "Page not found",
"errorMessage": "Something went wrong.",
"updatePage": "Refresh the page"
"mainPage": "Main Page",
"shortLang": "Eng",
"lang": "English",
"main": "Main",
"about": "About",
"loading": "Loading",
"NotFoundPage": "Page not found",
"errorMessage": "Something went wrong.",
"updatePage": "Refresh the page"
}
17 changes: 9 additions & 8 deletions public/locales/ru/translation.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"mainPage": "Главная страница",
"lang": "Русский",
"main": "Главная",
"about": "О сайте",
"loading": "Загрузка",
"NotFoundPage": "Страница не найдено",
"errorMessage": "Что-то пошло не так.",
"updatePage": "Обновить страницу"
"mainPage": "Главная страница",
"shortLang": "Рус",
"lang": "Русский",
"main": "Главная",
"about": "О сайте",
"loading": "Загрузка",
"NotFoundPage": "Страница не найдено",
"errorMessage": "Что-то пошло не так.",
"updatePage": "Обновить страницу"
}
6 changes: 3 additions & 3 deletions src/app/providers/ThemeProvider/lib/useTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { useContext } from 'react';
import { LOCAL_STORAGE_THEME_KEY, Theme, ThemeContext } from './ThemeContext';

interface UseThemeResult {
toggleTheme: () => void;
theme: Theme;
toggleTheme: () => void;
theme?: Theme;
}

export function useTheme(): UseThemeResult {
const { setTheme, theme } = useContext(ThemeContext);

const toggleTheme = () => {
const newTheme = theme === Theme.DARK ? Theme.LIGHT : Theme.DARK;
setTheme(newTheme);
setTheme?.(newTheme);
localStorage.setItem(LOCAL_STORAGE_THEME_KEY, newTheme);
};

Expand Down
8 changes: 2 additions & 6 deletions src/app/providers/router/ui/AppRouter.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Suspense } from 'react';
import { Route, Routes } from 'react-router-dom';
import { routeConfig } from 'shared/config/routeConfig/routeConfig';
import Layout from 'widgets/Layout/ui/Layout';
import { Layout } from 'widgets/Layout';
import { PageLoader } from 'widgets/PageLoader';

const AppRouter = () => (
Expand All @@ -18,11 +18,7 @@ const AppRouter = () => (
<Route
key={path}
path={path}
element={(
<Suspense fallback={<PageLoader />}>
{element}
</Suspense>
)}
element={<Suspense fallback={<PageLoader />}>{element}</Suspense>}
/>
))}
</Route>
Expand Down
8 changes: 4 additions & 4 deletions src/app/styles/themes/dark.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.app.dark {
--bg-color: #090949;
--inverted-bg-color: #e8e8ea;
--primary-color: #049604;
--secondary-color: #04ff04;
--inverted-primary-color: #0232c2;
--inverted-secondary-color: #0452ff;
--primary-color:#04ff04;
--secondary-color: #049604;
--inverted-primary-color:#0452ff;
--inverted-secondary-color: #0232c2;
}
8 changes: 4 additions & 4 deletions src/app/styles/themes/normal.scss
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
:root {
--bg-color: #e8e8ea;
--inverted-bg-color: #090949;
--primary-color: #0232c2;
--secondary-color: #0449e0;
--inverted-primary-color: #049604;
--inverted-secondary-color: #04ff04;
--primary-color: #0449e0;
--secondary-color:#0232c2;
--inverted-primary-color: #04ff04;
--inverted-secondary-color:#049604 ;
}
6 changes: 4 additions & 2 deletions src/app/styles/variables/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
--font-size-l: 24px;
--font-line-l: 32px;
--font-l: var(--font-size-l) / var(--font-line-l) var(--font-family-main);
--font-size-xl: 32px;
--font-line-xl: 40px;
--font-xl: var(--font-size-xl) / var(--font-line-xl) var(--font-family-main);

// sizes

/* size */
--navbar-height: 50px;
--sidebar-width: 300px;
--sidebar-width-collapsed: 80px;
Expand Down
4 changes: 2 additions & 2 deletions src/app/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ declare module '*.scss' {
[className: string]: string;
}
const classNames: IClassNames;
export = classNames;
export default classNames;
}

declare module '*.png';
Expand All @@ -12,7 +12,7 @@ declare module '*.jpeg';
declare module '*.svg' {
import React from 'react';

const SVG: React.VFC<React.SVGProps<SVGSVGElement>>;
const SVG: React.FC<React.SVGProps<SVGSVGElement>>;
export default SVG;
}

Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import App from './app/App';

import './shared/config/i18n/i18n';

const root = createRoot(document.getElementById('root'));
const root = createRoot(document.getElementById('root') as HTMLElement);

root.render(
<BrowserRouter>
Expand Down
24 changes: 24 additions & 0 deletions src/shared/assets/icons/about.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/shared/assets/icons/main.svg
24 changes: 12 additions & 12 deletions src/shared/lib/classNames/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
type classNamesProps = Array<
null |
undefined |
string |
Record<string, boolean | string>
>
null | undefined | string | Record<string, boolean | string | null | undefined>
>;

export function classNames(...args: classNamesProps): string {
return args.filter((item) => item).flatMap((arg) => {
if (typeof arg === 'string') return arg;
return args
.filter((item) => item)
.flatMap((arg) => {
if (typeof arg === 'string') return arg;

if (typeof arg === 'object') {
return Object.keys(arg).filter((key) => arg[key]);
}
return '';
}).join(' ');
if (arg && typeof arg === 'object') {
return Object.keys(arg).filter((key) => arg[key]);
}
return '';
})
.join(' ');
}
22 changes: 22 additions & 0 deletions src/shared/lib/tests/componentRender/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { render } from '@testing-library/react';
import { ReactNode } from 'react';
import { MemoryRouter } from 'react-router-dom';
import { I18nextProvider } from 'react-i18next';
import i18n from 'shared/config/i18n/i18ForTests';

interface OptionsRouter {
router?: string;
}

function componentRender(Component: ReactNode, options: OptionsRouter = {}) {
const { router = '/' } = options;

return render(
<MemoryRouter initialEntries={[router]}>
<I18nextProvider i18n={i18n}>{Component}</I18nextProvider>
</MemoryRouter>,
);
}

export default componentRender;
11 changes: 11 additions & 0 deletions src/shared/ui/AppLink/AppLink.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.link {
color: var(--primary-color);
}

.primary {
color: var(--primary-color);
}

.secondary {
color: var(--inverted-primary-color);
}
12 changes: 5 additions & 7 deletions src/shared/ui/AppLink/AppLink.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { Link } from 'react-router-dom';
import { classNames } from 'shared/lib/classNames';

import { AppLinkProps } from './AppLink.props';
import styles from './AppLink.module.scss';

const AppLink = ({
className,
// theme = AppLinkTheme.Primary,
...props
}: AppLinkProps) => (
import { AppLinkTheme, type AppLinkProps } from './AppLink.props';

const AppLink = ({ className, theme = AppLinkTheme.Primary, ...props }: AppLinkProps) => (
<Link
className={classNames(className)}
className={classNames(styles.link, styles[theme], className)}
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
/>
Expand Down
12 changes: 12 additions & 0 deletions src/shared/ui/Button/Button.enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export enum ButtonTheme {
Clear = 'clear',
Outline = 'outline',
Background = 'background',
BackgroundInvertend = 'backgroundInvertend'
}

export enum ButtonSize {
Small = 'small',
Middle = 'medium',
Large = 'large',
}
Loading
Loading