@ainias42/react-bootstrap-mobile 0.1.18 → 0.1.19
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.
- package/.npnignore +3 -0
- package/dist/bootstrapReactMobile.js +294 -290
- package/dist/bootstrapReactMobile.js.map +1 -1
- package/dist/src/Components/FormElements/ColorInput/ColorInput.d.ts +2 -1
- package/dist/src/Components/Layout/InlineBlock.d.ts +3 -1
- package/dist/src/Components/Menu/HoverMenu.d.ts +1 -1
- package/package.json +1 -1
- package/src/Components/FormElements/ColorInput/ColorInput.tsx +43 -40
- package/src/Components/FormElements/Select/Select.tsx +3 -3
- package/src/Components/Hooks/useKeyListener.ts +1 -1
- package/src/Components/Layout/InlineBlock.tsx +3 -1
- package/src/Components/Menu/HoverMenu.tsx +11 -4
|
@@ -11,7 +11,8 @@ export type ColorInputProps<OnChangeData> = {
|
|
|
11
11
|
disableAlpha?: boolean;
|
|
12
12
|
presetColors?: string[];
|
|
13
13
|
sharedColorKey?: string;
|
|
14
|
+
disabled?: boolean;
|
|
14
15
|
} & OptionalListener<'onChange', OnChangeData>;
|
|
15
|
-
declare function ColorInput<OnChangeData>({ defaultValue, value, label, onChangeColor, onChangeColorComplete, onOpen, onClose, disableAlpha, presetColors, sharedColorKey, ...otherProps }: ColorInputProps<OnChangeData>): React.JSX.Element;
|
|
16
|
+
declare function ColorInput<OnChangeData>({ defaultValue, value, label, onChangeColor, onChangeColorComplete, onOpen, onClose, disableAlpha, presetColors, sharedColorKey, disabled, ...otherProps }: ColorInputProps<OnChangeData>): React.JSX.Element;
|
|
16
17
|
declare const ColorInputMemo: typeof ColorInput;
|
|
17
18
|
export { ColorInputMemo as ColorInput };
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
/// <reference types="react" />
|
|
3
3
|
import { RbmComponentProps } from '../RbmComponentProps';
|
|
4
4
|
import { ViewWithoutListenersProps } from './ViewWithoutListeners';
|
|
5
|
-
export type InlineBlockProps<AsType extends keyof JSX.IntrinsicElements> = RbmComponentProps<ViewWithoutListenersProps<AsType
|
|
5
|
+
export type InlineBlockProps<AsType extends keyof JSX.IntrinsicElements> = RbmComponentProps<ViewWithoutListenersProps<AsType> & {
|
|
6
|
+
id?: string;
|
|
7
|
+
}>;
|
|
6
8
|
declare const InlineBlockMemo: import("../../helper/withForwardRef").RefComponent<InlineBlockProps<keyof JSX.IntrinsicElements>, SVGSymbolElement | SVGElement | HTMLObjectElement | HTMLElement | HTMLHtmlElement | SVGTextElement | HTMLTitleElement | HTMLLinkElement | HTMLAnchorElement | HTMLAreaElement | HTMLAudioElement | HTMLBaseElement | HTMLQuoteElement | HTMLBodyElement | HTMLBRElement | HTMLButtonElement | HTMLCanvasElement | HTMLTableColElement | HTMLDataElement | HTMLDataListElement | HTMLModElement | HTMLDetailsElement | HTMLDialogElement | HTMLDivElement | HTMLDListElement | HTMLEmbedElement | HTMLFieldSetElement | HTMLFormElement | HTMLHeadingElement | HTMLHeadElement | HTMLHRElement | HTMLIFrameElement | HTMLImageElement | HTMLInputElement | HTMLLabelElement | HTMLLegendElement | HTMLLIElement | HTMLMapElement | HTMLMetaElement | HTMLMeterElement | HTMLOListElement | HTMLOptGroupElement | HTMLOptionElement | HTMLOutputElement | HTMLParagraphElement | HTMLParamElement | HTMLPreElement | HTMLProgressElement | HTMLSlotElement | HTMLScriptElement | HTMLSelectElement | HTMLSourceElement | HTMLSpanElement | HTMLStyleElement | HTMLTableElement | HTMLTemplateElement | HTMLTableSectionElement | HTMLTableDataCellElement | HTMLTextAreaElement | HTMLTableHeaderCellElement | HTMLTimeElement | HTMLTableRowElement | HTMLTrackElement | HTMLUListElement | HTMLVideoElement | HTMLWebViewElement | SVGSVGElement | SVGCircleElement | SVGClipPathElement | SVGDefsElement | SVGDescElement | SVGEllipseElement | SVGFEBlendElement | SVGFEColorMatrixElement | SVGFEComponentTransferElement | SVGFECompositeElement | SVGFEConvolveMatrixElement | SVGFEDiffuseLightingElement | SVGFEDisplacementMapElement | SVGFEDistantLightElement | SVGFEDropShadowElement | SVGFEFloodElement | SVGFEFuncAElement | SVGFEFuncBElement | SVGFEFuncGElement | SVGFEFuncRElement | SVGFEGaussianBlurElement | SVGFEImageElement | SVGFEMergeElement | SVGFEMergeNodeElement | SVGFEMorphologyElement | SVGFEOffsetElement | SVGFEPointLightElement | SVGFESpecularLightingElement | SVGFESpotLightElement | SVGFETileElement | SVGFETurbulenceElement | SVGFilterElement | SVGForeignObjectElement | SVGGElement | SVGImageElement | SVGLineElement | SVGLinearGradientElement | SVGMarkerElement | SVGMaskElement | SVGMetadataElement | SVGPathElement | SVGPatternElement | SVGPolygonElement | SVGPolylineElement | SVGRadialGradientElement | SVGRectElement | SVGStopElement | SVGSwitchElement | SVGTextPathElement | SVGTSpanElement | SVGUseElement | SVGViewElement>;
|
|
7
9
|
export { InlineBlockMemo as InlineBlock };
|
|
@@ -3,7 +3,7 @@ import { RbmChildWithoutString, RbmComponentProps, WithNoStringAndChildrenProps
|
|
|
3
3
|
export type HoverMenuProps = RbmComponentProps<{
|
|
4
4
|
items: RbmChildWithoutString;
|
|
5
5
|
openToSide?: boolean;
|
|
6
|
-
onClick?: () => void;
|
|
6
|
+
onClick?: () => void | boolean;
|
|
7
7
|
onClose?: () => void;
|
|
8
8
|
}, WithNoStringAndChildrenProps>;
|
|
9
9
|
export declare const HoverMenu: ({ children, items, className, style, onClick, onClose, openToSide }: HoverMenuProps) => React.JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import {useCallback, useRef, useState, MouseEvent, useEffect, useLayoutEffect} from 'react';
|
|
3
|
+
import {Color, ColorChangeHandler, ColorResult, SketchPicker} from 'react-color';
|
|
4
|
+
import {OptionalListener, useListener} from '../../Hooks/useListener';
|
|
5
|
+
import {withMemo} from '../../../helper/withMemo';
|
|
6
6
|
|
|
7
7
|
import styles from './colorInput.scss';
|
|
8
|
-
import {
|
|
8
|
+
import {useSharedSelectedColor} from './sharedSelectedColor';
|
|
9
|
+
import {Menu} from "../../Menu/Menu";
|
|
9
10
|
|
|
10
11
|
export type ColorInputProps<OnChangeData> = {
|
|
11
12
|
defaultValue?: string;
|
|
@@ -18,6 +19,7 @@ export type ColorInputProps<OnChangeData> = {
|
|
|
18
19
|
disableAlpha?: boolean;
|
|
19
20
|
presetColors?: string[];
|
|
20
21
|
sharedColorKey?: string;
|
|
22
|
+
disabled?: boolean
|
|
21
23
|
} & OptionalListener<'onChange', OnChangeData>;
|
|
22
24
|
|
|
23
25
|
function convertToHex(color: { r: number; g: number; b: number; a?: number }, disableAlpha?: boolean) {
|
|
@@ -33,31 +35,32 @@ function convertToHex(color: { r: number; g: number; b: number; a?: number }, di
|
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
function ColorInput<OnChangeData>({
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
defaultValue,
|
|
39
|
+
value,
|
|
40
|
+
label,
|
|
41
|
+
onChangeColor,
|
|
42
|
+
onChangeColorComplete,
|
|
43
|
+
onOpen,
|
|
44
|
+
onClose,
|
|
45
|
+
disableAlpha,
|
|
46
|
+
presetColors,
|
|
47
|
+
sharedColorKey = "default",
|
|
48
|
+
disabled,
|
|
49
|
+
...otherProps
|
|
50
|
+
}: ColorInputProps<OnChangeData>) {
|
|
48
51
|
// Variables
|
|
49
52
|
// useStyles(styles);
|
|
50
53
|
|
|
51
54
|
// Refs
|
|
52
|
-
const containerRef = useRef<HTMLDivElement>(null);
|
|
53
55
|
const modalRef = useRef<HTMLDivElement>(null);
|
|
54
56
|
|
|
55
57
|
// States
|
|
56
58
|
const [color, setColor] = useState<string>(value ?? defaultValue ?? '#000000FF');
|
|
57
59
|
const [isOpen, setIsOpen] = useState(false);
|
|
58
|
-
const [position, setPosition] = useState({
|
|
60
|
+
const [position, setPosition] = useState({x: 0, y: 0});
|
|
59
61
|
|
|
60
|
-
const {
|
|
62
|
+
const {colors, addColor} = useSharedSelectedColor(sharedColorKey);
|
|
63
|
+
const realIsOpen = disabled !== true && isOpen;
|
|
61
64
|
|
|
62
65
|
const colVal: Color = value ?? color;
|
|
63
66
|
// Selectors
|
|
@@ -86,24 +89,26 @@ function ColorInput<OnChangeData>({
|
|
|
86
89
|
[disableAlpha, onChangeColorComplete]
|
|
87
90
|
);
|
|
88
91
|
|
|
89
|
-
const
|
|
90
|
-
(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
onClose?.(colVal);
|
|
95
|
-
}
|
|
92
|
+
const onMenuClose = useCallback(
|
|
93
|
+
() => {
|
|
94
|
+
setIsOpen(false);
|
|
95
|
+
addColor(colVal);
|
|
96
|
+
onClose?.(colVal);
|
|
96
97
|
},
|
|
97
98
|
[addColor, colVal, onClose]
|
|
98
99
|
);
|
|
99
100
|
|
|
100
101
|
const openElement = useCallback(
|
|
101
102
|
(e: MouseEvent) => {
|
|
103
|
+
if (disabled){
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
102
107
|
setIsOpen(true);
|
|
103
|
-
setPosition({
|
|
108
|
+
setPosition({x: e.clientX, y: e.clientY});
|
|
104
109
|
onOpen?.(colVal);
|
|
105
110
|
},
|
|
106
|
-
[colVal, onOpen]
|
|
111
|
+
[colVal, disabled, onOpen]
|
|
107
112
|
);
|
|
108
113
|
|
|
109
114
|
// Effects
|
|
@@ -114,10 +119,12 @@ function ColorInput<OnChangeData>({
|
|
|
114
119
|
const dimension = modalRef.current.getBoundingClientRect();
|
|
115
120
|
if (dimension.right > window.innerWidth || dimension.bottom > window.innerHeight) {
|
|
116
121
|
const newPosition = {
|
|
117
|
-
x: Math.max(0, Math.min(window.innerWidth - dimension.width, position.x)),
|
|
118
|
-
y: Math.max(0, Math.min(window.innerHeight - dimension.height, position.y)),
|
|
122
|
+
x: Math.max(0, Math.min(window.innerWidth - dimension.width - 3, position.x)),
|
|
123
|
+
y: Math.max(0, Math.min(window.innerHeight - dimension.height - 3, position.y)),
|
|
119
124
|
};
|
|
120
|
-
|
|
125
|
+
if (newPosition.x !== position.x || newPosition.y !== position.y) {
|
|
126
|
+
setPosition(newPosition);
|
|
127
|
+
}
|
|
121
128
|
}
|
|
122
129
|
}, [position]);
|
|
123
130
|
|
|
@@ -126,9 +133,7 @@ function ColorInput<OnChangeData>({
|
|
|
126
133
|
// Render Functions
|
|
127
134
|
return (
|
|
128
135
|
<span className={styles.colorInput}>
|
|
129
|
-
{isOpen
|
|
130
|
-
<div onClick={onContainerClick} className={styles.modalContainer} ref={containerRef}>
|
|
131
|
-
<div className={styles.modal} style={{ top: position.y, left: position.x }} ref={modalRef}>
|
|
136
|
+
<Menu x={position.x} y={position.y} isOpen={realIsOpen} onClose={onMenuClose}>
|
|
132
137
|
<SketchPicker
|
|
133
138
|
color={colVal}
|
|
134
139
|
onChange={onChange}
|
|
@@ -136,17 +141,15 @@ function ColorInput<OnChangeData>({
|
|
|
136
141
|
disableAlpha={disableAlpha}
|
|
137
142
|
presetColors={presetColors ?? colors}
|
|
138
143
|
/>
|
|
139
|
-
|
|
140
|
-
</div>
|
|
141
|
-
) : null}
|
|
144
|
+
</Menu>
|
|
142
145
|
<span onClick={openElement} className={styles.label}>
|
|
143
146
|
{label}
|
|
144
147
|
</span>
|
|
145
|
-
<span onClick={openElement} style={{
|
|
148
|
+
<span onClick={openElement} style={{backgroundColor: colVal}} className={styles.preview}/>
|
|
146
149
|
</span>
|
|
147
150
|
);
|
|
148
151
|
}
|
|
149
152
|
|
|
150
153
|
// Need ColorInputMemo for autocompletion of phpstorm
|
|
151
154
|
const ColorInputMemo = withMemo(ColorInput, styles);
|
|
152
|
-
export {
|
|
155
|
+
export {ColorInputMemo as ColorInput};
|
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { RbmComponentProps } from '../../RbmComponentProps';
|
|
3
3
|
import { Override } from '../../../TypeHelpers';
|
|
4
4
|
import { ChangeEventHandler, SelectHTMLAttributes, useCallback } from 'react';
|
|
5
|
-
import {
|
|
5
|
+
import {OptionalListener, useListener, useListenerWithExtractedProps} from '../../Hooks/useListener';
|
|
6
6
|
|
|
7
7
|
import styles from './select.scss';
|
|
8
8
|
import { withMemo } from '../../../helper/withMemo';
|
|
@@ -46,7 +46,7 @@ export const Select = withMemo(function Select<OnChangeData>({
|
|
|
46
46
|
// Selectors
|
|
47
47
|
|
|
48
48
|
// Callbacks
|
|
49
|
-
const onChangeWithData =
|
|
49
|
+
const [onChangeWithData, propsWithoutData] = useListenerWithExtractedProps<'onChange', OnChangeData>('onChange', otherProps);
|
|
50
50
|
const onChange = useCallback<ChangeEventHandler<HTMLSelectElement>>(
|
|
51
51
|
(e) => {
|
|
52
52
|
onChangeValue?.(e.target.value);
|
|
@@ -65,7 +65,7 @@ export const Select = withMemo(function Select<OnChangeData>({
|
|
|
65
65
|
// eslint-disable-next-line jsx-a11y/label-has-associated-control
|
|
66
66
|
<label className={classNames(styles.select, { [styles.inline]: inline, [styles.small]: small }, className)} style={style}>
|
|
67
67
|
{label ? <span className={styles.label}>{label}</span> : null}
|
|
68
|
-
<select {...
|
|
68
|
+
<select {...propsWithoutData} className={styles.input} onChange={onChange}>
|
|
69
69
|
{options.map((option) => (
|
|
70
70
|
<option value={option.value} key={option.key ?? option.value}>
|
|
71
71
|
{option.label}
|
|
@@ -39,7 +39,7 @@ export function useKeyUpListener(
|
|
|
39
39
|
useEffect(() => {
|
|
40
40
|
const lowercaseKey = key.toLowerCase();
|
|
41
41
|
const keyListener = (e: KeyboardEvent) => {
|
|
42
|
-
if (e.key.toLowerCase() === lowercaseKey && (!ignoreFormElements || !isFormElement(e.target))) {
|
|
42
|
+
if ((e.key === "Meta" || e.key.toLowerCase() === lowercaseKey) && (!ignoreFormElements || !isFormElement(e.target))) {
|
|
43
43
|
listener(e);
|
|
44
44
|
}
|
|
45
45
|
};
|
|
@@ -8,7 +8,9 @@ import { ComponentRef, ForwardedRef } from 'react';
|
|
|
8
8
|
import { withForwardRef } from '../../helper/withForwardRef';
|
|
9
9
|
|
|
10
10
|
export type InlineBlockProps<AsType extends keyof JSX.IntrinsicElements> = RbmComponentProps<
|
|
11
|
-
ViewWithoutListenersProps<AsType>
|
|
11
|
+
ViewWithoutListenersProps<AsType> & {
|
|
12
|
+
id?: string
|
|
13
|
+
}
|
|
12
14
|
>;
|
|
13
15
|
|
|
14
16
|
function InlineBlock<AsType extends keyof JSX.IntrinsicElements = 'span'>(
|
|
@@ -9,7 +9,7 @@ import {Menu} from "./Menu";
|
|
|
9
9
|
export type HoverMenuProps = RbmComponentProps<{
|
|
10
10
|
items: RbmChildWithoutString,
|
|
11
11
|
openToSide?: boolean;
|
|
12
|
-
onClick?: () => void;
|
|
12
|
+
onClick?: () => void | boolean;
|
|
13
13
|
onClose?: () => void;
|
|
14
14
|
}, WithNoStringAndChildrenProps>;
|
|
15
15
|
|
|
@@ -19,7 +19,7 @@ export const HoverMenu = withMemo(function HoverMenu({
|
|
|
19
19
|
className,
|
|
20
20
|
style,
|
|
21
21
|
onClick,
|
|
22
|
-
|
|
22
|
+
onClose,
|
|
23
23
|
openToSide
|
|
24
24
|
}: HoverMenuProps) {
|
|
25
25
|
// Refs
|
|
@@ -58,6 +58,12 @@ export const HoverMenu = withMemo(function HoverMenu({
|
|
|
58
58
|
setIsOpen(true);
|
|
59
59
|
}, [recalculatePosition]);
|
|
60
60
|
|
|
61
|
+
const onClickInner = useCallback(() => {
|
|
62
|
+
if (onClick?.() !== false) {
|
|
63
|
+
open();
|
|
64
|
+
}
|
|
65
|
+
}, [onClick, open]);
|
|
66
|
+
|
|
61
67
|
// Effects
|
|
62
68
|
|
|
63
69
|
// Other
|
|
@@ -68,14 +74,15 @@ export const HoverMenu = withMemo(function HoverMenu({
|
|
|
68
74
|
onMouseEnter={open}
|
|
69
75
|
onMouseLeave={close}
|
|
70
76
|
useReactOnMouseLeave={true}
|
|
71
|
-
onClick={
|
|
77
|
+
onClick={onClickInner}
|
|
72
78
|
className={classNames(styles.hoverMenu, {[styles.open]: isOpen}, className)}
|
|
73
79
|
style={style}
|
|
74
80
|
ref={hoverItemRef}
|
|
75
81
|
__allowChildren="all"
|
|
76
82
|
>
|
|
77
83
|
{children}
|
|
78
|
-
<Menu x={position.x} y={position.y} isOpen={true} onClose={close} offsetX={offset.x} offsetY={offset.y}
|
|
84
|
+
<Menu x={position.x} y={position.y} isOpen={true} onClose={close} offsetX={offset.x} offsetY={offset.y}
|
|
85
|
+
className={classNames({[styles.hidden]: !isOpen})}>
|
|
79
86
|
{items}
|
|
80
87
|
</Menu>
|
|
81
88
|
</Clickable>;
|