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

208 lines
20 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 };
2020-01-21 13:06:32 +01:00
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaW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vbXBvbmVudHMvdGV4dFwiLFxuICAgICAgICBwcm9wczoge1xuICAgICAgICAgICAgZm9udDogXCIxMnB0IGJvbGRcIixcbiAgICAgICAgfVxuICAgIH0sXG4gICAge1xuICAgICAgICBuYW1lOiBcImNvbW1vbi9INFwiLFxuICAgICAgICBkZXNjcmlwdGlvbjogXCJIZWFkZXIgNFwiLFxuICAgICAgICBpbmhlcml0czogXCJAYnVkaWJhc2Uvc3RhbmRhcmQtY29tcG9uZW50cy90ZXh0XCIsXG4gICAgICAgIHByb3BzOiB7XG4gICAgICAgICAgICBmb250OiBcIjEwcHQgYm9sZFwiLFxuICAgICAgICB9XG4gICAgfVxuXSIsImltcG9ydCB7aGVhZGVyc30gZnJvbSBcIi4vaGVhZGVyc0dlbmVyYXRvclwiO1xuXG5leHBvcnQgY29uc3QgZm9ybXMgPSAoe3JlY29yZHMsIGluZGV4ZXN9KSA9PiBcbiAgICBbLi4uaGVhZGVycyh7cmVjb3JkcywgaW5kZXhlc30pLFxuICAgIC4uLnJlY29yZHMubWFwKHJvb3QpXTtcblxuY29uc3Qgcm9vdCA9IHJlY29yZCA9PiAoe1xuICAgIG5hbWU6IGAke3JlY29yZC5uYW1lfSBGb3JtYCxcbiAgICBkZXNjcmlwdGlvbjogYEFsbCBmaWVsZHMgb24gcmVjb3JkICcke3JlY29yZC5ub2RlS2V5KCl9JyBgLFxuICAgIGluaGVyaXRzOiBcIkBidWRpYmFzZS9zdGFuZGFyZC1jb21wb25lbnRzL3N0YWNrcGFuZWxcIixcbiAgICBwcm9wczoge1xuICAgICAgICBkaXJlY3Rpb246IFwidmVydGljYWxcIixcbiAgICAgICAgY2hpbGRyZW46IFtcbiAgICAgICAgICAgIHtcbiAgICAgICAgICAgICAgICBjb250cm9sOiB7XG4gICAgICAgICAgICAgICAgICAgIF9jb21wb25lbnQ6IFwiY29tbW9uL0gxXCIsXG4gICAgICAgICAgICAgICAgICAgIHZhbHVlOiBgRWRpdCAke3JlY29yZC5uYW1lfWAsXG4gICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIGZvcm0ocmVjb3JkKSxcbiAgICAgICAgICAgIHNhdmVDYW5jZWxCdXR0b25zKHJlY29yZClcbiAgICAgICAgXVxuICAgIH1cbn0pIFxuXG5jb25zdCBmb3JtID0gcmVjb3JkID0+ICh7XG4gICAgY29udHJvbDoge1xuICAgICAgICBfY29tcG9uZW50OiBcIkBidWRpYmFzZS9zdGFuZGFyZC1jb21wb25lbnRzL2Zvcm1cIixcbiAgICAgICAgZm9ybUNvbnRyb2xzOiBcbiAgICAgICAgICAgIHJlY29yZC5maWVsZHMubWFwKGYgPT4gKHtcbiAgICAgICAgICAgICAgICBsYWJlbDogZi5sYWJlbCxcbiAgICAgICAgICAgICAgICBjb250cm9sOiB7XG4gICAgICAgICAgICAgICAgICAgIF9jb21wb25lbnQ6IFwiQGJ1ZGliYXNlL3N0YW5kYXJkLWNvbXBvbmVudHMvdGV4dGJveFwiLFxuICAgICAgICAgICAgICAgICAgICB2YWx1ZToge1xuICAgICAgICAgICAgICAgICAgICAgICAgXCIjI2Jic3RhdGVcIjpgY3VycmVudCR7cmVjb3JkLm5hbWV9LiR7Zi5uYW1lfWAsXG4gICAgICAgICAgICAgICAgICAgICAgICBcIiMjYmJzb3VyY2VcIjpcInN0b3JlXCJcbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pKVxuICAgIH1cbn0pXG5cbmNvbnN0IHNhdmVDYW5jZWxCdXR0b25zID0gKHJlY29yZCkgPT4gKHtcbiAgICBjb250cm9sOiB7XG4gICAgICAgIF9jb21wb25lbnQ6IFwiQGJ1ZGliYXNlL3N0YW5kYXJkLWNvbXBvbmVudHMvc3RhY2twYW5lbFwiLFxuICAgICAgICBkaXJlY3Rpb246IFwiaG9yaXpvbnRhbFwiLFxuICAgICAgICBjaGlsZHJlbjogW1xuICAgICAgICAgICAgcGFkZGVkUGFuZWxGb3JCdXR0b24oe1xuICAgICAgICAgICAgICAgIF9jb21wb25lbnQ6IFwiY29tbW9uL1ByaW1hcnkgQnV0dG9uXCIsXG4gICAgICAgICAgICAgICAgY29udGVudFRleHQ6IGBTYXZlICR7cmVjb3JkLm5hbWV9YCxcbiAgICAgICAgICAgICAgICBvbkNsaWNrOiBbICAgICAgICAgICAgICAgIFxuICAgICAgICAgICAgICAgICAgICB7XG4gICAgICAgICAgICAgICAgICAgICAgICBcIiMjZXZlbnRIYW5kbGVyVHlwZVwiOiBcIlNhdmUgUmVjb3JkXCIsXG4gICAgICAgICAgICAgICAgICAgICAgICBwYXJhbWV0ZXJzOiB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGVQYXRoOiBgY3VycmVudCR7cmVjb3JkLm5hbWV9YCxcbiAgICAgICAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgIF1cbiAgICAgICAgICAgIH0pLFxuICAgICAgICAgICAgcGFkZGV