Skip to content

Commit 1e33812

Browse files
committed
feat: update EditorInput to include onChange prop and adjust styles for better functionality
1 parent 665f8fb commit 1e33812

4 files changed

Lines changed: 27 additions & 4 deletions

File tree

src/components/form/EditorInput.style.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818

1919
.cm-line {
2020
align-self: stretch;
21+
padding-left: 0;
2122
}
2223
}

src/components/form/EditorInput.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@ import {tags as t} from "@lezer/highlight";
99
import {hashToColor, mergeComponentProps} from "../../utils";
1010
import "./EditorInput.style.scss"
1111

12-
export interface EditorInputProps extends InputWrapperProps, ValidationProps<any> {
12+
export interface EditorInputProps extends Omit<InputWrapperProps, 'onChange'>, ValidationProps<any> {
1313
language?: StreamLanguage<unknown>
1414
suggestions?: (context: CompletionContext) => CompletionResult
1515
extensions?: Extension[]
1616
disabled?: boolean
1717
readonly?: boolean
1818
tokenStyles?: TagStyle[]
19+
onChange?: (value: string) => void
1920
}
2021

2122
export const EditorInput: React.FC<EditorInputProps> = (props) => {
2223

23-
const {title, right, left, rightType, leftType, language, description, extensions = [], tokenStyles = [], formValidation, ...rest} = props
24+
const {title, right, left, rightType, leftType, language, description, extensions = [], tokenStyles = [], formValidation, onChange, ...rest} = props
2425

2526
const internalExtensions: Extension[] = [...extensions, language!]
2627

@@ -61,7 +62,10 @@ export const EditorInput: React.FC<EditorInputProps> = (props) => {
6162
leftType={leftType}
6263
formValidation={formValidation}>
6364

64-
<CodeMirror extensions={internalExtensions} theme={myTheme} {...mergeComponentProps("editor-input", rest)} basicSetup={{
65+
<CodeMirror extensions={internalExtensions} onChange={value => {
66+
onChange?.(value)
67+
formValidation?.setValue(value)
68+
}} theme={myTheme} {...mergeComponentProps("editor-input", rest)} basicSetup={{
6569
lineNumbers: false,
6670
foldGutter: false,
6771
highlightActiveLine: false,

src/components/form/Input.stories.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,25 @@ export const Select = () => {
387387
}
388388

389389
export const Editor = () => {
390+
391+
392+
const [inputs, validate] = useForm({
393+
initialValues: {
394+
editor: undefined
395+
},
396+
validate: {
397+
editor: (value) => {
398+
if (!value) return "Please type something"
399+
return null
400+
}
401+
},
402+
onSubmit: (values) => {
403+
console.log(values)
404+
}
405+
})
406+
390407
return <Card color={"secondary"} w={"400px"}>
391-
<EditorInput placeholder={"sd"} language={StreamLanguage.define({
408+
<EditorInput {...inputs.getInputProps("editor")} onChange={() => validate("editor")} placeholder={"sd"} language={StreamLanguage.define({
392409
token(stream) {
393410
if (stream.match(/\{\{\s*(.*?)\s*\}\}/)) {
394411
return "keyword";

src/components/form/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from "./CheckboxInput"
2+
export * from "./EditorInput"
23
export * from "./EmailInput"
34
export * from "./Input"
45
export * from "./InputDescription"

0 commit comments

Comments
 (0)