Skip to content

Currency

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

currency.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'currency',
path: 'price',
label: 'Price',
},
],
});

Use these props to customize your Currency component.

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 { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'currency',
path: 'price',
label: 'Price',
props: {
placeholder: 'Enter the amount',
},
},
],
});

Use the property hint to add a description.

currency.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'currency',
path: 'price',
label: 'Price',
props: {
hint: 'Please enter the price in USD.',
},
},
],
});

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

currency.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'currency',
path: 'price',
label: 'Price',
props: {
icon: 'attach_money',
},
},
],
});

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 { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
kind: 'input',
type: 'currency',
path: 'price',
label: 'Price (EUR)',
props: {
currency: 'EUR',
minimumFractionDigits: 2,
maximumFractionDigits: 4,
},
},
],
});

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

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

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

currency.ts
import { golemForm } from '@golemui/gui-shared';
export default golemForm().create({
form: [
{
uid: 'currency-step',
kind: 'input',
type: 'currency',
path: 'amount',
label: 'Amount (Step 5.50)',
props: {
currency: 'USD',
step: 5.5,
},
},
],
});

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