Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Izet Molla committed Aug 3, 2023
1 parent 7dae484 commit 62dc98a
Show file tree
Hide file tree
Showing 25 changed files with 260 additions and 298 deletions.
6 changes: 4 additions & 2 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

import { StyleSheet, View, Text } from 'react-native';
import { ThemeUiProvider } from 'react-native-themeui';
import { Box, ThemeUiProvider } from 'react-native-themeui';

export default function App() {

Check failure on line 7 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎⏎⏎⏎⏎`
Expand All @@ -12,7 +12,9 @@ export default function App() {
return (
<ThemeUiProvider>
<View style={styles.container}>
<Text>Result:</Text>
<Box >

Check failure on line 15 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
<Text>Result:</Text>
</Box>
</View>
</ThemeUiProvider>

Check failure on line 19 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-themeui",
"version": "1.1.1",
"version": "1.0.1",
"description": "Essential cross-platform UI components for React Native",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down Expand Up @@ -70,7 +70,7 @@
"react": "18.2.0",
"react-native": "0.72.3",
"react-native-builder-bob": "^0.20.0",
"react-native-safe-area-context": "^3.1.9",
"react-native-safe-area-context": "^4.7.1",
"release-it": "^15.0.0",
"typescript": "^5.0.2"
},
Expand Down
25 changes: 25 additions & 0 deletions src/components/Box/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { FC } from 'react';

import { View } from "react-native"

Check failure on line 3 in src/components/Box/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `"react-native"` with `'react-native';`
import { usePropsResolution } from "../../hooks/usePropsResolution"

Check failure on line 4 in src/components/Box/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `"../../hooks/usePropsResolution"` with `'../../hooks/usePropsResolution';`
import { BoxProps } from './types';
import { SafeAreaView } from 'react-native-safe-area-context';


Check failure on line 8 in src/components/Box/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Delete `⏎`
const Box: FC<BoxProps> = ({ children, ...props }) => {
const { ...resolvedProps } = usePropsResolution('Box', props);

Check failure on line 10 in src/components/Box/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `····` with `··`

if (props.safeArea) {

Check failure on line 12 in src/components/Box/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
return (

Check failure on line 13 in src/components/Box/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Replace `····return·(⏎············<SafeAreaView·{...resolvedProps}>{children}</SafeAreaView>` with `return·<SafeAreaView·{...resolvedProps}>{children}</SafeAreaView>;`
<SafeAreaView {...resolvedProps}>{children}</SafeAreaView>
)

Check failure on line 15 in src/components/Box/index.tsx

View workflow job for this annotation

GitHub Actions / lint

Delete `········)⏎··`
}

return (
<View {...resolvedProps} >
{children}
</View>
)
}

export default Box
7 changes: 7 additions & 0 deletions src/components/Box/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { PseudoComponentProps } from '../../contexts/theme';
import type { ViewProps } from 'react-native';


export interface BoxProps extends ViewProps, PseudoComponentProps<ViewProps["style"]> {
safeArea?: boolean
}
18 changes: 18 additions & 0 deletions src/components/Button/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React, { FC } from 'react';

import { View } from "react-native"
import { usePropsResolution } from "../../hooks/usePropsResolution"
import { ButtonProps } from './types';


const Button: FC<ButtonProps> = ({ children, ...props }) => {
const { ...resolvedProps } = usePropsResolution('Button', props);

return (
<View {...resolvedProps} >
{children}
</View>
)
}

export default Button
7 changes: 7 additions & 0 deletions src/components/Button/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { PseudoComponentProps } from '../../contexts/theme';
import type { ViewProps } from 'react-native';


export interface ButtonProps extends ViewProps, PseudoComponentProps<ViewProps["style"]> {

}
18 changes: 18 additions & 0 deletions src/components/Text/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React, { FC } from 'react';

import { Text as TxtComp } from "react-native"
import { usePropsResolution } from "../../hooks/usePropsResolution"
import { TextProps } from './types';


const Text: FC<TextProps> = ({ children, ...props }) => {
const { ...resolvedProps } = usePropsResolution('Text', props);

return (
<TxtComp {...resolvedProps} >
{children}
</TxtComp>
)
}

export default Text
7 changes: 7 additions & 0 deletions src/components/Text/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { PseudoComponentProps } from '../../contexts/theme';
import type { TextProps as TextCompProps } from 'react-native';


export interface TextProps extends TextCompProps, PseudoComponentProps<TextCompProps["style"]> {

}
7 changes: 7 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Box from "./Box";
import Text from "./Text";

export {
Box,
Text
}
9 changes: 0 additions & 9 deletions src/components/types/ExtraProps.ts

This file was deleted.

27 changes: 0 additions & 27 deletions src/components/types/PlatformProps.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/components/types/index.tsx

This file was deleted.

30 changes: 30 additions & 0 deletions src/contexts/ThemeUiProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { FC, ReactNode, useState, createContext } from "react";
import defaultTheme, { ThemeUiTypes, ThemeActionTypes } from "./theme";

interface ThemeUiProviderProps {
children: ReactNode
mode?: 'light' | 'dark'
}


const ThemeUiContext = createContext<ThemeUiTypes>(defaultTheme);
const ThemeUiActionContext = createContext<ThemeActionTypes>({
setThemeMode: () => { }
});

const ThemeUiProvider: FC<ThemeUiProviderProps> = ({ children, mode = "light" }) => {
const [theme, setTheme] = useState<ThemeUiTypes>({ ...defaultTheme, mode });

const setThemeMode = (mode: 'light' | 'dark' = 'light') => setTheme({ ...theme, mode });

Check warning on line 18 in src/contexts/ThemeUiProvider.tsx

View workflow job for this annotation

GitHub Actions / lint

'mode' is already declared in the upper scope on line 15 column 64

return (
<ThemeUiContext.Provider value={theme}>
<ThemeUiActionContext.Provider value={{ setThemeMode }}>
{children}
</ThemeUiActionContext.Provider>
</ThemeUiContext.Provider>
)
}

export { ThemeUiContext, ThemeUiActionContext }
export default ThemeUiProvider;
96 changes: 96 additions & 0 deletions src/contexts/theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { ButtonProps } from "../components/Button/types";

export interface PseudoComponentProps<T> {
_light?: T
_dark?: T
}

interface ThemeUiTypes {
mode: 'light' | 'dark';
colors: {
light: {
Box: BoxProps['style']
Text: TextProps['style']
Button: ButtonProps['style']
},
dark: {
Box: BoxProps['style']
Text: TextProps['style']
Button: ButtonProps['style']
}
}
components: {
Button: {}
Box: {},
Text: {
style: {
color: string;
}
}
}
}

export const colors: { light: any, dark: any } = {
light: {
Box: {
backgroundColor: 'white',
},
Text: {
color: "black"
},
Button: {
backgroundColor: 'blue'
}
},
dark: {
Box: {
backgroundColor: 'black',
},
Text: {
color: "white"
},
Button: {
backgroundColor: 'blue'
}
}
}
const theme: ThemeUiTypes = {
mode: 'light',
colors: colors,
components: {
Box: {
backgroundColor: 'red',
},
Text: {
style: {
color: "white"
}
},
Button: {
style: {
backgroundColor: 'blue'
}
}
}
};



interface ThemeActionTypes {
setThemeMode: (mode: 'light' | 'dark') => void;
}


export interface BoxProps {
style?: {
backgroundColor?: string;
}
}
export interface TextProps {
style?: {
color?: string;
}
}

export { ThemeUiTypes, ThemeActionTypes };
export default theme;
38 changes: 0 additions & 38 deletions src/core/StrictMode.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/core/ThemeUiContext.ts

This file was deleted.

Loading

0 comments on commit 62dc98a

Please sign in to comment.