@dtdot/lego 0.17.1 → 0.17.5

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.
@@ -72,7 +72,7 @@ const ImageUpload = ({ name, value, onChange, onSearch }) => {
72
72
  onChange(url);
73
73
  }
74
74
  if (contextOnChange) {
75
- contextOnChange({ target: { value: url } });
75
+ contextOnChange(url);
76
76
  }
77
77
  }
78
78
  };
@@ -28,6 +28,7 @@ export const InputStyles = css `
28
28
  width: 100%;
29
29
  height: ${INPUT_HEIGHT}px;
30
30
  padding: 0 12px;
31
+ scroll-margin-bottom: 100px;
31
32
 
32
33
  font-family: ${(props) => props.theme.fonts.default.family};
33
34
  font-size: ${(props) => props.theme.fonts.default.size};
@@ -46,7 +46,7 @@ const LiveList = ({ value: inputValue, name, onChange: propsOnChange }) => {
46
46
  }
47
47
  }, [propsOnChange, contextOnChange]);
48
48
  useEffect(() => {
49
- if (!(value === null || value === void 0 ? void 0 : value.length)) {
49
+ if (!value?.length) {
50
50
  wrappedOnChange([{ id: uuidv4(), value: '' }]);
51
51
  }
52
52
  }, [value, wrappedOnChange]);
@@ -65,10 +65,13 @@ const LiveList = ({ value: inputValue, name, onChange: propsOnChange }) => {
65
65
  return;
66
66
  }
67
67
  const focusedValue = value.find((val) => val.id === focusedId);
68
- if (focusedValue === null || focusedValue === void 0 ? void 0 : focusedValue.value) {
68
+ if (focusedValue?.value) {
69
69
  return;
70
70
  }
71
71
  const focusedIndex = value.findIndex((val) => val.id === focusedId);
72
+ if (focusedIndex === 0) {
73
+ return;
74
+ }
72
75
  const prevId = focusedIndex > 0 ? value[focusedIndex - 1].id : undefined;
73
76
  wrappedOnChange(value.filter((val) => val.id !== focusedId));
74
77
  if (prevId) {
@@ -94,7 +97,7 @@ const LiveList = ({ value: inputValue, name, onChange: propsOnChange }) => {
94
97
  const newItem = { id: uuidv4(), value: '' };
95
98
  wrappedOnChange([...value, newItem]);
96
99
  };
97
- if (!(value === null || value === void 0 ? void 0 : value.length)) {
100
+ if (!value?.length) {
98
101
  return null;
99
102
  }
100
103
  return (React.createElement("div", null,
@@ -3,5 +3,6 @@ import { Meta } from '@storybook/react/types-6-0';
3
3
  export declare const Standard: () => JSX.Element;
4
4
  export declare const InForm: () => JSX.Element;
5
5
  export declare const WithValidation: () => JSX.Element;
6
+ export declare const EmptyList: () => JSX.Element;
6
7
  declare const _default: Meta<import("@storybook/react/types-6-0").Args>;
7
8
  export default _default;
@@ -44,6 +44,13 @@ export const WithValidation = () => {
44
44
  React.createElement(Button, { onClick: clear }, "Clear"),
45
45
  React.createElement(Button, { onClick: validate }, "Set Errors"))));
46
46
  };
47
+ export const EmptyList = () => {
48
+ const [value, setValue] = useState({});
49
+ return (React.createElement(React.Fragment, null,
50
+ React.createElement(Heading.FormHeading, null, "Ingredients"),
51
+ React.createElement(Spacer, { size: '1x' }),
52
+ React.createElement(LiveList, { value: value, onChange: setValue })));
53
+ };
47
54
  export default {
48
55
  title: 'Components/LiveList',
49
56
  component: LiveList,
@@ -60,7 +60,7 @@ const LiveListRow = ({ id, value, error, onChange, onRemove }) => {
60
60
  onBlur(id);
61
61
  };
62
62
  return (React.createElement(InputContainer, { whileHover: 'hover' },
63
- React.createElement(Input, { onFocus: handleFocus, onBlur: handleBlur, ref: inputRef, value: value, error: error, onChange: handleChange }),
63
+ React.createElement(Input, { onFocus: handleFocus, onBlur: handleBlur, ref: inputRef, value: value || '', error: error, onChange: handleChange }),
64
64
  React.createElement(RemoveContainer, { animate: isFocused ? 'focus' : undefined, style: { opacity: 0 }, variants: removeVariants, transition: { type: 'spring', duration: 0.3 } },
65
65
  React.createElement(RemoveInner, { onClick: onRemove },
66
66
  React.createElement(FontAwesomeIcon, { icon: faTimes })))));
@@ -30,7 +30,7 @@ const Identicon = ({ value }) => {
30
30
  const hexColours = [colours.red, colours.green, colours.blue, colours.yellow];
31
31
  const convertedColours = hexColours.map((hex) => {
32
32
  const rgb = hexToRgb(hex);
33
- return [rgb === null || rgb === void 0 ? void 0 : rgb.r, rgb === null || rgb === void 0 ? void 0 : rgb.g, rgb === null || rgb === void 0 ? void 0 : rgb.b, 255];
33
+ return [rgb?.r, rgb?.g, rgb?.b, 255];
34
34
  });
35
35
  const hash = SparkMD5.hash(value || 'unknown user');
36
36
  const colourIndex = Math.floor(Math.random() * 4);
@@ -45,7 +45,7 @@ const QrCode = ({ value }) => {
45
45
  if (hintTimeoutRef.current) {
46
46
  window.clearTimeout(hintTimeoutRef.current);
47
47
  }
48
- if (inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) {
48
+ if (inputRef?.current) {
49
49
  inputRef.current.select();
50
50
  document.execCommand('copy');
51
51
  }
@@ -4,14 +4,13 @@ const useKeypress = (key, handler) => {
4
4
  useEffect(() => {
5
5
  eventListenerRef.current = (event) => {
6
6
  if (key === event.key) {
7
- handler === null || handler === void 0 ? void 0 : handler();
7
+ handler?.();
8
8
  }
9
9
  };
10
10
  }, [key, handler]);
11
11
  useEffect(() => {
12
12
  const eventListener = (event) => {
13
- var _a;
14
- (_a = eventListenerRef.current) === null || _a === void 0 ? void 0 : _a.call(eventListenerRef, event);
13
+ eventListenerRef.current?.(event);
15
14
  };
16
15
  window.addEventListener('keydown', eventListener);
17
16
  return () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dtdot/lego",
3
- "version": "0.17.1",
3
+ "version": "0.17.5",
4
4
  "description": "Some reusable components for building my applications",
5
5
  "main": "build/index.js",
6
6
  "scripts": {