Skip to content

Commit

Permalink
Link component created • Updates to detect util and typography component
Browse files Browse the repository at this point in the history
  • Loading branch information
AnselmMarie committed Oct 7, 2024
1 parent d0df250 commit 3cae823
Show file tree
Hide file tree
Showing 21 changed files with 164 additions and 75 deletions.
51 changes: 33 additions & 18 deletions libs/features/src/lib/footer/footer.module.native.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
import { THEME_SPACING_10, THEME_SPACING_5 } from '@pokemon-pet-shop/ui/styles/var';
import {
THEME_SPACING_10,
THEME_SPACING_15,
THEME_SPACING_45,
} from '@pokemon-pet-shop/ui/styles/var';
import { StyleSheet } from 'react-native';

export const styles = () =>
StyleSheet.create({
footerWrapper: {
display: 'flex',
justifyContent: 'center',
},
githubWrapper: {
display: 'flex',
},
githubIcon: {
marginRight: THEME_SPACING_5,
},
footerDivider: {
paddingLeft: THEME_SPACING_10,
paddingRight: THEME_SPACING_10,
},
});
export const styles = StyleSheet.create({
footerWrapper: {
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
marginBottom: THEME_SPACING_45,
},
githubWrapper: {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'column',
marginBottom: THEME_SPACING_15,
},
githubIcon: {
marginRight: THEME_SPACING_10,
},
scanWrapper: {
display: 'flex',
alignItems: 'center',
flexDirection: 'row',
marginBottom: THEME_SPACING_15,
},
footerDivider: {
display: 'none',
},
});
13 changes: 6 additions & 7 deletions libs/features/src/lib/footer/footer.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import { ThemeTypeEnum, useThemeStore } from '@pokemon-pet-shop/store';
import { IconTypeEnum, UiElementLayout, UiIcon, UiTypography } from '@pokemon-pet-shop/ui';
import { IconTypeEnum, UiElementLayout, UiIcon, UiLink, UiTypography } from '@pokemon-pet-shop/ui';
import { THEME_NETURAL_100, THEME_NETURAL_900 } from '@pokemon-pet-shop/ui/styles/var';

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

const Footer = () => {
const { theme } = useThemeStore();

const goToGithubProject = () => {
window.open('https://github.com/AnselmMarie/pokemon-pet-shop', '_blank');
};

return (
<UiElementLayout className={styles.footerWrapper}>
<UiElementLayout className={styles.githubWrapper} onClick={goToGithubProject}>
<UiLink
className={styles.githubWrapper}
link="https://github.com/AnselmMarie/pokemon-pet-shop"
>
<UiIcon
icon={IconTypeEnum.ICON_GITHUB}
size={20}
classNameIcon={styles.githubIcon}
color={theme === ThemeTypeEnum.LIGHT ? THEME_NETURAL_900 : THEME_NETURAL_100}
/>
<UiTypography>Github Project</UiTypography>
</UiElementLayout>
</UiLink>
<UiTypography className={styles.footerDivider}>|</UiTypography>
<UiElementLayout className={styles.scanWrapper}>
<UiIcon color={theme === ThemeTypeEnum.LIGHT ? THEME_NETURAL_900 : THEME_NETURAL_100} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { memo, ReactElement, useEffect } from 'react';

import { ThemeTypeEnum, useThemeStore } from '@pokemon-pet-shop/store';
import { DetectEnum } from '@pokemon-pet-shop/typing';
import { IconTypeEnum, SwitchStatusEnum, UiSwitch } from '@pokemon-pet-shop/ui';
import { variableThemeMode } from '@pokemon-pet-shop/ui/styles/var';
import { detectUtil } from '@pokemon-pet-shop/utils';
import { isWebUtil } from '@pokemon-pet-shop/utils';

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

Expand All @@ -15,7 +14,7 @@ const SwitchTheme = ({ className }: SwitchProps): ReactElement => {
const varThemeMode = variableThemeMode(newTheme);
updateTheme(newTheme, varThemeMode);

if (detectUtil() === DetectEnum.IS_WEB) {
if (isWebUtil()) {
const el = document.querySelector('html');
el?.setAttribute('data-theme', newTheme);
}
Expand All @@ -30,7 +29,7 @@ const SwitchTheme = ({ className }: SwitchProps): ReactElement => {
};

useEffect(() => {
if (detectUtil() === DetectEnum.IS_WEB) {
if (isWebUtil()) {
const el = document.querySelector('html');
el?.setAttribute('data-theme', theme);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
}

.btnWrapper {
text-align: center;
display: flex;
justify-content: center;
margin-top: var(--theme-spacing-35);
margin-bottom: var(--theme-spacing-35);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
THEME_SPACING_15,
THEME_SPACING_25,
THEME_SPACING_35,
THEME_SPACING_45,
} from '@pokemon-pet-shop/ui/styles/var';
Expand All @@ -23,7 +24,7 @@ export const styles = StyleSheet.create({
textAlign: 'center',
marginLeft: THEME_SPACING_15,
marginRight: THEME_SPACING_15,
marginTop: THEME_SPACING_35,
marginTop: THEME_SPACING_25,
marginBottom: THEME_SPACING_45,
},
});
5 changes: 2 additions & 3 deletions libs/hooks/src/lib/use.render.styles.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { useMemo } from 'react';

import { useThemeStore } from '@pokemon-pet-shop/store';
import { DetectEnum } from '@pokemon-pet-shop/typing';
import { detectUtil } from '@pokemon-pet-shop/utils';
import { isWebUtil } from '@pokemon-pet-shop/utils';

export const useRenderStyles = (styles: any): any => {
const { varThemeMode } = useThemeStore();
const newStyles = useMemo(() => {
if (detectUtil() === DetectEnum.IS_WEB) {
if (isWebUtil()) {
return styles;
}

Expand Down
1 change: 1 addition & 0 deletions libs/ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export * from './lib-base/ui/tag';
export * from './lib-base/ui/switch';
export * from './lib-base/ui/skeleton';
export * from './lib-base/ui/scroll.wrapper';
export * from './lib-base/ui/link';
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const ElementLayout = ({
}: PropsWithChildren<ElementLayoutProps>): ReactElement => {
if (onClick !== null) {
return (
<TouchableHighlight style={className} onPress={onClick}>
<View>{children}</View>
<TouchableHighlight onPress={onClick}>
<View style={className}>{children}</View>
</TouchableHighlight>
);
}
Expand Down
2 changes: 0 additions & 2 deletions libs/ui/src/lib-base/ui/icon/icon.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ const Icon = ({
const disabledStyles = isDisabled ? globalStyles.disabledElement : '';
const clickableStyles = onClick ? globalStyles.pointerCursor : '';

console.log('IconComponent', IconComponent);

return (
<IconComponent
size={size}
Expand Down
3 changes: 3 additions & 0 deletions libs/ui/src/lib-base/ui/link/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import UiLink from './link';

export { UiLink };
4 changes: 4 additions & 0 deletions libs/ui/src/lib-base/ui/link/link.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface LinkProps {
className?: string;
link?: string | null;
}
26 changes: 26 additions & 0 deletions libs/ui/src/lib-base/ui/link/link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { PropsWithChildren, ReactElement } from 'react';

import { UiElementLayout } from '../element.layout';

import { LinkProps } from './link.interface';
import { openLinkUtil } from './open.link.util';

const Link = ({
link = null,
className = '',
children,
}: PropsWithChildren<LinkProps>): ReactElement => {
const goToLink = () => {
if (link) {
openLinkUtil(link);
}
};

return (
<UiElementLayout className={className} onClick={goToLink}>
{children}
</UiElementLayout>
);
};

export default Link;
6 changes: 6 additions & 0 deletions libs/ui/src/lib-base/ui/link/open.link.util.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as Linking from 'expo-linking';

export const openLinkUtil = (link: string) => {
console.log('link', link);
Linking.openURL(link);
};
3 changes: 3 additions & 0 deletions libs/ui/src/lib-base/ui/link/open.link.util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const openLinkUtil = (link: string) => {
window.open(link, '_blank');
};
1 change: 1 addition & 0 deletions libs/ui/src/lib-base/ui/typography/typography.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import { TypographyTypeEnum } from './typography.enum';
export interface TypographyProps {
typographyType?: TypographyTypeEnum;
className?: any;
onClick?: any;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@ import { TypographyProps } from './typography.interface';
const Typography = ({
className = '',
children = null,
onClick,
}: PropsWithChildren<TypographyProps>): ReactElement => {
return <Text style={className}>{children}</Text>;
return (
<Text style={className} onPress={onClick}>
{children}
</Text>
);
};

export default memo(Typography);
3 changes: 2 additions & 1 deletion libs/ui/src/lib-base/ui/typography/typography.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { TypographyProps } from './typography.interface';
const Typography = ({
typographyType = TypographyTypeEnum.P,
className = '',
onClick,
children = null,
}: PropsWithChildren<TypographyProps>): ReactElement => {
return createElement(typographyType, { className }, children);
return createElement(typographyType, { className, onClick }, children);
};

export default memo(Typography);
8 changes: 8 additions & 0 deletions libs/utils/src/lib-base/utils/detect.util.native.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
export const detectUtil = () => {
return 'isNative';
};

export const isWebUtil = () => {
return false;
};

export const isNativeUtil = () => {
return true;
};
8 changes: 8 additions & 0 deletions libs/utils/src/lib-base/utils/detect.util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
export const detectUtil = () => {
return 'isWeb';
};

export const isWebUtil = () => {
return true;
};

export const isNativeUtil = () => {
return false;
};
Loading

0 comments on commit 3cae823

Please sign in to comment.