tycho-components 0.0.4 → 0.0.5-SNAPSHOT
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.
- package/dist/AppColorpicker/AppColorpicker.d.ts +10 -0
- package/dist/AppColorpicker/AppColorpicker.js +21 -0
- package/{src/AppColorpicker/index.tsx → dist/AppColorpicker/index.d.ts} +0 -1
- package/dist/AppColorpicker/index.js +2 -0
- package/dist/AppEditable/AppEditable.d.ts +14 -0
- package/dist/AppEditable/AppEditable.js +80 -0
- package/dist/AppEditable/AppEditableField.d.ts +7 -0
- package/dist/AppEditable/AppEditableField.js +1 -0
- package/dist/AppEditable/FormField.d.ts +14 -0
- package/dist/AppEditable/FormField.js +8 -0
- package/dist/AppEditable/FormFieldOption.d.ts +7 -0
- package/dist/AppEditable/FormFieldOption.js +20 -0
- package/{src/AppEditable/index.tsx → dist/AppEditable/index.d.ts} +0 -1
- package/dist/AppEditable/index.js +2 -0
- package/dist/AppModal/AppModal.d.ts +20 -0
- package/dist/AppModal/AppModal.js +22 -0
- package/dist/AppModal/AppModalConfirm.d.ts +11 -0
- package/dist/AppModal/AppModalConfirm.js +20 -0
- package/dist/AppModal/AppModalRemove.d.ts +9 -0
- package/dist/AppModal/AppModalRemove.js +20 -0
- package/{src/AppModal/index.tsx → dist/AppModal/index.d.ts} +0 -1
- package/dist/AppModal/index.js +2 -0
- package/dist/AppToast/AppToast.d.ts +2 -0
- package/dist/AppToast/AppToast.js +78 -0
- package/dist/AppToast/ToastMessage.d.ts +8 -0
- package/dist/AppToast/ToastMessage.js +4 -0
- package/{src/AppToast/index.tsx → dist/AppToast/index.d.ts} +0 -1
- package/dist/AppToast/index.js +2 -0
- package/dist/Dummy/Dummy.d.ts +9 -0
- package/dist/Dummy/Dummy.js +8 -0
- package/{src/Dummy/index.tsx → dist/Dummy/index.d.ts} +0 -1
- package/dist/Dummy/index.js +2 -0
- package/dist/Participants/ParticipantCreate/ParticipantCreate.d.ts +9 -0
- package/dist/Participants/ParticipantCreate/ParticipantCreate.js +41 -0
- package/{src/Participants/ParticipantCreate/index.tsx → dist/Participants/ParticipantCreate/index.d.ts} +0 -1
- package/dist/Participants/ParticipantCreate/index.js +2 -0
- package/dist/Participants/ParticipantRemove/ParticipantRemove.d.ts +11 -0
- package/dist/Participants/ParticipantRemove/ParticipantRemove.js +26 -0
- package/{src/Participants/ParticipantRemove/index.tsx → dist/Participants/ParticipantRemove/index.d.ts} +0 -1
- package/dist/Participants/ParticipantRemove/index.js +2 -0
- package/dist/Participants/Participants.d.ts +9 -0
- package/dist/Participants/Participants.js +57 -0
- package/{src/Participants/index.tsx → dist/Participants/index.d.ts} +0 -1
- package/dist/Participants/index.js +2 -0
- package/dist/Participants/types/Participant.d.ts +27 -0
- package/dist/Participants/types/Participant.js +17 -0
- package/dist/Participants/types/ParticipantService.d.ts +11 -0
- package/dist/Participants/types/ParticipantService.js +12 -0
- package/dist/configs/CommonContext.d.ts +10 -0
- package/dist/configs/CommonContext.js +10 -0
- package/dist/configs/CookieStorage.d.ts +10 -0
- package/dist/configs/CookieStorage.js +28 -0
- package/dist/configs/Localization.d.ts +64 -0
- package/dist/configs/Localization.js +28 -0
- package/dist/configs/MessageUtils.d.ts +20 -0
- package/dist/configs/MessageUtils.js +30 -0
- package/dist/configs/Storage.d.ts +9 -0
- package/dist/configs/Storage.js +16 -0
- package/dist/configs/api.d.ts +2 -0
- package/dist/configs/api.js +38 -0
- package/dist/configs/localization/CommonTexts.d.ts +27 -0
- package/dist/configs/localization/CommonTexts.js +27 -0
- package/dist/configs/localization/ParticipantsTexts.d.ts +34 -0
- package/dist/configs/localization/ParticipantsTexts.js +34 -0
- package/dist/configs/store/actions.d.ts +4 -0
- package/dist/configs/store/actions.js +9 -0
- package/dist/configs/store/reducer.d.ts +3 -0
- package/dist/configs/store/reducer.js +19 -0
- package/dist/configs/store/store.d.ts +3 -0
- package/dist/configs/store/store.js +6 -0
- package/dist/configs/store/types.d.ts +13 -0
- package/dist/configs/store/types.js +4 -0
- package/dist/index.js +9 -0
- package/package.json +33 -24
- package/.eslintignore +0 -2
- package/.eslintrc.cjs +0 -28
- package/.eslintrc.json +0 -31
- package/.gitlab-ci.yml +0 -14
- package/.storybook/main.ts +0 -32
- package/.storybook/preview-head.html +0 -4
- package/.storybook/preview.css +0 -6
- package/.storybook/preview.tsx +0 -29
- package/src/AppColorpicker/AppColorpicker.tsx +0 -69
- package/src/AppEditable/AppEditable.tsx +0 -280
- package/src/AppEditable/AppEditableField.ts +0 -7
- package/src/AppEditable/FormField.ts +0 -26
- package/src/AppEditable/FormFieldOption.ts +0 -38
- package/src/AppModal/AppModal.tsx +0 -93
- package/src/AppModal/AppModalConfirm.tsx +0 -62
- package/src/AppModal/AppModalRemove.tsx +0 -51
- package/src/AppToast/AppToast.tsx +0 -94
- package/src/AppToast/ToastMessage.ts +0 -9
- package/src/Dummy/Dummy.stories.tsx +0 -21
- package/src/Dummy/Dummy.tsx +0 -16
- package/src/Participants/ParticipantCreate/ParticipantCreate.tsx +0 -83
- package/src/Participants/ParticipantRemove/ParticipantRemove.tsx +0 -51
- package/src/Participants/Participants.stories.tsx +0 -45
- package/src/Participants/Participants.tsx +0 -145
- package/src/Participants/types/Participant.ts +0 -43
- package/src/Participants/types/ParticipantService.ts +0 -18
- package/src/configs/CommonContext.tsx +0 -23
- package/src/configs/CookieStorage.ts +0 -36
- package/src/configs/Localization.ts +0 -30
- package/src/configs/MessageUtils.ts +0 -60
- package/src/configs/Storage.ts +0 -21
- package/src/configs/api.ts +0 -49
- package/src/configs/localization/CommonTexts.ts +0 -27
- package/src/configs/localization/ParticipantsTexts.ts +0 -40
- package/src/configs/store/actions.ts +0 -12
- package/src/configs/store/reducer.ts +0 -22
- package/src/configs/store/store.ts +0 -9
- package/src/configs/store/types.ts +0 -16
- package/src/react-app-env.d.ts +0 -5
- package/src/vite-env.d.ts +0 -13
- package/stories/Configure.mdx +0 -171
- package/stories/StorybookUtils.tsx +0 -40
- package/tsconfig.json +0 -31
- package/tsconfig.node.json +0 -10
- package/vite.config.ts +0 -26
- /package/{src → dist}/AppColorpicker/style.scss +0 -0
- /package/{src → dist}/AppEditable/style.scss +0 -0
- /package/{src → dist}/AppModal/style.scss +0 -0
- /package/{src → dist}/AppToast/style.scss +0 -0
- /package/{src → dist}/Dummy/styles.scss +0 -0
- /package/{src → dist}/Participants/ParticipantCreate/style.scss +0 -0
- /package/{src → dist}/Participants/ParticipantRemove/style.scss +0 -0
- /package/{src → dist}/Participants/style.scss +0 -0
- /package/{src/index.ts → dist/index.d.ts} +0 -0
- /package/{src → dist}/new-styles/base/_borders.scss +0 -0
- /package/{src → dist}/new-styles/base/_colors.scss +0 -0
- /package/{src → dist}/new-styles/base/_displays.scss +0 -0
- /package/{src → dist}/new-styles/base/_margins.css +0 -0
- /package/{src → dist}/new-styles/base/_spacing.scss +0 -0
- /package/{src → dist}/new-styles/base/_tokens.scss +0 -0
- /package/{src → dist}/new-styles/base/_typographs.scss +0 -0
- /package/{src → dist}/new-styles/main.scss +0 -0
- /package/{src → dist}/styles/_variables.scss +0 -0
- /package/{src → dist}/styles/bootstrap.min.css +0 -0
- /package/{src → dist}/styles/main.scss +0 -0
package/package.json
CHANGED
|
@@ -1,39 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tycho-components",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
5
|
-
"main": "
|
|
4
|
+
"version": "0.0.5-SNAPSHOT",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/"
|
|
16
|
+
],
|
|
6
17
|
"dependencies": {
|
|
7
|
-
"@emotion/react": "^11.13.3",
|
|
8
|
-
"@emotion/styled": "^11.13.0",
|
|
9
18
|
"@fortawesome/fontawesome-svg-core": "^6.4.2",
|
|
10
19
|
"@fortawesome/free-regular-svg-icons": "^6.4.2",
|
|
11
20
|
"@fortawesome/free-solid-svg-icons": "^6.4.2",
|
|
12
21
|
"@fortawesome/react-fontawesome": "^0.2.0",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
22
|
+
"axios": "^1.7.7",
|
|
23
|
+
"classnames": "^2.5.1",
|
|
24
|
+
"date-fns": "^2.29.1",
|
|
25
|
+
"date-fns-tz": "^1.3.6",
|
|
26
|
+
"js-cookie": "^3.0.5",
|
|
27
|
+
"react-colorful": "^5.6.1",
|
|
28
|
+
"react-easy-edit": "^2.0.0",
|
|
29
|
+
"react-loading": "^2.0.3",
|
|
30
|
+
"react-switch": "^7.1.0",
|
|
31
|
+
"react-toastify": "^9.1.3",
|
|
32
|
+
"tycho-storybook": "0.1.2-SNAPSHOT-3"
|
|
16
33
|
},
|
|
17
34
|
"peerDependencies": {
|
|
35
|
+
"@emotion/react": "^11.13.3",
|
|
36
|
+
"@emotion/styled": "^11.13.0",
|
|
18
37
|
"@hookform/resolvers": "^3.1.1",
|
|
38
|
+
"@mui/icons-material": "6.1.5",
|
|
39
|
+
"@mui/material": "6.1.5",
|
|
19
40
|
"bootstrap": "^5.3.1",
|
|
20
|
-
"classnames": "^2.5.1",
|
|
21
|
-
"date-fns": "^2.29.1",
|
|
22
|
-
"date-fns-tz": "^1.3.6",
|
|
23
41
|
"i18next": "^23.3.0",
|
|
24
42
|
"i18next-browser-languagedetector": "^7.1.0",
|
|
25
|
-
"js-cookie": "^3.0.5",
|
|
26
43
|
"react": ">=17 <19",
|
|
27
44
|
"react-bootstrap": "^2.8.0",
|
|
28
|
-
"react-colorful": "^5.6.1",
|
|
29
45
|
"react-dom": ">=17 <19",
|
|
30
|
-
"react-easy-edit": "^2.0.0",
|
|
31
46
|
"react-hook-form": "^7.45.2",
|
|
32
47
|
"react-i18next": "^13.0.2",
|
|
33
|
-
"react-loading": "^2.0.3",
|
|
34
|
-
"react-switch": "^7.1.0",
|
|
35
|
-
"react-toastify": "^9.1.3",
|
|
36
|
-
"tycho-storybook": "0.0.33",
|
|
37
48
|
"yup": "^1.2.0"
|
|
38
49
|
},
|
|
39
50
|
"devDependencies": {
|
|
@@ -51,7 +62,6 @@
|
|
|
51
62
|
"@types/react-dom": "^18.2.0",
|
|
52
63
|
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
53
64
|
"@typescript-eslint/parser": "^5.62.0",
|
|
54
|
-
"@vitejs/plugin-react": "^4.1.1",
|
|
55
65
|
"eslint": "^8.57.1",
|
|
56
66
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
57
67
|
"eslint-plugin-react-refresh": "^0.4.1",
|
|
@@ -59,14 +69,13 @@
|
|
|
59
69
|
"react": "^18.2.0",
|
|
60
70
|
"react-dom": "^18.2.0",
|
|
61
71
|
"storybook": "^7.5.3",
|
|
62
|
-
"typescript": "^5.
|
|
63
|
-
"vite": "^4.5.0",
|
|
64
|
-
"vite-plugin-checker": "^0.6.1",
|
|
65
|
-
"vite-plugin-svgr": "^3.2.0",
|
|
66
|
-
"vitest": "^0.33.0"
|
|
72
|
+
"typescript": "^5.7.3"
|
|
67
73
|
},
|
|
68
74
|
"scripts": {
|
|
69
75
|
"start": "storybook dev -p 6006",
|
|
70
|
-
"build-storybook": "storybook build"
|
|
76
|
+
"build-storybook": "storybook build",
|
|
77
|
+
"build": "tsc && node scripts/copy-package-json.js && npm run copy-css",
|
|
78
|
+
"build-publish": "tsc && npm run copy-css",
|
|
79
|
+
"copy-css": "node scripts/copy-css.js"
|
|
71
80
|
}
|
|
72
81
|
}
|
package/.eslintignore
DELETED
package/.eslintrc.cjs
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/* eslint-env node */
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
root: true,
|
|
5
|
-
env: { browser: true, es2020: true },
|
|
6
|
-
extends: [
|
|
7
|
-
"eslint:recommended",
|
|
8
|
-
"plugin:@typescript-eslint/recommended",
|
|
9
|
-
"plugin:@typescript-eslint/recommended-requiring-type-checking",
|
|
10
|
-
"plugin:react-hooks/recommended",
|
|
11
|
-
],
|
|
12
|
-
parser: "@/typescript-eslint/parser",
|
|
13
|
-
parserOptions: {
|
|
14
|
-
ecmaVersion: "latest",
|
|
15
|
-
sourceType: "module",
|
|
16
|
-
project: true,
|
|
17
|
-
tsconfigRootDir: __dirname,
|
|
18
|
-
},
|
|
19
|
-
plugins: ["react-refresh"],
|
|
20
|
-
rules: {
|
|
21
|
-
"react-refresh/only-export-components": [
|
|
22
|
-
"warn",
|
|
23
|
-
{ allowConstantExport: true },
|
|
24
|
-
],
|
|
25
|
-
"@/typescript-eslint/no-non-null-assertion": "off",
|
|
26
|
-
"@/typescript-eslint/no-empty-function": "off",
|
|
27
|
-
},
|
|
28
|
-
};
|
package/.eslintrc.json
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"root": true,
|
|
3
|
-
"env": {
|
|
4
|
-
"browser": true,
|
|
5
|
-
"es2020": true
|
|
6
|
-
},
|
|
7
|
-
"extends": [
|
|
8
|
-
"eslint:recommended",
|
|
9
|
-
"plugin:@typescript-eslint/recommended",
|
|
10
|
-
"plugin:@typescript-eslint/recommended-requiring-type-checking",
|
|
11
|
-
"plugin:react-hooks/recommended",
|
|
12
|
-
"plugin:storybook/recommended"
|
|
13
|
-
],
|
|
14
|
-
"parser": "@typescript-eslint/parser",
|
|
15
|
-
"parserOptions": {
|
|
16
|
-
"ecmaVersion": "latest",
|
|
17
|
-
"sourceType": "module",
|
|
18
|
-
"project": "./tsconfig.json",
|
|
19
|
-
"tsconfigRootDir": "."
|
|
20
|
-
},
|
|
21
|
-
"plugins": ["react-refresh"],
|
|
22
|
-
"rules": {
|
|
23
|
-
"react-hooks/exhaustive-deps": "off",
|
|
24
|
-
"react-refresh/only-export-components": [
|
|
25
|
-
"warn",
|
|
26
|
-
{ "allowConstantExport": true }
|
|
27
|
-
],
|
|
28
|
-
"@typescript-eslint/no-non-null-assertion": "off",
|
|
29
|
-
"@typescript-eslint/no-empty-function": "off"
|
|
30
|
-
}
|
|
31
|
-
}
|
package/.gitlab-ci.yml
DELETED
package/.storybook/main.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { StorybookConfig } from '@storybook/react-vite';
|
|
2
|
-
|
|
3
|
-
import { join, dirname } from 'path';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* This function is used to resolve the absolute path of a package.
|
|
7
|
-
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
|
|
8
|
-
*/
|
|
9
|
-
function getAbsolutePath(value: string): any {
|
|
10
|
-
return dirname(require.resolve(join(value, 'package.json')));
|
|
11
|
-
}
|
|
12
|
-
const config: StorybookConfig = {
|
|
13
|
-
stories: [
|
|
14
|
-
'../stories/**/*.mdx',
|
|
15
|
-
'../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)',
|
|
16
|
-
'../**/**/*.stories.@(js|jsx|mjs|ts|tsx)',
|
|
17
|
-
],
|
|
18
|
-
addons: [
|
|
19
|
-
getAbsolutePath('@storybook/addon-links'),
|
|
20
|
-
getAbsolutePath('@storybook/addon-essentials'),
|
|
21
|
-
getAbsolutePath('@storybook/addon-onboarding'),
|
|
22
|
-
getAbsolutePath('@storybook/addon-interactions'),
|
|
23
|
-
],
|
|
24
|
-
framework: {
|
|
25
|
-
name: getAbsolutePath('@storybook/react-vite'),
|
|
26
|
-
options: {},
|
|
27
|
-
},
|
|
28
|
-
docs: {
|
|
29
|
-
autodocs: 'tag',
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
export default config;
|
package/.storybook/preview.css
DELETED
package/.storybook/preview.tsx
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { Preview } from '@storybook/react';
|
|
2
|
-
import { CommonProvider } from '../src/configs/CommonContext';
|
|
3
|
-
import commonLocalization from '../src/configs/Localization';
|
|
4
|
-
import '../src/styles/bootstrap.min.css';
|
|
5
|
-
import '../src/styles/main.scss';
|
|
6
|
-
import './preview.css';
|
|
7
|
-
|
|
8
|
-
commonLocalization();
|
|
9
|
-
|
|
10
|
-
const preview: Preview = {
|
|
11
|
-
parameters: {
|
|
12
|
-
actions: { argTypesRegex: '^on[A-Z].*' },
|
|
13
|
-
controls: {
|
|
14
|
-
matchers: {
|
|
15
|
-
color: /(background|color)$/i,
|
|
16
|
-
date: /Date$/i,
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
decorators: [
|
|
21
|
-
(Story) => (
|
|
22
|
-
<CommonProvider>
|
|
23
|
-
<Story />
|
|
24
|
-
</CommonProvider>
|
|
25
|
-
),
|
|
26
|
-
],
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export default preview;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { FieldValue } from '../AppEditable/FormFieldOption';
|
|
2
|
-
import { useEffect, useState } from 'react';
|
|
3
|
-
import { HexColorPicker } from 'react-colorful';
|
|
4
|
-
import { useTranslation } from 'react-i18next';
|
|
5
|
-
import FormField from '../AppEditable/FormField';
|
|
6
|
-
import './style.scss';
|
|
7
|
-
|
|
8
|
-
const defaultColor = '#FFFFFF';
|
|
9
|
-
|
|
10
|
-
type AppColorpickerProps = {
|
|
11
|
-
item: Record<string, unknown>;
|
|
12
|
-
field: FormField;
|
|
13
|
-
handleSave: (value: FieldValue, field: FormField) => void;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export default function AppColorpicker({
|
|
17
|
-
field,
|
|
18
|
-
item,
|
|
19
|
-
handleSave,
|
|
20
|
-
}: AppColorpickerProps) {
|
|
21
|
-
const { t } = useTranslation('common');
|
|
22
|
-
const [openColor, setOpenColor] = useState(false);
|
|
23
|
-
const [color, setColor] = useState(defaultColor);
|
|
24
|
-
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
if (item[field.name]) setColor(item[field.name] as string);
|
|
27
|
-
else setColor(defaultColor);
|
|
28
|
-
}, [item]);
|
|
29
|
-
|
|
30
|
-
return (
|
|
31
|
-
<div className="color-picker-container">
|
|
32
|
-
<div
|
|
33
|
-
className="swatch"
|
|
34
|
-
style={{ backgroundColor: color }}
|
|
35
|
-
onClick={() => setOpenColor(!openColor)}
|
|
36
|
-
onKeyDown={() => setOpenColor(!openColor)}
|
|
37
|
-
role="link"
|
|
38
|
-
aria-label="open color picker"
|
|
39
|
-
tabIndex={0}
|
|
40
|
-
/>
|
|
41
|
-
{openColor && (
|
|
42
|
-
<>
|
|
43
|
-
<HexColorPicker color={color} onChange={setColor} />
|
|
44
|
-
<div className="buttons">
|
|
45
|
-
<button
|
|
46
|
-
type="button"
|
|
47
|
-
className="easy-edit-button"
|
|
48
|
-
name="save"
|
|
49
|
-
onClick={() => {
|
|
50
|
-
handleSave(color, field);
|
|
51
|
-
setOpenColor(false);
|
|
52
|
-
}}
|
|
53
|
-
>
|
|
54
|
-
{t('button.confirm')}
|
|
55
|
-
</button>
|
|
56
|
-
<button
|
|
57
|
-
type="button"
|
|
58
|
-
className="easy-edit-button"
|
|
59
|
-
name="cancel"
|
|
60
|
-
onClick={() => setOpenColor(false)}
|
|
61
|
-
>
|
|
62
|
-
{t('button.cancel')}
|
|
63
|
-
</button>
|
|
64
|
-
</div>
|
|
65
|
-
</>
|
|
66
|
-
)}
|
|
67
|
-
</div>
|
|
68
|
-
);
|
|
69
|
-
}
|
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import { faQuestionCircle } from '@fortawesome/free-solid-svg-icons';
|
|
2
|
-
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
3
|
-
import { format } from 'date-fns-tz';
|
|
4
|
-
import EasyEdit from 'react-easy-edit';
|
|
5
|
-
import { useTranslation } from 'react-i18next';
|
|
6
|
-
import Switch from 'react-switch';
|
|
7
|
-
import AppColorpicker from '../AppColorpicker';
|
|
8
|
-
import AppEditableField from './AppEditableField';
|
|
9
|
-
import FormField from './FormField';
|
|
10
|
-
import FormFieldOption, { FieldValue } from './FormFieldOption';
|
|
11
|
-
import './style.scss';
|
|
12
|
-
|
|
13
|
-
type ItemValue = unknown;
|
|
14
|
-
type Item = {
|
|
15
|
-
[key: string]: ItemValue | Item;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
type Props = {
|
|
19
|
-
translation: string;
|
|
20
|
-
item: Record<string, unknown>;
|
|
21
|
-
fields: FormField[];
|
|
22
|
-
save?: (field: AppEditableField) => void;
|
|
23
|
-
group?: string;
|
|
24
|
-
className?: string;
|
|
25
|
-
reference?: string;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export default function AppEditable({
|
|
29
|
-
translation,
|
|
30
|
-
fields,
|
|
31
|
-
item,
|
|
32
|
-
save,
|
|
33
|
-
group,
|
|
34
|
-
className,
|
|
35
|
-
reference,
|
|
36
|
-
}: Props) {
|
|
37
|
-
const { t } = useTranslation([translation, 'common']);
|
|
38
|
-
|
|
39
|
-
const formatDate = (date: Date | null, fmt: string) => {
|
|
40
|
-
if (!date) return '';
|
|
41
|
-
return format(date, fmt);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const handleSave = (value: FieldValue, field: FormField) => {
|
|
45
|
-
save &&
|
|
46
|
-
save({
|
|
47
|
-
uid: item.uid as string,
|
|
48
|
-
name: field.name,
|
|
49
|
-
type: field.type,
|
|
50
|
-
value,
|
|
51
|
-
ref: reference ? (item[reference] as string) : undefined,
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const getDateValue = (field: FormField) => {
|
|
56
|
-
const v = getValue(field) as string;
|
|
57
|
-
return !v ? null : formatDate(new Date(v), 'yyyy-MM-dd');
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const getValue = (field: FormField): unknown => {
|
|
61
|
-
if (field.name.indexOf('.') === -1) {
|
|
62
|
-
if (!isEmptyValue(item, field.name)) return item[field.name];
|
|
63
|
-
return field.default !== undefined ? field.default : null;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const splits = field.name.split('.');
|
|
67
|
-
let val: unknown = item;
|
|
68
|
-
for (const split of splits) {
|
|
69
|
-
if (typeof val === 'object' && val !== null && split in val) {
|
|
70
|
-
val = (val as Item)[split];
|
|
71
|
-
} else {
|
|
72
|
-
val = undefined;
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (val !== undefined && val !== '') return val;
|
|
78
|
-
return field.default !== undefined ? field.default : null;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
const isEmptyValue = (thisItem: Item, thisName: string) =>
|
|
82
|
-
thisItem[thisName] === undefined || thisItem[thisName] === '';
|
|
83
|
-
|
|
84
|
-
const getValueToDisplay = (field: FormField): React.ReactNode => {
|
|
85
|
-
const value = getValue(field);
|
|
86
|
-
|
|
87
|
-
if (field.options && field.options.length > 0) {
|
|
88
|
-
const option = field.options.find((op) => op.value === value);
|
|
89
|
-
if (option) return option.label;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Fallback — if value is a string, number, or boolean, display it.
|
|
93
|
-
if (
|
|
94
|
-
typeof value === 'string' ||
|
|
95
|
-
typeof value === 'number' ||
|
|
96
|
-
typeof value === 'boolean'
|
|
97
|
-
) {
|
|
98
|
-
return value;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return null;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const getLabelValueForList = (options: FormFieldOption[]) => {
|
|
105
|
-
return options.map((op) => ({
|
|
106
|
-
label: t(op.label),
|
|
107
|
-
value: op.value,
|
|
108
|
-
}));
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
return (
|
|
112
|
-
<>
|
|
113
|
-
{fields.map((field: FormField, idx: number) => (
|
|
114
|
-
<div
|
|
115
|
-
className={`editable-container ${className || ''}`}
|
|
116
|
-
key={idx.valueOf()}
|
|
117
|
-
>
|
|
118
|
-
<div className="title">
|
|
119
|
-
<h6>
|
|
120
|
-
{field.title
|
|
121
|
-
? field.title
|
|
122
|
-
: t(`${translation}:${group || ''}.field.${field.name}`)}
|
|
123
|
-
{field.required && <span>*</span>}
|
|
124
|
-
</h6>
|
|
125
|
-
|
|
126
|
-
{field.tooltip && (
|
|
127
|
-
<FontAwesomeIcon
|
|
128
|
-
icon={faQuestionCircle}
|
|
129
|
-
className="info"
|
|
130
|
-
title={field.tooltip}
|
|
131
|
-
/>
|
|
132
|
-
)}
|
|
133
|
-
</div>
|
|
134
|
-
|
|
135
|
-
{field.type === 'display' ? (
|
|
136
|
-
<span>{getValueToDisplay(field) ?? '--'}</span>
|
|
137
|
-
) : null}
|
|
138
|
-
|
|
139
|
-
{field.type === 'code' ? (
|
|
140
|
-
<div className="textarea-code">
|
|
141
|
-
<EasyEdit
|
|
142
|
-
type="textarea"
|
|
143
|
-
onSave={(value: string) =>
|
|
144
|
-
handleSave(JSON.parse(value) as FieldValue, field)
|
|
145
|
-
}
|
|
146
|
-
saveButtonLabel={t('common:button.confirm')}
|
|
147
|
-
cancelButtonLabel={t('common:button.cancel')}
|
|
148
|
-
value={JSON.stringify(getValue(field) || {})}
|
|
149
|
-
placeholder={t('common:placeholder.input')}
|
|
150
|
-
/>
|
|
151
|
-
</div>
|
|
152
|
-
) : null}
|
|
153
|
-
|
|
154
|
-
{(field.type === 'text' ||
|
|
155
|
-
field.type === 'number' ||
|
|
156
|
-
field.type === 'locale' ||
|
|
157
|
-
field.type === 'year') && (
|
|
158
|
-
<EasyEdit
|
|
159
|
-
type="text"
|
|
160
|
-
onSave={(value: string) => handleSave(value, field)}
|
|
161
|
-
saveButtonLabel={t('common:button.confirm')}
|
|
162
|
-
cancelButtonLabel={t('common:button.cancel')}
|
|
163
|
-
value={getValue(field)}
|
|
164
|
-
placeholder={t('common:placeholder.input')}
|
|
165
|
-
/>
|
|
166
|
-
)}
|
|
167
|
-
|
|
168
|
-
{field.type === 'textarea' ? (
|
|
169
|
-
<EasyEdit
|
|
170
|
-
type="textarea"
|
|
171
|
-
onSave={(value: string) => handleSave(value, field)}
|
|
172
|
-
saveButtonLabel={t('common:button.confirm')}
|
|
173
|
-
cancelButtonLabel={t('common:button.cancel')}
|
|
174
|
-
value={getValue(field)}
|
|
175
|
-
placeholder={t('common:placeholder.input')}
|
|
176
|
-
/>
|
|
177
|
-
) : null}
|
|
178
|
-
|
|
179
|
-
{field.type === 'select' || field.type === 'list' ? (
|
|
180
|
-
<EasyEdit
|
|
181
|
-
type="select"
|
|
182
|
-
options={getLabelValueForList(field.options || [])}
|
|
183
|
-
onSave={(value: string) => handleSave(value, field)}
|
|
184
|
-
saveButtonLabel={t('common:button.confirm')}
|
|
185
|
-
cancelButtonLabel={t('common:button.cancel')}
|
|
186
|
-
placeholder={t('common:placeholder.input')}
|
|
187
|
-
value={getValue(field)}
|
|
188
|
-
/>
|
|
189
|
-
) : null}
|
|
190
|
-
|
|
191
|
-
{field.type === 'range' ? (
|
|
192
|
-
<EasyEdit
|
|
193
|
-
type="range"
|
|
194
|
-
onSave={(value: string) => handleSave(value, field)}
|
|
195
|
-
attributes={{ name: 'awesome-range', min: 0, max: 100, step: 1 }}
|
|
196
|
-
placeholder={t('common:placeholder.input')}
|
|
197
|
-
value={getValue(field)}
|
|
198
|
-
saveButtonLabel={t('common:button.confirm')}
|
|
199
|
-
cancelButtonLabel={t('common:button.cancel')}
|
|
200
|
-
/>
|
|
201
|
-
) : null}
|
|
202
|
-
|
|
203
|
-
{field.type === 'switch' ? (
|
|
204
|
-
<Switch
|
|
205
|
-
onChange={(checked: boolean) => handleSave(checked, field)}
|
|
206
|
-
checked={(getValue(field) as boolean) || false}
|
|
207
|
-
/>
|
|
208
|
-
) : null}
|
|
209
|
-
|
|
210
|
-
{field.type === 'date' && (
|
|
211
|
-
<EasyEdit
|
|
212
|
-
type="date"
|
|
213
|
-
onSave={(value: string) =>
|
|
214
|
-
handleSave(new Date(value) as FieldValue, field)
|
|
215
|
-
}
|
|
216
|
-
placeholder={t('common:placeholder.input')}
|
|
217
|
-
value={getDateValue(field)}
|
|
218
|
-
saveButtonLabel={t('common:button.confirm')}
|
|
219
|
-
cancelButtonLabel={t('common:button.cancel')}
|
|
220
|
-
/>
|
|
221
|
-
)}
|
|
222
|
-
|
|
223
|
-
{field.type === 'password' && (
|
|
224
|
-
<EasyEdit
|
|
225
|
-
type="password"
|
|
226
|
-
onSave={(value: string) => handleSave(value, field)}
|
|
227
|
-
saveButtonLabel={t('common:button.confirm')}
|
|
228
|
-
cancelButtonLabel={t('common:button.cancel')}
|
|
229
|
-
value={getValue(field)}
|
|
230
|
-
placeholder={t('common:placeholder.input')}
|
|
231
|
-
/>
|
|
232
|
-
)}
|
|
233
|
-
|
|
234
|
-
{field.type === 'color' ? (
|
|
235
|
-
<AppColorpicker item={item} field={field} handleSave={handleSave} />
|
|
236
|
-
) : null}
|
|
237
|
-
</div>
|
|
238
|
-
))}
|
|
239
|
-
|
|
240
|
-
{/*
|
|
241
|
-
<h3>Radio Buttons</h3>
|
|
242
|
-
<EasyEdit
|
|
243
|
-
type={Types.RADIO}
|
|
244
|
-
value="one"
|
|
245
|
-
onSave={save}
|
|
246
|
-
options={generateOptionsList()}
|
|
247
|
-
instructions="Custom instructions"
|
|
248
|
-
/>
|
|
249
|
-
<h3>DateTime</h3>
|
|
250
|
-
<EasyEdit
|
|
251
|
-
type={Types.DATETIME_LOCAL}
|
|
252
|
-
onSave={save}
|
|
253
|
-
instructions="Select your date and time of birth"
|
|
254
|
-
/>
|
|
255
|
-
<h3>Dropdown</h3>
|
|
256
|
-
<EasyEdit
|
|
257
|
-
type={Types.SELECT}
|
|
258
|
-
options={generateOptionsList()}
|
|
259
|
-
onSave={save}
|
|
260
|
-
placeholder={t('common:placeholder.input')}
|
|
261
|
-
instructions="Custom instructions"
|
|
262
|
-
/>
|
|
263
|
-
<h3>Datalist</h3>
|
|
264
|
-
<EasyEdit
|
|
265
|
-
type={Types.DATALIST}
|
|
266
|
-
options={generateOptionsList()}
|
|
267
|
-
onSave={save}
|
|
268
|
-
instructions="Start typing to get suggestions"
|
|
269
|
-
/>
|
|
270
|
-
<h3>Checkboxes</h3>
|
|
271
|
-
<EasyEdit
|
|
272
|
-
type={Types.CHECKBOX}
|
|
273
|
-
options={generateOptionsList()}
|
|
274
|
-
onSave={save}
|
|
275
|
-
value={['one', 'two']} // this will preselect two options
|
|
276
|
-
/>
|
|
277
|
-
*/}
|
|
278
|
-
</>
|
|
279
|
-
);
|
|
280
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import FormFieldOption from './FormFieldOption';
|
|
2
|
-
|
|
3
|
-
export type FieldOperations = 'create' | 'update' | 'delete';
|
|
4
|
-
|
|
5
|
-
export default interface FormField {
|
|
6
|
-
name: string;
|
|
7
|
-
title?: string;
|
|
8
|
-
type: string;
|
|
9
|
-
required?: boolean;
|
|
10
|
-
disabled?: boolean;
|
|
11
|
-
options?: FormFieldOption[];
|
|
12
|
-
tooltip?: string;
|
|
13
|
-
default?: string | boolean | number;
|
|
14
|
-
role?: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const validateFormField = (
|
|
18
|
-
entity: Record<string, unknown>,
|
|
19
|
-
fields: FormField[]
|
|
20
|
-
) => {
|
|
21
|
-
const invalids = [];
|
|
22
|
-
for (const field of fields) {
|
|
23
|
-
if (field.required && !entity[field.name]) invalids.push(field);
|
|
24
|
-
}
|
|
25
|
-
return invalids;
|
|
26
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export type FieldValue = string | number | boolean | Date | null;
|
|
2
|
-
|
|
3
|
-
export default interface FormFieldOption {
|
|
4
|
-
label: string;
|
|
5
|
-
value: FieldValue;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export const convertEnum = (
|
|
9
|
-
values: Record<string, string | number | boolean>
|
|
10
|
-
): FormFieldOption[] => {
|
|
11
|
-
let fields: FormFieldOption[] = [{ label: '', value: '' }];
|
|
12
|
-
|
|
13
|
-
Object.keys(values).forEach((key) => {
|
|
14
|
-
fields = [...fields, { label: String(values[key]), value: key }];
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
return fields;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const convertList = (
|
|
21
|
-
values: Array<Record<string, unknown>>,
|
|
22
|
-
keyAttr: string,
|
|
23
|
-
valueAttr: string
|
|
24
|
-
): FormFieldOption[] => {
|
|
25
|
-
let fields: FormFieldOption[] = [{ label: '', value: '' }];
|
|
26
|
-
|
|
27
|
-
values.forEach((value) => {
|
|
28
|
-
fields = [
|
|
29
|
-
...fields,
|
|
30
|
-
{
|
|
31
|
-
label: String(value[keyAttr]),
|
|
32
|
-
value: value[valueAttr] as FieldValue,
|
|
33
|
-
},
|
|
34
|
-
];
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
return fields;
|
|
38
|
-
};
|