-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
128 lines (118 loc) · 3.16 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
export const BUTTON_SCRIPT_URL = '//pocitadlolibise.seznam.cz/pocitadlolibise.js';
export const BUTTON_ELEMENT_NAME = 'seznam-pocitadlolibise';
export enum ButtonElementAttributeName {
ENTITY_ID = 'entity',
LAYOUT = 'layout',
SIZE = 'size',
ANALYTICS_HIT_PAYLOAD = 'data-payload',
ANALYTICS_HIT_BUTTON_POSITION = 'button-position',
}
export enum ButtonLayout {
SEAMLESS = 'seamless',
BUTTON_COUNT = 'button_count',
BOX_COUNT = 'box_count',
}
export enum ButtonSize {
MINIMALISTIC = 'minimalistic',
SMALL = 'small',
LARGE = 'large',
}
export enum ButtonColorVariable {
PRIMARY_COLOR = '--primary-color',
BACKGROUND_COLOR = '--background-color',
HOVER_COLOR = '--hover-color',
COUNT_COLOR = '--count-color',
ACTIVE_COLOR = '--active-color',
}
type LayoutDimensionsConfiguration = {
readonly [size in ButtonSize]: {
minWidth: number
height: number
}
}
export const BUTTON_DIMENSIONS: {readonly [layout in ButtonLayout]: LayoutDimensionsConfiguration} = {
[ButtonLayout.SEAMLESS]: {
[ButtonSize.MINIMALISTIC]: {
minWidth: 40,
height: 20,
},
[ButtonSize.SMALL]: {
minWidth: 100,
height: 20,
},
[ButtonSize.LARGE]: {
minWidth: 100,
height: 20,
},
},
[ButtonLayout.BUTTON_COUNT]: {
[ButtonSize.MINIMALISTIC]: {
minWidth: 40,
height: 20,
},
[ButtonSize.SMALL]: {
minWidth: 100,
height: 20,
},
[ButtonSize.LARGE]: {
minWidth: 100,
height: 28,
},
},
[ButtonLayout.BOX_COUNT]: {
[ButtonSize.MINIMALISTIC]: {
minWidth: 40,
height: 40,
},
[ButtonSize.SMALL]: {
minWidth: 100,
height: 40,
},
[ButtonSize.LARGE]: {
minWidth: 100,
height: 58,
},
},
}
export interface ButtonElementAttributes {
[ButtonElementAttributeName.ENTITY_ID]: string
[ButtonElementAttributeName.LAYOUT]?: ButtonLayout
[ButtonElementAttributeName.SIZE]?: ButtonSize
[ButtonElementAttributeName.ANALYTICS_HIT_PAYLOAD]?: string
[ButtonElementAttributeName.ANALYTICS_HIT_BUTTON_POSITION]?: string
}
export interface ButtonComponentProperties {
readonly entity: string
readonly layout?: ButtonLayout
readonly size?: ButtonSize
readonly colors?: {
readonly [color in ButtonColorVariable]: string
}
readonly analytics?: {
readonly payload?: JSON_serializable
readonly position?: string
}
}
type JSON_serializable =
null
| boolean
| number
| string
| readonly JSON_serializable[]
| {readonly [property: string]: JSON_serializable}
export function createElementAttributes(
componentProperties: Omit<ButtonComponentProperties, 'colors'>,
): ButtonElementAttributes {
const { analytics, ...otherProperties } = componentProperties
const attributes: ButtonElementAttributes = otherProperties
if (analytics) {
if (analytics.payload !== undefined) {
const serializedPayload = JSON.stringify(analytics.payload)
attributes[ButtonElementAttributeName.ANALYTICS_HIT_PAYLOAD] = serializedPayload
}
if (typeof analytics.position === 'string') {
attributes[ButtonElementAttributeName.ANALYTICS_HIT_BUTTON_POSITION] = analytics.position
}
}
return attributes
}