app-studio 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +208 -0
  3. package/dist/app-studio.cjs.development.js +944 -0
  4. package/dist/app-studio.cjs.development.js.map +1 -0
  5. package/dist/app-studio.cjs.production.min.js +2 -0
  6. package/dist/app-studio.cjs.production.min.js.map +1 -0
  7. package/dist/app-studio.esm.js +907 -0
  8. package/dist/app-studio.esm.js.map +1 -0
  9. package/dist/components/Element.d.ts +30 -0
  10. package/dist/components/Image.d.ts +23 -0
  11. package/dist/components/Layout.d.ts +11 -0
  12. package/dist/components/Text.d.ts +23 -0
  13. package/dist/components/View.d.ts +32 -0
  14. package/dist/components/Wrapper.d.ts +4 -0
  15. package/dist/hooks/useMount.d.ts +1 -0
  16. package/dist/hooks/useResponsive.d.ts +9 -0
  17. package/dist/index.d.ts +8 -0
  18. package/dist/index.js +8 -0
  19. package/dist/providers/Responsive.d.ts +20 -0
  20. package/dist/providers/Theme.d.ts +19 -0
  21. package/dist/utils/colors.d.ts +14 -0
  22. package/dist/utils/env.d.ts +15 -0
  23. package/dist/utils/shadow.d.ts +103 -0
  24. package/dist/utils/typography.d.ts +46 -0
  25. package/package.json +114 -0
  26. package/src/components/Element.tsx +430 -0
  27. package/src/components/Image.tsx +56 -0
  28. package/src/components/Layout.tsx +49 -0
  29. package/src/components/Text.tsx +118 -0
  30. package/src/components/View.md +6 -0
  31. package/src/components/View.tsx +87 -0
  32. package/src/components/Wrapper.tsx +11 -0
  33. package/src/hooks/useMount.ts +6 -0
  34. package/src/hooks/useResponsive.ts +102 -0
  35. package/src/index.tsx +8 -0
  36. package/src/providers/Responsive.tsx +61 -0
  37. package/src/providers/Theme.tsx +73 -0
  38. package/src/types/module.d.ts +1 -0
  39. package/src/types/style.d.ts +696 -0
  40. package/src/utils/colors.ts +321 -0
  41. package/src/utils/env.ts +43 -0
  42. package/src/utils/shadow.ts +102 -0
  43. package/src/utils/typography.ts +45 -0
@@ -0,0 +1,87 @@
1
+ import React from 'react';
2
+ import { ViewElement } from './Element';
3
+ import {
4
+ GenericStyleProp,
5
+ ViewProps,
6
+ ViewStyle,
7
+ ResponsiveStyle,
8
+ } from '../types/style';
9
+ import { CSSProperties } from 'styled-components';
10
+
11
+ export interface ComponentViewProps
12
+ extends Omit<ViewProps, 'pointerEvents'>,
13
+ CSSProperties {
14
+ size?: number;
15
+ className?: string;
16
+ loading?: boolean;
17
+ style?: GenericStyleProp<ViewStyle>;
18
+ paddingHorizontal?: number | string;
19
+ marginHorizontal?: number | string;
20
+ paddingVertical?: number | string;
21
+ marginVertical?: number | string;
22
+ responsive?: ResponsiveStyle;
23
+ onPress?: () => void;
24
+ action?: string;
25
+ backgroundColor?: string;
26
+ }
27
+
28
+ export const View = (props: ComponentViewProps) => <ViewElement {...props} />;
29
+
30
+ export const SafeArea = View;
31
+
32
+ export const Scroll = (props: any) => <View overflow={'auto'} {...props} />;
33
+
34
+ export const Horizontal = (props: any) => (
35
+ <View display={'flex'} flexDirection="row" {...props} />
36
+ );
37
+ export const HorizontalScroll = (props: any) => (
38
+ <Horizontal overflowX="auto" {...props} />
39
+ );
40
+
41
+ export const Vertical = (props: any) => (
42
+ <View flexDirection="column" {...props} />
43
+ );
44
+
45
+ export const VerticalScroll = (props: any) => (
46
+ <Vertical overflowY="auto" {...props} />
47
+ );
48
+
49
+ export const Inline = (props: any) => (
50
+ <View
51
+ display={'flex'}
52
+ flexDirection="row"
53
+ wordBreak="break-word"
54
+ {...props}
55
+ />
56
+ );
57
+
58
+ export const Start = (props: any) => (
59
+ <View display={'flex'} alignSelf="flex-start" {...props} />
60
+ );
61
+
62
+ export const End = (props: any) => (
63
+ <View display={'flex'} alignSelf="flex-end" {...props} />
64
+ );
65
+
66
+ export const Center = (props: any) => (
67
+ <View
68
+ display={'flex'}
69
+ justifyContent="center"
70
+ alignItems={'center'}
71
+ {...props}
72
+ />
73
+ );
74
+
75
+ export const AlignStart = (props: any) => (
76
+ <View display={'flex'} justifyContent="flex-start" {...props} />
77
+ );
78
+
79
+ export const AlignCenter = (props: any) => (
80
+ <View display={'flex'} justifyContent="center" width={'100%'} {...props} />
81
+ );
82
+
83
+ export const AlignEnd = (props: any) => (
84
+ <View display={'flex'} justifyContent="flex-end" width={'100%'} {...props} />
85
+ );
86
+
87
+ export default View;
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ import { ResponsiveProvider, ThemeProvider } from '..';
3
+ export default class Wrapper extends React.Component<{}, {}> {
4
+ render() {
5
+ return (
6
+ <ThemeProvider>
7
+ <ResponsiveProvider>{this.props.children}</ResponsiveProvider>
8
+ </ThemeProvider>
9
+ );
10
+ }
11
+ }
@@ -0,0 +1,6 @@
1
+ import { useEffect } from 'react';
2
+ export const useMount = (callback: () => void) => {
3
+ useEffect(() => {
4
+ callback();
5
+ }, []);
6
+ };
@@ -0,0 +1,102 @@
1
+ import { useState } from 'react';
2
+ import {
3
+ useResponsiveContext,
4
+ ScreenOrientation,
5
+ ScreenSizeRange,
6
+ } from '../providers/Responsive';
7
+
8
+ import { useMount } from './useMount';
9
+
10
+ export const createQuery = (keyScreen: string, query: string, set: any) => {
11
+ const mql = window.matchMedia(query);
12
+ const onChange = () => {
13
+ if (!!mql.matches) {
14
+ set(keyScreen);
15
+ }
16
+ };
17
+
18
+ mql.addListener(onChange);
19
+ if (!!mql.matches) {
20
+ set(keyScreen);
21
+ }
22
+
23
+ return () => {
24
+ mql.removeListener(onChange);
25
+ };
26
+ };
27
+
28
+ export const useResponsive = () => {
29
+ const { breakpoints, devices } = useResponsiveContext();
30
+ const [screen, setScreen] = useState('xs');
31
+ const [orientation, setOrientation] = useState(
32
+ 'landscape' as ScreenOrientation
33
+ );
34
+
35
+ const keys = Object.keys(breakpoints);
36
+
37
+ useMount(() => {
38
+ const breakpointValue = keys
39
+ .map((breakpoint) => {
40
+ const value: ScreenSizeRange = {
41
+ breakpoint: breakpoint as keyof typeof breakpoints,
42
+ min: breakpoints[breakpoint],
43
+ max: 0,
44
+ };
45
+
46
+ return value;
47
+ })
48
+ .sort((a, b) => a.min - b.min);
49
+
50
+ breakpointValue.reduce((a, b) => {
51
+ if (b) a.max = b.min;
52
+
53
+ return b;
54
+ });
55
+
56
+ breakpointValue.map((sizeScreen: ScreenSizeRange) => {
57
+ createQuery(
58
+ sizeScreen.breakpoint,
59
+ `only screen ${
60
+ sizeScreen.min && sizeScreen.min >= 0
61
+ ? 'and (min-width:' + sizeScreen.min + 'px)'
62
+ : ''
63
+ } ${
64
+ sizeScreen.max && sizeScreen.max >= 0
65
+ ? 'and (max-width:' + sizeScreen.max + 'px)'
66
+ : ''
67
+ }`,
68
+ setScreen
69
+ );
70
+
71
+ // if (
72
+ // window.innerWidth >= sizeScreen.min &&
73
+ // window.innerWidth <= sizeScreen.max
74
+ // ) {
75
+ // setScreen(key as ScreenResponsiveConfig);
76
+ // }
77
+ });
78
+
79
+ createQuery(
80
+ 'landscape',
81
+ 'only screen and (orientation: landscape)',
82
+ setOrientation
83
+ );
84
+ createQuery(
85
+ 'portrait',
86
+ 'only screen and (orientation: portrait)',
87
+ setOrientation
88
+ );
89
+ });
90
+
91
+ const on = (device: keyof typeof devices) => {
92
+ return devices[device].includes(screen);
93
+ };
94
+
95
+ return {
96
+ breakpoints,
97
+ devices,
98
+ orientation,
99
+ screen,
100
+ on,
101
+ };
102
+ };
package/src/index.tsx ADDED
@@ -0,0 +1,8 @@
1
+ export * from './components/View';
2
+ export * from './components/Image';
3
+ export * from './components/Text';
4
+ export * from './hooks/useMount';
5
+ export * from './hooks/useResponsive';
6
+ export * from './providers/Responsive';
7
+ export * from './providers/Theme';
8
+ export * from './hooks/useMount';
@@ -0,0 +1,61 @@
1
+ import React, { ReactNode, createContext, useContext } from 'react';
2
+
3
+ export type ScreenSizeRange = {
4
+ breakpoint: string;
5
+ min: number;
6
+ max?: number;
7
+ };
8
+ export type ResponsiveConfig = Record<string, number>;
9
+ const defaultBreakpointsConfig: ResponsiveConfig = {
10
+ xs: 0,
11
+ sm: 340,
12
+ md: 560,
13
+ lg: 1080,
14
+ xl: 1300,
15
+ };
16
+
17
+ export type DeviceConfig = Record<string, string[]>;
18
+ const defaultDeviceConfig: DeviceConfig = {
19
+ mobile: ['xs', 'sm'],
20
+ tablet: ['md', 'lg'],
21
+ desktop: ['lg', 'xl'],
22
+ };
23
+
24
+ export type ScreenConfig = {
25
+ breakpoints: ResponsiveConfig;
26
+ devices: DeviceConfig;
27
+ };
28
+
29
+ export type ScreenOrientation = 'landscape' | 'portrait';
30
+
31
+ const defaultScreenConfig: ScreenConfig = {
32
+ breakpoints: defaultBreakpointsConfig,
33
+ devices: defaultDeviceConfig,
34
+ };
35
+
36
+ export const ResponsiveContext =
37
+ createContext<ScreenConfig>(defaultScreenConfig);
38
+
39
+ export const useResponsiveContext = () => useContext(ResponsiveContext);
40
+
41
+ export const ResponsiveProvider = ({
42
+ breakpoints = defaultBreakpointsConfig,
43
+ devices = defaultDeviceConfig,
44
+ children,
45
+ }: {
46
+ breakpoints?: ResponsiveConfig;
47
+ devices?: DeviceConfig;
48
+
49
+ children?: ReactNode;
50
+ }): React.ReactElement => {
51
+ return (
52
+ <ResponsiveContext.Provider
53
+ value={{
54
+ breakpoints,
55
+ devices,
56
+ }}
57
+ >
58
+ {children}
59
+ </ResponsiveContext.Provider>
60
+ );
61
+ };
@@ -0,0 +1,73 @@
1
+ import React, { ReactNode } from 'react';
2
+
3
+ import { createContext, useContext } from 'react';
4
+ import { palette as defaultPalette } from '../utils/colors';
5
+
6
+ type ColorConfig = Record<string, string>;
7
+
8
+ type VariantColorConfig = Record<string, Record<string, string>>;
9
+
10
+ const defaultColors: ColorConfig = {
11
+ white: '#FFFFFF',
12
+ black: '#000000',
13
+ };
14
+
15
+ export const ThemeContext = createContext<{
16
+ getColor: (color: string) => string;
17
+ colors: ColorConfig;
18
+ palette: VariantColorConfig;
19
+ }>({
20
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
21
+ getColor: (name: string) => {
22
+ return name;
23
+ },
24
+ colors: defaultColors,
25
+ palette: defaultPalette,
26
+ });
27
+
28
+ export const useTheme = () => useContext(ThemeContext);
29
+
30
+ export const ThemeProvider = ({
31
+ palette = defaultPalette,
32
+ colors = defaultColors,
33
+ children,
34
+ }: {
35
+ colors?: ColorConfig;
36
+ palette?: VariantColorConfig;
37
+ children?: ReactNode;
38
+ }): React.ReactElement => {
39
+ const getColor = (name: string) => {
40
+ // console.log('getColor', name);
41
+ if (name === 'transparent') return name;
42
+ try {
43
+ if (name.indexOf('.') !== -1) {
44
+ const keys = name.split('.');
45
+
46
+ if (palette && palette[keys[0]][keys[1]] !== undefined) {
47
+ return palette[keys[0]][keys[1]];
48
+ }
49
+ if (palette[keys[0]][parseInt(keys[1])] !== undefined) {
50
+ return palette[keys[0]][parseInt(keys[1])];
51
+ }
52
+ } else if (colors && colors[name] !== undefined) {
53
+ return colors[name];
54
+ }
55
+ } catch (e) {
56
+ console.log('Color ' + name + ' not found');
57
+ }
58
+
59
+ return name;
60
+ };
61
+
62
+ return (
63
+ <ThemeContext.Provider
64
+ value={{
65
+ getColor,
66
+ colors,
67
+ palette,
68
+ }}
69
+ >
70
+ {children}
71
+ </ThemeContext.Provider>
72
+ );
73
+ };
@@ -0,0 +1 @@
1
+ declare module 'enquire-js';