cpk-ui 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 (69) hide show
  1. package/README.md +27 -0
  2. package/components/modals/AlertDialog/AlertDialog.js +80 -0
  3. package/components/modals/AlertDialog/AlertDialog.stories.tsx +80 -0
  4. package/components/modals/AlertDialog/AlertDialog.tsx +194 -0
  5. package/components/modals/Snackbar/Snackbar.js +94 -0
  6. package/components/modals/Snackbar/Snackbar.stories.tsx +98 -0
  7. package/components/modals/Snackbar/Snackbar.tsx +174 -0
  8. package/components/modals/Snackbar/const.js +5 -0
  9. package/components/modals/Snackbar/const.ts +4 -0
  10. package/components/uis/Accordion/Accordion.js +11 -0
  11. package/components/uis/Accordion/Accordion.stories.tsx +38 -0
  12. package/components/uis/Accordion/Accordion.test.tsx +128 -0
  13. package/components/uis/Accordion/Accordion.tsx +58 -0
  14. package/components/uis/Accordion/AccordionItem.js +102 -0
  15. package/components/uis/Accordion/AccordionItem.tsx +213 -0
  16. package/components/uis/Button/Button.js +161 -0
  17. package/components/uis/Button/Button.stories.tsx +81 -0
  18. package/components/uis/Button/Button.test.tsx +560 -0
  19. package/components/uis/Button/Button.tsx +335 -0
  20. package/components/uis/Checkbox/Checkbox.js +70 -0
  21. package/components/uis/Checkbox/Checkbox.stories.tsx +46 -0
  22. package/components/uis/Checkbox/Checkbox.test.tsx +139 -0
  23. package/components/uis/Checkbox/Checkbox.tsx +150 -0
  24. package/components/uis/Icon/Icon.js +3780 -0
  25. package/components/uis/Icon/Icon.stories.tsx +45 -0
  26. package/components/uis/Icon/Icon.test.tsx +19 -0
  27. package/components/uis/Icon/Icon.tsx +3800 -0
  28. package/components/uis/Icon/Pretendard-Bold.otf +0 -0
  29. package/components/uis/Icon/Pretendard-Regular.otf +0 -0
  30. package/components/uis/Icon/Pretendard-Thin.otf +0 -0
  31. package/components/uis/Icon/cpk.ttf +0 -0
  32. package/components/uis/Icon/selection.json +1 -0
  33. package/components/uis/IconButton/IconButton.js +120 -0
  34. package/components/uis/IconButton/IconButton.test.tsx +165 -0
  35. package/components/uis/IconButton/IconButton.tsx +252 -0
  36. package/components/uis/LoadingIndicator/LoadingIndicator.js +24 -0
  37. package/components/uis/LoadingIndicator/LoadingIndicator.tsx +79 -0
  38. package/components/uis/Rating/Rating.js +53 -0
  39. package/components/uis/Rating/Rating.test.tsx +72 -0
  40. package/components/uis/Rating/Rating.tsx +155 -0
  41. package/components/uis/StatusbarBrightness/StatusBarBrightness.js +13 -0
  42. package/components/uis/StatusbarBrightness/StatusBarBrightness.test.tsx +41 -0
  43. package/components/uis/StatusbarBrightness/StatusBarBrightness.tsx +17 -0
  44. package/components/uis/Styled/StyledComponents.js +130 -0
  45. package/components/uis/Styled/StyledComponents.tsx +200 -0
  46. package/components/uis/SwitchToggle/SwitchToggle.js +126 -0
  47. package/components/uis/SwitchToggle/SwitchToggle.test.tsx +70 -0
  48. package/components/uis/SwitchToggle/SwitchToggle.tsx +224 -0
  49. package/components/uis/Typography/Typography.js +90 -0
  50. package/components/uis/Typography/Typography.test.tsx +58 -0
  51. package/components/uis/Typography/Typography.tsx +132 -0
  52. package/hooks/useDebouncedColorScheme.js +21 -0
  53. package/hooks/useDebouncedColorScheme.tsx +30 -0
  54. package/index.js +16 -0
  55. package/index.tsx +18 -0
  56. package/package.json +35 -0
  57. package/providers/ThemeProvider.js +106 -0
  58. package/providers/ThemeProvider.tsx +180 -0
  59. package/providers/index.js +62 -0
  60. package/providers/index.tsx +125 -0
  61. package/react-native.config.cjs +5 -0
  62. package/utils/colors.js +124 -0
  63. package/utils/colors.ts +127 -0
  64. package/utils/createCtx.js +15 -0
  65. package/utils/createCtx.tsx +26 -0
  66. package/utils/guards.js +44 -0
  67. package/utils/guards.ts +93 -0
  68. package/utils/theme.js +5 -0
  69. package/utils/theme.ts +33 -0
@@ -0,0 +1,124 @@
1
+ export const light = {
2
+ bg: {
3
+ basic: "#FFFFFF",
4
+ paper: "#EDEDED",
5
+ disabled: "#BEBEBE",
6
+ },
7
+ role: {
8
+ primary: "#1B1B1B",
9
+ secondary: "#3D8BFF",
10
+ accent: "#6BF3C5",
11
+ info: "#307EF1",
12
+ link: "#A351F4",
13
+ success: "#1CD66C",
14
+ warning: "#E2B101",
15
+ danger: "#F84444",
16
+ border: "#CCCCCC",
17
+ underlay: "rgba(0, 0, 0, 0.16)",
18
+ underlayContrast: "rgba(0, 0, 0, 0.8)",
19
+ },
20
+ text: {
21
+ basic: "#000000",
22
+ label: "#4D4D4D",
23
+ placeholder: "#787878",
24
+ disabled: "#BEBEBE",
25
+ validation: "#DA0000",
26
+ contrast: "#FFFFFF",
27
+ },
28
+ button: {
29
+ primary: {
30
+ bg: "#1B1B1B",
31
+ text: "#FFFFFF",
32
+ },
33
+ secondary: {
34
+ bg: "#3D8BFF",
35
+ text: "#FFFFFF",
36
+ },
37
+ success: {
38
+ bg: "#1CD66C",
39
+ text: "#FFFFFF",
40
+ },
41
+ danger: {
42
+ bg: "#F84444",
43
+ text: "#FFFFFF",
44
+ },
45
+ warning: {
46
+ bg: "#E2B101",
47
+ text: "#FFFFFF",
48
+ },
49
+ info: {
50
+ bg: "#307EF1",
51
+ text: "#FFFFFF",
52
+ },
53
+ light: {
54
+ bg: "#E8E8E8",
55
+ text: "#232323",
56
+ },
57
+ disabled: {
58
+ bg: "#EDEDED",
59
+ text: "#BEBEBE",
60
+ },
61
+ },
62
+ };
63
+ export const dark = {
64
+ bg: {
65
+ basic: "#242424",
66
+ paper: "#1E1D1D",
67
+ disabled: "#474747",
68
+ },
69
+ role: {
70
+ primary: "#FFFFFF",
71
+ secondary: "#3D8BFF",
72
+ accent: "#6BF3C5",
73
+ info: "#2998FF",
74
+ link: "#A351F4",
75
+ success: "#2FFA86",
76
+ warning: "#F4CC3E",
77
+ danger: "#FF3C3C",
78
+ border: "#363636",
79
+ underlay: "rgba(255, 255, 255, 0.16)",
80
+ underlayContrast: "rgba(255, 255, 255, 0.8)",
81
+ },
82
+ text: {
83
+ basic: "#FFFFFF",
84
+ label: "#BEBEBE",
85
+ placeholder: "#909090",
86
+ disabled: "#4D4D4D",
87
+ validation: "#FF2C2C",
88
+ contrast: "#000000",
89
+ },
90
+ button: {
91
+ primary: {
92
+ bg: "#FFFFFF",
93
+ text: "#000000",
94
+ },
95
+ secondary: {
96
+ bg: "#3D8BFF",
97
+ text: "#000000",
98
+ },
99
+ success: {
100
+ bg: "#2FFA86",
101
+ text: "#000000",
102
+ },
103
+ danger: {
104
+ bg: "#FF3C3C",
105
+ text: "#000000",
106
+ },
107
+ warning: {
108
+ bg: "#F4CC3E",
109
+ text: "#000000",
110
+ },
111
+ info: {
112
+ bg: "#2998FF",
113
+ text: "#000000",
114
+ },
115
+ light: {
116
+ bg: "#313131",
117
+ text: "#EBEBEB",
118
+ },
119
+ disabled: {
120
+ bg: "#292929",
121
+ text: "#474747",
122
+ },
123
+ },
124
+ };
@@ -0,0 +1,127 @@
1
+ export const light = {
2
+ bg: {
3
+ basic: "#FFFFFF",
4
+ paper: "#EDEDED",
5
+ disabled: "#BEBEBE",
6
+ },
7
+ role: {
8
+ primary: "#1B1B1B",
9
+ secondary: "#3D8BFF",
10
+ accent: "#6BF3C5",
11
+ info: "#307EF1",
12
+ link: "#A351F4",
13
+ success: "#1CD66C",
14
+ warning: "#E2B101",
15
+ danger: "#F84444",
16
+ border: "#CCCCCC",
17
+ underlay: "rgba(0, 0, 0, 0.16)",
18
+ underlayContrast: "rgba(0, 0, 0, 0.8)",
19
+ },
20
+ text: {
21
+ basic: "#000000",
22
+ label: "#4D4D4D",
23
+ placeholder: "#787878",
24
+ disabled: "#BEBEBE",
25
+ validation: "#DA0000",
26
+ contrast: "#FFFFFF",
27
+ },
28
+ button: {
29
+ primary: {
30
+ bg: "#1B1B1B",
31
+ text: "#FFFFFF",
32
+ },
33
+ secondary: {
34
+ bg: "#3D8BFF",
35
+ text: "#FFFFFF",
36
+ },
37
+ success: {
38
+ bg: "#1CD66C",
39
+ text: "#FFFFFF",
40
+ },
41
+ danger: {
42
+ bg: "#F84444",
43
+ text: "#FFFFFF",
44
+ },
45
+ warning: {
46
+ bg: "#E2B101",
47
+ text: "#FFFFFF",
48
+ },
49
+ info: {
50
+ bg: "#307EF1",
51
+ text: "#FFFFFF",
52
+ },
53
+ light: {
54
+ bg: "#E8E8E8",
55
+ text: "#232323",
56
+ },
57
+ disabled: {
58
+ bg: "#EDEDED",
59
+ text: "#BEBEBE",
60
+ },
61
+ },
62
+ };
63
+
64
+ export const dark: typeof light = {
65
+ bg: {
66
+ basic: "#242424",
67
+ paper: "#1E1D1D",
68
+ disabled: "#474747",
69
+ },
70
+ role: {
71
+ primary: "#FFFFFF",
72
+ secondary: "#3D8BFF",
73
+ accent: "#6BF3C5",
74
+ info: "#2998FF",
75
+ link: "#A351F4",
76
+ success: "#2FFA86",
77
+ warning: "#F4CC3E",
78
+ danger: "#FF3C3C",
79
+ border: "#363636",
80
+ underlay: "rgba(255, 255, 255, 0.16)",
81
+ underlayContrast: "rgba(255, 255, 255, 0.8)",
82
+ },
83
+ text: {
84
+ basic: "#FFFFFF",
85
+ label: "#BEBEBE",
86
+ placeholder: "#909090",
87
+ disabled: "#4D4D4D",
88
+ validation: "#FF2C2C",
89
+ contrast: "#000000",
90
+ },
91
+ button: {
92
+ primary: {
93
+ bg: "#FFFFFF",
94
+ text: "#000000",
95
+ },
96
+ secondary: {
97
+ bg: "#3D8BFF",
98
+ text: "#000000",
99
+ },
100
+ success: {
101
+ bg: "#2FFA86",
102
+ text: "#000000",
103
+ },
104
+ danger: {
105
+ bg: "#FF3C3C",
106
+ text: "#000000",
107
+ },
108
+ warning: {
109
+ bg: "#F4CC3E",
110
+ text: "#000000",
111
+ },
112
+ info: {
113
+ bg: "#2998FF",
114
+ text: "#000000",
115
+ },
116
+ light: {
117
+ bg: "#313131",
118
+ text: "#EBEBEB",
119
+ },
120
+ disabled: {
121
+ bg: "#292929",
122
+ text: "#474747",
123
+ },
124
+ },
125
+ };
126
+
127
+ export type Colors = typeof light;
@@ -0,0 +1,15 @@
1
+ import React from "react";
2
+ // create context with no upfront defaultValue
3
+ // without having to do undefined check all the time
4
+ function createCtx() {
5
+ const ctx = React.createContext(undefined);
6
+ function useCtx() {
7
+ const c = React.useContext(ctx);
8
+ if (!c) {
9
+ throw new Error("useTheme must be inside a ThemeProvider");
10
+ }
11
+ return c;
12
+ }
13
+ return [useCtx, ctx.Provider];
14
+ }
15
+ export default createCtx;
@@ -0,0 +1,26 @@
1
+ import React from "react";
2
+
3
+ type CreateCtx<A> = readonly [
4
+ () => A,
5
+ React.ProviderExoticComponent<React.ProviderProps<A | undefined>>
6
+ ];
7
+
8
+ // create context with no upfront defaultValue
9
+ // without having to do undefined check all the time
10
+ function createCtx<A>(): CreateCtx<A> {
11
+ const ctx = React.createContext<A | undefined>(undefined);
12
+
13
+ function useCtx(): A {
14
+ const c = React.useContext(ctx);
15
+
16
+ if (!c) {
17
+ throw new Error("useTheme must be inside a ThemeProvider");
18
+ }
19
+
20
+ return c;
21
+ }
22
+
23
+ return [useCtx, ctx.Provider] as const;
24
+ }
25
+
26
+ export default createCtx;
@@ -0,0 +1,44 @@
1
+ import React, { cloneElement } from "react";
2
+ import { Button, Image, Pressable, Text, TextInput, TouchableHighlight, TouchableOpacity, TouchableWithoutFeedback, View, } from "react-native";
3
+ import { Icon } from "../components/uis/Icon/Icon";
4
+ const getRootElementStyleType = (element) => {
5
+ if (React.isValidElement(element)) {
6
+ if (element.type === Text ||
7
+ element.type === TextInput ||
8
+ element.type === Icon) {
9
+ return "TextStyle";
10
+ }
11
+ if (element.type === Image ||
12
+ element.type === View ||
13
+ element.type === Button ||
14
+ element.type === TouchableHighlight ||
15
+ element.type === TouchableOpacity ||
16
+ element.type === Pressable ||
17
+ element.type === TouchableWithoutFeedback) {
18
+ return "ViewStyle";
19
+ }
20
+ }
21
+ return "unknown";
22
+ };
23
+ /**
24
+ * This function applies default colors to cloned element.
25
+ *
26
+ * @param {CloneElemColorsParams} params
27
+ * @returns {JSX.Element} - Cloned element with default colors if exists. Otherwise, null.
28
+ */
29
+ export const cloneElemWithDefaultColors = ({ element, color, backgroundColor, style, }) => {
30
+ return element
31
+ ? cloneElement(element, {
32
+ style: [
33
+ getRootElementStyleType(element) === "TextStyle" && {
34
+ color,
35
+ },
36
+ getRootElementStyleType(element) === "ViewStyle" && {
37
+ borderColor: color,
38
+ backgroundColor: backgroundColor,
39
+ },
40
+ { ...style, ...element.props.style },
41
+ ],
42
+ })
43
+ : null;
44
+ };
@@ -0,0 +1,93 @@
1
+ import React, { cloneElement } from "react";
2
+ import type { ViewStyle } from "react-native";
3
+ import {
4
+ Button,
5
+ Image,
6
+ Pressable,
7
+ Text,
8
+ TextInput,
9
+ TouchableHighlight,
10
+ TouchableOpacity,
11
+ TouchableWithoutFeedback,
12
+ View,
13
+ } from "react-native";
14
+ import { Icon } from "../components/uis/Icon/Icon";
15
+
16
+ const getRootElementStyleType = (
17
+ element: JSX.Element
18
+ ): "TextStyle" | "ViewStyle" | "unknown" => {
19
+ if (React.isValidElement(element)) {
20
+ if (
21
+ element.type === Text ||
22
+ element.type === TextInput ||
23
+ element.type === Icon
24
+ ) {
25
+ return "TextStyle";
26
+ }
27
+
28
+ if (
29
+ element.type === Image ||
30
+ element.type === View ||
31
+ element.type === Button ||
32
+ element.type === TouchableHighlight ||
33
+ element.type === TouchableOpacity ||
34
+ element.type === Pressable ||
35
+ element.type === TouchableWithoutFeedback
36
+ ) {
37
+ return "ViewStyle";
38
+ }
39
+ }
40
+
41
+ return "unknown";
42
+ };
43
+
44
+ type CloneElemColorsParams = {
45
+ /**
46
+ * ReactElement to be cloned to shape default colors.
47
+ */
48
+ element?: JSX.Element;
49
+ /**
50
+ * Text color to be applied.
51
+ * If not passed, default color will be applied.
52
+ * Invalid if element is ViewStyle.
53
+ */
54
+ color?: string;
55
+ /**
56
+ * Background color to be applied.
57
+ * If not passed, default color will be applied.
58
+ * Invalid if element is TextStyle.
59
+ */
60
+ backgroundColor?: string;
61
+ /**
62
+ * Extra style to be applied.
63
+ */
64
+ style?: ViewStyle;
65
+ };
66
+
67
+ /**
68
+ * This function applies default colors to cloned element.
69
+ *
70
+ * @param {CloneElemColorsParams} params
71
+ * @returns {JSX.Element} - Cloned element with default colors if exists. Otherwise, null.
72
+ */
73
+ export const cloneElemWithDefaultColors = ({
74
+ element,
75
+ color,
76
+ backgroundColor,
77
+ style,
78
+ }: CloneElemColorsParams): JSX.Element | null => {
79
+ return element
80
+ ? cloneElement(element, {
81
+ style: [
82
+ getRootElementStyleType(element) === "TextStyle" && {
83
+ color,
84
+ },
85
+ getRootElementStyleType(element) === "ViewStyle" && {
86
+ borderColor: color,
87
+ backgroundColor: backgroundColor,
88
+ },
89
+ { ...style, ...element.props.style },
90
+ ],
91
+ })
92
+ : null;
93
+ };
package/utils/theme.js ADDED
@@ -0,0 +1,5 @@
1
+ import { light } from './colors';
2
+ export const isEmptyObject = (param) => Object.keys(param).length === 0 && param.constructor === Object;
3
+ export const getTheme = (theme) => {
4
+ return isEmptyObject(theme) || theme === undefined ? light : theme;
5
+ };
package/utils/theme.ts ADDED
@@ -0,0 +1,33 @@
1
+ import {Colors, light} from './colors';
2
+
3
+ export type CpkTheme = Colors & {
4
+ isPortrait?: boolean;
5
+ isDesktop?: boolean;
6
+ isTablet?: boolean;
7
+ isMobile?: boolean;
8
+ };
9
+
10
+ type RecursivePartial<T> = {
11
+ [P in keyof T]?: RecursivePartial<T[P]>;
12
+ };
13
+
14
+ export type CpkThemeParams = RecursivePartial<CpkTheme>;
15
+
16
+ export type ThemeObjParams = {
17
+ bg: Partial<Colors['bg']>;
18
+ role: Partial<Colors['role']>;
19
+ text: Partial<Colors['text']>;
20
+ button: Partial<Colors['button']>;
21
+ };
22
+
23
+ export interface ThemeParam {
24
+ light?: Partial<ThemeObjParams & any>;
25
+ dark?: Partial<ThemeObjParams & any>;
26
+ }
27
+
28
+ export const isEmptyObject = (param: any): boolean =>
29
+ Object.keys(param).length === 0 && param.constructor === Object;
30
+
31
+ export const getTheme = (theme?: CpkTheme): CpkTheme => {
32
+ return isEmptyObject(theme) || theme === undefined ? light : theme;
33
+ };