@ainias42/react-bootstrap-mobile 0.2.13 → 0.2.14

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.
@@ -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,14 @@ 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
+ console.log("LOG-d stopPropagation inside checkStopPropagation", ev);
64
+ ev.stopPropagation();
65
+ ev.nativeEvent.stopPropagation();
66
+ }
67
+ }, [stopPropagation]);
68
+
56
69
  // Effects
57
70
 
58
71
  // Other
@@ -71,17 +84,16 @@ export const Switch = withMemo(function Switch<OnChangeCheckedData>({
71
84
  isDual = true;
72
85
  }
73
86
  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
- );
87
+ <span className={classNames(styles.switch, {[styles.dual]: isDual}, className)} style={style} onClick={checkStopPropagation}>
88
+ <label htmlFor={id} key={id}>
89
+ <span className={classNames(styles.label, classNamePreLabel)}>{preLabel}</span>
90
+ <input {...otherProps} type="checkbox" id={id} onChange={realOnChange}/>
91
+ <div className={styles.toggle}>
92
+ <span className={styles.handle}/>
93
+ </div>
94
+ <span className={classNames(styles.label, classNameLabel)}>{label}</span>
95
+ <FormError error={error}/>
96
+ </label>
97
+ </span>);
86
98
  },
87
99
  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,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}