Template:Calculator button/doc

Creates a button for use with {{Calculator}} widgets. Requires the calculator gadget to be enabled.

Template:Calculator button/doc

Creates a button for use with {{Calculator}} widgets. Requires the calculator gadget to be enabled.

Usage

Upon clicking a button, the button evaluates its formula parameter and inserts the results into the field identified by the for parameter. You can separate multiple for/formula with a semicolon.

For example:

{{calculator button|contents=Add 1|for=x|formula=x+1|type=plain}}. X = {{calculator|type=plain|id=x|default=0}}

Creates

Add 1. X = 0

The contents of a button should only contain non-interactive phrasing content (No links, no <div>. Images are ok)

Repeating buttons

If the delay parameter is set, then the button will repeat every that many seconds. It will repeat until the max iterations parameter is reached or otherwise forever. There is only one button allowed to repeat at a time, so starting one repeating button cancels all other repeating buttons within a calculator container. If the toggle parameter is set then clicking the button a second time stops the iteration. The until parameter can be used to stop the iterations once some formula is true.

You can also use the functions timertime(), timer() timeriterations() in formulas to get information about the current repeating button.

{{calculator button
|id=buttoncount
|type=progressive
|contents=
	{{calculator
		|type=plain
		|formula=timer()
		|mapping={"Start counting":0,"Stop counting": 1}
		|default=Start counting
	}}
|for=y
|formula=y+1
|delay=0.5  <!-- Update every half a second -->
|toggle=1 <!-- Stop counting if we click again -->
|max iterations=40 <!-- Stop if we reach 40. If this is unspecified we'd go forever. -->
}}. I counted up to {{calculator|type=plain|id=y|default=0}} in total. I have been counting for {{calculator|type=plain|formula=timertime(buttoncount)|default=?}} seconds since my last break.

Makes:

Start counting. I counted up to 0 in total. I have been counting for ? seconds since my last break.

Types of buttons

There are many different types of buttons you can make. For codex style buttons, see [1] for best practice on how to use them. Note, the value default refers to the codex "default" styles, it is not the default option. The style of plain buttons may vary between different skins and operating systems.

type normal primary quiet disabled
plain (non-codex) Click me Click me
default Click me Click me Click me Click me
progressive Click me Click me Click me Click me
destructive Click me Click me Click me Click me

There is also support for size parameter that takes "medium" or "large". Medium is recommended unless the button is only a small icon. There is an alt parameter to provide alt text for screen readers. However you should only use it if the text contents of the button don't explain its purpose. Most of the time it is better to just make the button contents descriptive.

Template data

Create a button element that can affect a widget from Template:Calculator

Template parameters

ParameterDescriptionTypeStatus
forfor

id of Calculator field that is the target of this button

Stringrequired
formulaformula

Formula to set the field from the for parameter to

Example
x+1
Stringrequired
contentscontents 1

Contents of the button

Example
Click here
Contentrequired
typetype

Style of button. Default is "plain". The value of "default" means a codex default button, which is not the default of this template

Suggested values
plain default progressive desctructive
Default
plain
Example
progressive
Stringsuggested
altalt

Alt text of button for screen readers. Only use if the text content of the button would not be clear to a screen reader

Stringoptional
classclass

Extra CSS classes to add to the button. If you want this styled like a button even when the gadget is disabled add "cdx-button cdx-button--fake-button cdx-button--fake-button--enabled"

Stringoptional
class-liveclass-live

Extra CSS classes that are only added if the calculator gadget is enabled

Stringoptional
disableddisabled

Formula to determine if the button should be disabled. Button becomes disabled when formula is true

Stringoptional
idid

id of button element

Stringoptional
sizesize

Size of button. medium is default

Suggested values
medium large
Default
medium
Stringoptional
stylestyle

Extra CSS for button

Stringoptional
titletitle

Tooltip for button

Stringoptional
weightweight

Weight of button (Ignored for plain buttons)

Suggested values
normal primary quiet
Default
normal
Example
primary
Stringoptional
rolerole

Aria role for button. Typically you wouldn't need to set this.

Unknownoptional
aria-livearia-live

Value for aria-live attribute. Controls if screen readers announce changes.

Unknownoptional
delaydelay

Make this be a repeating button. How many seconds between each repeat. Must be at least 0.5 seconds.

Numberoptional
max iterationsmax iterations

How many times to repeat a button. Set to 0 to cancel any ongoing repeating button. If not set, then it is considered infinity if delay is set, otherwise 1.

Numberoptional
toggletoggle

If this is a repeating button, if set then when the user clicks the button a second time, it will stop the repeat. Otherwise a second click just restarts the repetition.

Booleanoptional
untiluntil

Repeat this button until this formula is true. delay parameter must also be set.

Unknownoptional


Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.