app-studio 0.0.7 → 0.0.11

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.
@@ -1,102 +0,0 @@
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 DELETED
@@ -1,8 +0,0 @@
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';
@@ -1,61 +0,0 @@
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
- };
@@ -1,73 +0,0 @@
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
- };
@@ -1 +0,0 @@
1
- declare module 'enquire-js';