Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit facf286

Browse files
committed
removed ui-library from boxes example
1 parent 67524eb commit facf286

File tree

25 files changed

+537
-1182
lines changed

25 files changed

+537
-1182
lines changed

examples/react/release/boxes/package.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,25 @@
77
"@agile-ts/logger": "^0.0.7",
88
"@agile-ts/proxytree": "^0.0.5",
99
"@agile-ts/react": "^0.1.2",
10-
"@chakra-ui/react": "^1.6.3",
11-
"@emotion/react": "^11.4.0",
12-
"@emotion/styled": "^11.3.0",
13-
"framer-motion": "^4.1.17",
10+
"lodash": "^4.17.21",
1411
"react": "^17.0.2",
1512
"react-dom": "^17.0.2",
1613
"react-draggable": "^4.4.3",
1714
"react-feather": "^2.0.9",
1815
"react-resizable": "^1.11.1",
1916
"react-router-dom": "^5.2.0",
2017
"react-scripts": "4.0.3",
21-
"styled-components": "^5.3.0",
22-
"typescript": "^4.1.2",
23-
"web-vitals": "^1.0.1"
18+
"styled-components": "^5.3.0"
2419
},
2520
"devDependencies": {
21+
"@types/lodash": "^4.14.171",
2622
"@types/node": "^12.0.0",
2723
"@types/react": "^17.0.0",
2824
"@types/react-dom": "^17.0.0",
2925
"@types/react-resizable": "^1.7.2",
3026
"@types/react-router-dom": "^5.1.7",
31-
"@types/styled-components": "^5.1.11"
27+
"@types/styled-components": "^5.1.11",
28+
"typescript": "^4.1.2"
3229
},
3330
"scripts": {
3431
"start": "react-scripts start",
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React from 'react';
2+
import styled from 'styled-components';
3+
4+
// https://tobiasahlin.com/spinkit/
5+
const BounceSpinner: React.FC = () => {
6+
return (
7+
<Container>
8+
<DoubleBounce1 />
9+
<DoubleBounce2 />
10+
</Container>
11+
);
12+
};
13+
14+
export default BounceSpinner;
15+
16+
const Container = styled.div`
17+
width: 40px;
18+
height: 40px;
19+
position: relative;
20+
margin: 100px auto;
21+
`;
22+
23+
const DoubleBounce = styled.div`
24+
width: 100%;
25+
height: 100%;
26+
border-radius: 50%;
27+
background-color: #000000;
28+
opacity: 0.6;
29+
position: absolute;
30+
top: 0;
31+
left: 0;
32+
33+
@-webkit-keyframes sk-bounce {
34+
0%,
35+
100% {
36+
-webkit-transform: scale(0);
37+
}
38+
50% {
39+
-webkit-transform: scale(1);
40+
}
41+
}
42+
43+
@keyframes sk-bounce {
44+
0%,
45+
100% {
46+
transform: scale(0);
47+
-webkit-transform: scale(0);
48+
}
49+
50% {
50+
transform: scale(1);
51+
-webkit-transform: scale(1);
52+
}
53+
}
54+
55+
-webkit-animation: sk-bounce 2s infinite ease-in-out;
56+
animation: sk-bounce 2s infinite ease-in-out;
57+
`;
58+
59+
const DoubleBounce1 = styled(DoubleBounce)``;
60+
const DoubleBounce2 = styled(DoubleBounce)`
61+
-webkit-animation-delay: -1s;
62+
animation-delay: -1s;
63+
`;

examples/react/release/boxes/src/components/Card.tsx renamed to examples/react/release/boxes/src/components/EditProperties/components/Card.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ const Container = styled.div`
1212
top: 20px;
1313
right: 20px;
1414
background: #ffffff;
15-
padding: 10px;
15+
padding: 5px 10px 0 10px;
1616
align-items: flex-start;
1717
justify-content: flex-start;
1818
box-shadow: rgba(99, 99, 99, 0.2) 0 2px 8px 0;
1919
border-radius: 4px;
20+
z-index: 1000;
2021
`;

examples/react/release/boxes/src/components/EditProperties/components/ImageInfo.tsx

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React from 'react';
2+
import styled from 'styled-components';
3+
4+
const Info = ({ label, value }: { label: string; value?: string }) => {
5+
return (
6+
<Container>
7+
<Title>{label}</Title>
8+
{value == null ? <Skeleton /> : <Description>{value}</Description>}
9+
</Container>
10+
);
11+
};
12+
13+
export default Info;
14+
15+
const Container = styled.div`
16+
max-width: 175px;
17+
`;
18+
19+
const Title = styled.div`
20+
font-size: 14px;
21+
font-weight: 500;
22+
`;
23+
24+
const Description = styled.div`
25+
font-size: 14px;
26+
`;
27+
28+
const Skeleton = styled.div`
29+
width: 100%;
30+
height: 21px;
31+
border-radius: 4px;
32+
background: linear-gradient(
33+
70deg,
34+
#ccca 30%,
35+
rgba(224, 223, 223, 0.67),
36+
#ccca 60%
37+
)
38+
right/300% 100%;
39+
animation: loading 1s linear infinite;
40+
41+
@keyframes loading {
42+
to {
43+
background-position: left;
44+
}
45+
}
46+
`;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from 'react';
2+
import { SELECTED_ELEMENT } from '../../../../core/entities/ui/ui.controller';
3+
import { useProxy } from '@agile-ts/react';
4+
import core from '../../../../core';
5+
import Info from './components/Info';
6+
import styled from 'styled-components';
7+
8+
type ImageInfoProps = {
9+
fallback?: boolean;
10+
};
11+
12+
const ImageInfo: React.FC<ImageInfoProps> = (props) => {
13+
const { fallback } = props;
14+
15+
const element = useProxy(SELECTED_ELEMENT);
16+
const [imageInfo, setImageInfo] = React.useState<{
17+
author: string;
18+
url: string;
19+
} | null>(null);
20+
21+
React.useEffect(() => {
22+
const imageId = element?.image?.id;
23+
if (imageId != null) {
24+
core.ui.fetchImage(imageId).then((value) => {
25+
setImageInfo(value);
26+
});
27+
}
28+
}, [element?.image?.id]);
29+
30+
return (
31+
<Container>
32+
<Info label="Author" value={imageInfo?.author} />
33+
<Info label="Image URL" value={imageInfo?.url} />
34+
</Container>
35+
);
36+
};
37+
38+
export default ImageInfo;
39+
40+
const Container = styled.div`
41+
align-items: flex-start;
42+
width: 100%;
43+
margin-bottom: 10px;
44+
`;
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import React from 'react';
2+
import styled from 'styled-components';
3+
4+
interface PropertyInputProps {
5+
label: string;
6+
value: number;
7+
onChange: (value: number) => void;
8+
}
9+
10+
const PropertyInput: React.FC<PropertyInputProps> = (props) => {
11+
const { label, value, onChange } = props;
12+
const [currentValue, setCurrentValue] = React.useState<string>(
13+
value.toString()
14+
);
15+
const [lastValue, setLastValue] = React.useState<string>(value.toString());
16+
17+
React.useEffect(() => {
18+
setCurrentValue(value.toString());
19+
setLastValue(value.toString());
20+
}, [value]);
21+
22+
return (
23+
<>
24+
<Label>{label}</Label>
25+
<InputContainer>
26+
<Input
27+
value={currentValue}
28+
onChange={(event) => {
29+
const value = event.target.value.replace(/\D/g, '');
30+
setCurrentValue(value);
31+
}}
32+
inputMode={'numeric'}
33+
onFocus={() => {
34+
setLastValue(currentValue);
35+
}}
36+
onBlur={() => {
37+
if (/^\d+$/.test(currentValue)) {
38+
onChange(parseInt(currentValue));
39+
} else {
40+
setCurrentValue(lastValue);
41+
}
42+
}}
43+
/>
44+
<PxInputLabel>px</PxInputLabel>
45+
</InputContainer>
46+
</>
47+
);
48+
};
49+
50+
export default PropertyInput;
51+
52+
const Label = styled.div`
53+
font-size: 12px;
54+
font-weight: bold;
55+
line-height: 1;
56+
margin-bottom: 5px;
57+
`;
58+
59+
const InputContainer = styled.div`
60+
position: relative;
61+
`;
62+
63+
const PxInputLabel = styled.div`
64+
position: absolute;
65+
top: 15%;
66+
right: 10px;
67+
text-align: center;
68+
69+
font-size: 12px;
70+
`;
71+
72+
const Input = styled.input`
73+
display: block;
74+
box-sizing: border-box;
75+
width: 100%;
76+
border-radius: 4px;
77+
border: 1px solid #dce8f3;
78+
background-color: #edf2f7;
79+
padding: 5px 10px;
80+
margin-bottom: 10px;
81+
font-size: 14px;
82+
83+
:hover {
84+
background-color: #deebf3;
85+
}
86+
87+
:focus {
88+
background-color: #ffffff;
89+
}
90+
`;

examples/react/release/boxes/src/components/EditProperties/components/Property.tsx renamed to examples/react/release/boxes/src/components/EditProperties/components/Property/index.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1-
import core from '../../../core';
1+
import core from '../../../../core';
22
import { useProxy } from '@agile-ts/react';
3-
import _ from 'lodash';
3+
import lodash from 'lodash';
44
import React from 'react';
5-
import PropertyInput from './PropertyInput';
5+
import PropertyInput from './components/PropertyInput';
66

77
interface PropertyProps {
88
label: string;
99
path: string;
1010
id: number | string;
11+
onChange: (newValue: number) => void;
1112
}
1213

1314
const Property: React.FC<PropertyProps> = (props) => {
14-
const { label, path, id } = props;
15+
const { label, path, id, onChange } = props;
16+
1517
const ELEMENT = core.ui.ELEMENTS.getItem(id);
1618
const element = useProxy(ELEMENT, { componentId: 'Property', deps: [id] });
1719

1820
return (
1921
<PropertyInput
2022
label={label}
21-
value={_.get(element, path)}
22-
onChange={(newValue) => {
23-
ELEMENT?.set((v) => {
24-
return _.set(v, path, newValue);
25-
});
26-
}}
23+
value={lodash.get(element, path)}
24+
onChange={onChange}
2725
/>
2826
);
2927
};

0 commit comments

Comments
 (0)