-
Notifications
You must be signed in to change notification settings - Fork 1
refactor/COMPASS-9877 add editable node handlers and interactions #135
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
Changes from 6 commits
f5f1409
3950576
4e068ac
4e6d3c8
725d591
e7c64bf
16fa8a8
d8595a8
be02b21
2e2404d
c423dd5
103c79c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { useCallback } from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { spacing, transitionDuration } from '@leafygreen-ui/tokens'; | ||
import { palette } from '@leafygreen-ui/palette'; | ||
|
||
import { PlusWithSquare } from '@/components/icons/plus-with-square'; | ||
|
||
const ObjectTypeContainer = styled.div` | ||
display: flex; | ||
justify-content: flex-end; | ||
align-items: center; | ||
line-height: 20px; | ||
`; | ||
|
||
const AddNestedFieldIconButton = styled.button` | ||
|
||
background: none; | ||
border: none; | ||
outline: none; | ||
padding: ${spacing[100]}px; | ||
margin: 0; | ||
margin-left: ${spacing[100]}px; | ||
cursor: pointer; | ||
color: inherit; | ||
display: flex; | ||
position: relative; | ||
color: ${props => props.theme.node.fieldIconButton}; | ||
&::before { | ||
content: ''; | ||
transition: ${transitionDuration.default}ms all ease-in-out; | ||
position: absolute; | ||
top: 0; | ||
bottom: 0; | ||
left: 0; | ||
right: 0; | ||
border-radius: 100%; | ||
transform: scale(0.8); | ||
} | ||
&:active::before, | ||
&:hover::before, | ||
&:focus::before, | ||
&[data-hover='true']::before, | ||
&[data-focus='true']::before { | ||
transform: scale(1); | ||
} | ||
&:active, | ||
&:hover, | ||
&[data-hover='true'], | ||
&:focus-visible, | ||
&[data-focus='true'] { | ||
color: ${props => props.theme.node.fieldIconButtonHover}; | ||
&::before { | ||
background-color: ${props => props.theme.node.fieldIconButtonHoverBackground}; | ||
} | ||
} | ||
// Focus ring styles. | ||
&::after { | ||
position: absolute; | ||
content: ''; | ||
pointer-events: none; | ||
top: 3px; | ||
right: 3px; | ||
bottom: 3px; | ||
left: 3px; | ||
border-radius: ${spacing[100]}px; | ||
box-shadow: 0 0 0 0 transparent; | ||
transition: box-shadow 0.16s ease-in; | ||
z-index: 1; | ||
} | ||
&:focus-visible { | ||
&::after { | ||
box-shadow: 0 0 0 3px ${palette.blue.light1} !important; | ||
transition-timing-function: ease-out; | ||
} | ||
} | ||
`; | ||
|
||
type ObjectFieldTypeProps = { | ||
onClickAddFieldToObject: (event: React.MouseEvent<HTMLButtonElement>) => void; | ||
['data-testid']: string; | ||
}; | ||
|
||
export const ObjectFieldType = ({ | ||
'data-testid': dataTestId, | ||
onClickAddFieldToObject: _onClickAddFieldToObject, | ||
}: ObjectFieldTypeProps) => { | ||
const onClickAddFieldToObject = useCallback( | ||
(event: React.MouseEvent<HTMLButtonElement>) => { | ||
// Don't click on the field element. | ||
event.stopPropagation(); | ||
_onClickAddFieldToObject(event); | ||
}, | ||
[_onClickAddFieldToObject], | ||
); | ||
|
||
return ( | ||
<ObjectTypeContainer> | ||
|
||
{'{}'} | ||
<AddNestedFieldIconButton | ||
data-testid={dataTestId} | ||
onClick={onClickAddFieldToObject} | ||
aria-label="Add new field" | ||
title="Add Field" | ||
> | ||
<PlusWithSquare /> | ||
</AddNestedFieldIconButton> | ||
</ObjectTypeContainer> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { useMemo } from 'react'; | ||
import { useTheme } from '@emotion/react'; | ||
|
||
export const PlusWithSquare: React.FunctionComponent = () => { | ||
const theme = useTheme(); | ||
|
||
const strokeColor = useMemo(() => theme.node.headerIcon, [theme]); | ||
Anemy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<path | ||
d="M12 0.75H2C1.66848 0.75 1.35054 0.881696 1.11612 1.11612C0.881696 1.35054 0.75 1.66848 0.75 2V12C0.75 12.3315 0.881696 12.6495 1.11612 12.8839C1.35054 13.1183 1.66848 13.25 2 13.25H12C12.3315 13.25 12.6495 13.1183 12.8839 12.8839C13.1183 12.6495 13.25 12.3315 13.25 12V2C13.25 1.66848 13.1183 1.35054 12.8839 1.11612C12.6495 0.881696 12.3315 0.75 12 0.75ZM11.75 11.75H2.25V2.25H11.75V11.75ZM3.75 7C3.75 6.80109 3.82902 6.61032 3.96967 6.46967C4.11032 6.32902 4.30109 6.25 4.5 6.25H6.25V4.5C6.25 4.30109 6.32902 4.11032 6.46967 3.96967C6.61032 3.82902 6.80109 3.75 7 3.75C7.19891 3.75 7.38968 3.82902 7.53033 3.96967C7.67098 4.11032 7.75 4.30109 7.75 4.5V6.25H9.5C9.69891 6.25 9.88968 6.32902 10.0303 6.46967C10.171 6.61032 10.25 6.80109 10.25 7C10.25 7.19891 10.171 7.38968 10.0303 7.53033C9.88968 7.67098 9.69891 7.75 9.5 7.75H7.75V9.5C7.75 9.69891 7.67098 9.88968 7.53033 10.0303C7.38968 10.171 7.19891 10.25 7 10.25C6.80109 10.25 6.61032 10.171 6.46967 10.0303C6.32902 9.88968 6.25 9.69891 6.25 9.5V7.75H4.5C4.30109 7.75 4.11032 7.67098 3.96967 7.53033C3.82902 7.38968 3.75 7.19891 3.75 7Z" | ||
fill={strokeColor} | ||
/> | ||
</svg> | ||
); | ||
}; |
Uh oh!
There was an error while loading. Please reload this page.