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/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 { end, vertical } = props as {
54
+ const { vertical } = props as {
58
55
  end?: boolean;
59
56
  vertical?: boolean;
60
57
  };
61
- const { editing, isDragging, onExtend: onExtend2 } = useAlignContext();
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
- onExtend2?.(id, !extended);
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: end ? 'end' : 'start',
73
- float: end ? 'right' : 'left',
68
+ alignItems: 'start',
69
+ float: 'left',
70
+ color: iconColor,
74
71
  }),
75
- [end]
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
- width: '100%',
111
- height: '100%',
112
- pointerEvents: editing ? 'none' : undefined,
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
- </div>
117
- <div
118
- className="overlay"
119
- style={{
120
- display:
121
- !disabled &&
122
- editing &&
123
- isHovered &&
124
- (snapshot.isDragging || !isDragging)
125
- ? 'block'
126
- : 'none',
127
- }}
128
- >
129
- <div className="overlay-buttons" style={buttonStyles}>
130
- <div {...provided.dragHandleProps}>
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>
@@ -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
 
@@ -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
- destLocation: string,
23
- destIndedx: number,
24
- originalLocation: string,
25
- originalIndex: number
23
+ destAreaId: string,
24
+ destIndex: number,
25
+ prevAreaId: string,
26
+ prevIndex: number
26
27
  ) => void;
27
- onAlignmentChange?: (location: string, align: Alignment) => void;
28
- onExtend?: (location: string, extended: boolean) => void;
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
- onAlignmentChange: onAlignChange,
41
+ onAlignChange,
41
42
  onExtend,
42
43
  }) => {
43
44
  const [isDragging, setDragging] = useState(false);
@@ -1,5 +1,4 @@
1
- import React, { CSSProperties } from '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 IconStyles = (size?: number) =>
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?: (location: string, align: Alignment) => void;
8
- onExtend?: (location: string, extended: boolean) => void;
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: 1px solid transparent;
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: 1px solid transparent;
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
- bottom: 0;
70
- right: 0;
66
+ width: 100%;
67
+ height: 100%;
71
68
  box-sizing: border-box;
72
69
  background: rgba(0,0,0,0.6);
73
70
  }