Skip to content

Currency

Currency widgets are Input Fields that allow the user to enter monetary values, displaying a formatted currency string over the input when inactive.

currency.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.inputs.currency('price', {
label: 'Price',
}),
];

Use these props to customize your Currency widget.

proptypedescription
placeholderstringA placeholder text to display when the currency input has no value
hintstringA description to display below the currency input
iconstringA css class to display an icon inside the input
currencystringThe ISO 4217 currency code (e.g., USD, EUR) to format the number as currency
stepnumberNumeric step size for user input
maximumFractionDigitsnumberMaximum number of decimal places to include in the formatted string
minimumFractionDigitsnumberMinimum number of decimal places to include in the formatted string
autocompletestring'on', 'off', or a space-separated list of W3C autofill tokens

Use the property placeholder to add a placeholder.

currency.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.inputs.currency('price', {
placeholder: 'Enter the amount',
label: 'Price',
}),
];

Use the property hint to add a description.

currency.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.inputs.currency('price', {
hint: 'Please enter the price in USD.',
label: 'Price',
}),
];

Use the property icon to add an icon to the widget. The value of icon represents a set of CSS classes separated by spaces. The icon is displayed inside the input field.

currency.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.inputs.currency('price', {
icon: 'attach_money',
label: 'Price',
}),
];

Use the properties currency, minimumFractionDigits, and maximumFractionDigits to tightly control how the monetary value is parsed and formatted when not actively being edited. Default for minimum fraction digits is usually 2.

currency.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.inputs.currency('price', {
currency: 'EUR',
minimumFractionDigits: 2,
maximumFractionDigits: 4,
label: 'Price (EUR)',
}),
];

Use the properties minimumFractionDigits and maximumFractionDigits to specify the exact number of decimal places for the formatted currency display.

currency.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.inputs.currency('price_high', {
currency: 'USD',
minimumFractionDigits: 4,
maximumFractionDigits: 6,
label: 'High Precision (4-6 digits)',
uid: 'currency-precision-high',
}),
gui.inputs.currency('price_low', {
currency: 'USD',
minimumFractionDigits: 0,
maximumFractionDigits: 0,
label: 'No Decimals',
uid: 'currency-precision-low',
}),
];

Use the step property to define the increment size for numeric input via keyboard (arrows) or browser controls.

currency.ts
import { gui } from '@golemui/gui-shared';
export default [
gui.inputs.currency('amount', {
currency: 'USD',
step: 5.5,
label: 'Amount (Step 5.50)',
uid: 'currency-step',
}),
];

Currency inputs can be styled as explained in the Styling Guide.

Following you will find a list with the CSS Variables and a quick description of what you will style.

CSS VariableDescription
--gui-bg-defaultFormatted value text background over input
--gui-font-smFormatted value text and hint font size
--gui-space-10Icon left padding or inline-start space
--gui-intent-errorBorder and text color when invalid
--gui-radius-mdInput radius
--gui-border-defaultInput border color
--gui-bg-surfaceInput background color
--gui-text-defaultInput text color

This is the anatomy of the Currency Widget in case you want to use your CSS styles.

currency-anatomy.html
<gui-currency>
<label for="fieldUid">
Label
<div class="gui-currency__hint" id="fieldUid_hint">Hint</div>
</label>
<div class="gui-widget">
<input
type="number"
inputmode="decimal"
id="fieldUid"
class="gui-currency--icon"
placeholder="Custom placeholder"
aria-required="true"
aria-describedby="fieldUid_hint"
/>
<label
for="fieldUid"
class="gui-currency__format-value gui-currency__format-value--icon"
>$1,111.10</label>
<span class="gui-widget-icon attach_money"></span>
</div>
</gui-currency>