@vixoniccom/aniversarios 0.0.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +92 -0
  3. package/build.zip +0 -0
  4. package/configuration.json +579 -0
  5. package/icon.png +0 -0
  6. package/package.json +39 -0
  7. package/src/App.tsx +86 -0
  8. package/src/components/FontLoader.tsx +58 -0
  9. package/src/components/FormattedText.tsx +81 -0
  10. package/src/components/Render.tsx +73 -0
  11. package/src/components/anniversary-item/AnniversaryItem.tsx +22 -0
  12. package/src/components/anniversary-item/clasic/ClasicItem.tsx +209 -0
  13. package/src/components/anniversary-item/shared/AnniversaryImage.tsx +63 -0
  14. package/src/components/anniversary-item/shared/anniversary-date/AnniversaryDate.tsx +39 -0
  15. package/src/components/anniversary-item/shared/anniversary-date/DateUtils.ts +33 -0
  16. package/src/components/anniversary-item/shared/anniversary-date/circle/CircleDate.tsx +39 -0
  17. package/src/components/anniversary-item/shared/anniversary-date/flat/FlatDate.tsx +79 -0
  18. package/src/components/anniversary-item/shared/anniversary-date/outline/OutlineDate.tsx +60 -0
  19. package/src/components/anniversary-item/shared/anniversary-date/text/TextDate.tsx +30 -0
  20. package/src/components/anniversary-item/shared/anniversary-date/text-calendar/TextCalendarDate.tsx +46 -0
  21. package/src/components/anniversary-item/shared/default-profile.png +0 -0
  22. package/src/components/anniversary-item/shared/separator/Separator.tsx +41 -0
  23. package/src/components/anniversary-item/shared/utils.ts +10 -0
  24. package/src/components/items-container/Item.tsx +52 -0
  25. package/src/components/items-container/ItemsContainer.tsx +137 -0
  26. package/src/components/items-container/animation.ts +123 -0
  27. package/src/contex/configureContext/ConfigureContext.tsx +9 -0
  28. package/src/contex/configureContext/ConfigureProvider.tsx +74 -0
  29. package/src/contex/configureContext/configureReducer.ts +62 -0
  30. package/src/contex/dataContext/DataContex.tsx +8 -0
  31. package/src/contex/dataContext/DataProvider.tsx +31 -0
  32. package/src/contex/dataContext/dataReducer.ts +19 -0
  33. package/src/helpers/filterEmployees.ts +42 -0
  34. package/src/helpers/getEmployees.ts +40 -0
  35. package/src/helpers/parseMonthAndDay.ts +38 -0
  36. package/src/helpers/setToken.ts +71 -0
  37. package/src/helpers/utils.ts +52 -0
  38. package/src/hooks/useFetch.ts +47 -0
  39. package/src/index.html +11 -0
  40. package/src/main.tsx +43 -0
  41. package/src/model/income.ts +129 -0
  42. package/src/parameters.d.ts +120 -0
  43. package/src/test/downloads/4a9bcc4e-f398-4317-9f0f-afa8bcef1a4f.png +0 -0
  44. package/src/test/downloads/7953953c-7029-4730-ae4d-cff4abd5288f.ttf +0 -0
  45. package/src/test/downloads/Roboto-Bold.ttf +0 -0
  46. package/src/test/downloads/Spring in May.ttf +0 -0
  47. package/src/test/downloads/c705a739-312e-4334-9231-e73a05e9d382.ttf +0 -0
  48. package/src/test/downloads/cumples.png +0 -0
  49. package/src/test/downloads/d1093778-f3c9-42c8-9b07-9f8736390aeb/Foto prueba.jpg +0 -0
  50. package/src/test/downloads/d1093778-f3c9-42c8-9b07-9f8736390aeb/foto1.jpg +0 -0
  51. package/src/test/downloads/d1093778-f3c9-42c8-9b07-9f8736390aeb.zip +0 -0
  52. package/src/test/parameters.json +93 -0
  53. package/tsconfig.json +38 -0
  54. package/tslint.json +6 -0
@@ -0,0 +1,33 @@
1
+ import PropTypes from 'prop-types'
2
+ import { utils } from '../utils';
3
+
4
+ const Months = ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre']
5
+
6
+ export class AnniveraryDateUtil {
7
+
8
+ static getZeroLeadedText(text:any) {
9
+ return `0${text}`.slice(-2)
10
+ }
11
+
12
+ static getMonth(index:any, abbreviated:any) {
13
+ if (!abbreviated) return Months[index]
14
+ return Months[index].substring(0, 3).toUpperCase()
15
+ }
16
+
17
+ static utils(orientation:any, size :any = undefined) {
18
+ return utils(orientation, size)
19
+ }
20
+
21
+ static commonPropTypes() {
22
+ return {
23
+ day: PropTypes.number.isRequired,
24
+ dayFormat: PropTypes.object,
25
+ month: PropTypes.number.isRequired,
26
+ monthFormat: PropTypes.object,
27
+ primaryColor: PropTypes.string,
28
+ abbreviatedMonths: PropTypes.bool,
29
+ orientation: PropTypes.string
30
+ }
31
+ }
32
+ }
33
+
@@ -0,0 +1,39 @@
1
+ import React, { useContext } from 'react'
2
+ import { AnniveraryDateUtil } from '../DateUtils'
3
+ import { FormattedText } from '../../../../FormattedText'
4
+ import { ConfigureContext } from '../../../../../contex/configureContext/ConfigureContext'
5
+
6
+ interface Props {
7
+ day: number,
8
+ month: number
9
+ }
10
+
11
+ export const CircleDate = ({ day, month }: Props) => {
12
+
13
+
14
+ const { configureState } = useContext(ConfigureContext)
15
+ const { orientation, dateMonthFormat, datePrimaryColor, dateDayFormat } = configureState.parameters
16
+ const sizeProp = AnniveraryDateUtil.utils(orientation)
17
+
18
+ let monthSize = (dateMonthFormat && dateMonthFormat.fontSize || 100) * 400 / 100
19
+ let daySize = (dateDayFormat && dateDayFormat.fontSize || 100) * 400 / 100
20
+
21
+ return (
22
+ <svg {...sizeProp} viewBox='0 0 400 400' xmlSpace='preserve'>
23
+ <g>
24
+ <circle fill={datePrimaryColor} cx='200' cy='200' r='200' />
25
+ <foreignObject width='400' height='400'>
26
+ {/* <div xmlns='http://www.w3.org/1999/xhtml' style={{ height: 400, width: 400, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}> */}
27
+ <div style={{ height: 400, width: 400, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>
28
+ <FormattedText text={AnniveraryDateUtil.getMonth(month, true)} format={Object.assign({}, dateMonthFormat, { fontSize: monthSize })} unit='px' />
29
+ <FormattedText text={AnniveraryDateUtil.getZeroLeadedText(day)} format={Object.assign({}, dateDayFormat, { fontSize: daySize })} unit='px' />
30
+ </div>
31
+ </foreignObject>
32
+ </g>
33
+ </svg>
34
+ )
35
+ }
36
+
37
+
38
+ CircleDate.propTypes = AnniveraryDateUtil.commonPropTypes()
39
+
@@ -0,0 +1,79 @@
1
+ import React, { useContext } from "react";
2
+ import { ConfigureContext } from "../../../../../contex/configureContext/ConfigureContext";
3
+ import { AnniveraryDateUtil } from "../DateUtils";
4
+
5
+ interface Props {
6
+ month: number;
7
+ day: number;
8
+ }
9
+
10
+ export const FlatDate = ({ month, day }: Props) => {
11
+ const { configureState } = useContext(ConfigureContext);
12
+ const {
13
+ abbreviatedMonths,
14
+ dateDayFormat,
15
+ dateMonthFormat,
16
+ orientation,
17
+ datePrimaryColor,
18
+ } = configureState.parameters;
19
+
20
+ const sizeProp = AnniveraryDateUtil.utils(orientation);
21
+ let monthSize = ((dateMonthFormat?.fontSize || 18.5) * 400) / 100;
22
+ let daySize = ((dateDayFormat?.fontSize || 57.5) * 400) / 100;
23
+ const getFontFamily = (format: any) => {
24
+ if (format && format.font && format.font.filename) {
25
+ return format.font.filename.replace(".", "-");
26
+ }
27
+ return "";
28
+ };
29
+ return (
30
+ <svg {...sizeProp} viewBox="0 0 400 400" xmlSpace="preserve">
31
+ <g>
32
+ <path
33
+ fill={datePrimaryColor}
34
+ d="M349.5,393.5h-299c-24.3,0-44-19.7-44-44v-299c0-24.3,19.7-44,44-44h299c24.3,0,44,19.7,44,44v299C393.5,373.8,373.8,393.5,349.5,393.5z"
35
+ />
36
+ <path
37
+ fill="#FFFFFF"
38
+ d="M349.5,389.5h-299c-22,0-40-18-40-40v-299c0-22,18-40,40-40h299c22,0,40,18,40,40v299C389.5,371.5,371.5,389.5,349.5,389.5z"
39
+ />
40
+ <path
41
+ fill={datePrimaryColor}
42
+ d="M9,99.9V50.5c0-22.2,18.1-40.3,40.3-40.3h301.4c22.2,0,40.3,18.1,40.3,40.3v49.4H9z"
43
+ />
44
+ <text
45
+ fontFamily={`"${getFontFamily(dateMonthFormat)}"`}
46
+ textAnchor="middle"
47
+ alignmentBaseline="central"
48
+ x="200"
49
+ y="55"
50
+ fontSize={monthSize}
51
+ preserveAspectRatio="none"
52
+ fill={dateMonthFormat?.fontColor || "#fff"}
53
+ fontSizeAdjust=""
54
+ >
55
+ {AnniveraryDateUtil.getMonth(month, abbreviatedMonths)}
56
+ </text>
57
+ <text
58
+ fontFamily={`"${getFontFamily(dateDayFormat)}"`}
59
+ textAnchor="middle"
60
+ alignmentBaseline="central"
61
+ x="200"
62
+ y="245"
63
+ fontSize={daySize}
64
+ preserveAspectRatio="none"
65
+ fill={dateDayFormat?.fontColor || "#fff"}
66
+ fontSizeAdjust=""
67
+ >
68
+ {AnniveraryDateUtil.getZeroLeadedText(day)}
69
+ </text>
70
+ </g>
71
+ </svg>
72
+ );
73
+ };
74
+
75
+ FlatDate.defaultProps = {
76
+ datePrimaryColor: "#5B5959",
77
+ };
78
+
79
+ FlatDate.propTypes = AnniveraryDateUtil.commonPropTypes();
@@ -0,0 +1,60 @@
1
+ import React, { useContext, useEffect, useState } from 'react'
2
+ import { ConfigureContext } from '../../../../../contex/configureContext/ConfigureContext'
3
+ import { FormattedText } from '../../../../FormattedText'
4
+ import { AnniveraryDateUtil } from '../DateUtils'
5
+
6
+
7
+ interface Props {
8
+ day: number
9
+ month: number
10
+ }
11
+
12
+ export const OutlineDate = ({ day, month }: Props) => {
13
+
14
+
15
+
16
+ const { configureState } = useContext(ConfigureContext)
17
+ const { abbreviatedMonths, dateDayFormat, dateMonthFormat, orientation, datePrimaryColor } = configureState.parameters
18
+
19
+
20
+ const sizeProp = AnniveraryDateUtil.utils(orientation)
21
+
22
+ const parseFormat = (format: any, defaultSize: any) => {
23
+ return Object.assign(
24
+ {},
25
+ format,
26
+ { fontSize: format.fontSize || defaultSize }
27
+ )
28
+ }
29
+
30
+ useEffect(() => {
31
+
32
+
33
+ }, [])
34
+
35
+ const [monthFormatState,] = useState(parseFormat(dateMonthFormat, 20))
36
+ const [dayFormatState,] = useState(parseFormat(dateDayFormat, 50))
37
+
38
+
39
+ return (
40
+ <svg {...sizeProp} viewBox='0 0 100 100'>
41
+ <foreignObject x='20' y='35' width='60' height='50'>
42
+ <div style={{ display: 'flex', alignItems: 'center', flexDirection: 'column', justifyContent: 'center', height: '100%' }}>
43
+ <FormattedText text={AnniveraryDateUtil.getMonth(month, abbreviatedMonths)} format={monthFormatState} unit='px' />
44
+ <FormattedText text={AnniveraryDateUtil.getZeroLeadedText(day)} format={dayFormatState} unit='px' />
45
+ </div>
46
+ </foreignObject>
47
+ <svg viewBox='0 0 300 300'>
48
+ <path fill={datePrimaryColor}
49
+ d='M35.11,164q0-37.73,0-75.46A57.4,57.4,0,0,1,37.32,72a34,34,0,0,1,6.46-12.35A31.3,31.3,0,0,1,57.5,50.32a51.33,51.33,0,0,1,12.9-2.69c2.44-.21,4.88-.19,7.32-.2,8,0,16,0,23.93,0h.61c1,0,1,0,1-1,0-7.84,0-15.68,0-23.52a6.53,6.53,0,0,1,2.57-5.4,6.42,6.42,0,0,1,7.08-.8,6.29,6.29,0,0,1,3.85,6c0,7.81,0,15.61,0,23.42,0,1.46-.19,1.31,1.29,1.31h26.58c1.42,0,1.33.23,1.33-1.28,0-7.71,0-15.41,0-23.12a6.62,6.62,0,0,1,2.89-5.75,6.43,6.43,0,0,1,6.94-.49,6.33,6.33,0,0,1,3.7,5.89c0,7.81,0,15.61,0,23.42,0,1.52-.2,1.33,1.36,1.33h26.27c1.32,0,1.22.14,1.22-1.18,0-7.74,0-15.48,0-23.22a6.62,6.62,0,0,1,2.56-5.51,6.42,6.42,0,0,1,7.08-.81,6.29,6.29,0,0,1,3.87,6c0,7.77,0,15.55,0,23.32,0,1.66-.24,1.42,1.47,1.43,8,0,16-.17,24,.11a47.11,47.11,0,0,1,17.4,3.75,30.67,30.67,0,0,1,16.93,17.89,48.7,48.7,0,0,1,2.91,13.06c.28,3,.35,6.1.35,9.15q0,74,0,148.06a57,57,0,0,1-2.4,17.17c-2.66,8.45-7.58,15.09-15.56,19.25a41.82,41.82,0,0,1-11,3.79,59.72,59.72,0,0,1-12,1.18q-74.24,0-148.47,0A52.82,52.82,0,0,1,57.69,278c-10-3.54-16.57-10.41-19.94-20.4a49.83,49.83,0,0,1-2.29-11.23c-.29-3-.35-6.09-.35-9.15Q35.11,200.61,35.11,164ZM251.4,89a38.39,38.39,0,0,0-1.66-11.84,21.13,21.13,0,0,0-14.1-14.37,35.43,35.43,0,0,0-11-1.77c-7.2-.06-14.39,0-21.59,0-.2,0-.41,0-.61,0-.37,0-.58.1-.56.51s0,.54,0,.81q0,11.91,0,23.83c0,.31,0,.61,0,.92A6.45,6.45,0,0,1,197.81,93a6.37,6.37,0,0,1-7.12-1.11,6.6,6.6,0,0,1-2.32-5.31c0-8.15,0-16.29,0-24.44,0-1.3.1-1.15-1.14-1.15H160.66c-.2,0-.41,0-.61,0-.39,0-.57.13-.54.52,0,.24,0,.47,0,.71q0,12,0,23.93c0,.34,0,.68,0,1a6.49,6.49,0,0,1-3.91,5.76,6.37,6.37,0,0,1-6.91-.72A6.71,6.71,0,0,1,146,86.42c0-8.11,0-16.22,0-24.34,0-1.36,0-1.14-1.15-1.14H117.94c-.2,0-.41,0-.61,0-.37,0-.58.1-.56.51s0,.54,0,.81q0,11.91,0,23.83c0,.34,0,.68,0,1a6.44,6.44,0,0,1-3.7,5.68,6.31,6.31,0,0,1-6.68-.34,6.54,6.54,0,0,1-3.13-5.82c0-8.25,0-16.5,0-24.74,0-.94,0-.95-.93-.95-9.1,0-18.19,0-27.29,0a34.25,34.25,0,0,0-10.22,1.58A21.14,21.14,0,0,0,50.12,77.7a37.8,37.8,0,0,0-1.4,8.92c0,.78,0,1.56,0,2.34q0,75.2,0,150.4A40.47,40.47,0,0,0,50,249.94c2.13,7.92,7,13.21,14.9,15.7a37.27,37.27,0,0,0,11.34,1.62q74,0,148.06,0a37.54,37.54,0,0,0,9-1.08c8.73-2.14,14.43-7.46,16.85-16.17a40,40,0,0,0,1.33-10.77q0-37.58,0-75.15T251.4,89Z' />
50
+ </svg>
51
+ </svg>
52
+ )
53
+ }
54
+
55
+
56
+ OutlineDate.defaultProps = {
57
+ primaryColor: '#5B5959'
58
+ }
59
+
60
+ OutlineDate.propTypes = AnniveraryDateUtil.commonPropTypes()
@@ -0,0 +1,30 @@
1
+ import React, { useContext } from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import { FormattedText } from '../../../../FormattedText'
4
+ import { ConfigureContext } from '../../../../../contex/configureContext/ConfigureContext'
5
+
6
+ interface Props {
7
+ day: number
8
+ month: number
9
+ }
10
+
11
+ export const TextDate = ({ day, month }: Props) => {
12
+
13
+ const { configureState } = useContext(ConfigureContext)
14
+ const { dateMonthFormat, dateDayFormat } = configureState.parameters
15
+
16
+ return (
17
+ <div style={{ display: 'flex', alignItems: 'center' }}>
18
+ <FormattedText text={`${day}/`} format={dateDayFormat} />
19
+ <FormattedText text={`${month + 1}`} format={dateMonthFormat} />
20
+ </div>
21
+ )
22
+ }
23
+
24
+ TextDate.propTypes = {
25
+ day: PropTypes.number.isRequired,
26
+ dayFormat: PropTypes.object,
27
+ month: PropTypes.number.isRequired,
28
+ monthFormat: PropTypes.object
29
+ }
30
+
@@ -0,0 +1,46 @@
1
+ import React, { useContext, useState } from 'react'
2
+ import { ConfigureContext } from '../../../../../contex/configureContext/ConfigureContext'
3
+ import { FormattedText } from '../../../../FormattedText'
4
+ import { AnniveraryDateUtil } from '../DateUtils'
5
+
6
+ interface Props {
7
+ day: number
8
+ month: number
9
+ }
10
+
11
+ export const TextCalendarDate = ({ day, month }: Props) => {
12
+
13
+
14
+ const { configureState } = useContext(ConfigureContext)
15
+ const { dateMonthFormat, dateDayFormat, abbreviatedMonths,orientation } = configureState.parameters
16
+
17
+
18
+ const sizeProp = AnniveraryDateUtil.utils(orientation, '100%')
19
+
20
+
21
+ const parseFormat = (format: any, defaultSize: any) => {
22
+ return Object.assign(
23
+ {},
24
+ format,
25
+ { fontSize: format.fontSize || defaultSize }
26
+ )
27
+ }
28
+
29
+ const [monthFormatState,] = useState(parseFormat(dateMonthFormat, 20))
30
+ const [dayFormatState,] = useState(parseFormat(dateDayFormat, 20))
31
+
32
+ return (
33
+ <svg {...sizeProp} viewBox='0 0 100 100'>
34
+ <foreignObject width='100' height='100'>
35
+ <div style={{ display: 'flex', alignItems: 'center', flexDirection: 'column', justifyContent: 'center', height: '100%' }}>
36
+ <FormattedText text={AnniveraryDateUtil.getMonth(month, abbreviatedMonths)} format={monthFormatState} unit='px' />
37
+ <FormattedText text={AnniveraryDateUtil.getZeroLeadedText(day)} format={dayFormatState} unit='px' />
38
+ </div>
39
+ </foreignObject>
40
+ </svg>
41
+ )
42
+ }
43
+
44
+
45
+ TextCalendarDate.propTypes = AnniveraryDateUtil.commonPropTypes()
46
+
@@ -0,0 +1,41 @@
1
+ import React from 'react'
2
+
3
+
4
+ interface Props {
5
+ order: number | undefined
6
+ size: number | undefined
7
+ color: string | undefined
8
+ orientation: string | undefined
9
+ margins: string | undefined
10
+ }
11
+
12
+ export const Separator = ({ order,size, color, orientation, margins }: Props) => {
13
+
14
+ const getSizeStyle = (orientation: any, size: any) => {
15
+ if (orientation === 'h') {
16
+ return {
17
+ width: size || 0,
18
+ height: '100%'
19
+ }
20
+ } else {
21
+ return {
22
+ height: size || 0,
23
+ width: '100%'
24
+ }
25
+ }
26
+ }
27
+
28
+ if (order === 3) return null
29
+ const sizeStyle = getSizeStyle(orientation, size)
30
+ return (
31
+ <div style={{
32
+ flexShrink: 0,
33
+ order: order,
34
+ backgroundColor: color || '',
35
+ margin: margins,
36
+ ...sizeStyle
37
+ }} />
38
+ )
39
+ }
40
+
41
+
@@ -0,0 +1,10 @@
1
+ export const utils = (orientation:string, size:number) => {
2
+ const sizeAttr = orientation === 'v' ? 'width' : 'height'
3
+ const percentage = size
4
+ ? `${size}`
5
+ : orientation === 'v' ? '40%' : '80%'
6
+ return {
7
+ [sizeAttr]: percentage
8
+ }
9
+ }
10
+
@@ -0,0 +1,52 @@
1
+ import React, { useRef } from 'react'
2
+
3
+ const aligments = {
4
+ start: 'flex-start',
5
+ center: 'center',
6
+ end: 'flex-end'
7
+ }
8
+
9
+ interface Props {
10
+ width: string
11
+ height: string
12
+ containerData: any
13
+ verticalGap: number
14
+ horizontalGap: number
15
+ children?: any
16
+ style: any
17
+ }
18
+
19
+
20
+ export const Item = ({ width, height, containerData, verticalGap, horizontalGap, children, style }: Props) => {
21
+
22
+ const itemRef = useRef(null)
23
+
24
+ return (
25
+ <div ref={itemRef}
26
+ style={{
27
+ overflow: 'hidden',
28
+ display: 'flex',
29
+ position: 'relative',
30
+ alignItems: aligments['center'],
31
+ justifyContent: aligments['center'],
32
+ width: width,
33
+ height: height,
34
+ top: containerData.ic_rowIndex === 0
35
+ ? '0'
36
+ : verticalGap
37
+ ? `${verticalGap * containerData.ic_rowIndex}%`
38
+ : '0',
39
+ paddingLeft: containerData.ic_columnIndex === 0
40
+ ? '0'
41
+ : horizontalGap
42
+ ? `${horizontalGap}%`
43
+ : '0'
44
+ , ...style
45
+ }}
46
+ >
47
+ {React.cloneElement(children, containerData)}
48
+ </div>
49
+ )
50
+ }
51
+
52
+
@@ -0,0 +1,137 @@
1
+ import React, { useContext, useState, useRef, useEffect } from 'react'
2
+ import { Item } from './Item'
3
+ import { ConfigureContext } from '../../contex/configureContext/ConfigureContext'
4
+ import { useStateWithCallbackLazy } from 'use-state-with-callback';
5
+ import { ReactElementLike } from 'prop-types';
6
+
7
+
8
+
9
+ const stages = {
10
+ idle: 'idle',
11
+ prepared: 'prepared',
12
+ animating: 'animating'
13
+ }
14
+
15
+
16
+
17
+ interface Props {
18
+ items: ReactElementLike[],
19
+ animation: Animation,
20
+ animate: boolean
21
+ }
22
+
23
+ interface Animation {
24
+ mode: string | undefined
25
+ duration: number | undefined,
26
+ speed: number | undefined,
27
+ reverse: boolean | undefined
28
+ }
29
+
30
+
31
+
32
+ export const ItemsContainer = ({ animation, items, animate }: Props) => {
33
+
34
+ const { configureState } = useContext(ConfigureContext)
35
+ const { containerColumns, containerRows, containerRowsGap } = configureState.parameters
36
+ const container = useRef<HTMLDivElement>(null)
37
+ const [animations] = useState(new (require('./animation'))())
38
+ let itemsCount = Number(containerColumns) * Number(containerRows)
39
+ let columns = Number(containerColumns) | 1
40
+ let rows = Number(containerRows) | 1
41
+ let rowsGap = Number(containerRowsGap) | 0
42
+ let columnsGap = 1
43
+
44
+ const [show, setShow] = useState(false)
45
+ const [item, setItem] = useState([])
46
+ const [stage, setStage] = useStateWithCallbackLazy('idle')
47
+ const [lastIndex, setLastIndex] = useState(0)
48
+
49
+ const configure = () => {
50
+ animations.configure(animation)
51
+ itemsCount = Number(containerColumns) * Number(containerRows)
52
+ columns = Number(containerColumns) | 1
53
+ rows = Number(containerRows) | 1
54
+ rowsGap = Number(containerRowsGap) | 0
55
+ if (animate && stage === stages.idle) createItems(lastIndex, items)
56
+ }
57
+
58
+
59
+ useEffect(() => {
60
+ configure()
61
+ }, [animation])
62
+
63
+ useEffect(() => {
64
+ if (animate && stage === stages.prepared) {
65
+ setStage(stages.animating, () => {
66
+ if (null !== container.current) {
67
+ animations.animate(container.current.childNodes, () => {
68
+ createItems(lastIndex, items)
69
+ })
70
+ }
71
+ })
72
+ }
73
+ }, [item, animate])
74
+
75
+
76
+ const createItems = (lastIndex: number, items: any) => {
77
+ let count = 0
78
+ if (lastIndex >= (items.length - 1)) {
79
+ setLastIndex(lastIndex = 0)
80
+ }
81
+ let newItems = items.filter((_item: any, index: number) => {
82
+ return index >= lastIndex
83
+ }).map((item: any, index: any, arr: any) => {
84
+ if (count >= itemsCount) return null
85
+ setLastIndex(++lastIndex)
86
+ count++
87
+ return <Item
88
+ key={lastIndex} containerData={{
89
+ ic_index: index,
90
+ ic_rowIndex: index / columns,
91
+ ic_columnIndex: index % columns,
92
+ ic_firstChild: index === 0,
93
+ ic_lastChild: index === (arr.length - 1)
94
+ }} style={animations.getInitialStyle()}
95
+ // Item alignment. By default is center - center.
96
+ // alignment={alignment}
97
+ // Setup item width based on columns count.
98
+ width={`${(100 - (columnsGap * (columns - 1))) / columns}%`}
99
+ // Setup item height based on rows count. If 0 set up on auto.
100
+ height={`${(100 - (rowsGap * (rows - 1))) / rows}%`}
101
+ // Setup horizontal gap
102
+ horizontalGap={columnsGap}
103
+ // Setup vertical gap
104
+ verticalGap={rowsGap}>
105
+ {item}
106
+ </Item>
107
+ })
108
+
109
+
110
+ if (newItems.length > 0) {
111
+ setShow(true)
112
+ setStage(stages.prepared, () => { })
113
+ setItem(newItems)
114
+ } else {
115
+ setShow(false)
116
+ setStage(stages.idle, () => { })
117
+ }
118
+ }
119
+
120
+
121
+ return (
122
+ <div ref={container} style={{
123
+ opacity: show ? 1 : 0,
124
+ position: 'relative',
125
+ height: '100%',
126
+ width: '100%',
127
+ display: 'flex',
128
+ flexWrap: 'wrap',
129
+ alignContent: 'flex-start'
130
+ }}>
131
+ {item}
132
+ </div>
133
+ )
134
+ }
135
+
136
+
137
+
@@ -0,0 +1,123 @@
1
+ import anime from 'animejs'
2
+
3
+
4
+ interface Options {
5
+ mode: keyof typeof animationModes
6
+ duration: number
7
+ speed: number
8
+ stagger: number
9
+ reverse: boolean
10
+ }
11
+
12
+ const animationModes = {
13
+ fade: {
14
+ in: {
15
+ opacity: [0, 1],
16
+ easing: 'linear'
17
+ },
18
+ out: {
19
+ opacity: [1, 0],
20
+ easing: 'linear'
21
+ },
22
+ init: {
23
+ opacity: 0
24
+ }
25
+ },
26
+ slideRight: {
27
+ in: {
28
+ translateX: () => {
29
+ return [`-100vw`, '0vw']
30
+ },
31
+ easing: 'easeOutQuad'
32
+ },
33
+ out: {
34
+ translateX: () => {
35
+ return ['0vw', `100vw`]
36
+ },
37
+ easing: 'easeInQuad'
38
+ },
39
+ init: {
40
+ transform: 'translate(0vw)'
41
+ }
42
+ },
43
+ slideLeft: {
44
+ in: {
45
+ translateX: (el: any) => {
46
+ return [`${el.parentNode.clientWidth}px`, '0px']
47
+ },
48
+ easing: 'easeOutQuad'
49
+ },
50
+ out: {
51
+ translateX: (el: any) => {
52
+ return ['0px', `${-el.parentNode.clientWidth}px`]
53
+ },
54
+ easing: 'easeInQuad'
55
+ },
56
+ init: {
57
+ transform: 'translate(0px)'
58
+ }
59
+ }
60
+ }
61
+
62
+ class Animation {
63
+
64
+ public mode: any
65
+ public duration: number
66
+ public speed: number
67
+ public stagger: number
68
+ public reverse: boolean
69
+
70
+
71
+ constructor() {
72
+ this.mode = animationModes.fade
73
+ this.duration = 5000
74
+ this.speed = 1000
75
+ this.stagger = 1000 / 4
76
+ this.reverse = true
77
+ }
78
+
79
+ configure(options: Options) {
80
+ this.mode = animationModes.hasOwnProperty(options.mode) ? animationModes[options.mode] : animationModes.fade
81
+ this.duration = options.duration || 10000
82
+ this.speed = 1000 * (options.speed || 1)
83
+ this.stagger = this.speed / (options.stagger || 4)
84
+ this.reverse = options.reverse
85
+ }
86
+
87
+ getInitialStyle() {
88
+ return this.mode.init
89
+ }
90
+
91
+ animate(listNodes: any, finished: any) {
92
+ let self = this
93
+ let els = [].slice.call(listNodes, 0)
94
+ if (this.reverse) els = els.reverse()
95
+ if (!els || els.length < 1) return
96
+ let offset = this.duration - (((els.length - 1) * this.stagger) + this.speed) * 2
97
+ offset = offset < 0 ? 0 : offset
98
+ let animation = anime.timeline({
99
+ autoplay: false
100
+ })
101
+ animation.add(Object.assign({
102
+ targets: els,
103
+ duration: this.speed,
104
+ delay: function (_el: any, i: any, _l: any) {
105
+ return i * self.stagger
106
+ }
107
+ }, this.mode.in))
108
+ animation.add(Object.assign({
109
+ targets: els,
110
+ duration: this.speed,
111
+ delay: function (_el: any, i: any, _l: any) {
112
+ return i * self.stagger
113
+ },
114
+ offset: `+=${offset}`,
115
+ complete: () => {
116
+ finished()
117
+ }
118
+ }, this.mode.out))
119
+ animation.play()
120
+ }
121
+ }
122
+
123
+ module.exports = exports = Animation
@@ -0,0 +1,9 @@
1
+ import { createContext } from "react";
2
+
3
+
4
+ type ConfigureContext = {
5
+ configureState: VixonicData
6
+ addConfiguration: (configure:VixonicData)=>void
7
+ }
8
+
9
+ export const ConfigureContext = createContext<ConfigureContext>({} as ConfigureContext);