@ainias42/react-bootstrap-mobile 0.1.15 → 0.1.17

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.
Files changed (81) hide show
  1. package/bin/updateCopies.js +9 -5
  2. package/bootstrapReactMobile.ts +13 -2
  3. package/dist/bootstrapReactMobile.d.ts +13 -2
  4. package/dist/bootstrapReactMobile.js +992 -395
  5. package/dist/bootstrapReactMobile.js.map +1 -1
  6. package/dist/src/Components/Clickable/Clickable.d.ts +7 -3
  7. package/dist/src/Components/Dialog/DialogBackground.d.ts +4 -5
  8. package/dist/src/Components/Dialog/DialogContainer.d.ts +7 -3
  9. package/dist/src/Components/DragAndDrop/DragItem.d.ts +1 -1
  10. package/dist/src/Components/Flavor.d.ts +4 -0
  11. package/dist/src/Components/FormElements/Button/Button.d.ts +8 -4
  12. package/dist/src/Components/FormElements/Button/ButtonType.d.ts +4 -0
  13. package/dist/src/Components/FormElements/Input/FileInput/FileInput.d.ts +12 -0
  14. package/dist/src/Components/FormElements/Input/FileInput/FileType.d.ts +7 -0
  15. package/dist/src/Components/FormElements/Input/FileInput/MultipleFileInput.d.ts +17 -0
  16. package/dist/src/Components/FormElements/Select/Select.d.ts +2 -1
  17. package/dist/src/Components/FormElements/Switch/Switch.d.ts +4 -4
  18. package/dist/src/Components/Hooks/useMousePosition.d.ts +5 -0
  19. package/dist/src/Components/Hooks/useWindowDimensions.d.ts +4 -0
  20. package/dist/src/Components/Icon/Icon.d.ts +2 -3
  21. package/dist/src/Components/Layout/Grid/Grid.d.ts +2 -1
  22. package/dist/src/Components/Layout/Grid/GridItem.d.ts +4 -1
  23. package/dist/src/Components/Menu/HoverMenu.d.ts +9 -0
  24. package/dist/src/Components/Menu/Menu.d.ts +16 -7
  25. package/dist/src/Components/Menu/MenuCloseContext.d.ts +3 -0
  26. package/dist/src/Components/Menu/MenuDivider.d.ts +2 -0
  27. package/dist/src/Components/Menu/MenuItem.d.ts +23 -0
  28. package/dist/src/Components/Menu/Submenu.d.ts +12 -0
  29. package/dist/src/Components/Menu/useMenu.d.ts +1 -1
  30. package/dist/src/Components/RbmComponentProps.d.ts +4 -0
  31. package/dist/src/Components/Text/Text.d.ts +1 -0
  32. package/dist/src/ListRow/ListRow.d.ts +1 -0
  33. package/package.json +8 -7
  34. package/src/Components/Clickable/Clickable.tsx +135 -19
  35. package/src/Components/Dialog/DialogBackground.tsx +5 -8
  36. package/src/Components/Dialog/DialogContainer.tsx +12 -8
  37. package/src/Components/Dialog/DialogContext.ts +1 -2
  38. package/src/Components/Dialog/dialogBackground.scss +5 -1
  39. package/src/Components/DragAndDrop/DragItem.tsx +7 -7
  40. package/src/Components/DragAndDrop/DropArea.tsx +2 -1
  41. package/src/Components/Flavor.ts +4 -0
  42. package/src/Components/FormElements/Button/Button.tsx +31 -13
  43. package/src/Components/FormElements/Button/ButtonType.ts +4 -0
  44. package/src/Components/FormElements/Button/button.scss +22 -5
  45. package/src/Components/FormElements/Input/FileInput/FileInput.tsx +55 -0
  46. package/src/Components/FormElements/Input/FileInput/FileType.ts +1 -0
  47. package/src/Components/FormElements/Input/FileInput/MultipleFileInput.tsx +281 -0
  48. package/src/Components/FormElements/{ImageInput/imageInput.scss → Input/FileInput/fileInput.scss} +37 -7
  49. package/src/Components/FormElements/Input/input.scss +1 -1
  50. package/src/Components/FormElements/SearchSelectInput/SearchSelectInput.tsx +2 -2
  51. package/src/Components/FormElements/SearchSelectInput/seachSelectInput.scss +1 -1
  52. package/src/Components/FormElements/Select/Select.tsx +3 -2
  53. package/src/Components/FormElements/Select/select.scss +5 -0
  54. package/src/Components/FormElements/Switch/Switch.tsx +9 -8
  55. package/src/Components/FormElements/Switch/switch.scss +1 -0
  56. package/src/Components/Hooks/useMousePosition.ts +13 -0
  57. package/src/Components/Hooks/useWindowDimensions.ts +17 -0
  58. package/src/Components/Icon/Icon.tsx +18 -14
  59. package/src/Components/Icon/icon.scss +9 -0
  60. package/src/Components/Layout/Grid/Grid.tsx +3 -2
  61. package/src/Components/Layout/Grid/GridItem.tsx +16 -1
  62. package/src/Components/Layout/Grid/grid.scss +113 -36
  63. package/src/Components/Menu/HoverMenu.tsx +82 -0
  64. package/src/Components/Menu/Menu.tsx +101 -47
  65. package/src/Components/Menu/MenuCloseContext.ts +10 -0
  66. package/src/Components/Menu/MenuDivider.tsx +22 -0
  67. package/src/Components/Menu/MenuItem.tsx +95 -0
  68. package/src/Components/Menu/Submenu.tsx +101 -0
  69. package/src/Components/Menu/menu.scss +99 -10
  70. package/src/Components/Menu/useMenu.ts +1 -1
  71. package/src/Components/RbmComponentProps.ts +6 -0
  72. package/src/Components/Text/Text.tsx +1 -0
  73. package/src/Components/Text/text.scss +13 -5
  74. package/src/ListRow/ListRow.tsx +20 -0
  75. package/src/WrongChildError.ts +0 -2
  76. package/src/scss/_colors.scss +1 -1
  77. package/src/scss/_flavorMixin.scss +10 -0
  78. package/dist/src/Components/FormElements/ImageInput/ImageInput.d.ts +0 -18
  79. package/dist/src/Components/FormElements/ImageInput/MultipleFileInput.d.ts +0 -21
  80. package/src/Components/FormElements/ImageInput/ImageInput.tsx +0 -98
  81. package/src/Components/FormElements/ImageInput/MultipleFileInput.tsx +0 -240
@@ -0,0 +1,281 @@
1
+ import * as React from 'react';
2
+ import {RbmComponentProps} from '../../../RbmComponentProps';
3
+ import {Override} from '../../../../TypeHelpers';
4
+ import {ChangeEventHandler, DragEvent, InputHTMLAttributes, useCallback, useRef} from 'react';
5
+ import {Listener, useListenerWithExtractedProps} from '../../../Hooks/useListener';
6
+
7
+ import styles from './fileInput.scss';
8
+ import {withMemo} from '../../../../helper/withMemo';
9
+ import classNames from 'classnames';
10
+ import {Block} from '../../../Layout/Block';
11
+ import {Text} from '../../../Text/Text';
12
+ import {Flex} from '../../../Layout/Flex';
13
+ import {Grow} from '../../../Layout/Grow';
14
+ import {Icon} from '../../../Icon/Icon';
15
+ import {faFile, faPlus, faTimesCircle} from '@fortawesome/free-solid-svg-icons';
16
+ import {Image} from '../../../Image/Image';
17
+ import {Clickable} from '../../../Clickable/Clickable';
18
+ import {Inline} from '../../../Layout/Inline';
19
+ import {FileType} from "./FileType";
20
+
21
+
22
+ export type MultipleFileInputProps<OnChangeFilesData> = RbmComponentProps<
23
+ Override<
24
+ Omit<InputHTMLAttributes<HTMLInputElement>, 'defaultValue' | 'onChange' | 'value'>,
25
+ {
26
+ value: FileType[];
27
+ label?: string;
28
+ mimeTypes?: string[];
29
+ maxFiles?: number;
30
+ maxSizePerFile?: number;
31
+ onError?: (error: string) => void;
32
+ allowOverride?: boolean
33
+ showDeleteButton?: boolean
34
+ } & Listener<'onChangeFiles', OnChangeFilesData, FileType[]>
35
+ >
36
+ >;
37
+
38
+ export const MultipleFileInput = withMemo(function MultipleImageInput<OnChangeData>({
39
+ className,
40
+ style,
41
+ value,
42
+ label,
43
+ mimeTypes = ['image/*'],
44
+ maxFiles = 1,
45
+ maxSizePerFile = 1024 * 1024 * 10,
46
+ allowOverride = maxFiles === 1,
47
+ onError,
48
+ showDeleteButton = true,
49
+ ...otherProps
50
+ }: MultipleFileInputProps<OnChangeData>) {
51
+ // Variables
52
+
53
+ // Refs
54
+ const inputRef = useRef<HTMLInputElement>(null);
55
+ const indexRef = useRef<number | undefined>(undefined);
56
+
57
+ // States
58
+
59
+ // Selectors
60
+
61
+ // Callbacks
62
+
63
+
64
+ const checkMimeType = useCallback(
65
+ (fileType: string) => {
66
+ return mimeTypes.some((type) => {
67
+ if (type === '*/*' || type === '*') {
68
+ return true;
69
+ }
70
+ if (type.endsWith('/*')) {
71
+ return fileType.startsWith(type.substring(0, type.length - 2));
72
+ }
73
+ return fileType === type;
74
+ });
75
+ },
76
+ [mimeTypes]
77
+ );
78
+
79
+ const [onChangeFiles, ...props] = useListenerWithExtractedProps('onChangeFiles', otherProps);
80
+ const getBase64 = useCallback((inputFiles: Blob[]) => {
81
+ const promises = inputFiles.map(
82
+ (file) =>
83
+ new Promise<string>((resolve, reject) => {
84
+ const reader = new FileReader();
85
+ reader.onload = () => {
86
+ resolve(reader.result as string);
87
+ };
88
+ reader.onerror = reject;
89
+ reader.readAsDataURL(file);
90
+ })
91
+ );
92
+ return Promise.all(promises);
93
+ }, []);
94
+
95
+ const onNewFiles = useCallback(
96
+ async (newFiles: File[], index?: number) => {
97
+ if (newFiles.some((file) => !checkMimeType(file.type))) {
98
+ onError?.('Eine Datei ist im falschen Format');
99
+ return;
100
+ }
101
+
102
+ if (newFiles.length + value.length > maxFiles && (!allowOverride || index === undefined || index + newFiles.length > maxFiles)) {
103
+ onError?.(`Es sind nur ${maxFiles} Dateien erlaubt.`);
104
+ return;
105
+ }
106
+
107
+ if (maxSizePerFile && newFiles.some((file) => file.size > maxSizePerFile)) {
108
+ onError?.(`Eine Datei ist zu groß. Jede Datei darf nur ${maxSizePerFile / 1024 / 1024}MB groß sein.`);
109
+ return;
110
+ }
111
+
112
+ const newUrls = await getBase64(newFiles);
113
+ const newValue = newFiles.map((file, fileIndex) => ({
114
+ name: file.name,
115
+ data: newUrls[fileIndex],
116
+ mimeType: file.type,
117
+ blob: file,
118
+ }));
119
+
120
+ if (newFiles.length + value.length > maxFiles && index !== undefined) {
121
+ const onChangeFilesValue = [...value];
122
+ onChangeFilesValue.splice(index, newFiles.length, ...newValue);
123
+ onChangeFiles(onChangeFilesValue);
124
+ } else {
125
+ onChangeFiles([...value, ...newValue]);
126
+ }
127
+ },
128
+ [allowOverride, checkMimeType, getBase64, maxFiles, maxSizePerFile, onChangeFiles, onError, value]
129
+ );
130
+
131
+ const onInputChange = useCallback<ChangeEventHandler<HTMLInputElement>>(
132
+ async (e) => {
133
+ const index = indexRef.current;
134
+ indexRef.current = undefined;
135
+
136
+ if (!e.target.files || e.target.files.length === 0) {
137
+ return;
138
+ }
139
+
140
+ const newFiles = Array.from(e.target.files);
141
+ await onNewFiles(newFiles, index);
142
+ },
143
+ [onNewFiles]
144
+ );
145
+
146
+ const removeFile = useCallback(
147
+ (_: any, index: number) => {
148
+ if (index >= 0 && index < value.length) {
149
+ const newData = [...value];
150
+ newData.splice(index, 1);
151
+ onChangeFiles(newData);
152
+ }
153
+ },
154
+ [onChangeFiles, value]
155
+ );
156
+
157
+ const onDrop = useCallback(
158
+ async (event: DragEvent, index: number) => {
159
+ event.preventDefault();
160
+
161
+ const files: File[] = [];
162
+ if (event.dataTransfer.items) {
163
+ for (let i = 0; i < event.dataTransfer.items.length; i++) {
164
+ if (event.dataTransfer.items[i].kind === 'file') {
165
+ const file = event.dataTransfer.items[i].getAsFile();
166
+ if (file) {
167
+ files.push(file);
168
+ }
169
+ }
170
+ }
171
+ } else {
172
+ for (let i = 0; i < event.dataTransfer.files.length; i++) {
173
+ files.push(event.dataTransfer.files[i]);
174
+ }
175
+ }
176
+
177
+ await onNewFiles(files, index);
178
+ },
179
+ [onNewFiles]
180
+ );
181
+
182
+ const onDragOver = useCallback((e: DragEvent) => e.preventDefault(), []);
183
+
184
+ const clickOnFile = useCallback((_: any, index?: number) => {
185
+ if (!allowOverride || !inputRef.current) {
186
+ return;
187
+ }
188
+
189
+ indexRef.current = index;
190
+ inputRef.current.dispatchEvent(new MouseEvent("click"));
191
+ }, [allowOverride]);
192
+
193
+ // Effects
194
+
195
+ // Other
196
+
197
+ // Render Functions
198
+ const renderFile = (file: FileType) => {
199
+ if (file.mimeType.startsWith('image/')) {
200
+ return (
201
+ <Image
202
+ key={file.data}
203
+ src={file.data}
204
+ alt={file.name}
205
+ className={classNames(styles.previewImage, file.data)}
206
+ />
207
+ );
208
+ }
209
+ // TODO style
210
+ return (
211
+ <Block className={styles.previewText}>
212
+ <Icon icon={faFile} className={styles.previewTextIcon}/><Text>{file.name}</Text>
213
+ </Block>
214
+ );
215
+ };
216
+
217
+ return (
218
+ <span
219
+ className={classNames(styles.fileInput, className)}
220
+ style={style}
221
+ >
222
+ <Flex horizontal={true}>
223
+ {!!label && (
224
+ <Grow>
225
+ <Text>{label}</Text>
226
+ </Grow>
227
+ )}
228
+ {maxFiles > 1 && (
229
+ <Inline>
230
+ <Text>
231
+ {value.length}/{maxFiles}
232
+ </Text>
233
+ </Inline>
234
+ )}
235
+ </Flex>
236
+ <Flex horizontal={true} className={styles.previewContainer}>
237
+ {value?.map((file, index) => (
238
+ <Grow className={styles.preview} center={true} key={file.data}>
239
+ <Clickable
240
+ onDrop={onDrop}
241
+ onDragOver={onDragOver}
242
+ onDropData={index}
243
+
244
+ onClick={clickOnFile}
245
+ onClickData={index}
246
+ >
247
+ {renderFile(file)}
248
+ {showDeleteButton &&
249
+ <Clickable className={styles.previewRemove} onClick={removeFile} onClickData={index}>
250
+ <Icon icon={faTimesCircle}/>
251
+ </Clickable>}
252
+ </Clickable>
253
+ </Grow>
254
+ ))}
255
+ <Grow className={classNames(styles.addFile, {[styles.hidden]: value.length >= maxFiles})} center={true}>
256
+ <Clickable
257
+ className={styles.addFileButton}
258
+ onDrop={onDrop}
259
+ onDragOver={onDragOver}
260
+ onDropData={maxFiles}
261
+ onClick={clickOnFile}
262
+ __allowChildren="html"
263
+ >
264
+ <Icon icon={faPlus}/>
265
+ <input
266
+ {...props}
267
+ ref={inputRef}
268
+ className={styles.value}
269
+ onChange={onInputChange}
270
+ value=''
271
+ type="file"
272
+ multiple={maxFiles > 1}
273
+ accept={mimeTypes.join(', ')}
274
+ />
275
+ </Clickable>
276
+ </Grow>
277
+ </Flex>
278
+ </span>
279
+ );
280
+ },
281
+ styles);
@@ -20,7 +20,7 @@
20
20
  font-size: 1.5rem;
21
21
 
22
22
  svg {
23
- background: white;
23
+ background: rgba(255, 255, 255, 0.2);
24
24
  }
25
25
  }
26
26
 
@@ -35,6 +35,21 @@
35
35
  object-fit: contain;
36
36
  }
37
37
 
38
+ .previewText {
39
+ width: 100%;
40
+ height: 100%;
41
+ min-height: 4rem;
42
+
43
+ display: flex;
44
+ justify-content: center;
45
+ align-items: center;
46
+ }
47
+
48
+ .previewTextIcon {
49
+ padding-right: 4px;
50
+ }
51
+
52
+
38
53
  .addFile {
39
54
  position: relative;
40
55
  border-radius: 3px;
@@ -44,16 +59,31 @@
44
59
  justify-content: center;
45
60
  align-items: center;
46
61
  font-size: 2rem;
62
+
63
+ .addFileButton {
64
+ width: 100%;
65
+ height: 100%;
66
+ min-height: 4rem;
67
+
68
+ display: flex;
69
+ justify-content: center;
70
+ align-items: center;
71
+ }
72
+
73
+ &.hidden {
74
+ display: none;
75
+ }
47
76
  }
48
77
  }
49
78
 
50
79
 
51
80
  .value {
52
- position: absolute;
53
- top: 0;
54
- left: 0;
55
- right: 0;
56
- bottom: 0;
57
- opacity: 0;
81
+ display: none;
82
+ //position: absolute;
83
+ //top: 0;
84
+ //left: 0;
85
+ //right: 0;
86
+ //bottom: 0;
87
+ //opacity: 0;
58
88
  }
59
89
  }
@@ -31,7 +31,7 @@
31
31
  }
32
32
 
33
33
  &:focus {
34
- background-image: linear-gradient(var(--flavor-focus), var(--flavor-focus)),
34
+ background-image: linear-gradient(var(--flavor-accent), var(--flavor-accent)),
35
35
  linear-gradient(to top, transparent 1px, #afafaf 1px);
36
36
  }
37
37
  }
@@ -128,9 +128,9 @@ export const SearchSelectInput = withMemo(function SearchSelectInput<OnChangeDat
128
128
  }
129
129
 
130
130
  return (
131
- <Clickable onClick={toggleOption} onClickData={value} key={indexedOptions[value].key}>
131
+ <Clickable onClick={toggleOption} onClickData={value} key={indexedOptions[value]?.key}>
132
132
  <InlineBlock className={styles.tag}>
133
- <Text size={TEXT_SIZE.xSmall}>{indexedOptions[value].label}</Text>
133
+ <Text size={TEXT_SIZE.xSmall}>{indexedOptions[value]?.label}</Text>
134
134
  </InlineBlock>
135
135
  </Clickable>
136
136
  );
@@ -21,7 +21,7 @@
21
21
  padding-bottom: 2px;
22
22
 
23
23
  &:focus {
24
- background-image: linear-gradient(var(--flavor-focus), var(--flavor-focus)),
24
+ background-image: linear-gradient(var(--flavor-accent), var(--flavor-accent)),
25
25
  linear-gradient(to top, transparent 1px, #afafaf 1px);
26
26
  }
27
27
  }
@@ -22,6 +22,7 @@ export type SelectProps<OnChangeData> = RbmComponentProps<
22
22
  options: SelectOption[];
23
23
  onChangeValue?: (newValue: string) => void;
24
24
  inline?: boolean;
25
+ small?: boolean;
25
26
  } & OptionalListener<'onChange', OnChangeData>
26
27
  >
27
28
  >;
@@ -33,10 +34,10 @@ export const Select = withMemo(function Select<OnChangeData>({
33
34
  style,
34
35
  onChangeValue,
35
36
  inline = false,
37
+ small = false,
36
38
  ...otherProps
37
39
  }: SelectProps<OnChangeData>) {
38
40
  // Variables
39
- console.log('LOG-d inline', inline);
40
41
 
41
42
  // Refs
42
43
 
@@ -62,7 +63,7 @@ export const Select = withMemo(function Select<OnChangeData>({
62
63
 
63
64
  return (
64
65
  // eslint-disable-next-line jsx-a11y/label-has-associated-control
65
- <label className={classNames(styles.select, { [styles.inline]: inline }, className)} style={style}>
66
+ <label className={classNames(styles.select, { [styles.inline]: inline, [styles.small]: small }, className)} style={style}>
66
67
  {label ? <span className={styles.label}>{label}</span> : null}
67
68
  <select {...otherProps} className={styles.input} onChange={onChange}>
68
69
  {options.map((option) => (
@@ -48,4 +48,9 @@
48
48
  flex: 1;
49
49
  }
50
50
  }
51
+
52
+ &.small .input {
53
+ height: initial;
54
+ line-height: 1.5rem;
55
+ }
51
56
  }
@@ -6,8 +6,9 @@ import classNames from 'classnames';
6
6
 
7
7
  import styles from './switch.scss';
8
8
  import { withMemo } from '../../../helper/withMemo';
9
+ import {OptionalListener, useListenerWithExtractedProps} from "../../Hooks/useListener";
9
10
 
10
- export type SwitchProps = RbmComponentProps<
11
+ export type SwitchProps<OnChangeCheckedData> = RbmComponentProps<
11
12
  Override<
12
13
  InputHTMLAttributes<HTMLInputElement>,
13
14
  {
@@ -16,12 +17,11 @@ export type SwitchProps = RbmComponentProps<
16
17
  children?: string;
17
18
  isLabelBeforeSwitch?: boolean;
18
19
  isDual?: boolean;
19
- onChangeChecked?(isChecked: boolean): void;
20
- }
20
+ } & OptionalListener<"onChangeChecked", OnChangeCheckedData, boolean>
21
21
  >
22
22
  >;
23
23
 
24
- export const Switch = withMemo(function Switch({
24
+ export const Switch = withMemo(function Switch<OnChangeCheckedData>({
25
25
  children,
26
26
  label = '',
27
27
  preLabel = '',
@@ -31,9 +31,8 @@ export const Switch = withMemo(function Switch({
31
31
  className,
32
32
  style,
33
33
  onChange,
34
- onChangeChecked,
35
34
  ...props
36
- }: SwitchProps) {
35
+ }: SwitchProps<OnChangeCheckedData>) {
37
36
  // Variables
38
37
 
39
38
  // States
@@ -41,10 +40,12 @@ export const Switch = withMemo(function Switch({
41
40
  // Refs
42
41
 
43
42
  // Callbacks
43
+ const [onChangeChecked, otherProps] = useListenerWithExtractedProps("onChangeChecked", props);
44
+
44
45
  const realOnChange = useCallback<ChangeEventHandler<HTMLInputElement>>(
45
46
  (e) => {
46
47
  onChange?.(e);
47
- onChangeChecked?.(e.target.checked);
48
+ onChangeChecked(e.target.checked);
48
49
  },
49
50
  [onChange, onChangeChecked]
50
51
  );
@@ -70,7 +71,7 @@ export const Switch = withMemo(function Switch({
70
71
  <span className={classNames(styles.switch, { [styles.dual]: isDual }, className)} style={style}>
71
72
  <label htmlFor={id} key={id}>
72
73
  <span className={styles.label}>{preLabel}</span>
73
- <input {...props} type="checkbox" id={id} onChange={realOnChange} />
74
+ <input {...otherProps} type="checkbox" id={id} onChange={realOnChange} />
74
75
  <div className={styles.toggle}>
75
76
  <span className={styles.handle} />
76
77
  </div>
@@ -9,6 +9,7 @@
9
9
  > label {
10
10
  display: flex;
11
11
  cursor: pointer;
12
+ align-items: center;
12
13
  }
13
14
 
14
15
  .label {
@@ -0,0 +1,13 @@
1
+ import {useLayoutEffect, useRef} from "react";
2
+
3
+ export function useMousePosition() {
4
+ const position = useRef({ x: 0, y: 0 });
5
+ useLayoutEffect(() => {
6
+ const setFromEvent = (e: MouseEvent) => {
7
+ position.current = { x: e.clientX, y: e.clientY };
8
+ };
9
+ window.addEventListener('mousemove', setFromEvent);
10
+ return () => window.removeEventListener('mousemove', setFromEvent);
11
+ }, []);
12
+ return position;
13
+ }
@@ -0,0 +1,17 @@
1
+ import {useWindow} from "../../WindowContext/WindowContext";
2
+ import {useEffect, useReducer} from "react";
3
+
4
+
5
+ export function useWindowDimensions() {
6
+ const [, redraw] = useReducer((x) => x + 1, 0);
7
+ const window = useWindow();
8
+
9
+ useEffect(() => {
10
+ window?.addEventListener('resize', redraw);
11
+ return () => {
12
+ window?.removeEventListener('resize', redraw);
13
+ };
14
+ }, [window]);
15
+
16
+ return {x: window?.innerWidth ?? 0, y: window?.innerHeight ?? 0};
17
+ }
@@ -1,10 +1,13 @@
1
- import { FontAwesomeIcon, FontAwesomeIconProps } from '@fortawesome/react-fontawesome';
1
+ import {FontAwesomeIcon, FontAwesomeIconProps} from '@fortawesome/react-fontawesome';
2
2
  import * as React from 'react';
3
- import { RbmComponentProps } from '../RbmComponentProps';
4
- import { Override } from '../../TypeHelpers';
5
- import { IconProp } from '@fortawesome/fontawesome-svg-core';
6
- import { withMemo } from '../../helper/withMemo';
7
- import { IconDefinition } from '@fortawesome/free-regular-svg-icons';
3
+ import {RbmComponentProps} from '../RbmComponentProps';
4
+ import {Override} from '../../TypeHelpers';
5
+ import {IconProp} from '@fortawesome/fontawesome-svg-core';
6
+ import {withMemo} from '../../helper/withMemo';
7
+ import {IconDefinition} from '@fortawesome/free-regular-svg-icons';
8
+ import classNames from "classnames";
9
+
10
+ import styles from "./icon.scss";
8
11
 
9
12
  export type IconSource = IconProp | string | IconDefinition;
10
13
 
@@ -12,13 +15,14 @@ export type IconProps = RbmComponentProps<
12
15
  Override<
13
16
  FontAwesomeIconProps,
14
17
  {
18
+ noMargin?: boolean
15
19
  icon: IconSource;
16
20
  alt?: string;
17
21
  }
18
22
  >
19
23
  >;
20
24
 
21
- function Icon({ icon, alt, className, style, title, ...props }: IconProps) {
25
+ export const Icon = withMemo(function Icon({icon, alt, className, noMargin = true, style, title, ...props}: IconProps) {
22
26
  // Variables
23
27
 
24
28
  // States
@@ -36,11 +40,11 @@ function Icon({ icon, alt, className, style, title, ...props }: IconProps) {
36
40
 
37
41
  // Render Functions
38
42
 
39
- if (typeof icon === 'string' && icon.indexOf('.') !== -1) {
40
- return <img src={icon} alt={alt} className={className} style={style} title={title} />;
43
+ if (typeof icon === 'string' && (icon.indexOf('.') !== -1 || icon.startsWith("data:"))) {
44
+ return <img src={icon} alt={alt} className={classNames(styles.imgIcon, className, {[styles.margin]: !noMargin})}
45
+ style={style} title={title}/>;
41
46
  }
42
- return <FontAwesomeIcon {...props} icon={icon as IconProp} className={className} style={style} title={title} />;
43
- }
44
-
45
- const IconMemo = withMemo(Icon);
46
- export { IconMemo as Icon };
47
+ return <FontAwesomeIcon {...props} icon={icon as IconProp}
48
+ className={classNames(className, {[styles.margin]: !noMargin})} style={style}
49
+ title={title}/>;
50
+ }, styles);
@@ -0,0 +1,9 @@
1
+ .margin {
2
+ margin-left: 0.3rem;
3
+ margin-right: 0.3rem;
4
+ }
5
+ .imgIcon {
6
+ width: calc(1em + 4px);
7
+ height: calc(1em + 4px);
8
+ object-fit: contain;
9
+ }
@@ -10,9 +10,10 @@ import { useMemo } from 'react';
10
10
  export type GridProps = RbmComponentProps<{
11
11
  columns?: number;
12
12
  rows?: number;
13
+ useContainerWidth?: boolean;
13
14
  }>;
14
15
 
15
- function Grid({ style, children, columns = 12, rows = 1, className, __allowChildren }: GridProps) {
16
+ function Grid({ style, children, columns = 12, rows = 1, useContainerWidth = false, className, __allowChildren }: GridProps) {
16
17
  // Variables
17
18
  const appliedStyle = useMemo(
18
19
  () => ({
@@ -40,7 +41,7 @@ function Grid({ style, children, columns = 12, rows = 1, className, __allowChild
40
41
  return (
41
42
  <Block
42
43
  style={appliedStyle}
43
- className={classNames(styles.grid, className)}
44
+ className={classNames(styles.grid, className, {[styles.useContainerWidth]: useContainerWidth})}
44
45
  __allowChildren={__allowChildren as 'all'}
45
46
  >
46
47
  {children}