import { styleProps } from "./Input"; export default { name: "Number Input", acceptsChildren: false, category: "Input", styleProps: styleProps, props: [ { label: "Initial Value", name: "defaultValue", type: { kind: "number", isDynamic: true }, isDefault: true, default: "", placeholder: "Enter a number...", help: "The input's default value", }, { label: "Placeholder", name: "placeholder", type: { kind: "text", isDynamic: true }, isDefault: true, default: "Enter a number...", placeholder: "Enter a placeholder...", help: "The placeholder text to display", }, { label: "Required", name: "required", type: { kind: "boolean" }, isDefault: true, default: false, placeholder: "", help: "The is this value required by a form?", }, { label: "Minimum Value", name: "min", type: { kind: "number", isDynamic: true }, default: "", placeholder: "Enter a number...", help: "The minimum value allowed", }, { label: "Maximum Value", name: "max", type: { kind: "number", isDynamic: true }, default: "", placeholder: "Enter a number...", help: "The maximum value allowed", }, { label: "Step", name: "step", type: { kind: "number", isDynamic: true }, default: "", placeholder: "Enter a number...", help: "The step value for the input", }, { label: "Hide Controls", name: "hideControls", type: { kind: "boolean" }, default: false, placeholder: "", help: "Set to true to hide the controls", }, { label: "Is disabled", name: "disabled", type: { kind: "boolean", isDynamic: true }, default: false, placeholder: "", help: "Whether the input is disabled", }, ], events: [ { label: "When changed", name: "onChange", offerDebounce: true, help: "Select an action to run when input's value has changed", }, { label: "When focused", name: "onFocus", help: "Select an action to run when input's has focused", }, { label: "When blurred", name: "onBlur", isDefault: true, help: "Select an action to run when input's has blurred", }, ], defaultStyles: { ":focus-visible": { "outline-width": "1px", "outline-style": "solid", "outline-color": "var(--palette-ring)", }, ":user-invalid": { "border-color": "var(--theme-border-error)", }, ":disabled": { opacity: 0.5, cursor: "not-allowed", }, "": { width: "100%", "min-width": "0", outline: "var(--theme-sizes-zero)", position: "relative", "text-align": "left", "border-radius": "var(--theme-radii-md)", "font-family": "var(--theme-fonts-body)", display: "inline-flex", }, }, sources: [ { id: "value", name: "{{= it.component.name }}'s current value", provider: "StateProvider", description: "The current value of the input", template: "$get('{{= it.component.id}}', { value: {{= it.stringify(it.component.props.defaultValue) }} ?? '' }).value", instanceTemplate: `{{= it.component.name }}'s current value`, outputType: { kind: "number" }, }, { id: "isValid", provider: "StateProvider", name: "{{= it.component.name }}'s value is valid", description: "Returns true if input value is valid", template: `document.querySelector('[data-id|="{{= it.component.id }}"]')?.checkValidity();`, instanceTemplate: `is {{= it.component.name }}'s value valid`, outputType: { kind: "boolean" }, }, ], actions: [ { id: "set", name: `Set "{{= it.component.name }}"'s value`, provider: "StateProvider", description: "Set the value of the state variable", async: false, template: // eslint-disable-next-line no-template-curly-in-string "$set('{{= it.component.id }}', { value: {{= it.stringify(it.data.value) }} });", instanceTemplate: `{{= it.stringify(it.data.value) }}`, props: [ { label: "Value", name: "value", type: { kind: "number", isDynamic: true }, placeholder: "Choose a value", required: true, default: null, help: "The value to set the state variable to", }, ], }, { id: "focus", name: `Focus "{{= it.component.name }}" input`, description: "Focus the input", async: false, template: // eslint-disable-next-line no-template-curly-in-string 'document.querySelector(`[data-id="${$$getKey({{= it.stringify(it.component.id) }})}"]`)?.focus();', instanceTemplate: ``, props: [], }, { id: "blur", name: `Blur "{{= it.component.name }}" input`, description: "Blur the input", async: false, template: // eslint-disable-next-line no-template-curly-in-string 'document.querySelector(`[data-id="${$$getKey({{= it.stringify(it.component.id) }})}"]`)?.blur();', instanceTemplate: ``, props: [], }, ], } as const;