-
Notifications
You must be signed in to change notification settings - Fork 104
feat: legend component for standings table #7477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ElectricalBoy
wants to merge
23
commits into
main
Choose a base branch
from
legend-widget
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
25eeb77
create legend widget
ElectricalBoy 09f407b
use same flex container
ElectricalBoy 5aa8927
add mobile breakpoint
ElectricalBoy 163c1f6
update min width
ElectricalBoy 5a92f6f
fix border
ElectricalBoy c9aa520
add color section
ElectricalBoy cf971f3
adjust title impl
ElectricalBoy 97e7b42
fix section divider
ElectricalBoy 4cef64a
add points section
ElectricalBoy 7d17fb3
better color section handle
ElectricalBoy 1c1027a
add number section
ElectricalBoy ace72db
add Legend.scss to main.scss
ElectricalBoy 7f56e1d
switch internal components to widget3
ElectricalBoy b519ba4
move the rest to widget3
ElectricalBoy c357b87
extract default props
ElectricalBoy 4e5b31c
workaround
ElectricalBoy f61baf9
add issue reference
ElectricalBoy 88b52e6
lint
ElectricalBoy 42f85d2
make collapsing configurable
ElectricalBoy 5bcf33a
fix chevrontoggle import
ElectricalBoy 83c148c
add golden
ElectricalBoy 0661b78
update golden props
ElectricalBoy 91331eb
chore: update visual snapshots
ElectricalBoy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| --- Triple Comment to Enable our LLS Plugin | ||
| insulate('Widget/Legend', function() | ||
| it('integration', function() | ||
| local LegendComponent = require('Module:Widget/Legend') | ||
|
|
||
| GoldenTest('standings_legend', tostring(LegendComponent{ | ||
| color = { | ||
| byeup = 'Lorem ipsum', | ||
| seedup = 'Lorem ipsum', | ||
| up = 'Lorem ipsum', | ||
| stayup = 'Lorem ipsum', | ||
| stay = 'Lorem ipsum', | ||
| staydown = 'Lorem ipsum', | ||
| down = 'Lorem ipsum', | ||
| }, | ||
| points = {'Lorem ipsum'}, | ||
| showMinimum = true, | ||
| showNumberSection = true, | ||
| })) | ||
| end) | ||
| end) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,185 @@ | ||
| --- | ||
| -- @Liquipedia | ||
| -- page=Module:Widget/Legend | ||
| -- | ||
| -- Please see https://github.com/Liquipedia/Lua-Modules to contribute | ||
| -- | ||
|
|
||
| local Lua = require('Module:Lua') | ||
|
|
||
| local Array = Lua.import('Module:Array') | ||
| local Json = Lua.import('Module:Json') | ||
| local Logic = Lua.import('Module:Logic') | ||
|
|
||
| local Component = Lua.import('Module:Widget/Component') | ||
| local ChevronToggle = Lua.import('Module:Widget/GeneralCollapsible/ChevronToggle') | ||
| local GeneralCollapsible = Lua.import('Module:Widget/GeneralCollapsible/Default') | ||
| local Html = Lua.import('Module:Widget/Html') | ||
| local Icon = Lua.import('Module:Widget/Image/Icon/Fontawesome') | ||
| local LabelWidget = Lua.import('Module:Widget/Basic/Label') | ||
| local WidgetUtil = Lua.import('Module:Widget/Util') | ||
|
|
||
| local LABEL_COLORS = {'byeup', 'seedup', 'up', 'stayup', 'stay', 'staydown', 'down'} | ||
|
|
||
| ---@class LegendComponent | ||
| local LegendComponent = {} | ||
|
|
||
| --TODO: pass defaultProps directly to Component.component (see #7476) | ||
| LegendComponent.defaultProps = { | ||
| title = 'Legend', | ||
| showConfirmed = true, | ||
| showUndecided = true, | ||
| } | ||
|
|
||
| ---@param props table | ||
| ---@return Widget | ||
| function LegendComponent.render(props) | ||
| return GeneralCollapsible{ | ||
| shouldCollapse = Logic.readBool(props.shouldCollapse), | ||
| collapseAreaClasses = {}, | ||
| classes = {'legend'}, | ||
| titleWidget = LegendComponent._createHeader(props), | ||
| children = WidgetUtil.collect( | ||
| LegendComponent._createColorSection(props), | ||
| LegendComponent._createPointsSection(props), | ||
| LegendComponent._createNumberSection(props) | ||
| ) | ||
| } | ||
| end | ||
|
|
||
| ---@private | ||
| ---@return VNode | ||
| function LegendComponent._createHeader(props) | ||
| return Html.Div{ | ||
| classes = {'legend-header'}, | ||
| attributes = {['data-collapsible-click-region'] = 'true'}, | ||
| children = { | ||
| Html.Div{children = { | ||
| Icon{iconName = 'general-info'}, | ||
| Html.Span{children = {Logic.emptyOr(props.title, LegendComponent.defaultProps.title)}} | ||
| }}, | ||
| ChevronToggle{} | ||
| } | ||
| } | ||
| end | ||
|
|
||
| ---@private | ||
| ---@return VNode? | ||
| function LegendComponent._createColorSection(props) | ||
| local sectionData = Json.parseIfString(props.color) | ||
| if Logic.isEmpty(sectionData) then | ||
| return | ||
| end | ||
| local labels = Array.map(LABEL_COLORS, function (labelColor) | ||
| local labelText = sectionData[labelColor] | ||
| if Logic.isEmpty(labelText) then | ||
| return | ||
| end | ||
| return Html.Div{ | ||
| classes = {'legend-item'}, | ||
| children = { | ||
| Html.Span{ | ||
| classes = {labelColor .. '-text'}, | ||
| children = {'●'} | ||
| }, | ||
| Html.Span{children = labelText} | ||
| } | ||
| } | ||
| end) | ||
|
|
||
| if Logic.isEmpty(labels) then | ||
| return | ||
| end | ||
|
|
||
| return Html.Div{ | ||
| classes = {'legend-section'}, | ||
| children = labels | ||
| } | ||
| end | ||
|
|
||
| ---@private | ||
| ---@return VNode? | ||
| function LegendComponent._createPointsSection(props) | ||
| local sectionData = Json.parseIfString(props.points) | ||
| if not sectionData then | ||
| return | ||
| end | ||
| local pointsText = sectionData[1] or sectionData.points | ||
| if Logic.isEmpty(pointsText) then | ||
| return | ||
| end | ||
| return Html.Div{ | ||
| classes = {'legend-section'}, | ||
| children = Html.Div{ | ||
| classes = {'legend-item'}, | ||
| children = { | ||
| Html.Span{ | ||
| css = {['font-weight'] = 'bold'}, | ||
| children = {'Pts'} | ||
| }, | ||
| Html.Span{children = pointsText} | ||
| } | ||
| } | ||
| } | ||
| end | ||
|
|
||
| ---@private | ||
| ---@return VNode? | ||
| function LegendComponent._createNumberSection(props) | ||
| if not Logic.readBool(props.showNumberSection) then | ||
| return | ||
| end | ||
|
|
||
| local labels = WidgetUtil.collect( | ||
| Logic.nilOr( | ||
| Logic.readBoolOrNil(props.showConfirmed), | ||
| LegendComponent.defaultProps.showConfirmed | ||
| ) and Html.Div{ | ||
| classes = {'legend-item'}, | ||
| children = { | ||
| LabelWidget{ | ||
| labelScheme = 'placement', | ||
| labelType = 'legend-confirmed', | ||
| children = 1 | ||
| }, | ||
| Html.Span{children = {'Placement confirmed'}} | ||
| } | ||
| } or nil, | ||
| Logic.readBool(props.showMinimum) and Html.Div{ | ||
| classes = {'legend-item'}, | ||
| children = { | ||
| LabelWidget{ | ||
| labelScheme = 'placement', | ||
| labelType = 'legend-minimum', | ||
| children = 1 | ||
| }, | ||
| Html.Span{children = {'Minimum placement reached'}} | ||
| } | ||
| } or nil, | ||
| Logic.nilOr( | ||
| Logic.readBoolOrNil(props.showUndecided), | ||
| LegendComponent.defaultProps.showUndecided | ||
| ) and Html.Div{ | ||
| classes = {'legend-item'}, | ||
| children = { | ||
| LabelWidget{ | ||
| labelScheme = 'placement', | ||
| labelType = 'legend-undecided', | ||
| children = 1 | ||
| }, | ||
| Html.Span{children = {'Placement undecided'}} | ||
| } | ||
| } or nil | ||
| ) | ||
|
|
||
| if Logic.isEmpty(labels) then | ||
| return | ||
| end | ||
|
|
||
| return Html.Div{ | ||
| classes = {'legend-section'}, | ||
| children = labels | ||
| } | ||
| end | ||
|
|
||
| return Component.component(LegendComponent.render) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| .legend { | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 0.5rem; | ||
| min-width: 16.5rem; | ||
| width: fit-content; | ||
| max-width: 100%; | ||
| border: 1px solid var( --clr-on-surface-light-primary-12 ); | ||
| border-radius: 0.5rem; | ||
| padding: 0.5rem; | ||
| background-color: var( --clr-primary-100 ); | ||
| font-size: 0.75rem; | ||
|
|
||
| .theme--dark & { | ||
| border-color: var( --clr-on-surface-dark-primary-8 ); | ||
| background-color: var( --clr-on-surface-dark-primary-8 ); | ||
| } | ||
|
|
||
| @media ( max-width: 435px ) { | ||
| width: 100% !important; | ||
| } | ||
|
|
||
| &-header { | ||
| display: grid; | ||
| grid-template-columns: min-content auto min-content; | ||
| align-items: center; | ||
| align-content: center; | ||
| gap: 0.25rem; | ||
| font-weight: bold; | ||
| color: var( --clr-secondary-16 ); | ||
|
|
||
| .theme--dark & { | ||
| color: var( --clr-secondary-90 ); | ||
| } | ||
|
|
||
| > :first-child { | ||
| grid-column: 1 / -2; | ||
| display: grid; | ||
| grid-template-columns: subgrid; | ||
| margin-left: 0.5rem; | ||
| align-items: center; | ||
| } | ||
|
|
||
| .general-collapsible-default-toggle { | ||
| min-width: unset; | ||
|
|
||
| .general-collapsible-expand-button, | ||
| .general-collapsible-expand-button:visited, | ||
| .general-collapsible-collapse-button, | ||
| .general-collapsible-collapse-button:visited { | ||
| outline: unset; | ||
| color: var( --clr-secondary-7 ); | ||
|
|
||
| .theme--dark & { | ||
| color: var( --clr-secondary-90 ); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| &-section { | ||
| display: grid; | ||
| grid-template-columns: min-content auto; | ||
| column-gap: 0.25rem; | ||
|
|
||
| & + &::before { | ||
| display: block; | ||
| grid-column: 1 / -1; | ||
| content: ""; | ||
| width: 100%; | ||
| border: 0; | ||
| border-top: 0.125rem solid var( --clr-on-surface-light-primary-8 ); | ||
| padding: 0; | ||
| position: relative; | ||
| top: -0.25rem; | ||
|
|
||
| .theme--dark & { | ||
| border-color: var( --clr-on-surface-dark-primary-8 ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| &-item { | ||
| display: grid; | ||
| grid-column: 1 / -1; | ||
| grid-template-columns: subgrid; | ||
| } | ||
|
|
||
| &:not( .collapsed ) .should-collapse { | ||
| display: contents; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe to make sure no one adds a bad mapping
(analogous for others)