@ainias42/react-bootstrap-mobile 0.2.3 → 0.2.4
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/bootstrapReactMobile.ts +2 -0
- package/dist/bootstrapReactMobile.d.ts +2 -0
- package/dist/bootstrapReactMobile.js +143 -85
- package/dist/bootstrapReactMobile.js.map +1 -1
- package/dist/src/Components/FormElements/Controller/SwitchController.d.ts +3 -0
- package/dist/src/Components/Hooks/useDelayedState.d.ts +5 -0
- package/dist/src/Components/TopBar/TopBar.d.ts +2 -1
- package/package.json +2 -2
- package/src/Components/Clickable/Clickable.tsx +1 -1
- package/src/Components/Clickable/clickable.scss +5 -0
- package/src/Components/FormElements/Controller/SwitchController.ts +4 -0
- package/src/Components/FormElements/Controller/withHookController.tsx +1 -0
- package/src/Components/Hooks/useDelayedState.ts +18 -0
- package/src/Components/Layout/Flex.tsx +1 -0
- package/src/Components/Layout/Grid/grid.scss +9 -9
- package/src/Components/TopBar/TopBar.tsx +17 -13
- package/src/Components/TopBar/topBar.scss +2 -2
- package/src/scss/_colors.scss +4 -1
|
@@ -3,6 +3,7 @@ import { ComponentType } from 'react';
|
|
|
3
3
|
import { RbmComponentProps } from '../RbmComponentProps';
|
|
4
4
|
import { IconSource } from '../Icon/Icon';
|
|
5
5
|
export type TopBarActionButtonType = {
|
|
6
|
+
order?: number;
|
|
6
7
|
title: string;
|
|
7
8
|
icon?: IconSource;
|
|
8
9
|
action: () => void;
|
|
@@ -21,6 +22,6 @@ export type TopBarProps = RbmComponentProps<{
|
|
|
21
22
|
transparent?: boolean;
|
|
22
23
|
drawBehind?: boolean;
|
|
23
24
|
}>;
|
|
24
|
-
declare function TopBar({ title, rightButtons, leftButtons, hiddenButtons, className, transparent, drawBehind, ...rbmProps }: TopBarProps): React.JSX.Element;
|
|
25
|
+
declare function TopBar({ title, rightButtons: unsortedRightButtons, leftButtons: unsortedLeftButtons, hiddenButtons: unsortedHiddenButtons, className, transparent, drawBehind, ...rbmProps }: TopBarProps): React.JSX.Element;
|
|
25
26
|
declare const TopBarMemo: typeof TopBar;
|
|
26
27
|
export { TopBarMemo as TopBar };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainias42/react-bootstrap-mobile",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "Mobile React Components using Bootstrap",
|
|
5
5
|
"main": "dist/bootstrapReactMobile",
|
|
6
6
|
"scripts": {
|
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
"webpack-dev-server": "^5.0.4"
|
|
93
93
|
},
|
|
94
94
|
"dependencies": {
|
|
95
|
-
"@ainias42/js-helper": ">=0.8.
|
|
95
|
+
"@ainias42/js-helper": ">=0.8.16",
|
|
96
96
|
"@types/react-virtualized-auto-sizer": "^1.0.4",
|
|
97
97
|
"classnames": "^2.5.1",
|
|
98
98
|
"isomorphic-style-loader": "^5.3.2",
|
|
@@ -315,7 +315,7 @@ function Clickable<
|
|
|
315
315
|
};
|
|
316
316
|
if (typeof href === 'string') {
|
|
317
317
|
return (
|
|
318
|
-
<a {...props} href={href} ref={refSetter as ForwardedRef<HTMLAnchorElement>}>
|
|
318
|
+
<a {...props} className={classNames(styles.link, props.className)} href={href} ref={refSetter as ForwardedRef<HTMLAnchorElement>}>
|
|
319
319
|
{children}
|
|
320
320
|
</a>
|
|
321
321
|
);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { useCallback, useState } from "react";
|
|
2
|
+
import { useDelayed } from "./useDelayed";
|
|
3
|
+
|
|
4
|
+
export function useDelayedState<T>(initialState: T | (() => T), delay = 100, maxDelay: number | undefined = undefined) {
|
|
5
|
+
const [immediateState, setImmediateState] = useState(initialState);
|
|
6
|
+
const [state, setState] = useState(immediateState);
|
|
7
|
+
|
|
8
|
+
const setDelayedState = useDelayed((newState: (T)) => {
|
|
9
|
+
setState(newState);
|
|
10
|
+
}, [], delay, maxDelay);
|
|
11
|
+
|
|
12
|
+
const setValue = useCallback((newValue: (T)) => {
|
|
13
|
+
setImmediateState(newValue);
|
|
14
|
+
setDelayedState(newValue);
|
|
15
|
+
}, [setDelayedState]);
|
|
16
|
+
|
|
17
|
+
return {state, immediateState, setState: setValue};
|
|
18
|
+
}
|
|
@@ -18,7 +18,7 @@ $containerBreakpoints: $grid-breakpoints;
|
|
|
18
18
|
@mixin printClasses {
|
|
19
19
|
@media print {
|
|
20
20
|
@for $i from 1 through $columns {
|
|
21
|
-
.item-print-#{$i} {
|
|
21
|
+
> .item-print-#{$i} {
|
|
22
22
|
grid-column: auto / span $i;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -26,14 +26,14 @@ $containerBreakpoints: $grid-breakpoints;
|
|
|
26
26
|
// Start with `1` because `0` is and invalid value.
|
|
27
27
|
// Ends with `$columns - 1` because offsetting by the width of an entire row isn't possible.
|
|
28
28
|
@for $i from 1 through ($columns - 1) {
|
|
29
|
-
.start-print-#{$i} {
|
|
29
|
+
> .start-print-#{$i} {
|
|
30
30
|
grid-column-start: $i;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// Add classes for reordering
|
|
35
35
|
@for $i from -10 through 10 {
|
|
36
|
-
.order-print-#{$i} {
|
|
36
|
+
> .order-print-#{$i} {
|
|
37
37
|
order: $i;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
@@ -42,7 +42,7 @@ $containerBreakpoints: $grid-breakpoints;
|
|
|
42
42
|
|
|
43
43
|
@mixin contentMin($breakpointName) {
|
|
44
44
|
@for $i from 1 through $columns {
|
|
45
|
-
.item-#{$breakpointName}-#{$i} {
|
|
45
|
+
> .item-#{$breakpointName}-#{$i} {
|
|
46
46
|
grid-column: auto / span $i;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
@@ -50,7 +50,7 @@ $containerBreakpoints: $grid-breakpoints;
|
|
|
50
50
|
// Start with `1` because `0` is and invalid value.
|
|
51
51
|
// Ends with `$columns - 1` because offsetting by the width of an entire row isn't possible.
|
|
52
52
|
@for $i from 1 through ($columns - 1) {
|
|
53
|
-
.start-#{$breakpointName}-#{$i} {
|
|
53
|
+
> .start-#{$breakpointName}-#{$i} {
|
|
54
54
|
grid-column-start: $i;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -58,7 +58,7 @@ $containerBreakpoints: $grid-breakpoints;
|
|
|
58
58
|
|
|
59
59
|
@mixin contentOnly($breakpointName) {
|
|
60
60
|
@for $i from -10 through 10 {
|
|
61
|
-
.order-#{$breakpointName}-#{$i} {
|
|
61
|
+
> .order-#{$breakpointName}-#{$i} {
|
|
62
62
|
order: $i;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -110,7 +110,7 @@ $containerBreakpoints: $grid-breakpoints;
|
|
|
110
110
|
@each $breakpoint in map-keys($breakpoints) {
|
|
111
111
|
@include media-breakpoint-up($breakpoint, $breakpoints) {
|
|
112
112
|
@for $i from 1 through $columns {
|
|
113
|
-
.item-#{$breakpoint}-#{$i} {
|
|
113
|
+
> .item-#{$breakpoint}-#{$i} {
|
|
114
114
|
grid-column: auto / span $i;
|
|
115
115
|
}
|
|
116
116
|
}
|
|
@@ -118,7 +118,7 @@ $containerBreakpoints: $grid-breakpoints;
|
|
|
118
118
|
// Start with `1` because `0` is and invalid value.
|
|
119
119
|
// Ends with `$columns - 1` because offsetting by the width of an entire row isn't possible.
|
|
120
120
|
@for $i from 1 through ($columns - 1) {
|
|
121
|
-
.start-#{$breakpoint}-#{$i} {
|
|
121
|
+
> .start-#{$breakpoint}-#{$i} {
|
|
122
122
|
grid-column-start: $i;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
@@ -127,7 +127,7 @@ $containerBreakpoints: $grid-breakpoints;
|
|
|
127
127
|
// Add classes for reordering
|
|
128
128
|
@include media-breakpoint-only($breakpoint, $breakpoints) {
|
|
129
129
|
@for $i from -10 through 10 {
|
|
130
|
-
.order-#{$breakpoint}-#{$i} {
|
|
130
|
+
> .order-#{$breakpoint}-#{$i} {
|
|
131
131
|
order: $i;
|
|
132
132
|
}
|
|
133
133
|
}
|
|
@@ -18,6 +18,7 @@ import { Inline } from '../Layout/Inline';
|
|
|
18
18
|
import { View } from '../Layout/View';
|
|
19
19
|
|
|
20
20
|
export type TopBarActionButtonType = {
|
|
21
|
+
order?: number;
|
|
21
22
|
title: string;
|
|
22
23
|
icon?: IconSource;
|
|
23
24
|
action: () => void;
|
|
@@ -45,11 +46,11 @@ function getButtonComponents(buttons: TopBarButtonType[]) {
|
|
|
45
46
|
const key = button.key ?? String(index);
|
|
46
47
|
if ('component' in button) {
|
|
47
48
|
const Component = button.component;
|
|
48
|
-
return <Component {...button} key={key} onClick={button.action}
|
|
49
|
+
return <Component {...button} key={key} onClick={button.action}/>;
|
|
49
50
|
}
|
|
50
51
|
let child: string | ReactElement | undefined = button.title;
|
|
51
52
|
if (button.icon) {
|
|
52
|
-
child = <Icon icon={button.icon}
|
|
53
|
+
child = <Icon icon={button.icon}/>;
|
|
53
54
|
}
|
|
54
55
|
return (
|
|
55
56
|
<TopBarButton key={key} onClick={button.action} disabled={button.disabled} __allowChildren="all">
|
|
@@ -60,15 +61,15 @@ function getButtonComponents(buttons: TopBarButtonType[]) {
|
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
function TopBar({
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}: TopBarProps) {
|
|
64
|
+
title = '',
|
|
65
|
+
rightButtons: unsortedRightButtons = [],
|
|
66
|
+
leftButtons: unsortedLeftButtons = [],
|
|
67
|
+
hiddenButtons: unsortedHiddenButtons = [],
|
|
68
|
+
className,
|
|
69
|
+
transparent = false,
|
|
70
|
+
drawBehind = false,
|
|
71
|
+
...rbmProps
|
|
72
|
+
}: TopBarProps) {
|
|
72
73
|
const [isHiddenMenuOpen, setIsHiddenMenuOpen] = useState(false);
|
|
73
74
|
|
|
74
75
|
if (isHiddenMenuOpen) {
|
|
@@ -76,6 +77,9 @@ function TopBar({
|
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
const actionSheetRef = useRef<React.ElementRef<typeof ActionSheet>>(null);
|
|
80
|
+
let rightButtons = useMemo(() => unsortedRightButtons.sort((a, b) => (a.order ?? 0) - (b.order ?? 0)), [unsortedRightButtons]);
|
|
81
|
+
const leftButtons = useMemo(() => unsortedLeftButtons.sort((a, b) => (a.order ?? 0) - (b.order ?? 0)), [unsortedLeftButtons]);
|
|
82
|
+
let hiddenButtons = useMemo(() => unsortedHiddenButtons.sort((a, b) => (a.order ?? 0) - (b.order ?? 0)), [unsortedHiddenButtons]);
|
|
79
83
|
|
|
80
84
|
const toggleHiddenMenu = useCallback(() => {
|
|
81
85
|
setIsHiddenMenuOpen((isOpen) => {
|
|
@@ -121,7 +125,7 @@ function TopBar({
|
|
|
121
125
|
|
|
122
126
|
const rightButtonComponents = getButtonComponents(rightButtons);
|
|
123
127
|
const leftButtonComponents = getButtonComponents(leftButtons);
|
|
124
|
-
const hiddenButtonComponents = getButtonComponents(hiddenButtons.map(({
|
|
128
|
+
const hiddenButtonComponents = getButtonComponents(hiddenButtons.map(({icon: _, ...button}) => button));
|
|
125
129
|
|
|
126
130
|
const actions: ActionSheetAction<any>[] = useMemo(
|
|
127
131
|
() =>
|
|
@@ -157,7 +161,7 @@ function TopBar({
|
|
|
157
161
|
</Flex>
|
|
158
162
|
{hiddenButtons.length > 0 && isHiddenMenuOpen ? (
|
|
159
163
|
<Inline className={styles.hiddenContainer}>
|
|
160
|
-
<View aria-hidden={true} className={styles.hiddenCloseCurtain} onClick={toggleHiddenMenu}
|
|
164
|
+
<View aria-hidden={true} className={styles.hiddenCloseCurtain} onClick={toggleHiddenMenu}/>
|
|
161
165
|
<View className={styles.hiddenMenu}>{hiddenButtonComponents}</View>
|
|
162
166
|
</Inline>
|
|
163
167
|
) : null}
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
|
|
31
31
|
display: block;
|
|
32
32
|
padding: 0.5rem 1rem;
|
|
33
|
-
color: #0d3efd;
|
|
33
|
+
color: var(--top-bar-button, #0d3efd);
|
|
34
34
|
text-decoration: none;
|
|
35
35
|
transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out;
|
|
36
36
|
|
|
37
37
|
&.disabled {
|
|
38
|
-
color: #6c757d;
|
|
38
|
+
color: var(--top-bar-button-disabled, #6c757d);
|
|
39
39
|
pointer-events: none;
|
|
40
40
|
cursor: default;
|
|
41
41
|
}
|
package/src/scss/_colors.scss
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
3
2
|
:root {
|
|
4
3
|
--flavor-basic: #000000;
|
|
5
4
|
--flavor-constructive: #15803D;
|
|
@@ -12,6 +11,10 @@
|
|
|
12
11
|
|
|
13
12
|
--text-error: var(--flavor-destructive);
|
|
14
13
|
|
|
14
|
+
--top-bar-button: #0d3efd;
|
|
15
|
+
--top-bar-button-disabled: #6c757d;
|
|
16
|
+
|
|
17
|
+
--link-color: #0d6efd;
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
.#{$material} {
|