@saltcorn/builder 0.8.7 → 0.8.8-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ import React, { Fragment, useState, useContext, useEffect } from "react";
8
8
  import { ntimes } from "./Columns";
9
9
  import { Column } from "./Column";
10
10
  import optionsCtx from "../context";
11
- import { setAPropGen } from "./utils";
11
+ import { setAPropGen, buildOptions } from "./utils";
12
12
 
13
13
  import { Element, useNode } from "@craftjs/core";
14
14
 
@@ -23,13 +23,25 @@ export /**
23
23
  * @category saltcorn-builder
24
24
  * @subcategory components
25
25
  */
26
- const Tabs = ({ contents, titles, tabsStyle, ntabs, independent, field }) => {
26
+ const Tabs = ({
27
+ contents,
28
+ titles,
29
+ tabsStyle,
30
+ ntabs,
31
+ independent,
32
+ startClosed,
33
+ field,
34
+ }) => {
27
35
  const {
28
36
  selected,
29
37
  connectors: { connect, drag },
30
38
  } = useNode((node) => ({ selected: node.events.selected }));
31
- const [showTab, setShowTab] = useState(0);
32
- const [showTabs, setShowTabs] = useState([true]);
39
+ const [showTab, setShowTab] = useState(
40
+ tabsStyle === "Accordion" && startClosed ? false : 0
41
+ );
42
+ const [showTabs, setShowTabs] = useState(
43
+ tabsStyle === "Accordion" && startClosed ? [] : [true]
44
+ );
33
45
  if (tabsStyle === "Accordion")
34
46
  return (
35
47
  <div className="accordion">
@@ -159,6 +171,7 @@ const TabsSettings = () => {
159
171
  tabsStyle: node.data.props.tabsStyle,
160
172
  ntabs: node.data.props.ntabs,
161
173
  independent: node.data.props.independent,
174
+ startClosed: node.data.props.startClosed,
162
175
  deeplink: node.data.props.deeplink,
163
176
  titles: node.data.props.titles,
164
177
  field: node.data.props.field,
@@ -169,6 +182,7 @@ const TabsSettings = () => {
169
182
  tabsStyle,
170
183
  deeplink,
171
184
  independent,
185
+ startClosed,
172
186
  ntabs,
173
187
  field,
174
188
  } = node;
@@ -196,6 +210,9 @@ const TabsSettings = () => {
196
210
  });
197
211
  }, [field]);
198
212
  const setAProp = setAPropGen(setProp);
213
+ const styleOptions = ["Tabs", "Pills", "Accordion"];
214
+ if (["show", "edit"].includes(options.mode))
215
+ styleOptions.push("Value switch");
199
216
 
200
217
  return (
201
218
  <table className="w-100" accordiontitle="Placement">
@@ -210,12 +227,7 @@ const TabsSettings = () => {
210
227
  className="form-control form-select"
211
228
  onChange={setAProp("tabsStyle")}
212
229
  >
213
- <option>Tabs</option>
214
- <option>Pills</option>
215
- <option>Accordion</option>
216
- {["show", "edit"].includes(options.mode) && (
217
- <option>Value switch</option>
218
- )}
230
+ {buildOptions(styleOptions)}
219
231
  </select>
220
232
  </td>
221
233
  </tr>
@@ -309,6 +321,24 @@ const TabsSettings = () => {
309
321
  </td>
310
322
  </tr>
311
323
  )}
324
+ {tabsStyle === "Accordion" ? (
325
+ <tr>
326
+ <td colSpan="2">
327
+ <div className="form-check">
328
+ <input
329
+ className="form-check-input"
330
+ name="block"
331
+ type="checkbox"
332
+ checked={startClosed}
333
+ onChange={setAProp("startClosed", { checked: true })}
334
+ />
335
+ <label className="form-check-label">
336
+ Inititally closed
337
+ </label>
338
+ </div>
339
+ </td>
340
+ </tr>
341
+ ) : null}
312
342
  </Fragment>
313
343
  )}
314
344
  </tbody>
@@ -325,6 +355,7 @@ Tabs.craft = {
325
355
  ntabs: 2,
326
356
  tabsStyle: "Tabs",
327
357
  independent: false,
358
+ startClosed: false,
328
359
  deeplink: true,
329
360
  },
330
361
  displayName: "Tabs",
@@ -7,7 +7,12 @@
7
7
  import React, { useContext, Fragment } from "react";
8
8
  import { useNode } from "@craftjs/core";
9
9
  import optionsCtx from "../context";
10
- import { blockProps, BlockSetting, TextStyleRow, setAPropGen } from "./utils";
10
+ import {
11
+ blockProps,
12
+ BlockSetting,
13
+ setAPropGen,
14
+ buildOptions,
15
+ } from "./utils";
11
16
 
12
17
  export /**
13
18
  * @param {object} props
@@ -196,14 +201,19 @@ const ToggleFilterSettings = () => {
196
201
  value={style}
197
202
  onChange={setAProp("style")}
198
203
  >
199
- <option value="primary">Primary</option>
200
- <option value="secondary">Secondary</option>
201
- <option value="success">Success</option>
202
- <option value="danger">Danger</option>
203
- <option value="warning">Warning</option>
204
- <option value="info">Info</option>
205
- <option value="light">Light</option>
206
- <option value="dark">Dark</option>
204
+ {buildOptions(
205
+ [
206
+ "primary",
207
+ "secondary",
208
+ "success",
209
+ "danger",
210
+ "warning",
211
+ "info",
212
+ "light",
213
+ "dark",
214
+ ],
215
+ { valAttr: true, capitalize: true }
216
+ )}
207
217
  </select>
208
218
  </td>
209
219
  </tr>
@@ -14,6 +14,7 @@ import {
14
14
  ConfigForm,
15
15
  setAPropGen,
16
16
  FormulaTooltip,
17
+ buildOptions,
17
18
  } from "./utils";
18
19
 
19
20
  import { RelationPicker } from "./RelationPicker";
@@ -206,9 +207,10 @@ const ViewSettings = () => {
206
207
  onChange={setAProp("state")}
207
208
  onBlur={setAProp("state")}
208
209
  >
209
- <option value="shared">Shared</option>
210
- <option value="fixed">Fixed</option>
211
- <option value="local">Local</option>
210
+ {buildOptions(["shared", "fixed", "local"], {
211
+ valAttr: true,
212
+ capitalize: true,
213
+ })}
212
214
  </select>
213
215
  </div>
214
216
  {state === "fixed" &&
@@ -519,16 +519,11 @@ export /**
519
519
  * @subcategory components / elements / utils
520
520
  * @namespace
521
521
  */
522
- const SelectUnits = ({ vert, autoable, ...props }) => (
523
- <select {...props}>
524
- <option>px</option>
525
- <option>%</option>
526
- <option>{vert ? "vh" : "vw"}</option>
527
- <option>em</option>
528
- <option>rem</option>
529
- {autoable && <option>auto</option>}
530
- </select>
531
- );
522
+ const SelectUnits = ({ vert, autoable, ...props }) => {
523
+ const options = ["px", "%", vert ? "vh" : "vw", "em", "rem"];
524
+ if (autoable) options.push("auto");
525
+ return <select {...props}>{buildOptions(options)}</select>;
526
+ };
532
527
 
533
528
  /**
534
529
  * @function
@@ -1427,3 +1422,38 @@ export const parseLegacyRelation = (type, rest, parentTbl) => {
1427
1422
  export const removeWhitespaces = (str) => {
1428
1423
  return str.replace(/\s/g, "X");
1429
1424
  };
1425
+
1426
+ /**
1427
+ *
1428
+ * @param {string} string
1429
+ * @returns {string}
1430
+ */
1431
+ export const capitalizeFirstLetter = (string) => {
1432
+ return string.charAt(0).toUpperCase() + string.slice(1);
1433
+ };
1434
+
1435
+ export const buildOptions = (
1436
+ options,
1437
+ { valAttr, keyAttr, capitalize } = {}
1438
+ ) => {
1439
+ return options.map((option) => (
1440
+ <option
1441
+ {...(valAttr ? { value: option } : {})}
1442
+ {...(keyAttr ? { key: option } : {})}
1443
+ >
1444
+ {capitalize ? capitalizeFirstLetter(option) : option}
1445
+ </option>
1446
+ ));
1447
+ };
1448
+
1449
+ export const buildBootstrapOptions = (values) => {
1450
+ const mappings = {
1451
+ sm: "small",
1452
+ md: "medium",
1453
+ lg: "large",
1454
+ xl: "x-large",
1455
+ };
1456
+ return values.map((option) => (
1457
+ <option value={option}>{mappings[option]}</option>
1458
+ ));
1459
+ };
@@ -158,6 +158,8 @@ const layoutToNodes = (layout, query, actions, parent = "ROOT") => {
158
158
  key={ix}
159
159
  name={segment.action_name}
160
160
  rndid={segment.rndid || "not_assigned"}
161
+ action_row_variable={segment.action_row_variable || ""}
162
+ action_row_limit={segment.action_row_limit || ""}
161
163
  action_label={segment.action_label || ""}
162
164
  action_style={segment.action_style || "btn-primary"}
163
165
  action_size={segment.action_size || ""}
@@ -244,6 +246,7 @@ const layoutToNodes = (layout, query, actions, parent = "ROOT") => {
244
246
  titles={segment.titles}
245
247
  ntabs={segment.ntabs}
246
248
  independent={segment.independent}
249
+ startClosed={segment.startClosed}
247
250
  deeplink={segment.deeplink}
248
251
  field={segment.field}
249
252
  tabsStyle={segment.tabsStyle}
@@ -502,6 +505,7 @@ const craftToSaltcorn = (nodes, startFrom = "ROOT") => {
502
505
  tabsStyle: node.props.tabsStyle,
503
506
  field: node.props.field,
504
507
  independent: node.props.independent,
508
+ startClosed: node.props.startClosed,
505
509
  deeplink: node.props.deeplink,
506
510
  ntabs: node.props.ntabs,
507
511
  };
@@ -524,6 +528,12 @@ const craftToSaltcorn = (nodes, startFrom = "ROOT") => {
524
528
  columns.push({
525
529
  type: "Action",
526
530
  action_name: node.props.name,
531
+ ...(node.props.name !== "Clear" && node.props.action_row_variable
532
+ ? {
533
+ action_row_variable: node.props.action_row_variable,
534
+ action_row_limit: node.props.action_row_limit,
535
+ }
536
+ : {}),
527
537
  action_label: node.props.action_label,
528
538
  action_style: node.props.action_style,
529
539
  action_size: node.props.action_size,
@@ -543,6 +553,12 @@ const craftToSaltcorn = (nodes, startFrom = "ROOT") => {
543
553
  configuration: node.props.configuration,
544
554
  confirm: node.props.confirm,
545
555
  action_name: node.props.name,
556
+ ...(node.props.name !== "Clear" && node.props.action_row_variable
557
+ ? {
558
+ action_row_variable: node.props.action_row_variable,
559
+ action_row_limit: node.props.action_row_limit,
560
+ }
561
+ : {}),
546
562
  action_label: node.props.action_label,
547
563
  action_style: node.props.action_style,
548
564
  action_size: node.props.action_size,