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 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
- ### **Drag 'n drop**
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
- ### **Alignment**
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
- // element containing GridWrapper needs to set the width and height
22
- <GridWrapper>
23
- <GridSection>
24
- <GridArea location={{ section: "left", area: "top" }}>
25
- <GridItem
26
- id="1234"
27
- index={1}
28
- minH={100}
29
- maxH={150}
30
- minW={100}
31
- maxW={150}
32
- onReorder={YourReorderCallbackFunction}
33
- onMoveArea={YourMoveAreaCallback}>
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
- 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.
45
+ All props used in the example above are **mandatory** for full functionality.
44
46
 
45
- 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:
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
- ```tsx
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
- Re:Align's editor mode is easily toggleable by passing an *enabled* prop to the GridWrapper.
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
- (If you want to use your own method and/or avoid style changes between editor mode and non-editor mode, pass *draggable* into GridItem and *droppable* into GridArea to enable drag 'n drop functionality directly)
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 '../grid.css';
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
- styles?: CSSProperties;
10
- editorStyles?: CSSProperties;
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;
@@ -5,8 +5,8 @@ export declare type IconProps = {
5
5
  className?: string;
6
6
  name: string | Icons;
7
7
  size?: number;
8
+ style?: CSSProperties;
8
9
  onClick?: () => void;
9
- styles?: CSSProperties;
10
10
  };
11
11
  declare const Icon: React.FC<IconProps>;
12
12
  export default Icon;
package/dist/context.d.ts CHANGED
@@ -1,7 +1,14 @@
1
1
  /// <reference types="react" />
2
- export declare const EditorModeContext: import("react").Context<{
3
- enabled: boolean | undefined;
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 useEditorMode: () => {
6
- enabled: boolean | undefined;
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 "./Grid/GridWrapper";
2
- export { default as GridSection } from "./Grid/GridSection";
3
- export { default as GridArea } from "./Grid/GridArea";
4
- export { default as GridItem } from "./Grid/GridItem";
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 "./Grid/GridArea";
6
+ export type { Alignment } from "./GridArea";