Skip to content

Commit 3afac49

Browse files
refactor(date-time-picker-web): hide properties and start editor config preview layout
1 parent 6e1e46e commit 3afac49

File tree

1 file changed

+67
-127
lines changed

1 file changed

+67
-127
lines changed
Lines changed: 67 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,80 @@
1+
import { hidePropertiesIn, Properties } from "@mendix/pluggable-widgets-tools";
2+
import {
3+
container,
4+
ContainerProps,
5+
dropzone,
6+
structurePreviewPalette,
7+
StructurePreviewProps
8+
} from "@mendix/widget-plugin-platform/preview/structure-preview-api";
19
import { DateTimePickerPreviewProps } from "../typings/DateTimePickerProps";
210

3-
export type Platform = "web" | "desktop";
4-
5-
export type Properties = PropertyGroup[];
6-
7-
type PropertyGroup = {
8-
caption: string;
9-
propertyGroups?: PropertyGroup[];
10-
properties?: Property[];
11-
};
12-
13-
type Property = {
14-
key: string;
15-
caption: string;
16-
description?: string;
17-
objectHeaders?: string[]; // used for customizing object grids
18-
objects?: ObjectProperties[];
19-
properties?: Properties[];
20-
};
21-
22-
type ObjectProperties = {
23-
properties: PropertyGroup[];
24-
captions?: string[]; // used for customizing object grids
25-
};
26-
27-
export type Problem = {
28-
property?: string; // key of the property, at which the problem exists
29-
severity?: "error" | "warning" | "deprecation"; // default = "error"
30-
message: string; // description of the problem
31-
studioMessage?: string; // studio-specific message, defaults to message
32-
url?: string; // link with more information about the problem
33-
studioUrl?: string; // studio-specific link
34-
};
35-
36-
type BaseProps = {
37-
type: "Image" | "Container" | "RowLayout" | "Text" | "DropZone" | "Selectable" | "Datasource";
38-
grow?: number; // optionally sets a growth factor if used in a layout (default = 1)
39-
};
40-
41-
type ImageProps = BaseProps & {
42-
type: "Image";
43-
document?: string; // svg image
44-
data?: string; // base64 image
45-
property?: object; // widget image property object from Values API
46-
width?: number; // sets a fixed maximum width
47-
height?: number; // sets a fixed maximum height
48-
};
49-
50-
type ContainerProps = BaseProps & {
51-
type: "Container" | "RowLayout";
52-
children: PreviewProps[]; // any other preview element
53-
borders?: boolean; // sets borders around the layout to visually group its children
54-
borderRadius?: number; // integer. Can be used to create rounded borders
55-
backgroundColor?: string; // HTML color, formatted #RRGGBB
56-
borderWidth?: number; // sets the border width
57-
padding?: number; // integer. adds padding around the container
58-
};
59-
60-
type RowLayoutProps = ContainerProps & {
61-
type: "RowLayout";
62-
columnSize?: "fixed" | "grow"; // default is fixed
63-
};
11+
export function getProperties(values: DateTimePickerPreviewProps, defaultProperties: Properties): Properties {
12+
if (values.type !== "date" && values.type !== "range") {
13+
hidePropertiesIn(defaultProperties, values, ["dateFormat"]);
14+
}
6415

65-
type TextProps = BaseProps & {
66-
type: "Text";
67-
content: string; // text that should be shown
68-
fontSize?: number; // sets the font size
69-
fontColor?: string; // HTML color, formatted #RRGGBB
70-
bold?: boolean;
71-
italic?: boolean;
72-
};
16+
if (values.type !== "time") {
17+
hidePropertiesIn(defaultProperties, values, ["timeFormat"]);
18+
}
7319

74-
type DropZoneProps = BaseProps & {
75-
type: "DropZone";
76-
property: object; // widgets property object from Values API
77-
placeholder: string; // text to be shown inside the dropzone when empty
78-
showDataSourceHeader?: boolean; // true by default. Toggles whether to show a header containing information about the datasource
79-
};
20+
if (values.type !== "datetime") {
21+
hidePropertiesIn(defaultProperties, values, ["dateTimeFormat"]);
22+
}
8023

81-
type SelectableProps = BaseProps & {
82-
type: "Selectable";
83-
object: object; // object property instance from the Value API
84-
child: PreviewProps; // any type of preview property to visualize the object instance
85-
};
24+
if (values.type !== "range") {
25+
hidePropertiesIn(defaultProperties, values, ["endDateAttribute"]);
26+
}
8627

87-
type DatasourceProps = BaseProps & {
88-
type: "Datasource";
89-
property: object | null; // datasource property object from Values API
90-
child?: PreviewProps; // any type of preview property component (optional)
91-
};
28+
if (values.showLabel === false) {
29+
hidePropertiesIn(defaultProperties, values, ["label"]);
30+
}
9231

93-
export type PreviewProps =
94-
| ImageProps
95-
| ContainerProps
96-
| RowLayoutProps
97-
| TextProps
98-
| DropZoneProps
99-
| SelectableProps
100-
| DatasourceProps;
32+
if (values.editable !== "conditionally") {
33+
hidePropertiesIn(defaultProperties, values, ["editabilityCondition"]);
34+
}
10135

102-
export function getProperties(
103-
_values: DateTimePickerPreviewProps,
104-
defaultProperties: Properties /*, target: Platform*/
105-
): Properties {
106-
// Do the values manipulation here to control the visibility of properties in Studio and Studio Pro conditionally.
107-
/* Example
108-
if (values.myProperty === "custom") {
109-
delete defaultProperties.properties.myOtherProperty;
36+
if (values.validationType !== "custom") {
37+
hidePropertiesIn(defaultProperties, values, ["customValidation"]);
11038
}
111-
*/
39+
11240
return defaultProperties;
11341
}
11442

115-
// export function check(_values: DateTimePickerPreviewProps): Problem[] {
116-
// const errors: Problem[] = [];
117-
// // Add errors to the above array to throw errors in Studio and Studio Pro.
118-
// /* Example
119-
// if (values.myProperty !== "custom") {
120-
// errors.push({
121-
// property: `myProperty`,
122-
// message: `The value of 'myProperty' is different of 'custom'.`,
123-
// url: "https://github.com/myrepo/mywidget"
124-
// });
125-
// }
126-
// */
127-
// return errors;
128-
// }
129-
130-
// export function getPreview(values: DateTimePickerPreviewProps, isDarkMode: boolean, version: number[]): PreviewProps {
131-
// // Customize your pluggable widget appearance for Studio Pro.
132-
// return {
133-
// type: "Container",
134-
// children: []
135-
// }
136-
// }
43+
export function getPreview(values: DateTimePickerPreviewProps, isDarkMode: boolean): StructurePreviewProps {
44+
const palette = structurePreviewPalette[isDarkMode ? "dark" : "light"];
45+
const structurePreviewChildren: StructurePreviewProps[] = [];
46+
let dropdownPreviewChildren: StructurePreviewProps[] = [];
47+
let readOnly = values.readOnly;
48+
49+
if (structurePreviewChildren.length === 0) {
50+
structurePreviewChildren.push({
51+
type: "Text",
52+
content: values.dateAttribute ? `[${values.dateAttribute}]` : "[Date time picker]",
53+
fontColor: palette.text.data
54+
});
55+
}
13756

138-
// export function getCustomCaption(values: DateTimePickerPreviewProps, platform: Platform): string {
139-
// return "DateTimePicker";
140-
// }
57+
return {
58+
type: "Container",
59+
children: [
60+
{
61+
type: "RowLayout",
62+
columnSize: "grow",
63+
borders: true,
64+
borderWidth: 1,
65+
borderRadius: 2,
66+
backgroundColor: readOnly ? palette.background.containerDisabled : palette.background.container,
67+
children: [
68+
{
69+
type: "Container",
70+
grow: 1,
71+
padding: 4,
72+
children: structurePreviewChildren
73+
},
74+
container({ grow: 0, padding: 4 })()
75+
]
76+
},
77+
...dropdownPreviewChildren
78+
]
79+
};
80+
}

0 commit comments

Comments
 (0)