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:
parent
605fdc6d66
commit
632048601b
3 changed files with 67 additions and 1 deletions
|
@ -3,6 +3,6 @@ import { Bluelib } from "../src/components/Bluelib"
|
||||||
|
|
||||||
export const parameters = {
|
export const parameters = {
|
||||||
actions: {
|
actions: {
|
||||||
argTypesRegex: "^on[A-Z].*"
|
argTypesRegex: "^on[A-Z][a-z]*$"
|
||||||
},
|
},
|
||||||
}
|
}
|
29
src/components/inputs/Field.stories.jsx
Normal file
29
src/components/inputs/Field.stories.jsx
Normal 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,
|
||||||
|
}
|
37
src/components/inputs/Field.tsx
Normal file
37
src/components/inputs/Field.tsx
Normal 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}/>
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in a new issue