diff --git a/packages/components/_templates/mitosis/new/component/tsx.ejs.t b/packages/components/_templates/mitosis/new/component/tsx.ejs.t index 2dd734ce0462..533bce3dcdda 100644 --- a/packages/components/_templates/mitosis/new/component/tsx.ejs.t +++ b/packages/components/_templates/mitosis/new/component/tsx.ejs.t @@ -5,25 +5,22 @@ import { onMount, Show, useMetadata, useStore } from "@builder.io/mitosis"; import { DB<%= h.changeCase.pascal(name) %>State, DB<%= h.changeCase.pascal(name) %>Props } from "./model"; import { cls, uuid } from "../../utils"; import {DEFAULT_ID} from "../../shared/constants"; +<% if(formValue!=="no"){ -%> +import {ChangeEvent, InteractionEvent} from "../../shared/model"; +<% } -%> useMetadata({ - isAttachedToShadowDom: true, - component: { - // MS Power Apps - includeIcon: false, - properties: [], - }, + isAttachedToShadowDom: true }); export default function DB<%= h.changeCase.pascal(name) %>(props: DB<%= h.changeCase.pascal(name) %>Props) { // This is used as forwardRef - let component: any; + const ref = useRef(null); // jscpd:ignore-start const state = useStoreState>({ _id: DEFAULT_ID, <% if(formValue!=="no"){ -%> - _isValid: undefined, - handleChange: (event: any) => { + handleChange: (event: ChangeEvent) => { if (props.onChange) { props.onChange(event); } @@ -32,21 +29,16 @@ export default function DB<%= h.changeCase.pascal(name) %>(props: DB<%= h.change props.change(event); } - if (event.target?.validity?.valid != state._isValid) { - state._isValid = event.target?.validity?.valid; - if (props.validityChange) { - props.validityChange(!!event.target?.validity?.valid); - } - } + const target = event.target as HTMLInputElement; // TODO: Replace this with the solution out of https://github.com/BuilderIO/mitosis/issues/833 after this has been "solved" - // VUE:this.$emit("update:<%= formValue %>", event.target.<%= formValue %>); + // VUE:this.$emit("update:<%= formValue %>", target.<%= formValue %>); // Change event to work with reactive and template driven forms - // ANGULAR: this.propagateChange(event.target.<%= formValue %>); - // ANGULAR: this.writeValue(event.target.<%= formValue %>); + // ANGULAR: this.propagateChange(target.<%= formValue %>); + // ANGULAR: this.writeValue(target.<%= formValue %>); }, - handleBlur: (event: any) => { + handleBlur: (event: InteractionEvent) => { if (props.onBlur) { props.onBlur(event); } @@ -55,7 +47,7 @@ export default function DB<%= h.changeCase.pascal(name) %>(props: DB<%= h.change props.blur(event); } }, - handleFocus: (event: any) => { + handleFocus: (event: InteractionEvent) => { if (props.onFocus) { props.onFocus(event); } @@ -77,13 +69,13 @@ export default function DB<%= h.changeCase.pascal(name) %>(props: DB<%= h.change return (
', props.className)} <% if(formValue!=="no"){ -%> - onChange={(event) => state.handleChange(event)} - onBlur={(event) => state.handleBlur(event)} - onFocus={(event) => state.handleFocus(event)} + onChange={(event: ChangeEvent) => state.handleChange(event)} + onBlur={(event: InteractionEvent) => state.handleBlur(event)} + onFocus={(event: InteractionEvent) => state.handleFocus(event)} <% } -%> > diff --git a/packages/components/scripts/post-build/angular.js b/packages/components/scripts/post-build/angular.js index 9ce5a02503e2..0c8bb46a884a 100644 --- a/packages/components/scripts/post-build/angular.js +++ b/packages/components/scripts/post-build/angular.js @@ -89,8 +89,8 @@ const setControlValueAccessorReplacements = ( writeValue(value: any) { this.${valueAccessor} = value; - if (this.component?.nativeElement) { - this.renderer.setProperty(this.component?.nativeElement, '${valueAccessor}', value); + if (this.ref?.nativeElement) { + this.renderer.setProperty(this.ref?.nativeElement, '${valueAccessor}', value); } } diff --git a/packages/components/scripts/post-build/components.js b/packages/components/scripts/post-build/components.js index bcc77cfa1fe0..0ed6999a044a 100644 --- a/packages/components/scripts/post-build/components.js +++ b/packages/components/scripts/post-build/components.js @@ -37,12 +37,6 @@ const getComponents = () => [ overwrites: { angular: [ { from: 'openItems = []', to: 'openItems: string[] = []' } - ], - react: [ - { - from: 'const ref = useRef(null);', - to: 'const ref = useRef(component);' - } ] } }, @@ -56,22 +50,11 @@ const getComponents = () => [ angular: { controlValueAccessor: 'value' } - }, - overwrites: { + },overwrites: { angular: [ - { - from: '[attr.defaultValue]="defaultValue ?? children"', - to: '' - }, { from: '', - to: '{{value || defaultValue}}' - } - ], - vue: [ - { - from: ':defaultValue="defaultValue || $slots.default"', - to: '' + to: '{{value}}' } ] } @@ -106,12 +89,6 @@ const getComponents = () => [ { name: 'drawer', overwrites: { - react: [ - { - from: 'const dialogRef = useRef(null);', - to: 'const dialogRef = useRef(component);' - } - ], webComponents: [{ from: '__prev.find', to: '!!__prev.find' }] } }, @@ -142,7 +119,7 @@ const getComponents = () => [ vModel: [{ modelValue: 'checked', binding: ':checked' }] }, angular: { - controlValueAccessor: false + controlValueAccessor: 'checked' } } }, diff --git a/packages/components/scripts/post-build/react.js b/packages/components/scripts/post-build/react.js index 9c96dd062a88..b3be1ea3adc7 100644 --- a/packages/components/scripts/post-build/react.js +++ b/packages/components/scripts/post-build/react.js @@ -1,28 +1,62 @@ const { components } = require('./components'); +const FS = require('node:fs'); const { getComponentName, runReplacements } = require('../utils'); +const overwriteEvents = (tmp) => { + const modelFilePath = `../../${ + tmp ? 'output/tmp' : 'output' + }/react/src/shared/model.ts`; + let modelFileContent = FS.readFileSync(modelFilePath).toString('utf-8'); + modelFileContent = 'import * as React from "react";\n' + modelFileContent; + modelFileContent = modelFileContent.replace( + 'export type ClickEvent = MouseEvent;', + 'export type ClickEvent = React.MouseEvent;' + ); + modelFileContent = modelFileContent.replace( + 'export type ChangeEvent = Event;', + 'export type ChangeEvent = React.ChangeEvent;' + ); + modelFileContent = modelFileContent.replace( + 'export type InteractionEvent = FocusEvent;', + 'export type InteractionEvent = React.FocusEvent;' + ); + FS.writeFileSync(modelFilePath, modelFileContent); +}; + module.exports = (tmp) => { - for (const component of components) { - try { + try { + overwriteEvents(tmp); + + for (const component of components) { const upperComponentName = getComponentName(component.name); const tsxFile = `../../${ tmp ? 'output/tmp' : 'output' }/react/src/components/${component.name}/${component.name}.tsx`; + const tsxFileContent = FS.readFileSync(tsxFile).toString('utf-8'); + const htmlElements = tsxFileContent.match('(?<=useRef<)(.*?)(?=>)'); + let htmlElement = 'HTMLDivElement'; + if (htmlElements.length > 0) { + htmlElement = htmlElements[0]; + } + let replacements = [ { from: /= useState/g, to: '= useState' }, - { from: ` } from "react"`, to: `, forwardRef } from "react"` }, + { + from: ` } from "react"`, + to: `, forwardRef, HTMLProps } from "react"` + }, { from: `function DB${upperComponentName}(props: DB${upperComponentName}Props) {`, - to: `function DB${upperComponentName}Fn(props: DB${upperComponentName}Props, component: any) {` + to: `function DB${upperComponentName}Fn(props: Omit, keyof DB${upperComponentName}Props> & DB${upperComponentName}Props, component: any) {` }, { from: `export default DB${upperComponentName};`, - to: `const DB${upperComponentName} = forwardRef(DB${upperComponentName}Fn);\nexport default DB${upperComponentName};` + to: `const DB${upperComponentName} = forwardRef<${htmlElement}, Omit, keyof DB${upperComponentName}Props> & DB${upperComponentName}Props>(DB${upperComponentName}Fn);\nexport default DB${upperComponentName};` }, { from: 'if (ref.current)', @@ -31,12 +65,28 @@ module.exports = (tmp) => { { from: '[ref.current]', to: '[ref]' + }, + { + from: '>(null);', + to: '>(component);' + }, + { + from: '={true}', + to: '' + }, + { + from: '} from "../../utils"', + to: ', filterPassingProps } from "../../utils"' + }, + { + from: 'ref={ref}', + to: 'ref={ref}\n' + '{...filterPassingProps(props)}' } ]; runReplacements(replacements, component, 'react', tsxFile); - } catch (error) { - console.error('Error occurred:', error); } + } catch (error) { + console.error('Error occurred:', error); } }; diff --git a/packages/components/src/components/accordion-item/accordion-item.lite.tsx b/packages/components/src/components/accordion-item/accordion-item.lite.tsx index 1370fc1bcccf..2feef846740e 100644 --- a/packages/components/src/components/accordion-item/accordion-item.lite.tsx +++ b/packages/components/src/components/accordion-item/accordion-item.lite.tsx @@ -4,11 +4,13 @@ import { Show, Slot, useMetadata, + useRef, useStore } from '@builder.io/mitosis'; import { DBAccordionItemState, DBAccordionItemProps } from './model'; import { cls, uuid } from '../../utils'; import { DEFAULT_ID } from '../../shared/constants'; +import { ClickEvent } from '../../shared/model'; useMetadata({ isAttachedToShadowDom: true, @@ -20,12 +22,11 @@ useMetadata({ }); export default function DBAccordionItem(props: DBAccordionItemProps) { - // This is used as forwardRef - let component: any; + const ref = useRef(null); // jscpd:ignore-start const state = useStore({ _id: DEFAULT_ID, - toggle: (event: any) => { + toggle: (event: ClickEvent) => { // We need this for react https://github.com/facebook/react/issues/15486#issuecomment-488028431 event?.preventDefault(); if (props.onToggle) { @@ -44,7 +45,7 @@ export default function DBAccordionItem(props: DBAccordionItemProps) { return (
- state.toggle(event)}> + ) => + state.toggle(event) + }> {props.title} diff --git a/packages/components/src/components/accordion-item/model.ts b/packages/components/src/components/accordion-item/model.ts index e8fc9caa8ece..af3692973b88 100644 --- a/packages/components/src/components/accordion-item/model.ts +++ b/packages/components/src/components/accordion-item/model.ts @@ -36,4 +36,4 @@ export interface DBAccordionItemDefaultState {} export type DBAccordionItemState = DBAccordionItemDefaultState & GlobalState & - ToggleEventState; + ToggleEventState; diff --git a/packages/components/src/components/alert/alert.lite.tsx b/packages/components/src/components/alert/alert.lite.tsx index 958217c0fe7b..246e78eba699 100644 --- a/packages/components/src/components/alert/alert.lite.tsx +++ b/packages/components/src/components/alert/alert.lite.tsx @@ -1,47 +1,26 @@ -import { onMount, Show, useMetadata, useStore } from '@builder.io/mitosis'; +import { + onMount, + Show, + useMetadata, + useRef, + useStore +} from '@builder.io/mitosis'; import { DBAlertProps, DBAlertState } from './model'; import { DBButton } from '../button'; import { DBLink } from '../link'; import { DEFAULT_CLOSE_BUTTON } from '../../shared/constants'; import { cls } from '../../utils'; +import { ClickEvent } from '../../shared/model'; useMetadata({ - isAttachedToShadowDom: true, - component: { - // MS Power Apps - includeIcon: true, - hasOnClick: true, - canvasSize: { - height: 'fixed', // 'fixed', 'controlled' - width: 'controlled' // 'fixed', 'dynamic' (requires width property), 'controlled' - }, - properties: [ - { name: 'headline', type: 'SingleLine.Text' }, - { - name: 'children', - type: 'SingleLine.Text', - defaultValue: 'Alert' - }, - { - name: 'icon', - type: 'Icon', // this is a custom type not provided by ms - defaultValue: 'info' - }, - { - name: 'variant', - type: 'DefaultVariant', // this is a custom type not provided by ms - defaultValue: 'adaptive' - } - ] - } + isAttachedToShadowDom: true }); export default function DBAlert(props: DBAlertProps) { - // This is used as forwardRef - let component: any; + const ref = useRef(null); // jscpd:ignore-start const state = useStore({ - handleClick: (event: any) => { + handleClick: (event: ClickEvent) => { if (props.onClick) { props.onClick(event); } @@ -57,7 +36,7 @@ export default function DBAlert(props: DBAlertProps) { return (
@@ -98,7 +77,9 @@ export default function DBAlert(props: DBAlertProps) { variant="text" size="small" noText - onClick={(event) => state.handleClick(event)}> + onClick={(event: ClickEvent) => + state.handleClick(event) + }> {props.closeButtonText ?? DEFAULT_CLOSE_BUTTON} diff --git a/packages/components/src/components/alert/model.ts b/packages/components/src/components/alert/model.ts index 83fc60113c5d..7945879c8e41 100644 --- a/packages/components/src/components/alert/model.ts +++ b/packages/components/src/components/alert/model.ts @@ -21,10 +21,6 @@ export interface DBAlertDefaultProps { * The behaviour attribute shows/hides the close button on the top right. */ behaviour?: 'closable' | 'permanent'; - /** - * The closeButtonText attribute changes the text inside the close button (only visible with behaviour="closeable"). - */ - closeButtonText?: string; /** * The headline attribute changes the text of the bold headline. */ @@ -43,7 +39,7 @@ export interface DBAlertDefaultProps { export type DBAlertProps = DBAlertDefaultProps & GlobalProps & - ClickEventProps & + ClickEventProps & IconProps & CardProps & DefaultVariantProps & @@ -51,4 +47,6 @@ export type DBAlertProps = DBAlertDefaultProps & export interface DBAlertDefaultState {} -export type DBAlertState = DBAlertDefaultState & GlobalState & ClickEventState; +export type DBAlertState = DBAlertDefaultState & + GlobalState & + ClickEventState; diff --git a/packages/components/src/components/badge/badge.lite.tsx b/packages/components/src/components/badge/badge.lite.tsx index d9431be8cafb..583e70461d0b 100644 --- a/packages/components/src/components/badge/badge.lite.tsx +++ b/packages/components/src/components/badge/badge.lite.tsx @@ -1,19 +1,13 @@ -import { onMount, Show, useMetadata, useStore } from '@builder.io/mitosis'; +import {onMount, Show, useMetadata, useRef, useStore} from '@builder.io/mitosis'; import { DBBadgeState, DBBadgeProps } from './model'; import { cls } from '../../utils'; useMetadata({ - isAttachedToShadowDom: true, - component: { - // MS Power Apps - includeIcon: false, - properties: [] - } + isAttachedToShadowDom: true }); export default function DBBadge(props: DBBadgeProps) { - // This is used as forwardRef - let component: any; + const ref = useRef(null); // jscpd:ignore-start const state = useStore({}); @@ -26,7 +20,7 @@ export default function DBBadge(props: DBBadgeProps) { return ( (null); // jscpd:ignore-start const state = useStore({ defaultValues: { @@ -67,7 +27,7 @@ export default function DBBrand(props: DBBrandProps) { return (
diff --git a/packages/components/src/components/button/button.lite.tsx b/packages/components/src/components/button/button.lite.tsx index 7b5a7d792b63..22c4570e0e78 100644 --- a/packages/components/src/components/button/button.lite.tsx +++ b/packages/components/src/components/button/button.lite.tsx @@ -1,68 +1,23 @@ -import { onMount, Show, useMetadata, useStore } from '@builder.io/mitosis'; +import { + onMount, + Show, + useMetadata, + useRef, + useStore +} from '@builder.io/mitosis'; import type { DBButtonProps, DBButtonState } from './model'; import { cls } from '../../utils'; +import { ClickEvent } from '../../shared/model'; useMetadata({ - isAttachedToShadowDom: true, - component: { - // MS Power Apps - includeIcon: true, - hasDisabledProp: true, - hasOnClick: true, - canvasSize: { - height: 'fixed', // 'fixed', 'controlled' - width: 'dynamic' // 'fixed', 'dynamic' (requires width property), 'controlled' - }, - properties: [ - { - name: 'children', - type: 'SingleLine.Text', - defaultValue: 'Button' - }, - { - name: 'variant', - type: 'Enum', - values: [ - { key: 'Primary', name: 'Primary', value: 'primary' }, - { key: 'Outlined', name: 'Outlined', value: 'outlined' }, - { - key: 'Text', - name: 'Text', - value: 'text' - }, - { - key: 'Solid', - name: 'Solid', - value: 'solid' - } - ], - defaultValue: 'primary' - }, - { - name: 'icon', - type: 'Icon' - }, - { name: 'noText', type: 'TwoOptions' }, - { - name: 'width', - powerAppsName: 'autoWidth', // width property is reserved in power apps - type: 'Enum', - defaultValue: 'auto', - values: [ - { key: 'Full', name: 'Full', value: 'full' }, - { key: 'Auto', name: 'Auto', value: 'auto' } - ] - } - ] - } + isAttachedToShadowDom: true }); export default function DBButton(props: DBButtonProps) { - // This is used as forwardRef - let component: any; + const ref = useRef(null); // jscpd:ignore-start const state = useStore({ - handleClick: (event: any) => { + handleClick: (event: ClickEvent) => { if (props.onClick) { props.onClick(event); } @@ -78,8 +33,8 @@ export default function DBButton(props: DBButtonProps) { return ( diff --git a/packages/components/src/components/page/page.lite.tsx b/packages/components/src/components/page/page.lite.tsx index 469d25be41d8..e3e9bf98775c 100644 --- a/packages/components/src/components/page/page.lite.tsx +++ b/packages/components/src/components/page/page.lite.tsx @@ -2,24 +2,18 @@ import { onMount, Show, Slot, - useMetadata, + useMetadata, useRef, useStore } from '@builder.io/mitosis'; import { DBPageProps, DBPageState } from './model'; import { cls } from '../../utils'; useMetadata({ - isAttachedToShadowDom: true, - component: { - // MS Power Apps - includeIcon: false, - properties: [] - } + isAttachedToShadowDom: true }); export default function DBPage(props: DBPageProps) { - // This is used as forwardRef - let component: any; + const ref = useRef(null); // jscpd:ignore-start const state = useStore({ fontsLoaded: false @@ -43,7 +37,7 @@ export default function DBPage(props: DBPageProps) { return (
; diff --git a/packages/components/src/components/popover/popover.lite.tsx b/packages/components/src/components/popover/popover.lite.tsx index 069b730961e4..f943d1f37e90 100644 --- a/packages/components/src/components/popover/popover.lite.tsx +++ b/packages/components/src/components/popover/popover.lite.tsx @@ -1,24 +1,25 @@ -import { onMount, Show, useMetadata, useStore } from '@builder.io/mitosis'; +import { + onMount, + Show, + useMetadata, + useRef, + useStore +} from '@builder.io/mitosis'; import { DBPopoverState, DBPopoverProps } from './model'; import { cls, uuid } from '../../utils'; import { DEFAULT_ID } from '../../shared/constants'; +import { ClickEvent } from '../../shared/model'; useMetadata({ - isAttachedToShadowDom: true, - component: { - // MS Power Apps - includeIcon: false, - properties: [] - } + isAttachedToShadowDom: true }); export default function DBPopover(props: DBPopoverProps) { - // This is used as forwardRef - let component: any; + const ref = useRef(null); // jscpd:ignore-start const state = useStore({ _id: DEFAULT_ID, - handleClick: (event: any) => { + handleClick: (event: ClickEvent) => { event.stopPropagation(); } }); @@ -33,7 +34,7 @@ export default function DBPopover(props: DBPopoverProps) { return ( state.handleClick(event)}> + onClick={(event: ClickEvent) => + state.handleClick(event) + }> diff --git a/packages/components/src/components/radio/model.ts b/packages/components/src/components/radio/model.ts index dcc32da5a629..0571c2e66ca7 100644 --- a/packages/components/src/components/radio/model.ts +++ b/packages/components/src/components/radio/model.ts @@ -1,7 +1,6 @@ import { FocusEventProps, FocusEventState, - ValidEventProps, ChangeEventState, ChangeEventProps, GlobalProps, @@ -19,9 +18,8 @@ export interface DBRadioDefaultProps { export type DBRadioProps = DBRadioDefaultProps & GlobalProps & - ChangeEventProps & - FocusEventProps & - ValidEventProps & + ChangeEventProps & + FocusEventProps & FormProps & FormCheckProps; @@ -29,7 +27,7 @@ export type DBRadioDefaultState = {}; export type DBRadioState = DBRadioDefaultState & GlobalState & - ChangeEventState & - FocusEventState & + ChangeEventState & + FocusEventState & FormState & InitializedState; diff --git a/packages/components/src/components/radio/radio.lite.tsx b/packages/components/src/components/radio/radio.lite.tsx index f07ea2a788b0..37fe1e532fb3 100644 --- a/packages/components/src/components/radio/radio.lite.tsx +++ b/packages/components/src/components/radio/radio.lite.tsx @@ -3,47 +3,26 @@ import { onUpdate, Show, useMetadata, + useRef, useStore } from '@builder.io/mitosis'; import { DBRadioProps, DBRadioState } from './model'; import { uuid } from '../../utils'; import { DEFAULT_ID } from '../../shared/constants'; import { cls } from '../../utils'; +import { ChangeEvent, InteractionEvent } from '../../shared/model'; useMetadata({ - isAttachedToShadowDom: true, - component: { - // MS Power Apps - includeIcon: false, - hasDisabledProp: true, - properties: [ - // jscpd:ignore-start - { - name: 'children', - type: 'SingleLine.Text', - defaultValue: 'Radio' - }, - { name: 'name', type: 'SingleLine.Text' }, - { name: 'id', type: 'SingleLine.Text' }, - { name: 'value', type: 'SingleLine.Text', onChange: 'value' } // $event.target["value"|"checked"|...] - // TODO: We'll most likely need these later on - // { name: 'checked', type: 'TwoOptions' }, - // { name: 'disabled', type: 'TwoOptions' }, - // jscpd:ignore-end - ] - } + isAttachedToShadowDom: true }); export default function DBRadio(props: DBRadioProps) { - // This is used as forwardRef - let component: any; + const ref = useRef(null); // jscpd:ignore-start const state = useStore({ initialized: false, _id: DEFAULT_ID, - _isValid: undefined, - - handleChange: (event: any) => { + handleChange: (event: ChangeEvent) => { if (props.onChange) { props.onChange(event); } @@ -52,20 +31,16 @@ export default function DBRadio(props: DBRadioProps) { props.change(event); } - if (event.target?.validity?.valid != state._isValid) { - state._isValid = event.target?.validity?.valid; - if (props.validityChange) { - props.validityChange(!!event.target?.validity?.valid); - } - } + const target = event.target as HTMLInputElement; + // TODO: Replace this with the solution out of https://github.com/BuilderIO/mitosis/issues/833 after this has been "solved" - // VUE:this.$emit("update:checked", event.target.checked); + // VUE:this.$emit("update:checked", target.checked); // Change event to work with reactive and template driven forms - // ANGULAR: this.propagateChange(event.target.checked); - // ANGULAR: this.writeValue(event.target.checked); + // ANGULAR: this.propagateChange(target.checked); + // ANGULAR: this.writeValue(target.checked); }, - handleBlur: (event: any) => { + handleBlur: (event: InteractionEvent) => { if (props.onBlur) { props.onBlur(event); } @@ -74,7 +49,7 @@ export default function DBRadio(props: DBRadioProps) { props.blur(event); } }, - handleFocus: (event: any) => { + handleFocus: (event: InteractionEvent) => { if (props.onFocus) { props.onFocus(event); } @@ -104,11 +79,6 @@ export default function DBRadio(props: DBRadioProps) { if (props.checked != undefined) { radioElement.checked = true; } - - if (props.defaultChecked !== undefined) { - // only set by JS: https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement#instance_properties_that_apply_only_to_elements_of_type_checkbox_or_radio - radioElement.defaultChecked = props.defaultChecked; - } } } }, [state.initialized]); @@ -123,7 +93,7 @@ export default function DBRadio(props: DBRadioProps) { state.handleChange(event)} - onBlur={(event) => state.handleBlur(event)} - onFocus={(event) => state.handleFocus(event)} + onChange={(event: ChangeEvent) => + state.handleChange(event) + } + onBlur={(event: InteractionEvent) => + state.handleBlur(event) + } + onFocus={(event: InteractionEvent) => + state.handleFocus(event) + } /> {props.label} diff --git a/packages/components/src/components/section/section.lite.tsx b/packages/components/src/components/section/section.lite.tsx index eb2f1b95beba..8fd29dcd6f13 100644 --- a/packages/components/src/components/section/section.lite.tsx +++ b/packages/components/src/components/section/section.lite.tsx @@ -1,19 +1,13 @@ -import { onMount, Show, useMetadata, useStore } from '@builder.io/mitosis'; +import {onMount, Show, useMetadata, useRef, useStore} from '@builder.io/mitosis'; import { DBSectionState, DBSectionProps } from './model'; import { cls } from '../../utils'; useMetadata({ - isAttachedToShadowDom: true, - component: { - // MS Power Apps - includeIcon: false, - properties: [] - } + isAttachedToShadowDom: true }); export default function DBSection(props: DBSectionProps) { - // This is used as forwardRef - let component: any; + const ref = useRef(null); // jscpd:ignore-start const state = useStore({}); @@ -26,7 +20,7 @@ export default function DBSection(props: DBSectionProps) { return (
diff --git a/packages/components/src/components/select/model.ts b/packages/components/src/components/select/model.ts index f67f83fb6792..5b6fef5b1caa 100644 --- a/packages/components/src/components/select/model.ts +++ b/packages/components/src/components/select/model.ts @@ -11,9 +11,7 @@ import { FormState, GlobalProps, GlobalState, - IconProps, - OverflowProps, - ValidEventProps + IconProps } from '../../shared/model'; export interface DBSelectDefaultProps { @@ -53,10 +51,9 @@ export type DBSelectOptionType = { export type DBSelectProps = DBSelectDefaultProps & GlobalProps & - ClickEventProps & - ChangeEventProps & - FocusEventProps & - ValidEventProps & + ClickEventProps & + ChangeEventProps & + FocusEventProps & FormProps & DefaultVariantProps & IconProps & @@ -69,7 +66,7 @@ export interface DBSelectDefaultState { export type DBSelectState = DBSelectDefaultState & GlobalState & - ClickEventState & - ChangeEventState & - FocusEventState & + ClickEventState & + ChangeEventState & + FocusEventState & FormState; diff --git a/packages/components/src/components/select/select.lite.tsx b/packages/components/src/components/select/select.lite.tsx index e88a9fbed87c..3858e2123fe3 100644 --- a/packages/components/src/components/select/select.lite.tsx +++ b/packages/components/src/components/select/select.lite.tsx @@ -4,6 +4,7 @@ import { onUpdate, Show, useMetadata, + useRef, useStore } from '@builder.io/mitosis'; import { DBSelectOptionType, DBSelectProps, DBSelectState } from './model'; @@ -15,30 +16,25 @@ import { DEFAULT_PLACEHOLDER_ID_SUFFIX } from '../../shared/constants'; import { DBInfotext } from '../infotext'; +import { ChangeEvent, ClickEvent, InteractionEvent } from '../../shared/model'; useMetadata({ - isAttachedToShadowDom: true, - component: { - includeIcon: false, - properties: [] - } + isAttachedToShadowDom: true }); export default function DBSelect(props: DBSelectProps) { - // This is used as forwardRef - let component: any; + const ref = useRef(null); // jscpd:ignore-start const state = useStore({ _id: DEFAULT_ID, _messageId: DEFAULT_ID + DEFAULT_MESSAGE_ID_SUFFIX, _placeholderId: DEFAULT_ID + DEFAULT_PLACEHOLDER_ID_SUFFIX, - _isValid: undefined, - handleClick: (event: any) => { + handleClick: (event: ClickEvent) => { if (props.onClick) { props.onClick(event); } }, - handleChange: (event: any) => { + handleChange: (event: ChangeEvent) => { if (props.onChange) { props.onChange(event); } @@ -46,22 +42,16 @@ export default function DBSelect(props: DBSelectProps) { if (props.change) { props.change(event); } - - if (event.target?.validity?.valid != state._isValid) { - state._isValid = event.target?.validity?.valid; - if (props.validityChange) { - props.validityChange(!!event.target?.validity?.valid); - } - } + const target = event.target as HTMLSelectElement; // TODO: Replace this with the solution out of https://github.com/BuilderIO/mitosis/issues/833 after this has been "solved" - // VUE:this.$emit("update:value", event.target.value); + // VUE:this.$emit("update:value", target.value); // Change event to work with reactive and template driven forms - // ANGULAR: this.propagateChange(event.target.checked); - // ANGULAR: this.writeValue(event.target.checked); + // ANGULAR: this.propagateChange(target.value); + // ANGULAR: this.writeValue(target.value); }, - handleBlur: (event: any) => { + handleBlur: (event: InteractionEvent) => { if (props.onBlur) { props.onBlur(event); } @@ -70,7 +60,7 @@ export default function DBSelect(props: DBSelectProps) { props.blur(event); } }, - handleFocus: (event: any) => { + handleFocus: (event: InteractionEvent) => { if (props.onFocus) { props.onFocus(event); } @@ -107,17 +97,25 @@ export default function DBSelect(props: DBSelectProps) {