Number3.0
Installation
npm i @tryg/ui-libraryUsage
Individual only imports the desired component, and only needs to be included once within the application. Which is beneficial to keep the application size small.
<script type="module">
import { defineCustomElement } from '@tryg/ui-library/dist/components/anchor-number';
defineCustomElement();
</script>
<anchor-number name="number-field" max-length="100" >Write a number</anchor-number>Global only needs to be defined once in the application, but it will import all components even the ones that are not in use..
<script type="module">
import { defineCustomElements } from '@tryg/ui-library/dist/loader';
defineCustomElements();
</script>
<anchor-number name="number-field" max-length="100" >Write a number</anchor-number>Disabled
<anchor-number name="number-field" disabled>Write a number</anchor-number>Read Only
<anchor-number name="number-field" readonly>Write a number</anchor-number>Required
If you pass the required property to the input, the input will be required.
<anchor-number name="number-field" required>Write a number</anchor-number>Help text
You can add a helpful text to the input by passing the help-text property.
<anchor-number name="number-field" help-text="This is a help text">Write a number</anchor-number>With Error Message
You can combine the error-prop properties to show an invalid input.
<anchor-number name="number-field" error-prop="This is a error message">Write a number</anchor-number>Message Placements
You can change the position of the label by setting the messagePlacement property to inside, or below.
<anchor-number error-prop="This is a error message">Hello</anchor-number>Note
If the label is not passed, the messagePlacement property will be outside by default.
Controlled
You can use the value and onValueChange properties to control the input value.
<script type="text/javascript">
window.addEventListener("load", (event) => {
document.querySelector('anchor-input').addEventListener('inputevent', function(data) {
document.querySelector('#input-preview').innerHTML = data.detail.value
})
});
</script>
<anchor-input>Your number please</anchor-input>
<div id="input-preview"></div>Accessibility
- Built with a native
<input>element. - Visual and ARIA labeling support.
aria-liveattribute for the input field.aria-describedbyattribute for the input field.aria-activedescendantattribute for the input field.
- Change, clipboard, composition, selection, and input event support.
- Required and invalid states exposed to assistive technology via ARIA.
aria-requiredattribute automatically set ifrequiredprop is set.aria-invalidattribute automatically set iferror-propprop is set.
- Support for description and error message help text linked to the input via ARIA.
API
anchor-number
Properties
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
disabled | disabled | Disable the number field | boolean | false |
errorProp | error-prop | Show an error message | string | '' |
filled | filled | Show a checkmark icon when the number field has been succesfully filled | boolean | false |
helpText | help-text | Show a help text | string | '' |
hideSpinButtons | hide-spin-buttons | Hide spin button when using type="number". | boolean | undefined |
icon | icon | Add an icon at the right side of the input field, by putting in the name of an Anchor icon | "activity" | "airplay" | "alarm" | "alert-circle" | "alert-octagon" | "alert-triangle" | "align-center" | "align-justify" | "align-left" | "align-right" | "anchor" | "aperture" | "archive" | "arrow-down" | "arrow-down-circle" | "arrow-down-left" | "arrow-down-right" | "arrow-left" | "arrow-left-circle" | "arrow-right" | "arrow-right-circle" | "arrow-up" | "arrow-up-circle" | "arrow-up-left" | "arrow-up-right" | "at-sign" | "award" | "band-aid" | "bar-chart" | "bar-chart-2" | "basket" | "battery" | "battery-charging" | "bell" | "bell-off" | "bluetooth" | "bold" | "bonus-tryghedsgruppen" | "book" | "book-open" | "bookmark" | "box" | "briefcase" | "calculator" | "calendar" | "camera" | "camera-off" | "cast" | "check" | "check-circle" | "check-square" | "chevron-down" | "chevron-left" | "chevron-right" | "chevron-up" | "chevrons-down" | "chevrons-left" | "chevrons-right" | "chevrons-up" | "chrome" | "circle" | "clipboard" | "clock" | "cloud" | "cloud-drizzle" | "cloud-lightning" | "cloud-off" | "cloud-rain" | "cloud-snow" | "code" | "codepen" | "codesandbox" | "coffee" | "columns" | "command" | "company" | "compass" | "copy" | "corner-down-left" | "corner-down-right" | "corner-left-down" | "corner-left-up" | "corner-right-down" | "corner-right-up" | "corner-up-left" | "corner-up-right" | "cpu" | "credit-card" | "crop" | "crosshair" | "database" | "delete" | "disc" | "divide" | "divide-circle" | "divide-square" | "dollar-sign" | "download" | "download-cloud" | "dribbble" | "droplet" | "edit" | "edit-2" | "edit-3" | "external-link" | "eye" | "eye-off" | "facebook" | "fast-forward" | "feather" | "figma" | "file" | "file-minus" | "file-pdf" | "file-plus" | "file-text" | "film" | "filter" | "flag" | "folder" | "folder-minus" | "folder-plus" | "framer" | "frown" | "gift" | "git-branch" | "git-commit" | "git-merge" | "git-pull-request" | "github" | "gitlab" | "globe" | "grid" | "hard-drive" | "hash" | "headphones" | "heart" | "help-circle" | "hexagon" | "home" | "image" | "inbox" | "info" | "instagram" | "italic" | "key" | "layers" | "layout" | "life-buoy" | "link" | "link-2" | "linkedin" | "list" | "loader" | "lock" | "log-in" | "log-out" | "mail" | "map" | "map-pin" | "maximize" | "maximize-2" | "megaphone" | "meh" | "menu" | "message-circle" | "message-square" | "mic" | "mic-off" | "minimize" | "minimize-2" | "minus" | "minus-circle" | "minus-square" | "monitor" | "moon" | "more-horizontal" | "more-vertical" | "mouse-pointer" | "move" | "music" | "navigation" | "navigation-2" | "octagon" | "offer" | "package" | "paperclip" | "pause" | "pause-circle" | "pen-tool" | "percent" | "phone" | "phone-call" | "phone-forwarded" | "phone-incoming" | "phone-missed" | "phone-off" | "phone-outgoing" | "pie-chart" | "play" | "play-circle" | "plus" | "plus-circle" | "plus-square" | "pocket" | "power" | "printer" | "radio" | "refresh-ccw" | "refresh-cw" | "repeat" | "rewind" | "rotate-ccw" | "rotate-cw" | "rss" | "save" | "scissors" | "search" | "send" | "server" | "settings" | "share" | "share-2" | "shield" | "shield-off" | "shopping-bag" | "shopping-cart" | "shuffle" | "sidebar" | "skip-back" | "skip-forward" | "slack" | "slash" | "sliders" | "smartphone" | "smile" | "speaker" | "sprout" | "square" | "star" | "star-filled" | "stop-circle" | "storm" | "sun" | "sunrise" | "sunset" | "table" | "tablet" | "tag" | "target" | "terminal" | "thermometer" | "thumbs-down" | "thumbs-up" | "toggle-left" | "toggle-right" | "tool" | "trash" | "trash-2" | "trello" | "trending-down" | "trending-up" | "triangle" | "truck" | "trygfonden" | "tv" | "twitch" | "twitter" | "type" | "umbrella" | "underline" | "unlock" | "upload" | "upload-cloud" | "user" | "user-check" | "user-minus" | "user-plus" | "user-x" | "users" | "video" | "video-off" | "voicemail" | "volume" | "volume-1" | "volume-2" | "volume-x" | "watch" | "wifi" | "wifi-off" | "wind" | "x" | "x-circle" | "x-octagon" | "x-square" | "youtube" | "zap" | "zap-off" | "zoom-in" | "zoom-out" | undefined |
iconPlacement | icon-placement | Should the icon be inside or outside the input field | "inside" | "outside" | 'inside' |
label | label | Show the label (you can't currently disable the label) | boolean | true |
labelPlacement | label-placement | Placement of the label | "left" | "top" | 'top' |
maxLength | max-length | Set a max width in characters for the number field. | number | undefined |
name | name | The name of the number field | string | '' |
placeholder | placeholder | Placeholder text is shown until the user interacts with the number field | string | '' |
readonly | readonly | Set the field to be read only | boolean | false |
required | required | Mark the field as required | boolean | false |
size | size | Set a fixed width in characters for the number field. | number | null |
spinners | spinners | "big" | "none" | "small" | 'none' | |
tooltipText | tooltip-text | Add an info icon with a tooltip to the right of the label | string | '' |
type | type | The input type of the number field | string | 'text' |
validityMissingValueText | validity-missing-value-text | Text to be displayed if when value is missing an native form validation is used | string | undefined |
value | value | The value in the number field. Use this to set a value | number | string | null |
warning | warning | Show a warning message | string | '' |
Events
| Event | Description | Type |
|---|---|---|
blurevent | Event emitted when the user blurs the input field | CustomEvent<any> |
clearevent | Event emitted when the user clears the input field | CustomEvent<any> |
focusevent | Event emitted when the user is focusing the input field | CustomEvent<any> |
inputChange | Event emitted when the input is changed. Only triggers when focus leaves the input. | CustomEvent<EventDetail> |
inputevent | Event emitted when the user is inputting something into the input field | CustomEvent<EventDetail> |
CSS Custom Properties
| Name | Description |
|---|---|
--number-input-border-color | Set the border color of the number input. |
--number-input-border-color-disabled | Set the border color of the number input when disabled. |
--number-input-border-color-error | Set the border color of the number input for error states. |
--number-input-border-color-focus | Set the border color of the number input when focused. |
--number-input-border-color-hover | Set the border color of the number input on hover. |
--number-input-border-color-readonly | Set the border color of the number input when readonly. |
--number-input-border-color-warning | Set the border color of the number input for warning states. |
--number-input-border-width | Set the border width of the number input. |
--number-input-max-width | Set the max width of the number input. |
--number-input-padding-bottom | Set the bottom padding of the number input. |
--number-input-padding-left | Set the left padding of the number input. |
--number-input-padding-right | Set the right padding of the number input. |
--number-input-padding-top | Set the top padding of the number input. |
--number-input-width | Set the width of the number input. |
Dependencies
Depends on
Graph
Built with StencilJS
| Anchor version | Status | Notes |
|---|---|---|
| 3.0 | Ready for Implementation | This component is in sync with Figma. |
