react-align 1.1.6 → 2.0.2
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 +33 -34
- 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 +225 -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 +226 -318
- package/dist/react-align.esm.js.map +1 -1
- package/package.json +7 -12
- package/src/GridArea.tsx +152 -0
- package/src/GridItem.tsx +155 -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,61 +7,60 @@ 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, index: number, prevAreaId: string, prevIndex: number) => { /* ... */ }}
|
|
32
|
+
onExtend={(id: string, extebded: boolean) => { /* ... */ }}
|
|
33
|
+
onAlignmentChange={(areaId: string, alignment: Alignment) => { /* ... */ }>
|
|
34
|
+
<GridSection>
|
|
35
|
+
<GridArea location="location1">
|
|
36
|
+
<GridItem id="1234" index={1}>
|
|
37
|
+
...your component
|
|
38
|
+
</GridItem>
|
|
39
|
+
</GridArea>
|
|
40
|
+
</GridSection>
|
|
41
|
+
</GridWrapper>
|
|
39
42
|
</div>
|
|
40
43
|
```
|
|
41
|
-
|
|
44
|
+
|
|
45
|
+
All props used in the example above are **mandatory**.
|
|
42
46
|
|
|
43
47
|
Location is based on a section/area combo that allows for unique grid layouts. The drag n drop will recognize the GridAreas based on your own desired naming convention that makes sense with your layout.
|
|
44
48
|
|
|
45
49
|
GridItem's id, index, onReorder and onMoveArea are necessary for the drag n drop as well. The id and index are presumed to be needed in your onMoveArea and OnReorder callback functions, respectively, as a way to manipulate your unique data. Types necessary for the callbacks are:
|
|
46
50
|
|
|
47
51
|
```tsx
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
) => void;
|
|
54
|
-
onMoveArea: (
|
|
55
|
-
currentItem?: string,
|
|
56
|
-
dropLocation?: { section: string, area: string},
|
|
57
|
-
originalLocation?: { section: string, area: string}
|
|
58
|
-
) => void;
|
|
52
|
+
type Props = {
|
|
53
|
+
onMove: (id: string, destAreaId: string, index: number, prevAreaId: string, prevIndex: number) => { /* ... */ }
|
|
54
|
+
onExtend: (id: string, extebded: boolean) => { /* ... */ }
|
|
55
|
+
onAlignmentChange: (areaId: string, alignment: Alignment) => { /* ... */ }
|
|
56
|
+
};
|
|
59
57
|
```
|
|
60
58
|
|
|
61
59
|
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.
|
|
62
60
|
|
|
63
61
|
## Editor mode
|
|
64
|
-
|
|
62
|
+
|
|
63
|
+
Re:Align's editor mode is easily toggleable by passing an *enabled* prop to the GridWrapper.
|
|
65
64
|
|
|
66
65
|
<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
66
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CSSProperties, PropsWithChildren } from 'react';
|
|
2
|
+
import './grid.css';
|
|
3
|
+
export declare type Alignment = 'start' | 'end' | 'centered';
|
|
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
|
+
onAlignmentChange?: (alignment: Alignment) => void;
|
|
17
|
+
};
|
|
18
|
+
export default function GridArea({ id, className, vertical, stretch, end, disabled, align, onAlignmentChange, 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
|
+
/** Extra customizable parts only for the really picky */
|
|
11
|
+
style?: CSSProperties;
|
|
12
|
+
editorStyle?: CSSProperties;
|
|
13
|
+
iconSize?: number;
|
|
14
|
+
iconColor?: string;
|
|
15
|
+
onExtend?: (extended: boolean) => void;
|
|
16
|
+
children?: ReactNode | ((context: {
|
|
17
|
+
id: string;
|
|
18
|
+
editing: boolean;
|
|
19
|
+
isDragging: boolean;
|
|
20
|
+
isHovered: boolean;
|
|
21
|
+
extended: boolean;
|
|
22
|
+
extendable: boolean;
|
|
23
|
+
disabled: boolean;
|
|
24
|
+
index: number;
|
|
25
|
+
}) => ReactNode);
|
|
26
|
+
};
|
|
27
|
+
export default function GridItem({ className, children, id, index, extendable, extended, disabled, onExtend, 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, destLocation: string, destIndedx: number, originalLocation: string, originalIndex: number) => void;
|
|
13
|
+
onAlignmentChange?: (location: string, align: Alignment) => void;
|
|
14
|
+
onExtend?: (location: 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?: ((location: string, align: Alignment) => void) | undefined;
|
|
7
|
+
onExtend?: ((location: 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?: ((location: string, align: Alignment) => void) | undefined;
|
|
13
|
+
onExtend?: ((location: 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";
|