@ainias42/react-bootstrap-mobile 0.2.13 → 0.2.15

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 (25) hide show
  1. package/bin/updateCopies.js +1 -0
  2. package/bootstrapReactMobile.ts +1 -0
  3. package/dist/bootstrapReactMobile.d.ts +1 -0
  4. package/dist/bootstrapReactMobile.js +201 -68
  5. package/dist/bootstrapReactMobile.js.map +1 -1
  6. package/dist/src/Components/FormElements/Button/Button.d.ts +2 -1
  7. package/dist/src/Components/FormElements/Controller/useYupResolver.d.ts +11 -0
  8. package/dist/src/Components/FormElements/SearchSelectInput/SearchSelectInput.d.ts +8 -1
  9. package/dist/src/Components/FormElements/Slider/Slider.d.ts +2 -1
  10. package/dist/src/Components/FormElements/Switch/Switch.d.ts +4 -1
  11. package/dist/src/Components/SpoilerList/Spoiler/Spoiler.d.ts +2 -1
  12. package/package.json +3 -2
  13. package/src/Components/Dialog/dialogBackground.scss +1 -0
  14. package/src/Components/FormElements/Button/Button.tsx +11 -3
  15. package/src/Components/FormElements/ColorInput/ColorInput.tsx +1 -1
  16. package/src/Components/FormElements/ColorInput/sharedSelectedColor.ts +1 -1
  17. package/src/Components/FormElements/Controller/useYupResolver.ts +53 -0
  18. package/src/Components/FormElements/SearchSelectInput/SearchSelectInput.tsx +161 -129
  19. package/src/Components/FormElements/SearchSelectInput/seachSelectInput.scss +6 -1
  20. package/src/Components/FormElements/Slider/Slider.tsx +9 -1
  21. package/src/Components/FormElements/Switch/Switch.tsx +25 -14
  22. package/src/Components/FormElements/Switch/switch.scss +18 -16
  23. package/src/Components/Icon/Icon.tsx +0 -1
  24. package/src/Components/Menu/Menu.tsx +43 -42
  25. package/src/Components/SpoilerList/Spoiler/Spoiler.tsx +24 -18
@@ -1,9 +1,8 @@
1
1
  import * as React from 'react';
2
- import { ChangeEventHandler, InputHTMLAttributes, useCallback } from 'react';
2
+ import { ChangeEventHandler, InputHTMLAttributes, MouseEvent, useCallback } from 'react';
3
3
  import { RbmComponentProps } from '../../RbmComponentProps';
4
4
  import { Override } from '../../../TypeHelpers';
5
5
  import classNames from 'classnames';
6
-
7
6
  import styles from './switch.scss';
8
7
  import { withMemo } from '../../../helper/withMemo';
9
8
  import { OptionalListener, useListenerWithExtractedProps } from "../../Hooks/useListener";
@@ -19,6 +18,9 @@ export type SwitchProps<OnChangeCheckedData> = RbmComponentProps<
19
18
  isLabelBeforeSwitch?: boolean;
20
19
  isDual?: boolean;
21
20
  error?: string;
21
+ classNameLabel?: string;
22
+ classNamePreLabel?: string;
23
+ stopPropagation?: boolean;
22
24
  } & OptionalListener<"onChangeChecked", OnChangeCheckedData, boolean>
23
25
  >
24
26
  >;
@@ -29,8 +31,11 @@ export const Switch = withMemo(function Switch<OnChangeCheckedData>({
29
31
  preLabel = '',
30
32
  isLabelBeforeSwitch = false,
31
33
  isDual = undefined,
34
+ stopPropagation = true,
32
35
  id,
33
36
  className,
37
+ classNamePreLabel,
38
+ classNameLabel,
34
39
  style,
35
40
  error,
36
41
  onChange,
@@ -53,6 +58,13 @@ export const Switch = withMemo(function Switch<OnChangeCheckedData>({
53
58
  [onChange, onChangeChecked]
54
59
  );
55
60
 
61
+ const checkStopPropagation = useCallback((ev: MouseEvent) => {
62
+ if (stopPropagation) {
63
+ ev.stopPropagation();
64
+ ev.nativeEvent.stopPropagation();
65
+ }
66
+ }, [stopPropagation]);
67
+
56
68
  // Effects
57
69
 
58
70
  // Other
@@ -71,17 +83,16 @@ export const Switch = withMemo(function Switch<OnChangeCheckedData>({
71
83
  isDual = true;
72
84
  }
73
85
  return (
74
- <span className={classNames(styles.switch, {[styles.dual]: isDual}, className)} style={style}>
75
- <label htmlFor={id} key={id}>
76
- <span className={styles.label}>{preLabel}</span>
77
- <input {...otherProps} type="checkbox" id={id} onChange={realOnChange}/>
78
- <div className={styles.toggle}>
79
- <span className={styles.handle}/>
80
- </div>
81
- <span className={styles.label}>{label}</span>
82
- <FormError error={error}/>
83
- </label>
84
- </span>
85
- );
86
+ <span className={classNames(styles.switch, {[styles.dual]: isDual}, className)} style={style} onClick={checkStopPropagation}>
87
+ <label htmlFor={id} key={id}>
88
+ <span className={classNames(styles.label, classNamePreLabel)}>{preLabel}</span>
89
+ <input {...otherProps} type="checkbox" id={id} onChange={realOnChange}/>
90
+ <div className={styles.toggle}>
91
+ <span className={styles.handle}/>
92
+ </div>
93
+ <span className={classNames(styles.label, classNameLabel)}>{label}</span>
94
+ <FormError error={error}/>
95
+ </label>
96
+ </span>);
86
97
  },
87
98
  styles);
@@ -24,6 +24,7 @@
24
24
  }
25
25
 
26
26
  .toggle {
27
+ flex-shrink: 0;
27
28
  width: 40px;
28
29
  display: inline-block;
29
30
  position: relative;
@@ -33,6 +34,7 @@
33
34
  border-radius: 30px;
34
35
 
35
36
  .handle {
37
+ left: var(--switch-handle-offset, 0);
36
38
  transition-property: all;
37
39
  transition-duration: 0.35s;
38
40
  transition-timing-function: cubic-bezier(.59, .01, .5, .99);
@@ -60,14 +62,14 @@
60
62
  }
61
63
 
62
64
  @include design($material) {
63
- input:checked + {
64
- .toggle {
65
- //box-shadow: none;
65
+ --switch-handle-checked-offset: 18px;
66
+ --switch-handle-offset: 0px;
66
67
 
67
- .handle {
68
- @extend %dual-handle-material;
69
- left: 18px;
70
- }
68
+ input:checked + .toggle {
69
+ --switch-handle-offset: var(--switch-handle-checked-offset);
70
+
71
+ .handle {
72
+ @extend %dual-handle-material;
71
73
  }
72
74
  }
73
75
 
@@ -82,7 +84,6 @@
82
84
  width: 22px;
83
85
  height: 22px;
84
86
  background-color: #f1f1f1;
85
- left: 0;
86
87
  box-shadow: 0 4px 5px 0 rgb(0 0 0 / 14%), 0 1px 10px 0 rgb(0 0 0 / 12%), 0 2px 4px -1px rgb(0 0 0 / 40%);
87
88
 
88
89
  &:before {
@@ -101,15 +102,17 @@
101
102
  }
102
103
 
103
104
  @include design($flat) {
104
- input:checked + {
105
- .toggle {
106
- @extend %dual-toggle-flat;
105
+ --switch-handle-offset: 2px;
106
+ --switch-handle-checked-offset: 19px;
107
107
 
108
- .handle {
109
- @extend %dual-handle-flat;
110
- left: 19px
111
- }
108
+ input:checked + .toggle {
109
+ @extend %dual-toggle-flat;
110
+ --switch-handle-offset: var(--switch-handle-checked-offset);
111
+
112
+ .handle {
113
+ @extend %dual-handle-flat;
112
114
  }
115
+
113
116
  }
114
117
 
115
118
  .toggle {
@@ -122,7 +125,6 @@
122
125
  height: 19px;
123
126
  width: 19px;
124
127
  background-color: #ffffff;
125
- left: 2px;
126
128
  top: 2px;
127
129
  box-shadow: 0 0 1px 0 rgb(0 0 0 / 25%), 0 3px 2px rgb(0 0 0 / 25%);
128
130
  }
@@ -6,7 +6,6 @@ import {IconProp} from '@fortawesome/fontawesome-svg-core';
6
6
  import {withMemo} from '../../helper/withMemo';
7
7
  import {IconDefinition} from '@fortawesome/free-regular-svg-icons';
8
8
  import classNames from "classnames";
9
-
10
9
  import styles from "./icon.scss";
11
10
 
12
11
  export type IconSource = IconProp | string | IconDefinition;
@@ -1,16 +1,16 @@
1
1
  import * as React from 'react';
2
- import {withMemo} from '../../helper/withMemo';
3
- import {RbmComponentProps} from '../RbmComponentProps';
4
- import {IconSource} from '../Icon/Icon';
5
- import {Block} from '../Layout/Block';
2
+ import { withMemo } from '../../helper/withMemo';
3
+ import { RbmComponentProps } from '../RbmComponentProps';
4
+ import { IconSource } from '../Icon/Icon';
5
+ import { Block } from '../Layout/Block';
6
6
  import classNames from 'classnames';
7
7
  import styles from './menu.scss';
8
- import {useEffect, useRef, useState} from 'react';
9
- import {withRenderBrowserOnly} from '../../helper/withRenderBrowserOnly';
10
- import {useWindow} from '../../WindowContext/WindowContext';
11
- import {MenuItem} from "./MenuItem";
12
- import {MenuCloseContextProvider} from "./MenuCloseContext";
13
- import {createPortal} from "react-dom";
8
+ import { useEffect, useRef, useState } from 'react';
9
+ import { withRenderBrowserOnly } from '../../helper/withRenderBrowserOnly';
10
+ import { useWindow } from '../../WindowContext/WindowContext';
11
+ import { MenuItem } from "./MenuItem";
12
+ import { MenuCloseContextProvider } from "./MenuCloseContext";
13
+ import { createPortal } from "react-dom";
14
14
  import { useClientLayoutEffect } from "../Hooks/useClientLayoutEffect";
15
15
 
16
16
  export type MenuItemType = {
@@ -71,7 +71,7 @@ export const Menu = withMemo(
71
71
  // Effects
72
72
  useEffect(() => {
73
73
  if (isOpen) {
74
- const listener = (e: MouseEvent|TouchEvent) => {
74
+ const listener = (e: MouseEvent | TouchEvent) => {
75
75
  if (!menuRef.current?.contains(e.target as Node)) {
76
76
  onClose();
77
77
  }
@@ -90,7 +90,7 @@ export const Menu = withMemo(
90
90
  if (!isOpen) {
91
91
  return;
92
92
  }
93
- let elem = window?.document.body.querySelector(`.${ MENU_CONTAINER_CLASS}`);
93
+ let elem = window?.document.body.querySelector(`.${MENU_CONTAINER_CLASS}`);
94
94
  if (!elem) {
95
95
  elem = window?.document.body;
96
96
  }
@@ -99,37 +99,38 @@ export const Menu = withMemo(
99
99
 
100
100
  useClientLayoutEffect(() => {
101
101
  if (!menuRef.current) {
102
- return;
103
- }
104
- const width = parseFloat(getComputedStyle(menuRef.current).width);
105
- let newX = x;
106
- if (newX > (window?.innerWidth ?? 0) - width) {
107
- newX -= width + offsetX;
108
- }
109
-
110
- if (newX < 0) {
111
- newX = 0;
112
- }
113
-
114
- setInnerX(newX);
115
- }, [offsetX, window?.innerWidth, x]);
116
-
117
- useClientLayoutEffect(() => {
118
- if (!menuRef.current) {
119
- return;
120
- }
121
- const height = parseFloat(getComputedStyle(menuRef.current).height);
122
- let newY = y;
123
- if (newY > (window?.innerHeight ?? 0) - height) {
124
- newY -= height + offsetY;
102
+ return undefined;
125
103
  }
126
-
127
- if (newY < 0) {
128
- newY = 0;
129
- }
130
-
131
- setInnerY(newY);
132
- }, [offsetY, window?.innerHeight, y]);
104
+ const menuElement = menuRef.current;
105
+
106
+ const updateInnerPositions = () => {
107
+ const computedStyle = getComputedStyle(menuElement);
108
+ const height = parseFloat(computedStyle.height);
109
+ let newY = y;
110
+ if (newY > (window?.innerHeight ?? 0) - height) {
111
+ newY -= height + offsetY;
112
+ }
113
+ setInnerY(Math.max(0, newY));
114
+
115
+ const width = parseFloat(computedStyle.width);
116
+ let newX = x;
117
+ if (newX > (window?.innerWidth ?? 0) - width) {
118
+ newX -= width + offsetX;
119
+ }
120
+ setInnerX(Math.max(0, newX));
121
+
122
+ };
123
+
124
+ const observer = new ResizeObserver(() => {
125
+ updateInnerPositions();
126
+ });
127
+ observer.observe(menuElement);
128
+ updateInnerPositions();
129
+
130
+ return () => {
131
+ observer.disconnect();
132
+ };
133
+ }, [window, x, y, offsetX, offsetY]);
133
134
 
134
135
  // Other
135
136
 
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { withMemo } from '../../../helper/withMemo';
3
3
  import { RbmComponentProps } from '../../RbmComponentProps';
4
- import { ReactChild, useCallback, useEffect, useRef, useState } from 'react';
4
+ import { MouseEvent, ReactChild, useCallback, useEffect, useRef, useState } from 'react';
5
5
  import { Flex } from '../../Layout/Flex';
6
6
  import { Grow } from '../../Layout/Grow';
7
7
  import { Text, TEXT_SIZE } from '../../Text/Text';
@@ -18,6 +18,7 @@ export type SpoilerProps<OnClickData> = RbmComponentProps<
18
18
  title: ReactChild;
19
19
  initialOpen?: boolean;
20
20
  open?: boolean;
21
+ onlyTitleToggles?: boolean;
21
22
  noClosingAnimation?: boolean;
22
23
  openIcon?: IconSource | null;
23
24
  closeIcon?: IconSource | null;
@@ -25,17 +26,18 @@ export type SpoilerProps<OnClickData> = RbmComponentProps<
25
26
  >;
26
27
 
27
28
  function Spoiler<OnClickData>({
28
- title,
29
- children,
30
- initialOpen = false,
31
- noClosingAnimation = false,
32
- openIcon = faChevronDown,
33
- closeIcon = faChevronUp,
34
- className,
35
- style,
36
- open,
37
- ...listenerProps
38
- }: SpoilerProps<OnClickData>) {
29
+ title,
30
+ children,
31
+ initialOpen = false,
32
+ noClosingAnimation = false,
33
+ openIcon = faChevronDown,
34
+ closeIcon = faChevronUp,
35
+ className,
36
+ onlyTitleToggles = false,
37
+ style,
38
+ open,
39
+ ...listenerProps
40
+ }: SpoilerProps<OnClickData>) {
39
41
  // Variables
40
42
 
41
43
  // Refs
@@ -50,12 +52,14 @@ function Spoiler<OnClickData>({
50
52
  // Callbacks
51
53
  const onClickListener = useListener<'onClick', OnClickData, boolean>('onClick', listenerProps);
52
54
 
53
- const toggleOpen = useCallback(() => {
55
+ const toggleOpen = useCallback((ev: MouseEvent) => {
56
+ console.log("LOG-d target", ev.target);
54
57
  if (open !== undefined) {
55
58
  onClickListener?.(!open);
56
59
  } else {
57
60
  setIsInitialValue(false);
58
61
  setIsOpen((old) => {
62
+ console.log("LOG-d toggleOpen", !old);
59
63
  onClickListener?.(!old);
60
64
  return !old;
61
65
  });
@@ -78,7 +82,7 @@ function Spoiler<OnClickData>({
78
82
 
79
83
  return (
80
84
  <Clickable
81
- onClick={toggleOpen}
85
+ onClick={onlyTitleToggles ? undefined: toggleOpen}
82
86
  className={classNames(className, styles.spoiler, {
83
87
  [styles.open]: open ?? isOpen,
84
88
  [styles.noAnimation]: isInitialValue,
@@ -86,10 +90,12 @@ function Spoiler<OnClickData>({
86
90
  })}
87
91
  style={style}
88
92
  >
89
- <Flex horizontal={true}>
90
- <Grow __allowChildren="all">{titleComponent}</Grow>
91
- {icon ? <Icon icon={icon} className={styles.icon} /> : null}
92
- </Flex>
93
+ <Clickable onClick={toggleOpen}>
94
+ <Flex horizontal={true}>
95
+ <Grow __allowChildren="all">{titleComponent}</Grow>
96
+ {icon ? <Icon icon={icon} className={styles.icon}/> : null}
97
+ </Flex>
98
+ </Clickable>
93
99
  <Block className={styles.bodyContainer}>
94
100
  <Block __allowChildren="all" className={styles.body}>
95
101
  {children}