@rulab/adminjs-components 0.0.7 → 0.0.9
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/index.cjs +372 -241
- package/dist/index.d.cts +25 -13
- package/dist/index.d.ts +25 -13
- package/dist/index.js +365 -238
- package/package.json +4 -1
- package/src/components/ColorStatus/ColorStatusEdit.tsx +94 -0
- package/src/components/ColorStatus/ColorStatusList.tsx +20 -0
- package/src/components/ColorStatus/ColorStatusShow.tsx +23 -0
- package/src/components/ColorStatus/index.ts +3 -0
- package/src/components/ColorStatus/styles.ts +30 -0
- package/src/components/ColorStatus/types.ts +5 -0
- package/src/components/Editor/EditorList.jsx +23 -0
- package/src/components/Editor/EditorShow.jsx +1 -1
- package/src/components/Editor/index.ts +1 -0
- package/src/components/Editor/styles.ts +5 -3
- package/src/components/index.ts +6 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulab/adminjs-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -25,12 +25,15 @@
|
|
|
25
25
|
"@editorjs/list": "^1.9.0",
|
|
26
26
|
"@editorjs/paragraph": "^2.11.6",
|
|
27
27
|
"adminjs": "^7.8.1",
|
|
28
|
+
"chroma-js": "^3.0.0",
|
|
28
29
|
"editorjs-html": "^3.4.3",
|
|
29
30
|
"react": "^18.2.0",
|
|
31
|
+
"react-select": "^5.8.0",
|
|
30
32
|
"slugify": "^1.6.6",
|
|
31
33
|
"styled-components": "^6.1.11"
|
|
32
34
|
},
|
|
33
35
|
"devDependencies": {
|
|
36
|
+
"@types/chroma-js": "^2.4.4",
|
|
34
37
|
"@types/node": "^20.11.24",
|
|
35
38
|
"@types/react": "^18.2.61",
|
|
36
39
|
"eslint": "^8.57.0",
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import React, { FC, useState, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
import { EditPropertyProps } from "adminjs";
|
|
4
|
+
import Select, { MultiValue, SingleValue, StylesConfig } from "react-select";
|
|
5
|
+
import chroma from "chroma-js";
|
|
6
|
+
|
|
7
|
+
import { ColorStatusWrapper, Label } from "./styles";
|
|
8
|
+
|
|
9
|
+
import type { AvailableValueType } from "./types";
|
|
10
|
+
|
|
11
|
+
type ColorStatusTypes = Omit<EditPropertyProps, "where" | "resource">;
|
|
12
|
+
|
|
13
|
+
const dot = (color = "transparent") => ({
|
|
14
|
+
alignItems: "center",
|
|
15
|
+
display: "flex",
|
|
16
|
+
|
|
17
|
+
":before": {
|
|
18
|
+
backgroundColor: color,
|
|
19
|
+
borderRadius: 10,
|
|
20
|
+
content: '" "',
|
|
21
|
+
display: "block",
|
|
22
|
+
marginRight: 8,
|
|
23
|
+
height: 10,
|
|
24
|
+
width: 10,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const colorStyles: StylesConfig<AvailableValueType> = {
|
|
29
|
+
control: (styles) => ({ ...styles, backgroundColor: "white" }),
|
|
30
|
+
option: (styles, { data, isDisabled, isFocused, isSelected }) => {
|
|
31
|
+
const color = chroma(data.color);
|
|
32
|
+
return {
|
|
33
|
+
...styles,
|
|
34
|
+
backgroundColor: isSelected
|
|
35
|
+
? data.color
|
|
36
|
+
: isFocused
|
|
37
|
+
? color.alpha(0.1).css()
|
|
38
|
+
: undefined,
|
|
39
|
+
color: isSelected
|
|
40
|
+
? chroma.contrast(color, "white") > 2
|
|
41
|
+
? "white"
|
|
42
|
+
: "black"
|
|
43
|
+
: data.color,
|
|
44
|
+
|
|
45
|
+
":active": {
|
|
46
|
+
...styles[":active"],
|
|
47
|
+
backgroundColor: isSelected ? data.color : color.alpha(0.3).css(),
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
input: (styles) => ({ ...styles, ...dot() }),
|
|
52
|
+
placeholder: (styles) => ({ ...styles, ...dot("#ccc") }),
|
|
53
|
+
singleValue: (styles, { data }) => ({ ...styles, ...dot(data.color) }),
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const ColorStatus: FC<ColorStatusTypes> = ({ property, record, onChange }) => {
|
|
57
|
+
const availableValues = property.availableValues as AvailableValueType[];
|
|
58
|
+
|
|
59
|
+
const currentOption = availableValues.find(
|
|
60
|
+
(item) => item.value === record.params.colorStatus,
|
|
61
|
+
) as AvailableValueType;
|
|
62
|
+
|
|
63
|
+
const [selectOption, setCurrentOption] = useState<
|
|
64
|
+
SingleValue<AvailableValueType> | undefined
|
|
65
|
+
>(currentOption);
|
|
66
|
+
|
|
67
|
+
const handleSelectChange = (
|
|
68
|
+
option: SingleValue<AvailableValueType> | MultiValue<AvailableValueType>,
|
|
69
|
+
) => {
|
|
70
|
+
setCurrentOption(option as SingleValue<AvailableValueType>);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
onChange(property.path, selectOption?.value);
|
|
75
|
+
}, [selectOption]);
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<ColorStatusWrapper>
|
|
79
|
+
<Label>{property.path}</Label>
|
|
80
|
+
<Select
|
|
81
|
+
className="basic-single"
|
|
82
|
+
classNamePrefix="select"
|
|
83
|
+
defaultValue={selectOption ?? availableValues[0]}
|
|
84
|
+
onChange={handleSelectChange}
|
|
85
|
+
isClearable={true}
|
|
86
|
+
name="color"
|
|
87
|
+
options={availableValues}
|
|
88
|
+
styles={colorStyles}
|
|
89
|
+
/>
|
|
90
|
+
</ColorStatusWrapper>
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export default ColorStatus;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { FC } from "react";
|
|
2
|
+
import { ShowPropertyProps } from "adminjs";
|
|
3
|
+
|
|
4
|
+
import { ColorStatusBadge } from "./styles";
|
|
5
|
+
|
|
6
|
+
import type { AvailableValueType } from "./types";
|
|
7
|
+
|
|
8
|
+
const ColorStatusList: FC<ShowPropertyProps> = ({ property, record }) => {
|
|
9
|
+
const currentOption = property.availableValues?.find(
|
|
10
|
+
(item) => item.value === record.params.colorStatus,
|
|
11
|
+
) as AvailableValueType;
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<ColorStatusBadge color={currentOption.color}>
|
|
15
|
+
{record.params.colorStatus}
|
|
16
|
+
</ColorStatusBadge>
|
|
17
|
+
);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default ColorStatusList;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React, { FC } from "react";
|
|
2
|
+
import { ShowPropertyProps } from "adminjs";
|
|
3
|
+
|
|
4
|
+
import { ColorStatusBadgeWrapper, ColorStatusBadge, ShowLabel } from "./styles";
|
|
5
|
+
|
|
6
|
+
import type { AvailableValueType } from "./types";
|
|
7
|
+
|
|
8
|
+
const ColorStatusShow: FC<ShowPropertyProps> = ({ property, record }) => {
|
|
9
|
+
const currentOption = property.availableValues?.find(
|
|
10
|
+
(item) => item.value === record.params.colorStatus,
|
|
11
|
+
) as AvailableValueType;
|
|
12
|
+
|
|
13
|
+
return (
|
|
14
|
+
<ColorStatusBadgeWrapper>
|
|
15
|
+
<ShowLabel>{property.path}</ShowLabel>
|
|
16
|
+
<ColorStatusBadge color={currentOption.color}>
|
|
17
|
+
{record.params.colorStatus}
|
|
18
|
+
</ColorStatusBadge>
|
|
19
|
+
</ColorStatusBadgeWrapper>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default ColorStatusShow;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { styled } from "@adminjs/design-system/styled-components";
|
|
2
|
+
|
|
3
|
+
export const ColorStatusWrapper = styled.div`
|
|
4
|
+
margin-bottom: 24px;
|
|
5
|
+
`;
|
|
6
|
+
|
|
7
|
+
export const Label = styled.div`
|
|
8
|
+
font-size: 12px;
|
|
9
|
+
margin-bottom: 8px;
|
|
10
|
+
`;
|
|
11
|
+
|
|
12
|
+
export const ShowLabel = styled.div`
|
|
13
|
+
font-size: 12px;
|
|
14
|
+
margin-bottom: 8px;
|
|
15
|
+
color: rgb(137, 138, 154);
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
export const ColorStatusBadgeWrapper = styled.div`
|
|
19
|
+
margin-bottom: 20px;
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
export const ColorStatusBadge = styled.div`
|
|
23
|
+
background-color: ${(props: any) => props.color};
|
|
24
|
+
width: fit-content;
|
|
25
|
+
padding: 5px 10px;
|
|
26
|
+
border-radius: 20px;
|
|
27
|
+
font-size: 12px;
|
|
28
|
+
color: white;
|
|
29
|
+
white-space: nowrap;
|
|
30
|
+
`;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ThemeProvider } from "styled-components";
|
|
3
|
+
import { theme } from "@adminjs/design-system";
|
|
4
|
+
|
|
5
|
+
import { parseHtml } from "../../utils/parseHtml";
|
|
6
|
+
|
|
7
|
+
import { StyledEditorViewWrapper } from "./styles";
|
|
8
|
+
|
|
9
|
+
const EditorList = ({ property, record }) => {
|
|
10
|
+
const htmlContent = parseHtml(record.params[property.path]);
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<ThemeProvider theme={theme}>
|
|
14
|
+
<StyledEditorViewWrapper>
|
|
15
|
+
{htmlContent && (
|
|
16
|
+
<div dangerouslySetInnerHTML={{ __html: htmlContent }} />
|
|
17
|
+
)}
|
|
18
|
+
</StyledEditorViewWrapper>
|
|
19
|
+
</ThemeProvider>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default EditorList;
|
|
@@ -18,9 +18,7 @@ export const StyledEditorWrapper = styled(Box)`
|
|
|
18
18
|
border: 1px solid rgb(187, 195, 203);
|
|
19
19
|
`;
|
|
20
20
|
|
|
21
|
-
export const
|
|
22
|
-
margin-bottom: 24px;
|
|
23
|
-
|
|
21
|
+
export const StyledEditorViewWrapper = styled(Box)`
|
|
24
22
|
h1,
|
|
25
23
|
h2,
|
|
26
24
|
h3 {
|
|
@@ -59,6 +57,10 @@ export const StyledEditorShowWrapper = styled(Box)`
|
|
|
59
57
|
}
|
|
60
58
|
`;
|
|
61
59
|
|
|
60
|
+
export const StyledEditorShowWrapper = styled(StyledEditorViewWrapper)`
|
|
61
|
+
margin-bottom: 24px;
|
|
62
|
+
`;
|
|
63
|
+
|
|
62
64
|
export const StyledEditor = styled.div`
|
|
63
65
|
.cdx-block,
|
|
64
66
|
.ce-header {
|
package/src/components/index.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
export { default as ColorStatusEdit } from "./ColorStatus/ColorStatusEdit.jsx";
|
|
2
|
+
export { default as ColorStatusShow } from "./ColorStatus/ColorStatusShow.js";
|
|
3
|
+
export { default as ColorStatusList } from "./ColorStatus/ColorStatusList.js";
|
|
1
4
|
export { default as CustomSlug } from "./CustomSlug/CustomSlug.js";
|
|
2
|
-
export { default as StringList } from "./StringList/StringList.js";
|
|
3
|
-
export { default as StringListShow } from "./StringList/StringListShow.js";
|
|
4
5
|
export { default as Editor } from "./Editor/Editor.jsx";
|
|
6
|
+
export { default as EditorList } from "./Editor/EditorList.jsx";
|
|
5
7
|
export { default as EditorShow } from "./Editor/EditorShow.jsx";
|
|
8
|
+
export { default as StringList } from "./StringList/StringList.js";
|
|
9
|
+
export { default as StringListShow } from "./StringList/StringListShow.js";
|