@conveyorhq/arrow-ds 1.42.0 → 1.43.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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@conveyorhq/arrow-ds",
3
3
  "author": "Conveyor",
4
4
  "license": "MIT",
5
- "version": "1.42.0",
5
+ "version": "1.43.0",
6
6
  "description": "Arrow Design System",
7
7
  "repository": "https://github.com/conveyor/arrow-ds",
8
8
  "publishConfig": {
@@ -94,8 +94,12 @@ const Modal = (props) => {
94
94
  const { title, secondaryTitle, description, children, isOpen, onClose, autoFocus = false, disableOutsideClick = true, disableEscClose = false, hideCloseButton = false, size = MODAL_SIZE.DEFAULT, center = false, noHeader = false, className, ...rest } = props;
95
95
  const modalElement = react_1.useRef(null);
96
96
  const showHeader = title || secondaryTitle || !hideCloseButton;
97
+ const [esc, setEsc] = react_1.useState(disableEscClose);
98
+ react_1.useEffect(() => {
99
+ setEsc(disableEscClose);
100
+ }, [disableEscClose]);
97
101
  hooks_1.useKeyPress(types_1.KEY_CODE.ESC, () => {
98
- if (!disableEscClose && onClose) {
102
+ if (!esc && onClose) {
99
103
  onClose();
100
104
  }
101
105
  });
@@ -20,7 +20,7 @@ export declare type SelectBaseProps = ({
20
20
  } & SelectAsyncProps);
21
21
  declare const Select: {
22
22
  (props: SelectProps): JSX.Element;
23
- Creatable: (props: SelectCreatableProps) => JSX.Element;
23
+ Creatable: ({ createOptionPosition, ...rest }: SelectCreatableProps) => JSX.Element;
24
24
  Async: (props: SelectAsyncProps) => JSX.Element;
25
25
  };
26
26
  export { Select };
@@ -126,15 +126,15 @@ const SelectBase = ({ variant: variantProp = types_1.STATUS_VARIANT.DEFAULT, id:
126
126
  return (react_1.default.createElement(async_1.default, Object.assign({ className: getClassNames(className, variant), id: id }, rest, hardcodedProps)));
127
127
  }
128
128
  if (rest.type === "creatable") {
129
- return (react_1.default.createElement(creatable_1.default, Object.assign({ className: getClassNames(className, variant), id: id }, rest, hardcodedProps, { createOptionPosition: "first" })));
129
+ return (react_1.default.createElement(creatable_1.default, Object.assign({ className: getClassNames(className, variant), id: id }, rest, hardcodedProps)));
130
130
  }
131
131
  return (react_1.default.createElement(react_select_1.default, Object.assign({ className: getClassNames(className, variant), id: id }, rest, hardcodedProps)));
132
132
  };
133
133
  const SelectAsync = (props) => {
134
134
  return react_1.default.createElement(SelectBase, Object.assign({}, props, { type: "async" }));
135
135
  };
136
- const SelectCreatable = (props) => {
137
- return react_1.default.createElement(SelectBase, Object.assign({}, props, { type: "creatable" }));
136
+ const SelectCreatable = ({ createOptionPosition = "first", ...rest }) => {
137
+ return (react_1.default.createElement(SelectBase, Object.assign({ createOptionPosition: createOptionPosition }, rest, { type: "creatable" })));
138
138
  };
139
139
  const Select = (props) => {
140
140
  return react_1.default.createElement(SelectBase, Object.assign({}, props, { type: "default" }));
@@ -898,3 +898,60 @@ Hide the header to create a custom layout.
898
898
  }}
899
899
  </Story>
900
900
  </Preview>
901
+
902
+ ### Dynamically controlling disableEscClose prop
903
+
904
+ There are times when you might want to use <kbd>escape</kbd> to control a
905
+ component inside of a modal. Previously, you would need to set `disableEscClose`
906
+ to false in order to preserve <kbd>escape</kbd> for the component instead of
907
+ closing the modal.
908
+
909
+ Here’s an example showing a Select component inside of a modal and how you can
910
+ control both the Select and Modal with <kbd>escape</kbd>.
911
+
912
+ To do so, we need to track the open state of the select. Then we can pass that
913
+ state variable to the `disableEscClose` prop.
914
+
915
+ When the select menu is open, the first <kbd>escape</kbd> keypress closes the
916
+ select menu. The second <kbd>escape</kbd> keypress closes the modal.
917
+
918
+ <Preview>
919
+ <Story name="Dynamically controlling disableEscClose prop">
920
+ {() => {
921
+ const { isOpen, onOpen, onClose } = useDisclosure();
922
+ const [isSelectOpen, setIsSelectOpen] = React.useState(false);
923
+ return (
924
+ <Fragment>
925
+ <Button onClick={onOpen}>Show Modal</Button>
926
+ <Modal
927
+ title="Modal component"
928
+ isOpen={isOpen}
929
+ onClose={onClose}
930
+ disableEscClose={isSelectOpen}
931
+ >
932
+ <Modal.Body>
933
+ <Box style={{ height: "400px" }}>
934
+ <Select
935
+ autoFocus
936
+ placeholder="Favorite ice cream?"
937
+ options={[
938
+ { value: "chocolate", label: "Chocolate" },
939
+ { value: "strawberry", label: "Strawberry" },
940
+ { value: "vanilla", label: "Vanilla" },
941
+ ]}
942
+ onMenuOpen={() => {
943
+ setIsSelectOpen(true);
944
+ }}
945
+ onMenuClose={() => {
946
+ setIsSelectOpen(false);
947
+ }}
948
+ menuInPortal
949
+ />
950
+ </Box>
951
+ </Modal.Body>
952
+ </Modal>
953
+ </Fragment>
954
+ );
955
+ }}
956
+ </Story>
957
+ </Preview>
@@ -1,4 +1,4 @@
1
- import React, { useRef } from "react";
1
+ import React, { useEffect, useRef, useState } from "react";
2
2
  import classNames from "classnames";
3
3
  import FocusLock from "react-focus-lock";
4
4
  import { RemoveScroll } from "react-remove-scroll";
@@ -266,8 +266,14 @@ export const Modal = (props: ModalProps) => {
266
266
  const modalElement = useRef<HTMLDivElement>(null);
267
267
  const showHeader = title || secondaryTitle || !hideCloseButton;
268
268
 
269
+ const [esc, setEsc] = useState(disableEscClose);
270
+
271
+ useEffect(() => {
272
+ setEsc(disableEscClose);
273
+ }, [disableEscClose]);
274
+
269
275
  useKeyPress(KEY_CODE.ESC, () => {
270
- if (!disableEscClose && onClose) {
276
+ if (!esc && onClose) {
271
277
  onClose();
272
278
  }
273
279
  });
@@ -258,7 +258,6 @@ const SelectBase = ({
258
258
  id={id}
259
259
  {...rest}
260
260
  {...hardcodedProps}
261
- createOptionPosition="first"
262
261
  />
263
262
  );
264
263
  }
@@ -277,8 +276,17 @@ const SelectAsync = (props: SelectAsyncProps) => {
277
276
  return <SelectBase {...props} type="async" />;
278
277
  };
279
278
 
280
- const SelectCreatable = (props: SelectCreatableProps) => {
281
- return <SelectBase {...props} type="creatable" />;
279
+ const SelectCreatable = ({
280
+ createOptionPosition = "first",
281
+ ...rest
282
+ }: SelectCreatableProps) => {
283
+ return (
284
+ <SelectBase
285
+ createOptionPosition={createOptionPosition}
286
+ {...rest}
287
+ type="creatable"
288
+ />
289
+ );
282
290
  };
283
291
 
284
292
  const Select = (props: SelectProps) => {