Update list autoscreen to be theme aware and use new component props

This commit is contained in:
Andrew Kingston 2021-06-30 20:14:41 +01:00
parent b7f50b8f8f
commit b4a1ae575d
1 changed files with 18 additions and 67 deletions

View File

@ -19,21 +19,10 @@ export const rowListUrl = table => sanitizeUrl(`/${table.name}`)
function generateTitleContainer(table) { function generateTitleContainer(table) {
const newButton = new Component("@budibase/standard-components/button") const newButton = new Component("@budibase/standard-components/button")
.normalStyle({
background: "#000000",
"border-width": "0",
"border-style": "None",
color: "#fff",
"font-weight": "600",
"font-size": "14px",
})
.hoverStyle({
background: "#4285f4",
})
.text("Create New") .text("Create New")
.customProps({ .customProps({
className: "", size: "M",
disabled: false, type: "primary",
onClick: [ onClick: [
{ {
parameters: { parameters: {
@ -46,12 +35,6 @@ function generateTitleContainer(table) {
.instanceName("New Button") .instanceName("New Button")
const heading = new Component("@budibase/standard-components/heading") const heading = new Component("@budibase/standard-components/heading")
.normalStyle({
margin: "0px",
flex: "1 1 auto",
"text-transform": "capitalize",
})
.type("h2")
.instanceName("Title") .instanceName("Title")
.text(table.name) .text(table.name)
.customProps({ .customProps({
@ -60,14 +43,12 @@ function generateTitleContainer(table) {
}) })
return new Component("@budibase/standard-components/container") return new Component("@budibase/standard-components/container")
.normalStyle({
"margin-bottom": "32px",
})
.customProps({ .customProps({
direction: "row", direction: "row",
hAlign: "stretch", hAlign: "stretch",
vAlign: "middle", vAlign: "middle",
size: "shrink", size: "shrink",
gap: "M",
}) })
.instanceName("Title Container") .instanceName("Title Container")
.addChild(heading) .addChild(heading)
@ -91,68 +72,38 @@ const createScreen = table => {
const spectrumTable = new Component("@budibase/standard-components/table") const spectrumTable = new Component("@budibase/standard-components/table")
.customProps({ .customProps({
dataProvider: `{{ literal ${makePropSafe(provider._json._id)} }}`, dataProvider: `{{ literal ${makePropSafe(provider._json._id)} }}`,
theme: "spectrum--lightest",
showAutoColumns: false, showAutoColumns: false,
quiet: true, quiet: false,
size: "spectrum--medium",
rowCount: 8, rowCount: 8,
}) })
.instanceName(`${table.name} Table`) .instanceName(`${table.name} Table`)
const safeTableId = makePropSafe(spectrumTable._json._id) const safeTableId = makePropSafe(spectrumTable._json._id)
const safeRowId = makePropSafe("_id") const safeRowId = makePropSafe("_id")
const viewButton = new Component("@budibase/standard-components/button") const viewLink = new Component("@budibase/standard-components/link")
.customProps({ .customProps({
text: "View", text: "View",
onClick: [ url: `${rowListUrl(table)}/{{ ${safeTableId}.${safeRowId} }}`,
{ size: "S",
"##eventHandlerType": "Navigate To", color: "var(--spectrum-global-color-gray-600)",
parameters: { align: "left",
url: `${rowListUrl(table)}/{{ ${safeTableId}.${safeRowId} }}`,
},
},
],
}) })
.instanceName("View Button")
.normalStyle({ .normalStyle({
background: "transparent", ["margin-left"]: "16px",
"font-weight": "600", ["margin-right"]: "16px",
color: "#888",
"border-width": "0",
})
.hoverStyle({
color: "#4285f4",
}) })
.instanceName("View Link")
spectrumTable.addChild(viewButton) spectrumTable.addChild(viewLink)
provider.addChild(spectrumTable) provider.addChild(spectrumTable)
const mainContainer = new Component("@budibase/standard-components/container")
.normalStyle({
background: "white",
"border-radius": "0.5rem",
"box-shadow": "0 1px 2px 0 rgba(0, 0, 0, 0.05)",
"border-width": "2px",
"border-color": "rgba(0, 0, 0, 0.1)",
"border-style": "None",
"padding-top": "48px",
"padding-bottom": "48px",
"padding-right": "48px",
"padding-left": "48px",
})
.customProps({
direction: "column",
hAlign: "stretch",
vAlign: "top",
size: "shrink",
})
.instanceName("Container")
.addChild(generateTitleContainer(table))
.addChild(provider)
return new Screen() return new Screen()
.route(rowListUrl(table)) .route(rowListUrl(table))
.instanceName(`${table.name} - List`) .instanceName(`${table.name} - List`)
.addChild(mainContainer) .normalStyle({
["padding-top"]: "32px",
})
.addChild(generateTitleContainer(table))
.addChild(provider)
.json() .json()
} }