Jump to content
Toggle menu
  • 8 articles
  • 75 files
  • 7 users
  • 37.8K edits
Neodyland Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Clickable button/doc: Difference between revisions

From Neodyland Wiki
m 27 revisions imported
 
(16 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{documentation subpage}} {{copied from wikipedia}}
{{documentation subpage}} {{copied from wikipedia}}
{{Module rating|release}}
{{template rating|beta}}
<div style="background-color: var(--background-color-neutral-subtle); width: auto; padding: 0.2em 0.5em; margin: 4px 10%; border: 1px solid var(--border-color-disabled)">'''Shortcuts:''' {{mdl|module=Clickable button}}</div>
{{lua|Module:Arguments|Module:Yesno|Module:Check for unknown parameters|Module:If preview}}
{{uses templatestyles|Module:Clickable button/styles.css|Module:Clickable button/icons.css}}
{{mbox|type=message|text='''Shortcuts:'''{{nbsp}}{{mdl|module=Clickable button}}|image=none}}


'''Generates wikitext to render the a clickable button'''. Renders the button component from the [[wmdoc:codex/latest|Codex design system for Wikimedia]]. Includes helper functions for URL parsing and cleaning, adding tracking categories. Intended for use in templates and other modules. Implements [[Template:Clickable button]] and others. Supports legacy parameters.
'''Generates wikitext for clickable Codex button'''. Renders the [[wmdoc:codex/latest/components/demos/button.html|button component]] from the [[wmdoc:codex/latest|Codex design system for Wikimedia]]. Includes helper functions for URL parsing and cleaning, adding tracking categories. Intended for use in templates and other modules. Implements [[Template:Clickable button]] and others. Supports legacy parameters.
* Options to include an icon from the list in [[Template:Clickable button/styles.css]]
* Options to include an icon or create an icon-only button.
* Create an icon-only or a dummy button (no target link/URL)
* Target a URL or a wikilink
* Target a URL or a wikilink
* Set the weight, size and state of the button (enabled or disabled).
* Set the weight, size and state of the button (enabled or disabled).
* Dummy button creation can be disabled.


'''For more information on appropriate usage of UI buttons, see [[wmdoc:codex/latest/components/demos/button.html|the Codex documentation]].'''
<ul style="list-style-type: circle;">
<li> Inserts two CSS files. [[Module:Clickable button/styles.css]] is required and makes minor tweaks for word-wrapping if the visible label is too long, centering or aligning button left or right, and minimum widths as is needed for icon-only buttons and labels containing two characters or less.</li>
<li> The second CSS file, [[Module:Clickable button/icons.css]], is prepended to the button's HTML only if an icon is used.</li>
<li> Supports legacy parameters from previous templates.</li>
</ul>
== Usage in wikitext ==
== Usage in wikitext ==
Input is case-'''in'''sensitive.
Some arguments are case-'''in'''sensitive.
<syntaxhighlight lang=wikitext>{{#invoke:Clickable button|main
<syntaxhighlight lang=wikitext>{{#invoke:Clickable button|main
| 1       = <!-- Alias for wikilink -->
| 1       = <!-- Alias for wikilink -->
| 2       = <!-- Alias for label -->
| 2       = <!-- Alias for label -->
| label   = <!-- Button label -->
| label   = <!-- Button visible text label -->
| link   = <!-- Wikilink -->
| link     = <!-- Target wikilink -->
| url     = <!-- URL -->
| url     = <!-- Target external URL -->
<!-- Inputs are case-insensitive -->
<!-- Inputs action, weight, size, and icon are case-insensitive -->
| action = <!-- progressive | destructive | default: default. -->
| action   = <!-- progressive | destructive | default: default. -->
| weight = <!-- primary | quiet | default: normal. -->
| weight   = <!-- primary | quiet | default: normal. -->
| size   = <!-- small | large | default: medium. Automatically chooses size based on line-height and device. -->
| size     = <!-- small | large | default: medium. Automatically chooses size based on line-height and device. -->
| icon   = <!-- Per stored icon-list in [[Template:Clickable button/styles.css]] e.g., search  -->
| icon     = <!-- Name of icon, stored in [[Module:Clickable button/icons.css]] e.g., search  -->
| disabled = <!-- `true` or any other true value like `1` or `yes`. -->
| aria-label = <!-- [[w:ARIA]] label for accessibility DOM tree. -->
| aria-label = <!-- [[w:ARIA]] label for accessibility DOM tree. -->
| nocat      = <!-- `true` to not auto-categorize. -->
| nocat      = <!-- `true` to not auto-categorize. -->
| category   = <!-- Category name e.g., [[Category:Name]] or Category:Name or just Name -->
<!-- Others -->
| category = <!-- Category name e.g., Category:Name or Name or [[Category:Name]] -->
| class    = <!-- Custom CSS class without quotation marks -->
| style    = <!-- Custom CSS styling without quotation marks -->
<!-- Legacy arguments -->
| color    = <!-- blue | red -->  
}}</syntaxhighlight>
}}</syntaxhighlight>


== Usage in other modules ==
== Usage in other modules ==
Ensure you know what to expect from the function you are calling.
Ensure you know what to expect from the function you call from another module.
* <syntaxhighlight inline lang=lua>function main</syntaxhighlight> emits a TemplateStyles call and pre-processes the arguments with [[Module:Arguments]] first, e.g. ignore blank values <code style="color: var(--color-destructive);">'<nowiki/>'</code>.
* <syntaxhighlight inline lang=lua>function p.main(frame)</syntaxhighlight> emits TemplateStyles for the CSS files with the wikitext, and pre-processes the arguments in a <syntaxhighlight inline lang=lua>frame</syntaxhighlight> using [[Module:Arguments]], e.g. ignore blank values<code style="color: var(--color-destructive);">'<nowiki/>'</code>, and trim trailing whitespace.
* <syntaxhighlight inline lang=lua>function _main</syntaxhighlight> Parses the arguments to account for use of legacy parameters and decides whether <code class="mw-highlight mw-highlight-lang-lua"><span class=nv>aria-disabled</span></code> should be <code class="mw-highlight mw-highlight-lang-lua"><span class=kc>true</span></code>.
* <syntaxhighlight inline lang=lua>function p._main(arguments)</syntaxhighlight> Parses the arguments such as lowercase appropriate arguments, account for use of legacy parameters and decides whether <code class="mw-highlight mw-highlight-lang-lua"><span class=nv>aria-disabled</span></code> should be <code class="mw-highlight mw-highlight-lang-lua"><span class=kc>true</span></code>.
* The module's other functions, such as <code class="mw-highlight mw-highlight-lang-lua"><span class="nf">_renderLinkData</span></code> and <code class="mw-highlight mw-highlight-lang-lua"><span class="nf">renderLink</span></code>, are localised and would need to be made global first to be accessible to other modules.
* <syntaxhighlight inline lang=lua>function p.url(url, [label])</syntaxhighlight> is available, not for button creation, but as an adaption of [[Module:URL]] to clean and normalise a URL string and optionally generate a label.
To call <code class="mw-highlight mw-highlight-lang-lua"><span class="nf">main</span></code> for example, use:
* The module's other functions, such as <syntaxhighlight inline lang=lua>makeLinkData()</syntaxhighlight> and <syntaxhighlight inline lang=lua>renderLink()</syntaxhighlight>, are localised/local to the module and would need to be made global first to be accessible to other modules.
To call <syntaxhighlight inline lang=lua>p.main()</syntaxhighlight> for example, use:
<!-- {{codesample-header|myLuaModule.lua}} -->
<!-- {{codesample-header|myLuaModule.lua}} -->
<syntaxhighlight lang=lua>local createButton = require( 'Module:Clickable button/sandbox' )
<syntaxhighlight lang=lua>local createButton = require( 'Module:Clickable button/sandbox' )
Line 39: Line 55:
     label = 'Go to South Africa',
     label = 'Go to South Africa',
     action = 'progressive'
     action = 'progressive'
     weight = 'quiet',
     weight = 'default',
     size = 'medium',
     size = 'medium',
     icon = 'link',
     icon = 'link-external',
    disabled = true
} )  
} )
return buttonWikitext</syntaxhighlight>
return buttonWikitext</syntaxhighlight>
which generates wikitext such the value of <code class="mw-highlight mw-highlight-lang-lua"><span class="nv">buttonWikitext</span></code> would be:
<div style="text-align:center;">{{#invoke:Clickable button|main|link = South Africa|
<syntaxhighlight lang=wikitext><templatestyles src="Template:Clickable button/styles.css" /><templatestyles src="Template:Clickable button/icons.css" /><span class="cdx-button cdx-button--fake-button cdx-button--action-progressive cdx-button--weight-quiet cdx-button--size-medium cdx-button--fake-button--disabled" role="button" aria-disabled="true"><span class="cdx-button__icon cdx-demo-css-icon--link" aria-hidden="true"></span>Go to South Africa</span> [[Category:Pages using disabled dummy button]]</syntaxhighlight>
    label = Go to South Africa|
    action = progressive|
    weight = default|
    size = medium|
    icon = link-external}}</div>
and the value of <code class="mw-highlight mw-highlight-lang-lua"><span class="nv">buttonWikitext</span></code> would be:
<syntaxhighlight lang=wikitext><<templatestyles src="Module:Cdx-button/styles.css" /><templatestyles src="Module:Cdx-button/icons.css" /><span class="cdx-button cdx-button--fake-button cdx-button--action-progressive cdx-button--weight-quiet cdx-button--size-medium" role="button" aria-disabled="false"><span class="cdx-button__icon cdx-demo-css-icon--link-external" aria-hidden="true"></span>Go to South Africa</span></syntaxhighlight>
 
Function <code class="mw-highlight mw-highlight-lang-lua"><span class="nf">_main</span></code> would output:
<syntaxhighlight lang=wikitext><span class="cdx-button cdx-button--fake-button cdx-button--action-progressive cdx-button--weight-quiet cdx-button--size-medium" role="button" aria-disabled="false"><span class="cdx-button__icon cdx-demo-css-icon--link-external" aria-hidden="true"></span>Go to South Africa</span></syntaxhighlight>
As a result, unless a CSS file is added to give the appropriate class an icon, the icon will not render.
 
== Implementation ==
=== Length of visible label <span id="Button label length"></span> ===
 
See [[wmdoc:codex/latest/components/demos/button.html|the Codex button component documentation]].


<includeonly>
<includeonly>
<!-- Categories go here. -->
<!-- Categories go here. -->
</includeonly>
</includeonly>

Latest revision as of 17:55, 12 August 2026

Template:Template rating

Template:Uses templatestyles

Generates wikitext for clickable Codex button. Renders the button component from the Codex design system for Wikimedia. Includes helper functions for URL parsing and cleaning, adding tracking categories. Intended for use in templates and other modules. Implements Template:Clickable button and others. Supports legacy parameters.

  • Options to include an icon or create an icon-only button.
  • Target a URL or a wikilink
  • Set the weight, size and state of the button (enabled or disabled).
  • Dummy button creation can be disabled.

For more information on appropriate usage of UI buttons, see the Codex documentation.

  • Inserts two CSS files. Module:Clickable button/styles.css is required and makes minor tweaks for word-wrapping if the visible label is too long, centering or aligning button left or right, and minimum widths as is needed for icon-only buttons and labels containing two characters or less.
  • The second CSS file, Module:Clickable button/icons.css, is prepended to the button's HTML only if an icon is used.
  • Supports legacy parameters from previous templates.

Usage in wikitext

edit

Some arguments are case-insensitive.

{{#invoke:Clickable button|main
| 1        = <!-- Alias for wikilink -->
| 2        = <!-- Alias for label -->
| label    = <!-- Button visible text label -->
| link     = <!-- Target wikilink -->
| url      = <!-- Target external URL -->
<!-- Inputs action, weight, size, and icon are case-insensitive -->
| action   = <!-- progressive | destructive | default: default. -->
| weight   = <!-- primary | quiet | default: normal. -->
| size     = <!-- small | large | default: medium. Automatically chooses size based on line-height and device. -->
| icon     = <!-- Name of icon, stored in [[Module:Clickable button/icons.css]] e.g., search  -->
| disabled = <!-- `true` or any other true value like `1` or `yes`. -->
| aria-label = <!-- [[w:ARIA]] label for accessibility DOM tree. -->
| nocat      = <!-- `true` to not auto-categorize. -->
<!-- Others -->
| category = <!-- Category name e.g., Category:Name or Name or [[Category:Name]] -->
| class    = <!-- Custom CSS class without quotation marks -->
| style    = <!-- Custom CSS styling without quotation marks -->
<!-- Legacy arguments -->
| color    = <!-- blue | red --> 
}}

Usage in other modules

edit

Ensure you know what to expect from the function you call from another module.

  • function p.main(frame) emits TemplateStyles for the CSS files with the wikitext, and pre-processes the arguments in a frame using Module:Arguments, e.g. ignore blank values'', and trim trailing whitespace.
  • function p._main(arguments) Parses the arguments such as lowercase appropriate arguments, account for use of legacy parameters and decides whether aria-disabled should be true.
  • function p.url(url, [label]) is available, not for button creation, but as an adaption of Module:URL to clean and normalise a URL string and optionally generate a label.
  • The module's other functions, such as makeLinkData() and renderLink(), are localised/local to the module and would need to be made global first to be accessible to other modules.

To call p.main() for example, use:

local createButton = require( 'Module:Clickable button/sandbox' )
buttonWikitext = createButton.main( {
    link = 'South Africa',
    label = 'Go to South Africa',
    action = 'progressive'
    weight = 'default',
    size = 'medium',
    icon = 'link-external',
} ) 
return buttonWikitext

and the value of buttonWikitext would be:

<<templatestyles src="Module:Cdx-button/styles.css" /><templatestyles src="Module:Cdx-button/icons.css" /><span class="cdx-button cdx-button--fake-button cdx-button--action-progressive cdx-button--weight-quiet cdx-button--size-medium" role="button" aria-disabled="false"><span class="cdx-button__icon cdx-demo-css-icon--link-external" aria-hidden="true"></span>Go to South Africa</span>

Function _main would output:

<span class="cdx-button cdx-button--fake-button cdx-button--action-progressive cdx-button--weight-quiet cdx-button--size-medium" role="button" aria-disabled="false"><span class="cdx-button__icon cdx-demo-css-icon--link-external" aria-hidden="true"></span>Go to South Africa</span>

As a result, unless a CSS file is added to give the appropriate class an icon, the icon will not render.

Implementation

edit

Length of visible label

edit

See the Codex button component documentation.


Cookies help us deliver our services. By using our services, you agree to our use of cookies.