react-align 1.1.7 → 2.0.3
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 +30 -41
- package/dist/GridArea.d.ts +18 -0
- package/dist/GridItem.d.ts +27 -0
- package/dist/{Grid/GridSection/index.d.ts → GridSection.d.ts} +4 -3
- package/dist/GridWrapper.d.ts +17 -0
- package/dist/Icon/index.d.ts +1 -1
- package/dist/context.d.ts +11 -4
- package/dist/index.d.ts +5 -5
- package/dist/react-align.cjs.development.js +223 -317
- 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 +224 -318
- package/dist/react-align.esm.js.map +1 -1
- package/package.json +4 -9
- package/src/GridArea.tsx +152 -0
- package/src/GridItem.tsx +153 -0
- package/src/GridSection.tsx +53 -0
- package/src/GridWrapper.tsx +87 -0
- package/src/Icon/index.tsx +3 -3
- package/src/context.tsx +8 -4
- package/src/grid.css +80 -0
- package/src/index.tsx +5 -5
- package/dist/Grid/GridArea/index.d.ts +0 -18
- package/dist/Grid/GridItem/index.d.ts +0 -25
- package/dist/Grid/GridWrapper/index.d.ts +0 -12
- package/src/Grid/GridArea/index.tsx +0 -180
- package/src/Grid/GridItem/index.tsx +0 -266
- package/src/Grid/GridSection/index.tsx +0 -46
- package/src/Grid/GridWrapper/index.tsx +0 -39
- package/src/Grid/grid.css +0 -78
- package/src/Grid/interfaces.ts +0 -5
- package/src/stories/GridArea.stories.tsx +0 -28
package/README.md
CHANGED
|
@@ -7,65 +7,54 @@ A highly customizable and powerful drag 'n drop align system for React.
|
|
|
7
7
|
- Customizable features and styles to integrate into your app effectively
|
|
8
8
|
- Fully written in TypeScript
|
|
9
9
|
|
|
10
|
-
###
|
|
10
|
+
### Drag 'n drop
|
|
11
11
|
|
|
12
12
|
<img width="638" alt="Screen Shot 2021-06-24 at 18 19 33" src="https://user-images.githubusercontent.com/34051327/123242363-ed2ecd00-d51c-11eb-8f59-b7a74a39e942.png">
|
|
13
13
|
|
|
14
|
-
###
|
|
14
|
+
### Alignment
|
|
15
15
|
|
|
16
16
|
<img width="1278" alt="Screen Shot 2021-06-24 at 18 46 47" src="https://user-images.githubusercontent.com/34051327/123242051-9e813300-d51c-11eb-88e4-0620db121148.png">
|
|
17
17
|
|
|
18
|
+
### Getting started
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
npm install react-align
|
|
22
|
+
yarn add react-align
|
|
23
|
+
```
|
|
24
|
+
|
|
18
25
|
## Basic use
|
|
26
|
+
|
|
19
27
|
```tsx
|
|
20
|
-
<div style={{ width: "100vw", height: "100vh" }}>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
...your component
|
|
35
|
-
</GridItem>
|
|
36
|
-
</GridArea>
|
|
37
|
-
</GridSection>
|
|
38
|
-
</GridWrapper>
|
|
28
|
+
<div style={{ width: "100vw", height: "100vh" }}>
|
|
29
|
+
{/* element containing GridWrapper needs to set the width and height */}
|
|
30
|
+
<GridWrapper
|
|
31
|
+
onMove={(id: string, destAreaId: string, destIndex: number, prevAreaId: string, prevIndex: number) => { /* ... */ }}
|
|
32
|
+
onExtend={(id: string, extended: boolean) => { /* ... */ }}
|
|
33
|
+
onAlignmentChange={(areaId: string, alignment: Alignment) => { /* ... */ }>
|
|
34
|
+
<GridSection>
|
|
35
|
+
<GridArea id="area1">
|
|
36
|
+
<GridItem id="1234" index={1}>
|
|
37
|
+
...your component
|
|
38
|
+
</GridItem>
|
|
39
|
+
</GridArea>
|
|
40
|
+
</GridSection>
|
|
41
|
+
</GridWrapper>
|
|
39
42
|
</div>
|
|
40
43
|
```
|
|
41
|
-
All props used in the example above are **mandatory**.
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
All props used in the example above are **mandatory** for full functionality.
|
|
44
46
|
|
|
45
|
-
|
|
47
|
+
To make sure the drag 'n drop works correctly all GridArea ids **inside a GridWrapper** must be unique. The drag n drop will recognize the GridAreas based on your own desired naming convention that makes sense with your layout.
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
type onReorder: (
|
|
49
|
-
id?: string,
|
|
50
|
-
originalLocation?: { section: string, area: string },
|
|
51
|
-
currentIndex?: number,
|
|
52
|
-
hoverIndex?: number
|
|
53
|
-
) => void;
|
|
54
|
-
onMoveArea: (
|
|
55
|
-
currentItem?: string,
|
|
56
|
-
dropLocation?: { section: string, area: string},
|
|
57
|
-
originalLocation?: { section: string, area: string}
|
|
58
|
-
) => void;
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
Finally, the min/max for width and height is expected to set the GridItem container that will dynamically shrink when space is limited or if you choose to allow your GridItems to extend.
|
|
49
|
+
There are many other fields for each component, so please take a look at the source code to better customize react-align to your needs and look at the example for a simple example.
|
|
62
50
|
|
|
63
51
|
## Editor mode
|
|
64
|
-
|
|
52
|
+
|
|
53
|
+
Re:Align's editor mode is easily toggleable by passing an *editing* prop to the GridWrapper.
|
|
65
54
|
|
|
66
55
|
<img width="854" alt="Screen Shot 2021-06-24 at 18 15 51" src="https://user-images.githubusercontent.com/34051327/123240889-ad1b1a80-d51b-11eb-9a7d-8f9e75a9b9e0.png">
|
|
67
56
|
|
|
68
|
-
|
|
57
|
+
If you find any bugs or would like to suggest any changes feel free to open an issue!
|
|
69
58
|
|
|
70
59
|
Enjoy!
|
|
71
60
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CSSProperties, PropsWithChildren } from 'react';
|
|
2
|
+
import './grid.css';
|
|
3
|
+
export declare type Alignment = 'start' | 'centered' | 'end';
|
|
4
|
+
export declare type AreaProps = {
|
|
5
|
+
id: string;
|
|
6
|
+
className?: string;
|
|
7
|
+
vertical?: boolean;
|
|
8
|
+
stretch?: boolean;
|
|
9
|
+
end?: boolean;
|
|
10
|
+
align?: Alignment;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
/** Extra customizable parts only for the really picky */
|
|
13
|
+
style?: CSSProperties;
|
|
14
|
+
editorStyle?: CSSProperties;
|
|
15
|
+
iconColor?: string;
|
|
16
|
+
onAlignChange?: (alignment: Alignment) => void;
|
|
17
|
+
};
|
|
18
|
+
export default function GridArea({ id, className, vertical, stretch, end, disabled, align, onAlignChange, children, style, editorStyle, iconColor, }: PropsWithChildren<AreaProps>): JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CSSProperties, ReactNode } from 'react';
|
|
2
|
+
import './grid.css';
|
|
3
|
+
export declare type ItemProps = {
|
|
4
|
+
className?: string;
|
|
5
|
+
id: string;
|
|
6
|
+
index: number;
|
|
7
|
+
extendable?: boolean;
|
|
8
|
+
extended?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
onExtend?: (extended: boolean) => void;
|
|
11
|
+
children?: ReactNode | ((context: {
|
|
12
|
+
id: string;
|
|
13
|
+
editing: boolean;
|
|
14
|
+
isDragging: boolean;
|
|
15
|
+
isHovered: boolean;
|
|
16
|
+
extended: boolean;
|
|
17
|
+
extendable: boolean;
|
|
18
|
+
disabled: boolean;
|
|
19
|
+
index: number;
|
|
20
|
+
}) => ReactNode);
|
|
21
|
+
/** Extra customizable parts only for the really picky */
|
|
22
|
+
style?: CSSProperties;
|
|
23
|
+
editorStyle?: CSSProperties;
|
|
24
|
+
iconSize?: number;
|
|
25
|
+
iconColor?: string;
|
|
26
|
+
};
|
|
27
|
+
export default function GridItem({ className, children, id, index, extendable, extended, disabled, style, editorStyle, iconSize, iconColor, ...props }: ItemProps): JSX.Element;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import React, { CSSProperties } from 'react';
|
|
2
|
-
import '
|
|
2
|
+
import './grid.css';
|
|
3
3
|
export declare type GridSectionProps = {
|
|
4
4
|
className?: string;
|
|
5
5
|
horizontal?: boolean;
|
|
6
6
|
stretch?: boolean;
|
|
7
7
|
fixedWidth?: number;
|
|
8
8
|
fixedHeight?: number;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/** Extra customizable parts only for the really picky */
|
|
10
|
+
style?: CSSProperties;
|
|
11
|
+
editorStyle?: CSSProperties;
|
|
11
12
|
};
|
|
12
13
|
declare const GridSection: React.FC<GridSectionProps>;
|
|
13
14
|
export default GridSection;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React, { CSSProperties } from 'react';
|
|
2
|
+
import { Alignment } from './GridArea';
|
|
3
|
+
import './grid.css';
|
|
4
|
+
export declare type GridWrapperProps = {
|
|
5
|
+
className?: string;
|
|
6
|
+
editing?: boolean;
|
|
7
|
+
vertical?: boolean;
|
|
8
|
+
stretch?: boolean;
|
|
9
|
+
/** Extra customizable parts only for the really picky */
|
|
10
|
+
style?: CSSProperties;
|
|
11
|
+
editorStyle?: CSSProperties;
|
|
12
|
+
onMove?: (id: string, destAreaId: string, destIndex: number, prevAreaId: string, prevIndex: number) => void;
|
|
13
|
+
onAlignChange?: (areaId: string, align: Alignment) => void;
|
|
14
|
+
onExtend?: (id: string, extended: boolean) => void;
|
|
15
|
+
};
|
|
16
|
+
declare const GridWrapper: React.FC<GridWrapperProps>;
|
|
17
|
+
export default GridWrapper;
|
package/dist/Icon/index.d.ts
CHANGED
package/dist/context.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { Alignment } from '.';
|
|
3
|
+
export declare const Context: import("react").Context<{
|
|
4
|
+
editing: boolean;
|
|
5
|
+
isDragging: boolean;
|
|
6
|
+
onAlignChange?: ((areaId: string, align: Alignment) => void) | undefined;
|
|
7
|
+
onExtend?: ((id: string, extended: boolean) => void) | undefined;
|
|
4
8
|
}>;
|
|
5
|
-
export declare const
|
|
6
|
-
|
|
9
|
+
export declare const useAlignContext: () => {
|
|
10
|
+
editing: boolean;
|
|
11
|
+
isDragging: boolean;
|
|
12
|
+
onAlignChange?: ((areaId: string, align: Alignment) => void) | undefined;
|
|
13
|
+
onExtend?: ((id: string, extended: boolean) => void) | undefined;
|
|
7
14
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { default as GridWrapper } from "./
|
|
2
|
-
export { default as GridSection } from "./
|
|
3
|
-
export { default as GridArea } from "./
|
|
4
|
-
export { default as GridItem } from "./
|
|
1
|
+
export { default as GridWrapper } from "./GridWrapper";
|
|
2
|
+
export { default as GridSection } from "./GridSection";
|
|
3
|
+
export { default as GridArea } from "./GridArea";
|
|
4
|
+
export { default as GridItem } from "./GridItem";
|
|
5
5
|
export { default as Icon } from "./Icon";
|
|
6
|
-
export type { Alignment } from "./
|
|
6
|
+
export type { Alignment } from "./GridArea";
|