Skip to content

Commit 20eedea

Browse files
committed
feat(form): add slider widget
1 parent 455f994 commit 20eedea

11 files changed

Lines changed: 456 additions & 76 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Formule includes a variety of predefined field types, grouped in three categorie
7373
- `Accordion`: When containing a `List`, it works as a `List` with collapsible entries.
7474
- `Layer`: When containing a `List`, it works as a `List` whose entries will open in a dialog window.
7575
- `Tab`: It's commonly supposed to be used as a wrapper around the rest of the elements. You will normally want to add an `Object` inside and you can use it to separate the form in different pages or sections.
76-
- **Advanced fields**: More complex or situational fields such as `URI`, `Rich/Latex editor`, `Tags`, `ID Fetcher`, `Code Editor` and `Files`.
76+
- **Advanced fields**: More complex or situational fields such as `URI`, `Rich/Latex editor`, `Tags`, `ID Fetcher`, `Code Editor`, `Files` and `Slider`.
7777

7878
You can freely remove some of these predefined fields and add your own custom fields and widgets following the JSON Schema specifications. More details below.
7979

formule-demo/cypress/e2e/builder.cy.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,4 +875,114 @@ describe("test basic functionality", () => {
875875
.find('[data-cy="fileAllowedExtensionsText"]')
876876
.should("contain.text", "Allowed file extensions: .pdf");
877877
});
878+
879+
it("tests slider field", () => {
880+
cy.get("span").contains("Advanced fields").click();
881+
cy.addFieldWithName("slider", "myfield");
882+
cy.getByDataCy("treeItem").click();
883+
884+
// Test continuous type
885+
cy.get(`input#root${SEP}kind`)
886+
.parent()
887+
.parent()
888+
.find('[title="Continuous"]')
889+
.should("exist");
890+
891+
// min, max and step
892+
cy.get(`input#root${SEP}minimum`).clearTypeBlur("0");
893+
cy.get(`input#root${SEP}maximum`).clearTypeBlur("100");
894+
cy.get(`input#root${SEP}step`).clearTypeBlur("10", { force: true });
895+
896+
// slider interaction
897+
cy.getByDataCy("formPreview")
898+
.find(".ant-slider")
899+
.as("slider")
900+
.click("center");
901+
cy.getByDataCy("formPreview")
902+
.find(".ant-input-number-input")
903+
.should("have.value", "50");
904+
905+
// input interaction
906+
cy.getByDataCy("formPreview")
907+
.find(".ant-input-number-input")
908+
.clearTypeBlur("30");
909+
cy.get("@slider")
910+
.find(".ant-slider-handle")
911+
.invoke("attr", "aria-valuenow")
912+
.should("eq", "30");
913+
914+
// hide input
915+
cy.getByDataCy("fieldSettings")
916+
.find(".scrollableTabs .ant-tabs-nav-list")
917+
.find("[data-node-key=2]")
918+
.click();
919+
cy.get(`button#root${SEP}ui\\:options${SEP}hideInput`).click();
920+
cy.getByDataCy("formPreview").find(".ant-input-number").should("not.exist");
921+
cy.get(`button#root${SEP}ui\\:options${SEP}hideInput`).click();
922+
923+
// suffix in tooltip and input
924+
cy.get(`input#root${SEP}ui\\:options${SEP}suffix`).clearTypeBlur("px");
925+
cy.getByDataCy("formPreview")
926+
.find(".ant-slider-handle")
927+
.trigger("mouseover");
928+
cy.get(".ant-tooltip").should("contain.text", "px");
929+
cy.getByDataCy("formPreview")
930+
.find(".ant-input-number-suffix")
931+
.should("contain.text", "px");
932+
933+
// Test discrete type
934+
cy.getByDataCy("fieldSettings")
935+
.find(".scrollableTabs .ant-tabs-nav-list")
936+
.find("[data-node-key=1]")
937+
.click({ force: true });
938+
cy.get(`input#root${SEP}kind`).type("{downArrow}{enter}", { force: true });
939+
cy.get(`input#root${SEP}kind`)
940+
.parent()
941+
.parent()
942+
.find('[title="Discrete"]')
943+
.should("exist");
944+
945+
// values and labels
946+
cy.get(`fieldset#root${SEP}values`)
947+
.find('[data-cy="addItemButton"]')
948+
.click();
949+
cy.get(`input#root${SEP}values${SEP}0`).clearTypeBlur("25");
950+
cy.get(`fieldset#root${SEP}values`)
951+
.find('[data-cy="addItemButton"]')
952+
.click();
953+
cy.get(`input#root${SEP}values${SEP}1`).clearTypeBlur("50");
954+
cy.get(`fieldset#root${SEP}values`)
955+
.find('[data-cy="addItemButton"]')
956+
.click();
957+
cy.get(`input#root${SEP}values${SEP}2`).clearTypeBlur("100");
958+
cy.get(`fieldset#root${SEP}labels`)
959+
.find('[data-cy="addItemButton"]')
960+
.click();
961+
cy.get(`input#root${SEP}labels${SEP}0`).clearTypeBlur("Small");
962+
cy.get(`fieldset#root${SEP}labels`)
963+
.find('[data-cy="addItemButton"]')
964+
.click();
965+
cy.get(`input#root${SEP}labels${SEP}1`).clearTypeBlur("Medium");
966+
967+
// marks and interaction
968+
cy.getByDataCy("formPreview")
969+
.find(".ant-slider-mark-text")
970+
.first()
971+
.should("contain.text", "Small");
972+
cy.getByDataCy("formPreview")
973+
.find(".ant-slider-mark-text")
974+
.last()
975+
.should("contain.text", "100"); // no label for 100 provided
976+
cy.getByDataCy("formPreview").find(".ant-slider").click("right");
977+
cy.getByDataCy("formPreview")
978+
.find(".ant-slider-handle")
979+
.invoke("attr", "aria-valuenow")
980+
.should("eq", "2"); // last value (index 2)
981+
982+
// Test readonly
983+
cy.get(`button#root${SEP}readOnly`).click();
984+
cy.getByDataCy("formPreview")
985+
.find(".ant-slider")
986+
.should("have.class", "ant-slider-disabled");
987+
});
878988
});

src/admin/components/PropKeyEditorForm.jsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import PropTypes from "prop-types";
22
import Form from "../../forms/Form";
33
import { hiddenFields } from "../utils/fieldTypes";
4-
import widgets from "../formComponents/widgets";
54
import { useContext } from "react";
65
import CustomizationContext from "../../contexts/CustomizationContext";
76

@@ -59,7 +58,6 @@ const PropertyKeyEditorForm = ({
5958
<Form
6059
schema={objs[type][`${optionsSchemaObject}`] || {}}
6160
uiSchema={objs[type][`${optionsUiSchemaObject}`] || {}}
62-
widgets={widgets}
6361
formData={updatedFormData}
6462
onChange={onChange}
6563
liveValidate

src/admin/formComponents/widgets/SliderWidget.jsx

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/admin/formComponents/widgets/index.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)