@vixoniccom/aniversarios 1.2.0-dev.1 → 1.2.1-dev.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 (55) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/build.zip +0 -0
  3. package/configuration.json +4 -0
  4. package/package.json +3 -4
  5. package/src/App.tsx +59 -73
  6. package/src/components/AnniversaryItem/components/AnniversaryDate/CircleDate/index.tsx +31 -0
  7. package/src/components/AnniversaryItem/components/AnniversaryDate/FlatDate/index.tsx +47 -0
  8. package/src/components/{anniversary-item/shared/anniversary-date/outline/OutlineDate.tsx → AnniversaryItem/components/AnniversaryDate/OutlineDate/index.tsx} +7 -25
  9. package/src/components/{anniversary-item/shared/anniversary-date/text-calendar/TextCalendarDate.tsx → AnniversaryItem/components/AnniversaryDate/TextCalendarDate/index.tsx} +7 -16
  10. package/src/components/{anniversary-item/shared/anniversary-date/text/TextDate.tsx → AnniversaryItem/components/AnniversaryDate/TextDate/index.tsx} +2 -12
  11. package/src/components/{anniversary-item/shared/anniversary-date/AnniversaryDate.tsx → AnniversaryItem/components/AnniversaryDate/index.tsx} +7 -11
  12. package/src/components/AnniversaryItem/components/AnniversaryDate/utils.ts +18 -0
  13. package/src/components/{anniversary-item/shared/AnniversaryImage.tsx → AnniversaryItem/components/AnniversaryImage/index.tsx} +11 -19
  14. package/src/components/AnniversaryItem/components/ClassicItem/index.tsx +109 -0
  15. package/src/components/{anniversary-item/shared/separator → AnniversaryItem/components/Separator}/Separator.tsx +3 -6
  16. package/src/components/AnniversaryItem/components/index.ts +11 -0
  17. package/src/components/AnniversaryItem/components/utils.ts +75 -0
  18. package/src/components/AnniversaryItem/index.tsx +17 -0
  19. package/src/components/{FontLoader.tsx → FontLoader/index.tsx} +11 -12
  20. package/src/components/FormattedText/index.tsx +81 -0
  21. package/src/components/{items-container → ItemsContainer/components}/Item.tsx +2 -10
  22. package/src/components/ItemsContainer/components/animation.ts +130 -0
  23. package/src/components/{items-container/ItemsContainer.tsx → ItemsContainer/index.tsx} +52 -61
  24. package/src/components/{Render.tsx → Render/index.tsx} +9 -11
  25. package/src/components/index.ts +13 -0
  26. package/src/context/configureContext/ConfigureContext.tsx +8 -0
  27. package/src/context/configureContext/ConfigureProvider.tsx +72 -0
  28. package/src/context/configureContext/configureReducer.ts +62 -0
  29. package/src/context/dataContext/DataContex.tsx +8 -0
  30. package/src/context/dataContext/DataProvider.tsx +25 -0
  31. package/src/context/dataContext/dataReducer.ts +12 -0
  32. package/src/helpers/filterEmployees.ts +31 -37
  33. package/src/helpers/getEmployees.ts +18 -22
  34. package/src/helpers/utils.ts +44 -50
  35. package/src/main.tsx +2 -2
  36. package/src/test/parameters.json +97 -97
  37. package/src/components/FormattedText.tsx +0 -81
  38. package/src/components/anniversary-item/AnniversaryItem.tsx +0 -22
  39. package/src/components/anniversary-item/clasic/ClasicItem.tsx +0 -220
  40. package/src/components/anniversary-item/shared/anniversary-date/DateUtils.ts +0 -33
  41. package/src/components/anniversary-item/shared/anniversary-date/circle/CircleDate.tsx +0 -39
  42. package/src/components/anniversary-item/shared/anniversary-date/flat/FlatDate.tsx +0 -79
  43. package/src/components/anniversary-item/shared/utils.ts +0 -10
  44. package/src/components/items-container/animation.ts +0 -125
  45. package/src/contex/configureContext/ConfigureContext.tsx +0 -8
  46. package/src/contex/configureContext/ConfigureProvider.tsx +0 -77
  47. package/src/contex/configureContext/configureReducer.ts +0 -67
  48. package/src/contex/dataContext/DataContex.tsx +0 -8
  49. package/src/contex/dataContext/DataProvider.tsx +0 -31
  50. package/src/contex/dataContext/dataReducer.ts +0 -19
  51. package/src/helpers/parseMonthAndDay.ts +0 -38
  52. package/src/helpers/setToken.ts +0 -69
  53. package/src/hooks/useFetch.ts +0 -47
  54. package/src/model/income.ts +0 -129
  55. /package/src/components/{anniversary-item/shared → AnniversaryItem/components}/default-profile.png +0 -0
@@ -0,0 +1,109 @@
1
+ import React, { useContext, useEffect, useRef, useState } from "react"
2
+ import { AnniversaryDate, AnniversaryImage, Separator } from '..'
3
+ import { FormattedText } from "../../../FormattedText"
4
+ import { ConfigureContext } from "../../../../context/configureContext/ConfigureContext"
5
+ import { getPhotoUrl, parseBorderMargin, parseParameters } from '../utils'
6
+
7
+ interface Props {
8
+ anniversary: DataEmployee
9
+ }
10
+
11
+ export const ClassicItem: React.FunctionComponent<Props> = ({ anniversary }: Props) => {
12
+ let month = anniversary.month
13
+ const cont = useRef(null)
14
+ const { configureState } = useContext(ConfigureContext)
15
+ const { parameters, downloadsPath } = configureState
16
+ const { orientation, separatorColor, separatorWidth, imageSize } = parameters
17
+ const [margins, setMargins] = useState(parseBorderMargin(parameters.itemMargins))
18
+ const [state, setState] = useState(Object.assign({}, parseParameters(parameters)))
19
+
20
+ useEffect(() => {
21
+ setMargins(parseBorderMargin(parameters.itemMargins))
22
+ setState(Object.assign({}, parseParameters(parameters)))
23
+ }, [])
24
+
25
+ const separatorProps = {
26
+ orientation: orientation,
27
+ size: separatorWidth,
28
+ color: separatorColor,
29
+ margins: orientation === "v"
30
+ ? `${margins.r} 0 ${margins.l} 0`
31
+ : `0 ${margins.r} 0 ${margins.l}`,
32
+ }
33
+
34
+ return (
35
+ <div
36
+ style={{
37
+ display: "flex",
38
+ flexDirection: orientation === "v" ? "column" : "row",
39
+ backgroundColor: "transparent",
40
+ overflow: "hidden",
41
+ alignItems: "center",
42
+ height: "100%",
43
+ width: "100%",
44
+ }}
45
+ ref={cont}
46
+ >
47
+ {state.imageEnabled && parameters.imageStyle && (
48
+ <div style={state.imageStyle}>
49
+ {
50
+ <AnniversaryImage
51
+ url={anniversary.image ? getPhotoUrl(anniversary.image, parameters, downloadsPath) : null}
52
+ orientation={orientation}
53
+ size={Number(imageSize) || 100}
54
+ borderStyle={parameters.imageStyle}
55
+ />
56
+ }
57
+ </div>
58
+ )}
59
+ {state.imageEnabled && parameters.separator && (
60
+ <Separator order={state.imageStyle.order} {...separatorProps} />
61
+ )}
62
+ <div
63
+ style={{
64
+ ...state.textStyle,
65
+ flexDirection: "column",
66
+ }}
67
+ >
68
+ <FormattedText
69
+ text={anniversary.name}
70
+ format={parameters.nameFormat}
71
+ maxChar={Number(parameters.nameMaxChar)}
72
+ lineHeight={1.2}
73
+ />
74
+ {state.descriptionEnabled && (
75
+ <FormattedText
76
+ text={anniversary.position}
77
+ format={parameters.descriptionFormat}
78
+ maxChar={Number(parameters.descriptionMaxChar)}
79
+ lineHeight={1.2}
80
+ />
81
+ )}
82
+ {state.optionalEnabled && (
83
+ <FormattedText
84
+ text={anniversary.optional}
85
+ format={parameters.optionalFormat}
86
+ maxChar={Number(parameters.descriptionMaxChar)}
87
+ lineHeight={1.2}
88
+ />
89
+ )
90
+ }
91
+ </div>
92
+ {parameters.separator && (
93
+ <Separator order={state.textStyle.order} {...separatorProps} />
94
+ )}
95
+ {state.dateEnabled && parameters.dateStyle && (
96
+ <div style={state.dateStyle}>
97
+ <AnniversaryDate
98
+ style={parameters.dateStyle}
99
+ day={anniversary.day}
100
+ month={month}
101
+ />
102
+ </div>
103
+ )}
104
+ {state.dateEnabled && parameters.separator && (
105
+ <Separator order={state.dateStyle.order} {...separatorProps} />
106
+ )}
107
+ </div>
108
+ )
109
+ }
@@ -1,5 +1,4 @@
1
1
  import React from 'react'
2
-
3
2
 
4
3
  interface Props {
5
4
  order: number | undefined
@@ -9,8 +8,7 @@ interface Props {
9
8
  margins: string | undefined
10
9
  }
11
10
 
12
- export const Separator = ({ order,size, color, orientation, margins }: Props) => {
13
-
11
+ export const Separator = ({ order, size, color, orientation, margins }: Props) => {
14
12
  const getSizeStyle = (orientation: any, size: any) => {
15
13
  if (orientation === 'h') {
16
14
  return {
@@ -26,11 +24,11 @@ export const Separator = ({ order,size, color, orientation, margins }: Props) =
26
24
  }
27
25
 
28
26
  if (order === 3) return null
29
- const sizeStyle = getSizeStyle(orientation, size)
27
+ const sizeStyle = getSizeStyle(orientation, size)
30
28
  return (
31
29
  <div style={{
32
30
  flexShrink: 0,
33
- order: order,
31
+ order: order,
34
32
  backgroundColor: color || '',
35
33
  margin: margins,
36
34
  ...sizeStyle
@@ -38,4 +36,3 @@ export const Separator = ({ order,size, color, orientation, margins }: Props) =
38
36
  )
39
37
  }
40
38
 
41
-
@@ -0,0 +1,11 @@
1
+ import { AnniversaryDate } from './AnniversaryDate'
2
+ import { AnniversaryImage } from './AnniversaryImage'
3
+ import { ClassicItem } from './ClassicItem'
4
+ import { Separator } from './Separator/Separator'
5
+
6
+ export {
7
+ AnniversaryDate,
8
+ AnniversaryImage,
9
+ ClassicItem,
10
+ Separator
11
+ }
@@ -0,0 +1,75 @@
1
+ export const utils = (orientation: string, size: number) => {
2
+ const sizeAttr = orientation === 'v' ? 'width' : 'height'
3
+ const percentage = size ? `${size}` : orientation === 'v' ? '40%' : '80%'
4
+ return { [sizeAttr]: percentage }
5
+ }
6
+
7
+ export const parseBorderMargin = (marginString: any) => {
8
+ const pattern = /(( )?[+-]?[0-9]+.?([0-9]+)?(px|em|ex|%|in|cm|mm|pt|pc))?/g
9
+ const match = marginString ? marginString.match(pattern) : ['']
10
+
11
+ switch (match.length) {
12
+ case 1:
13
+ return { r: '4%', l: '4%' }
14
+ case 2:
15
+ return { r: match[0], l: match[0] }
16
+ default:
17
+ return { r: match[0], l: match[1] }
18
+ }
19
+ }
20
+
21
+ const parseElementStyles = (margin: string, position: number, defaultPosition: number, parameters: VixonicParameters) => {
22
+ const { orientation, separator } = parameters
23
+ const marginAttr = orientation === 'v' ? 'marginBottom' : 'marginRight'
24
+ const sizeAttr = orientation === 'v' ? 'width' : 'height'
25
+ const pos = position !== undefined ? position : defaultPosition
26
+ return {
27
+ order: pos,
28
+ [sizeAttr]: '100%',
29
+ [marginAttr]: margin !== undefined && margin !== '' ? `${margin}%` : pos === 3 || separator === true ? 0 : '4%',
30
+ }
31
+ }
32
+
33
+ export const parseParameters = (parameters: any) => {
34
+ const imageAlignment = parameters.imageAlignment || 'center'
35
+ const textAlignment = parameters.textAlignment || 'center'
36
+ const dateAlignment = parameters.dateAlignment || 'center'
37
+
38
+ return {
39
+ imageEnabled: parameters.imageEnabled,
40
+ imageStyle: Object.assign(
41
+ {
42
+ flexShrink: 0,
43
+ display: 'flex',
44
+ justifyContent: imageAlignment,
45
+ alignItems: imageAlignment,
46
+ },
47
+ parseElementStyles(parameters.imageMargin, parameters.imagePosition, 1, parameters)
48
+ ),
49
+ descriptionEnabled: parameters.descriptionEnabled,
50
+ optionalEnabled: parameters.optionalEnabled,
51
+ textStyle: Object.assign(
52
+ { display: 'flex', flexDirection: 'column', justifyContent: textAlignment, flex: 1 },
53
+ parseElementStyles(parameters.textMargin, parameters.textPosition, 2, parameters)
54
+ ),
55
+ dateEnabled: parameters.dateEnabled,
56
+ dateStyle: Object.assign(
57
+ {
58
+ display: 'flex',
59
+ justifyContent: dateAlignment,
60
+ alignItems: dateAlignment,
61
+ flexShrink: 0,
62
+ },
63
+ parseElementStyles(parameters.dateMargin, parameters.datePosition, 3, parameters)
64
+ ),
65
+ }
66
+ }
67
+
68
+ export const getPhotoUrl = (filename: string, parameters: VixonicParameters, downloadsPath: string) => {
69
+ const mode = parameters.photosMode
70
+ if (mode === 'zip' && parameters.photosZip && parameters.photosZip.filename !== undefined) {
71
+ return downloadsPath + '/' + parameters.photosZip.filename.replace('.zip', '/') + filename
72
+ } else {
73
+ return filename
74
+ }
75
+ }
@@ -0,0 +1,17 @@
1
+ import React from 'react'
2
+ import { ClassicItem } from './components'
3
+
4
+ const itemStyles = {
5
+ standard: ClassicItem
6
+ }
7
+
8
+ interface Props {
9
+ style: 'standard' | 'custom',
10
+ anniversary: DataEmployee
11
+ }
12
+
13
+ export const AnniversaryItem = ({ style, anniversary }: Props) => {
14
+ const StyledItem = itemStyles.hasOwnProperty(style) ? itemStyles['standard'] : itemStyles.standard
15
+
16
+ return <StyledItem anniversary={anniversary} />
17
+ }
@@ -1,36 +1,36 @@
1
1
  import React, { useContext } from 'react'
2
2
  import PropTypes from 'prop-types'
3
- import { ConfigureContext } from '../contex/configureContext/ConfigureContext'
3
+ import { ConfigureContext } from '../../context/configureContext/ConfigureContext'
4
4
 
5
5
  interface Props {
6
6
  paths: Array<string>
7
7
  }
8
8
 
9
- export const FontLoader = ({ paths}: Props) => {
10
-
9
+ export const FontLoader = ({ paths }: Props) => {
11
10
  const { configureState } = useContext(ConfigureContext)
12
11
  const { parameters, downloadsPath } = configureState
13
12
 
14
- const _getValueByPath = (path: any, obj: any): any => {
15
- let pathsArray = path.split('.')
16
- let propertyName = pathsArray[0]
13
+ const _getValueByPath = (path: string, obj: any): any => {
14
+ const pathsArray = path.split('.')
15
+ const propertyName = pathsArray[0]
17
16
  if (pathsArray.length === 1) return obj[propertyName]
18
17
  else {
19
18
  pathsArray.splice(0, 1)
20
19
  return _getValueByPath(pathsArray.join('.'), obj[propertyName])
21
20
  }
22
21
  }
23
- let fonts = paths.map((path: any) => {
22
+
23
+ const fonts = paths.map((path: any) => {
24
24
  try {
25
- let fontParam = _getValueByPath(path, parameters)
26
- let font = {
25
+ const fontParam = _getValueByPath(path, parameters)
26
+ const font = {
27
27
  family: fontParam.filename.replace('.', '-'),
28
28
  src: `${downloadsPath}/${fontParam.filename}`
29
29
  }
30
30
  return `
31
31
  @font-face {
32
- font-family: "${font.family}";
33
- src: url("${font.src}");
32
+ font-family: '${font.family}';
33
+ src: url('${font.src}');
34
34
  }
35
35
  `
36
36
  } catch (err) {
@@ -43,7 +43,6 @@ export const FontLoader = ({ paths}: Props) => {
43
43
  )
44
44
  }
45
45
 
46
-
47
46
  FontLoader.defaultProps = {
48
47
  paths: [],
49
48
  parameters: {},
@@ -0,0 +1,81 @@
1
+ import React from 'react'
2
+
3
+ const alignments = {
4
+ center: 'center',
5
+ left: 'flex-start',
6
+ right: 'flex-end'
7
+ }
8
+
9
+ type Aligment = {
10
+ horizontal: keyof typeof alignments,
11
+ vertical: keyof typeof alignments
12
+ }
13
+
14
+ interface Props {
15
+ format?: any
16
+ lineHeight?: number
17
+ maxChar?: number
18
+ style?: number
19
+ text: string
20
+ unit?: string
21
+ paddingBottom?: string
22
+ paddingTop?: string
23
+ }
24
+
25
+ export const FormattedText: React.FunctionComponent<Props> = ({ text, format, maxChar, lineHeight, style, unit, paddingBottom, paddingTop }) => {
26
+ const trimText = (text: any, maxChar: any) => {
27
+ const isValid = maxChar && maxChar >= 3
28
+ if (isValid && (text && text.length > maxChar) || false) {
29
+ const returnText = text.substring(0, maxChar - 3)
30
+ returnText.substr(-1, 3)
31
+ return `${returnText.trim()}...`
32
+ }
33
+ return text
34
+ }
35
+
36
+ const checkNested = (obj: any, path: string): boolean => {
37
+ return path.split('.').every(segment => {
38
+ if (obj && obj.hasOwnProperty(segment)) {
39
+ obj = obj[segment]
40
+ return true
41
+ }
42
+ return false
43
+ })
44
+ }
45
+
46
+ const getHorizontalAlignment = (alignment: Aligment) => {
47
+ if (alignment) {
48
+ const hA = alignment.horizontal
49
+ return alignments.hasOwnProperty(hA) ? alignments[alignment.horizontal] : 'flex-start'
50
+ }
51
+ return 'flex-start'
52
+ }
53
+
54
+ const renderText = maxChar ? trimText(text, maxChar) : text
55
+ const containerStyle = Object.assign({
56
+ display: 'inline-flex',
57
+ justifyContent: getHorizontalAlignment(format.alignment)
58
+ }, style)
59
+
60
+ return (
61
+ <div style={containerStyle}>
62
+ <span style={{
63
+ color: format?.fontColor,
64
+ fontFamily: checkNested(format, 'font.filename') ? `'${format?.font?.filename?.replace('.', '-')}'` : '',
65
+ fontSize: `${format?.fontSize}${unit}`,
66
+ textAlign: checkNested(format, 'alignment.horizontal') ? format?.alignment?.horizontal : 'left',
67
+ lineHeight: lineHeight,
68
+ paddingBottom: paddingBottom,
69
+ paddingTop: paddingTop,
70
+ display: 'inline-flex'
71
+ }}>{renderText}</span>
72
+ </div>
73
+ )
74
+ }
75
+
76
+ FormattedText.defaultProps = {
77
+ format: {},
78
+ lineHeight: 1,
79
+ unit: 'vh',
80
+ maxChar: undefined
81
+ }
@@ -16,9 +16,7 @@ interface Props {
16
16
  style: any
17
17
  }
18
18
 
19
-
20
19
  export const Item = ({ width, height, containerData, verticalGap, horizontalGap, children, style }: Props) => {
21
-
22
20
  const itemRef = useRef(null)
23
21
 
24
22
  return (
@@ -33,14 +31,10 @@ export const Item = ({ width, height, containerData, verticalGap, horizontalGap,
33
31
  height: height,
34
32
  top: containerData.ic_rowIndex === 0
35
33
  ? '0'
36
- : verticalGap
37
- ? `${verticalGap * containerData.ic_rowIndex}%`
38
- : '0',
34
+ : verticalGap ? `${verticalGap * containerData.ic_rowIndex}%` : '0',
39
35
  paddingLeft: containerData.ic_columnIndex === 0
40
36
  ? '0'
41
- : horizontalGap
42
- ? `${horizontalGap}%`
43
- : '0'
37
+ : horizontalGap ? `${horizontalGap}%` : '0'
44
38
  , ...style
45
39
  }}
46
40
  >
@@ -48,5 +42,3 @@ export const Item = ({ width, height, containerData, verticalGap, horizontalGap,
48
42
  </div>
49
43
  )
50
44
  }
51
-
52
-
@@ -0,0 +1,130 @@
1
+ import anime from 'animejs'
2
+
3
+ interface Options {
4
+ mode: keyof typeof animationModes
5
+ duration: number
6
+ speed: number
7
+ stagger: number
8
+ reverse: boolean
9
+ }
10
+
11
+ const animationModes = {
12
+ fade: {
13
+ in: {
14
+ opacity: [0, 1],
15
+ easing: 'linear',
16
+ },
17
+ out: {
18
+ opacity: [1, 0],
19
+ easing: 'linear',
20
+ },
21
+ init: {
22
+ opacity: 0,
23
+ },
24
+ },
25
+ slideRight: {
26
+ in: {
27
+ translateX: () => {
28
+ return [`-100vw`, '0vw']
29
+ },
30
+ easing: 'easeOutQuad',
31
+ },
32
+ out: {
33
+ translateX: () => {
34
+ return ['0vw', `100vw`]
35
+ },
36
+ easing: 'easeInQuad',
37
+ },
38
+ init: {
39
+ transform: 'translateX(-100vw)',
40
+ },
41
+ },
42
+ slideLeft: {
43
+ in: {
44
+ translateX: () => {
45
+ return [`100vw`, '0vw']
46
+ },
47
+ easing: 'easeOutQuad',
48
+ },
49
+ out: {
50
+ translateX: () => {
51
+ return ['0vw', `-100vw`]
52
+ },
53
+ easing: 'easeInQuad',
54
+ },
55
+ init: {
56
+ transform: 'translateX(100vw)',
57
+ },
58
+ },
59
+ }
60
+
61
+ class Animation {
62
+ public mode: any
63
+ public duration: number
64
+ public speed: number
65
+ public stagger: number
66
+ public reverse: boolean
67
+
68
+ constructor() {
69
+ this.mode = animationModes.fade
70
+ this.duration = 10000
71
+ this.speed = 1000
72
+ this.stagger = 1000 / 4
73
+ this.reverse = true
74
+ }
75
+
76
+ configure(options: Options) {
77
+ this.mode = animationModes.hasOwnProperty(options.mode) ? animationModes[options.mode] : animationModes.fade
78
+ this.duration = options.duration || 10000
79
+ this.speed = 1000 * (options.speed || 1)
80
+ this.stagger = this.speed / (options.stagger || 4)
81
+ this.reverse = options.reverse
82
+ }
83
+
84
+ getInitialStyle() {
85
+ return this.mode.init
86
+ }
87
+
88
+ animate(listNodes: any, finished: any) {
89
+ let self = this
90
+ let els = [].slice.call(listNodes, 0)
91
+ if (this.reverse) els = els.reverse()
92
+ if (!els || els.length < 1) return
93
+ let offset = this.duration - ((els.length - 1) * this.stagger + this.speed) * 2
94
+ offset = offset < 0 ? 0 : offset
95
+ let animation = anime.timeline({
96
+ autoplay: false,
97
+ })
98
+ animation.add(
99
+ Object.assign(
100
+ {
101
+ targets: els,
102
+ duration: this.speed,
103
+ delay: function (_el: any, i: any, _l: any) {
104
+ return i * self.stagger
105
+ },
106
+ },
107
+ this.mode.in
108
+ )
109
+ )
110
+ animation.add(
111
+ Object.assign(
112
+ {
113
+ targets: els,
114
+ duration: this.speed,
115
+ delay: function (_el: any, _i: any, _l: any) {
116
+ return _i * self.stagger
117
+ },
118
+ complete: () => {
119
+ finished()
120
+ },
121
+ },
122
+ this.mode.out
123
+ ),
124
+ `+=${offset}`
125
+ )
126
+ animation.play()
127
+ }
128
+ }
129
+
130
+ module.exports = exports = Animation