Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RTL Support #96

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
width: 20px;
height: 20px;
bottom: 0;
right: 0;
background: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2IDYiIHN0eWxlPSJiYWNrZ3JvdW5kLWNvbG9yOiNmZmZmZmYwMCIgeD0iMHB4IiB5PSIwcHgiIHdpZHRoPSI2cHgiIGhlaWdodD0iNnB4Ij48ZyBvcGFjaXR5PSIwLjMwMiI+PHBhdGggZD0iTSA2IDYgTCAwIDYgTCAwIDQuMiBMIDQgNC4yIEwgNC4yIDQuMiBMIDQuMiAwIEwgNiAwIEwgNiA2IEwgNiA2IFoiIGZpbGw9IiMwMDAwMDAiLz48L2c+PC9zdmc+');
background-position: bottom right;
padding: 0 3px 3px 0;
background-repeat: no-repeat;
background-origin: content-box;
box-sizing: border-box;
}
.react-resizable-handle.ltr{
background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2IDYiIHN0eWxlPSJiYWNrZ3JvdW5kLWNvbG9yOiNmZmZmZmYwMCIgeD0iMHB4IiB5PSIwcHgiIHdpZHRoPSI2cHgiIGhlaWdodD0iNnB4Ij48ZyBvcGFjaXR5PSIwLjMwMiI+PHBhdGggZD0iTSA2IDYgTCAwIDYgTCAwIDQuMiBMIDQgNC4yIEwgNC4yIDQuMiBMIDQuMiAwIEwgNiAwIEwgNiA2IEwgNiA2IFoiIGZpbGw9IiMwMDAwMDAiLz48L2c+PC9zdmc+');
background-position: bottom right;
cursor: se-resize;
right: 0;
}
.react-resizable-handle.rtl{
background-image: url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNiIgaGVpZ2h0PSI2IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPiA8Zz4gIDx0aXRsZT5iYWNrZ3JvdW5kPC90aXRsZT4gIDxyZWN0IGZpbGw9Im5vbmUiIGlkPSJjYW52YXNfYmFja2dyb3VuZCIgaGVpZ2h0PSI0MDIiIHdpZHRoPSI1ODIiIHk9Ii0xIiB4PSItMSIvPiA8L2c+IDxnPiAgPHRpdGxlPkxheWVyIDE8L3RpdGxlPiAgPGcgaWQ9InN2Z18xIiBvcGFjaXR5PSIwLjMwMiI+ICAgPHBhdGggdHJhbnNmb3JtPSJyb3RhdGUoODkuOTM3MDcyNzUzOTA2MjUgMywzKSAiIGlkPSJzdmdfMiIgZmlsbD0iIzAwMDAwMCIgZD0ibTYsNmwtNiwwbDAsLTEuOGw0LDBsMC4yLDBsMCwtNC4ybDEuOCwwbDAsNmwwLDB6Ii8+ICA8L2c+IDwvZz48L3N2Zz4=');
background-position: bottom left;
cursor: sw-resize;
left: 0;
}
21 changes: 15 additions & 6 deletions lib/Resizable.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type DragCallbackData = {
deltaX: number, deltaY: number,
lastX: number, lastY: number
};
type Direction = 'ltr' | 'rtl';
export type ResizeCallbackData = {
node: HTMLElement,
size: {width: number, height: number}
Expand All @@ -34,7 +35,8 @@ export type Props = {
onResizeStop?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
onResizeStart?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
onResize?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
draggableOpts?: ?Object
draggableOpts?: ?Object,
direction?: ?Direction
};

export default class Resizable extends React.Component<Props, State> {
Expand Down Expand Up @@ -77,15 +79,19 @@ export default class Resizable extends React.Component<Props, State> {
onResize: PropTypes.func,

// These will be passed wholesale to react-draggable's DraggableCore
draggableOpts: PropTypes.object
draggableOpts: PropTypes.object,

// To support RTL resizing
direction: PropTypes.String,
};

static defaultProps = {
handleSize: [20, 20],
lockAspectRatio: false,
axis: 'both',
minConstraints: [20, 20],
maxConstraints: [Infinity, Infinity]
maxConstraints: [Infinity, Infinity],
direction: 'ltr',
};

state: State = {
Expand Down Expand Up @@ -165,7 +171,10 @@ export default class Resizable extends React.Component<Props, State> {
const canDragY = this.props.axis === 'both' || this.props.axis === 'y';

// Update w/h
let width = this.state.width + (canDragX ? deltaX : 0);
let width = this.props.direction === 'ltr'
? this.state.width + (canDragX ? deltaX : 0)
: this.state.width - (canDragX ? deltaX : 0);

let height = this.state.height + (canDragY ? deltaY : 0);

// Early return if no change
Expand Down Expand Up @@ -202,7 +211,7 @@ export default class Resizable extends React.Component<Props, State> {
// eslint-disable-next-line no-unused-vars
const {children, draggableOpts, width, height, handleSize,
lockAspectRatio, axis, minConstraints, maxConstraints, onResize,
onResizeStop, onResizeStart, ...p} = this.props;
onResizeStop, onResizeStart, direction, ...p} = this.props;

const className = p.className ?
`${p.className} react-resizable`:
Expand All @@ -224,7 +233,7 @@ export default class Resizable extends React.Component<Props, State> {
onStart={this.resizeHandler('onResizeStart')}
onDrag={this.resizeHandler('onResize')}
>
<span className="react-resizable-handle" />
<span className={`react-resizable-handle ${direction}`} />
</DraggableCore>
]
});
Expand Down