Module:Clickable button/doc: Difference between revisions
From Neodyland Wiki
More actions
| Line 35: | Line 35: | ||
<!-- {{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' ) | ||
buttonWikitext = createButton( { | buttonWikitext = createButton.main( { | ||
link = 'South Africa', | link = 'South Africa', | ||
label = 'Go to South Africa', | label = 'Go to South Africa', | ||
| Line 42: | Line 42: | ||
size = 'medium', | size = 'medium', | ||
icon = 'link', | icon = 'link', | ||
disabled = true | |||
} ) | } ) | ||
return buttonWikitext</syntaxhighlight> | return buttonWikitext</syntaxhighlight> | ||
which generates the wikitext: | which generates the wikitext: | ||
<syntaxhighlight lang=wikitext><templatestyles src="Template:Clickable button/styles.css" /><templatestyles src="Template:Clickable button/icons.css" /> | <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> | ||
<includeonly> | <includeonly> | ||
<!-- Categories go here. --> | <!-- Categories go here. --> | ||
</includeonly> | </includeonly> | ||
Revision as of 20:40, 22 September 2025
Shortcuts: Module:Clickable button (talk · edit · hist · links · doc · subpages · tests / results · sandbox · all modules)
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/styles.css
- 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).
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. -->
| icon = <!-- Per stored icon-list in [[Template:Clickable button/styles.css]] e.g., search -->
| aria-label = <!-- [[w:ARIA]] label for accessibility DOM tree. -->
| nocat = <!-- `true` to not auto-categorize. -->
| category = <!-- Category name e.g., [[Category:Name]] or Category:Name or just Name -->
}}
Usage in other modules
Ensure you know what to expect from the function you are calling.
function mainemits a TemplateStyles call and pre-processes the arguments with Module:Arguments first, e.g. ignore blank values''.function _mainParses the arguments to account for use of legacy parameters and decides whetheraria-disabledshould betrue.- The module's other functions, such as
_renderLinkDataandrenderLink, 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 the 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]]