budibase/packages/standard-components/dist/generators.js

208 lines
19 KiB
JavaScript
Raw Normal View History

2019-10-10 07:18:02 +02:00
const headers = () => [
{
name: "common/H1",
description: "Header 1",
inherits: "@budibase/standard-components/text",
props: {
font: "20pt",
}
},
{
name: "common/H2",
description: "Header 2",
inherits: "@budibase/standard-components/text",
props: {
font: "15pt",
}
},
{
name: "common/H3",
description: "Header 3",
inherits: "@budibase/standard-components/text",
props: {
font: "12pt bold",
}
},
{
name: "common/H4",
description: "Header 4",
inherits: "@budibase/standard-components/text",
props: {
font: "10pt bold",
}
}
];
const forms = ({records, indexes}) =>
[...headers(),
...records.map(root)];
2019-10-07 07:03:41 +02:00
const root = record => ({
name: `${record.name} Form`,
description: `All fields on record '${record.nodeKey()}' `,
inherits: "@budibase/standard-components/stackpanel",
props: {
direction: "vertical",
children: [
{
2019-10-10 07:18:02 +02:00
control: {
_component: "common/H1",
value: `Edit ${record.name}`,
}
2019-10-07 07:03:41 +02:00
},
form(record),
saveCancelButtons(record)
]
}
});
const form = record => ({
2019-10-10 07:18:02 +02:00
control: {
_component: "@budibase/standard-components/form",
formControls:
record.fields.map(f => ({
label: f.label,
control: {
_component: "@budibase/standard-components/textbox",
value: {
"##bbstate":`current${record.name}.${f.name}`,
"##bbsource":"store"
}
2019-10-07 07:03:41 +02:00
}
2019-10-10 07:18:02 +02:00
}))
}
2019-10-07 07:03:41 +02:00
});
const saveCancelButtons = (record) => ({
2019-10-10 07:18:02 +02:00
control: {
_component: "@budibase/standard-components/stackpanel",
direction: "horizontal",
children: [
paddedPanelForButton({
_component: "common/Primary Button",
contentText: `Save ${record.name}`,
onClick: [
{
"##eventHandlerType": "Save Record",
parameters: {
statePath: `current${record.name}`,
}
2019-10-07 07:03:41 +02:00
}
2019-10-10 07:18:02 +02:00
]
}),
paddedPanelForButton({
_component: "common/Secondary Button",
contentText: `Cancel`,
onClick: [
{
"##eventHandlerType": "Save Record",
parameters: {
statePath: `current${record.name}`,
}
2019-10-07 07:03:41 +02:00
}
2019-10-10 07:18:02 +02:00
]
})
]
}
2019-10-07 07:03:41 +02:00
});
const paddedPanelForButton = (button) => ({
2019-10-10 07:18:02 +02:00
control: {
_component: "@budibase/standard-components/panel",
padding: "20px",
component: button
}
2019-10-07 07:03:41 +02:00
});
const indexTables = ({indexes, helpers}) =>
indexes.filter(i => i.parent().type === "root")
.map(i => indexTable(i, helpers));
const indexTableProps = (index, helpers) => ({
data: {
"##bbstate":index.nodeKey(),
"##bbsource":"store"
},
columns: helpers.indexSchema(index).map(column)
});
const indexTable = (index, helpers) => ({
name: `tables/${index.name} Table`,
inherits: "@budibase/standard-components/table",
props: indexTableProps(index, helpers)
});
const column = (col) => ({
title: col.name,
value: {
"##bbstate": col.name,
"##bbsource":"context"
}
});
const nav = ({records, indexes, helpers}) => [
{
name: "Application Root",
inherits: "@budibase/standard-components/nav",
props: {
2019-10-10 07:18:02 +02:00
items: indexes
.filter(i => i.parent().type === "root")
2019-10-18 18:32:03 +02:00
.map(navItem),
selectedItem: {
"##bbstate": "selectedNav",
"##bbstatefallback": records[0].collectionName,
"##bbsource":"store"
}
},
2019-10-07 07:03:41 +02:00
},
...indexTables({records, indexes, helpers})
];
const navItem = (index) => ({
title: index.name,
component : {
_component: `tables/${index.name} Table`
}
});
const app = (params) => {
return [
...nav(params),
...forms(params)
];
};
const buttons = () => [
{
name: "common/Primary Button",
description: "a styled button",
inherits: "@budibase/standard-components/button",
props: {
padding: "5px 7px",
border: "1px solid #EEE",
color: "#5F6368",
background: "##f2f2f2",
hoverColor: "black",
hoverBackground: "#cccccc"
}
},
{
name: "common/Secondary Button",
description: "a styled button",
inherits: "@budibase/standard-components/button",
props: {
padding: "5px 7px",
border: "1px solid #EEE",
color: "#5F6368",
background: "##f2f2f2",
hoverColor: "black",
hoverBackground: "#cccccc"
}
}
];
export { app, buttons, forms, headers, indexTables, nav };
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2VuZXJhdG9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VyaXRzOiBcIkBidWRpYmFzZS9zdGFuZGFyZC1jb21wb25lbnRzL3RleHRcIixcclxuICAgICAgICBwcm9wczoge1xyXG4gICAgICAgICAgICBmb250OiBcIjEycHQgYm9sZFwiLFxyXG4gICAgICAgIH1cclxuICAgIH0sXHJcbiAgICB7XHJcbiAgICAgICAgbmFtZTogXCJjb21tb24vSDRcIixcclxuICAgICAgICBkZXNjcmlwdGlvbjogXCJIZWFkZXIgNFwiLFxyXG4gICAgICAgIGluaGVyaXRzOiBcIkBidWRpYmFzZS9zdGFuZGFyZC1jb21wb25lbnRzL3RleHRcIixcclxuICAgICAgICBwcm9wczoge1xyXG4gICAgICAgICAgICBmb250OiBcIjEwcHQgYm9sZFwiLFxyXG4gICAgICAgIH1cclxuICAgIH1cclxuXSIsImltcG9ydCB7aGVhZGVyc30gZnJvbSBcIi4vaGVhZGVyc0dlbmVyYXRvclwiO1xyXG5cclxuZXhwb3J0IGNvbnN0IGZvcm1zID0gKHtyZWNvcmRzLCBpbmRleGVzfSkgPT4gXHJcbiAgICBbLi4uaGVhZGVycyh7cmVjb3JkcywgaW5kZXhlc30pLFxyXG4gICAgLi4ucmVjb3Jkcy5tYXAocm9vdCldO1xyXG5cclxuY29uc3Qgcm9vdCA9IHJlY29yZCA9PiAoe1xyXG4gICAgbmFtZTogYCR7cmVjb3JkLm5hbWV9IEZvcm1gLFxyXG4gICAgZGVzY3JpcHRpb246IGBBbGwgZmllbGRzIG9uIHJlY29yZCAnJHtyZWNvcmQubm9kZUtleSgpfScgYCxcclxuICAgIGluaGVyaXRzOiBcIkBidWRpYmFzZS9zdGFuZGFyZC1jb21wb25lbnRzL3N0YWNrcGFuZWxcIixcclxuICAgIHByb3BzOiB7XHJcbiAgICAgICAgZGlyZWN0aW9uOiBcInZlcnRpY2FsXCIsXHJcbiAgICAgICAgY2hpbGRyZW46IFtcclxuICAgICAgICAgICAge1xyXG4gICAgICAgICAgICAgICAgY29udHJvbDoge1xyXG4gICAgICAgICAgICAgICAgICAgIF9jb21wb25lbnQ6IFwiY29tbW9uL0gxXCIsXHJcbiAgICAgICAgICAgICAgICAgICAgdmFsdWU6IGBFZGl0ICR7cmVjb3JkLm5hbWV9YCxcclxuICAgICAgICAgICAgICAgIH1cclxuICAgICAgICAgICAgfSxcclxuICAgICAgICAgICAgZm9ybShyZWNvcmQpLFxyXG4gICAgICAgICAgICBzYXZlQ2FuY2VsQnV0dG9ucyhyZWNvcmQpXHJcbiAgICAgICAgXVxyXG4gICAgfVxyXG59KSBcclxuXHJcbmNvbnN0IGZvcm0gPSByZWNvcmQgPT4gKHtcclxuICAgIGNvbnRyb2w6IHtcclxuICAgICAgICBfY29tcG9uZW50OiBcIkBidWRpYmFzZS9zdGFuZGFyZC1jb21wb25lbnRzL2Zvcm1cIixcclxuICAgICAgICBmb3JtQ29udHJvbHM6IFxyXG4gICAgICAgICAgICByZWNvcmQuZmllbGRzLm1hcChmID0+ICh7XHJcbiAgICAgICAgICAgICAgICBsYWJlbDogZi5sYWJlbCxcclxuICAgICAgICAgICAgICAgIGNvbnRyb2w6IHtcclxuICAgICAgICAgICAgICAgICAgICBfY29tcG9uZW50OiBcIkBidWRpYmFzZS9zdGFuZGFyZC1jb21wb25lbnRzL3RleHRib3hcIixcclxuICAgICAgICAgICAgICAgICAgICB2YWx1ZToge1xyXG4gICAgICAgICAgICAgICAgICAgICAgICBcIiMjYmJzdGF0ZVwiOmBjdXJyZW50JHtyZWNvcmQubmFtZX0uJHtmLm5hbWV9YCxcclxuICAgICAgICAgICAgICAgICAgICAgICAgXCIjI2Jic291cmNlXCI6XCJzdG9yZVwiXHJcbiAgICAgICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICAgICAgfVxyXG4gICAgICAgICAgICB9KSlcclxuICAgIH1cclxufSlcclxuXHJcbmNvbnN0IHNhdmVDYW5jZWxCdXR0b25zID0gKHJlY29yZCkgPT4gKHtcclxuICAgIGNvbnRyb2w6IHtcclxuICAgICAgICBfY29tcG9uZW50OiBcIkBidWRpYmFzZS9zdGFuZGFyZC1jb21wb25lbnRzL3N0YWNrcGFuZWxcIixcclxuICAgICAgICBkaXJlY3Rpb246IFwiaG9yaXpvbnRhbFwiLFxyXG4gICAgICAgIGNoaWxkcmVuOiBbXHJcbiAgICAgICAgICAgIHBhZGRlZFBhbmVsRm9yQnV0dG9uKHtcclxuICAgICAgICAgICAgICAgIF9jb21wb25lbnQ6IFwiY29tbW9uL1ByaW1hcnkgQnV0dG9uXCIsXHJcbiAgICAgICAgICAgICAgICBjb250ZW50VGV4dDogYFNhdmUgJHtyZWNvcmQubmFtZX1gLFxyXG4gICAgICAgICAgICAgICAgb25DbGljazogWyAgICAgICAgICAgICAgICBcclxuICAgICAgICAgICAgICAgICAgICB7XHJcbiAgICAgICAgICAgICAgICAgICAgICAgIFwiIyNldmVudEhhbmRsZXJUeXBlXCI6IFwiU2F2ZSBSZWNvcmRcIixcclxuICAgICAgICAgICAgICAgICAgICAgICAgcGFyYW1ldGVyczo