Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 7 additions & 2 deletions packages/components/configs/angular/index.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const onClickPlugin = require('../plugins/on-click.cjs');

/**
* @type {import('@builder.io/mitosis').ToAngularOptions}
*/
module.exports = {
typescript: true,
attributePassing: {
customRef: '_ref'
},
api: 'signals'
api: 'signals',
plugins: [onClickPlugin]
};
3 changes: 3 additions & 0 deletions packages/components/configs/mitosis.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module.exports = {
files: 'src/**',
targets: ['angular', 'vue', 'react', 'stencil'],
dest: '../../output',
commonOptions: {
typescript: true
},
options: {
react,
angular,
Expand Down
31 changes: 31 additions & 0 deletions packages/components/configs/plugins/on-click.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @type {import('@builder.io/mitosis').MitosisPlugin}
*/
module.exports = () => ({
json: {
pre: (json) => {
if (['DBButton', 'DBLink'].includes(json.name)) {
if (json.pluginData.target === 'vue') {
json.children[0].bindings.onClick = {
code: 'state.handleClick(event)',
bindingType: 'expression',
type: 'single'
};

json.state = {
...json.state,
handleClick: {
code: `function handleClick(event){if (props.onClick){props.onClick(event);}}`,
type: 'method'
}
};
} else {
delete json.props.onClick;
delete json.props.click;
}
}

return json;
}
}
});
4 changes: 3 additions & 1 deletion packages/components/configs/react/index.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const onClickPlugin = require('../plugins/on-click.cjs');

/**
* @type {import('@builder.io/mitosis').ToReactOptions}
*/
module.exports = {
typescript: true
plugins: [onClickPlugin]
};
9 changes: 7 additions & 2 deletions packages/components/configs/stencil/index.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const onClickPlugin = require('../plugins/on-click.cjs');

/**
* @type {import('@builder.io/mitosis').ToStencilOptions}
*/
module.exports = {
typescript: true,
attributePassing: {
enabled: true,
customRef: '_ref'
}
},
plugins: [onClickPlugin]
};
6 changes: 4 additions & 2 deletions packages/components/configs/vue/index.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const onClickPlugin = require('../plugins/on-click.cjs');

/**
* @type {import('@builder.io/mitosis').ToVueOptions}
*/
module.exports = {
typescript: true,
api: 'composition'
api: 'composition',
plugins: [onClickPlugin]
};
21 changes: 3 additions & 18 deletions packages/components/src/components/button/button.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import {
Show,
useDefaultProps,
useMetadata,
useRef,
useStore
useRef
} from '@builder.io/mitosis';
import type { DBButtonProps, DBButtonState } from './model';
import type { DBButtonProps } from './model';
import { cls, getBoolean, getBooleanAsString, getHideProp } from '../../utils';
import { ClickEvent } from '../../shared/model';

useMetadata({
angular: {
Expand All @@ -19,16 +17,6 @@ useDefaultProps<DBButtonProps>({});

export default function DBButton(props: DBButtonProps) {
const _ref = useRef<HTMLButtonElement | any>(null);
// jscpd:ignore-start
const state = useStore<DBButtonState>({
handleClick: (event: ClickEvent<HTMLButtonElement>) => {
if (props.onClick) {
props.onClick(event);
}
}
});

// jscpd:ignore-end

return (
<button
Expand All @@ -50,10 +38,7 @@ export default function DBButton(props: DBButtonProps) {
value={props.value}
aria-describedby={props.describedbyid}
aria-expanded={props.ariaexpanded}
aria-pressed={props.ariapressed}
onClick={(event: ClickEvent<HTMLButtonElement>) =>
state.handleClick(event)
}>
aria-pressed={props.ariapressed}>
<Show when={props.text} else={props.children}>
{props.text}
</Show>
Expand Down
21 changes: 3 additions & 18 deletions packages/components/src/components/link/link.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,17 @@ import {
Show,
useDefaultProps,
useMetadata,
useRef,
useStore
useRef
} from '@builder.io/mitosis';
import { DBLinkProps, DBLinkState } from './model';
import { DBLinkProps } from './model';
import { cls, getBooleanAsString, getHideProp } from '../../utils';
import { ClickEvent } from '../../shared/model';

useMetadata({});

useDefaultProps<DBLinkProps>({});

export default function DBLink(props: DBLinkProps) {
const _ref = useRef<HTMLAnchorElement | any>(null);
// jscpd:ignore-start
const state = useStore<DBLinkState>({
handleClick: (event: ClickEvent<HTMLAnchorElement>) => {
if (props.onClick) {
props.onClick(event);
}
}
});

// jscpd:ignore-end

return (
<a
Expand All @@ -44,10 +32,7 @@ export default function DBLink(props: DBLinkProps) {
data-size={props.size}
data-hide-icon-after={getHideProp(props.showIcon ?? true)}
data-variant={props.variant}
data-content={props.content || 'internal'}
onClick={(event: ClickEvent<HTMLAnchorElement>) =>
state.handleClick(event)
}>
data-content={props.content || 'internal'}>
<Show when={props.text} else={props.children}>
{props.text}
</Show>
Expand Down
Loading