@ainias42/react-bootstrap-mobile 0.1.20 → 0.1.22

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.
@@ -10,6 +10,7 @@ type OnDragOverListener<Data> = OptionalListener<'onDragOver', Data>;
10
10
  export type ClickableProps<OnClickData, OnMouseDownData, OnMouseMoveData, OnMouseUpData, OnClickCaptureData, OnDropData, OnDragOverData, OnMouseEnterData, OnMouseLeaveData, OnDoubleClickData, HrefType extends string | undefined> = RbmComponentProps<{
11
11
  interactable?: boolean;
12
12
  href?: HrefType;
13
+ target?: string;
13
14
  preventDefault?: boolean;
14
15
  stopPropagation?: boolean;
15
16
  useReactOnMouseLeave?: boolean;
@@ -6,5 +6,6 @@ export type InputProps<OnChangeData, OnBlurData, OnChangeDoneData> = RbmComponen
6
6
  label?: string;
7
7
  onChangeText?: (newText: string) => void;
8
8
  onEnter?: (newText: string) => void;
9
+ inline?: boolean;
9
10
  } & OptionalListener<'onChange', OnChangeData> & OptionalListener<'onBlur', OnBlurData> & OptionalListener<'onChangeDone', OnChangeDoneData>>>;
10
11
  export declare const Input: import("../../../helper/withForwardRef").RefComponent<InputProps<unknown, unknown, unknown>, HTMLInputElement>;
@@ -1,13 +1,13 @@
1
- import * as React from 'react';
2
1
  import { RbmComponentProps } from '../../RbmComponentProps';
3
2
  import { Override } from '../../../TypeHelpers';
4
- import { TextareaHTMLAttributes } from 'react';
3
+ import { TextareaHTMLAttributes, MutableRefObject, CSSProperties } from 'react';
5
4
  import { OptionalListener } from '../../Hooks/useListener';
6
- export type TextareaProps<OnChangeData> = RbmComponentProps<Override<TextareaHTMLAttributes<HTMLTextAreaElement>, {
5
+ export type TextareaProps<OnChangeData, OnChangeDoneData> = RbmComponentProps<Override<TextareaHTMLAttributes<HTMLTextAreaElement>, {
7
6
  label?: string;
8
7
  onChangeText?: (newText: string) => void;
9
8
  onEnter?: (newText: string) => void;
10
- } & OptionalListener<'onChange', OnChangeData>>>;
11
- declare function Textarea<OnChangeData>({ label, className, style, onKeyUp, onChangeText, onEnter, ...otherProps }: TextareaProps<OnChangeData>): React.JSX.Element;
12
- declare const TextareaMemo: typeof Textarea;
13
- export { TextareaMemo as Textarea };
9
+ onEscape?: (newText: string) => void;
10
+ textareaStyles?: CSSProperties & Record<`--${string}`, string | number | undefined>;
11
+ containerRef?: MutableRefObject<HTMLLabelElement | null>;
12
+ } & OptionalListener<'onChange', OnChangeData> & OptionalListener<'onChangeDone', OnChangeDoneData>>>;
13
+ export declare const Textarea: import("../../../helper/withForwardRef").RefComponent<TextareaProps<unknown, unknown>, HTMLTextAreaElement>;
@@ -1,2 +1,2 @@
1
1
  import { MutableRefObject } from 'react';
2
- export declare function useOnChangeDone(onChangeDone: (ev: any) => void, ref?: MutableRefObject<HTMLInputElement | null>): import("react").RefObject<HTMLInputElement>;
2
+ export declare function useOnChangeDone(onChangeDone: (ev: any) => void, ref?: MutableRefObject<HTMLInputElement | HTMLTextAreaElement | null>): import("react").RefObject<HTMLInputElement> | MutableRefObject<HTMLInputElement | HTMLTextAreaElement | null>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainias42/react-bootstrap-mobile",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "Mobile React Components using Bootstrap",
5
5
  "main": "dist/bootstrapReactMobile",
6
6
  "scripts": {
@@ -82,7 +82,7 @@
82
82
  "@types/react-virtualized-auto-sizer": "^1.0.1",
83
83
  "classnames": "^2.3.1",
84
84
  "isomorphic-style-loader": "^5.3.2",
85
- "@ainias42/js-helper": ">=0.8.9",
85
+ "@ainias42/js-helper": ">=0.8.10",
86
86
  "react-color": "^2.19.3",
87
87
  "react-table": "^7.7.0",
88
88
  "react-virtualized-auto-sizer": "^1.0.7",
@@ -31,6 +31,7 @@ export type ClickableProps<
31
31
  {
32
32
  interactable?: boolean;
33
33
  href?: HrefType;
34
+ target?: string
34
35
  preventDefault?: boolean;
35
36
  stopPropagation?: boolean;
36
37
  useReactOnMouseLeave?: boolean;
@@ -64,6 +65,7 @@ function Clickable<
64
65
  children,
65
66
  style,
66
67
  href,
68
+ target,
67
69
  interactable = true,
68
70
  preventDefault = false,
69
71
  stopPropagation = true,
@@ -257,6 +259,7 @@ function Clickable<
257
259
  // Render Functions
258
260
  const props = {
259
261
  style,
262
+ target,
260
263
  role: interactable ? 'button' : undefined,
261
264
  'aria-hidden': interactable ? undefined : true,
262
265
  className: classNames(styles.clickable, className),
@@ -182,11 +182,12 @@ export const MultipleFileInput = withMemo(function MultipleImageInput<OnChangeDa
182
182
  const onDragOver = useCallback((e: DragEvent) => e.preventDefault(), []);
183
183
 
184
184
  const clickOnFile = useCallback((_: any, index?: number) => {
185
- if (!allowOverride || !inputRef.current) {
185
+ if ((index !== undefined && !allowOverride) || !inputRef.current) {
186
186
  return;
187
187
  }
188
188
 
189
189
  indexRef.current = index;
190
+ console.log("LOG-d inputRef dispatch", inputRef.current);
190
191
  inputRef.current.dispatchEvent(new MouseEvent("click"));
191
192
  }, [allowOverride]);
192
193
 
@@ -17,6 +17,7 @@ export type InputProps<OnChangeData, OnBlurData, OnChangeDoneData> = RbmComponen
17
17
  label?: string;
18
18
  onChangeText?: (newText: string) => void;
19
19
  onEnter?: (newText: string) => void;
20
+ inline?: boolean
20
21
  } & OptionalListener<'onChange', OnChangeData> &
21
22
  OptionalListener<'onBlur', OnBlurData> &
22
23
  OptionalListener<'onChangeDone', OnChangeDoneData>
@@ -30,6 +31,7 @@ export const Input = withForwardRef(function Input<OnChangeData, OnBlurData, OnC
30
31
  style,
31
32
  onEnter,
32
33
  onKeyDown,
34
+ inline = false,
33
35
  onChangeText,
34
36
  ...otherProps
35
37
  }: InputProps<OnChangeData, OnBlurData, OnChangeDoneData>,
@@ -86,7 +88,7 @@ export const Input = withForwardRef(function Input<OnChangeData, OnBlurData, OnC
86
88
 
87
89
  return (
88
90
  // eslint-disable-next-line jsx-a11y/label-has-associated-control
89
- <label className={classNames(styles.input, className)} style={style}>
91
+ <label className={classNames(styles.input, {[styles.inline]: inline}, className)} style={style}>
90
92
  {label ? <span className={styles.label}>{label}</span> : null}
91
93
  <input
92
94
  {...otherPropsWithoutData}
@@ -4,6 +4,22 @@
4
4
  .input {
5
5
  width: 100%;
6
6
 
7
+ &.inline {
8
+ --basis: 50%;
9
+ display: flex;
10
+ .label {
11
+ display: inline-block;
12
+ flex-grow: 1;
13
+ flex-shrink: 0;
14
+ flex-basis: var(--basis);
15
+ font-weight: normal;
16
+ }
17
+ .text {
18
+ // 3 numbers
19
+ min-width: 41px;
20
+ }
21
+ }
22
+
7
23
  .label {
8
24
  display: block;
9
25
  font-weight: bold;
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { RbmComponentProps } from '../../RbmComponentProps';
3
3
  import { withMemo } from '../../../helper/withMemo';
4
- import { ChangeEventHandler, InputHTMLAttributes, useCallback } from 'react';
4
+ import { ChangeEventHandler, InputHTMLAttributes, MutableRefObject, useCallback } from 'react';
5
5
 
6
6
  import styles from './slider.scss';
7
7
  import classNames from 'classnames';
@@ -58,7 +58,7 @@ export const Slider = withMemo(function Slider<OnChangeData, OnChangeValueData,
58
58
  );
59
59
 
60
60
  // Effects
61
- const innerRef = useOnChangeDone(onChangeDone);
61
+ const innerRef = useOnChangeDone(onChangeDone) as MutableRefObject<HTMLInputElement|null>;
62
62
 
63
63
  // Other
64
64
 
@@ -1,41 +1,66 @@
1
1
  import * as React from 'react';
2
2
  import { RbmComponentProps } from '../../RbmComponentProps';
3
3
  import { Override } from '../../../TypeHelpers';
4
- import { TextareaHTMLAttributes, useCallback, KeyboardEvent, ChangeEvent } from 'react';
5
- import { OptionalListener, useListener } from '../../Hooks/useListener';
6
- import { withMemo } from '../../../helper/withMemo';
4
+ import {
5
+ TextareaHTMLAttributes,
6
+ useCallback,
7
+ KeyboardEvent,
8
+ ChangeEvent,
9
+ MutableRefObject,
10
+ CSSProperties
11
+ } from 'react';
12
+ import { OptionalListener, useListenerWithExtractedProps } from '../../Hooks/useListener';
7
13
 
8
14
  import styles from './textarea.scss';
9
15
  import classNames from 'classnames';
16
+ import { withForwardRef } from "../../../helper/withForwardRef";
17
+ import { useOnChangeDone } from "../hooks/useOnChangeDone";
18
+ import { useComposedRef } from "../../Hooks/useComposedRef";
10
19
 
11
- export type TextareaProps<OnChangeData> = RbmComponentProps<
20
+ export type TextareaProps<OnChangeData, OnChangeDoneData> = RbmComponentProps<
12
21
  Override<
13
22
  TextareaHTMLAttributes<HTMLTextAreaElement>,
14
23
  {
15
24
  label?: string;
16
25
  onChangeText?: (newText: string) => void;
17
26
  onEnter?: (newText: string) => void;
27
+ onEscape?: (newText: string) => void;
28
+ textareaStyles?: CSSProperties & Record<`--${string}`, string | number | undefined>,
29
+ containerRef?: MutableRefObject<HTMLLabelElement|null>
18
30
  } & OptionalListener<'onChange', OnChangeData>
31
+ & OptionalListener<'onChangeDone', OnChangeDoneData>
19
32
  >
20
33
  >;
21
34
 
22
- function Textarea<OnChangeData>({
23
- label,
24
- className,
25
- style,
26
- onKeyUp,
27
- onChangeText,
28
- onEnter,
29
- ...otherProps
30
- }: TextareaProps<OnChangeData>) {
35
+ export const Textarea = withForwardRef(function Textarea<OnChangeData, OnChangeDoneData>({
36
+ label,
37
+ className,
38
+ style,
39
+ onKeyUp,
40
+ onChangeText,
41
+ onEnter,
42
+ onEscape,
43
+ textareaStyles,
44
+ containerRef,
45
+ ...otherProps
46
+ }: TextareaProps<OnChangeData, OnChangeDoneData>, ref: MutableRefObject<HTMLTextAreaElement> | null) {
47
+ // Refs
48
+ const innerRef = useComposedRef(ref);
49
+
31
50
  // Variables
32
51
 
33
52
  // States
34
53
 
35
- // Refs
36
-
37
54
  // Callbacks
38
- const onChangeWithData = useListener<'onChange', OnChangeData>('onChange', otherProps);
55
+ const [onChangeWithData, otherPropsWithoutOnchange] = useListenerWithExtractedProps<'onChange', OnChangeData>(
56
+ 'onChange',
57
+ otherProps
58
+ );
59
+ const [onChangeDone, otherPropsWithoutData] = useListenerWithExtractedProps<'onChangeDone', OnChangeDoneData>(
60
+ 'onChangeDone',
61
+ otherPropsWithoutOnchange
62
+ );
63
+
39
64
  const onChange = useCallback(
40
65
  (e: ChangeEvent<HTMLTextAreaElement>) => {
41
66
  if (onChangeText) {
@@ -54,24 +79,27 @@ function Textarea<OnChangeData>({
54
79
  if (onEnter && e.key === 'Enter' && !e.defaultPrevented) {
55
80
  onEnter((e.target as HTMLTextAreaElement).value);
56
81
  }
82
+ if (onEscape && e.key === 'Escape' && !e.defaultPrevented) {
83
+ onEscape((e.target as HTMLTextAreaElement).value);
84
+ }
57
85
  },
58
- [onEnter, onKeyUp]
86
+ [onEnter, onEscape, onKeyUp]
59
87
  );
60
88
 
61
89
  // Effects
90
+ useOnChangeDone(onChangeDone, innerRef);
91
+
62
92
 
63
93
  // Other
64
94
 
65
95
  // Render Functions
66
96
 
67
97
  return (
68
- <label className={classNames(styles.container, className)} style={style}>
98
+ <label className={classNames(styles.container, className)} style={style} ref={containerRef}>
69
99
  {label ? <span className={styles.label}>{label}</span> : null}
70
- <textarea {...otherProps} onKeyUp={realOnKeyPress} className={styles.textarea} onChange={onChange} />
100
+ <textarea {...otherPropsWithoutData} style={textareaStyles} onKeyUp={realOnKeyPress}
101
+ className={styles.textarea} onChange={onChange} ref={innerRef}/>
71
102
  </label>
72
103
  );
73
- }
104
+ }, styles);
74
105
 
75
- // Need TextareaMemo for autocompletion of phpstorm
76
- const TextareaMemo = withMemo(Textarea, styles);
77
- export { TextareaMemo as Textarea };
@@ -1,6 +1,6 @@
1
1
  import { MutableRefObject, useEffect, useRef } from 'react';
2
2
 
3
- export function useOnChangeDone(onChangeDone: (ev: any) => void, ref?: MutableRefObject<HTMLInputElement | null>) {
3
+ export function useOnChangeDone(onChangeDone: (ev: any) => void, ref?: MutableRefObject<HTMLInputElement| HTMLTextAreaElement | null>) {
4
4
  const innerRef = useRef<HTMLInputElement>(null);
5
5
  const usedRef = ref ?? innerRef;
6
6
 
@@ -1,5 +1,6 @@
1
1
  import { CSSProperties, ReactNode } from 'react';
2
2
  import { Recursive } from '../TypeHelpers';
3
+ import { URecord } from "@ainias42/js-helper";
3
4
 
4
5
  export type RbmChildWithoutString = Recursive<JSX.Element | undefined | null | RbmChildWithoutString[]> | false;
5
6
  export type WithNoStringProps =
@@ -5,7 +5,7 @@ import styles from './text.scss';
5
5
  import { Recursive, ValueOf } from '../../TypeHelpers';
6
6
  import { WrongChildError } from '../../WrongChildError';
7
7
  import withStyles from 'isomorphic-style-loader/withStyles';
8
- import { Inline } from '../Layout/Inline';
8
+ import { Inline, InlineProps } from '../Layout/Inline';
9
9
  import { ViewProps } from '../Layout/View';
10
10
 
11
11
  export const TEXT_PRIO = {
@@ -68,7 +68,7 @@ function Text<AsType extends keyof JSX.IntrinsicElements = 'span'>({
68
68
  <Inline
69
69
  __allowChildren="text"
70
70
  as={as}
71
- {...props}
71
+ {...props as InlineProps<AsType>}
72
72
  className={classNames(styles.text, { [styles.block]: block }, prio, size, className)}
73
73
  >
74
74
  {children}