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
No edit summary
No edit summary
Line 1: Line 1:
{{documentation subpage}} {{copied from wikipedia}}
{{documentation subpage}} {{copied from wikipedia}}
{{template rating|beta}}
{{template rating|beta}}
{{lua|Module:Arguments|Module:Yesno|Module:Neturl|Module:Check for unknown parameters|Module:If preview}}
{{lua|Module:Arguments|Module:Yesno|Module:Check for unknown parameters|Module:If preview}}
{{uses templatestyles|Template:Clickable button/base.css|Template:Clickable button/styles.css}}
{{uses templatestyles|Template:Clickable button/styles.css|Template:Clickable button/icons.css}}
<div style="display:flex; 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:'''{{nbsp}}{{mdl|module=Clickable button}}</div>
{{mbox|type=message|text='''Shortcuts:'''{{nbsp}}{{mdl|module=Clickable button}}|image=none}}


'''Generates wikitext to render the a clickable 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.
'''Generates wikitext to render the a clickable 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 from the list in [[Template:Clickable button/icons.css]]
* Target a URL or a wikilink
* Create an icon-only or a dummy button (no target link/URL)
* Create an icon-only or a dummy button (no target link/URL)
* 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).
<hr/>
<hr/>
<ul style="list-style-type: circle;">
<ul style="list-style-type: circle;">
<li> It has two CSS files. [[Template:Clickable button/base.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 two characters or less.</li>
<li> It has two CSS files. [[Template: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 two characters or less.</li>
<li> The second CSS file, [[Template:Clickable button/styles.css]], is prepended to the button's HTML only if an icon is used.</li>
<li> The second CSS file, [[Template:Clickable button/icons.css]], is prepended to the button's HTML only if an icon is used.</li>
</ul>
</ul>
== Usage in wikitext ==
== Usage in wikitext ==
Input is case-'''in'''sensitive.
Input is 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 label -->
| link   = <!-- Wikilink -->
| link     = <!-- Wikilink -->
| url     = <!-- URL -->
| url     = <!-- URL -->
<!-- Inputs are case-insensitive -->
<!-- Inputs 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  -->
| disabled = <!-- `true` or any other true value like `1` or `yes`. -->
| icon     = <!-- Per stored icon-list in [[Template:Clickable button/icons.css]] e.g., search  -->
| 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 Category:Name or just Name -->
| class    = <!-- Custom CSS class -->
| style    = <!-- Custom CSS styling -->
}}</syntaxhighlight>
}}</syntaxhighlight>



Revision as of 05:16, 25 September 2025

Template:Template rating

Template:Uses templatestyles

Generates wikitext to render the a clickable 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 from the list in Template:Clickable button/icons.css
  • Target a URL or a wikilink
  • Create an icon-only or a dummy button (no target link/URL)
  • Set the weight, size and state of the button (enabled or disabled).

  • It has two CSS files. Template: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 two characters or less.
  • The second CSS file, Template:Clickable button/icons.css, is prepended to the button's HTML only if an icon is used.

Usage in wikitext

Input is case-insensitive.

{{#invoke:Clickable button|main
| 1        = <!-- Alias for wikilink -->
| 2        = <!-- Alias for label -->
| label    = <!-- Button label -->
| link     = <!-- Wikilink -->
| url      = <!-- URL -->
<!-- Inputs 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. -->
| disabled = <!-- `true` or any other true value like `1` or `yes`. -->
| icon     = <!-- Per stored icon-list in [[Template:Clickable button/icons.css]] e.g., search  -->
| aria-label = <!-- [[w:ARIA]] label for accessibility DOM tree. -->
| nocat      = <!-- `true` to not auto-categorize. -->
<!-- Others -->
| category = <!-- Category name e.g., [[Category:Name]] or Category:Name or just Name -->
| class    = <!-- Custom CSS class -->
| style    = <!-- Custom CSS styling -->
}}

Usage in other modules

Ensure you know what to expect from the function you are calling.

  • function main emits a TemplateStyles call and pre-processes the arguments with Module:Arguments first, e.g. ignore blank values ''.
  • function _main Parses the arguments to account for use of legacy parameters and decides whether aria-disabled should be true.
  • The module's other functions, such as _renderLinkData and renderLink, are localised and would need to be made global first to be accessible to other modules.

To call 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 = 'quiet',
    size = 'medium',
    icon = 'link',
    disabled = true
} )
return buttonWikitext

which generates wikitext such the value of buttonWikitext would be:

<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]]

Function _main would output:

<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]]

And as a result, unless a templatestyle is added to give the class an icon, the icon would not render.

Implementation

Length of visible label

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