-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[7.x] Convert Positionable, RenderToDom and RenderWithFn to functiona…
…l/hooks/no recompose. (#68202) (#69866) Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
bc2e63f
commit 8665d57
Showing
18 changed files
with
331 additions
and
390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 0 additions & 60 deletions
60
x-pack/plugins/canvas/public/components/element_wrapper/lib/handlers.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
x-pack/plugins/canvas/public/components/positionable/positionable.js
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
x-pack/plugins/canvas/public/components/positionable/positionable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { FC, ReactElement, CSSProperties } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { matrixToCSS } from '../../lib/dom'; | ||
import { TransformMatrix3d } from '../../lib/aeroelastic'; | ||
|
||
interface Props { | ||
children: ReactElement; | ||
transformMatrix: TransformMatrix3d; | ||
height: number; | ||
width: number; | ||
} | ||
|
||
export const Positionable: FC<Props> = ({ children, transformMatrix, width, height }) => { | ||
// Throw if there is more than one child | ||
const childNode = React.Children.only(children); | ||
|
||
const matrix = (transformMatrix.map((n, i) => | ||
i < 12 ? n : Math.round(n) | ||
) as any) as TransformMatrix3d; | ||
|
||
const newStyle: CSSProperties = { | ||
width, | ||
height, | ||
marginLeft: -width / 2, | ||
marginTop: -height / 2, | ||
position: 'absolute', | ||
transform: matrixToCSS(matrix), | ||
}; | ||
|
||
return ( | ||
<div className="canvasPositionable canvasInteractable" style={newStyle}> | ||
{childNode} | ||
</div> | ||
); | ||
}; | ||
|
||
Positionable.propTypes = { | ||
children: PropTypes.element.isRequired, | ||
transformMatrix: PropTypes.arrayOf(PropTypes.number).isRequired, | ||
width: PropTypes.number.isRequired, | ||
height: PropTypes.number.isRequired, | ||
}; |
12 changes: 0 additions & 12 deletions
12
x-pack/plugins/canvas/public/components/render_to_dom/index.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
x-pack/plugins/canvas/public/components/render_to_dom/render_to_dom.js
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
x-pack/plugins/canvas/public/components/render_to_dom/render_to_dom.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useCallback, FC } from 'react'; | ||
import CSS from 'csstype'; | ||
|
||
interface Props { | ||
render: (element: HTMLElement) => void; | ||
style?: CSS.Properties; | ||
} | ||
|
||
export const RenderToDom: FC<Props> = ({ render, style }) => { | ||
// https://reactjs.org/docs/hooks-faq.html#how-can-i-measure-a-dom-node | ||
const ref = useCallback( | ||
(node: HTMLDivElement) => { | ||
if (node !== null) { | ||
render(node); | ||
} | ||
}, | ||
[render] | ||
); | ||
|
||
return <div className="render_to_dom" {...{ ref, style }} />; | ||
}; |
30 changes: 0 additions & 30 deletions
30
x-pack/plugins/canvas/public/components/render_with_fn/index.js
This file was deleted.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
x-pack/plugins/canvas/public/components/render_with_fn/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { RenderWithFn } from './render_with_fn'; |
Oops, something went wrong.