move renderer map to separate file

This commit is contained in:
kevmodrome 2020-10-08 15:34:47 +02:00
parent da32029c31
commit e43dc488e4
2 changed files with 24 additions and 9 deletions

View File

@ -1,14 +1,10 @@
<script>
// Import valueSetters and custom renderers
import { number } from "./valueSetters"
import { booleanRenderer, attachmentRenderer } from "./customRenderer"
import renderers from "./customRenderer"
// These maps need to be set up to handle whatever types that are used in the models.
const setters = new Map([["number", number]])
const renderers = new Map([
["boolean", booleanRenderer],
["attachment", attachmentRenderer],
])
import fetchData from "../fetchData.js"
import { isEmpty } from "lodash/fp"

View File

@ -2,8 +2,15 @@
// https://www.ag-grid.com/javascript-grid-cell-rendering-components/
import AttachmentCell from './AttachmentCell/Button.svelte'
import { DatePicker } from "@budibase/bbui"
export const booleanRenderer = (params) => {
export default new Map([
["boolean", booleanRenderer],
["attachment", attachmentRenderer],
["datetime", dateRenderer],
])
function booleanRenderer(params) {
const toggle = (e) => {
params.value = !params.value
params.setValue(e.currentTarget.checked)
@ -15,10 +22,10 @@ export const booleanRenderer = (params) => {
return input
}
export const attachmentRenderer = (params) => {
let container = document.createElement("div")
function attachmentRenderer(params) {
const container = document.createElement("div")
const attachment = new AttachmentCell({
const attachmentInstance = new AttachmentCell({
target: container,
props: {
files: params.value || [],
@ -27,3 +34,15 @@ export const attachmentRenderer = (params) => {
return container
}
function dateRenderer(params) {
const container = document.createElement("div")
const datePickerInstance = new DatePicker({
target: container,
props: {
value: params.value,
}
});
return container
}