Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: react-component/align
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.0.7
Choose a base ref
...
head repository: react-component/align
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.0.8
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Sep 24, 2020

  1. fix: Align should support svg

    zombieJ committed Sep 24, 2020
    Copy the full SHA
    a785b98 View commit details
  2. 4.0.8

    zombieJ committed Sep 24, 2020
    Copy the full SHA
    4c6b10b View commit details
Showing with 41 additions and 23 deletions.
  1. +37 −20 examples/follow.js
  2. +2 −2 package.json
  3. +2 −1 src/Align.tsx
57 changes: 37 additions & 20 deletions examples/follow.js
Original file line number Diff line number Diff line change
@@ -7,6 +7,16 @@ const Demo = () => {
const [left, setLeft] = React.useState(100);
const [top, setTop] = React.useState(100);
const [visible, setVisible] = React.useState(true);
const [svg, setSvg] = React.useState(false);

const sharedStyle: React.CSSProperties = {
width,
height,
position: 'absolute',
left,
top,
display: visible ? 'flex' : 'none',
};

return (
<div>
@@ -29,6 +39,14 @@ const Demo = () => {
>
Trigger Visible
</button>
<button
type="button"
onClick={() => {
setSvg(!svg);
}}
>
Follow SVG ({String(svg)})
</button>

<div
style={{
@@ -38,27 +56,26 @@ const Demo = () => {
position: 'relative',
}}
>
<div
style={{
width,
height,
border: '1px solid green',
alignItems: 'center',
justifyContent: 'center',
position: 'absolute',
left,
top,
display: visible ? 'flex' : 'none',
}}
id="content"
>
Content
</div>
{svg ? (
<svg id="content" width={width} height={height} style={sharedStyle}>
<rect x="0" y="0" width={width} height={height} />
</svg>
) : (
<div
style={{
border: '1px solid green',
boxSizing: 'border-box',
alignItems: 'center',
justifyContent: 'center',
...sharedStyle,
}}
id="content"
>
Content
</div>
)}

<Align
target={() => document.getElementById('content')}
align={{ points: ['tc', 'bc'] }}
>
<Align target={() => document.getElementById('content')} align={{ points: ['tc', 'bc'] }}>
<div
style={{
border: '1px solid blue',
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rc-align",
"version": "4.0.7",
"version": "4.0.8",
"description": "align ui component for react",
"keywords": [
"react",
@@ -42,7 +42,7 @@
"@babel/runtime": "^7.10.1",
"classnames": "2.x",
"dom-align": "^1.7.0",
"rc-util": "^5.0.1",
"rc-util": "^5.3.0",
"resize-observer-polyfill": "^1.5.1"
},
"devDependencies": {
3 changes: 2 additions & 1 deletion src/Align.tsx
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@

import React from 'react';
import { composeRef } from 'rc-util/lib/ref';
import isVisible from 'rc-util/lib/Dom/isVisible';
import { alignElement, alignPoint } from 'dom-align';
import addEventListener from 'rc-util/lib/Dom/addEventListener';

@@ -79,7 +80,7 @@ const Align: React.RefForwardingComponent<RefAlign, AlignProps> = (
const { activeElement } = document;

// We only align when element is visible
if (element && element.offsetParent) {
if (element && isVisible(element)) {
result = alignElement(source, element, align);
} else if (point) {
result = alignPoint(source, point, align);