Skip to content

Commit

Permalink
Continuing work the theming work
Browse files Browse the repository at this point in the history
  • Loading branch information
AnselmMarie committed Sep 10, 2024
1 parent 71d3800 commit 9993af7
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 181 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import UiSwitchTheme from './switch.theme.view';

export { UiSwitchTheme };
// export * from './switch.enum';
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ThemeTypeEnum } from '@pokemon-pet-shop/store';

import { IconType } from '../icon/icon.interface';
import { IconType } from '@pokemon-pet-shop/ui';

export interface SwitchProps {
className?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { memo, ReactElement, useEffect } from 'react';

import { ThemeTypeEnum, useThemeStore } from '@pokemon-pet-shop/store';
import { IconTypeEnum, SwitchStatusEnum, UiSwitch } from '@pokemon-pet-shop/ui';

import { SwitchProps } from './switch.theme.interface';

const SwitchTheme = ({ className }: SwitchProps): ReactElement => {
const { theme, updateTheme } = useThemeStore();

const updateTheming = (newTheme: ThemeTypeEnum) => {
updateTheme(newTheme);
const el = document.querySelector('html');

el?.classList.toggle(ThemeTypeEnum.DARK);
el?.classList.toggle(ThemeTypeEnum.LIGHT);
};

const turnLightOnClick = () => {
updateTheming(ThemeTypeEnum.LIGHT);
};

const turnDarkOnClick = () => {
updateTheming(ThemeTypeEnum.DARK);
};

useEffect(() => {
const el = document.querySelector('html');

el?.classList.add(theme);

return () => {
el?.classList.remove(theme);
};
}, [theme]);

return (
<UiSwitch
className={className}
iconLeft={IconTypeEnum.ICON_SUN}
iconRight={IconTypeEnum.ICON_MOON}
val={theme === ThemeTypeEnum.LIGHT ? SwitchStatusEnum.ON : SwitchStatusEnum.OFF}
onLeftClick={turnLightOnClick}
onRightClick={turnDarkOnClick}
/>
);
};

export default memo(SwitchTheme);
9 changes: 3 additions & 6 deletions libs/features/src/lib/navigation/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
UiIcon,
IconTypeEnum,
UiInput,
UiSwitchTheme,
UiTypography,
TypographyTypeEnum,
UiContainer,
Expand All @@ -18,6 +17,7 @@ import {
import { noopUtil } from '@pokemon-pet-shop/utils';

import { UiCartModal } from '../../cart';
import { UiSwitchTheme } from '../component/switch.theme';

import { styles } from './header.module';

Expand Down Expand Up @@ -59,11 +59,8 @@ const Header = () => {
</UiElementLayout>

<UiHideInMobile>
<UiSwitchTheme
className={styles.switchTheme}
iconLeft={IconTypeEnum.ICON_SUN}
iconRight={IconTypeEnum.ICON_MOON}
/>
<UiSwitchTheme className={styles.switchTheme} />
<UiSwitchTheme className={styles.switchTheme} />
</UiHideInMobile>

<UiElementLayout onClick={handleOpenDetailModalClick}>
Expand Down
17 changes: 4 additions & 13 deletions libs/features/src/lib/navigation/nav.mobile/nav.mobile.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import { ReactElement } from 'react';

import { AlignmentEnum } from '@pokemon-pet-shop/typing';
import {
UiElementLayout,
UiIcon,
IconTypeEnum,
UiTypography,
UiModal,
UiSwitchTheme,
} from '@pokemon-pet-shop/ui';
import { UiElementLayout, UiIcon, IconTypeEnum, UiTypography, UiModal } from '@pokemon-pet-shop/ui';

import { UiSwitchTheme } from '../component/switch.theme';

import { NavMobileModalProps } from './nav.mobile.interface';
import styles from './nav.mobile.module.css';
Expand All @@ -27,11 +22,7 @@ const NavMobileModal = ({ isModalShown = false }: NavMobileModalProps): ReactEle
</UiElementLayout>
</UiElementLayout>
<UiElementLayout className={styles.dropdownBtm}>
<UiSwitchTheme
className={styles.switchTheme}
iconLeft={IconTypeEnum.ICON_SUN}
iconRight={IconTypeEnum.ICON_MOON}
/>
<UiSwitchTheme className={styles.switchTheme} />
</UiElementLayout>
</UiModal>
);
Expand Down
4 changes: 3 additions & 1 deletion libs/services/src/lib/cart/api.cart.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { CartDataApi } from '@pokemon-pet-shop/typing';

import { axiosInstance } from '../common/utils/api.util';

export const getCart = async () => {
return (await axiosInstance.get<any[]>('cart')).data;
return (await axiosInstance.get<CartDataApi>('cart')).data;
};

export const updateCart = async (data: any) => {
Expand Down
2 changes: 1 addition & 1 deletion libs/ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export * from './lib-base/ui/typography';
export * from './lib-base/ui/image';
export * from './lib-base/ui/icon';
export * from './lib-base/ui/input';
export * from './lib-base/ui/switch.theme';
export * from './lib-base/ui/button';
export * from './lib-base/ui/icon.poke.type';
export * from './lib-base/ui/modal';
export * from './lib-base/ui/card';
export * from './lib-base/ui/dropdown';
export * from './lib-base/ui/hide.in.mobile';
export * from './lib-base/ui/tag';
export * from './lib-base/ui/switch';
1 change: 1 addition & 0 deletions libs/ui/src/lib-base/ui/icon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ import UiIcon from './icon.view';

export { UiIcon };
export * from './icon.enum';
export * from './icon.interface';
41 changes: 0 additions & 41 deletions libs/ui/src/lib-base/ui/switch.theme/switch.theme.module.css

This file was deleted.

43 changes: 0 additions & 43 deletions libs/ui/src/lib-base/ui/switch.theme/switch.theme.module.native.ts

This file was deleted.

3 changes: 0 additions & 3 deletions libs/ui/src/lib-base/ui/switch.theme/switch.theme.module.ts

This file was deleted.

61 changes: 0 additions & 61 deletions libs/ui/src/lib-base/ui/switch.theme/switch.theme.view.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion libs/ui/src/lib-base/ui/switch/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import UiSwitch from './switch.view';

export { UiSwitch };
// export * from './switch.enum';
export * from './switch.enum';
4 changes: 4 additions & 0 deletions libs/ui/src/lib-base/ui/switch/switch.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export enum SwitchStatusEnum {
ON = 'ON',
OFF = 'OFF',
}
3 changes: 2 additions & 1 deletion libs/ui/src/lib-base/ui/switch/switch.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export interface SwitchProps {
name?: string;
iconLeft?: IconType | null;
iconRight?: IconType | null;
defaultValue?: boolean;
defaultValue?: string;
val?: string | null;
isDisabled?: boolean;
onLeftClick?: GenericNonReturnType;
onRightClick?: GenericNonReturnType;
Expand Down
Loading

0 comments on commit 9993af7

Please sign in to comment.