1
Fork 0
mirror of https://github.com/Steffo99/bluelib.git synced 2024-12-22 19:44:21 +00:00

🚧 Start working on inputs (input-field)

This commit is contained in:
Steffo 2021-08-19 04:50:23 +02:00
parent 605fdc6d66
commit 632048601b
Signed by: steffo
GPG key ID: 6965406171929D01
3 changed files with 67 additions and 1 deletions

View file

@ -3,6 +3,6 @@ import { Bluelib } from "../src/components/Bluelib"
export const parameters = {
actions: {
argTypesRegex: "^on[A-Z].*"
argTypesRegex: "^on[A-Z][a-z]*$"
},
}

View file

@ -0,0 +1,29 @@
import * as React from "react"
import * as ReactDOM from "react-dom"
import * as Decorators from "../../utils/Decorators"
import { Field } from "./Field"
export default {
component: Field,
title: "Inputs/Field",
decorators: [Decorators.Bluelib],
argTypes: {
customColor: {
control: {type: "color"},
},
disabled: {
control: {type: "boolean"},
},
},
}
export const Default = props => (
<Field {...props}/>
)
Default.args = {
placeholder: "Enter text here",
disabled: false,
required: false,
}

View file

@ -0,0 +1,37 @@
import * as React from "react"
import * as ReactDOM from "react-dom"
import * as Types from "../../types"
import {BaseElement} from "../BaseElement"
import mergeClassNames from "classnames"
interface FieldProps {
placeholder: string,
required?: boolean,
disabled?: boolean,
onChange?: (event: React.FormEvent<HTMLInputElement>) => boolean,
onInput?: (event: React.FormEvent<HTMLInputElement>) => boolean,
onInvalid?: (event: React.FormEvent<HTMLInputElement>) => boolean,
onReset?: (event: React.FormEvent<HTMLInputElement>) => boolean,
onSubmit?: (event: React.FormEvent<HTMLInputElement>) => boolean,
[props: string]: any,
}
export function Field({onChange, onInput, onInvalid, ...props}: FieldProps): JSX.Element {
props.bluelibClassNames = mergeClassNames(props.bluelibClassNames, "input", "input-field")
// Propagate change events only if the element is enabled
if(!props.disabled) {
props.onChange = onChange
props.onInput = onInput
props.onInvalid = onInvalid
}
return (
<BaseElement kind={"input"} {...props}/>
)
}