react-align 2.0.2 → 2.0.5
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/README.md +8 -18
- package/dist/GridArea.d.ts +3 -3
- package/dist/GridItem.d.ts +5 -6
- package/dist/GridSection.d.ts +2 -1
- package/dist/GridWrapper.d.ts +5 -4
- package/dist/Icon/index.d.ts +1 -3
- package/dist/context.d.ts +4 -4
- package/dist/react-align.cjs.development.js +37 -64
- package/dist/react-align.cjs.development.js.map +1 -1
- package/dist/react-align.cjs.production.min.js +1 -1
- package/dist/react-align.cjs.production.min.js.map +1 -1
- package/dist/react-align.esm.js +37 -64
- package/dist/react-align.esm.js.map +1 -1
- package/package.json +13 -13
- package/src/GridArea.tsx +6 -8
- package/src/GridItem.tsx +51 -52
- package/src/GridSection.tsx +3 -2
- package/src/GridWrapper.tsx +10 -9
- package/src/Icon/index.tsx +3 -30
- package/src/context.tsx +2 -2
- package/src/grid.css +4 -7
package/src/GridItem.tsx
CHANGED
|
@@ -18,11 +18,6 @@ export type ItemProps = {
|
|
|
18
18
|
extendable?: boolean;
|
|
19
19
|
extended?: boolean;
|
|
20
20
|
disabled?: boolean;
|
|
21
|
-
/** Extra customizable parts only for the really picky */
|
|
22
|
-
style?: CSSProperties;
|
|
23
|
-
editorStyle?: CSSProperties;
|
|
24
|
-
iconSize?: number;
|
|
25
|
-
iconColor?: string;
|
|
26
21
|
onExtend?: (extended: boolean) => void;
|
|
27
22
|
children?:
|
|
28
23
|
| ReactNode
|
|
@@ -36,6 +31,10 @@ export type ItemProps = {
|
|
|
36
31
|
disabled: boolean;
|
|
37
32
|
index: number;
|
|
38
33
|
}) => ReactNode);
|
|
34
|
+
/** Extra customizable parts only for the really picky */
|
|
35
|
+
style?: CSSProperties;
|
|
36
|
+
editorStyle?: CSSProperties;
|
|
37
|
+
iconColor?: string;
|
|
39
38
|
};
|
|
40
39
|
|
|
41
40
|
export default function GridItem({
|
|
@@ -46,33 +45,31 @@ export default function GridItem({
|
|
|
46
45
|
extendable = false,
|
|
47
46
|
extended = false,
|
|
48
47
|
disabled = false,
|
|
49
|
-
onExtend,
|
|
50
48
|
// Picky stuff.
|
|
51
49
|
style,
|
|
52
50
|
editorStyle,
|
|
53
|
-
iconSize,
|
|
54
51
|
iconColor = 'rgb(255, 255, 255)',
|
|
55
52
|
...props
|
|
56
53
|
}: ItemProps) {
|
|
57
|
-
const {
|
|
54
|
+
const { vertical } = props as {
|
|
58
55
|
end?: boolean;
|
|
59
56
|
vertical?: boolean;
|
|
60
57
|
};
|
|
61
|
-
const { editing, isDragging, onExtend
|
|
58
|
+
const { editing, isDragging, onExtend } = useAlignContext();
|
|
62
59
|
const [isHovered, setHovered] = useState(false);
|
|
63
60
|
const handleExtend = useCallback(() => {
|
|
64
61
|
if (!extendable) return;
|
|
65
62
|
setHovered(false);
|
|
66
|
-
onExtend?.(!extended);
|
|
67
|
-
|
|
68
|
-
}, [extendable, onExtend, extended, onExtend2, id]);
|
|
63
|
+
onExtend?.(id, !extended);
|
|
64
|
+
}, [extendable, onExtend, extended, id]);
|
|
69
65
|
|
|
70
66
|
const buttonStyles: CSSProperties = useMemo(
|
|
71
67
|
() => ({
|
|
72
|
-
alignItems:
|
|
73
|
-
float:
|
|
68
|
+
alignItems: 'start',
|
|
69
|
+
float: 'left',
|
|
70
|
+
color: iconColor,
|
|
74
71
|
}),
|
|
75
|
-
[
|
|
72
|
+
[iconColor]
|
|
76
73
|
);
|
|
77
74
|
|
|
78
75
|
const ctx = useMemo(
|
|
@@ -102,50 +99,52 @@ export default function GridItem({
|
|
|
102
99
|
...(editing ? editorStyle : style),
|
|
103
100
|
...provided.draggableProps.style,
|
|
104
101
|
}}
|
|
105
|
-
onMouseEnter={() => setHovered(true)}
|
|
106
|
-
onMouseLeave={() => setHovered(false)}
|
|
107
102
|
>
|
|
108
103
|
<div
|
|
109
104
|
style={{
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
display: 'inline-block',
|
|
106
|
+
position: 'relative',
|
|
107
|
+
minHeight: isHovered && !disabled ? '35px' : undefined,
|
|
108
|
+
width: !vertical && extended ? '100%' : undefined,
|
|
109
|
+
minWidth:
|
|
110
|
+
isHovered && !disabled
|
|
111
|
+
? extendable
|
|
112
|
+
? '70px'
|
|
113
|
+
: '35px'
|
|
114
|
+
: undefined,
|
|
115
|
+
height: vertical && extended ? '100%' : undefined,
|
|
113
116
|
}}
|
|
117
|
+
onMouseEnter={() => setHovered(true)}
|
|
118
|
+
onMouseLeave={() => setHovered(false)}
|
|
114
119
|
>
|
|
115
120
|
{typeof children === 'function' ? children(ctx) : children}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
<Icon
|
|
132
|
-
name="moveArrows"
|
|
133
|
-
size={iconSize}
|
|
134
|
-
style={{ color: iconColor }}
|
|
135
|
-
/>
|
|
136
|
-
</div>
|
|
137
|
-
{extendable && (
|
|
138
|
-
<div
|
|
139
|
-
style={{ cursor: 'pointer', marginLeft: '8px' }}
|
|
140
|
-
onClick={handleExtend}
|
|
141
|
-
>
|
|
142
|
-
<Icon
|
|
143
|
-
name={vertical ? 'verticalExtend' : 'horizontalExtend'}
|
|
144
|
-
size={iconSize}
|
|
145
|
-
style={{ color: iconColor }}
|
|
146
|
-
/>
|
|
121
|
+
<div
|
|
122
|
+
className="overlay"
|
|
123
|
+
style={{
|
|
124
|
+
display:
|
|
125
|
+
!disabled &&
|
|
126
|
+
editing &&
|
|
127
|
+
isHovered &&
|
|
128
|
+
(snapshot.isDragging || !isDragging)
|
|
129
|
+
? 'block'
|
|
130
|
+
: 'none',
|
|
131
|
+
}}
|
|
132
|
+
>
|
|
133
|
+
<div className="overlay-buttons" style={buttonStyles}>
|
|
134
|
+
<div {...provided.dragHandleProps}>
|
|
135
|
+
<Icon name="moveArrows" />
|
|
147
136
|
</div>
|
|
148
|
-
|
|
137
|
+
{extendable && (
|
|
138
|
+
<div
|
|
139
|
+
style={{ cursor: 'pointer', marginLeft: '8px' }}
|
|
140
|
+
onClick={handleExtend}
|
|
141
|
+
>
|
|
142
|
+
<Icon
|
|
143
|
+
name={vertical ? 'verticalExtend' : 'horizontalExtend'}
|
|
144
|
+
/>
|
|
145
|
+
</div>
|
|
146
|
+
)}
|
|
147
|
+
</div>
|
|
149
148
|
</div>
|
|
150
149
|
</div>
|
|
151
150
|
</div>
|
package/src/GridSection.tsx
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import React, { CSSProperties } from 'react';
|
|
1
|
+
import React, { CSSProperties, ReactNode } from 'react';
|
|
2
2
|
|
|
3
3
|
import { useAlignContext } from './context';
|
|
4
4
|
import './grid.css';
|
|
5
5
|
|
|
6
6
|
export type GridSectionProps = {
|
|
7
7
|
className?: string;
|
|
8
|
+
children?: ReactNode;
|
|
8
9
|
horizontal?: boolean;
|
|
9
10
|
stretch?: boolean;
|
|
10
11
|
fixedWidth?: number;
|
|
@@ -16,13 +17,13 @@ export type GridSectionProps = {
|
|
|
16
17
|
|
|
17
18
|
const GridSection: React.FC<GridSectionProps> = ({
|
|
18
19
|
className,
|
|
20
|
+
children,
|
|
19
21
|
horizontal,
|
|
20
22
|
stretch,
|
|
21
23
|
fixedWidth,
|
|
22
24
|
fixedHeight,
|
|
23
25
|
style,
|
|
24
26
|
editorStyle,
|
|
25
|
-
children,
|
|
26
27
|
}) => {
|
|
27
28
|
const { editing: enabled } = useAlignContext();
|
|
28
29
|
|
package/src/GridWrapper.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { CSSProperties, useCallback, useState } from 'react';
|
|
1
|
+
import React, { CSSProperties, ReactNode, useCallback, useState } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
DragDropContext,
|
|
4
4
|
DropResult,
|
|
@@ -11,6 +11,7 @@ import './grid.css';
|
|
|
11
11
|
|
|
12
12
|
export type GridWrapperProps = {
|
|
13
13
|
className?: string;
|
|
14
|
+
children?: ReactNode;
|
|
14
15
|
editing?: boolean;
|
|
15
16
|
vertical?: boolean;
|
|
16
17
|
stretch?: boolean;
|
|
@@ -19,25 +20,25 @@ export type GridWrapperProps = {
|
|
|
19
20
|
editorStyle?: CSSProperties;
|
|
20
21
|
onMove?: (
|
|
21
22
|
id: string,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
destAreaId: string,
|
|
24
|
+
destIndex: number,
|
|
25
|
+
prevAreaId: string,
|
|
26
|
+
prevIndex: number
|
|
26
27
|
) => void;
|
|
27
|
-
|
|
28
|
-
onExtend?: (
|
|
28
|
+
onAlignChange?: (areaId: string, align: Alignment) => void;
|
|
29
|
+
onExtend?: (id: string, extended: boolean) => void;
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
const GridWrapper: React.FC<GridWrapperProps> = ({
|
|
32
33
|
className,
|
|
34
|
+
children,
|
|
33
35
|
editing,
|
|
34
36
|
vertical,
|
|
35
37
|
stretch,
|
|
36
38
|
style,
|
|
37
39
|
editorStyle,
|
|
38
|
-
children,
|
|
39
40
|
onMove,
|
|
40
|
-
|
|
41
|
+
onAlignChange,
|
|
41
42
|
onExtend,
|
|
42
43
|
}) => {
|
|
43
44
|
const [isDragging, setDragging] = useState(false);
|
package/src/Icon/index.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import { css } from 'glamor';
|
|
1
|
+
import React from 'react';
|
|
3
2
|
|
|
4
3
|
import Icons from './icons';
|
|
5
4
|
|
|
@@ -8,38 +7,12 @@ export type Icons = keyof typeof Icons;
|
|
|
8
7
|
export type IconProps = {
|
|
9
8
|
className?: string;
|
|
10
9
|
name: string | Icons;
|
|
11
|
-
size?: number;
|
|
12
|
-
style?: CSSProperties;
|
|
13
10
|
onClick?: () => void;
|
|
14
11
|
};
|
|
15
12
|
|
|
16
|
-
const
|
|
17
|
-
css({
|
|
18
|
-
cursor: 'pointer',
|
|
19
|
-
width: size || 24 + 'px',
|
|
20
|
-
height: size || 24 + 'px',
|
|
21
|
-
' svg': {
|
|
22
|
-
height: size || 24 + 'px',
|
|
23
|
-
width: size || 24 + 'px',
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const Icon: React.FC<IconProps> = ({
|
|
28
|
-
className,
|
|
29
|
-
name,
|
|
30
|
-
size,
|
|
31
|
-
style,
|
|
32
|
-
onClick,
|
|
33
|
-
}) => {
|
|
13
|
+
const Icon: React.FC<IconProps> = ({ className, name, onClick }) => {
|
|
34
14
|
const LocalIconComponent = Icons[name as Icons];
|
|
35
|
-
return
|
|
36
|
-
<LocalIconComponent
|
|
37
|
-
className={className}
|
|
38
|
-
{...IconStyles(size)}
|
|
39
|
-
style={style}
|
|
40
|
-
onClick={onClick}
|
|
41
|
-
/>
|
|
42
|
-
);
|
|
15
|
+
return <LocalIconComponent className={className} onClick={onClick} />;
|
|
43
16
|
};
|
|
44
17
|
|
|
45
18
|
export default Icon;
|
package/src/context.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { Alignment } from '.';
|
|
|
4
4
|
export const Context = createContext<{
|
|
5
5
|
editing: boolean;
|
|
6
6
|
isDragging: boolean;
|
|
7
|
-
onAlignChange?: (
|
|
8
|
-
onExtend?: (
|
|
7
|
+
onAlignChange?: (areaId: string, align: Alignment) => void;
|
|
8
|
+
onExtend?: (id: string, extended: boolean) => void;
|
|
9
9
|
}>({ editing: false, isDragging: false });
|
|
10
10
|
export const useAlignContext = () => useContext(Context);
|
package/src/grid.css
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
.area {
|
|
15
15
|
display: flex;
|
|
16
|
-
border:
|
|
16
|
+
border: 0 solid transparent;
|
|
17
17
|
box-sizing: border-box;
|
|
18
18
|
border-radius: 8px;
|
|
19
19
|
position: relative;
|
|
@@ -29,12 +29,9 @@
|
|
|
29
29
|
|
|
30
30
|
.item {
|
|
31
31
|
position: relative;
|
|
32
|
-
border:
|
|
33
|
-
box-sizing: border-box;
|
|
32
|
+
border: 0 solid transparent;
|
|
34
33
|
margin: 6px;
|
|
35
34
|
border-radius: 6px;
|
|
36
|
-
min-width: 70px;
|
|
37
|
-
min-height: 40px;
|
|
38
35
|
}
|
|
39
36
|
|
|
40
37
|
.stretch {
|
|
@@ -66,8 +63,8 @@
|
|
|
66
63
|
position: absolute;
|
|
67
64
|
top: 0;
|
|
68
65
|
left: 0;
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
width: 100%;
|
|
67
|
+
height: 100%;
|
|
71
68
|
box-sizing: border-box;
|
|
72
69
|
background: rgba(0,0,0,0.6);
|
|
73
70
|
}
|