@sunggang/ui-lib 0.0.4 → 0.0.5

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 (109) hide show
  1. package/.eslintrc.json +18 -0
  2. package/.storybook/main.js +14 -0
  3. package/.storybook/preview.js +1 -0
  4. package/.storybook/tailwind-imports.css +81 -0
  5. package/components.json +15 -0
  6. package/package.json +8 -4
  7. package/postcss.config.js +10 -0
  8. package/project.json +31 -0
  9. package/src/components/ui/switch.tsx +27 -0
  10. package/src/index.ts +7 -0
  11. package/src/lib/DropImage/index.stories.tsx +42 -0
  12. package/src/lib/DropImage/index.tsx +110 -0
  13. package/src/lib/Modal/BaseModal.jsx +52 -0
  14. package/src/lib/Modal/ErrorContent.tsx +21 -0
  15. package/src/lib/Modal/FullScreenModal.jsx +39 -0
  16. package/src/lib/Modal/Modal.tsx +36 -0
  17. package/src/lib/Modal/ModalContent.tsx +60 -0
  18. package/src/lib/Modal/NoticeModal.jsx +91 -0
  19. package/src/lib/Modal/index.jsx +1 -0
  20. package/src/lib/Spin/index.tsx +20 -0
  21. package/src/lib/Switch/index.stories.tsx +24 -0
  22. package/src/lib/UploadImage/BaseTemplate.tsx +73 -0
  23. package/src/lib/UploadImage/CustomUpload.stories.tsx +52 -0
  24. package/src/lib/UploadImage/CustomUpload.tsx +95 -0
  25. package/src/lib/hello-server.tsx +4 -0
  26. package/src/lib/uiLibrary.spec.tsx +10 -0
  27. package/src/lib/uiLibrary.tsx +14 -0
  28. package/src/lib/utils.ts +6 -0
  29. package/src/server.ts +2 -0
  30. package/storybook-static/249.d700bcb8.iframe.bundle.js +95 -0
  31. package/storybook-static/249.d700bcb8.iframe.bundle.js.LICENSE.txt +25 -0
  32. package/storybook-static/249.d700bcb8.iframe.bundle.js.map +1 -0
  33. package/storybook-static/272.859c45b5.iframe.bundle.js +1 -0
  34. package/storybook-static/297.86b29044.iframe.bundle.js +1 -0
  35. package/storybook-static/301.7b83a51f.iframe.bundle.js +1 -0
  36. package/storybook-static/311.5beb2d3d.iframe.bundle.js +1 -0
  37. package/storybook-static/312.aa18d841.iframe.bundle.js +1 -0
  38. package/storybook-static/501.1fba3663.iframe.bundle.js +1 -0
  39. package/storybook-static/754.9ec23ac4.iframe.bundle.js +1 -0
  40. package/storybook-static/777.4b1d90f9.iframe.bundle.js +1 -0
  41. package/storybook-static/794.2230a3f3.iframe.bundle.js +1 -0
  42. package/storybook-static/852.18487f4c.iframe.bundle.js +402 -0
  43. package/storybook-static/852.18487f4c.iframe.bundle.js.LICENSE.txt +23 -0
  44. package/storybook-static/852.18487f4c.iframe.bundle.js.map +1 -0
  45. package/storybook-static/DropImage-index-stories.befa1b35.iframe.bundle.js +1 -0
  46. package/storybook-static/Switch-index-stories.9cfb2ba1.iframe.bundle.js +1 -0
  47. package/storybook-static/UploadImage-CustomUpload-stories.521444aa.iframe.bundle.js +1 -0
  48. package/storybook-static/favicon.svg +7 -0
  49. package/storybook-static/iframe.html +370 -0
  50. package/storybook-static/index.html +151 -0
  51. package/storybook-static/index.json +1 -0
  52. package/storybook-static/main.6f3c811b.iframe.bundle.js +1 -0
  53. package/storybook-static/project.json +1 -0
  54. package/storybook-static/runtime~main.28408b82.iframe.bundle.js +1 -0
  55. package/storybook-static/sb-addons/essentials-actions-2/manager-bundle.js +3 -0
  56. package/storybook-static/sb-addons/essentials-actions-2/manager-bundle.js.LEGAL.txt +0 -0
  57. package/storybook-static/sb-addons/essentials-backgrounds-3/manager-bundle.js +12 -0
  58. package/storybook-static/sb-addons/essentials-backgrounds-3/manager-bundle.js.LEGAL.txt +0 -0
  59. package/storybook-static/sb-addons/essentials-controls-1/manager-bundle.js +79 -0
  60. package/storybook-static/sb-addons/essentials-controls-1/manager-bundle.js.LEGAL.txt +28 -0
  61. package/storybook-static/sb-addons/essentials-measure-6/manager-bundle.js +3 -0
  62. package/storybook-static/sb-addons/essentials-measure-6/manager-bundle.js.LEGAL.txt +0 -0
  63. package/storybook-static/sb-addons/essentials-outline-7/manager-bundle.js +3 -0
  64. package/storybook-static/sb-addons/essentials-outline-7/manager-bundle.js.LEGAL.txt +0 -0
  65. package/storybook-static/sb-addons/essentials-toolbars-5/manager-bundle.js +3 -0
  66. package/storybook-static/sb-addons/essentials-toolbars-5/manager-bundle.js.LEGAL.txt +0 -0
  67. package/storybook-static/sb-addons/essentials-viewport-4/manager-bundle.js +3 -0
  68. package/storybook-static/sb-addons/essentials-viewport-4/manager-bundle.js.LEGAL.txt +0 -0
  69. package/storybook-static/sb-addons/storybook-core-server-presets-0/common-manager-bundle.js +3 -0
  70. package/storybook-static/sb-addons/storybook-core-server-presets-0/common-manager-bundle.js.LEGAL.txt +0 -0
  71. package/storybook-static/sb-common-assets/fonts.css +31 -0
  72. package/storybook-static/sb-common-assets/nunito-sans-bold-italic.woff2 +0 -0
  73. package/storybook-static/sb-common-assets/nunito-sans-bold.woff2 +0 -0
  74. package/storybook-static/sb-common-assets/nunito-sans-italic.woff2 +0 -0
  75. package/storybook-static/sb-common-assets/nunito-sans-regular.woff2 +0 -0
  76. package/storybook-static/sb-manager/WithTooltip-Y7J54OF7-KHQOWZXS.js +1 -0
  77. package/storybook-static/sb-manager/chunk-3F3RRPB3.js +347 -0
  78. package/storybook-static/sb-manager/chunk-62YMTM65.js +6 -0
  79. package/storybook-static/sb-manager/chunk-AQBE2B7B.js +183 -0
  80. package/storybook-static/sb-manager/chunk-Q3RBXCN3.js +231 -0
  81. package/storybook-static/sb-manager/chunk-XP3HGWTR.js +1 -0
  82. package/storybook-static/sb-manager/chunk-YME6VNXZ.js +9 -0
  83. package/storybook-static/sb-manager/formatter-B5HCVTEV-7DCBOGO6.js +58 -0
  84. package/storybook-static/sb-manager/globals-module-info.js +1 -0
  85. package/storybook-static/sb-manager/globals-runtime.js +1 -0
  86. package/storybook-static/sb-manager/globals.js +1 -0
  87. package/storybook-static/sb-manager/index.js +1 -0
  88. package/storybook-static/sb-manager/runtime.js +1 -0
  89. package/storybook-static/sb-manager/syntaxhighlighter-JOJW2KGS-WAFIMSO6.js +1 -0
  90. package/storybook-static/sb-preview/globals.js +1 -0
  91. package/storybook-static/sb-preview/runtime.js +128 -0
  92. package/tailwind.config.js +76 -0
  93. package/tsconfig.json +25 -0
  94. package/tsconfig.lib.json +29 -0
  95. package/tsconfig.storybook.json +31 -0
  96. package/index.esm.d.ts +0 -1
  97. package/index.esm.js +0 -5755
  98. package/src/index.d.ts +0 -4
  99. package/src/lib/DropImage/index.d.ts +0 -14
  100. package/src/lib/Modal/ErrorContent.d.ts +0 -7
  101. package/src/lib/Modal/Modal.d.ts +0 -7
  102. package/src/lib/Modal/ModalContent.d.ts +0 -10
  103. package/src/lib/Spin/index.d.ts +0 -5
  104. package/src/lib/UploadImage/BaseTemplate.d.ts +0 -7
  105. package/src/lib/UploadImage/CustomUpload.d.ts +0 -10
  106. package/src/lib/hello-server.d.ts +0 -1
  107. package/src/lib/uiLibrary.d.ts +0 -4
  108. package/src/server.d.ts +0 -1
  109. /package/{index.esm.css → src/lib/uiLibrary.module.css} +0 -0
@@ -0,0 +1 @@
1
+ export { default } from './Modal';
@@ -0,0 +1,20 @@
1
+ export function Spin(props: {
2
+ show: boolean;
3
+ overlayBackground?: 'bg-[#00000055]' | undefined;
4
+ }) {
5
+ const { show, overlayBackground = 'bg-[#00000055]' } = props;
6
+ return show ? (
7
+ <div
8
+ className={[
9
+ 'fixed flex justify-center items-center w-full h-full left-0 top-0 z-[9999] overflow-hidden',
10
+ overlayBackground,
11
+ ].join(' ')}
12
+ >
13
+ <div className="top-2/4 left-2/4">
14
+ <div className="w-10 h-10 rounded-full border-4 border-solid border-[#ffffff33] border-t-[#dbdbdb] animate-spin" />
15
+ </div>
16
+ </div>
17
+ ) : null;
18
+ }
19
+
20
+ export default Spin;
@@ -0,0 +1,24 @@
1
+ import type { Meta, StoryFn } from '@storybook/react';
2
+ import { Switch } from '../../components/ui/switch';
3
+
4
+ interface SwitchProps {
5
+ id?: string;
6
+ onCheckedChange?: () => void;
7
+ disabled: boolean;
8
+ }
9
+
10
+ export default {
11
+ component: Switch,
12
+ title: 'Switch',
13
+ } as Meta;
14
+
15
+ const Template: StoryFn<SwitchProps> = (args) => {
16
+ return <Switch {...args} />;
17
+ };
18
+
19
+ export const Base = Template.bind({});
20
+ Base.args = {
21
+ id: 'ad-123',
22
+ onCheckedChange: () => ({}),
23
+ disabled: false,
24
+ };
@@ -0,0 +1,73 @@
1
+ import { useState, useEffect, FC } from 'react';
2
+ import { Icon } from '@iconify/react';
3
+
4
+ interface BaseTemplateProps {
5
+ file?: File | null;
6
+ imageUrl?: string;
7
+ }
8
+
9
+ const BaseTemplate: FC<BaseTemplateProps> = ({ file, imageUrl }) => {
10
+ const [tempImage, setTempImage] = useState<string | null>(null);
11
+
12
+ useEffect(() => {
13
+ let fileReader: FileReader | null;
14
+ let isCancel = false;
15
+
16
+ if (file) {
17
+ fileReader = new FileReader();
18
+ fileReader.onload = (e) => {
19
+ const { result } = e.target as FileReader;
20
+ if (result && !isCancel) {
21
+ setTempImage(result.toString());
22
+ }
23
+ };
24
+ fileReader.readAsDataURL(file);
25
+ }
26
+ return () => {
27
+ setTempImage(null);
28
+ isCancel = true;
29
+ if (fileReader && fileReader.readyState === 1) {
30
+ fileReader.abort();
31
+ }
32
+ };
33
+ }, [file]);
34
+
35
+ return (
36
+ <div className="max-w-sm mx-auto bg-white rounded-lg shadow-md overflow-hidden items-center">
37
+ <div className="px-4 py-6 w-72 h-56">
38
+ {tempImage || imageUrl ? (
39
+ <img
40
+ className="w-full h-full object-contain border-dashed border-2 border-gray-400 p-6 rounded-lg"
41
+ src={tempImage || imageUrl}
42
+ alt=""
43
+ />
44
+ ) : (
45
+ <div
46
+ id="image-preview"
47
+ className="max-w-sm p-6 bg-gray-100 border-dashed border-2 border-gray-400 rounded-lg items-center mx-auto text-center cursor-pointer"
48
+ >
49
+ <div className="cursor-pointer">
50
+ <div className="flex justify-center">
51
+ <Icon
52
+ icon="material-symbols:upload"
53
+ width="2.5rem"
54
+ height="2.5rem"
55
+ />
56
+ </div>
57
+
58
+ <p className="font-normal text-sm text-gray-400 py-4">
59
+ 圖片僅支援 png、jpg、jpeg
60
+ </p>
61
+
62
+ <h5 className="mb-2 text-xl font-bold tracking-tight text-gray-700">
63
+ 上傳圖片
64
+ </h5>
65
+ </div>
66
+ </div>
67
+ )}
68
+ </div>
69
+ </div>
70
+ );
71
+ };
72
+
73
+ export default BaseTemplate;
@@ -0,0 +1,52 @@
1
+ import React, { useState } from 'react';
2
+ import type { Meta, StoryFn } from '@storybook/react';
3
+ import { CustomUpload } from './CustomUpload';
4
+
5
+ interface CustomUploadProps {
6
+ file?: File | null;
7
+ setFile?: any;
8
+ imageUrl?: string;
9
+ }
10
+
11
+ export default {
12
+ component: CustomUpload,
13
+ title: 'CustomUpload',
14
+ } as Meta;
15
+
16
+ const demoIcon =
17
+ 'https://gobobook.s3.ap-northeast-1.amazonaws.com/regions/DEV/vaadin_golf.svg';
18
+
19
+ const Template: StoryFn<CustomUploadProps> = (args) => {
20
+ const [file, setFile] = useState(null);
21
+ return <CustomUpload {...args} file={file} setFile={setFile} />;
22
+ };
23
+
24
+ const CustomerTemplate: StoryFn<CustomUploadProps> = (args) => {
25
+ const [file, setFile] = useState(null);
26
+ return (
27
+ <CustomUpload {...args} file={file} setFile={setFile}>
28
+ <div className="border border-solid border-gray-400 p-4">
29
+ <div>圖片僅支援 png、jpg、jpeg</div>
30
+ <div>點擊上傳</div>
31
+ </div>
32
+ </CustomUpload>
33
+ );
34
+ };
35
+
36
+ export const Base = Template.bind({});
37
+ Base.args = {
38
+ file: null,
39
+ setFile: () => {
40
+ return;
41
+ },
42
+ imageUrl: demoIcon,
43
+ };
44
+
45
+ export const Customer = CustomerTemplate.bind({});
46
+ Customer.args = {
47
+ file: null,
48
+ setFile: () => {
49
+ return;
50
+ },
51
+ imageUrl: '',
52
+ };
@@ -0,0 +1,95 @@
1
+ import React, { useState, useRef, ChangeEvent } from 'react';
2
+ import ErrorContent from '../Modal/ErrorContent';
3
+ import Modal from '../Modal';
4
+ import BaseTemplate from './BaseTemplate';
5
+
6
+
7
+ interface CustomUploadProps {
8
+ className?: string;
9
+ children?: React.ReactNode;
10
+ file?: File | null;
11
+ setFile?: any;
12
+ imageUrl?: string;
13
+ }
14
+
15
+ export const CustomUpload: React.FC<CustomUploadProps> = ({
16
+ className,
17
+ children,
18
+ file,
19
+ setFile,
20
+ imageUrl,
21
+ }) => {
22
+ const imageMimeType = /image\/(png|jpg|jpeg)/i;
23
+ const DEFAULT_IMAGE_SIZE_LIMIT_IN_BYTES = 5120000; // 5000 KB
24
+
25
+ const [modal, setModal] = useState<React.ReactNode | null>(null);
26
+
27
+ const hiddenFileInput = useRef<HTMLInputElement | null>(null);
28
+
29
+ const handleImageClick = () => {
30
+ hiddenFileInput.current?.click();
31
+ };
32
+
33
+ const handleImageChange = (event: ChangeEvent<HTMLInputElement>) => {
34
+ const currentFile = event.target.files?.[0];
35
+
36
+ if (!currentFile) {
37
+ setFile(null);
38
+ return;
39
+ }
40
+
41
+ if (currentFile && !currentFile.type?.match(imageMimeType)) {
42
+ setModal(
43
+ <ErrorContent setModal={setModal} errmsg="圖片僅支援 png、jpg、jpeg!" />
44
+ );
45
+ return;
46
+ }
47
+
48
+ if (currentFile && currentFile.size > DEFAULT_IMAGE_SIZE_LIMIT_IN_BYTES) {
49
+ setModal(
50
+ <ErrorContent
51
+ setModal={setModal}
52
+ errmsg={
53
+ <span>
54
+ 選擇的檔案大小:
55
+ {String((currentFile.size / 1024 / 1024).toFixed(3))}
56
+ {' MB'}
57
+ <br />
58
+ <hr />
59
+ 上限:
60
+ {String(
61
+ (DEFAULT_IMAGE_SIZE_LIMIT_IN_BYTES / 1024 / 1024).toFixed(3)
62
+ )}
63
+ {' MB'}
64
+ </span>
65
+ }
66
+ />
67
+ );
68
+ return;
69
+ }
70
+
71
+ setFile(currentFile);
72
+ };
73
+
74
+ return (
75
+ <>
76
+ <button
77
+ className={className ? [className].join(' ') : ''}
78
+ type="button"
79
+ onClick={handleImageClick}
80
+ >
81
+ {children || <BaseTemplate file={file} imageUrl={imageUrl} />}
82
+ <input
83
+ type="file"
84
+ ref={hiddenFileInput}
85
+ accept=".png, .jpg, .jpeg"
86
+ onChange={handleImageChange}
87
+ className="hidden"
88
+ />
89
+ </button>
90
+ {modal && <Modal modal={modal} unsetModal={setModal} />}
91
+ </>
92
+ );
93
+ };
94
+
95
+ export default CustomUpload;
@@ -0,0 +1,4 @@
1
+ // React server components are async so you make database or API calls.
2
+ export async function HelloServer() {
3
+ return <h1>Hello Server</h1>;
4
+ }
@@ -0,0 +1,10 @@
1
+ import { render } from '@testing-library/react';
2
+
3
+ import UiLibrary from './uiLibrary';
4
+
5
+ describe('UiLibrary', () => {
6
+ it('should render successfully', () => {
7
+ const { baseElement } = render(<UiLibrary />);
8
+ expect(baseElement).toBeTruthy();
9
+ });
10
+ });
@@ -0,0 +1,14 @@
1
+ import styles from './uiLibrary.module.css';
2
+
3
+ /* eslint-disable-next-line */
4
+ export interface UiLibraryProps {}
5
+
6
+ export function UiLibrary(props: UiLibraryProps) {
7
+ return (
8
+ <div className={styles['container']}>
9
+ <h1>Welcome to UiLibrary!</h1>
10
+ </div>
11
+ );
12
+ }
13
+
14
+ export default UiLibrary;
@@ -0,0 +1,6 @@
1
+ import { clsx, type ClassValue } from "clsx"
2
+ import { twMerge } from "tailwind-merge"
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs))
6
+ }
package/src/server.ts ADDED
@@ -0,0 +1,2 @@
1
+ // Use this file to export React server components
2
+ export * from './lib/hello-server';