mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
Merge pull request #114 from utopia-os/remove-defaultProps
fix(source): use JavaScript default parameters instead defaultProps
This commit is contained in:
commit
14dc0e38ba
@ -1,4 +1,3 @@
|
|||||||
import { node, string } from 'prop-types'
|
|
||||||
import { Children, cloneElement, isValidElement, useEffect } from 'react'
|
import { Children, cloneElement, isValidElement, useEffect } from 'react'
|
||||||
|
|
||||||
import type { Item } from '#types/Item'
|
import type { Item } from '#types/Item'
|
||||||
@ -33,11 +32,4 @@ export const ItemForm = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemForm.propTypes = {
|
ItemForm.__TYPE = 'ItemForm'
|
||||||
children: node,
|
|
||||||
__TYPE: string,
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemForm.defaultProps = {
|
|
||||||
__TYPE: 'ItemForm',
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import { node, string } from 'prop-types'
|
|
||||||
import { Children, cloneElement, isValidElement } from 'react'
|
import { Children, cloneElement, isValidElement } from 'react'
|
||||||
|
|
||||||
import type { Item } from '#types/Item'
|
import type { Item } from '#types/Item'
|
||||||
@ -8,18 +7,11 @@ export const ItemView = ({ children, item }: { children?: React.ReactNode; item?
|
|||||||
<div>
|
<div>
|
||||||
{children
|
{children
|
||||||
? Children.toArray(children).map((child) =>
|
? Children.toArray(children).map((child) =>
|
||||||
isValidElement<{ item: Item }>(child) ? cloneElement(child, { item }) : '',
|
isValidElement<{ item: Item }>(child) ? cloneElement(child, { item }) : null,
|
||||||
)
|
)
|
||||||
: ''}
|
: null}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemView.propTypes = {
|
ItemView.__TYPE = 'ItemView'
|
||||||
children: node,
|
|
||||||
__TYPE: string,
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemView.defaultProps = {
|
|
||||||
__TYPE: 'ItemView',
|
|
||||||
}
|
|
||||||
|
|||||||
@ -32,6 +32,7 @@ import type { Item } from '#types/Item'
|
|||||||
import type { LayerProps } from '#types/LayerProps'
|
import type { LayerProps } from '#types/LayerProps'
|
||||||
import type { Tag } from '#types/Tag'
|
import type { Tag } from '#types/Tag'
|
||||||
import type { Popup } from 'leaflet'
|
import type { Popup } from 'leaflet'
|
||||||
|
import type { ReactElement, ReactNode } from 'react'
|
||||||
|
|
||||||
export const Layer = ({
|
export const Layer = ({
|
||||||
data,
|
data,
|
||||||
@ -284,10 +285,10 @@ export const Layer = ({
|
|||||||
>
|
>
|
||||||
{children &&
|
{children &&
|
||||||
Children.toArray(children).some(
|
Children.toArray(children).some(
|
||||||
(child) => isValidElement(child) && child.props.__TYPE === 'ItemView',
|
(child) => isComponentWithType(child) && child.type.__TYPE === 'ItemView',
|
||||||
) ? (
|
) ? (
|
||||||
Children.toArray(children).map((child) =>
|
Children.toArray(children).map((child) =>
|
||||||
isValidElement(child) && child.props.__TYPE === 'ItemView' ? (
|
isComponentWithType(child) && child.type.__TYPE === 'ItemView' ? (
|
||||||
<ItemViewPopup
|
<ItemViewPopup
|
||||||
ref={(r) => {
|
ref={(r) => {
|
||||||
if (!(item.id in leafletRefs && leafletRefs[item.id].popup === r)) {
|
if (!(item.id in leafletRefs && leafletRefs[item.id].popup === r)) {
|
||||||
@ -300,9 +301,7 @@ export const Layer = ({
|
|||||||
>
|
>
|
||||||
{child}
|
{child}
|
||||||
</ItemViewPopup>
|
</ItemViewPopup>
|
||||||
) : (
|
) : null,
|
||||||
''
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
@ -318,6 +317,7 @@ export const Layer = ({
|
|||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Tooltip offset={[0, -38]} direction='top'>
|
<Tooltip offset={[0, -38]} direction='top'>
|
||||||
{item.name ? item.name : getValue(item, itemNameField)}
|
{item.name ? item.name : getValue(item, itemNameField)}
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
@ -332,10 +332,10 @@ export const Layer = ({
|
|||||||
itemFormPopup.layer.name === name &&
|
itemFormPopup.layer.name === name &&
|
||||||
(children &&
|
(children &&
|
||||||
Children.toArray(children).some(
|
Children.toArray(children).some(
|
||||||
(child) => isValidElement(child) && child.props.__TYPE === 'ItemForm',
|
(child) => isComponentWithType(child) && child.type.__TYPE === 'ItemForm',
|
||||||
) ? (
|
) ? (
|
||||||
Children.toArray(children).map((child) =>
|
Children.toArray(children).map((child) =>
|
||||||
isValidElement(child) && child.props.__TYPE === 'ItemForm' ? (
|
isComponentWithType(child) && child.type.__TYPE === 'ItemForm' ? (
|
||||||
<ItemFormPopup
|
<ItemFormPopup
|
||||||
key={setItemFormPopup?.name}
|
key={setItemFormPopup?.name}
|
||||||
position={itemFormPopup.position}
|
position={itemFormPopup.position}
|
||||||
@ -362,3 +362,7 @@ export const Layer = ({
|
|||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isComponentWithType(node: ReactNode): node is ReactElement & { type: { __TYPE: string } } {
|
||||||
|
return isValidElement(node) && typeof node.type !== 'string' && '__TYPE' in node.type
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user