@tsed/react-formio 3.0.0-rc.23 → 3.0.0-rc.25
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.
- package/dist/all.js +1 -2
- package/dist/all.js.map +1 -1
- package/dist/atoms/icon/Icon.js +4 -4
- package/dist/atoms/icon/Icon.js.map +1 -1
- package/dist/chunks/clsx.js +17 -0
- package/dist/chunks/clsx.js.map +1 -0
- package/dist/chunks/index.js +59969 -36
- package/dist/chunks/index.js.map +1 -1
- package/dist/contexts/FormioContext.js +1 -1
- package/dist/index.js +1 -1
- package/dist/molecules/button/Button.js +4 -4
- package/dist/molecules/button/Button.js.map +1 -1
- package/dist/molecules/card/Card.js +4 -4
- package/dist/molecules/card/Card.js.map +1 -1
- package/dist/molecules/forms/form-control/FormControl.js +1 -1
- package/dist/molecules/forms/form-control/FormControl.js.map +1 -1
- package/dist/molecules/forms/select/components/ChoicesSelect.js +53 -46
- package/dist/molecules/forms/select/components/ChoicesSelect.js.map +1 -1
- package/dist/molecules/forms/select/components/HtmlSelect.js +21 -21
- package/dist/molecules/forms/select/components/HtmlSelect.js.map +1 -1
- package/dist/molecules/forms/select/components/choices.template.d.ts +27 -2
- package/dist/molecules/forms/select/components/choices.template.js +1085 -1086
- package/dist/molecules/forms/select/components/choices.template.js.map +1 -1
- package/dist/molecules/forms/select/hooks/useOptions.d.ts +1 -1
- package/dist/molecules/forms/select/hooks/useOptions.js +15 -15
- package/dist/molecules/forms/select/hooks/useOptions.js.map +1 -1
- package/dist/molecules/loader/Loader.js +2 -5
- package/dist/molecules/loader/Loader.js.map +1 -1
- package/dist/molecules/pagination/Pagination.js +8 -8
- package/dist/molecules/pagination/Pagination.js.map +1 -1
- package/dist/molecules/pagination/PaginationButton.js +4 -4
- package/dist/molecules/pagination/PaginationButton.js.map +1 -1
- package/dist/molecules/table/Table.js +1 -1
- package/dist/molecules/table/Table.js.map +1 -1
- package/dist/molecules/table/components/DefaultCellHeader.js +1 -1
- package/dist/molecules/table/components/DefaultCellHeader.js.map +1 -1
- package/dist/molecules/table/components/DefaultOperationButton.js +1 -1
- package/dist/molecules/table/components/DefaultOperationButton.js.map +1 -1
- package/dist/molecules/table/filters/Filters.d.ts +2 -2
- package/dist/molecules/table/hooks/useUniqValues.d.ts +6 -2
- package/dist/molecules/table/hooks/useUniqValues.js.map +1 -1
- package/dist/molecules/table/utils/mapFormToColumns.js +27 -28
- package/dist/molecules/table/utils/mapFormToColumns.js.map +1 -1
- package/dist/molecules/tabs/Tab.js +1 -1
- package/dist/molecules/tabs/Tab.js.map +1 -1
- package/dist/molecules/tabs/TabPanel.js +4 -4
- package/dist/molecules/tabs/TabPanel.js.map +1 -1
- package/dist/molecules/tabs/Tabs.js +1 -1
- package/dist/molecules/tabs/Tabs.js.map +1 -1
- package/dist/organisms/form/actions/FormAction.js +1 -1
- package/dist/organisms/form/builder/FormEdit.js +1 -1
- package/dist/organisms/form/builder/FormEdit.js.map +1 -1
- package/dist/organisms/form/builder/useFormBuilder.js +1 -1
- package/dist/organisms/form/useForm.js +1 -1
- package/dist/organisms/modal/RemoveModal.js +1 -1
- package/dist/organisms/modal/RemoveModal.js.map +1 -1
- package/dist/organisms/table/actions/ActionsTable.js +1 -1
- package/dist/organisms/table/actions/ActionsTable.js.map +1 -1
- package/dist/organisms/table/forms/components/FormsCell.js +1 -1
- package/dist/organisms/table/forms/components/FormsCell.js.map +1 -1
- package/dist/utils/iconClass.js +1 -1
- package/package.json +4 -4
- package/src/atoms/icon/Icon.tsx +1 -1
- package/src/molecules/button/Button.tsx +1 -1
- package/src/molecules/card/Card.tsx +2 -2
- package/src/molecules/forms/form-control/FormControl.tsx +2 -2
- package/src/molecules/forms/select/components/ChoicesSelect.stories.tsx +134 -2
- package/src/molecules/forms/select/components/ChoicesSelect.tsx +11 -4
- package/src/molecules/forms/select/components/HtmlSelect.tsx +7 -7
- package/src/molecules/forms/select/components/choices.template.tsx +51 -29
- package/src/molecules/forms/select/hooks/useOptions.ts +1 -5
- package/src/molecules/loader/Loader.tsx +3 -7
- package/src/molecules/pagination/Pagination.tsx +5 -5
- package/src/molecules/pagination/PaginationButton.tsx +2 -2
- package/src/molecules/table/Table.tsx +2 -2
- package/src/molecules/table/components/DefaultCellHeader.tsx +3 -3
- package/src/molecules/table/components/DefaultOperationButton.tsx +1 -1
- package/src/molecules/table/filters/Filters.ts +2 -2
- package/src/molecules/table/hooks/useUniqValues.tsx +7 -3
- package/src/molecules/table/utils/mapFormToColumns.tsx +4 -4
- package/src/molecules/tabs/Tab.tsx +3 -3
- package/src/molecules/tabs/TabPanel.tsx +2 -2
- package/src/molecules/tabs/Tabs.tsx +2 -2
- package/src/organisms/form/builder/FormEdit.tsx +2 -2
- package/src/organisms/modal/RemoveModal.tsx +3 -3
- package/src/organisms/table/actions/ActionsTable.tsx +2 -2
- package/src/organisms/table/forms/components/FormsCell.tsx +1 -1
- package/dist/chunks/index2.js +0 -59979
- package/dist/chunks/index2.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tabs.js","sources":["../../../src/molecules/tabs/Tabs.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"Tabs.js","sources":["../../../src/molecules/tabs/Tabs.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport type { CSSProperties, PropsWithChildren } from \"react\";\n\nimport { registerComponent } from \"../../registries/components.js\";\nimport { TabsProvider } from \"./context/TabControl.js\";\n\nexport interface TabsProps extends Record<string, any> {\n style?: CSSProperties;\n className?: string;\n selected?: number;\n}\n\nexport function Tabs({ style, selected, children, className }: PropsWithChildren<TabsProps>) {\n return (\n <div data-testid={\"Tabs\"} className={clsx(\"tw-tabs\", className)} style={style}>\n <TabsProvider selected={selected}>{children}</TabsProvider>\n </div>\n );\n}\n\nregisterComponent(\"Tabs\", Tabs);\n"],"names":["Tabs","style","selected","children","className","jsx","clsx","TabsProvider","registerComponent"],"mappings":";;;;AAYO,SAASA,EAAK,EAAE,OAAAC,GAAO,UAAAC,GAAU,UAAAC,GAAU,WAAAC,KAA2C;AAC3F,SACE,gBAAAC,EAAC,OAAA,EAAI,eAAa,QAAQ,WAAWC,EAAK,WAAWF,CAAS,GAAG,OAAAH,GAC/D,UAAA,gBAAAI,EAACE,GAAA,EAAa,UAAAL,GAAqB,UAAAC,GAAS,GAC9C;AAEJ;AAEAK,EAAkB,QAAQR,CAAI;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs as m, jsx as l } from "react/jsx-runtime";
|
|
2
2
|
import { g as f } from "../../../chunks/_commonjsHelpers.js";
|
|
3
|
-
import { r as c } from "../../../chunks/
|
|
3
|
+
import { r as c } from "../../../chunks/index.js";
|
|
4
4
|
import { Form as p } from "../Form.js";
|
|
5
5
|
var d = c();
|
|
6
6
|
const n = /* @__PURE__ */ f(d);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs as s, jsx as d } from "react/jsx-runtime";
|
|
2
2
|
import { createElement as j } from "react";
|
|
3
|
-
import { c as v } from "../../../chunks/
|
|
3
|
+
import { c as v } from "../../../chunks/clsx.js";
|
|
4
4
|
import { getComponent as n } from "../../../registries/components.js";
|
|
5
5
|
import { useFormEdit as A } from "./useFormEdit.js";
|
|
6
6
|
function T({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormEdit.js","sources":["../../../../src/organisms/form/builder/FormEdit.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"FormEdit.js","sources":["../../../../src/organisms/form/builder/FormEdit.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport type { CSSProperties } from \"react\";\n\nimport type { FormBuilderOptions, FormOptions } from \"../../../interfaces/index.js\";\nimport { getComponent } from \"../../../registries/components\";\nimport { FormBuilder as DefaultFormBuilder } from \"./FormBuilder\";\nimport { FormEditCTAs as DefaultFormEditCTAs } from \"./FormEditCtas\";\nimport { FormParameters as DefaultFormParameters } from \"./FormParameters\";\nimport { FormBuilderEvents } from \"./useFormBuilder\";\nimport { useFormEdit, UseFormEditHookProps } from \"./useFormEdit\";\n\nexport interface FormEditProps extends UseFormEditHookProps, FormBuilderEvents {\n options?: FormBuilderOptions & FormOptions;\n layout?: \"html5\" | \"choicesjs\" | \"react\";\n className?: string;\n style?: CSSProperties;\n}\n\nexport function FormEdit({\n form: initialForm,\n typeChoices,\n displayChoices,\n enableTags,\n onSubmit: initialOnSubmit,\n onCopy: initialOnCopy,\n className,\n style,\n ...props\n}: FormEditProps) {\n const { form, isValid, setChange, hasRedo, hasChanged, hasUndo, redo, undo, reset, onSubmit, onCopy } = useFormEdit({\n form: initialForm,\n typeChoices,\n displayChoices,\n enableTags,\n onSubmit: initialOnSubmit,\n onCopy: initialOnCopy\n });\n\n const FormParameters = getComponent<typeof DefaultFormParameters>(\"FormParameters\");\n const FormBuilder = getComponent<typeof DefaultFormBuilder>(\"FormBuilder\");\n const FormEditCTAs = getComponent<typeof DefaultFormEditCTAs>(\"FormEditCTAs\");\n\n return (\n <div className={clsx(\"form-edit-container\", className)} style={style}>\n <div className='form-edit'>\n <FormParameters\n enableTags={enableTags}\n typeChoices={typeChoices}\n displayChoices={displayChoices}\n key={`form-settings-${form._id}`}\n form={form}\n onChange={setChange}\n layout={props.layout}\n />\n <FormEditCTAs\n key={`form-edit-ctas-${form._id}`}\n options={props.options}\n hasRedo={hasRedo}\n hasUndo={hasUndo}\n disabled={!(isValid && hasChanged)}\n onRedo={redo}\n onUndo={undo}\n onReset={reset}\n onCopy={onCopy}\n onSubmit={onSubmit}\n />\n </div>\n\n <FormBuilder\n {...props}\n key={`form-builder-${form._id}`}\n components={form.components!}\n display={form.display}\n options={props.options}\n onChange={(components) => {\n setChange(\"components\", components);\n }}\n />\n </div>\n );\n}\n"],"names":["FormEdit","initialForm","typeChoices","displayChoices","enableTags","initialOnSubmit","initialOnCopy","className","style","props","form","isValid","setChange","hasRedo","hasChanged","hasUndo","redo","undo","reset","onSubmit","onCopy","useFormEdit","FormParameters","getComponent","FormBuilder","FormEditCTAs","clsx","jsxs","jsx","createElement","components"],"mappings":";;;;;AAkBO,SAASA,EAAS;AAAA,EACvB,MAAMC;AAAA,EACN,aAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,YAAAC;AAAA,EACA,UAAUC;AAAA,EACV,QAAQC;AAAA,EACR,WAAAC;AAAA,EACA,OAAAC;AAAA,EACA,GAAGC;AACL,GAAkB;AAChB,QAAM,EAAE,MAAAC,GAAM,SAAAC,GAAS,WAAAC,GAAW,SAAAC,GAAS,YAAAC,GAAY,SAAAC,GAAS,MAAAC,GAAM,MAAAC,GAAM,OAAAC,GAAO,UAAAC,GAAU,QAAAC,EAAA,IAAWC,EAAY;AAAA,IAClH,MAAMpB;AAAA,IACN,aAAAC;AAAA,IACA,gBAAAC;AAAA,IACA,YAAAC;AAAA,IACA,UAAUC;AAAA,IACV,QAAQC;AAAA,EAAA,CACT,GAEKgB,IAAiBC,EAA2C,gBAAgB,GAC5EC,IAAcD,EAAwC,aAAa,GACnEE,IAAeF,EAAyC,cAAc;AAE5E,2BACG,OAAA,EAAI,WAAWG,EAAK,uBAAuBnB,CAAS,GAAG,OAAAC,GACtD,UAAA;AAAA,IAAA,gBAAAmB,EAAC,OAAA,EAAI,WAAU,aACb,UAAA;AAAA,MAAA,gBAAAC;AAAA,QAACN;AAAA,QAAA;AAAA,UACC,YAAAlB;AAAA,UACA,aAAAF;AAAA,UACA,gBAAAC;AAAA,UAEA,MAAAO;AAAA,UACA,UAAUE;AAAA,UACV,QAAQH,EAAM;AAAA,QAAA;AAAA,QAHT,iBAAiBC,EAAK,GAAG;AAAA,MAAA;AAAA,MAKhC,gBAAAkB;AAAA,QAACH;AAAA,QAAA;AAAA,UAEC,SAAShB,EAAM;AAAA,UACf,SAAAI;AAAA,UACA,SAAAE;AAAA,UACA,UAAU,EAAEJ,KAAWG;AAAA,UACvB,QAAQE;AAAA,UACR,QAAQC;AAAA,UACR,SAASC;AAAA,UACT,QAAAE;AAAA,UACA,UAAAD;AAAA,QAAA;AAAA,QATK,kBAAkBT,EAAK,GAAG;AAAA,MAAA;AAAA,IAUjC,GACF;AAAA,IAEA,gBAAAmB;AAAA,MAACL;AAAA,MAAA;AAAA,QACE,GAAGf;AAAA,QACJ,KAAK,gBAAgBC,EAAK,GAAG;AAAA,QAC7B,YAAYA,EAAK;AAAA,QACjB,SAASA,EAAK;AAAA,QACd,SAASD,EAAM;AAAA,QACf,UAAU,CAACqB,MAAe;AACxB,UAAAlB,EAAU,cAAckB,CAAU;AAAA,QACpC;AAAA,MAAA;AAAA,IAAA;AAAA,EACF,GACF;AAEJ;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as n, jsxs as t } from "react/jsx-runtime";
|
|
2
|
-
import { c as s } from "../../chunks/
|
|
2
|
+
import { c as s } from "../../chunks/clsx.js";
|
|
3
3
|
import { useState as d } from "react";
|
|
4
4
|
import { InputText as u } from "../../molecules/forms/input-text/InputText.js";
|
|
5
5
|
import { Modal as h } from "../../molecules/modal/Modal.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RemoveModal.js","sources":["../../../src/organisms/modal/RemoveModal.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"RemoveModal.js","sources":["../../../src/organisms/modal/RemoveModal.tsx"],"sourcesContent":["import clsx from \"clsx\";\nimport { PropsWithChildren, useState } from \"react\";\n\nimport { InputText } from \"../../molecules/forms/input-text/InputText\";\nimport { Modal, ModalProps } from \"../../molecules/modal/Modal\";\nimport { iconClass } from \"../../utils/iconClass\";\n\nfunction RemoveModalFooter({ value, valueToCompare, onSubmit, onClose, i18n = (f: string) => f }: ModalProps) {\n return (\n <div className={\"flex items-center justify-center bg-white p-2\"}>\n <button data-testid='customCloseModal' className={\"btn btn-outline-dark mx-2\"} onClick={onClose}>\n {i18n(\"Cancel\")}\n </button>\n <button\n disabled={valueToCompare !== value}\n data-testid='customSubmitModal'\n className={\"btn btn-danger mx-2\"}\n onClick={(e) => {\n if (valueToCompare === value) {\n onSubmit(e);\n }\n }}\n >\n <i className={clsx(iconClass(undefined, \"trash\"), \"mr-2\")} />\n {i18n(\"Remove\")}\n </button>\n </div>\n );\n}\n\nexport interface RemoveModalProps extends ModalProps {\n valueToCompare: string;\n itemType?: string;\n i18n?: (f: string) => string;\n maxWidth?: string;\n}\n\nexport function RemoveModal({ maxWidth = \"300px\", children, ...props }: PropsWithChildren<RemoveModalProps>) {\n const { i18n = (f) => f } = props;\n const [value, setValue] = useState();\n\n return (\n <Modal\n {...props}\n className={clsx(props.className, \"formio-dialog-theme-remove\")}\n style={{ maxWidth }}\n title={`Drop ${props.itemType?.toLowerCase()}`}\n value={value}\n footer={RemoveModalFooter}\n >\n <div className='px-4 pt-3 pb-5'>\n <div className='pb-1'>\n {children}\n {i18n(\"To drop\")} <strong>{props.valueToCompare}</strong>, \n {i18n(\"type the\")} \n <strong>"{props.itemType?.toLowerCase()}"</strong> \n {i18n(\"name\")} <strong>"{props.valueToCompare}"</strong>.\n </div>\n <InputText name='remove' value={value} onChange={(name, value) => setValue(value)} />\n </div>\n </Modal>\n );\n}\n"],"names":["RemoveModalFooter","value","valueToCompare","onSubmit","onClose","i18n","f","jsxs","jsx","e","clsx","iconClass","RemoveModal","maxWidth","children","props","setValue","useState","Modal","InputText","name"],"mappings":";;;;;;AAOA,SAASA,EAAkB,EAAE,OAAAC,GAAO,gBAAAC,GAAgB,UAAAC,GAAU,SAAAC,GAAS,MAAAC,IAAO,CAACC,MAAcA,KAAiB;AAC5G,SACE,gBAAAC,EAAC,OAAA,EAAI,WAAW,iDACd,UAAA;AAAA,IAAA,gBAAAC,EAAC,UAAA,EAAO,eAAY,oBAAmB,WAAW,6BAA6B,SAASJ,GACrF,UAAAC,EAAK,QAAQ,EAAA,CAChB;AAAA,IACA,gBAAAE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,UAAUL,MAAmBD;AAAA,QAC7B,eAAY;AAAA,QACZ,WAAW;AAAA,QACX,SAAS,CAACQ,MAAM;AACd,UAAIP,MAAmBD,KACrBE,EAASM,CAAC;AAAA,QAEd;AAAA,QAEA,UAAA;AAAA,UAAA,gBAAAD,EAAC,KAAA,EAAE,WAAWE,EAAKC,EAAU,QAAW,OAAO,GAAG,MAAM,GAAG;AAAA,UAC1DN,EAAK,QAAQ;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAChB,GACF;AAEJ;AASO,SAASO,EAAY,EAAE,UAAAC,IAAW,SAAS,UAAAC,GAAU,GAAGC,KAA8C;AAC3G,QAAM,EAAE,MAAAV,IAAO,CAACC,MAAMA,MAAMS,GACtB,CAACd,GAAOe,CAAQ,IAAIC,EAAA;AAE1B,SACE,gBAAAT;AAAA,IAACU;AAAA,IAAA;AAAA,MACE,GAAGH;AAAA,MACJ,WAAWL,EAAKK,EAAM,WAAW,4BAA4B;AAAA,MAC7D,OAAO,EAAE,UAAAF,EAAA;AAAA,MACT,OAAO,QAAQE,EAAM,UAAU,aAAa;AAAA,MAC5C,OAAAd;AAAA,MACA,QAAQD;AAAA,MAER,UAAA,gBAAAO,EAAC,OAAA,EAAI,WAAU,kBACb,UAAA;AAAA,QAAA,gBAAAA,EAAC,OAAA,EAAI,WAAU,QACZ,UAAA;AAAA,UAAAO;AAAA,UACAT,EAAK,SAAS;AAAA,UAAE;AAAA,UAAC,gBAAAG,EAAC,UAAA,EAAQ,UAAAO,EAAM,eAAA,CAAe;AAAA,UAAS;AAAA,UACxDV,EAAK,UAAU;AAAA,UAAE;AAAA,4BACjB,UAAA,EAAO,UAAA;AAAA,YAAA;AAAA,YAAOU,EAAM,UAAU,YAAA;AAAA,YAAc;AAAA,UAAA,GAAM;AAAA,UAAS;AAAA,UAC3DV,EAAK,MAAM;AAAA,UAAE;AAAA,4BAAE,UAAA,EAAO,UAAA;AAAA,YAAA;AAAA,YAAOU,EAAM;AAAA,YAAe;AAAA,UAAA,GAAM;AAAA,UAAS;AAAA,QAAA,GACpE;AAAA,QACA,gBAAAP,EAACW,GAAA,EAAU,MAAK,UAAS,OAAAlB,GAAc,UAAU,CAACmB,GAAMnB,MAAUe,EAASf,CAAK,EAAA,CAAG;AAAA,MAAA,EAAA,CACrF;AAAA,IAAA;AAAA,EAAA;AAGN;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as o, jsxs as n } from "react/jsx-runtime";
|
|
2
|
-
import { c as m } from "../../../chunks/
|
|
2
|
+
import { c as m } from "../../../chunks/clsx.js";
|
|
3
3
|
import { n as d } from "../../../chunks/noop.js";
|
|
4
4
|
import { useState as p } from "react";
|
|
5
5
|
import { useI18n as u } from "../../../hooks/useI18n.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ActionsTable.js","sources":["../../../../src/organisms/table/actions/ActionsTable.tsx"],"sourcesContent":["import { ColumnDef } from \"@tanstack/react-table\";\nimport
|
|
1
|
+
{"version":3,"file":"ActionsTable.js","sources":["../../../../src/organisms/table/actions/ActionsTable.tsx"],"sourcesContent":["import { ColumnDef } from \"@tanstack/react-table\";\nimport clsx from \"clsx\";\nimport noop from \"lodash/noop\";\nimport { useState } from \"react\";\n\nimport { useI18n } from \"../../../hooks/useI18n.js\";\nimport { ActionType, type FormOptions } from \"../../../interfaces\";\nimport { Select } from \"../../../molecules/forms/select/Select\";\nimport { Table, type TableProps } from \"../../../molecules/table/Table\";\nimport { iconClass } from \"../../../utils/iconClass\";\n\nexport type ActionsTableProps = Omit<TableProps<ActionType>, \"columns\"> & {\n onAddAction?: (actionName: string) => void;\n availableActions?: { label: string; value: string }[];\n i18n?: FormOptions[\"i18n\"];\n};\n\nexport function ActionsTable({ availableActions = [], onAddAction = noop, ...props }: ActionsTableProps) {\n const { t } = useI18n(props.i18n);\n const [currentAction, setAction] = useState(\"\");\n\n const columns: ColumnDef<ActionType>[] = [\n {\n header: t(\"Action\"),\n accessorKey: \"title\"\n }\n ];\n\n return (\n <Table {...props} columns={columns}>\n <div className={\"pagination-group\"}>\n <Select\n data-testid={\"action-table-select\"}\n name={\"actions\"}\n value={currentAction}\n options={[{ label: t(\"Select an action\"), value: \"\" }].concat(availableActions)}\n onChange={(_, action) => setAction(action)}\n />\n <div className={\"pl-3\"}>\n <button\n data-testid={\"action-table-add\"}\n disabled={currentAction === \"\"}\n className={\"btn btn-success\"}\n onClick={() => currentAction && onAddAction(currentAction)}\n type={\"submit\"}\n >\n <i className={clsx(iconClass(undefined, \"plus\"), \"mr-1\")} /> {t(\"Add action\")}\n </button>\n </div>\n </div>\n </Table>\n );\n}\n"],"names":["ActionsTable","availableActions","onAddAction","noop","props","t","useI18n","currentAction","setAction","useState","columns","jsx","Table","jsxs","Select","_","action","clsx","iconClass"],"mappings":";;;;;;;;AAiBO,SAASA,EAAa,EAAE,kBAAAC,IAAmB,CAAA,GAAI,aAAAC,IAAcC,GAAM,GAAGC,KAA4B;AACvG,QAAM,EAAE,GAAAC,EAAA,IAAMC,EAAQF,EAAM,IAAI,GAC1B,CAACG,GAAeC,CAAS,IAAIC,EAAS,EAAE,GAExCC,IAAmC;AAAA,IACvC;AAAA,MACE,QAAQL,EAAE,QAAQ;AAAA,MAClB,aAAa;AAAA,IAAA;AAAA,EACf;AAGF,SACE,gBAAAM,EAACC,KAAO,GAAGR,GAAO,SAAAM,GAChB,UAAA,gBAAAG,EAAC,OAAA,EAAI,WAAW,oBACd,UAAA;AAAA,IAAA,gBAAAF;AAAA,MAACG;AAAA,MAAA;AAAA,QACC,eAAa;AAAA,QACb,MAAM;AAAA,QACN,OAAOP;AAAA,QACP,SAAS,CAAC,EAAE,OAAOF,EAAE,kBAAkB,GAAG,OAAO,GAAA,CAAI,EAAE,OAAOJ,CAAgB;AAAA,QAC9E,UAAU,CAACc,GAAGC,MAAWR,EAAUQ,CAAM;AAAA,MAAA;AAAA,IAAA;AAAA,IAE3C,gBAAAL,EAAC,OAAA,EAAI,WAAW,QACd,UAAA,gBAAAE;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,eAAa;AAAA,QACb,UAAUN,MAAkB;AAAA,QAC5B,WAAW;AAAA,QACX,SAAS,MAAMA,KAAiBL,EAAYK,CAAa;AAAA,QACzD,MAAM;AAAA,QAEN,UAAA;AAAA,UAAA,gBAAAI,EAAC,KAAA,EAAE,WAAWM,EAAKC,EAAU,QAAW,MAAM,GAAG,MAAM,GAAG;AAAA,UAAE;AAAA,UAAEb,EAAE,YAAY;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA,EAC9E,CACF;AAAA,EAAA,EAAA,CACF,EAAA,CACF;AAEJ;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsxs as e, jsx as a } from "react/jsx-runtime";
|
|
2
|
-
import { c as t } from "../../../../chunks/
|
|
2
|
+
import { c as t } from "../../../../chunks/clsx.js";
|
|
3
3
|
import { h as m } from "../../../../chunks/moment.js";
|
|
4
4
|
import { registerComponent as c } from "../../../../registries/components.js";
|
|
5
5
|
import { iconClass as r } from "../../../../utils/iconClass.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormsCell.js","sources":["../../../../../src/organisms/table/forms/components/FormsCell.tsx"],"sourcesContent":["import { CellContext } from \"@tanstack/react-table\";\nimport cx from \"
|
|
1
|
+
{"version":3,"file":"FormsCell.js","sources":["../../../../../src/organisms/table/forms/components/FormsCell.tsx"],"sourcesContent":["import { CellContext } from \"@tanstack/react-table\";\nimport cx from \"clsx\";\nimport moment from \"moment\";\n\nimport type { FormType } from \"../../../../interfaces/index.js\";\nimport { registerComponent } from \"../../../../registries/components.js\";\nimport { iconClass } from \"../../../../utils/iconClass\";\nimport { stopPropagationWrapper } from \"../../../../utils/stopPropagationWrapper\";\n\nexport function FormsCell(\n props: CellContext<FormType, any> & {\n i18n: (i18n: string) => string;\n }\n) {\n const {\n row: { original: form }\n } = props;\n\n return (\n <div className={\"p-1\"}>\n <h4 className={\"text-primary text-lg flex space-x-2 items-center\"}>\n <i className={cx(iconClass(undefined, \"server\"), \"text-secondary\")} />\n <span>{form.title}</span>\n </h4>\n\n <ul className='reset-list text-gray-500'>\n <li className={\"text-sm\"}>Name: {form.name || form.machineName}</li>\n <li className='mt-5 flex space-x-1'>\n <span className='badge bg-light flex space-x-1'>\n <i className={iconClass(undefined, \"history\")} />\n <span>Updated {moment(form.modified).fromNow()}</span>\n </span>\n\n {(form.tags || []).map((tag, index) => (\n <button\n key={index}\n className='badge badge-hover bg-secondary flex space-x-1'\n onClick={stopPropagationWrapper(() => {\n // props.setFilter(\"tags\", tag);\n // props.gotoPage(0);\n })}\n >\n <i className={iconClass(undefined, \"tags\")} />\n <span>{tag}</span>\n </button>\n ))}\n </li>\n </ul>\n </div>\n );\n}\n\nregisterComponent(\"FormsCell\", FormsCell);\n"],"names":["FormsCell","props","form","jsxs","jsx","cx","iconClass","moment","tag","index","stopPropagationWrapper","registerComponent"],"mappings":";;;;;;AASO,SAASA,EACdC,GAGA;AACA,QAAM;AAAA,IACJ,KAAK,EAAE,UAAUC,EAAA;AAAA,EAAK,IACpBD;AAEJ,SACE,gBAAAE,EAAC,OAAA,EAAI,WAAW,OACd,UAAA;AAAA,IAAA,gBAAAA,EAAC,MAAA,EAAG,WAAW,oDACb,UAAA;AAAA,MAAA,gBAAAC,EAAC,KAAA,EAAE,WAAWC,EAAGC,EAAU,QAAW,QAAQ,GAAG,gBAAgB,GAAG;AAAA,MACpE,gBAAAF,EAAC,QAAA,EAAM,UAAAF,EAAK,MAAA,CAAM;AAAA,IAAA,GACpB;AAAA,IAEA,gBAAAC,EAAC,MAAA,EAAG,WAAU,4BACZ,UAAA;AAAA,MAAA,gBAAAA,EAAC,MAAA,EAAG,WAAW,WAAW,UAAA;AAAA,QAAA;AAAA,QAAOD,EAAK,QAAQA,EAAK;AAAA,MAAA,GAAY;AAAA,MAC/D,gBAAAC,EAAC,MAAA,EAAG,WAAU,uBACZ,UAAA;AAAA,QAAA,gBAAAA,EAAC,QAAA,EAAK,WAAU,iCACd,UAAA;AAAA,UAAA,gBAAAC,EAAC,KAAA,EAAE,WAAWE,EAAU,QAAW,SAAS,GAAG;AAAA,4BAC9C,QAAA,EAAK,UAAA;AAAA,YAAA;AAAA,YAASC,EAAOL,EAAK,QAAQ,EAAE,QAAA;AAAA,UAAQ,EAAA,CAAE;AAAA,QAAA,GACjD;AAAA,SAEEA,EAAK,QAAQ,CAAA,GAAI,IAAI,CAACM,GAAKC,MAC3B,gBAAAN;AAAA,UAAC;AAAA,UAAA;AAAA,YAEC,WAAU;AAAA,YACV,SAASO,EAAuB,MAAM;AAAA,YAGtC,CAAC;AAAA,YAED,UAAA;AAAA,cAAA,gBAAAN,EAAC,KAAA,EAAE,WAAWE,EAAU,QAAW,MAAM,GAAG;AAAA,cAC5C,gBAAAF,EAAC,UAAM,UAAAI,EAAA,CAAI;AAAA,YAAA;AAAA,UAAA;AAAA,UARNC;AAAA,QAAA,CAUR;AAAA,MAAA,EAAA,CACH;AAAA,IAAA,EAAA,CACF;AAAA,EAAA,GACF;AAEJ;AAEAE,EAAkB,aAAaX,CAAS;"}
|
package/dist/utils/iconClass.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/react-formio",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.25",
|
|
4
4
|
"description": "Provide a react formio wrapper. Written in TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"watch": "vite build --watch"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"
|
|
27
|
+
"clsx": "2.1.1",
|
|
28
28
|
"eventemitter2": "^6.4.3",
|
|
29
29
|
"use-debounce": "^10.0.4"
|
|
30
30
|
},
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@tanstack/react-table": ">=8.20.6",
|
|
47
|
-
"@tsed/tailwind-formio": "3.0.0-rc.
|
|
48
|
-
"@tsed/typescript": "3.0.0-rc.
|
|
47
|
+
"@tsed/tailwind-formio": "3.0.0-rc.25",
|
|
48
|
+
"@tsed/typescript": "3.0.0-rc.25",
|
|
49
49
|
"microbundle": "0.13.0",
|
|
50
50
|
"vite": "7.1.5",
|
|
51
51
|
"vitest": "3.2.4"
|
package/src/atoms/icon/Icon.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import clsx from "clsx";
|
|
2
2
|
import { PropsWithChildren } from "react";
|
|
3
3
|
|
|
4
4
|
import { registerComponent } from "../../registries/components.js";
|
|
@@ -10,7 +10,7 @@ export interface CardProps {
|
|
|
10
10
|
|
|
11
11
|
export function Card({ children, label, className }: PropsWithChildren<CardProps>) {
|
|
12
12
|
return (
|
|
13
|
-
<div className={
|
|
13
|
+
<div className={clsx("card", className)}>
|
|
14
14
|
<div className={"card-header "}>
|
|
15
15
|
<h4 className={"card-title"}>{label}</h4>
|
|
16
16
|
</div>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import clsx from "clsx";
|
|
2
2
|
import omit from "lodash/omit";
|
|
3
3
|
import { HTMLAttributes, InputHTMLAttributes, PropsWithChildren, ReactNode } from "react";
|
|
4
4
|
|
|
@@ -42,7 +42,7 @@ export function FormControl<Value = unknown>({
|
|
|
42
42
|
<div
|
|
43
43
|
data-testid={name && `form-group-${name}`}
|
|
44
44
|
id={`form-group-${name || ""}`}
|
|
45
|
-
className={
|
|
45
|
+
className={clsx(
|
|
46
46
|
"form-group",
|
|
47
47
|
{
|
|
48
48
|
"-with-before": !!before,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "./ChoicesSelect";
|
|
2
2
|
|
|
3
3
|
import { Meta, StoryObj } from "@storybook/react-vite";
|
|
4
|
-
import { fn } from "storybook/test";
|
|
4
|
+
import { expect, fn, userEvent, waitFor, within } from "storybook/test";
|
|
5
5
|
|
|
6
6
|
import { iconClass } from "../../../../utils/iconClass";
|
|
7
7
|
import { useValue } from "../../../__fixtures__/useValue.hook";
|
|
@@ -21,6 +21,36 @@ const options = [
|
|
|
21
21
|
value: "option-3"
|
|
22
22
|
}
|
|
23
23
|
];
|
|
24
|
+
|
|
25
|
+
const OptionTemplate = ({ label, data }: any) => {
|
|
26
|
+
return (
|
|
27
|
+
<span style={{ display: "flex", justifyContent: "space-between", width: "100%" }}>
|
|
28
|
+
<span>{label}</span>
|
|
29
|
+
<small style={{ opacity: 0.7 }}>{data?.hint}</small>
|
|
30
|
+
</span>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
async function openChoicesDropdown(canvasElement: HTMLElement) {
|
|
35
|
+
await waitFor(() => {
|
|
36
|
+
expect(canvasElement.querySelector(".choices")).toBeInTheDocument();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const choicesElement = canvasElement.querySelector(".choices") as HTMLElement;
|
|
40
|
+
const inner = choicesElement.querySelector(".choices__inner") as HTMLElement;
|
|
41
|
+
|
|
42
|
+
await userEvent.click(inner);
|
|
43
|
+
|
|
44
|
+
await waitFor(() => {
|
|
45
|
+
expect(choicesElement.classList.contains("is-open")).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
return choicesElement;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function sleep(ms = 300) {
|
|
52
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
53
|
+
}
|
|
24
54
|
/**
|
|
25
55
|
* ChoicesJS select component.
|
|
26
56
|
*
|
|
@@ -38,7 +68,13 @@ export default {
|
|
|
38
68
|
component: Select,
|
|
39
69
|
parameters: {
|
|
40
70
|
layout: "centered",
|
|
41
|
-
backgrounds: { default: "pearl" }
|
|
71
|
+
backgrounds: { default: "pearl" },
|
|
72
|
+
docs: {
|
|
73
|
+
description: {
|
|
74
|
+
component:
|
|
75
|
+
"Choices.js layout using the v11 template callback API. Custom option renderers should be passed with `customProperties.template` on each option to keep Choices `data-*` and ARIA attributes intact."
|
|
76
|
+
}
|
|
77
|
+
}
|
|
42
78
|
},
|
|
43
79
|
args: {
|
|
44
80
|
layout: "choicesjs"
|
|
@@ -95,6 +131,34 @@ export const Usage: Story = {
|
|
|
95
131
|
value: "option-1",
|
|
96
132
|
options,
|
|
97
133
|
onChange: fn()
|
|
134
|
+
},
|
|
135
|
+
parameters: {
|
|
136
|
+
docs: {
|
|
137
|
+
description: {
|
|
138
|
+
story: "Baseline story for default Choices rendering (no custom option template)."
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
play: async ({ canvasElement, args }) => {
|
|
143
|
+
const canvas = within(canvasElement);
|
|
144
|
+
const select = canvas.getByTestId("select_name");
|
|
145
|
+
|
|
146
|
+
await waitFor(() => {
|
|
147
|
+
expect(select).toHaveValue("option-1");
|
|
148
|
+
});
|
|
149
|
+
await sleep();
|
|
150
|
+
|
|
151
|
+
const choicesElement = await openChoicesDropdown(canvasElement);
|
|
152
|
+
await sleep();
|
|
153
|
+
const option = choicesElement.querySelector('[data-choice-selectable][data-value="option-2"]') as HTMLElement;
|
|
154
|
+
|
|
155
|
+
await userEvent.click(option);
|
|
156
|
+
await sleep();
|
|
157
|
+
|
|
158
|
+
await waitFor(() => {
|
|
159
|
+
expect(select).toHaveValue("option-2");
|
|
160
|
+
expect(args.onChange).toHaveBeenCalledWith("name", "option-2");
|
|
161
|
+
});
|
|
98
162
|
}
|
|
99
163
|
};
|
|
100
164
|
|
|
@@ -330,3 +394,71 @@ export const WithGroupsAndMultiple: Story = {
|
|
|
330
394
|
]
|
|
331
395
|
}
|
|
332
396
|
};
|
|
397
|
+
|
|
398
|
+
export const WithCustomOptionTemplate: Story = {
|
|
399
|
+
args: {
|
|
400
|
+
label: "Label",
|
|
401
|
+
name: "name",
|
|
402
|
+
value: "",
|
|
403
|
+
placeholder: "Select an option",
|
|
404
|
+
onChange: fn(),
|
|
405
|
+
options: [
|
|
406
|
+
{
|
|
407
|
+
label: "Option 1",
|
|
408
|
+
value: "option-1",
|
|
409
|
+
customProperties: {
|
|
410
|
+
hint: "alpha",
|
|
411
|
+
template: OptionTemplate
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
label: "Option 2",
|
|
416
|
+
value: "option-2",
|
|
417
|
+
customProperties: {
|
|
418
|
+
hint: "beta",
|
|
419
|
+
template: OptionTemplate
|
|
420
|
+
}
|
|
421
|
+
},
|
|
422
|
+
{
|
|
423
|
+
label: "Option 3",
|
|
424
|
+
value: "option-3",
|
|
425
|
+
customProperties: {
|
|
426
|
+
hint: "gamma",
|
|
427
|
+
template: OptionTemplate
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
]
|
|
431
|
+
},
|
|
432
|
+
parameters: {
|
|
433
|
+
docs: {
|
|
434
|
+
description: {
|
|
435
|
+
story:
|
|
436
|
+
"Demonstrates the v11-compatible custom option renderer via `option.customProperties.template`. The callback keeps required Choices attributes (`data-choice`, `data-id`, `data-value`, roles)."
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
play: async ({ canvasElement, args }) => {
|
|
441
|
+
const canvas = within(canvasElement);
|
|
442
|
+
const select = canvas.getByTestId("select_name");
|
|
443
|
+
|
|
444
|
+
const choicesElement = await openChoicesDropdown(canvasElement);
|
|
445
|
+
await sleep();
|
|
446
|
+
const customOption = choicesElement.querySelector('[data-choice][data-value="option-1"]') as HTMLElement;
|
|
447
|
+
|
|
448
|
+
await waitFor(() => {
|
|
449
|
+
expect(customOption).toBeInTheDocument();
|
|
450
|
+
expect(customOption).toHaveAttribute("role", "option");
|
|
451
|
+
expect(customOption).toHaveTextContent("alpha");
|
|
452
|
+
});
|
|
453
|
+
await sleep();
|
|
454
|
+
|
|
455
|
+
const option = choicesElement.querySelector('[data-choice-selectable][data-value="option-3"]') as HTMLElement;
|
|
456
|
+
await userEvent.click(option);
|
|
457
|
+
await sleep();
|
|
458
|
+
|
|
459
|
+
await waitFor(() => {
|
|
460
|
+
expect(select).toHaveValue("option-3");
|
|
461
|
+
expect(args.onChange).toHaveBeenCalledWith("name", "option-3");
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import Choices from "choices.js";
|
|
2
|
-
import cx from "
|
|
2
|
+
import cx from "clsx";
|
|
3
3
|
import { useEffect, useMemo, useRef } from "react";
|
|
4
4
|
import { useDebouncedCallback } from "use-debounce";
|
|
5
5
|
|
|
6
6
|
import { registerComponent } from "../../../../registries/components";
|
|
7
7
|
import { cleanFormControlProps } from "../../form-control/FormControl";
|
|
8
8
|
import type { AllSelectProps } from "../Select.interface";
|
|
9
|
-
import { callbackOnCreateTemplates } from "./choices.template";
|
|
9
|
+
import { callbackOnCreateTemplates as defaultTemplateCallback } from "./choices.template";
|
|
10
10
|
|
|
11
11
|
export function useChoices({
|
|
12
12
|
name,
|
|
@@ -75,7 +75,14 @@ export function useChoices({
|
|
|
75
75
|
|
|
76
76
|
useEffect(() => {
|
|
77
77
|
if (!choicesRef.current) {
|
|
78
|
-
const {
|
|
78
|
+
const {
|
|
79
|
+
allowHTML = true,
|
|
80
|
+
silent = true,
|
|
81
|
+
removeItemButton = true,
|
|
82
|
+
shouldSort = false,
|
|
83
|
+
itemSelectText = "",
|
|
84
|
+
callbackOnCreateTemplates
|
|
85
|
+
} = customProperties;
|
|
79
86
|
choicesRef.current = new Choices(ref.current, {
|
|
80
87
|
...customProperties,
|
|
81
88
|
allowHTML,
|
|
@@ -87,7 +94,7 @@ export function useChoices({
|
|
|
87
94
|
placeholderValue: "" as string,
|
|
88
95
|
itemSelectText,
|
|
89
96
|
shouldSort,
|
|
90
|
-
callbackOnCreateTemplates
|
|
97
|
+
callbackOnCreateTemplates: callbackOnCreateTemplates || defaultTemplateCallback
|
|
91
98
|
} as any);
|
|
92
99
|
}
|
|
93
100
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import cx from "
|
|
1
|
+
import cx from "clsx";
|
|
2
2
|
|
|
3
3
|
import { registerComponent } from "../../../../registries/components";
|
|
4
4
|
import { getEventValue } from "../../../../utils/getEventValue";
|
|
@@ -35,17 +35,17 @@ export function HTMLSelect({ name, id = name, size, value, multiple, onChange, o
|
|
|
35
35
|
</option>
|
|
36
36
|
)}
|
|
37
37
|
{hasGroup
|
|
38
|
-
? options.map(({ label, options }) => {
|
|
38
|
+
? options.map(({ label, options }, index) => {
|
|
39
39
|
return (
|
|
40
|
-
<optgroup key={
|
|
41
|
-
{options.map((props: SelectOptionBaseProps) => {
|
|
42
|
-
return <Option key={
|
|
40
|
+
<optgroup key={id + "-" + index} label={label}>
|
|
41
|
+
{options.map((props: SelectOptionBaseProps, index: number) => {
|
|
42
|
+
return <Option key={`${id}-optgroup-${index}`} {...props} />;
|
|
43
43
|
})}
|
|
44
44
|
</optgroup>
|
|
45
45
|
);
|
|
46
46
|
})
|
|
47
|
-
: (options as SelectOptionBaseProps[]).map((props) => {
|
|
48
|
-
return <Option key={
|
|
47
|
+
: (options as SelectOptionBaseProps[]).map((props, index) => {
|
|
48
|
+
return <Option key={`${id}-option-${index}`} {...props} />;
|
|
49
49
|
})}
|
|
50
50
|
</select>
|
|
51
51
|
);
|
|
@@ -1,38 +1,60 @@
|
|
|
1
|
-
import classnames from "classnames";
|
|
2
1
|
import { renderToString } from "react-dom/server";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
type StrToEl = (template: string) => HTMLElement;
|
|
4
|
+
type EscapeForTemplate = (allowHTML: boolean, value: unknown) => string;
|
|
5
|
+
type GetClassNames = (className: string | string[]) => string[];
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
</div>
|
|
27
|
-
);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export function callbackOnCreateTemplates(this: { config: { itemSelectText: string } }, strToEl: (template: string) => any) {
|
|
7
|
+
/**
|
|
8
|
+
* Choices.js v11 template callback.
|
|
9
|
+
*
|
|
10
|
+
* Why this file exists:
|
|
11
|
+
* - We need to keep Choices expected DOM/data attributes (`data-choice`, `data-id`,
|
|
12
|
+
* `data-value`, `data-choice-selectable`, etc.) so keyboard/mouse interactions keep working.
|
|
13
|
+
* - We optionally support a React custom option renderer via `customProperties.template`.
|
|
14
|
+
*
|
|
15
|
+
* Notes:
|
|
16
|
+
* - The callback signature changed in Choices v11 and now receives:
|
|
17
|
+
* `strToEl`, `escapeForTemplate`, `getClassNames`.
|
|
18
|
+
* - `this` is the current Choices instance, so we can read `this.config`.
|
|
19
|
+
*/
|
|
20
|
+
export function callbackOnCreateTemplates(
|
|
21
|
+
this: { config: { itemSelectText: string; allowHTML: boolean } },
|
|
22
|
+
strToEl: StrToEl,
|
|
23
|
+
escapeForTemplate: EscapeForTemplate,
|
|
24
|
+
getClassNames: GetClassNames
|
|
25
|
+
) {
|
|
31
26
|
const itemSelectText = this.config.itemSelectText;
|
|
32
27
|
|
|
33
28
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Custom renderer for each dropdown option ("choice" in Choices terminology).
|
|
31
|
+
* Keep all required attributes when editing this template, otherwise
|
|
32
|
+
* selection/highlight/accessibility behavior can break.
|
|
33
|
+
*/
|
|
34
|
+
choice: ({ classNames }: { classNames: Record<string, string | string[]> }, data: any) => {
|
|
35
|
+
const Template = data.customProperties?.template;
|
|
36
|
+
const classes = [
|
|
37
|
+
...getClassNames(classNames.item),
|
|
38
|
+
...getClassNames(classNames.itemChoice),
|
|
39
|
+
...getClassNames(data.disabled ? classNames.itemDisabled : classNames.itemSelectable)
|
|
40
|
+
].join(" ");
|
|
41
|
+
|
|
42
|
+
const label = Template
|
|
43
|
+
? renderToString(<Template {...data} data={{ ...data, ...data?.customProperties }} />)
|
|
44
|
+
: escapeForTemplate(this.config.allowHTML, data.label);
|
|
45
|
+
|
|
46
|
+
// Keep this markup aligned with Choices defaults: attributes below are required by the library.
|
|
47
|
+
return strToEl(
|
|
48
|
+
`<div class="${classes}" aria-label="${escapeForTemplate(true, data.label)}"
|
|
49
|
+
data-select-text="${escapeForTemplate(true, itemSelectText)}"
|
|
50
|
+
data-choice
|
|
51
|
+
${data.disabled ? 'data-choice-disabled aria-disabled="true"' : "data-choice-selectable"}
|
|
52
|
+
data-id="${data.id}"
|
|
53
|
+
data-value="${escapeForTemplate(true, data.value)}"
|
|
54
|
+
${data.groupId > 0 ? 'role="treeitem"' : 'role="option"'}>
|
|
55
|
+
${label}
|
|
56
|
+
</div>`
|
|
57
|
+
);
|
|
36
58
|
}
|
|
37
59
|
};
|
|
38
60
|
}
|
|
@@ -42,11 +42,7 @@ export function mapOptions(options: AllSelectProps["options"]) {
|
|
|
42
42
|
return options;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
export function useOptions<Data = string>({ options
|
|
46
|
-
if (choices) {
|
|
47
|
-
options = choices;
|
|
48
|
-
}
|
|
49
|
-
|
|
45
|
+
export function useOptions<Data = string>({ options }: AllSelectProps<Data>) {
|
|
50
46
|
return useMemo(() => {
|
|
51
47
|
return mapOptions(options);
|
|
52
48
|
}, [options]);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import cx from "classnames";
|
|
1
|
+
import clsx from "clsx";
|
|
3
2
|
import { type ComponentPropsWithoutRef, PropsWithChildren } from "react";
|
|
4
3
|
|
|
5
4
|
import { Icon } from "../../atoms/icon/Icon.js";
|
|
@@ -23,12 +22,9 @@ export function Loader({
|
|
|
23
22
|
return (
|
|
24
23
|
<div
|
|
25
24
|
{...props}
|
|
26
|
-
className={
|
|
27
|
-
"opacity-85 z-20 flex items-center justify-center p-5 absolute top-0 right-0 left-0 bottom-0 bg-white",
|
|
28
|
-
className
|
|
29
|
-
)}
|
|
25
|
+
className={clsx("opacity-85 z-20 flex items-center justify-center p-5 absolute top-0 right-0 left-0 bottom-0 bg-white", className)}
|
|
30
26
|
>
|
|
31
|
-
<Icon data-testid={`icon_${icon}`} className={
|
|
27
|
+
<Icon data-testid={`icon_${icon}`} className={clsx("text-8xl", color)} iconset={iconset} name={icon} spinning={true} />
|
|
32
28
|
</div>
|
|
33
29
|
);
|
|
34
30
|
}
|