-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathTeamIcon.lua
More file actions
112 lines (98 loc) · 2.88 KB
/
TeamIcon.lua
File metadata and controls
112 lines (98 loc) · 2.88 KB
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
---
-- @Liquipedia
-- page=Module:Widget/Image/Icon/TeamIcon
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--
local Lua = require('Module:Lua')
local Array = Lua.import('Module:Array')
local Class = Lua.import('Module:Class')
local HtmlWidgets = Lua.import('Module:Widget/Html/All')
local Span = HtmlWidgets.Span
local WidgetIcon = Lua.import('Module:Widget/Image/Icon')
local WidgetIconImage = Lua.import('Module:Widget/Image/Icon/Image')
local WidgetIconFontawesome = Lua.import('Module:Widget/Image/Icon/Fontawesome')
---@class TeamIconWidgetProps
---@field imageLight string?
---@field imageDark string?
---@field name string?
---@field page string?
---@field size string
---@field noLink boolean?
---@field legacy boolean?
---@class TeamIconWidget: IconWidget
---@operator call(TeamIconWidgetProps): TeamIconWidget
---@field props TeamIconWidgetProps
local TeamIcon = Class.new(WidgetIcon)
TeamIcon.defaultProps = {
size = '100x50px',
}
---This is the TBD Team icon in Team Template. This will be replaced by the Icon for the TBD Team.
---This is a medium term solution until we have refactored and standardized more of the Team Template.
---Hopefully in the future we can remove this.
local TBD_FILLER_IMAGE = 'Filler 600px.png'
---@private
---@return Widget
function TeamIcon:_getDefaultIcon()
return WidgetIconFontawesome{
iconName = 'team_tbd',
}
end
---@private
---@param image string
---@param size string
---@param link string
---@return Widget
function TeamIcon:_getIcon(image, size, link)
return WidgetIconImage{
imageLight = image,
size = size,
verticalAlignment = 'middle',
caption = self.props.name,
link = link,
}
end
---@private
---@param icon Widget
---@param onlyForTheme 'lightmode'|'darkmode'|nil
---@param isLegacy boolean
---@return Widget
function TeamIcon:_buildSpan(icon, onlyForTheme, isLegacy)
return Span{
classes = Array.extend(
'team-template-image-' .. (isLegacy and 'legacy' or 'icon'),
onlyForTheme and ('team-template-' .. onlyForTheme) or nil
),
children = {
icon,
}
}
end
---@private
---@return string
function TeamIcon:_getPageLink()
if self.props.noLink then
return ''
end
return self.props.page or ''
end
---@return Widget|Widget[]
function TeamIcon:render()
local size = self.props.size
local isLegacy = self.props.legacy or false
local imageLight = self.props.imageLight
if imageLight == TBD_FILLER_IMAGE or not imageLight then
return self:_buildSpan(self:_getDefaultIcon(), nil, false)
end
local link = self:_getPageLink()
local imageDark = self.props.imageDark or imageLight
local allmode = imageLight == imageDark
if allmode then
return self:_buildSpan(self:_getIcon(imageLight, size, link), nil, isLegacy)
end
return {
self:_buildSpan(self:_getIcon(imageLight, size, link), 'lightmode', isLegacy),
self:_buildSpan(self:_getIcon(imageDark, size, link), 'darkmode', isLegacy),
}
end
return TeamIcon