1
1
import { useMemo } from 'react' ;
2
+ import styled from '@emotion/styled' ;
3
+ import { spacing , transitionDuration } from '@leafygreen-ui/tokens' ;
4
+ import { palette } from '@leafygreen-ui/palette' ;
2
5
3
- import { ObjectFieldType } from '@/components/field/object-field-type' ;
4
6
import { useEditableDiagramInteractions } from '@/hooks/use-editable-diagram-interactions' ;
7
+ import { PlusWithSquare } from '@/components/icons/plus-with-square' ;
8
+
9
+ const ObjectTypeContainer = styled . div `
10
+ display: flex;
11
+ justify-content: flex-end;
12
+ align-items: center;
13
+ line-height: 20px;
14
+ ` ;
15
+
16
+ const AddNestedFieldIconButton = styled . button `
17
+ background: none;
18
+ border: none;
19
+ outline: none;
20
+ padding: ${ spacing [ 100 ] } px;
21
+ margin: 0;
22
+ margin-left: ${ spacing [ 100 ] } px;
23
+ cursor: pointer;
24
+ color: inherit;
25
+ display: flex;
26
+ position: relative;
27
+ color: ${ props => props . theme . node . fieldIconButton } ;
28
+
29
+ &::before {
30
+ content: '';
31
+ transition: ${ transitionDuration . default } ms all ease-in-out;
32
+ position: absolute;
33
+ top: 0;
34
+ bottom: 0;
35
+ left: 0;
36
+ right: 0;
37
+ border-radius: 100%;
38
+ transform: scale(0.8);
39
+ }
40
+
41
+ &:active::before,
42
+ &:hover::before,
43
+ &:focus::before,
44
+ &[data-hover='true']::before,
45
+ &[data-focus='true']::before {
46
+ transform: scale(1);
47
+ }
48
+
49
+ &:active,
50
+ &:hover,
51
+ &[data-hover='true'],
52
+ &:focus-visible,
53
+ &[data-focus='true'] {
54
+ color: ${ palette . black } ;
55
+
56
+ &::before {
57
+ background-color: ${ props => props . theme . node . fieldIconButtonHoverBackground } ;
58
+ }
59
+ }
60
+
61
+ // Focus ring styles.
62
+ &::after {
63
+ position: absolute;
64
+ content: '';
65
+ pointer-events: none;
66
+ top: 3px;
67
+ right: 3px;
68
+ bottom: 3px;
69
+ left: 3px;
70
+ border-radius: ${ spacing [ 100 ] } px;
71
+ box-shadow: 0 0 0 0 transparent;
72
+ transition: box-shadow 0.16s ease-in;
73
+ z-index: 1;
74
+ }
75
+ &:focus-visible {
76
+ &::after {
77
+ box-shadow: 0 0 0 3px ${ palette . blue . light1 } !important;
78
+ transition-timing-function: ease-out;
79
+ }
80
+ }
81
+ ` ;
5
82
6
83
export const FieldTypeContent = ( {
7
84
type,
@@ -18,6 +95,7 @@ export const FieldTypeContent = ({
18
95
( ) =>
19
96
_onClickAddFieldToObjectField
20
97
? ( event : React . MouseEvent < HTMLButtonElement > ) => {
98
+ // Don't click on the field element.
21
99
event . stopPropagation ( ) ;
22
100
_onClickAddFieldToObjectField ( event , nodeId , Array . isArray ( id ) ? id : [ id ] ) ;
23
101
}
@@ -27,10 +105,17 @@ export const FieldTypeContent = ({
27
105
28
106
if ( type === 'object' && ! ! onClickAddFieldToObject ) {
29
107
return (
30
- < ObjectFieldType
31
- data-testid = { `object-field-type-${ nodeId } -${ typeof id === 'string' ? id : id . join ( '.' ) } ` }
32
- onClickAddFieldToObject = { onClickAddFieldToObject }
33
- />
108
+ < ObjectTypeContainer >
109
+ { '{}' }
110
+ < AddNestedFieldIconButton
111
+ data-testid = { `object-field-type-${ nodeId } -${ typeof id === 'string' ? id : id . join ( '.' ) } ` }
112
+ onClick = { onClickAddFieldToObject }
113
+ aria-label = "Add new field"
114
+ title = "Add Field"
115
+ >
116
+ < PlusWithSquare />
117
+ </ AddNestedFieldIconButton >
118
+ </ ObjectTypeContainer >
34
119
) ;
35
120
}
36
121
0 commit comments