-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor out PortInfo and add coercion into it
- Loading branch information
Showing
2 changed files
with
122 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import Portal from '@atlaskit/portal'; | ||
import { css } from '@emotion/react'; | ||
import { | ||
getScalarTypeOf, | ||
type NodeId, | ||
type NodeInputDefinition, | ||
type NodeOutputDefinition, | ||
type PortId, | ||
} from '@ironclad/rivet-core'; | ||
import { type CSSProperties, forwardRef } from 'react'; | ||
|
||
const style = css` | ||
position: absolute; | ||
padding: 12px; | ||
border-radius: 5px; | ||
background-color: var(--grey-darker); | ||
color: var(--foreground); | ||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5); | ||
border: 1px solid var(--grey); | ||
z-index: 1000; | ||
font-size: 12px; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 4px; | ||
dl { | ||
display: grid; | ||
grid-template-columns: auto 2fr; | ||
flex-direction: column; | ||
margin: 0; | ||
padding: 0; | ||
align-items: center; | ||
column-gap: 16px; | ||
row-gap: 4px; | ||
dt { | ||
font-weight: bold; | ||
margin: 0; | ||
white-space: nowrap; | ||
padding: 0; | ||
} | ||
dd { | ||
margin: 0; | ||
padding: 0; | ||
min-width: 200px; | ||
} | ||
dt.id-title { | ||
grid-column: 1 / span 2; | ||
.id { | ||
font-family: var(--font-family-monospace); | ||
font-weight: 400; | ||
font-size: 12px; | ||
} | ||
} | ||
dd.description { | ||
grid-column: 1 / span 2; | ||
} | ||
} | ||
`; | ||
|
||
export const PortInfo = forwardRef< | ||
HTMLDivElement, | ||
{ | ||
port: { | ||
nodeId: NodeId; | ||
isInput: boolean; | ||
portId: PortId; | ||
definition: NodeInputDefinition | NodeOutputDefinition; | ||
}; | ||
floatingStyles: CSSProperties; | ||
} | ||
>(({ port, floatingStyles }, ref) => { | ||
const { definition } = port; | ||
const { dataType, title, description, id } = definition; | ||
|
||
let dataTypeDisplay: string = Array.isArray(dataType) ? dataType.join(' or ') : (dataType as string); | ||
|
||
if (port.isInput && ((definition as NodeInputDefinition).coerced ?? true)) { | ||
dataTypeDisplay += ' (coerced)'; | ||
} | ||
|
||
return ( | ||
<Portal> | ||
<div css={style} ref={ref} style={floatingStyles}> | ||
<dl> | ||
<dt className="id-title"> | ||
{title === id ? ( | ||
title | ||
) : ( | ||
<span> | ||
{title} <span className="id">({id})</span> | ||
</span> | ||
)} | ||
</dt> | ||
<dt>Data Type</dt> | ||
<dd>{dataTypeDisplay}</dd> | ||
|
||
{(definition as NodeInputDefinition).required && ( | ||
<> | ||
<dt>Required</dt> | ||
<dd>Yes</dd> | ||
</> | ||
)} | ||
|
||
{description && ( | ||
<> | ||
<dd className="description">{description}</dd> | ||
</> | ||
)} | ||
</dl> | ||
</div> | ||
</Portal> | ||
); | ||
}); |