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

202 lines
18 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",
2019-10-10 07:18:02 +02:00
},
},
{
name: "common/H3",
description: "Header 3",
inherits: "@budibase/standard-components/text",
props: {
font: "12pt bold",
2019-10-10 07:18:02 +02:00
},
},
{
name: "common/H4",
description: "Header 4",
inherits: "@budibase/standard-components/text",
props: {
font: "10pt bold",
2019-10-10 07:18:02 +02:00
},
},
];
2019-10-10 07:18:02 +02:00
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: [
{
control: {
_component: "common/H1",
value: `Edit ${record.name}`,
},
},
form(record),
saveCancelButtons(record),
],
},
});
2019-10-07 07:03:41 +02:00
const form = record => ({
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",
},
},
})),
},
});
const saveCancelButtons = record => ({
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}`,
},
},
],
}),
paddedPanelForButton({
_component: "common/Secondary Button",
contentText: `Cancel`,
onClick: [
{
"##eventHandlerType": "Save Record",
parameters: {
statePath: `current${record.name}`,
},
},
],
}),
],
},
});
const paddedPanelForButton = button => ({
control: {
_component: "@budibase/standard-components/panel",
padding: "20px",
component: button,
},
});
const indexTables = ({ indexes, helpers }) =>
indexes
.filter(i => i.parent().type === "root")
.map(i => indexTable(i, helpers));
2019-10-07 07:03:41 +02:00
const indexTableProps = (index, helpers) => ({
data: {
"##bbstate": index.nodeKey(),
"##bbsource": "store",
},
columns: helpers.indexSchema(index).map(column),
});
2019-10-07 07:03:41 +02:00
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: {
items: indexes.filter(i => i.parent().type === "root").map(navItem),
selectedItem: {
"##bbstate": "selectedNav",
"##bbstatefallback": records[0].collectionName,
"##bbsource": "store",
},
2019-10-07 07:03:41 +02:00
},
},
...indexTables({ records, indexes, helpers }),
];
2019-10-07 07:03:41 +02:00
const navItem = index => ({
title: index.name,
component: {
_component: `tables/${index.name} Table`,
},
});
2019-10-07 07:03:41 +02:00
const app = params => {
return [...nav(params), ...forms(params)]
};
2019-10-07 07:03:41 +02:00
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",
2019-10-07 07:03:41 +02:00
},
},
];
2019-10-07 07:03:41 +02:00
export { app, buttons, forms, headers, indexTables, nav };
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZ2VuZXJhdG9ycy5qcyIsInNvdXJjZXMiOlsiLi4vc3JjL2dlbmVyYXRvcnMvaGVhZGVyc0dlbmVyYXRvci5qcyIsIi4u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GFuZWxGb3JCdXR0b24oe1xuICAgICAgICBfY29tcG9uZW50OiBcImNvbW1vbi9TZWNvbmRhcnkgQnV0dG9uXCIsXG4gICAgICAgIGNvbnRlbnRUZXh0OiBgQ2FuY2VsYCxcbiAgICAgICAgb25DbGljazogW1xuICAgICAgICAgIHtcbiAgICAgICAgICAgIFwiIyNldmVudEhhbmRsZXJUeXBlXCI6IFwiU2F2ZSBSZWNvcmRcIixcbiAgICAgICAgICAgIHBhcmFtZXRlcnM6IHtcbiAgICAgICAgICAgICAgc3RhdGVQYXRoOiBgY3VycmVudCR7cmVjb3JkLm5hbWV9YCxcbiAgICAgICAgICAgIH0sXG4gICAgICAgICAgfSxcbiAgICAgICAgXSxcbiAgICAgIH0pLFxuICAgIF0sXG4gIH0sXG59KVxuXG5jb25zdCBwYWRkZWRQYW5lbEZvckJ1dHRvbiA9IGJ1dHRvbiA9PiAoe1xuICBjb250cm9sOiB7XG4gICAgX2NvbXBvbmVudDogXCJAYnVkaWJhc2Uvc3RhbmRhcmQtY29tcG9uZW50cy9wYW5lbFwiLFxuICAgIHB