Skip to content

Commit 23c91e4

Browse files
authored
chore: update onClick for button and link with mitosis plugin (#4392)
1 parent ea6e454 commit 23c91e4

File tree

9 files changed

+61
-46
lines changed

9 files changed

+61
-46
lines changed
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
const onClickPlugin = require('../plugins/on-click.cjs');
2+
3+
/**
4+
* @type {import('@builder.io/mitosis').ToAngularOptions}
5+
*/
16
module.exports = {
2-
typescript: true,
37
attributePassing: {
48
customRef: '_ref'
59
},
6-
api: 'signals'
10+
api: 'signals',
11+
plugins: [onClickPlugin]
712
};
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const angular = require('./index.cjs');
12
/**
23
* @type {import('@builder.io/mitosis').MitosisConfig}
34
*/
@@ -6,12 +7,6 @@ module.exports = {
67
targets: ['angular'],
78
dest: '../../output/tmp',
89
options: {
9-
angular: {
10-
experimental: {
11-
outputs: (_json, propName) => {
12-
return propName === 'click' ? 'click' : undefined;
13-
}
14-
}
15-
}
10+
angular
1611
}
1712
};

packages/components/configs/mitosis.config.cjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ module.exports = {
1010
files: 'src/**',
1111
targets: ['angular', 'vue', 'react', 'stencil'],
1212
dest: '../../output',
13+
commonOptions: {
14+
typescript: true
15+
},
1316
options: {
1417
react,
1518
angular,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @type {import('@builder.io/mitosis').MitosisPlugin}
3+
*/
4+
module.exports = () => ({
5+
json: {
6+
pre: (json) => {
7+
console.log(json.name);
8+
if (['DBButton', 'DBLink'].includes(json.name)) {
9+
if (json.pluginData.target === 'vue') {
10+
console.log(json.state);
11+
json.children[0].bindings.onClick = {
12+
code: 'state.handleClick(event)',
13+
bindingType: 'expression',
14+
type: 'single'
15+
};
16+
17+
json.state = {
18+
...json.state,
19+
handleClick: {
20+
code: `function handleClick(event){if (props.onClick){props.onClick(event);}}`,
21+
type: 'method'
22+
}
23+
};
24+
} else {
25+
delete json.props.onClick;
26+
delete json.props.click;
27+
}
28+
}
29+
30+
return json;
31+
}
32+
}
33+
});
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
const onClickPlugin = require('../plugins/on-click.cjs');
2+
13
/**
24
* @type {import('@builder.io/mitosis').ToReactOptions}
35
*/
46
module.exports = {
5-
typescript: true
7+
plugins: [onClickPlugin]
68
};
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
const onClickPlugin = require('../plugins/on-click.cjs');
2+
3+
/**
4+
* @type {import('@builder.io/mitosis').ToStencilOptions}
5+
*/
16
module.exports = {
2-
typescript: true,
37
attributePassing: {
48
enabled: true,
59
customRef: '_ref'
6-
}
10+
},
11+
plugins: [onClickPlugin]
712
};
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
const onClickPlugin = require('../plugins/on-click.cjs');
2+
13
/**
24
* @type {import('@builder.io/mitosis').ToVueOptions}
35
*/
46
module.exports = {
5-
typescript: true,
6-
api: 'composition'
7+
api: 'composition',
8+
plugins: [onClickPlugin]
79
};

packages/components/src/components/button/button.lite.tsx

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ useDefaultProps<DBButtonProps>({});
2020

2121
export default function DBButton(props: DBButtonProps) {
2222
const _ref = useRef<HTMLButtonElement | any>(null);
23-
// jscpd:ignore-start
24-
const state = useStore<DBButtonState>({
25-
handleClick: (event: ClickEvent<HTMLButtonElement>) => {
26-
if (props.onClick) {
27-
props.onClick(event);
28-
}
29-
}
30-
});
31-
32-
// jscpd:ignore-end
3323

3424
return (
3525
<button
@@ -51,14 +41,7 @@ export default function DBButton(props: DBButtonProps) {
5141
value={props.value}
5242
aria-describedby={props.describedbyid}
5343
aria-expanded={props.ariaexpanded}
54-
aria-pressed={props.ariapressed}
55-
{...useTarget({
56-
vue: {
57-
onClick: (event: ClickEvent<HTMLButtonElement>) =>
58-
state.handleClick(event)
59-
},
60-
default: {}
61-
})}>
44+
aria-pressed={props.ariapressed}>
6245
<Show when={props.text} else={props.children}>
6346
{props.text}
6447
</Show>

packages/components/src/components/link/link.lite.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@ useDefaultProps<DBLinkProps>({});
1515

1616
export default function DBLink(props: DBLinkProps) {
1717
const _ref = useRef<HTMLAnchorElement | any>(null);
18-
// jscpd:ignore-start
19-
const state = useStore<DBLinkState>({
20-
handleClick: (event: ClickEvent<HTMLAnchorElement>) => {
21-
if (props.onClick) {
22-
props.onClick(event);
23-
}
24-
}
25-
});
26-
27-
// jscpd:ignore-end
2818

2919
return (
3020
<a
@@ -44,10 +34,7 @@ export default function DBLink(props: DBLinkProps) {
4434
data-size={props.size}
4535
data-hide-icon-after={getHideProp(props.showIcon ?? true)}
4636
data-variant={props.variant}
47-
data-content={props.content || 'internal'}
48-
onClick={(event: ClickEvent<HTMLAnchorElement>) =>
49-
state.handleClick(event)
50-
}>
37+
data-content={props.content || 'internal'}>
5138
<Show when={props.text} else={props.children}>
5239
{props.text}
5340
</Show>

0 commit comments

Comments
 (0)