Skip to content

Commit 35bc6fa

Browse files
authored
fix: remove any from Component<any> (#190)
1 parent ff6016f commit 35bc6fa

File tree

1 file changed

+53
-52
lines changed

1 file changed

+53
-52
lines changed
Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,57 @@
11
import {
2-
$, Component,
2+
$,
3+
Component,
34
component$,
45
PropFunction,
56
Slot,
67
useId,
78
useStore,
8-
useStyles$
9+
useStyles$,
910
} from '@builder.io/qwik';
1011
import styles from './rating.css?inline';
1112

1213
export type RatingProps = {
1314
value?: number;
1415
total?: number;
15-
icon?: Component<any>;
16-
onChange$?: PropFunction<(index: number) => void>
17-
}
18-
19-
export const Rating = component$(
20-
(props: RatingProps) => {
21-
const {value, total = 5, onChange$} = props
22-
const uniqueId = useId()
16+
icon?: Component<{}>;
17+
onChange$?: PropFunction<(index: number) => void>;
18+
};
2319

24-
useStyles$(styles)
25-
const state = useStore({
26-
index: 0,
27-
tempIndex: 0
28-
});
20+
export const Rating = component$((props: RatingProps) => {
21+
const { value, total = 5, onChange$ } = props;
22+
const uniqueId = useId();
2923

30-
const onItemClick$ = $((index: number) => {
31-
state.index = index;
32-
if (onChange$) {
33-
onChange$(index + 1)
34-
}
35-
})
36-
return (
37-
<span class="wrapper">
38-
{
39-
new Array(total).fill('').map((item, i) => {
40-
const Icon = props.icon || DefaultIcon ;
41-
return (
42-
<RatingIcon
43-
key={useId()}
44-
name={`rating-${uniqueId}`}
45-
index={i}
46-
onChange$={() => onItemClick$(i)}
47-
value={value}
48-
>
49-
<Icon />
50-
</RatingIcon>
51-
)
52-
})
53-
}
54-
</span>
55-
)
56-
}
57-
);
24+
useStyles$(styles);
25+
const state = useStore({
26+
index: 0,
27+
tempIndex: 0,
28+
});
5829

30+
const onItemClick$ = $((index: number) => {
31+
state.index = index;
32+
if (onChange$) {
33+
onChange$(index + 1);
34+
}
35+
});
36+
return (
37+
<span class="wrapper">
38+
{new Array(total).fill('').map((item, i) => {
39+
const Icon = props.icon || DefaultIcon;
40+
return (
41+
<RatingIcon
42+
key={useId()}
43+
name={`rating-${uniqueId}`}
44+
index={i}
45+
onChange$={() => onItemClick$(i)}
46+
value={value}
47+
>
48+
<Icon />
49+
</RatingIcon>
50+
);
51+
})}
52+
</span>
53+
);
54+
});
5955

6056
/**
6157
* Rating Icon
@@ -66,22 +62,27 @@ interface RatingIconProps {
6662
value?: number;
6763
onChange$: PropFunction<() => void>;
6864
}
69-
export const RatingIcon = component$(
70-
(props: RatingIconProps) => {
71-
const { index, name, value } = props;
65+
export const RatingIcon = component$((props: RatingIconProps) => {
66+
const { index, name, value } = props;
7267

73-
return <>
74-
<label for={`${name}-${index}`}><Slot/></label>
68+
return (
69+
<>
70+
<label for={`${name}-${index}`}>
71+
<Slot />
72+
</label>
7573
<input
76-
onChange$={props.onChange$} hidden type="radio"
77-
checked={value === (index + 1)}
74+
onChange$={props.onChange$}
75+
hidden
76+
type="radio"
77+
checked={value === index + 1}
7878
name={name}
7979
id={`${name}-${index}`}
8080
/>
8181
</>
82-
})
82+
);
83+
});
8384

8485
/**
8586
* Default Icon
8687
*/
87-
export const DefaultIcon = component$(() => <>⭐️</>)
88+
export const DefaultIcon = component$(() => <>⭐️</>);

0 commit comments

Comments
 (0)