@spscommerce/ds-react 6.29.1 → 6.30.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.
- package/lib/index.cjs.js +71 -30
- package/lib/index.es.js +95 -1
- package/lib/modal/index.d.ts +1 -0
- package/lib/modal/useModals.d.ts +15 -0
- package/package.json +9 -9
package/lib/index.es.js
CHANGED
|
@@ -29893,6 +29893,56 @@ const SpsModalExamples = {
|
|
|
29893
29893
|
`
|
|
29894
29894
|
}
|
|
29895
29895
|
}
|
|
29896
|
+
},
|
|
29897
|
+
hook: {
|
|
29898
|
+
label: "Hooks",
|
|
29899
|
+
description: () => /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("p", null, "This hook allows to manage modals like a stack, so you can call pushModal/popModal from any place to show/hide modal."), /* @__PURE__ */ React.createElement("p", null, "It also helps with chain of modals, when you need to show several modals one by one and use results from them"), "If you use the useModals hook, you should ideally invoke it and place", " ", /* @__PURE__ */ React.createElement("code", null, "modals"), " at the top level of your app, and pass down", " ", /* @__PURE__ */ React.createElement("code", null, "pushModal"), " and ", /* @__PURE__ */ React.createElement("code", null, "popModal"), "."),
|
|
29900
|
+
examples: {
|
|
29901
|
+
hook: {
|
|
29902
|
+
react: code`
|
|
29903
|
+
function SpsModalsHook() {
|
|
29904
|
+
const [modals, pushModal, popModal] = useModals();
|
|
29905
|
+
|
|
29906
|
+
async function openModalAction() {
|
|
29907
|
+
const modalResult = await pushModal(<ModalComponent />);
|
|
29908
|
+
console.log(modalResult);
|
|
29909
|
+
}
|
|
29910
|
+
|
|
29911
|
+
function cancelAction() {
|
|
29912
|
+
popModal({
|
|
29913
|
+
action: ModalAction.Cancel
|
|
29914
|
+
});
|
|
29915
|
+
}
|
|
29916
|
+
|
|
29917
|
+
function primaryAction() {
|
|
29918
|
+
popModal({
|
|
29919
|
+
action: ModalAction.Ok,
|
|
29920
|
+
data: 'any data'
|
|
29921
|
+
});
|
|
29922
|
+
}
|
|
29923
|
+
|
|
29924
|
+
const ModalComponent = () => (
|
|
29925
|
+
<SpsModal size={ModalSize.MEDIUM}>
|
|
29926
|
+
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
|
|
29927
|
+
<SpsModalFooter>
|
|
29928
|
+
<SpsButton onClick={cancelAction}>Cancel Action</SpsButton>
|
|
29929
|
+
<SpsButton kind={ButtonKind.KEY} onClick={primaryAction}>
|
|
29930
|
+
Primary Action
|
|
29931
|
+
</SpsButton>
|
|
29932
|
+
</SpsModalFooter>
|
|
29933
|
+
</SpsModal>
|
|
29934
|
+
);
|
|
29935
|
+
|
|
29936
|
+
return (
|
|
29937
|
+
<>
|
|
29938
|
+
<SpsButton onClick={openModalAction}>Open a modal</SpsButton>
|
|
29939
|
+
{modals}
|
|
29940
|
+
</>
|
|
29941
|
+
);
|
|
29942
|
+
}
|
|
29943
|
+
`
|
|
29944
|
+
}
|
|
29945
|
+
}
|
|
29896
29946
|
}
|
|
29897
29947
|
};
|
|
29898
29948
|
const propsDoc$I = {
|
|
@@ -39230,6 +39280,50 @@ const SpsKeyValueTagExamples = {
|
|
|
39230
39280
|
}
|
|
39231
39281
|
}
|
|
39232
39282
|
};
|
|
39283
|
+
var ModalAction;
|
|
39284
|
+
(function(ModalAction2) {
|
|
39285
|
+
ModalAction2["Ok"] = "Ok";
|
|
39286
|
+
ModalAction2["Cancel"] = "Cancel";
|
|
39287
|
+
})(ModalAction || (ModalAction = {}));
|
|
39288
|
+
const useModals = () => {
|
|
39289
|
+
const [modals, setModals] = useState([]);
|
|
39290
|
+
const pushModal = (component) => {
|
|
39291
|
+
const modalsClone = [...modals];
|
|
39292
|
+
const componentClone = __spreadValues({}, component);
|
|
39293
|
+
componentClone.key = nanoid();
|
|
39294
|
+
const promise = new Promise((resolve) => {
|
|
39295
|
+
modalsClone.push({
|
|
39296
|
+
component: componentClone,
|
|
39297
|
+
resolve
|
|
39298
|
+
});
|
|
39299
|
+
setModals(modalsClone);
|
|
39300
|
+
});
|
|
39301
|
+
return promise;
|
|
39302
|
+
};
|
|
39303
|
+
const popModal = (result) => {
|
|
39304
|
+
const modalsClone = [...modals];
|
|
39305
|
+
const modal = modalsClone.pop();
|
|
39306
|
+
modal == null ? void 0 : modal.resolve(result);
|
|
39307
|
+
setModals(modalsClone);
|
|
39308
|
+
};
|
|
39309
|
+
const [schedulePopEnabled, setSchedulePopEnabled] = useState(false);
|
|
39310
|
+
const [schedulePopResult, setSchedulePopResult] = useState(null);
|
|
39311
|
+
useEffect(() => {
|
|
39312
|
+
if (schedulePopEnabled) {
|
|
39313
|
+
popModal(schedulePopResult);
|
|
39314
|
+
setSchedulePopEnabled(false);
|
|
39315
|
+
}
|
|
39316
|
+
}, [schedulePopEnabled]);
|
|
39317
|
+
const scheduledPopModal = (result) => {
|
|
39318
|
+
setSchedulePopEnabled(true);
|
|
39319
|
+
setSchedulePopResult(result);
|
|
39320
|
+
};
|
|
39321
|
+
return [
|
|
39322
|
+
modals.map((m2) => m2.component),
|
|
39323
|
+
pushModal,
|
|
39324
|
+
scheduledPopModal
|
|
39325
|
+
];
|
|
39326
|
+
};
|
|
39233
39327
|
function useSpsAction(descriptor, fn) {
|
|
39234
39328
|
const metadata = __spreadValues(__spreadValues({}, SPS_ACTION_DEFAULTS), descriptor);
|
|
39235
39329
|
const [state, patchState] = usePatchReducer(metadata);
|
|
@@ -39325,4 +39419,4 @@ Object.assign(SpsVr, {
|
|
|
39325
39419
|
propTypes,
|
|
39326
39420
|
displayName: "SpsDescriptionListTerm / SpsDt"
|
|
39327
39421
|
});
|
|
39328
|
-
export { AsTypingErrorKeys, ContentOrderExample, DEFAULT_PRESETS, DragDropContext, PublicDraggable as Draggable, ConnectedDroppable as Droppable, FauxChangeEvent, I18nContext, MANIFEST, OnBlurErrorKeys, OnSubmitErrorKeys, PortalContext, PreventativeErrorKeys, Provide, SimpleDateUtils, SpsAddRemoveFormRowExamples, SpsAdvancedSearch, SpsAdvancedSearchExamples, SpsApp, SpsAutocomplete, SpsAutocompleteExamples, SpsButton, SpsButtonExamples, SpsButtonGroup, SpsCard, SpsCardExamples, SpsCardTabbedPane, SpsCardV2, SpsCardV2Footer, SpsCardV2Header, SpsCardV2Title, SpsCheckbox, SpsCheckboxDropdown, SpsCheckboxExamples, SpsClickableTag, SpsClickableTagExamples, SpsColumnChooser, SpsColumnChooserColumn, SpsColumnChooserExamples, SpsConditionalField, SpsConditionalFieldExamples, SpsContentRow, SpsContentRowCol, SpsContentRowExamples, SpsContentRowExpansion, SpsContextBar, SpsCurrencyInput, SpsCurrencyInputExamples, SpsDateRangePicker, SpsDateRangePickerExamples, SpsDateTime, SpsDatepicker, SpsDatepickerExamples, SpsDatetimeExamples, SpsDd, SpsDescriptionList, SpsDescriptionListDefinition, SpsDescriptionListExamples, SpsDescriptionListTerm, SpsDl, SpsDropdown, SpsDropdownExamples, SpsDt, SpsFeedbackBlock, SpsFeedbackBlockExamples, SpsFieldset, SpsFieldsetExamples, SpsFilterPanel, SpsFilterPanelCap, SpsFilterPanelExamples, SpsFilterPanelFilterBox, SpsFilterPanelSection, SpsFilterTile, SpsFilterTileList, SpsFilterTileListExamples, SpsFocusedTask, SpsFocusedTaskActions, SpsFocusedTaskExamples, SpsForm, SpsFormArrayMeta, SpsFormComponentWrapper, SpsFormExamples, SpsFormFieldMeta, SpsFormGroupMeta, SpsFormMetaBase, SpsFormSetMeta, SpsGrowler, SpsGrowlerExamples, SpsI, SpsIconButtonPanel, SpsIncrementor, SpsIncrementorExamples, SpsInputGroup, SpsInsightTile, SpsInsights, SpsKeyValueList, SpsKeyValueListExamples, SpsKeyValueListItem, SpsKeyValueTag, SpsKeyValueTagExamples, SpsLabel, SpsLabelExamples, SpsListActionBar, SpsListActionBarExamples, SpsListToolbar, SpsListToolbarExamples, SpsListToolbarSearch, SpsListToolbarSearchInfo, SpsListToolbarSortBy, SpsMicroBlock, SpsMicroBlockExamples, SpsMicroZeroState, SpsModal, SpsModalExamples, SpsModalFooter, SpsMultiSelect, SpsMultiSelectExamples, SpsMultiValueTextInput, SpsMultiValueTextInputExamples, SpsPageSelector, SpsPageSubtitle, SpsPageTitle, SpsPageTitleExamples, SpsPagination, SpsPaginationExamples, SpsProductBar, SpsProductBarExamples, SpsProductBarTab, SpsProgressBar, SpsProgressBarExamples, SpsProgressRing, SpsRadioButton, SpsRadioButtonExamples, SpsScrollableContainer, SpsScrollableContainerExamples, SpsSearchResultsBar, SpsSearchResultsBarExamples, SpsSearchResultsBarV2, SpsSelect, SpsSelectExamples, SpsSideNav, SpsSideNavExamples, SpsSlackLink, SpsSlackLinkExamples, SpsSlideInPanel, SpsSlideInPanelExamples, SpsSortingHeader, SpsSortingHeaderCell, SpsSortingHeaderExamples, SpsSpinner, SpsSpinnerExamples, SpsSplitButton, SpsSplitButtonExamples, SpsSteppedProgressBar, SpsSteppedProgressBarExamples, SpsSummaryListColumn, SpsSummaryListExamples, SpsSummaryListExpansion, SpsSummaryListRow, SpsTab, SpsTabPanel, SpsTable, SpsTableBody, SpsTableCell, SpsTableExamples, SpsTableHead, SpsTableHeader, SpsTableRow, SpsTabsV2, SpsTag, SpsTagExamples, SpsTaskQueue, SpsTaskQueueExamples, SpsTbody, SpsTd, SpsTextInput, SpsTextInputExamples, SpsTextarea, SpsTextareaExamples, SpsTh, SpsThead, SpsTile, SpsTileList, SpsTileListExamples, SpsToggle, SpsToggleExamples, SpsTooltip, SpsTooltipExamples, SpsTooltipTitle, SpsTr, SpsValidators, SpsVerticalRule, SpsVr, SpsWf, SpsWfDoc, SpsWfDs, SpsWfStep, SpsWizardExamples, SpsWizardSidebar, SpsWizardSubstep, SpsWorkflow, SpsWorkflowDocument, SpsWorkflowDocumentStatus, SpsWorkflowExamples, SpsWorkflowStep, SpsZeroState, SpsZeroStateExamples, TooltipVisibility, ValidationMode, addOnChangeErrorKey, addOnSubmitErrorKey, bindProps, contentOf, date, dateConstraint, dateRange, findParentBranches, flipPosition, formArray, formControl, formGroup, getMember, getPosition, resetServerContext, selectChildren, toggleTooltipState, useCheckDeprecatedProps, useColumnResizer, useCustomValidator, useDidUpdateEffect, useDocumentEventListener, useElementId, useForm, useGrowlers, useInputPopup, useKeyboardSensor, useMouseSensor, usePatchReducer, usePortal, useServerSideValidation, useSpsAction, useSpsForm, useTouchSensor, validate };
|
|
39422
|
+
export { AsTypingErrorKeys, ContentOrderExample, DEFAULT_PRESETS, DragDropContext, PublicDraggable as Draggable, ConnectedDroppable as Droppable, FauxChangeEvent, I18nContext, MANIFEST, ModalAction, OnBlurErrorKeys, OnSubmitErrorKeys, PortalContext, PreventativeErrorKeys, Provide, SimpleDateUtils, SpsAddRemoveFormRowExamples, SpsAdvancedSearch, SpsAdvancedSearchExamples, SpsApp, SpsAutocomplete, SpsAutocompleteExamples, SpsButton, SpsButtonExamples, SpsButtonGroup, SpsCard, SpsCardExamples, SpsCardTabbedPane, SpsCardV2, SpsCardV2Footer, SpsCardV2Header, SpsCardV2Title, SpsCheckbox, SpsCheckboxDropdown, SpsCheckboxExamples, SpsClickableTag, SpsClickableTagExamples, SpsColumnChooser, SpsColumnChooserColumn, SpsColumnChooserExamples, SpsConditionalField, SpsConditionalFieldExamples, SpsContentRow, SpsContentRowCol, SpsContentRowExamples, SpsContentRowExpansion, SpsContextBar, SpsCurrencyInput, SpsCurrencyInputExamples, SpsDateRangePicker, SpsDateRangePickerExamples, SpsDateTime, SpsDatepicker, SpsDatepickerExamples, SpsDatetimeExamples, SpsDd, SpsDescriptionList, SpsDescriptionListDefinition, SpsDescriptionListExamples, SpsDescriptionListTerm, SpsDl, SpsDropdown, SpsDropdownExamples, SpsDt, SpsFeedbackBlock, SpsFeedbackBlockExamples, SpsFieldset, SpsFieldsetExamples, SpsFilterPanel, SpsFilterPanelCap, SpsFilterPanelExamples, SpsFilterPanelFilterBox, SpsFilterPanelSection, SpsFilterTile, SpsFilterTileList, SpsFilterTileListExamples, SpsFocusedTask, SpsFocusedTaskActions, SpsFocusedTaskExamples, SpsForm, SpsFormArrayMeta, SpsFormComponentWrapper, SpsFormExamples, SpsFormFieldMeta, SpsFormGroupMeta, SpsFormMetaBase, SpsFormSetMeta, SpsGrowler, SpsGrowlerExamples, SpsI, SpsIconButtonPanel, SpsIncrementor, SpsIncrementorExamples, SpsInputGroup, SpsInsightTile, SpsInsights, SpsKeyValueList, SpsKeyValueListExamples, SpsKeyValueListItem, SpsKeyValueTag, SpsKeyValueTagExamples, SpsLabel, SpsLabelExamples, SpsListActionBar, SpsListActionBarExamples, SpsListToolbar, SpsListToolbarExamples, SpsListToolbarSearch, SpsListToolbarSearchInfo, SpsListToolbarSortBy, SpsMicroBlock, SpsMicroBlockExamples, SpsMicroZeroState, SpsModal, SpsModalExamples, SpsModalFooter, SpsMultiSelect, SpsMultiSelectExamples, SpsMultiValueTextInput, SpsMultiValueTextInputExamples, SpsPageSelector, SpsPageSubtitle, SpsPageTitle, SpsPageTitleExamples, SpsPagination, SpsPaginationExamples, SpsProductBar, SpsProductBarExamples, SpsProductBarTab, SpsProgressBar, SpsProgressBarExamples, SpsProgressRing, SpsRadioButton, SpsRadioButtonExamples, SpsScrollableContainer, SpsScrollableContainerExamples, SpsSearchResultsBar, SpsSearchResultsBarExamples, SpsSearchResultsBarV2, SpsSelect, SpsSelectExamples, SpsSideNav, SpsSideNavExamples, SpsSlackLink, SpsSlackLinkExamples, SpsSlideInPanel, SpsSlideInPanelExamples, SpsSortingHeader, SpsSortingHeaderCell, SpsSortingHeaderExamples, SpsSpinner, SpsSpinnerExamples, SpsSplitButton, SpsSplitButtonExamples, SpsSteppedProgressBar, SpsSteppedProgressBarExamples, SpsSummaryListColumn, SpsSummaryListExamples, SpsSummaryListExpansion, SpsSummaryListRow, SpsTab, SpsTabPanel, SpsTable, SpsTableBody, SpsTableCell, SpsTableExamples, SpsTableHead, SpsTableHeader, SpsTableRow, SpsTabsV2, SpsTag, SpsTagExamples, SpsTaskQueue, SpsTaskQueueExamples, SpsTbody, SpsTd, SpsTextInput, SpsTextInputExamples, SpsTextarea, SpsTextareaExamples, SpsTh, SpsThead, SpsTile, SpsTileList, SpsTileListExamples, SpsToggle, SpsToggleExamples, SpsTooltip, SpsTooltipExamples, SpsTooltipTitle, SpsTr, SpsValidators, SpsVerticalRule, SpsVr, SpsWf, SpsWfDoc, SpsWfDs, SpsWfStep, SpsWizardExamples, SpsWizardSidebar, SpsWizardSubstep, SpsWorkflow, SpsWorkflowDocument, SpsWorkflowDocumentStatus, SpsWorkflowExamples, SpsWorkflowStep, SpsZeroState, SpsZeroStateExamples, TooltipVisibility, ValidationMode, addOnChangeErrorKey, addOnSubmitErrorKey, bindProps, contentOf, date, dateConstraint, dateRange, findParentBranches, flipPosition, formArray, formControl, formGroup, getMember, getPosition, resetServerContext, selectChildren, toggleTooltipState, useCheckDeprecatedProps, useColumnResizer, useCustomValidator, useDidUpdateEffect, useDocumentEventListener, useElementId, useForm, useGrowlers, useInputPopup, useKeyboardSensor, useModals, useMouseSensor, usePatchReducer, usePortal, useServerSideValidation, useSpsAction, useSpsForm, useTouchSensor, validate };
|
package/lib/modal/index.d.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
declare type UseModalsType = [
|
|
2
|
+
modals: JSX.Element[],
|
|
3
|
+
pushModal: <T>(component: JSX.Element) => Promise<ModalResult<T>>,
|
|
4
|
+
popModal: <T>(result?: ModalResult<T>) => void
|
|
5
|
+
];
|
|
6
|
+
export declare enum ModalAction {
|
|
7
|
+
Ok = "Ok",
|
|
8
|
+
Cancel = "Cancel"
|
|
9
|
+
}
|
|
10
|
+
export interface ModalResult<T> {
|
|
11
|
+
action: ModalAction;
|
|
12
|
+
data?: T;
|
|
13
|
+
}
|
|
14
|
+
export declare const useModals: () => UseModalsType;
|
|
15
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spscommerce/ds-react",
|
|
3
3
|
"description": "SPS Design System React components",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.30.0",
|
|
5
5
|
"author": "SPS Commerce",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"repository": "https://github.com/spscommerce/design-system/tree/main/packages/@spscommerce/ds-react",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@react-stately/collections": "^3.3.3",
|
|
31
|
-
"@spscommerce/ds-colors": "6.
|
|
32
|
-
"@spscommerce/ds-illustrations": "6.
|
|
33
|
-
"@spscommerce/ds-shared": "6.
|
|
34
|
-
"@spscommerce/positioning": "6.
|
|
31
|
+
"@spscommerce/ds-colors": "6.30.0",
|
|
32
|
+
"@spscommerce/ds-illustrations": "6.30.0",
|
|
33
|
+
"@spscommerce/ds-shared": "6.30.0",
|
|
34
|
+
"@spscommerce/positioning": "6.30.0",
|
|
35
35
|
"@spscommerce/utils": "^6.11.3",
|
|
36
36
|
"moment": "^2.25.3",
|
|
37
37
|
"moment-timezone": "^0.5.28",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@react-stately/collections": "^3.3.3",
|
|
43
|
-
"@spscommerce/ds-colors": "6.
|
|
44
|
-
"@spscommerce/ds-illustrations": "6.
|
|
45
|
-
"@spscommerce/ds-shared": "6.
|
|
46
|
-
"@spscommerce/positioning": "6.
|
|
43
|
+
"@spscommerce/ds-colors": "6.30.0",
|
|
44
|
+
"@spscommerce/ds-illustrations": "6.30.0",
|
|
45
|
+
"@spscommerce/ds-shared": "6.30.0",
|
|
46
|
+
"@spscommerce/positioning": "6.30.0",
|
|
47
47
|
"@spscommerce/utils": "^6.11.3",
|
|
48
48
|
"@testing-library/react": "^9.3.2",
|
|
49
49
|
"@types/prop-types": "^15.7.1",
|